From 5b050aee6c3164ff5b67328e9a34893f9bd5937b Mon Sep 17 00:00:00 2001 From: Pyrbu Date: Wed, 14 Jun 2023 15:30:43 +0200 Subject: [PATCH] major help message improvements --- .../java/lol/pyr/znpcsplus/ZNpcsPlus.java | 21 ++++++++++--------- plugin/src/main/resources/help-message.txt | 5 ----- .../main/resources/help-messages/action.txt | 9 ++++++++ .../src/main/resources/help-messages/holo.txt | 11 ++++++++++ .../src/main/resources/help-messages/root.txt | 20 ++++++++++++++++++ .../main/resources/help-messages/storage.txt | 7 +++++++ 6 files changed, 58 insertions(+), 15 deletions(-) delete mode 100644 plugin/src/main/resources/help-message.txt create mode 100644 plugin/src/main/resources/help-messages/action.txt create mode 100644 plugin/src/main/resources/help-messages/holo.txt create mode 100644 plugin/src/main/resources/help-messages/root.txt create mode 100644 plugin/src/main/resources/help-messages/storage.txt diff --git a/plugin/src/main/java/lol/pyr/znpcsplus/ZNpcsPlus.java b/plugin/src/main/java/lol/pyr/znpcsplus/ZNpcsPlus.java index 983d8fa..86b42e0 100644 --- a/plugin/src/main/java/lol/pyr/znpcsplus/ZNpcsPlus.java +++ b/plugin/src/main/java/lol/pyr/znpcsplus/ZNpcsPlus.java @@ -210,13 +210,7 @@ public class ZNpcsPlus extends JavaPlugin { private void registerCommands(NpcRegistryImpl npcRegistry, SkinCache skinCache, BukkitAudiences adventure, ActionRegistry actionRegistry, NpcTypeRegistryImpl typeRegistry, EntityPropertyRegistryImpl propertyRegistry) { - Reader reader = getTextResource("help-message.txt"); - if (reader == null) throw new RuntimeException("help-message.txt is missing from the ZNpcsPlus jar!"); - Component component = MiniMessage.miniMessage().deserialize(FileUtil.dumpReaderAsString(reader).replace("{version}", this.getDescription().getVersion())); - - Message helpMessage = context -> context.send(component); Message incorrectUsageMessage = context -> context.send(Component.text("Incorrect usage: /" + context.getUsage(), NamedTextColor.RED)); - CommandManager manager = new CommandManager(this, adventure, incorrectUsageMessage); manager.registerParser(NpcTypeImpl.class, new NpcTypeParser(incorrectUsageMessage, typeRegistry)); @@ -228,7 +222,7 @@ public class ZNpcsPlus extends JavaPlugin { manager.registerParser(NamedTextColor.class, new NamedTextColorParser(incorrectUsageMessage)); manager.registerParser(InteractionType.class, new InteractionTypeParser(incorrectUsageMessage)); - manager.registerCommand("npc", new MultiCommand(helpMessage) + manager.registerCommand("npc", new MultiCommand(loadHelpMessage("root")) .addSubcommand("create", new CreateCommand(npcRegistry, typeRegistry)) .addSubcommand("skin", new SkinCommand(skinCache, npcRegistry, typeRegistry, propertyRegistry)) .addSubcommand("delete", new DeleteCommand(npcRegistry, adventure)) @@ -238,21 +232,28 @@ public class ZNpcsPlus extends JavaPlugin { .addSubcommand("list", new ListCommand(npcRegistry)) .addSubcommand("near", new NearCommand(npcRegistry)) .addSubcommand("type", new TypeCommand(npcRegistry, typeRegistry)) - .addSubcommand("storage", new MultiCommand(context -> context.send(Component.text("Incorrect usage: /" + context.getLabel() + " storage ", NamedTextColor.RED))) + .addSubcommand("storage", new MultiCommand(loadHelpMessage("storage")) .addSubcommand("save", new SaveAllCommand(npcRegistry)) .addSubcommand("reload", new LoadAllCommand(npcRegistry))) - .addSubcommand("holo", new MultiCommand(context -> context.send(Component.text("Incorrect usage: /" + context.getLabel() + " holo ", NamedTextColor.RED))) + .addSubcommand("holo", new MultiCommand(loadHelpMessage("holo")) .addSubcommand("add", new HoloAddCommand(npcRegistry, textSerializer)) .addSubcommand("delete", new HoloDeleteCommand(npcRegistry)) .addSubcommand("info", new HoloInfoCommand(npcRegistry)) .addSubcommand("insert", new HoloInsertCommand(npcRegistry, textSerializer)) .addSubcommand("set", new HoloSetCommand(npcRegistry, textSerializer)) .addSubcommand("offset", new HoloOffsetCommand(npcRegistry))) - .addSubcommand("action", new MultiCommand(context -> context.send(Component.text("Incorrect usage: /" + context.getLabel() + " action ", NamedTextColor.RED))) + .addSubcommand("action", new MultiCommand(loadHelpMessage("action")) .addSubcommand("add", new ActionAddCommand(npcRegistry, actionRegistry)) .addSubcommand("delete", new ActionDeleteCommand(npcRegistry)) .addSubcommand("edit", new ActionEditCommand(npcRegistry, actionRegistry)) .addSubcommand("list", new ActionListCommand(npcRegistry))) ); } + + private Message loadHelpMessage(String name) { + Reader reader = getTextResource("help-messages/" + name + ".txt"); + if (reader == null) throw new RuntimeException(name + ".txt is missing from the help-messages folder in the ZNPCsPlus jar!"); + Component component = MiniMessage.miniMessage().deserialize(FileUtil.dumpReaderAsString(reader)); + return context -> context.send(component); + } } diff --git a/plugin/src/main/resources/help-message.txt b/plugin/src/main/resources/help-message.txt deleted file mode 100644 index 111659e..0000000 --- a/plugin/src/main/resources/help-message.txt +++ /dev/null @@ -1,5 +0,0 @@ - -ZNPCsPlus v{version} -Hover over any command for example usage - -TODO diff --git a/plugin/src/main/resources/help-messages/action.txt b/plugin/src/main/resources/help-messages/action.txt new file mode 100644 index 0000000..fe8e62e --- /dev/null +++ b/plugin/src/main/resources/help-messages/action.txt @@ -0,0 +1,9 @@ + +ZNPCsPlus v${version} Click to view the main help message'>[BACK] +Hover over any command for more info + + * /npc action add + * /npc action delete + * /npc action edit + * /npc action list + diff --git a/plugin/src/main/resources/help-messages/holo.txt b/plugin/src/main/resources/help-messages/holo.txt new file mode 100644 index 0000000..677f264 --- /dev/null +++ b/plugin/src/main/resources/help-messages/holo.txt @@ -0,0 +1,11 @@ + +ZNPCsPlus v${version} Click to view the main help message'>[BACK] +Hover over any command more info + + * /npc holo add + * /npc holo delete + * /npc holo set + * /npc holo insert + * /npc holo offset + * /npc holo info + diff --git a/plugin/src/main/resources/help-messages/root.txt b/plugin/src/main/resources/help-messages/root.txt new file mode 100644 index 0000000..674b221 --- /dev/null +++ b/plugin/src/main/resources/help-messages/root.txt @@ -0,0 +1,20 @@ + +ZNPCsPlus v${version} +Hover over any command for more info + + * /npc create + * /npc delete + * /npc list + * /npc type + + * /npc near + * /npc move + * /npc teleport + + * /npc property + * /npc skin + + * Npc hologram commands
Click to view full list'>/npc holo help + * Player interaction commands
Click to view full list'>/npc action help + * Npc data storage commands
Click to view full list'>/npc storage help + diff --git a/plugin/src/main/resources/help-messages/storage.txt b/plugin/src/main/resources/help-messages/storage.txt new file mode 100644 index 0000000..a88f672 --- /dev/null +++ b/plugin/src/main/resources/help-messages/storage.txt @@ -0,0 +1,7 @@ + +ZNPCsPlus v${version} Click to view the main help message'>[BACK] +Hover over any command for more info + + * /npc storage save + * /npc storage reload +