From 80e7ac82f7d33c5e22572017f27f1f57c8761563 Mon Sep 17 00:00:00 2001 From: D3v1s0m <49519439+D3v1s0m@users.noreply.github.com> Date: Fri, 12 May 2023 19:18:46 +0530 Subject: [PATCH] add type command --- .../java/lol/pyr/znpcsplus/ZNpcsPlus.java | 1 + .../pyr/znpcsplus/commands/TypeCommand.java | 32 +++++++++++++++++++ 2 files changed, 33 insertions(+) create mode 100644 plugin/src/main/java/lol/pyr/znpcsplus/commands/TypeCommand.java diff --git a/plugin/src/main/java/lol/pyr/znpcsplus/ZNpcsPlus.java b/plugin/src/main/java/lol/pyr/znpcsplus/ZNpcsPlus.java index ad30d04..30ab377 100644 --- a/plugin/src/main/java/lol/pyr/znpcsplus/ZNpcsPlus.java +++ b/plugin/src/main/java/lol/pyr/znpcsplus/ZNpcsPlus.java @@ -199,6 +199,7 @@ public class ZNpcsPlus extends JavaPlugin { .addSubcommand("teleport", new TeleportCommand()) .addSubcommand("list", new ListCommand()) .addSubcommand("near", new NearCommand()) + .addSubcommand("type", new TypeCommand()) .addSubcommand("storage", new MultiCommand() .addSubcommand("save", new SaveAllCommand()) .addSubcommand("load", new LoadAllCommand())) diff --git a/plugin/src/main/java/lol/pyr/znpcsplus/commands/TypeCommand.java b/plugin/src/main/java/lol/pyr/znpcsplus/commands/TypeCommand.java new file mode 100644 index 0000000..17c9c50 --- /dev/null +++ b/plugin/src/main/java/lol/pyr/znpcsplus/commands/TypeCommand.java @@ -0,0 +1,32 @@ +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.npc.NpcTypeImpl; +import net.kyori.adventure.text.Component; +import net.kyori.adventure.text.format.NamedTextColor; + +import java.util.Collections; +import java.util.List; + +public class TypeCommand implements CommandHandler { + @Override + public void run(CommandContext context) throws CommandExecutionException { + context.setUsage(context.getLabel() + " type "); + NpcImpl npc = context.parse(NpcEntryImpl.class).getNpc(); + NpcTypeImpl type = context.parse(NpcTypeImpl.class); + npc.setType(type); + context.send(Component.text("NPC type set to " + type.getName() + ".", 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(NpcTypeImpl.values().stream().map(NpcTypeImpl::getName)); + return Collections.emptyList(); + } +}