From bbd34f343eaca70d8bc1e884243e3e7a4ad16e7b Mon Sep 17 00:00:00 2001 From: D3v1s0m Date: Thu, 30 May 2024 00:05:09 +0530 Subject: [PATCH] fix clone command --- .../main/java/lol/pyr/znpcsplus/ZNpcsPlus.java | 1 + .../pyr/znpcsplus/commands/CloneCommand.java | 18 +++++++----------- 2 files changed, 8 insertions(+), 11 deletions(-) diff --git a/plugin/src/main/java/lol/pyr/znpcsplus/ZNpcsPlus.java b/plugin/src/main/java/lol/pyr/znpcsplus/ZNpcsPlus.java index 21b879c..00b0aa1 100644 --- a/plugin/src/main/java/lol/pyr/znpcsplus/ZNpcsPlus.java +++ b/plugin/src/main/java/lol/pyr/znpcsplus/ZNpcsPlus.java @@ -282,6 +282,7 @@ public class ZNpcsPlus { manager.registerCommand("npc", new MultiCommand(bootstrap.loadHelpMessage("root")) .addSubcommand("center", new CenterCommand(npcRegistry)) .addSubcommand("create", new CreateCommand(npcRegistry, typeRegistry)) + .addSubcommand("clone", new CloneCommand(npcRegistry)) .addSubcommand("reloadconfig", new ReloadConfigCommand(configManager)) .addSubcommand("toggle", new ToggleCommand(npcRegistry)) .addSubcommand("skin", new SkinCommand(skinCache, npcRegistry, typeRegistry, propertyRegistry)) diff --git a/plugin/src/main/java/lol/pyr/znpcsplus/commands/CloneCommand.java b/plugin/src/main/java/lol/pyr/znpcsplus/commands/CloneCommand.java index de1ceaa..eb9d001 100644 --- a/plugin/src/main/java/lol/pyr/znpcsplus/commands/CloneCommand.java +++ b/plugin/src/main/java/lol/pyr/znpcsplus/commands/CloneCommand.java @@ -5,7 +5,6 @@ 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.NpcRegistryImpl; -import lol.pyr.znpcsplus.npc.NpcTypeImpl; import lol.pyr.znpcsplus.npc.NpcTypeRegistryImpl; import lol.pyr.znpcsplus.util.NpcLocation; import net.kyori.adventure.text.Component; @@ -17,32 +16,29 @@ import java.util.List; public class CloneCommand implements CommandHandler { private final NpcRegistryImpl npcRegistry; - private final NpcTypeRegistryImpl typeRegistry; - public CloneCommand(NpcRegistryImpl npcRegistry, NpcTypeRegistryImpl typeRegistry) { + public CloneCommand(NpcRegistryImpl npcRegistry) { this.npcRegistry = npcRegistry; - this.typeRegistry = typeRegistry; } @Override public void run(CommandContext context) throws CommandExecutionException { - context.setUsage(context.getLabel() + " create "); + context.setUsage(context.getLabel() + " clone "); 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); + if (npcRegistry.getById(id) == null) context.halt(Component.text("NPC with ID " + id + " does not exist.", NamedTextColor.RED)); + String newId = context.popString(); + if (npcRegistry.getById(newId) != null) context.halt(Component.text("NPC with ID " + newId + " already exists.", NamedTextColor.RED)); - NpcEntryImpl entry = npcRegistry.create(id, player.getWorld(), type, new NpcLocation(player.getLocation())); - entry.enableEverything(); + npcRegistry.clone(id, newId, player.getWorld(), new NpcLocation(player.getLocation())); - context.send(Component.text("Created a " + type.getName() + " NPC with ID " + id + ".", NamedTextColor.GREEN)); + context.send(Component.text("Cloned NPC with ID " + id + " to ID " + newId + ".", NamedTextColor.GREEN)); } @Override public List suggest(CommandContext context) throws CommandExecutionException { if (context.argSize() == 1) return context.suggestCollection(npcRegistry.getModifiableIds()); - if (context.argSize() == 2) return context.suggestStream(typeRegistry.getAllImpl().stream().map(NpcTypeImpl::getName)); return Collections.emptyList(); } }