From c7020f73a49611ab8c0e24df5fa6ddce1d512a20 Mon Sep 17 00:00:00 2001 From: Om Choksi <–49519439+D3v1s0m@users.noreply.github.com> Date: Tue, 9 May 2023 16:17:43 +0530 Subject: [PATCH] command it --- plugin/build.gradle | 2 +- .../java/lol/pyr/znpcsplus/ZNpcsPlus.java | 27 +++++-- .../pyr/znpcsplus/command/CreateCommand.java | 14 ---- .../pyr/znpcsplus/commands/ActionCommand.java | 20 ++++++ .../commands/ConversationsCommand.java | 19 +++++ .../pyr/znpcsplus/commands/CreateCommand.java | 72 +++++++++++++++++++ .../pyr/znpcsplus/commands/DeleteCommand.java | 39 ++++++++++ .../znpcsplus/commands/HoloAddCommand.java | 43 +++++++++++ .../znpcsplus/commands/HoloDeleteCommand.java | 55 ++++++++++++++ .../znpcsplus/commands/HoloInfoCommand.java | 53 ++++++++++++++ .../znpcsplus/commands/HoloInsertCommand.java | 57 +++++++++++++++ .../znpcsplus/commands/HoloSetCommand.java | 58 +++++++++++++++ .../pyr/znpcsplus/commands/ListCommand.java | 45 ++++++++++++ .../pyr/znpcsplus/commands/MoveCommand.java | 46 ++++++++++++ .../pyr/znpcsplus/commands/PathCommand.java | 19 +++++ .../znpcsplus/commands/PropertiesCommand.java | 19 +++++ .../znpcsplus/commands/TeleportCommand.java | 44 ++++++++++++ 17 files changed, 613 insertions(+), 19 deletions(-) delete mode 100644 plugin/src/main/java/lol/pyr/znpcsplus/command/CreateCommand.java create mode 100644 plugin/src/main/java/lol/pyr/znpcsplus/commands/ActionCommand.java create mode 100644 plugin/src/main/java/lol/pyr/znpcsplus/commands/ConversationsCommand.java create mode 100644 plugin/src/main/java/lol/pyr/znpcsplus/commands/CreateCommand.java create mode 100644 plugin/src/main/java/lol/pyr/znpcsplus/commands/DeleteCommand.java create mode 100644 plugin/src/main/java/lol/pyr/znpcsplus/commands/HoloAddCommand.java create mode 100644 plugin/src/main/java/lol/pyr/znpcsplus/commands/HoloDeleteCommand.java create mode 100644 plugin/src/main/java/lol/pyr/znpcsplus/commands/HoloInfoCommand.java create mode 100644 plugin/src/main/java/lol/pyr/znpcsplus/commands/HoloInsertCommand.java create mode 100644 plugin/src/main/java/lol/pyr/znpcsplus/commands/HoloSetCommand.java create mode 100644 plugin/src/main/java/lol/pyr/znpcsplus/commands/ListCommand.java create mode 100644 plugin/src/main/java/lol/pyr/znpcsplus/commands/MoveCommand.java create mode 100644 plugin/src/main/java/lol/pyr/znpcsplus/commands/PathCommand.java create mode 100644 plugin/src/main/java/lol/pyr/znpcsplus/commands/PropertiesCommand.java create mode 100644 plugin/src/main/java/lol/pyr/znpcsplus/commands/TeleportCommand.java diff --git a/plugin/build.gradle b/plugin/build.gradle index 0fdd0e5..f872efa 100644 --- a/plugin/build.gradle +++ b/plugin/build.gradle @@ -28,7 +28,7 @@ dependencies { implementation "com.github.retrooper.packetevents:spigot:2.0.0-SNAPSHOT" implementation "space.arim.dazzleconf:dazzleconf-ext-snakeyaml:1.2.1" - implementation "lol.pyr:director-adventure:2.0.2" + implementation "lol.pyr:director-adventure:2.0.4" implementation project(":api") } diff --git a/plugin/src/main/java/lol/pyr/znpcsplus/ZNpcsPlus.java b/plugin/src/main/java/lol/pyr/znpcsplus/ZNpcsPlus.java index d573d16..0fdd8bb 100644 --- a/plugin/src/main/java/lol/pyr/znpcsplus/ZNpcsPlus.java +++ b/plugin/src/main/java/lol/pyr/znpcsplus/ZNpcsPlus.java @@ -7,6 +7,7 @@ import io.github.retrooper.packetevents.factory.spigot.SpigotPacketEventsBuilder import lol.pyr.director.adventure.command.CommandManager; import lol.pyr.director.adventure.command.MultiCommand; import lol.pyr.znpcsplus.api.ZApiProvider; +import lol.pyr.znpcsplus.commands.*; import lol.pyr.znpcsplus.entity.EntityPropertyImpl; import lol.pyr.znpcsplus.npc.NpcTypeImpl; import lol.pyr.znpcsplus.config.Configs; @@ -57,6 +58,7 @@ public class ZNpcsPlus extends JavaPlugin { public static boolean PLACEHOLDERS_SUPPORTED; private boolean enabled = false; + public static final String DEBUG_NPC_PREFIX = "debug_npc"; public static void debug(String str) { if (!Configs.config().debugEnabled()) return; @@ -144,7 +146,7 @@ public class ZNpcsPlus extends JavaPlugin { World world = Bukkit.getWorld("world"); if (world == null) world = Bukkit.getWorlds().get(0); for (NpcTypeImpl type : NpcTypeImpl.values()) { - NpcEntryImpl entry = NpcRegistryImpl.get().create("debug_npc" + (z * wrap + x), world, type, new ZLocation(x * 3, 200, z * 3, 0, 0)); + NpcEntryImpl entry = NpcRegistryImpl.get().create(ZNpcsPlus.DEBUG_NPC_PREFIX + (z * wrap + x), world, type, new ZLocation(x * 3, 200, z * 3, 0, 0)); entry.setProcessed(true); NpcImpl npc = entry.getNpc(); if (type.getType() == EntityTypes.PLAYER) { @@ -159,13 +161,13 @@ public class ZNpcsPlus extends JavaPlugin { z++; } } - NpcEntryImpl entry = NpcRegistryImpl.get().create("debug_npc" + (z * wrap + x), world, NpcTypeImpl.byName("player"), new ZLocation(x * 3, 200, z * 3, 0, 0)); + NpcEntryImpl entry = NpcRegistryImpl.get().create(ZNpcsPlus.DEBUG_NPC_PREFIX + (z * wrap + x), world, NpcTypeImpl.byName("player"), new ZLocation(x * 3, 200, z * 3, 0, 0)); entry.setProcessed(true); NpcImpl npc = entry.getNpc(); npc.setProperty(EntityPropertyImpl.SKIN, new FetchingDescriptor("jeb_")); npc.addAction(new MessageAction(1000L, "Hi, I'm jeb!")); x++; - entry = NpcRegistryImpl.get().create("debug_npc" + (z * wrap + x), world, NpcTypeImpl.byName("player"), new ZLocation(x * 3, 200, z * 3, 0, 0)); + entry = NpcRegistryImpl.get().create(ZNpcsPlus.DEBUG_NPC_PREFIX + (z * wrap + x), world, NpcTypeImpl.byName("player"), new ZLocation(x * 3, 200, z * 3, 0, 0)); entry.setProcessed(true); npc = entry.getNpc(); npc.setProperty(EntityPropertyImpl.SKIN, new MirrorDescriptor()); @@ -184,6 +186,23 @@ public class ZNpcsPlus extends JavaPlugin { private void registerCommands() { CommandManager manager = new CommandManager(this, ADVENTURE, context -> {}); - manager.registerCommand("npc", new MultiCommand()); + manager.registerCommand("npc", new MultiCommand() + .addSubcommand("action", new ActionCommand()) + .addSubcommand("conversations", new ConversationsCommand()) + .addSubcommand("create", new CreateCommand()) + .addSubcommand("delete", new DeleteCommand()) + .addSubcommand("holo", new MultiCommand() + .addSubcommand("add", new HoloAddCommand()) + .addSubcommand("delete", new HoloDeleteCommand()) + .addSubcommand("info", new HoloInfoCommand()) + .addSubcommand("insert", new HoloInsertCommand()) + .addSubcommand("set", new HoloSetCommand()) + ) + .addSubcommand("list", new ListCommand()) + .addSubcommand("move", new MoveCommand()) + .addSubcommand("path", new PathCommand()) + .addSubcommand("properties", new PropertiesCommand()) + .addSubcommand("teleport", new TeleportCommand()) + ); } } diff --git a/plugin/src/main/java/lol/pyr/znpcsplus/command/CreateCommand.java b/plugin/src/main/java/lol/pyr/znpcsplus/command/CreateCommand.java deleted file mode 100644 index d127831..0000000 --- a/plugin/src/main/java/lol/pyr/znpcsplus/command/CreateCommand.java +++ /dev/null @@ -1,14 +0,0 @@ -package lol.pyr.znpcsplus.command; - -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.NpcRegistryImpl; - -public class CreateCommand implements CommandHandler { - @Override - public void run(CommandContext context) throws CommandExecutionException { - String id = context.popString(); - NpcRegistryImpl.get().get(id); - } -} diff --git a/plugin/src/main/java/lol/pyr/znpcsplus/commands/ActionCommand.java b/plugin/src/main/java/lol/pyr/znpcsplus/commands/ActionCommand.java new file mode 100644 index 0000000..0475f9a --- /dev/null +++ b/plugin/src/main/java/lol/pyr/znpcsplus/commands/ActionCommand.java @@ -0,0 +1,20 @@ +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 java.util.List; + +public class ActionCommand implements CommandHandler { + + @Override + public void run(CommandContext commandContext) throws CommandExecutionException { + commandContext.getSender().sendMessage("Not implemented yet."); + } + + @Override + public List suggest(CommandContext context) throws CommandExecutionException { + return CommandHandler.super.suggest(context); + } +} diff --git a/plugin/src/main/java/lol/pyr/znpcsplus/commands/ConversationsCommand.java b/plugin/src/main/java/lol/pyr/znpcsplus/commands/ConversationsCommand.java new file mode 100644 index 0000000..bedb154 --- /dev/null +++ b/plugin/src/main/java/lol/pyr/znpcsplus/commands/ConversationsCommand.java @@ -0,0 +1,19 @@ +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 java.util.List; + +public class ConversationsCommand implements CommandHandler { + @Override + public void run(CommandContext commandContext) throws CommandExecutionException { + commandContext.getSender().sendMessage("Not implemented yet."); + } + + @Override + public List suggest(CommandContext context) throws CommandExecutionException { + return CommandHandler.super.suggest(context); + } +} diff --git a/plugin/src/main/java/lol/pyr/znpcsplus/commands/CreateCommand.java b/plugin/src/main/java/lol/pyr/znpcsplus/commands/CreateCommand.java new file mode 100644 index 0000000..cfe31a5 --- /dev/null +++ b/plugin/src/main/java/lol/pyr/znpcsplus/commands/CreateCommand.java @@ -0,0 +1,72 @@ +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.ZNpcsPlus; +import lol.pyr.znpcsplus.entity.EntityPropertyImpl; +import lol.pyr.znpcsplus.npc.NpcEntryImpl; +import lol.pyr.znpcsplus.npc.NpcImpl; +import lol.pyr.znpcsplus.npc.NpcRegistryImpl; +import lol.pyr.znpcsplus.npc.NpcTypeImpl; +import lol.pyr.znpcsplus.skin.descriptor.FetchingDescriptor; +import lol.pyr.znpcsplus.util.ZLocation; +import net.kyori.adventure.text.Component; +import net.kyori.adventure.text.format.NamedTextColor; +import org.bukkit.entity.Player; + +import java.util.List; +import java.util.stream.Collectors; + +public class CreateCommand implements CommandHandler { + @Override + public void run(CommandContext context) throws CommandExecutionException { + if (!(context.getSender() instanceof Player)) { + ZNpcsPlus.ADVENTURE.sender(context.getSender()).sendMessage(Component.text("Only players can use this command.", NamedTextColor.RED)); + return; + } + Player player = (Player) context.getSender(); + if (context.argSize() < 3) { + ZNpcsPlus.ADVENTURE.player(player).sendMessage(Component.text("Usage: /npc create ", NamedTextColor.RED)); + return; + } + String npcId = context.popString(); + if (npcId.toLowerCase().startsWith(ZNpcsPlus.DEBUG_NPC_PREFIX)) { + ZNpcsPlus.ADVENTURE.player(player).sendMessage(Component.text("You can not create an Npc with that ID", NamedTextColor.RED)); + return; + } + NpcEntryImpl npcEntry = NpcRegistryImpl.get().get(npcId); + if (npcEntry != null) { + ZNpcsPlus.ADVENTURE.player(player).sendMessage(Component.text("NPC with that ID already exists.", NamedTextColor.RED)); + return; + } + NpcTypeImpl npcType = NpcTypeImpl.byName(context.popString().toUpperCase()); + if (npcType == null) { + ZNpcsPlus.ADVENTURE.player(player).sendMessage(Component.text("Invalid NPC type.", NamedTextColor.RED)); + return; + } + String npcName = context.popString(); + NpcEntryImpl npcEntry1 = NpcRegistryImpl.get().create(npcId, player.getWorld(), npcType, new ZLocation(player.getLocation())); + npcEntry1.enableEverything(); + NpcImpl npc = npcEntry1.getNpc(); + if (npcType == NpcTypeImpl.PLAYER) { + npc.setProperty(EntityPropertyImpl.SKIN, new FetchingDescriptor(npcName)); + } + npc.getHologram().addLine(Component.text(npcName)); + ZNpcsPlus.ADVENTURE.player(player).sendMessage(Component.text("Created NPC with ID " + npcId + " and name " + npcName + ".", NamedTextColor.GREEN)); + } + + @Override + public List suggest(CommandContext context) throws CommandExecutionException { + if (context.argSize() == 1) { + return context.suggestLiteral(""); + } + if (context.argSize() == 2) { + return context.suggestCollection(NpcTypeImpl.values().stream().map(NpcTypeImpl::getName).collect(Collectors.toList())); + } + if (context.argSize() == 3) { + return context.suggestLiteral(""); + } + return CommandHandler.super.suggest(context); + } +} diff --git a/plugin/src/main/java/lol/pyr/znpcsplus/commands/DeleteCommand.java b/plugin/src/main/java/lol/pyr/znpcsplus/commands/DeleteCommand.java new file mode 100644 index 0000000..27a3519 --- /dev/null +++ b/plugin/src/main/java/lol/pyr/znpcsplus/commands/DeleteCommand.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.ZNpcsPlus; +import lol.pyr.znpcsplus.npc.NpcEntryImpl; +import lol.pyr.znpcsplus.npc.NpcRegistryImpl; +import net.kyori.adventure.text.Component; +import net.kyori.adventure.text.format.NamedTextColor; + +import java.util.List; +import java.util.stream.Collectors; + +public class DeleteCommand implements CommandHandler { + @Override + public void run(CommandContext context) throws CommandExecutionException { + if (context.argSize() != 1) { + ZNpcsPlus.ADVENTURE.sender(context.getSender()).sendMessage(Component.text("Usage: /npc delete ", NamedTextColor.RED)); + return; + } + String id = context.popString(); + NpcEntryImpl npcEntry = NpcRegistryImpl.get().get(id); + if (npcEntry == null) { + ZNpcsPlus.ADVENTURE.sender(context.getSender()).sendMessage(Component.text("NPC not found!", NamedTextColor.RED)); + return; + } + NpcRegistryImpl.get().delete(id); + ZNpcsPlus.ADVENTURE.sender(context.getSender()).sendMessage(Component.text("Deleted NPC with ID: " + id, NamedTextColor.GREEN)); + } + + @Override + public List suggest(CommandContext context) throws CommandExecutionException { + if (context.argSize() == 1) { + return context.suggestCollection(NpcRegistryImpl.get().ids().stream().filter(s -> !s.startsWith(ZNpcsPlus.DEBUG_NPC_PREFIX)).collect(Collectors.toList())); + } + return CommandHandler.super.suggest(context); + } +} diff --git a/plugin/src/main/java/lol/pyr/znpcsplus/commands/HoloAddCommand.java b/plugin/src/main/java/lol/pyr/znpcsplus/commands/HoloAddCommand.java new file mode 100644 index 0000000..1ca10dc --- /dev/null +++ b/plugin/src/main/java/lol/pyr/znpcsplus/commands/HoloAddCommand.java @@ -0,0 +1,43 @@ +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.ZNpcsPlus; +import lol.pyr.znpcsplus.npc.NpcEntryImpl; +import lol.pyr.znpcsplus.npc.NpcRegistryImpl; +import net.kyori.adventure.text.Component; +import net.kyori.adventure.text.format.NamedTextColor; + +import java.util.List; +import java.util.stream.Collectors; +import java.util.stream.Stream; + +public class HoloAddCommand implements CommandHandler { + @Override + public void run(CommandContext commandContext) throws CommandExecutionException { + if (commandContext.argSize() < 2) { + ZNpcsPlus.ADVENTURE.sender(commandContext.getSender()).sendMessage(Component.text("Usage: /npc holo add ", NamedTextColor.RED)); + return; + } + String id = commandContext.popString(); + NpcEntryImpl npcEntry = NpcRegistryImpl.get().get(id); + if (npcEntry == null) { + ZNpcsPlus.ADVENTURE.sender(commandContext.getSender()).sendMessage(Component.text("NPC not found!", NamedTextColor.RED)); + return; + } + npcEntry.getNpc().getHologram().addLine(Component.text(commandContext.dumpAllArgs())); + ZNpcsPlus.ADVENTURE.sender(commandContext.getSender()).sendMessage(Component.text("NPC line added!", NamedTextColor.GREEN)); + } + + @Override + public List suggest(CommandContext context) throws CommandExecutionException { + if (context.argSize() == 1) { + return context.suggestCollection(NpcRegistryImpl.get().ids().stream().filter(s -> !s.startsWith(ZNpcsPlus.DEBUG_NPC_PREFIX)).collect(Collectors.toList())); + } + if (context.argSize() == 2) { + return context.suggestStream(Stream.of("")); + } + return CommandHandler.super.suggest(context); + } +} diff --git a/plugin/src/main/java/lol/pyr/znpcsplus/commands/HoloDeleteCommand.java b/plugin/src/main/java/lol/pyr/znpcsplus/commands/HoloDeleteCommand.java new file mode 100644 index 0000000..c61f45a --- /dev/null +++ b/plugin/src/main/java/lol/pyr/znpcsplus/commands/HoloDeleteCommand.java @@ -0,0 +1,55 @@ +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.ZNpcsPlus; +import lol.pyr.znpcsplus.npc.NpcEntryImpl; +import lol.pyr.znpcsplus.npc.NpcRegistryImpl; +import net.kyori.adventure.text.Component; +import net.kyori.adventure.text.format.NamedTextColor; + +import java.util.List; +import java.util.stream.Collectors; +import java.util.stream.Stream; + +public class HoloDeleteCommand implements CommandHandler { + @Override + public void run(CommandContext commandContext) throws CommandExecutionException { + if (commandContext.argSize() < 2) { + ZNpcsPlus.ADVENTURE.sender(commandContext.getSender()).sendMessage(Component.text("Usage: /npc holo delete ", NamedTextColor.RED)); + return; + } + String id = commandContext.popString(); + NpcEntryImpl npcEntry = NpcRegistryImpl.get().get(id); + if (npcEntry == null) { + ZNpcsPlus.ADVENTURE.sender(commandContext.getSender()).sendMessage(Component.text("NPC not found!", NamedTextColor.RED)); + return; + } + int line; + try { + line = Integer.parseInt(commandContext.popString()); + } catch (NumberFormatException e) { + ZNpcsPlus.ADVENTURE.sender(commandContext.getSender()).sendMessage(Component.text("Invalid line number!", NamedTextColor.RED)); + return; + } + if (line < 0 || line >= npcEntry.getNpc().getHologram().getLines().size()) { + ZNpcsPlus.ADVENTURE.sender(commandContext.getSender()).sendMessage(Component.text("Invalid line number!", NamedTextColor.RED)); + return; + } + npcEntry.getNpc().getHologram().removeLine(line); + ZNpcsPlus.ADVENTURE.sender(commandContext.getSender()).sendMessage(Component.text("NPC line removed!", NamedTextColor.GREEN)); + } + + @Override + public List suggest(CommandContext context) throws CommandExecutionException { + if (context.argSize() == 1) { + return context.suggestCollection(NpcRegistryImpl.get().ids().stream().filter(s -> !s.startsWith(ZNpcsPlus.DEBUG_NPC_PREFIX)).collect(Collectors.toList())); + } + if (context.argSize() == 2) { + int lines = NpcRegistryImpl.get().get(context.popString()).getNpc().getHologram().getLines().size(); + return context.suggestStream(Stream.iterate(0, n -> n + 1).limit(lines).map(String::valueOf)); + } + return CommandHandler.super.suggest(context); + } +} diff --git a/plugin/src/main/java/lol/pyr/znpcsplus/commands/HoloInfoCommand.java b/plugin/src/main/java/lol/pyr/znpcsplus/commands/HoloInfoCommand.java new file mode 100644 index 0000000..50e660c --- /dev/null +++ b/plugin/src/main/java/lol/pyr/znpcsplus/commands/HoloInfoCommand.java @@ -0,0 +1,53 @@ +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.ZNpcsPlus; +import lol.pyr.znpcsplus.hologram.HologramLine; +import lol.pyr.znpcsplus.npc.NpcEntryImpl; +import lol.pyr.znpcsplus.npc.NpcRegistryImpl; +import net.kyori.adventure.text.Component; +import net.kyori.adventure.text.TextComponent; +import net.kyori.adventure.text.format.NamedTextColor; +import org.bukkit.entity.Player; + +import java.util.List; +import java.util.stream.Collectors; + +public class HoloInfoCommand implements CommandHandler { + @Override + public void run(CommandContext commandContext) throws CommandExecutionException { + if (!(commandContext.getSender() instanceof Player)) { + commandContext.getSender().sendMessage("Only players can use this command!"); + return; + } + Player player = (Player) commandContext.getSender(); + if (commandContext.argSize() < 1) { + ZNpcsPlus.ADVENTURE.player(player).sendMessage(Component.text("Usage: /npc holo info ", NamedTextColor.RED)); + return; + } + String id = commandContext.popString(); + NpcEntryImpl npcEntry = NpcRegistryImpl.get().get(id); + if (npcEntry == null) { + ZNpcsPlus.ADVENTURE.player(player).sendMessage(Component.text("NPC not found!", NamedTextColor.RED)); + return; + } + List lines = npcEntry.getNpc().getHologram().getLines(); + TextComponent component = Component.text("NPC Hologram Info of ID " + npcEntry.getId() + ":", NamedTextColor.GREEN); + component = component.append(Component.newline()); + for (HologramLine line : lines) { + component = component.append(line.getText()); + component = component.append(Component.newline()); + } + ZNpcsPlus.ADVENTURE.player(player).sendMessage(component); + } + + @Override + public List suggest(CommandContext context) throws CommandExecutionException { + if (context.argSize() == 1) { + return context.suggestCollection(NpcRegistryImpl.get().ids().stream().filter(s -> !s.startsWith(ZNpcsPlus.DEBUG_NPC_PREFIX)).collect(Collectors.toList())); + } + return CommandHandler.super.suggest(context); + } +} diff --git a/plugin/src/main/java/lol/pyr/znpcsplus/commands/HoloInsertCommand.java b/plugin/src/main/java/lol/pyr/znpcsplus/commands/HoloInsertCommand.java new file mode 100644 index 0000000..c5622bd --- /dev/null +++ b/plugin/src/main/java/lol/pyr/znpcsplus/commands/HoloInsertCommand.java @@ -0,0 +1,57 @@ +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.ZNpcsPlus; +import lol.pyr.znpcsplus.npc.NpcEntryImpl; +import lol.pyr.znpcsplus.npc.NpcRegistryImpl; +import net.kyori.adventure.text.Component; +import net.kyori.adventure.text.format.NamedTextColor; + +import java.util.List; +import java.util.stream.Collectors; +import java.util.stream.Stream; + +public class HoloInsertCommand implements CommandHandler { + @Override + public void run(CommandContext commandContext) throws CommandExecutionException { + if (commandContext.argSize() < 3) { + ZNpcsPlus.ADVENTURE.sender(commandContext.getSender()).sendMessage(Component.text("Usage: /npc holo insert ", NamedTextColor.RED)); + return; + } + String id = commandContext.popString(); + NpcEntryImpl npcEntry = NpcRegistryImpl.get().get(id); + if (npcEntry == null) { + ZNpcsPlus.ADVENTURE.sender(commandContext.getSender()).sendMessage(Component.text("NPC not found!", NamedTextColor.RED)); + return; + } + int line; + try { + line = Integer.parseInt(commandContext.popString()); + } catch (NumberFormatException e) { + ZNpcsPlus.ADVENTURE.sender(commandContext.getSender()).sendMessage(Component.text("Invalid line number!", NamedTextColor.RED)); + return; + } + if (line < 0 || line >= npcEntry.getNpc().getHologram().getLines().size()) { + ZNpcsPlus.ADVENTURE.sender(commandContext.getSender()).sendMessage(Component.text("Invalid line number!", NamedTextColor.RED)); + } + npcEntry.getNpc().getHologram().insertLine(line, Component.text(commandContext.dumpAllArgs())); + ZNpcsPlus.ADVENTURE.sender(commandContext.getSender()).sendMessage(Component.text("NPC line inserted!", NamedTextColor.GREEN)); + } + + @Override + public List suggest(CommandContext context) throws CommandExecutionException { + if (context.argSize() == 1) { + return context.suggestCollection(NpcRegistryImpl.get().ids().stream().filter(s -> !s.startsWith(ZNpcsPlus.DEBUG_NPC_PREFIX)).collect(Collectors.toList())); + } + if (context.argSize() == 2) { + int lines = NpcRegistryImpl.get().get(context.popString()).getNpc().getHologram().getLines().size(); + return context.suggestStream(Stream.iterate(0, n -> n + 1).limit(lines).map(String::valueOf)); + } + if (context.argSize() == 3) { + return context.suggestStream(Stream.of("")); + } + return CommandHandler.super.suggest(context); + } +} diff --git a/plugin/src/main/java/lol/pyr/znpcsplus/commands/HoloSetCommand.java b/plugin/src/main/java/lol/pyr/znpcsplus/commands/HoloSetCommand.java new file mode 100644 index 0000000..add49e3 --- /dev/null +++ b/plugin/src/main/java/lol/pyr/znpcsplus/commands/HoloSetCommand.java @@ -0,0 +1,58 @@ +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.ZNpcsPlus; +import lol.pyr.znpcsplus.npc.NpcEntryImpl; +import lol.pyr.znpcsplus.npc.NpcRegistryImpl; +import net.kyori.adventure.text.Component; +import net.kyori.adventure.text.format.NamedTextColor; + +import java.util.List; +import java.util.stream.Collectors; +import java.util.stream.Stream; + +public class HoloSetCommand implements CommandHandler { + @Override + public void run(CommandContext commandContext) throws CommandExecutionException { + if (commandContext.argSize() < 2) { + ZNpcsPlus.ADVENTURE.sender(commandContext.getSender()).sendMessage(Component.text("Usage: /npc holo set ", NamedTextColor.RED)); + return; + } + String id = commandContext.popString(); + NpcEntryImpl npcEntry = NpcRegistryImpl.get().get(id); + if (npcEntry == null) { + ZNpcsPlus.ADVENTURE.sender(commandContext.getSender()).sendMessage(Component.text("NPC not found!", NamedTextColor.RED)); + return; + } + int line; + try { + line = Integer.parseInt(commandContext.popString()); + } catch (NumberFormatException e) { + ZNpcsPlus.ADVENTURE.sender(commandContext.getSender()).sendMessage(Component.text("Invalid line number!", NamedTextColor.RED)); + return; + } + if (line < 0 || line >= npcEntry.getNpc().getHologram().getLines().size()) { + ZNpcsPlus.ADVENTURE.sender(commandContext.getSender()).sendMessage(Component.text("Invalid line number!", NamedTextColor.RED)); + } + npcEntry.getNpc().getHologram().removeLine(line); + npcEntry.getNpc().getHologram().insertLine(line, Component.text(commandContext.dumpAllArgs())); + ZNpcsPlus.ADVENTURE.sender(commandContext.getSender()).sendMessage(Component.text("NPC line set!", NamedTextColor.GREEN)); + } + + @Override + public List suggest(CommandContext context) throws CommandExecutionException { + if (context.argSize() == 1) { + return context.suggestCollection(NpcRegistryImpl.get().ids().stream().filter(s -> !s.startsWith(ZNpcsPlus.DEBUG_NPC_PREFIX)).collect(Collectors.toList())); + } + if (context.argSize() == 2) { + int lines = NpcRegistryImpl.get().get(context.popString()).getNpc().getHologram().getLines().size(); + return context.suggestStream(Stream.iterate(0, n -> n + 1).limit(lines).map(String::valueOf)); + } + if (context.argSize() == 3) { + return context.suggestStream(Stream.of("")); + } + return CommandHandler.super.suggest(context); + } +} diff --git a/plugin/src/main/java/lol/pyr/znpcsplus/commands/ListCommand.java b/plugin/src/main/java/lol/pyr/znpcsplus/commands/ListCommand.java new file mode 100644 index 0000000..121a62b --- /dev/null +++ b/plugin/src/main/java/lol/pyr/znpcsplus/commands/ListCommand.java @@ -0,0 +1,45 @@ +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.ZNpcsPlus; +import lol.pyr.znpcsplus.npc.NpcEntryImpl; +import lol.pyr.znpcsplus.npc.NpcRegistryImpl; +import net.kyori.adventure.text.Component; +import net.kyori.adventure.text.TextComponent; +import net.kyori.adventure.text.event.ClickEvent; +import net.kyori.adventure.text.format.NamedTextColor; +import org.bukkit.Location; + +import java.util.List; + +public class ListCommand implements CommandHandler { + + @Override + public void run(CommandContext commandContext) throws CommandExecutionException { + TextComponent.Builder component = Component.text("Npc's:\n").color(NamedTextColor.GOLD).toBuilder(); + for (String id : lol.pyr.znpcsplus.npc.NpcRegistryImpl.get().ids().stream().filter(s -> !s.startsWith(ZNpcsPlus.DEBUG_NPC_PREFIX)).toArray(String[]::new)) { + NpcEntryImpl npcEntry = NpcRegistryImpl.get().get(id); + Location location = npcEntry.getNpc().getLocation().toBukkitLocation(npcEntry.getNpc().getWorld()); + component.append(Component.text("ID: " + id, NamedTextColor.GREEN)) + .append(Component.text(" | ", NamedTextColor.GRAY)) + .append(Component.text("Type: ", NamedTextColor.GREEN)) + .append(Component.text(npcEntry.getNpc().getType().getName(), NamedTextColor.GREEN)) + .append(Component.text(" | ", NamedTextColor.GRAY)) + .append(Component.text("Name: ", NamedTextColor.GREEN)) + .append(npcEntry.getNpc().getHologram().getLine(0).color(NamedTextColor.GREEN)) + .append(Component.text(" | ", NamedTextColor.GRAY)) + .append(Component.text("Location: " + npcEntry.getNpc().getWorld().getName() + " X:" + location.getBlockX() + " Y:" + location.getBlockY() + " Z:" + location.getBlockZ(), NamedTextColor.GREEN)) + .append(Component.text(" | ", NamedTextColor.GRAY)) + .append(Component.text("[TELEPORT]", NamedTextColor.DARK_GREEN).clickEvent(ClickEvent.runCommand("/npc teleport " + id))) + .append(Component.text("\n", NamedTextColor.GRAY)); + } + ZNpcsPlus.ADVENTURE.sender(commandContext.getSender()).sendMessage(component.build()); + } + + @Override + public List suggest(CommandContext context) throws CommandExecutionException { + return CommandHandler.super.suggest(context); + } +} diff --git a/plugin/src/main/java/lol/pyr/znpcsplus/commands/MoveCommand.java b/plugin/src/main/java/lol/pyr/znpcsplus/commands/MoveCommand.java new file mode 100644 index 0000000..e0b982c --- /dev/null +++ b/plugin/src/main/java/lol/pyr/znpcsplus/commands/MoveCommand.java @@ -0,0 +1,46 @@ +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.ZNpcsPlus; +import lol.pyr.znpcsplus.npc.NpcEntryImpl; +import lol.pyr.znpcsplus.npc.NpcRegistryImpl; +import lol.pyr.znpcsplus.util.ZLocation; +import net.kyori.adventure.text.Component; +import net.kyori.adventure.text.format.NamedTextColor; +import org.bukkit.entity.Player; + +import java.util.List; +import java.util.stream.Collectors; + +public class MoveCommand implements CommandHandler { + @Override + public void run(CommandContext commandContext) throws CommandExecutionException { + if (!(commandContext.getSender() instanceof Player)) { + commandContext.getSender().sendMessage("Only players can use this command!"); + return; + } + Player player = (Player) commandContext.getSender(); + if (commandContext.argSize() == 0) { + ZNpcsPlus.ADVENTURE.player(player).sendMessage(Component.text("Usage: /npc ", NamedTextColor.RED)); + return; + } + NpcEntryImpl npcEntry = NpcRegistryImpl.get().get(commandContext.popString()); + if (npcEntry == null) { + ZNpcsPlus.ADVENTURE.player(player).sendMessage(Component.text("NPC not found!", NamedTextColor.RED)); + return; + } + npcEntry.getNpc().setLocation(new ZLocation(player.getLocation())); + npcEntry.getNpc().respawn(); + ZNpcsPlus.ADVENTURE.player(player).sendMessage(Component.text("NPC moved!", NamedTextColor.GREEN)); + } + + @Override + public List suggest(CommandContext context) throws CommandExecutionException { + if (context.argSize() == 1) { + return context.suggestCollection(NpcRegistryImpl.get().ids().stream().filter(s -> !s.startsWith(ZNpcsPlus.DEBUG_NPC_PREFIX)).collect(Collectors.toList())); + } + return CommandHandler.super.suggest(context); + } +} diff --git a/plugin/src/main/java/lol/pyr/znpcsplus/commands/PathCommand.java b/plugin/src/main/java/lol/pyr/znpcsplus/commands/PathCommand.java new file mode 100644 index 0000000..68a45ad --- /dev/null +++ b/plugin/src/main/java/lol/pyr/znpcsplus/commands/PathCommand.java @@ -0,0 +1,19 @@ +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 java.util.List; + +public class PathCommand implements CommandHandler { + @Override + public void run(CommandContext commandContext) throws CommandExecutionException { + commandContext.getSender().sendMessage("Not implemented yet."); + } + + @Override + public List suggest(CommandContext context) throws CommandExecutionException { + return CommandHandler.super.suggest(context); + } +} diff --git a/plugin/src/main/java/lol/pyr/znpcsplus/commands/PropertiesCommand.java b/plugin/src/main/java/lol/pyr/znpcsplus/commands/PropertiesCommand.java new file mode 100644 index 0000000..124ccc9 --- /dev/null +++ b/plugin/src/main/java/lol/pyr/znpcsplus/commands/PropertiesCommand.java @@ -0,0 +1,19 @@ +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 java.util.List; + +public class PropertiesCommand implements CommandHandler { + @Override + public void run(CommandContext commandContext) throws CommandExecutionException { + commandContext.getSender().sendMessage("Not implemented yet!"); + } + + @Override + public List suggest(CommandContext context) throws CommandExecutionException { + return CommandHandler.super.suggest(context); + } +} diff --git a/plugin/src/main/java/lol/pyr/znpcsplus/commands/TeleportCommand.java b/plugin/src/main/java/lol/pyr/znpcsplus/commands/TeleportCommand.java new file mode 100644 index 0000000..f68082b --- /dev/null +++ b/plugin/src/main/java/lol/pyr/znpcsplus/commands/TeleportCommand.java @@ -0,0 +1,44 @@ +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.ZNpcsPlus; +import lol.pyr.znpcsplus.npc.NpcEntryImpl; +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.List; +import java.util.stream.Collectors; + +public class TeleportCommand implements CommandHandler { + @Override + public void run(CommandContext commandContext) throws CommandExecutionException { + if (!(commandContext.getSender() instanceof Player)) { + commandContext.getSender().sendMessage("Only players can use this command!"); + return; + } + Player player = (Player) commandContext.getSender(); + if (commandContext.argSize() == 0) { + ZNpcsPlus.ADVENTURE.player(player).sendMessage(Component.text("Usage: /npc teleport ", NamedTextColor.RED)); + return; + } + NpcEntryImpl npcEntry = NpcRegistryImpl.get().get(commandContext.popString()); + if (npcEntry == null) { + ZNpcsPlus.ADVENTURE.player(player).sendMessage(Component.text("NPC not found!", NamedTextColor.RED)); + return; + } + player.teleport(npcEntry.getNpc().getLocation().toBukkitLocation(npcEntry.getNpc().getWorld())); + ZNpcsPlus.ADVENTURE.player(player).sendMessage(Component.text("Teleported to NPC!", NamedTextColor.GREEN)); + } + + @Override + public List suggest(CommandContext context) throws CommandExecutionException { + if (context.argSize() == 1) { + return context.suggestCollection(NpcRegistryImpl.get().ids().stream().filter(s -> !s.startsWith(ZNpcsPlus.DEBUG_NPC_PREFIX)).collect(Collectors.toList())); + } + return CommandHandler.super.suggest(context); + } +}