From d1b890a9126632e988b3ac86d75f40928822ef91 Mon Sep 17 00:00:00 2001 From: envizar Date: Sun, 29 Dec 2024 14:13:37 +0300 Subject: [PATCH 1/3] toggle command with arg --- .../lol/pyr/znpcsplus/commands/ToggleCommand.java | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/plugin/src/main/java/lol/pyr/znpcsplus/commands/ToggleCommand.java b/plugin/src/main/java/lol/pyr/znpcsplus/commands/ToggleCommand.java index c6d1c06..764f771 100644 --- a/plugin/src/main/java/lol/pyr/znpcsplus/commands/ToggleCommand.java +++ b/plugin/src/main/java/lol/pyr/znpcsplus/commands/ToggleCommand.java @@ -11,6 +11,7 @@ import net.kyori.adventure.text.format.NamedTextColor; import java.util.Collections; import java.util.List; +import java.util.Set; public class ToggleCommand implements CommandHandler { private final NpcRegistryImpl npcRegistry; @@ -21,9 +22,14 @@ public class ToggleCommand implements CommandHandler { @Override public void run(CommandContext context) throws CommandExecutionException { - context.setUsage(context.getLabel() + " toggle "); + context.setUsage(context.getLabel() + " toggle []"); NpcImpl npc = context.parse(NpcEntryImpl.class).getNpc(); - boolean enabled = !npc.isEnabled(); + boolean enabled; + if (context.argSize() == 1) { + enabled = context.popString().equals("enable"); + } else { + enabled = !npc.isEnabled(); + } npc.setEnabled(enabled); context.send(Component.text("NPC has been " + (enabled ? "enabled" : "disabled"), NamedTextColor.GREEN)); } @@ -31,6 +37,7 @@ public class ToggleCommand implements CommandHandler { @Override public List suggest(CommandContext context) throws CommandExecutionException { if (context.argSize() == 1) return context.suggestCollection(npcRegistry.getModifiableIds()); + if (context.argSize() == 2) return context.suggestLiteral("enable", "disable"); return Collections.emptyList(); } } From dfdcc54313639e0a190e5581dc44368550b18c94 Mon Sep 17 00:00:00 2001 From: envizar Date: Sun, 29 Dec 2024 14:29:17 +0300 Subject: [PATCH 2/3] default type = player in create command --- .../java/lol/pyr/znpcsplus/commands/CreateCommand.java | 10 ++++++++-- .../java/lol/pyr/znpcsplus/commands/ToggleCommand.java | 1 - 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/plugin/src/main/java/lol/pyr/znpcsplus/commands/CreateCommand.java b/plugin/src/main/java/lol/pyr/znpcsplus/commands/CreateCommand.java index 1c3c1e9..341edca 100644 --- a/plugin/src/main/java/lol/pyr/znpcsplus/commands/CreateCommand.java +++ b/plugin/src/main/java/lol/pyr/znpcsplus/commands/CreateCommand.java @@ -26,12 +26,18 @@ public class CreateCommand implements CommandHandler { @Override public void run(CommandContext context) throws CommandExecutionException { - context.setUsage(context.getLabel() + " create "); + context.setUsage(context.getLabel() + " create []"); Player player = context.ensureSenderIsPlayer(); String id = context.popString(); if (npcRegistry.getById(id) != null) context.halt(Component.text("NPC with that ID already exists.", NamedTextColor.RED)); - NpcTypeImpl type = context.parse(NpcTypeImpl.class); + + NpcTypeImpl type; + if (context.argSize() == 1) { + type = context.parse(NpcTypeImpl.class); + } else { + type = typeRegistry.getByName("player"); + } NpcEntryImpl entry = npcRegistry.create(id, player.getWorld(), type, new NpcLocation(player.getLocation())); entry.enableEverything(); diff --git a/plugin/src/main/java/lol/pyr/znpcsplus/commands/ToggleCommand.java b/plugin/src/main/java/lol/pyr/znpcsplus/commands/ToggleCommand.java index 764f771..4b122d6 100644 --- a/plugin/src/main/java/lol/pyr/znpcsplus/commands/ToggleCommand.java +++ b/plugin/src/main/java/lol/pyr/znpcsplus/commands/ToggleCommand.java @@ -11,7 +11,6 @@ import net.kyori.adventure.text.format.NamedTextColor; import java.util.Collections; import java.util.List; -import java.util.Set; public class ToggleCommand implements CommandHandler { private final NpcRegistryImpl npcRegistry; From ec60af7186b43ea8da0c662646ecbc5f04e31815 Mon Sep 17 00:00:00 2001 From: envizar Date: Sun, 29 Dec 2024 14:43:19 +0300 Subject: [PATCH 3/3] This should be equalsIgnoreCase --- .../src/main/java/lol/pyr/znpcsplus/commands/ToggleCommand.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugin/src/main/java/lol/pyr/znpcsplus/commands/ToggleCommand.java b/plugin/src/main/java/lol/pyr/znpcsplus/commands/ToggleCommand.java index 4b122d6..60a09c8 100644 --- a/plugin/src/main/java/lol/pyr/znpcsplus/commands/ToggleCommand.java +++ b/plugin/src/main/java/lol/pyr/znpcsplus/commands/ToggleCommand.java @@ -25,7 +25,7 @@ public class ToggleCommand implements CommandHandler { NpcImpl npc = context.parse(NpcEntryImpl.class).getNpc(); boolean enabled; if (context.argSize() == 1) { - enabled = context.popString().equals("enable"); + enabled = context.popString().equalsIgnoreCase("enable"); } else { enabled = !npc.isEnabled(); }