From 310ebb1458533e9d837da6010ea88052fb80c4ec Mon Sep 17 00:00:00 2001 From: fullwall Date: Sun, 25 Aug 2024 17:19:09 +0800 Subject: [PATCH] Add /npc bat --- .../citizensnpcs/commands/NPCCommands.java | 18 +++++++++++ .../npc/CitizensTraitFactory.java | 2 ++ .../java/net/citizensnpcs/trait/BatTrait.java | 32 +++++++++++++++++++ .../java/net/citizensnpcs/util/Messages.java | 6 ++-- main/src/main/resources/en.json | 4 +++ 5 files changed, 60 insertions(+), 2 deletions(-) create mode 100644 main/src/main/java/net/citizensnpcs/trait/BatTrait.java diff --git a/main/src/main/java/net/citizensnpcs/commands/NPCCommands.java b/main/src/main/java/net/citizensnpcs/commands/NPCCommands.java index 06f7fcad4..e8aef29f9 100644 --- a/main/src/main/java/net/citizensnpcs/commands/NPCCommands.java +++ b/main/src/main/java/net/citizensnpcs/commands/NPCCommands.java @@ -122,6 +122,7 @@ import net.citizensnpcs.trait.Age; import net.citizensnpcs.trait.Anchors; import net.citizensnpcs.trait.ArmorStandTrait; import net.citizensnpcs.trait.AttributeTrait; +import net.citizensnpcs.trait.BatTrait; import net.citizensnpcs.trait.BoatTrait; import net.citizensnpcs.trait.BoundingBoxTrait; import net.citizensnpcs.trait.ClickRedirectTrait; @@ -431,6 +432,23 @@ public class NPCCommands { } } + @Command( + aliases = { "npc" }, + usage = "bat --awake [awake]", + desc = "", + modifiers = { "bat" }, + min = 1, + max = 1, + permission = "citizens.npc.bat") + @Requirements(selected = true, ownership = true, types = EntityType.BAT) + public void bat(CommandContext args, CommandSender sender, NPC npc, @Flag("awake") Boolean awake) + throws CommandException { + if (awake == null) + throw new CommandException(); + npc.getOrAddTrait(BatTrait.class).setAwake(awake); + Messaging.sendTr(sender, awake ? Messages.BAT_AWAKE_SET : Messages.BAT_AWAKE_UNSET, npc.getName()); + } + @Command( aliases = { "npc" }, usage = "boat --type [type]", diff --git a/main/src/main/java/net/citizensnpcs/npc/CitizensTraitFactory.java b/main/src/main/java/net/citizensnpcs/npc/CitizensTraitFactory.java index d71ed8c9c..237c8ddca 100644 --- a/main/src/main/java/net/citizensnpcs/npc/CitizensTraitFactory.java +++ b/main/src/main/java/net/citizensnpcs/npc/CitizensTraitFactory.java @@ -24,6 +24,7 @@ import net.citizensnpcs.trait.Age; import net.citizensnpcs.trait.Anchors; import net.citizensnpcs.trait.ArmorStandTrait; import net.citizensnpcs.trait.AttributeTrait; +import net.citizensnpcs.trait.BatTrait; import net.citizensnpcs.trait.BoatTrait; import net.citizensnpcs.trait.BoundingBoxTrait; import net.citizensnpcs.trait.ClickRedirectTrait; @@ -80,6 +81,7 @@ public class CitizensTraitFactory implements TraitFactory { registerTrait(TraitInfo.create(ArmorStandTrait.class)); registerTrait(TraitInfo.create(AttributeTrait.class)); registerTrait(TraitInfo.create(Anchors.class)); + registerTrait(TraitInfo.create(BatTrait.class)); registerTrait(TraitInfo.create(BoatTrait.class)); registerTrait(TraitInfo.create(BoundingBoxTrait.class)); registerTrait(TraitInfo.create(ClickRedirectTrait.class)); diff --git a/main/src/main/java/net/citizensnpcs/trait/BatTrait.java b/main/src/main/java/net/citizensnpcs/trait/BatTrait.java new file mode 100644 index 000000000..b826852da --- /dev/null +++ b/main/src/main/java/net/citizensnpcs/trait/BatTrait.java @@ -0,0 +1,32 @@ +package net.citizensnpcs.trait; + +import org.bukkit.entity.Bat; + +import net.citizensnpcs.api.persistence.Persist; +import net.citizensnpcs.api.trait.Trait; +import net.citizensnpcs.api.trait.TraitName; + +@TraitName("battrait") +public class BatTrait extends Trait { + @Persist + private boolean awake; + + public BatTrait() { + super("battrait"); + } + + public boolean isAwake() { + return awake; + } + + @Override + public void run() { + if (!(npc.getEntity() instanceof Bat)) + return; + ((Bat) npc.getEntity()).setAwake(awake); + } + + public void setAwake(boolean awake) { + this.awake = awake; + } +} diff --git a/main/src/main/java/net/citizensnpcs/util/Messages.java b/main/src/main/java/net/citizensnpcs/util/Messages.java index 311f400c3..efcc02988 100644 --- a/main/src/main/java/net/citizensnpcs/util/Messages.java +++ b/main/src/main/java/net/citizensnpcs/util/Messages.java @@ -26,6 +26,8 @@ public class Messages { public static final String AXOLOTL_NOT_PLAYING_DEAD = "citizens.commands.npc.axolotl.playing-dead-stopped"; public static final String AXOLOTL_PLAYING_DEAD = "citizens.commands.npc.axolotl.playing-dead"; public static final String AXOLOTL_VARIANT_SET = "citizens.commands.npc.axolotl.variant-set"; + public static final String BAT_AWAKE_SET = "citizens.commands.npc.bat.awake-set"; + public static final String BAT_AWAKE_UNSET = "citizens.commands.npc.bat.awake-unset"; public static final String BEE_ANGER_SET = "citizens.commands.npc.bee.anger-set"; public static final String BEE_HAS_NECTAR = "citizens.commands.npc.bee.has-nectar"; public static final String BEE_NO_NECTAR = "citizens.commands.npc.bee.no-nectar"; @@ -271,6 +273,7 @@ public class Messages { public static final String MOBTYPE_CANNOT_BE_AGED = "citizens.commands.npc.age.cannot-be-aged"; public static final String MONEY_WITHDRAWN = "citizens.economy.money-withdrawn"; public static final String MOUNT_NPC_MUST_BE_SPAWNED = "citizens.commands.npc.mount.must-be-spawned"; + public static final String MOUNT_TRIED_TO_MOUNT_NPC_ON_ITSELF = "citizens.commands.npc.mount.mount-on-itself"; public static final String MOVETO_FORMAT = "citizens.commands.npc.moveto.format"; public static final String MOVETO_TELEPORTED = "citizens.commands.npc.moveto.teleported"; public static final String MUSHROOM_COW_VARIANT_SET = "citizens.commands.npc.mushroomcow.variant-set"; @@ -426,9 +429,9 @@ public class Messages { public static final String TEXT_EDITOR_RANGE_SET = "citizens.editors.text.range-set"; public static final String TEXT_EDITOR_SET_ITEM = "citizens.editors.text.talk-item-set"; public static final String TEXT_EDITOR_START_PROMPT = "citizens.editors.text.start-prompt"; - public static final String TPTO_ENTITY_NOT_FOUND = "citizens.commands.npc.tpto.to-not-found"; public static final String TOGGLED_USING_HELD_ITEM = "citizens.commands.npc.useitem.held-item-toggled"; public static final String TOGGLED_USING_OFFHAND_ITEM = "citizens.commands.npc.useitem.offhand-item-toggled"; + public static final String TPTO_ENTITY_NOT_FOUND = "citizens.commands.npc.tpto.to-not-found"; public static final String TPTO_SUCCESS = "citizens.commands.npc.tpto.success"; public static final String TRACKING_RANGE_SET = "citizens.commands.npc.trackingrange.set"; public static final String TRAIT_LOAD_FAILED = "citizens.notifications.trait-load-failed"; @@ -436,7 +439,6 @@ public class Messages { public static final String TRAITS_ADDED = "citizens.commands.trait.added"; public static final String TRAITS_FAILED_TO_ADD = "citizens.commands.trait.failed-to-add"; public static final String TRAITS_REMOVED = "citizens.commands.trait.removed"; - public static final String MOUNT_TRIED_TO_MOUNT_NPC_ON_ITSELF = "citizens.commands.npc.mount.mount-on-itself"; public static final String TROPICALFISH_BODY_COLOR_SET = "citizens.commands.npc.tropicalfish.body-color-set"; public static final String TROPICALFISH_PATTERN_COLOR_SET = "citizens.commands.npc.tropicalfish.pattern-color-set"; public static final String TROPICALFISH_PATTERN_SET = "citizens.commands.npc.tropicalfish.pattern-set"; diff --git a/main/src/main/resources/en.json b/main/src/main/resources/en.json index 206c6db74..ba4ec25c4 100644 --- a/main/src/main/resources/en.json +++ b/main/src/main/resources/en.json @@ -24,6 +24,10 @@ "citizens.commands.npc.age.help" : "Can only be used on entities that can become babies. Use the [[-l]] flag to lock age over time (note: relogs may be required to see this).", "citizens.commands.npc.age.invalid-age" : "Invalid age. Valid ages are adult, baby, number between -24000 and 0", "citizens.commands.npc.age.locked" : "Age locked.", + "citizens.commands.npc.bat.awake-set" : "[[{0}]] is now awake.", + "citizens.commands.npc.bat.awake-unset" : "[[{0}]] is no longer awake.", + "citizens.commands.npc.bat.description" : "Set bat modifiers", + "citizens.commands.npc.bat.help" : "", "citizens.commands.npc.forcefield.describe": "[[{0}]] has a forcefield with height [[{1}]], width [[{2}]], strength [[{3}]].", "citizens.commands.npc.forcefield.description": "Creates a forcefield which pushes players close to the NPC away", "citizens.commands.npc.age.set" : "[[{0}]] is now [[{1}]].",