From fa69b22ac9cdb0677797d992e55ed0652b06ba69 Mon Sep 17 00:00:00 2001 From: Pyrbu Date: Sat, 21 Oct 2023 07:08:29 +0200 Subject: [PATCH] more position commands (resolves #81) --- .../java/lol/pyr/znpcsplus/ZNpcsPlus.java | 5 +++ .../znpcsplus/commands/LookAtMeCommand.java | 37 ++++++++++++++++++ .../commands/SetLocationCommand.java | 39 +++++++++++++++++++ .../commands/SetRotationCommand.java | 38 ++++++++++++++++++ .../src/main/resources/help-messages/root.txt | 3 ++ 5 files changed, 122 insertions(+) create mode 100644 plugin/src/main/java/lol/pyr/znpcsplus/commands/LookAtMeCommand.java create mode 100644 plugin/src/main/java/lol/pyr/znpcsplus/commands/SetLocationCommand.java create mode 100644 plugin/src/main/java/lol/pyr/znpcsplus/commands/SetRotationCommand.java diff --git a/plugin/src/main/java/lol/pyr/znpcsplus/ZNpcsPlus.java b/plugin/src/main/java/lol/pyr/znpcsplus/ZNpcsPlus.java index ce2700d..6efcf33 100644 --- a/plugin/src/main/java/lol/pyr/znpcsplus/ZNpcsPlus.java +++ b/plugin/src/main/java/lol/pyr/znpcsplus/ZNpcsPlus.java @@ -10,6 +10,7 @@ import lol.pyr.director.adventure.command.CommandManager; import lol.pyr.director.adventure.command.MultiCommand; import lol.pyr.director.adventure.parse.primitive.BooleanParser; import lol.pyr.director.adventure.parse.primitive.DoubleParser; +import lol.pyr.director.adventure.parse.primitive.FloatParser; import lol.pyr.director.adventure.parse.primitive.IntegerParser; import lol.pyr.director.common.message.Message; import lol.pyr.znpcsplus.api.NpcApiProvider; @@ -243,6 +244,7 @@ public class ZNpcsPlus { manager.registerParser(EntityPropertyImpl.class, new EntityPropertyParser(incorrectUsageMessage, propertyRegistry)); manager.registerParser(Integer.class, new IntegerParser(incorrectUsageMessage)); manager.registerParser(Double.class, new DoubleParser(incorrectUsageMessage)); + manager.registerParser(Float.class, new FloatParser(incorrectUsageMessage)); manager.registerParser(Boolean.class, new BooleanParser(incorrectUsageMessage)); manager.registerParser(NamedTextColor.class, new NamedTextColorParser(incorrectUsageMessage)); manager.registerParser(InteractionType.class, new InteractionTypeParser(incorrectUsageMessage)); @@ -291,6 +293,9 @@ public class ZNpcsPlus { .addSubcommand("list", new ListCommand(npcRegistry)) .addSubcommand("near", new NearCommand(npcRegistry)) .addSubcommand("type", new TypeCommand(npcRegistry, typeRegistry)) + .addSubcommand("setlocation", new SetLocationCommand(npcRegistry)) + .addSubcommand("lookatme", new LookAtMeCommand(npcRegistry)) + .addSubcommand("setrotation", new SetRotationCommand(npcRegistry)) .addSubcommand("property", new MultiCommand(bootstrap.loadHelpMessage("property")) .addSubcommand("set", new PropertySetCommand(npcRegistry)) .addSubcommand("remove", new PropertyRemoveCommand(npcRegistry))) diff --git a/plugin/src/main/java/lol/pyr/znpcsplus/commands/LookAtMeCommand.java b/plugin/src/main/java/lol/pyr/znpcsplus/commands/LookAtMeCommand.java new file mode 100644 index 0000000..d95a146 --- /dev/null +++ b/plugin/src/main/java/lol/pyr/znpcsplus/commands/LookAtMeCommand.java @@ -0,0 +1,37 @@ +package lol.pyr.znpcsplus.commands; + +import lol.pyr.director.adventure.command.CommandContext; +import lol.pyr.director.adventure.command.CommandHandler; +import lol.pyr.director.common.command.CommandExecutionException; +import lol.pyr.znpcsplus.npc.NpcEntryImpl; +import lol.pyr.znpcsplus.npc.NpcImpl; +import lol.pyr.znpcsplus.npc.NpcRegistryImpl; +import net.kyori.adventure.text.Component; +import net.kyori.adventure.text.format.NamedTextColor; +import org.bukkit.entity.Player; + +import java.util.Collections; +import java.util.List; + +public class LookAtMeCommand implements CommandHandler { + private final NpcRegistryImpl npcRegistry; + + public LookAtMeCommand(NpcRegistryImpl npcRegistry) { + this.npcRegistry = npcRegistry; + } + + @Override + public void run(CommandContext context) throws CommandExecutionException { + context.setUsage(context.getLabel() + " lookatme "); + Player player = context.ensureSenderIsPlayer(); + NpcImpl npc = context.parse(NpcEntryImpl.class).getNpc(); + npc.setLocation(npc.getLocation().lookingAt(player.getLocation())); + context.send(Component.text("NPC is now looking at you.", NamedTextColor.GREEN)); + } + + @Override + public List suggest(CommandContext context) throws CommandExecutionException { + if (context.argSize() == 1) return context.suggestCollection(npcRegistry.getModifiableIds()); + return Collections.emptyList(); + } +} diff --git a/plugin/src/main/java/lol/pyr/znpcsplus/commands/SetLocationCommand.java b/plugin/src/main/java/lol/pyr/znpcsplus/commands/SetLocationCommand.java new file mode 100644 index 0000000..91cde48 --- /dev/null +++ b/plugin/src/main/java/lol/pyr/znpcsplus/commands/SetLocationCommand.java @@ -0,0 +1,39 @@ +package lol.pyr.znpcsplus.commands; + +import lol.pyr.director.adventure.command.CommandContext; +import lol.pyr.director.adventure.command.CommandHandler; +import lol.pyr.director.common.command.CommandExecutionException; +import lol.pyr.znpcsplus.npc.NpcEntryImpl; +import lol.pyr.znpcsplus.npc.NpcImpl; +import lol.pyr.znpcsplus.npc.NpcRegistryImpl; +import lol.pyr.znpcsplus.util.NpcLocation; +import net.kyori.adventure.text.Component; +import net.kyori.adventure.text.format.NamedTextColor; + +import java.util.Collections; +import java.util.List; + +public class SetLocationCommand implements CommandHandler { + private final NpcRegistryImpl npcRegistry; + + public SetLocationCommand(NpcRegistryImpl npcRegistry) { + this.npcRegistry = npcRegistry; + } + + @Override + public void run(CommandContext context) throws CommandExecutionException { + context.setUsage(context.getLabel() + " setlocation "); + NpcImpl npc = context.parse(NpcEntryImpl.class).getNpc(); + double x = context.parse(Double.class); + double y = context.parse(Double.class); + double z = context.parse(Double.class); + npc.setLocation(new NpcLocation(x, y, z, npc.getLocation().getYaw(), npc.getLocation().getPitch())); + context.send(Component.text("NPC has been moved to " + x + ", " + y + ", " + z + ".", NamedTextColor.GREEN)); + } + + @Override + public List suggest(CommandContext context) throws CommandExecutionException { + if (context.argSize() == 1) return context.suggestCollection(npcRegistry.getModifiableIds()); + return Collections.emptyList(); + } +} diff --git a/plugin/src/main/java/lol/pyr/znpcsplus/commands/SetRotationCommand.java b/plugin/src/main/java/lol/pyr/znpcsplus/commands/SetRotationCommand.java new file mode 100644 index 0000000..99cb7ff --- /dev/null +++ b/plugin/src/main/java/lol/pyr/znpcsplus/commands/SetRotationCommand.java @@ -0,0 +1,38 @@ +package lol.pyr.znpcsplus.commands; + +import lol.pyr.director.adventure.command.CommandContext; +import lol.pyr.director.adventure.command.CommandHandler; +import lol.pyr.director.common.command.CommandExecutionException; +import lol.pyr.znpcsplus.npc.NpcEntryImpl; +import lol.pyr.znpcsplus.npc.NpcImpl; +import lol.pyr.znpcsplus.npc.NpcRegistryImpl; +import lol.pyr.znpcsplus.util.NpcLocation; +import net.kyori.adventure.text.Component; +import net.kyori.adventure.text.format.NamedTextColor; + +import java.util.Collections; +import java.util.List; + +public class SetRotationCommand implements CommandHandler { + private final NpcRegistryImpl npcRegistry; + + public SetRotationCommand(NpcRegistryImpl npcRegistry) { + this.npcRegistry = npcRegistry; + } + + @Override + public void run(CommandContext context) throws CommandExecutionException { + context.setUsage(context.getLabel() + " setrotation "); + NpcImpl npc = context.parse(NpcEntryImpl.class).getNpc(); + float yaw = context.parse(Float.class); + float pitch = context.parse(Float.class); + npc.setLocation(new NpcLocation(npc.getLocation().getX(), npc.getLocation().getY(), npc.getLocation().getZ(), yaw, pitch)); + context.send(Component.text("NPC has been rotated to " + yaw + ", " + pitch + ".", NamedTextColor.GREEN)); + } + + @Override + public List suggest(CommandContext context) throws CommandExecutionException { + if (context.argSize() == 1) return context.suggestCollection(npcRegistry.getModifiableIds()); + return Collections.emptyList(); + } +} diff --git a/plugin/src/main/resources/help-messages/root.txt b/plugin/src/main/resources/help-messages/root.txt index 4030145..70ff31f 100644 --- a/plugin/src/main/resources/help-messages/root.txt +++ b/plugin/src/main/resources/help-messages/root.txt @@ -10,6 +10,9 @@ * /npc near * /npc center + * /npc lookatme + * /npc setlocation + * /npc setrotation * /npc move * /npc teleport