diff --git a/plugin/src/main/java/lol/pyr/znpcsplus/ZNpcsPlus.java b/plugin/src/main/java/lol/pyr/znpcsplus/ZNpcsPlus.java index 1472ade..265fd79 100644 --- a/plugin/src/main/java/lol/pyr/znpcsplus/ZNpcsPlus.java +++ b/plugin/src/main/java/lol/pyr/znpcsplus/ZNpcsPlus.java @@ -13,9 +13,11 @@ import lol.pyr.director.adventure.parse.primitive.DoubleParser; import lol.pyr.director.adventure.parse.primitive.IntegerParser; import lol.pyr.director.common.message.Message; import lol.pyr.znpcsplus.api.NpcApiProvider; +import lol.pyr.znpcsplus.api.interaction.InteractionType; import lol.pyr.znpcsplus.commands.*; import lol.pyr.znpcsplus.commands.action.ActionAddCommand; import lol.pyr.znpcsplus.commands.action.ActionDeleteCommand; +import lol.pyr.znpcsplus.commands.action.ActionEditCommand; import lol.pyr.znpcsplus.commands.action.ActionListCommand; import lol.pyr.znpcsplus.commands.hologram.*; import lol.pyr.znpcsplus.commands.storage.LoadAllCommand; @@ -25,7 +27,6 @@ import lol.pyr.znpcsplus.entity.EntityPropertyImpl; import lol.pyr.znpcsplus.entity.EntityPropertyRegistryImpl; import lol.pyr.znpcsplus.interaction.ActionRegistry; import lol.pyr.znpcsplus.interaction.InteractionPacketListener; -import lol.pyr.znpcsplus.api.interaction.InteractionType; import lol.pyr.znpcsplus.metadata.*; import lol.pyr.znpcsplus.npc.*; import lol.pyr.znpcsplus.packets.*; @@ -117,7 +118,7 @@ public class ZNpcsPlus extends JavaPlugin { log(ChatColor.WHITE + " * Registerring components..."); typeRegistry.registerDefault(packetEvents, propertyRegistry); - actionRegistry.registerTypes(npcRegistry, scheduler, adventure, bungeeConnector, textSerializer); + actionRegistry.registerTypes(scheduler, adventure, bungeeConnector, textSerializer); packetEvents.getEventManager().registerListener(new InteractionPacketListener(userManager, npcRegistry), PacketListenerPriority.MONITOR); new Metrics(this, PLUGIN_ID); pluginManager.registerEvents(new UserListener(userManager), this); @@ -243,8 +244,9 @@ public class ZNpcsPlus extends JavaPlugin { .addSubcommand("set", new HoloSetCommand(npcRegistry, textSerializer)) .addSubcommand("offset", new HoloOffsetCommand(npcRegistry))) .addSubcommand("action", new MultiCommand() - .addSubcommand("add", new ActionAddCommand(actionRegistry)) + .addSubcommand("add", new ActionAddCommand(npcRegistry, actionRegistry)) .addSubcommand("delete", new ActionDeleteCommand(npcRegistry)) + .addSubcommand("edit", new ActionEditCommand(npcRegistry, actionRegistry)) .addSubcommand("list", new ActionListCommand())) ); } diff --git a/plugin/src/main/java/lol/pyr/znpcsplus/commands/action/ActionAddCommand.java b/plugin/src/main/java/lol/pyr/znpcsplus/commands/action/ActionAddCommand.java index e70b8cf..060d316 100644 --- a/plugin/src/main/java/lol/pyr/znpcsplus/commands/action/ActionAddCommand.java +++ b/plugin/src/main/java/lol/pyr/znpcsplus/commands/action/ActionAddCommand.java @@ -5,6 +5,9 @@ import lol.pyr.director.adventure.command.CommandHandler; import lol.pyr.director.common.command.CommandExecutionException; import lol.pyr.znpcsplus.interaction.ActionRegistry; import lol.pyr.znpcsplus.interaction.InteractionCommandHandler; +import lol.pyr.znpcsplus.npc.NpcEntryImpl; +import lol.pyr.znpcsplus.npc.NpcImpl; +import lol.pyr.znpcsplus.npc.NpcRegistryImpl; import net.kyori.adventure.text.Component; import net.kyori.adventure.text.format.NamedTextColor; @@ -13,19 +16,22 @@ import java.util.List; import java.util.stream.Collectors; public class ActionAddCommand implements CommandHandler { + private final NpcRegistryImpl npcRegistry; private final ActionRegistry actionRegistry; - public ActionAddCommand(ActionRegistry actionRegistry) { + public ActionAddCommand(NpcRegistryImpl npcRegistry, ActionRegistry actionRegistry) { + this.npcRegistry = npcRegistry; this.actionRegistry = actionRegistry; } @Override public void run(CommandContext context) throws CommandExecutionException { List commands = actionRegistry.getCommands(); - context.setUsage(context.getLabel() + " action add "); + context.setUsage(context.getLabel() + " action add ..."); + NpcImpl npc = context.parse(NpcEntryImpl.class).getNpc(); String sub = context.popString(); for (InteractionCommandHandler command : commands) if (command.getSubcommandName().equalsIgnoreCase(sub)) { - command.run(context); + command.parse(context, npc); return; } context.send(Component.text("Invalid action type, available action types:\n" + @@ -34,8 +40,10 @@ public class ActionAddCommand implements CommandHandler { @Override public List suggest(CommandContext context) throws CommandExecutionException { + if (context.argSize() == 1) return context.suggestCollection(npcRegistry.getModifiableIds()); List commands = actionRegistry.getCommands(); - if (context.argSize() == 1) return context.suggestStream(commands.stream().map(InteractionCommandHandler::getSubcommandName)); + if (context.argSize() == 2) return context.suggestStream(commands.stream().map(InteractionCommandHandler::getSubcommandName)); + context.popString(); String sub = context.popString(); for (InteractionCommandHandler command : commands) if (command.getSubcommandName().equalsIgnoreCase(sub)) return command.suggest(context); return Collections.emptyList(); diff --git a/plugin/src/main/java/lol/pyr/znpcsplus/commands/action/ActionEditCommand.java b/plugin/src/main/java/lol/pyr/znpcsplus/commands/action/ActionEditCommand.java new file mode 100644 index 0000000..47f7f40 --- /dev/null +++ b/plugin/src/main/java/lol/pyr/znpcsplus/commands/action/ActionEditCommand.java @@ -0,0 +1,64 @@ +package lol.pyr.znpcsplus.commands.action; + +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.interaction.ActionRegistry; +import lol.pyr.znpcsplus.interaction.InteractionAction; +import lol.pyr.znpcsplus.interaction.InteractionCommandHandler; +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 java.util.Collections; +import java.util.List; +import java.util.stream.Collectors; +import java.util.stream.Stream; + +public class ActionEditCommand implements CommandHandler { + private final NpcRegistryImpl npcRegistry; + private final ActionRegistry actionRegistry; + + private InteractionCommandHandler commandHandler = null; + + public ActionEditCommand(NpcRegistryImpl npcRegistry, ActionRegistry actionRegistry) { + this.npcRegistry = npcRegistry; + this.actionRegistry = actionRegistry; + } + + @Override + public void run(CommandContext context) throws CommandExecutionException { + context.setUsage(context.getLabel() + " action edit ..."); + NpcEntryImpl entry = context.parse(NpcEntryImpl.class); + int index = context.parse(Integer.class); + if (index >= entry.getNpc().getActions().size() || index < 0) context.halt(Component.text("That npc doesn't have any action with the index " + index, NamedTextColor.RED)); + List commands = actionRegistry.getCommands(); + String sub = context.popString(); + for (InteractionCommandHandler command : commands) if (command.getSubcommandName().equalsIgnoreCase(sub)) { + this.commandHandler = command; + } + if (this.commandHandler == null) { + context.send(Component.text("Invalid action type, available action types:\n" + + commands.stream().map(InteractionCommandHandler::getSubcommandName).collect(Collectors.joining(", ")), NamedTextColor.RED)); + } + InteractionAction newAction = this.commandHandler.parse(context, null); + entry.getNpc().editAction(index, newAction); + context.send(Component.text("Edited action with index " + index + " of Npc " + entry.getId(), 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(Stream.iterate(0, n -> n + 1) + .limit(context.suggestionParse(0, NpcEntryImpl.class).getNpc().getActions().size()) + .map(String::valueOf)); + List commands = actionRegistry.getCommands(); + if (context.argSize() == 3) return context.suggestStream(commands.stream().map(InteractionCommandHandler::getSubcommandName)); + context.popString(); + context.popString(); + String sub = context.popString(); + for (InteractionCommandHandler command : commands) if (command.getSubcommandName().equalsIgnoreCase(sub)) return command.suggest(context); + return Collections.emptyList(); + } +} diff --git a/plugin/src/main/java/lol/pyr/znpcsplus/interaction/ActionRegistry.java b/plugin/src/main/java/lol/pyr/znpcsplus/interaction/ActionRegistry.java index dc135cf..a075c50 100644 --- a/plugin/src/main/java/lol/pyr/znpcsplus/interaction/ActionRegistry.java +++ b/plugin/src/main/java/lol/pyr/znpcsplus/interaction/ActionRegistry.java @@ -4,7 +4,6 @@ import lol.pyr.znpcsplus.interaction.consolecommand.ConsoleCommandActionType; import lol.pyr.znpcsplus.interaction.message.MessageActionType; import lol.pyr.znpcsplus.interaction.playercommand.PlayerCommandActionType; import lol.pyr.znpcsplus.interaction.switchserver.SwitchServerActionType; -import lol.pyr.znpcsplus.npc.NpcRegistryImpl; import lol.pyr.znpcsplus.scheduling.TaskScheduler; import lol.pyr.znpcsplus.util.BungeeConnector; import net.kyori.adventure.platform.bukkit.BukkitAudiences; @@ -22,11 +21,11 @@ public class ActionRegistry { public ActionRegistry() { } - public void registerTypes(NpcRegistryImpl npcRegistry, TaskScheduler taskScheduler, BukkitAudiences adventure, BungeeConnector bungeeConnector, LegacyComponentSerializer textSerializer) { - register(new ConsoleCommandActionType(taskScheduler, npcRegistry)); - register(new PlayerCommandActionType(taskScheduler, npcRegistry)); - register(new SwitchServerActionType(bungeeConnector, npcRegistry)); - register(new MessageActionType(adventure, textSerializer, npcRegistry)); + public void registerTypes(TaskScheduler taskScheduler, BukkitAudiences adventure, BungeeConnector bungeeConnector, LegacyComponentSerializer textSerializer) { + register(new ConsoleCommandActionType(taskScheduler)); + register(new PlayerCommandActionType(taskScheduler)); + register(new SwitchServerActionType(bungeeConnector)); + register(new MessageActionType(adventure, textSerializer)); } public void register(InteractionActionType type) { diff --git a/plugin/src/main/java/lol/pyr/znpcsplus/interaction/InteractionCommandHandler.java b/plugin/src/main/java/lol/pyr/znpcsplus/interaction/InteractionCommandHandler.java index ad704c6..2b07e2a 100644 --- a/plugin/src/main/java/lol/pyr/znpcsplus/interaction/InteractionCommandHandler.java +++ b/plugin/src/main/java/lol/pyr/znpcsplus/interaction/InteractionCommandHandler.java @@ -1,7 +1,12 @@ package lol.pyr.znpcsplus.interaction; +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.NpcImpl; public interface InteractionCommandHandler extends CommandHandler { String getSubcommandName(); + + InteractionAction parse(CommandContext context, NpcImpl npc) throws CommandExecutionException; } diff --git a/plugin/src/main/java/lol/pyr/znpcsplus/interaction/consolecommand/ConsoleCommandActionType.java b/plugin/src/main/java/lol/pyr/znpcsplus/interaction/consolecommand/ConsoleCommandActionType.java index 23f7f86..afed159 100644 --- a/plugin/src/main/java/lol/pyr/znpcsplus/interaction/consolecommand/ConsoleCommandActionType.java +++ b/plugin/src/main/java/lol/pyr/znpcsplus/interaction/consolecommand/ConsoleCommandActionType.java @@ -2,11 +2,11 @@ package lol.pyr.znpcsplus.interaction.consolecommand; import lol.pyr.director.adventure.command.CommandContext; import lol.pyr.director.common.command.CommandExecutionException; +import lol.pyr.znpcsplus.api.interaction.InteractionType; +import lol.pyr.znpcsplus.interaction.InteractionAction; import lol.pyr.znpcsplus.interaction.InteractionActionType; import lol.pyr.znpcsplus.interaction.InteractionCommandHandler; -import lol.pyr.znpcsplus.api.interaction.InteractionType; -import lol.pyr.znpcsplus.npc.NpcEntryImpl; -import lol.pyr.znpcsplus.npc.NpcRegistryImpl; +import lol.pyr.znpcsplus.npc.NpcImpl; import lol.pyr.znpcsplus.scheduling.TaskScheduler; import net.kyori.adventure.text.Component; import net.kyori.adventure.text.format.NamedTextColor; @@ -18,11 +18,9 @@ import java.util.List; public class ConsoleCommandActionType implements InteractionActionType, InteractionCommandHandler { private final TaskScheduler scheduler; - private final NpcRegistryImpl npcRegistry; - public ConsoleCommandActionType(TaskScheduler scheduler, NpcRegistryImpl npcRegistry) { + public ConsoleCommandActionType(TaskScheduler scheduler) { this.scheduler = scheduler; - this.npcRegistry = npcRegistry; } @Override @@ -48,21 +46,28 @@ public class ConsoleCommandActionType implements InteractionActionType "); - NpcEntryImpl entry = context.parse(NpcEntryImpl.class); + public InteractionAction parse(CommandContext context, NpcImpl npc) throws CommandExecutionException { + context.setUsage(context.getUsage() + getSubcommandName() + " "); InteractionType type = context.parse(InteractionType.class); long cooldown = (long) (context.parse(Double.class) * 1000D); String command = context.dumpAllArgs(); - entry.getNpc().addAction(new ConsoleCommandAction(scheduler, command, type, cooldown)); - context.send(Component.text("Added a console command action to the npc with the command " + command, NamedTextColor.GREEN)); + ConsoleCommandAction action = new ConsoleCommandAction(scheduler, command, type, cooldown); + if (npc != null) { + npc.addAction(action); + context.send(Component.text("Added a console command action to the npc with the command " + action.getCommand(), NamedTextColor.GREEN)); + } + return action; + } + + @Override + public void run(CommandContext context) throws CommandExecutionException { + } @Override public List suggest(CommandContext context) throws CommandExecutionException { - if (context.argSize() == 1) return context.suggestCollection(npcRegistry.getModifiableIds()); - if (context.argSize() == 2) return context.suggestEnum(InteractionType.values()); - if (context.argSize() == 3) return context.suggestLiteral("1"); + if (context.argSize() == 1) return context.suggestEnum(InteractionType.values()); + if (context.argSize() == 2) return context.suggestLiteral("1"); return Collections.emptyList(); } } diff --git a/plugin/src/main/java/lol/pyr/znpcsplus/interaction/message/MessageActionType.java b/plugin/src/main/java/lol/pyr/znpcsplus/interaction/message/MessageActionType.java index 64e6e38..010a1b8 100644 --- a/plugin/src/main/java/lol/pyr/znpcsplus/interaction/message/MessageActionType.java +++ b/plugin/src/main/java/lol/pyr/znpcsplus/interaction/message/MessageActionType.java @@ -3,10 +3,10 @@ package lol.pyr.znpcsplus.interaction.message; import lol.pyr.director.adventure.command.CommandContext; import lol.pyr.director.common.command.CommandExecutionException; import lol.pyr.znpcsplus.api.interaction.InteractionType; +import lol.pyr.znpcsplus.interaction.InteractionAction; import lol.pyr.znpcsplus.interaction.InteractionActionType; import lol.pyr.znpcsplus.interaction.InteractionCommandHandler; -import lol.pyr.znpcsplus.npc.NpcEntryImpl; -import lol.pyr.znpcsplus.npc.NpcRegistryImpl; +import lol.pyr.znpcsplus.npc.NpcImpl; import net.kyori.adventure.platform.bukkit.BukkitAudiences; import net.kyori.adventure.text.Component; import net.kyori.adventure.text.format.NamedTextColor; @@ -20,12 +20,10 @@ import java.util.List; public class MessageActionType implements InteractionActionType, InteractionCommandHandler { private final BukkitAudiences adventure; private final LegacyComponentSerializer textSerializer; - private final NpcRegistryImpl npcRegistry; - public MessageActionType(BukkitAudiences adventure, LegacyComponentSerializer textSerializer, NpcRegistryImpl npcRegistry) { + public MessageActionType(BukkitAudiences adventure, LegacyComponentSerializer textSerializer) { this.adventure = adventure; this.textSerializer = textSerializer; - this.npcRegistry = npcRegistry; } @Override @@ -51,21 +49,28 @@ public class MessageActionType implements InteractionActionType, } @Override - public void run(CommandContext context) throws CommandExecutionException { - context.setUsage(context.getUsage() + " message "); - NpcEntryImpl entry = context.parse(NpcEntryImpl.class); + public InteractionAction parse(CommandContext context, NpcImpl npc) throws CommandExecutionException { + context.setUsage(context.getUsage() + " "); InteractionType type = context.parse(InteractionType.class); long cooldown = (long) (context.parse(Double.class) * 1000D); String message = context.dumpAllArgs(); - entry.getNpc().addAction(new MessageAction(adventure, message, type, textSerializer, cooldown)); - context.send(Component.text("Added a message action to the npc with the message ", NamedTextColor.GREEN).append(Component.text(message))); + MessageAction action = new MessageAction(adventure, message, type, textSerializer, cooldown); + if (npc != null) { + npc.addAction(action); + context.send(Component.text("Added a message action to the npc with the message ", NamedTextColor.GREEN).append(Component.text(message))); + } + return action; + } + + @Override + public void run(CommandContext context) throws CommandExecutionException { + } @Override public List suggest(CommandContext context) throws CommandExecutionException { - if (context.argSize() == 1) return context.suggestCollection(npcRegistry.getModifiableIds()); - if (context.argSize() == 2) return context.suggestEnum(InteractionType.values()); - if (context.argSize() == 3) return context.suggestLiteral("1"); + if (context.argSize() == 1) return context.suggestEnum(InteractionType.values()); + if (context.argSize() == 2) return context.suggestLiteral("1"); return Collections.emptyList(); } } diff --git a/plugin/src/main/java/lol/pyr/znpcsplus/interaction/playercommand/PlayerCommandActionType.java b/plugin/src/main/java/lol/pyr/znpcsplus/interaction/playercommand/PlayerCommandActionType.java index 8684c69..a60f6ba 100644 --- a/plugin/src/main/java/lol/pyr/znpcsplus/interaction/playercommand/PlayerCommandActionType.java +++ b/plugin/src/main/java/lol/pyr/znpcsplus/interaction/playercommand/PlayerCommandActionType.java @@ -2,11 +2,11 @@ package lol.pyr.znpcsplus.interaction.playercommand; import lol.pyr.director.adventure.command.CommandContext; import lol.pyr.director.common.command.CommandExecutionException; +import lol.pyr.znpcsplus.api.interaction.InteractionType; +import lol.pyr.znpcsplus.interaction.InteractionAction; import lol.pyr.znpcsplus.interaction.InteractionActionType; import lol.pyr.znpcsplus.interaction.InteractionCommandHandler; -import lol.pyr.znpcsplus.api.interaction.InteractionType; -import lol.pyr.znpcsplus.npc.NpcEntryImpl; -import lol.pyr.znpcsplus.npc.NpcRegistryImpl; +import lol.pyr.znpcsplus.npc.NpcImpl; import lol.pyr.znpcsplus.scheduling.TaskScheduler; import net.kyori.adventure.text.Component; import net.kyori.adventure.text.format.NamedTextColor; @@ -18,11 +18,9 @@ import java.util.List; public class PlayerCommandActionType implements InteractionActionType, InteractionCommandHandler { private final TaskScheduler scheduler; - private final NpcRegistryImpl npcRegistry; - public PlayerCommandActionType(TaskScheduler scheduler, NpcRegistryImpl npcRegistry) { + public PlayerCommandActionType(TaskScheduler scheduler) { this.scheduler = scheduler; - this.npcRegistry = npcRegistry; } @Override @@ -48,21 +46,28 @@ public class PlayerCommandActionType implements InteractionActionType "); - NpcEntryImpl entry = context.parse(NpcEntryImpl.class); + public InteractionAction parse(CommandContext context, NpcImpl npc) throws CommandExecutionException { + context.setUsage(context.getUsage() + getSubcommandName() + " "); InteractionType type = context.parse(InteractionType.class); long cooldown = (long) (context.parse(Double.class) * 1000D); String command = context.dumpAllArgs(); - entry.getNpc().addAction(new PlayerCommandAction(scheduler, command, type, cooldown)); - context.send(Component.text("Added a player command action to the npc with the command " + command, NamedTextColor.GREEN)); + PlayerCommandAction action = new PlayerCommandAction(scheduler, command, type, cooldown); + if (npc != null) { + npc.addAction(action); + context.send(Component.text("Added a player command action to the npc with the command " + action.getCommand(), NamedTextColor.GREEN)); + } + return action; + } + + @Override + public void run(CommandContext context) throws CommandExecutionException { + } @Override public List suggest(CommandContext context) throws CommandExecutionException { - if (context.argSize() == 1) return context.suggestCollection(npcRegistry.getModifiableIds()); - if (context.argSize() == 2) return context.suggestEnum(InteractionType.values()); - if (context.argSize() == 3) return context.suggestLiteral("1"); + if (context.argSize() == 1) return context.suggestEnum(InteractionType.values()); + if (context.argSize() == 2) return context.suggestLiteral("1"); return Collections.emptyList(); } } diff --git a/plugin/src/main/java/lol/pyr/znpcsplus/interaction/switchserver/SwitchServerActionType.java b/plugin/src/main/java/lol/pyr/znpcsplus/interaction/switchserver/SwitchServerActionType.java index 7c598e4..677f648 100644 --- a/plugin/src/main/java/lol/pyr/znpcsplus/interaction/switchserver/SwitchServerActionType.java +++ b/plugin/src/main/java/lol/pyr/znpcsplus/interaction/switchserver/SwitchServerActionType.java @@ -2,11 +2,11 @@ package lol.pyr.znpcsplus.interaction.switchserver; import lol.pyr.director.adventure.command.CommandContext; import lol.pyr.director.common.command.CommandExecutionException; +import lol.pyr.znpcsplus.api.interaction.InteractionType; +import lol.pyr.znpcsplus.interaction.InteractionAction; import lol.pyr.znpcsplus.interaction.InteractionActionType; import lol.pyr.znpcsplus.interaction.InteractionCommandHandler; -import lol.pyr.znpcsplus.api.interaction.InteractionType; -import lol.pyr.znpcsplus.npc.NpcEntryImpl; -import lol.pyr.znpcsplus.npc.NpcRegistryImpl; +import lol.pyr.znpcsplus.npc.NpcImpl; import lol.pyr.znpcsplus.util.BungeeConnector; import net.kyori.adventure.text.Component; import net.kyori.adventure.text.format.NamedTextColor; @@ -18,11 +18,9 @@ import java.util.List; public class SwitchServerActionType implements InteractionActionType, InteractionCommandHandler { private final BungeeConnector bungeeConnector; - private final NpcRegistryImpl npcRegistry; - public SwitchServerActionType(BungeeConnector bungeeConnector, NpcRegistryImpl npcRegistry) { + public SwitchServerActionType(BungeeConnector bungeeConnector) { this.bungeeConnector = bungeeConnector; - this.npcRegistry = npcRegistry; } @Override @@ -48,21 +46,28 @@ public class SwitchServerActionType implements InteractionActionType "); - NpcEntryImpl entry = context.parse(NpcEntryImpl.class); + public InteractionAction parse(CommandContext context, NpcImpl npc) throws CommandExecutionException { + context.setUsage(context.getUsage() +getSubcommandName() + " "); InteractionType type = context.parse(InteractionType.class); long cooldown = (long) (context.parse(Double.class) * 1000D); String server = context.dumpAllArgs(); - entry.getNpc().addAction(new SwitchServerAction(bungeeConnector, server, type, cooldown)); - context.send(Component.text("Added a switch server action to the npc with the server " + server, NamedTextColor.GREEN)); + SwitchServerAction action = new SwitchServerAction(bungeeConnector, server, type, cooldown); + if (npc != null) { + npc.addAction(action); + context.send(Component.text("Added a switch server action to the npc with the server " + action.getServer(), NamedTextColor.GREEN)); + } + return action; + } + + @Override + public void run(CommandContext context) throws CommandExecutionException { + } @Override public List suggest(CommandContext context) throws CommandExecutionException { - if (context.argSize() == 1) return context.suggestCollection(npcRegistry.getModifiableIds()); - if (context.argSize() == 2) return context.suggestEnum(InteractionType.values()); - if (context.argSize() == 3) return context.suggestLiteral("1"); + if (context.argSize() == 1) return context.suggestEnum(InteractionType.values()); + if (context.argSize() == 2) return context.suggestLiteral("1"); return Collections.emptyList(); } } diff --git a/plugin/src/main/java/lol/pyr/znpcsplus/npc/NpcImpl.java b/plugin/src/main/java/lol/pyr/znpcsplus/npc/NpcImpl.java index fa5faad..03e309d 100644 --- a/plugin/src/main/java/lol/pyr/znpcsplus/npc/NpcImpl.java +++ b/plugin/src/main/java/lol/pyr/znpcsplus/npc/NpcImpl.java @@ -146,4 +146,8 @@ public class NpcImpl extends Viewable implements Npc { public void addAction(InteractionAction action) { actions.add(action); } + + public void editAction(int index, InteractionAction action) { + actions.set(index, action); + } }