From a551fe4890f1aeda70c608e2740422a867b820f2 Mon Sep 17 00:00:00 2001 From: fullwall Date: Sun, 18 Jun 2023 17:23:55 +0800 Subject: [PATCH] Add /npc setequipment --- .../java/net/citizensnpcs/EventListen.java | 2 -- .../citizensnpcs/commands/NPCCommands.java | 28 ++++++++++++++++++- .../java/net/citizensnpcs/util/Messages.java | 5 ++-- .../src/main/resources/messages_en.properties | 1 + 4 files changed, 31 insertions(+), 5 deletions(-) diff --git a/main/src/main/java/net/citizensnpcs/EventListen.java b/main/src/main/java/net/citizensnpcs/EventListen.java index dbdee4d2c..34353a765 100644 --- a/main/src/main/java/net/citizensnpcs/EventListen.java +++ b/main/src/main/java/net/citizensnpcs/EventListen.java @@ -718,8 +718,6 @@ public class EventListen implements Listener { Method getAcceleration = kbc.getMethod("getAcceleration"); handlers.register(new RegisteredListener(new Listener() { }, (listener, event) -> { - if (NPCKnockbackEvent.getHandlerList().getRegisteredListeners().length == 0) - return; try { Entity entity = (Entity) getEntity.invoke(event); if (!(entity instanceof NPCHolder)) diff --git a/main/src/main/java/net/citizensnpcs/commands/NPCCommands.java b/main/src/main/java/net/citizensnpcs/commands/NPCCommands.java index f17f6f5f4..ff7863448 100644 --- a/main/src/main/java/net/citizensnpcs/commands/NPCCommands.java +++ b/main/src/main/java/net/citizensnpcs/commands/NPCCommands.java @@ -78,6 +78,8 @@ import net.citizensnpcs.api.npc.NPC; import net.citizensnpcs.api.npc.NPC.NPCUpdate; import net.citizensnpcs.api.npc.NPCRegistry; import net.citizensnpcs.api.trait.Trait; +import net.citizensnpcs.api.trait.trait.Equipment; +import net.citizensnpcs.api.trait.trait.Equipment.EquipmentSlot; import net.citizensnpcs.api.trait.trait.Inventory; import net.citizensnpcs.api.trait.trait.MobType; import net.citizensnpcs.api.trait.trait.Owner; @@ -1088,7 +1090,10 @@ public class NPCCommands { max = -1, permission = "citizens.npc.hologram") public void hologram(CommandContext args, CommandSender sender, NPC npc, - @Arg(value = 1, completions = { "add", "set", "remove", "clear", "lineheight", "direction", "margintop", "marginbottom" }) String action) + @Arg( + value = 1, + completions = { "add", "set", "remove", "clear", "lineheight", "direction", "margintop", + "marginbottom" }) String action) throws CommandException { HologramTrait trait = npc.getOrAddTrait(HologramTrait.class); if (args.argsLength() == 1) { @@ -2621,6 +2626,27 @@ public class NPCCommands { } } + @Command( + aliases = { "npc" }, + usage = "setequipment [slot] [item]", + desc = "Sets equipment via commands", + modifiers = { "setequipment" }, + min = 2, + max = 3, + permission = "citizens.npc.setequipment") + public void setequipment(CommandContext args, CommandSender sender, NPC npc, @Arg(1) EquipmentSlot slot, + @Arg(2) ItemStack item) throws CommandException { + if (slot == null) + throw new CommandUsageException(); + if (item == null && args.argsLength() == 3 && args.getString(2).equalsIgnoreCase("hand")) { + if (!(sender instanceof Player)) + throw new ServerCommandException(); + item = ((Player) sender).getItemInHand().clone(); + } + npc.getOrAddTrait(Equipment.class).set(slot, item); + Messaging.sendTr(sender, Messages.EQUIPMENT_SET, slot, item); + } + @Command( aliases = { "npc" }, usage = "sheep (--color [color]) (--sheared [sheared])", diff --git a/main/src/main/java/net/citizensnpcs/util/Messages.java b/main/src/main/java/net/citizensnpcs/util/Messages.java index 019c0be64..34c0dc1cf 100644 --- a/main/src/main/java/net/citizensnpcs/util/Messages.java +++ b/main/src/main/java/net/citizensnpcs/util/Messages.java @@ -104,6 +104,7 @@ public class Messages { public static final String EQUIPMENT_EDITOR_BEGIN = "citizens.editors.equipment.begin"; public static final String EQUIPMENT_EDITOR_END = "citizens.editors.equipment.end"; public static final String EQUIPMENT_EDITOR_SHEEP_COLOURED = "citizens.editors.equipment.sheep-coloured"; + public static final String EQUIPMENT_SET = "citizens.commands.npc.setequipment.set"; public static final String ERROR_CLEARING_GOALS = "citizens.nms-errors.clearing-goals"; public static final String ERROR_GETTING_FIELD = "citizens.nms-errors.getting-field"; public static final String ERROR_GETTING_ID_MAPPING = "citizens.nms-errors.getting-id-mapping"; @@ -156,10 +157,10 @@ public class Messages { public static final String HOLOGRAM_LINE_HEIGHT_SET = "citizens.commands.npc.hologram.line-height-set"; public static final String HOLOGRAM_LINE_REMOVED = "citizens.commands.npc.hologram.line-removed"; public static final String HOLOGRAM_LINE_SET = "citizens.commands.npc.hologram.text-set"; - public static final String HOLOGRAM_TEXT_MISSING = "citizens.commands.npc.hologram.text-missing"; - public static final String HOLOGRAM_TEXT_REMOVED = "citizens.commands.npc.hologram.text-removed"; public static final String HOLOGRAM_MARGIN_MISSING = "citizens.commands.npc.hologram.margin-missing"; public static final String HOLOGRAM_MARGIN_SET = "citizens.commands.npc.hologram.margin-set"; + public static final String HOLOGRAM_TEXT_MISSING = "citizens.commands.npc.hologram.text-missing"; + public static final String HOLOGRAM_TEXT_REMOVED = "citizens.commands.npc.hologram.text-removed"; public static final String HOME_TRAIT_DELAY_SET = "citizens.commands.npc.home.delay-set"; public static final String HOME_TRAIT_DISTANCE_SET = "citizens.commands.npc.home.distance-set"; public static final String HOME_TRAIT_LOCATION_SET = "citizens.commands.npc.home.home-set"; diff --git a/main/src/main/resources/messages_en.properties b/main/src/main/resources/messages_en.properties index e54cfe889..09cf2aa11 100644 --- a/main/src/main/resources/messages_en.properties +++ b/main/src/main/resources/messages_en.properties @@ -272,6 +272,7 @@ citizens.commands.npc.remove.removed=You permanently removed [[{0}]] ID [[{1}]] citizens.commands.npc.rename.renamed=You renamed [[{0}]] to [[{1}]]. citizens.commands.npc.respawn.delay-set=Respawn delay set to [[{0}]] ticks. citizens.commands.npc.respawn.describe=Respawn delay is currently [[{0}]] ticks. +citizens.commands.npc.setequipment.set=Set [[{0}]] to [[{1}]]. citizens.commands.npc.select.already-selected=You already have that NPC selected. citizens.commands.npc.script.invalid-file=Unknown or unavailable script ''[[{0}]]''. citizens.commands.npc.scoreboard.added-tags=Added these tags: [[{0}]].