diff --git a/main/src/main/java/net/citizensnpcs/EventListen.java b/main/src/main/java/net/citizensnpcs/EventListen.java index 8083a7908..50ffbb284 100644 --- a/main/src/main/java/net/citizensnpcs/EventListen.java +++ b/main/src/main/java/net/citizensnpcs/EventListen.java @@ -224,9 +224,6 @@ public class EventListen implements Listener { } } - /* - * Entity events - */ @EventHandler public void onEntityCombust(EntityCombustEvent event) { NPC npc = CitizensAPI.getNPCRegistry().getNPC(event.getEntity()); diff --git a/main/src/main/java/net/citizensnpcs/commands/NPCCommands.java b/main/src/main/java/net/citizensnpcs/commands/NPCCommands.java index 362b99049..1b860a15c 100644 --- a/main/src/main/java/net/citizensnpcs/commands/NPCCommands.java +++ b/main/src/main/java/net/citizensnpcs/commands/NPCCommands.java @@ -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])", diff --git a/main/src/main/java/net/citizensnpcs/trait/PacketNPC.java b/main/src/main/java/net/citizensnpcs/trait/PacketNPC.java index 5637b8818..942c76937 100644 --- a/main/src/main/java/net/citizensnpcs/trait/PacketNPC.java +++ b/main/src/main/java/net/citizensnpcs/trait/PacketNPC.java @@ -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()); diff --git a/main/src/main/java/net/citizensnpcs/trait/ShopTrait.java b/main/src/main/java/net/citizensnpcs/trait/ShopTrait.java index d97bee440..00dec7cc0 100644 --- a/main/src/main/java/net/citizensnpcs/trait/ShopTrait.java +++ b/main/src/main/java/net/citizensnpcs/trait/ShopTrait.java @@ -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); diff --git a/main/src/main/java/net/citizensnpcs/util/Messages.java b/main/src/main/java/net/citizensnpcs/util/Messages.java index 5bfb00166..fbcca5116 100644 --- a/main/src/main/java/net/citizensnpcs/util/Messages.java +++ b/main/src/main/java/net/citizensnpcs/util/Messages.java @@ -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"; diff --git a/main/src/main/resources/messages_en.properties b/main/src/main/resources/messages_en.properties index 8c7f3e55f..30094f80e 100644 --- a/main/src/main/resources/messages_en.properties +++ b/main/src/main/resources/messages_en.properties @@ -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.