From 191eae3778f4c8284d06a6edb536efafe0d6374c Mon Sep 17 00:00:00 2001 From: Pyrbu Date: Thu, 11 May 2023 07:27:28 +0100 Subject: [PATCH] improve holo commands --- .../java/lol/pyr/znpcsplus/ZNpcsPlus.java | 7 +++++-- .../commands/ConversationsCommand.java | 20 ------------------- .../pyr/znpcsplus/commands/PathCommand.java | 20 ------------------- .../commands/hologram/HoloAddCommand.java | 4 ++-- .../commands/hologram/HoloDeleteCommand.java | 2 +- .../commands/hologram/HoloInsertCommand.java | 6 +++--- .../commands/hologram/HoloSetCommand.java | 14 ++++++++----- 7 files changed, 20 insertions(+), 53 deletions(-) delete mode 100644 plugin/src/main/java/lol/pyr/znpcsplus/commands/ConversationsCommand.java delete mode 100644 plugin/src/main/java/lol/pyr/znpcsplus/commands/PathCommand.java diff --git a/plugin/src/main/java/lol/pyr/znpcsplus/ZNpcsPlus.java b/plugin/src/main/java/lol/pyr/znpcsplus/ZNpcsPlus.java index d0d5e3b..3aef95a 100644 --- a/plugin/src/main/java/lol/pyr/znpcsplus/ZNpcsPlus.java +++ b/plugin/src/main/java/lol/pyr/znpcsplus/ZNpcsPlus.java @@ -41,6 +41,7 @@ import lol.pyr.znpcsplus.util.ZLocation; import net.kyori.adventure.platform.bukkit.BukkitAudiences; import net.kyori.adventure.text.Component; import net.kyori.adventure.text.format.NamedTextColor; +import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer; import org.apache.commons.io.FileUtils; import org.bstats.bukkit.Metrics; import org.bukkit.Bukkit; @@ -63,6 +64,10 @@ public class ZNpcsPlus extends JavaPlugin { public static TaskScheduler SCHEDULER; public static BungeeUtil BUNGEE_UTIL; public static BukkitAudiences ADVENTURE; + public static LegacyComponentSerializer LEGACY_AMPERSAND_SERIALIZER = LegacyComponentSerializer.builder() + .character('&') + .hexCharacter('#') + .hexColors().build(); private boolean enabled = false; public static final String DEBUG_NPC_PREFIX = "debug_npc"; @@ -205,11 +210,9 @@ public class ZNpcsPlus extends JavaPlugin { manager.registerCommand("npc", new MultiCommand() .addSubcommand("action", new ActionCommand()) - .addSubcommand("conversations", new ConversationsCommand()) .addSubcommand("create", new CreateCommand()) .addSubcommand("delete", new DeleteCommand()) .addSubcommand("move", new MoveCommand()) - .addSubcommand("path", new PathCommand()) .addSubcommand("properties", new PropertiesCommand()) .addSubcommand("teleport", new TeleportCommand()) .addSubcommand("list", new ListCommand()) diff --git a/plugin/src/main/java/lol/pyr/znpcsplus/commands/ConversationsCommand.java b/plugin/src/main/java/lol/pyr/znpcsplus/commands/ConversationsCommand.java deleted file mode 100644 index d809b3b..0000000 --- a/plugin/src/main/java/lol/pyr/znpcsplus/commands/ConversationsCommand.java +++ /dev/null @@ -1,20 +0,0 @@ -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.Collections; -import java.util.List; - -public class ConversationsCommand implements CommandHandler { - @Override - public void run(CommandContext context) throws CommandExecutionException { - context.send("Not implemented yet."); - } - - @Override - public List suggest(CommandContext context) throws CommandExecutionException { - return Collections.emptyList(); - } -} diff --git a/plugin/src/main/java/lol/pyr/znpcsplus/commands/PathCommand.java b/plugin/src/main/java/lol/pyr/znpcsplus/commands/PathCommand.java deleted file mode 100644 index 55d1b79..0000000 --- a/plugin/src/main/java/lol/pyr/znpcsplus/commands/PathCommand.java +++ /dev/null @@ -1,20 +0,0 @@ -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.Collections; -import java.util.List; - -public class PathCommand implements CommandHandler { - @Override - public void run(CommandContext context) throws CommandExecutionException { - context.send("Not implemented yet."); - } - - @Override - public List suggest(CommandContext context) throws CommandExecutionException { - return Collections.emptyList(); - } -} diff --git a/plugin/src/main/java/lol/pyr/znpcsplus/commands/hologram/HoloAddCommand.java b/plugin/src/main/java/lol/pyr/znpcsplus/commands/hologram/HoloAddCommand.java index 74dd866..a9d3069 100644 --- a/plugin/src/main/java/lol/pyr/znpcsplus/commands/hologram/HoloAddCommand.java +++ b/plugin/src/main/java/lol/pyr/znpcsplus/commands/hologram/HoloAddCommand.java @@ -3,12 +3,12 @@ package lol.pyr.znpcsplus.commands.hologram; 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.HologramImpl; 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 net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer; import java.util.Collections; import java.util.List; @@ -18,7 +18,7 @@ public class HoloAddCommand implements CommandHandler { public void run(CommandContext context) throws CommandExecutionException { context.setUsage(context.getLabel() + " holo add "); HologramImpl hologram = context.parse(NpcEntryImpl.class).getNpc().getHologram(); - hologram.addLine(LegacyComponentSerializer.legacyAmpersand().deserialize(context.dumpAllArgs())); + hologram.addLine(ZNpcsPlus.LEGACY_AMPERSAND_SERIALIZER.deserialize(context.dumpAllArgs())); context.send(Component.text("NPC line added!", NamedTextColor.GREEN)); } diff --git a/plugin/src/main/java/lol/pyr/znpcsplus/commands/hologram/HoloDeleteCommand.java b/plugin/src/main/java/lol/pyr/znpcsplus/commands/hologram/HoloDeleteCommand.java index de5a95e..be5e2e3 100644 --- a/plugin/src/main/java/lol/pyr/znpcsplus/commands/hologram/HoloDeleteCommand.java +++ b/plugin/src/main/java/lol/pyr/znpcsplus/commands/hologram/HoloDeleteCommand.java @@ -28,7 +28,7 @@ public class HoloDeleteCommand implements CommandHandler { public List suggest(CommandContext context) throws CommandExecutionException { if (context.argSize() == 1) return context.suggestCollection(NpcRegistryImpl.get().modifiableIds()); if (context.argSize() == 2) return context.suggestStream(Stream.iterate(0, n -> n + 1) - .limit(context.suggestionParse(1, NpcEntryImpl.class).getNpc().getHologram().getLines().size()) + .limit(context.suggestionParse(0, NpcEntryImpl.class).getNpc().getHologram().getLines().size()) .map(String::valueOf)); return Collections.emptyList(); } diff --git a/plugin/src/main/java/lol/pyr/znpcsplus/commands/hologram/HoloInsertCommand.java b/plugin/src/main/java/lol/pyr/znpcsplus/commands/hologram/HoloInsertCommand.java index 590c1c3..f1e8853 100644 --- a/plugin/src/main/java/lol/pyr/znpcsplus/commands/hologram/HoloInsertCommand.java +++ b/plugin/src/main/java/lol/pyr/znpcsplus/commands/hologram/HoloInsertCommand.java @@ -3,12 +3,12 @@ package lol.pyr.znpcsplus.commands.hologram; 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.HologramImpl; 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 net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer; import java.util.Collections; import java.util.List; @@ -21,7 +21,7 @@ public class HoloInsertCommand implements CommandHandler { HologramImpl hologram = context.parse(NpcEntryImpl.class).getNpc().getHologram(); int line = context.parse(Integer.class); if (line < 0 || line >= hologram.getLines().size()) context.halt(Component.text("Invalid line number!", NamedTextColor.RED)); - hologram.insertLine(line, LegacyComponentSerializer.legacyAmpersand().deserialize(context.dumpAllArgs())); + hologram.insertLine(line, ZNpcsPlus.LEGACY_AMPERSAND_SERIALIZER.deserialize(context.dumpAllArgs())); context.send(Component.text("NPC line inserted!", NamedTextColor.GREEN)); } @@ -29,7 +29,7 @@ public class HoloInsertCommand implements CommandHandler { public List suggest(CommandContext context) throws CommandExecutionException { if (context.argSize() == 1) return context.suggestCollection(NpcRegistryImpl.get().modifiableIds()); if (context.argSize() == 2) return context.suggestStream(Stream.iterate(0, n -> n + 1) - .limit(context.suggestionParse(1, NpcEntryImpl.class).getNpc().getHologram().getLines().size()) + .limit(context.suggestionParse(0, NpcEntryImpl.class).getNpc().getHologram().getLines().size()) .map(String::valueOf)); return Collections.emptyList(); } diff --git a/plugin/src/main/java/lol/pyr/znpcsplus/commands/hologram/HoloSetCommand.java b/plugin/src/main/java/lol/pyr/znpcsplus/commands/hologram/HoloSetCommand.java index daf4781..c02bc81 100644 --- a/plugin/src/main/java/lol/pyr/znpcsplus/commands/hologram/HoloSetCommand.java +++ b/plugin/src/main/java/lol/pyr/znpcsplus/commands/hologram/HoloSetCommand.java @@ -3,12 +3,12 @@ package lol.pyr.znpcsplus.commands.hologram; 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.HologramImpl; 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 net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer; import java.util.Collections; import java.util.List; @@ -22,16 +22,20 @@ public class HoloSetCommand implements CommandHandler { int line = context.parse(Integer.class); if (line < 0 || line >= hologram.getLines().size()) context.halt(Component.text("Invalid line number!", NamedTextColor.RED)); hologram.removeLine(line); - hologram.insertLine(line, LegacyComponentSerializer.legacyAmpersand().deserialize(context.dumpAllArgs())); + hologram.insertLine(line, ZNpcsPlus.LEGACY_AMPERSAND_SERIALIZER.deserialize(context.dumpAllArgs())); context.send(Component.text("NPC line set!", NamedTextColor.GREEN)); } @Override public List suggest(CommandContext context) throws CommandExecutionException { if (context.argSize() == 1) return context.suggestCollection(NpcRegistryImpl.get().modifiableIds()); - if (context.argSize() == 2) return context.suggestStream(Stream.iterate(0, n -> n + 1) - .limit(context.suggestionParse(1, NpcEntryImpl.class).getNpc().getHologram().getLines().size()) - .map(String::valueOf)); + if (context.argSize() >= 2) { + HologramImpl hologram = context.suggestionParse(0, NpcEntryImpl.class).getNpc().getHologram(); + if (context.argSize() == 2) return context.suggestStream(Stream.iterate(0, n -> n + 1) + .limit(hologram.getLines().size()).map(String::valueOf)); + if (context.argSize() == 3) return context.suggestLiteral(ZNpcsPlus.LEGACY_AMPERSAND_SERIALIZER.serialize( + hologram.getLine(context.suggestionParse(1, Integer.class)))); + } return Collections.emptyList(); } }