action clear command

This commit is contained in:
Pyrbu 2023-08-23 12:14:57 +02:00
parent 91c1cc17a5
commit 446761c52c
4 changed files with 43 additions and 4 deletions

@ -15,10 +15,7 @@ import lol.pyr.director.common.message.Message;
import lol.pyr.znpcsplus.api.NpcApiProvider; import lol.pyr.znpcsplus.api.NpcApiProvider;
import lol.pyr.znpcsplus.api.interaction.InteractionType; import lol.pyr.znpcsplus.api.interaction.InteractionType;
import lol.pyr.znpcsplus.commands.*; import lol.pyr.znpcsplus.commands.*;
import lol.pyr.znpcsplus.commands.action.ActionAddCommand; import lol.pyr.znpcsplus.commands.action.*;
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.hologram.*;
import lol.pyr.znpcsplus.commands.property.PropertyRemoveCommand; import lol.pyr.znpcsplus.commands.property.PropertyRemoveCommand;
import lol.pyr.znpcsplus.commands.property.PropertySetCommand; import lol.pyr.znpcsplus.commands.property.PropertySetCommand;
@ -321,6 +318,7 @@ public class ZNpcsPlus extends JavaPlugin {
.addSubcommand("refreshdelay", new HoloRefreshDelayCommand(npcRegistry))) .addSubcommand("refreshdelay", new HoloRefreshDelayCommand(npcRegistry)))
.addSubcommand("action", new MultiCommand(loadHelpMessage("action")) .addSubcommand("action", new MultiCommand(loadHelpMessage("action"))
.addSubcommand("add", new ActionAddCommand(npcRegistry, actionRegistry)) .addSubcommand("add", new ActionAddCommand(npcRegistry, actionRegistry))
.addSubcommand("clear", new ActionClearCommand(npcRegistry))
.addSubcommand("delete", new ActionDeleteCommand(npcRegistry)) .addSubcommand("delete", new ActionDeleteCommand(npcRegistry))
.addSubcommand("edit", new ActionEditCommand(npcRegistry, actionRegistry)) .addSubcommand("edit", new ActionEditCommand(npcRegistry, actionRegistry))
.addSubcommand("list", new ActionListCommand(npcRegistry))) .addSubcommand("list", new ActionListCommand(npcRegistry)))

@ -0,0 +1,36 @@
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.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;
import java.util.Collections;
import java.util.List;
public class ActionClearCommand implements CommandHandler {
private final NpcRegistryImpl npcRegistry;
public ActionClearCommand(NpcRegistryImpl npcRegistry) {
this.npcRegistry = npcRegistry;
}
@Override
public void run(CommandContext context) throws CommandExecutionException {
context.setUsage(context.getLabel() + " action clear <id>");
NpcImpl npc = context.parse(NpcEntryImpl.class).getNpc();
if (npc.getActions().size() == 0) context.halt(Component.text("That npc doesn't have any actions", NamedTextColor.RED));
npc.clearActions();
context.send(Component.text("Removed all actions from the npc", NamedTextColor.GREEN));
}
@Override
public List<String> suggest(CommandContext context) throws CommandExecutionException {
if (context.argSize() == 1) return context.suggestCollection(npcRegistry.getModifiableIds());
return Collections.emptyList();
}
}

@ -171,6 +171,10 @@ public class NpcImpl extends Viewable implements Npc {
actions.remove(index); actions.remove(index);
} }
public void clearActions() {
actions.clear();
}
public void addAction(InteractionActionImpl action) { public void addAction(InteractionActionImpl action) {
actions.add(action); actions.add(action);
} }

@ -3,6 +3,7 @@
<gray>Hover over any command for more info <gray>Hover over any command for more info
<gold>* <yellow>/npc action add <type> <id> <args> <gold>* <yellow>/npc action add <type> <id> <args>
<gold>* <yellow>/npc action clear <id>
<gold>* <yellow>/npc action delete <id> <index> <gold>* <yellow>/npc action delete <id> <index>
<gold>* <yellow>/npc action edit <id> <index> <type> <args> <gold>* <yellow>/npc action edit <id> <index> <type> <args>
<gold>* <yellow>/npc action list <id> <gold>* <yellow>/npc action list <id>