Added action list command

This commit is contained in:
D3v1s0m 2023-06-07 15:55:04 +05:30
parent eafb5a1f53
commit 92a2762868
No known key found for this signature in database
GPG Key ID: 3B6EC35367B8D82E
8 changed files with 162 additions and 6 deletions

@ -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)))
);
}
}

@ -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 <id>");
NpcEntryImpl entry = context.parse(NpcEntryImpl.class);
List<InteractionAction> 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<String> suggest(CommandContext context) throws CommandExecutionException {
return CommandHandler.super.suggest(context);
if (context.argSize() == 1) return context.suggestCollection(npcRegistry.getModifiableIds());
return Collections.emptyList();
}
}

@ -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);
}

@ -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;
}

@ -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;
}

@ -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;
}

@ -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;
}

@ -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;
}