Add /npc packet

This commit is contained in:
fullwall 2023-03-02 23:08:03 +08:00
parent 98e95b6ffb
commit cb6f8be7fc
6 changed files with 37 additions and 3 deletions

View File

@ -224,9 +224,6 @@ public class EventListen implements Listener {
}
}
/*
* Entity events
*/
@EventHandler
public void onEntityCombust(EntityCombustEvent event) {
NPC npc = CitizensAPI.getNPCRegistry().getNPC(event.getEntity());

View File

@ -1861,6 +1861,28 @@ public class NPCCommands {
Messaging.sendTr(sender, serverOwner ? Messages.OWNER_SET_SERVER : Messages.OWNER_SET, npc.getName(), uuid);
}
@Command(
aliases = { "npc" },
usage = "packet --enabled [true|false]",
desc = "Controls packet NPC settings",
modifiers = { "packet" },
min = 1,
max = 1,
permission = "citizens.npc.packet")
@Requirements(selected = true, ownership = true)
public void packet(CommandContext args, CommandSender sender, NPC npc, @Flag("enabled") Boolean explicit)
throws CommandException {
if (explicit != null) {
if (explicit) {
npc.getOrAddTrait(PacketNPC.class);
Messaging.sendTr(sender, Messages.NPC_PACKET_ENABLED, npc.getName());
} else {
npc.removeTrait(PacketNPC.class);
Messaging.sendTr(sender, Messages.NPC_PACKET_DISABLED, npc.getName());
}
}
}
@Command(
aliases = { "npc" },
usage = "passive (--set [true|false])",

View File

@ -2,12 +2,15 @@ package net.citizensnpcs.trait;
import java.util.function.Consumer;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Player;
import net.citizensnpcs.api.CitizensAPI;
import net.citizensnpcs.api.LocationLookup.PerPlayerMetadata;
import net.citizensnpcs.api.event.DespawnReason;
import net.citizensnpcs.api.event.SpawnReason;
import net.citizensnpcs.api.npc.NPC;
import net.citizensnpcs.api.trait.Trait;
import net.citizensnpcs.api.trait.TraitName;
@ -24,6 +27,13 @@ public class PacketNPC extends Trait {
super("packet");
}
@Override
public void onRemove() {
npc.despawn(DespawnReason.PENDING_RESPAWN);
Bukkit.getScheduler().scheduleSyncDelayedTask(CitizensAPI.getPlugin(),
() -> npc.spawn(npc.getStoredLocation(), SpawnReason.RESPAWN));
}
@Override
public void onSpawn() {
playerTracker = NMS.getPlayerTracker(npc.getEntity());

View File

@ -183,6 +183,7 @@ public class ShopTrait extends Trait {
public void changePage(int newPage) {
this.page = newPage;
ctx.setTitle("NPC Shop Contents Editor Page " + newPage);
NPCShopPage shopPage = shop.getOrCreatePage(page);
for (int i = 0; i < ctx.getInventory().getSize(); i++) {
InventoryMenuSlot slot = ctx.getSlot(i);

View File

@ -273,6 +273,8 @@ public class Messages {
public static final String NPC_NOT_DAMAGEABLE = "citizens.commands.npc.hurt.not-damageable";
public static final String NPC_NOT_FOUND = "citizens.notifications.npc-not-found";
public static final String NPC_OWNER = "citizens.commands.npc.owner.owner";
public static final String NPC_PACKET_DISABLED = "citizens.commands.npc.packet.disabled";
public static final String NPC_PACKET_ENABLED = "citizens.commands.npc.packet.enabled";
public static final String NPC_PROTECTED = "citizens.commands.npc.hurt.protected";
public static final String NPC_REMOVED = "citizens.commands.npc.remove.removed";
public static final String NPC_RENAMED = "citizens.commands.npc.rename.renamed";

View File

@ -189,6 +189,8 @@ citizens.commands.npc.owner.already-owner={0} is already the owner of [[{1}]].
citizens.commands.npc.owner.owner=[[{0}]]''s owner is [[{1}]].
citizens.commands.npc.owner.set-server=[[The server]] is now the owner of [[{0}]].
citizens.commands.npc.owner.set=[[{1}]] is now the owner of [[{0}]].
citizens.commands.npc.packet.enabled=[[{0}]] is now a packet NPC.
citizens.commands.npc.packet.disabled=[[{0}]] is no longer a packet NPC.
citizens.commands.npc.panda.invalid-gene=Invalid gene. Valid genes are [[{0}]].
citizens.commands.npc.panda.sneezing=Started sneezing.
citizens.commands.npc.panda.sneezing-stopped=Stopped sneezing.