From 92a27628685b45bc951eb58f0b85c80365bb00bc Mon Sep 17 00:00:00 2001 From: D3v1s0m <49519439+D3v1s0m@users.noreply.github.com> Date: Wed, 7 Jun 2023 15:55:04 +0530 Subject: [PATCH] Added action list command --- .../java/lol/pyr/znpcsplus/ZNpcsPlus.java | 2 +- .../commands/action/ActionListCommand.java | 23 +++++++++++++-- .../interaction/InteractionAction.java | 4 +++ .../consolecommand/ConsoleCommandAction.java | 29 ++++++++++++++++++- .../interaction/message/MessageAction.java | 27 +++++++++++++++++ .../playerchat/PlayerChatAction.java | 27 +++++++++++++++++ .../playercommand/PlayerCommandAction.java | 27 +++++++++++++++++ .../switchserver/SwitchServerAction.java | 29 ++++++++++++++++++- 8 files changed, 162 insertions(+), 6 deletions(-) diff --git a/plugin/src/main/java/lol/pyr/znpcsplus/ZNpcsPlus.java b/plugin/src/main/java/lol/pyr/znpcsplus/ZNpcsPlus.java index 265fd79..1de2b2f 100644 --- a/plugin/src/main/java/lol/pyr/znpcsplus/ZNpcsPlus.java +++ b/plugin/src/main/java/lol/pyr/znpcsplus/ZNpcsPlus.java @@ -247,7 +247,7 @@ public class ZNpcsPlus extends JavaPlugin { .addSubcommand("add", new ActionAddCommand(npcRegistry, actionRegistry)) .addSubcommand("delete", new ActionDeleteCommand(npcRegistry)) .addSubcommand("edit", new ActionEditCommand(npcRegistry, actionRegistry)) - .addSubcommand("list", new ActionListCommand())) + .addSubcommand("list", new ActionListCommand(npcRegistry))) ); } } diff --git a/plugin/src/main/java/lol/pyr/znpcsplus/commands/action/ActionListCommand.java b/plugin/src/main/java/lol/pyr/znpcsplus/commands/action/ActionListCommand.java index 72caa0f..ef4487c 100644 --- a/plugin/src/main/java/lol/pyr/znpcsplus/commands/action/ActionListCommand.java +++ b/plugin/src/main/java/lol/pyr/znpcsplus/commands/action/ActionListCommand.java @@ -3,17 +3,34 @@ 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.InteractionAction; +import lol.pyr.znpcsplus.npc.NpcEntryImpl; +import lol.pyr.znpcsplus.npc.NpcRegistryImpl; +import java.util.Collections; import java.util.List; public class ActionListCommand implements CommandHandler { - @Override - public void run(CommandContext commandContext) throws CommandExecutionException { + private final NpcRegistryImpl npcRegistry; + public ActionListCommand(NpcRegistryImpl npcRegistry) { + this.npcRegistry = npcRegistry; + } + + @Override + public void run(CommandContext context) throws CommandExecutionException { + context.setUsage(context.getLabel() + " action list "); + NpcEntryImpl entry = context.parse(NpcEntryImpl.class); + List actions = entry.getNpc().getActions(); + context.send("Actions of Npc " + entry.getId() + ":"); + for (int i = 0; i < actions.size(); i++) { + context.send(actions.get(i).getInfo(entry.getId(), i, context)); + } } @Override public List suggest(CommandContext context) throws CommandExecutionException { - return CommandHandler.super.suggest(context); + if (context.argSize() == 1) return context.suggestCollection(npcRegistry.getModifiableIds()); + return Collections.emptyList(); } } diff --git a/plugin/src/main/java/lol/pyr/znpcsplus/interaction/InteractionAction.java b/plugin/src/main/java/lol/pyr/znpcsplus/interaction/InteractionAction.java index 6837a04..32eb958 100644 --- a/plugin/src/main/java/lol/pyr/znpcsplus/interaction/InteractionAction.java +++ b/plugin/src/main/java/lol/pyr/znpcsplus/interaction/InteractionAction.java @@ -1,6 +1,8 @@ package lol.pyr.znpcsplus.interaction; +import lol.pyr.director.adventure.command.CommandContext; import lol.pyr.znpcsplus.api.interaction.InteractionType; +import net.kyori.adventure.text.Component; import org.bukkit.entity.Player; import java.util.UUID; @@ -29,4 +31,6 @@ public abstract class InteractionAction { } public abstract void run(Player player); + + public abstract Component getInfo(String id, int index, CommandContext context); } diff --git a/plugin/src/main/java/lol/pyr/znpcsplus/interaction/consolecommand/ConsoleCommandAction.java b/plugin/src/main/java/lol/pyr/znpcsplus/interaction/consolecommand/ConsoleCommandAction.java index aee99e2..7f789de 100644 --- a/plugin/src/main/java/lol/pyr/znpcsplus/interaction/consolecommand/ConsoleCommandAction.java +++ b/plugin/src/main/java/lol/pyr/znpcsplus/interaction/consolecommand/ConsoleCommandAction.java @@ -1,9 +1,15 @@ package lol.pyr.znpcsplus.interaction.consolecommand; -import lol.pyr.znpcsplus.interaction.InteractionAction; +import lol.pyr.director.adventure.command.CommandContext; import lol.pyr.znpcsplus.api.interaction.InteractionType; +import lol.pyr.znpcsplus.interaction.InteractionAction; import lol.pyr.znpcsplus.scheduling.TaskScheduler; import lol.pyr.znpcsplus.util.PapiUtil; +import net.kyori.adventure.text.Component; +import net.kyori.adventure.text.event.ClickEvent; +import net.kyori.adventure.text.event.HoverEvent; +import net.kyori.adventure.text.format.NamedTextColor; +import net.kyori.adventure.text.format.TextDecoration; import org.bukkit.Bukkit; import org.bukkit.entity.Player; @@ -23,6 +29,27 @@ public class ConsoleCommandAction extends InteractionAction { scheduler.runSyncGlobal(() -> Bukkit.dispatchCommand(Bukkit.getConsoleSender(), PapiUtil.set(player, cmd))); } + @Override + public Component getInfo(String id, int index, CommandContext context) { + return Component.text(index + ") ", NamedTextColor.GOLD) + .append(Component.text("[EDIT]", NamedTextColor.DARK_GREEN, TextDecoration.BOLD) + .hoverEvent(HoverEvent.hoverEvent(HoverEvent.Action.SHOW_TEXT, + Component.text("Click to edit this action", NamedTextColor.GRAY))) + .clickEvent(ClickEvent.clickEvent(ClickEvent.Action.SUGGEST_COMMAND, + "/" + context.getLabel() + " action edit " + id + " " + index + " consolecommand " + " " + getInteractionType().name() + " " + getCooldown()/1000 + " " + command)) + .append(Component.text(" | ", NamedTextColor.GRAY).decoration(TextDecoration.BOLD, false)) + .append(Component.text("[DELETE]", NamedTextColor.RED, TextDecoration.BOLD) + .hoverEvent(HoverEvent.hoverEvent(HoverEvent.Action.SHOW_TEXT, + Component.text("Click to delete this action", NamedTextColor.GRAY))) + .clickEvent(ClickEvent.clickEvent(ClickEvent.Action.SUGGEST_COMMAND, + "/" + context.getLabel() + " action delete " + id + " " + index))) + .append(Component.text(" | ", NamedTextColor.GRAY).style(style -> style.decoration(TextDecoration.BOLD, false))) + .append(Component.text("Console Command: ", NamedTextColor.GREEN) + .hoverEvent(HoverEvent.hoverEvent(HoverEvent.Action.SHOW_TEXT, + Component.text("Click Type: " + getInteractionType().name() + " Cooldown: " + getCooldown()/1000, NamedTextColor.GREEN)))) + .append(Component.text(command, NamedTextColor.WHITE))); + } + public String getCommand() { return command; } diff --git a/plugin/src/main/java/lol/pyr/znpcsplus/interaction/message/MessageAction.java b/plugin/src/main/java/lol/pyr/znpcsplus/interaction/message/MessageAction.java index 526aa63..2692e87 100644 --- a/plugin/src/main/java/lol/pyr/znpcsplus/interaction/message/MessageAction.java +++ b/plugin/src/main/java/lol/pyr/znpcsplus/interaction/message/MessageAction.java @@ -1,9 +1,15 @@ package lol.pyr.znpcsplus.interaction.message; +import lol.pyr.director.adventure.command.CommandContext; import lol.pyr.znpcsplus.api.interaction.InteractionType; import lol.pyr.znpcsplus.interaction.InteractionAction; import lol.pyr.znpcsplus.util.PapiUtil; import net.kyori.adventure.platform.bukkit.BukkitAudiences; +import net.kyori.adventure.text.Component; +import net.kyori.adventure.text.event.ClickEvent; +import net.kyori.adventure.text.event.HoverEvent; +import net.kyori.adventure.text.format.NamedTextColor; +import net.kyori.adventure.text.format.TextDecoration; import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer; import org.bukkit.entity.Player; @@ -26,6 +32,27 @@ public class MessageAction extends InteractionAction { adventure.player(player).sendMessage(textSerializer.deserialize(PapiUtil.set(player, msg))); } + @Override + public Component getInfo(String id, int index, CommandContext context) { + return Component.text(index + ") ", NamedTextColor.GOLD) + .append(Component.text("[EDIT]", NamedTextColor.DARK_GREEN, TextDecoration.BOLD) + .hoverEvent(HoverEvent.hoverEvent(HoverEvent.Action.SHOW_TEXT, + Component.text("Click to edit this action", NamedTextColor.GRAY))) + .clickEvent(ClickEvent.clickEvent(ClickEvent.Action.SUGGEST_COMMAND, + "/" + context.getLabel() + " action edit " + id + " " + index + " message " + getInteractionType().name() + " " + getCooldown()/1000 + " " + message)) + .append(Component.text(" | ", NamedTextColor.GRAY)) + .append(Component.text("[DELETE]", NamedTextColor.RED, TextDecoration.BOLD) + .hoverEvent(HoverEvent.hoverEvent(HoverEvent.Action.SHOW_TEXT, + Component.text("Click to delete this action", NamedTextColor.GRAY))) + .clickEvent(ClickEvent.clickEvent(ClickEvent.Action.SUGGEST_COMMAND, + "/" + context.getLabel() + " action delete " + id + " " + index))) + .append(Component.text(" | ", NamedTextColor.GRAY)) + .append(Component.text("Message: ", NamedTextColor.GREEN) + .hoverEvent(HoverEvent.hoverEvent(HoverEvent.Action.SHOW_TEXT, + Component.text("Click Type: " + getInteractionType().name() + " Cooldown: " + getCooldown()/1000, NamedTextColor.GREEN)))) + .append(Component.text(message, NamedTextColor.WHITE))); + } + public String getMessage() { return message; } diff --git a/plugin/src/main/java/lol/pyr/znpcsplus/interaction/playerchat/PlayerChatAction.java b/plugin/src/main/java/lol/pyr/znpcsplus/interaction/playerchat/PlayerChatAction.java index f2aa063..3871ef3 100644 --- a/plugin/src/main/java/lol/pyr/znpcsplus/interaction/playerchat/PlayerChatAction.java +++ b/plugin/src/main/java/lol/pyr/znpcsplus/interaction/playerchat/PlayerChatAction.java @@ -1,7 +1,13 @@ package lol.pyr.znpcsplus.interaction.playerchat; +import lol.pyr.director.adventure.command.CommandContext; import lol.pyr.znpcsplus.api.interaction.InteractionType; import lol.pyr.znpcsplus.interaction.InteractionAction; +import net.kyori.adventure.text.Component; +import net.kyori.adventure.text.event.ClickEvent; +import net.kyori.adventure.text.event.HoverEvent; +import net.kyori.adventure.text.format.NamedTextColor; +import net.kyori.adventure.text.format.TextDecoration; import org.bukkit.entity.Player; public class PlayerChatAction extends InteractionAction { @@ -18,6 +24,27 @@ public class PlayerChatAction extends InteractionAction { .replace("{uuid}", player.getUniqueId().toString())); } + @Override + public Component getInfo(String id, int index, CommandContext context) { + return Component.text(index + ") ", NamedTextColor.GOLD) + .append(Component.text("[EDIT]", NamedTextColor.DARK_GREEN, TextDecoration.BOLD) + .hoverEvent(HoverEvent.hoverEvent(HoverEvent.Action.SHOW_TEXT, + Component.text("Click to edit this action", NamedTextColor.GRAY))) + .clickEvent(ClickEvent.clickEvent(ClickEvent.Action.SUGGEST_COMMAND, + "/" + context.getLabel() + " action edit " + id + " " + index + " playerchat " + " " + getInteractionType().name() + " " + getCooldown()/1000 + " " + message)) + .append(Component.text(" | ", NamedTextColor.GRAY).decoration(TextDecoration.BOLD, false)) + .append(Component.text("[DELETE]", NamedTextColor.RED, TextDecoration.BOLD) + .hoverEvent(HoverEvent.hoverEvent(HoverEvent.Action.SHOW_TEXT, + Component.text("Click to delete this action", NamedTextColor.GRAY))) + .clickEvent(ClickEvent.clickEvent(ClickEvent.Action.SUGGEST_COMMAND, + "/" + context.getLabel() + " action delete " + id + " " + index))) + .append(Component.text(" | ", NamedTextColor.GRAY).style(style -> style.decoration(TextDecoration.BOLD, false))) + .append(Component.text("Player Chat: ", NamedTextColor.GREEN) + .hoverEvent(HoverEvent.hoverEvent(HoverEvent.Action.SHOW_TEXT, + Component.text("Click Type: " + getInteractionType().name() + " Cooldown: " + getCooldown()/1000, NamedTextColor.GREEN)))) + .append(Component.text(message, NamedTextColor.WHITE))); + } + public String getMessage() { return message; } diff --git a/plugin/src/main/java/lol/pyr/znpcsplus/interaction/playercommand/PlayerCommandAction.java b/plugin/src/main/java/lol/pyr/znpcsplus/interaction/playercommand/PlayerCommandAction.java index a028545..4e505b6 100644 --- a/plugin/src/main/java/lol/pyr/znpcsplus/interaction/playercommand/PlayerCommandAction.java +++ b/plugin/src/main/java/lol/pyr/znpcsplus/interaction/playercommand/PlayerCommandAction.java @@ -1,9 +1,15 @@ package lol.pyr.znpcsplus.interaction.playercommand; +import lol.pyr.director.adventure.command.CommandContext; import lol.pyr.znpcsplus.api.interaction.InteractionType; import lol.pyr.znpcsplus.interaction.InteractionAction; import lol.pyr.znpcsplus.scheduling.TaskScheduler; import lol.pyr.znpcsplus.util.PapiUtil; +import net.kyori.adventure.text.Component; +import net.kyori.adventure.text.event.ClickEvent; +import net.kyori.adventure.text.event.HoverEvent; +import net.kyori.adventure.text.format.NamedTextColor; +import net.kyori.adventure.text.format.TextDecoration; import org.bukkit.entity.Player; public class PlayerCommandAction extends InteractionAction { @@ -22,6 +28,27 @@ public class PlayerCommandAction extends InteractionAction { scheduler.schedulePlayerCommand(player, PapiUtil.set(player, cmd)); } + @Override + public Component getInfo(String id, int index, CommandContext context) { + return Component.text(index + ") ", NamedTextColor.GOLD) + .append(Component.text("[EDIT]", NamedTextColor.DARK_GREEN, TextDecoration.BOLD) + .hoverEvent(HoverEvent.hoverEvent(HoverEvent.Action.SHOW_TEXT, + Component.text("Click to edit this action", NamedTextColor.GRAY))) + .clickEvent(ClickEvent.clickEvent(ClickEvent.Action.SUGGEST_COMMAND, + "/" + context.getLabel() + " action edit " + id + " " + index + " playercommand " + " " + getInteractionType().name() + " " + getCooldown()/1000 + " " + command)) + .append(Component.text(" | ", NamedTextColor.GRAY)) + .append(Component.text("[DELETE]", NamedTextColor.RED, TextDecoration.BOLD) + .hoverEvent(HoverEvent.hoverEvent(HoverEvent.Action.SHOW_TEXT, + Component.text("Click to delete this action", NamedTextColor.GRAY))) + .clickEvent(ClickEvent.clickEvent(ClickEvent.Action.SUGGEST_COMMAND, + "/" + context.getLabel() + " action delete " + id + " " + index))) + .append(Component.text(" | ", NamedTextColor.GRAY)) + .append(Component.text("Player Command: ", NamedTextColor.GREEN) + .hoverEvent(HoverEvent.hoverEvent(HoverEvent.Action.SHOW_TEXT, + Component.text("Click Type: " + getInteractionType().name() + " Cooldown: " + getCooldown()/1000, NamedTextColor.GREEN)))) + .append(Component.text(command, NamedTextColor.WHITE))); + } + public String getCommand() { return command; } diff --git a/plugin/src/main/java/lol/pyr/znpcsplus/interaction/switchserver/SwitchServerAction.java b/plugin/src/main/java/lol/pyr/znpcsplus/interaction/switchserver/SwitchServerAction.java index 3c4cccb..5effa2e 100644 --- a/plugin/src/main/java/lol/pyr/znpcsplus/interaction/switchserver/SwitchServerAction.java +++ b/plugin/src/main/java/lol/pyr/znpcsplus/interaction/switchserver/SwitchServerAction.java @@ -1,8 +1,14 @@ package lol.pyr.znpcsplus.interaction.switchserver; -import lol.pyr.znpcsplus.interaction.InteractionAction; +import lol.pyr.director.adventure.command.CommandContext; import lol.pyr.znpcsplus.api.interaction.InteractionType; +import lol.pyr.znpcsplus.interaction.InteractionAction; import lol.pyr.znpcsplus.util.BungeeConnector; +import net.kyori.adventure.text.Component; +import net.kyori.adventure.text.event.ClickEvent; +import net.kyori.adventure.text.event.HoverEvent; +import net.kyori.adventure.text.format.NamedTextColor; +import net.kyori.adventure.text.format.TextDecoration; import org.bukkit.entity.Player; public class SwitchServerAction extends InteractionAction { @@ -20,6 +26,27 @@ public class SwitchServerAction extends InteractionAction { bungeeConnector.sendPlayer(player, server); } + @Override + public Component getInfo(String id, int index, CommandContext context) { + return Component.text(index + ") ", NamedTextColor.GOLD) + .append(Component.text("[EDIT]", NamedTextColor.DARK_GREEN, TextDecoration.BOLD) + .hoverEvent(HoverEvent.hoverEvent(HoverEvent.Action.SHOW_TEXT, + Component.text("Click to edit this action", NamedTextColor.GRAY))) + .clickEvent(ClickEvent.clickEvent(ClickEvent.Action.SUGGEST_COMMAND, + "/" + context.getLabel() + " action edit " + id + " " + index + " switcserver " + " " + getInteractionType().name() + " " + getCooldown()/1000 + " " + server)) + .append(Component.text(" | ", NamedTextColor.GRAY)) + .append(Component.text("[DELETE]", NamedTextColor.RED, TextDecoration.BOLD) + .hoverEvent(HoverEvent.hoverEvent(HoverEvent.Action.SHOW_TEXT, + Component.text("Click to delete this action", NamedTextColor.GRAY))) + .clickEvent(ClickEvent.clickEvent(ClickEvent.Action.SUGGEST_COMMAND, + "/" + context.getLabel() + " action delete " + id + " " + index))) + .append(Component.text(" | ", NamedTextColor.GRAY)) + .append(Component.text("Switch Server: ", NamedTextColor.GREEN) + .hoverEvent(HoverEvent.hoverEvent(HoverEvent.Action.SHOW_TEXT, + Component.text("Click Type: " + getInteractionType().name() + " Cooldown: " + getCooldown()/1000, NamedTextColor.GREEN)))) + .append(Component.text(server, NamedTextColor.WHITE))); + } + public String getServer() { return server; }