Merge remote-tracking branch 'origin/2.0.0' into 2.0.0

This commit is contained in:
Pyrbu 2023-06-10 13:59:36 +02:00
commit 699d3cc999
10 changed files with 166 additions and 8 deletions

@ -247,7 +247,7 @@ public class ZNpcsPlus extends JavaPlugin {
.addSubcommand("add", new ActionAddCommand(npcRegistry, actionRegistry)) .addSubcommand("add", new ActionAddCommand(npcRegistry, actionRegistry))
.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())) .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.CommandContext;
import lol.pyr.director.adventure.command.CommandHandler; import lol.pyr.director.adventure.command.CommandHandler;
import lol.pyr.director.common.command.CommandExecutionException; 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; import java.util.List;
public class ActionListCommand implements CommandHandler { public class ActionListCommand implements CommandHandler {
@Override private final NpcRegistryImpl npcRegistry;
public void run(CommandContext commandContext) throws CommandExecutionException {
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 @Override
public List<String> suggest(CommandContext context) throws CommandExecutionException { 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();
} }
} }

@ -4,7 +4,7 @@ public class ZNpcsAction {
private String actionType; private String actionType;
private String clickType; private String clickType;
private String action; private String action;
private double delay; private int delay;
public String getActionType() { public String getActionType() {
return actionType; return actionType;
@ -18,7 +18,7 @@ public class ZNpcsAction {
return action; return action;
} }
public double getDelay() { public int getDelay() {
return delay; return delay;
} }
} }

@ -2,6 +2,7 @@ package lol.pyr.znpcsplus.interaction;
import lol.pyr.znpcsplus.interaction.consolecommand.ConsoleCommandActionType; import lol.pyr.znpcsplus.interaction.consolecommand.ConsoleCommandActionType;
import lol.pyr.znpcsplus.interaction.message.MessageActionType; import lol.pyr.znpcsplus.interaction.message.MessageActionType;
import lol.pyr.znpcsplus.interaction.playerchat.PlayerChatActionType;
import lol.pyr.znpcsplus.interaction.playercommand.PlayerCommandActionType; import lol.pyr.znpcsplus.interaction.playercommand.PlayerCommandActionType;
import lol.pyr.znpcsplus.interaction.switchserver.SwitchServerActionType; import lol.pyr.znpcsplus.interaction.switchserver.SwitchServerActionType;
import lol.pyr.znpcsplus.scheduling.TaskScheduler; import lol.pyr.znpcsplus.scheduling.TaskScheduler;
@ -26,6 +27,7 @@ public class ActionRegistry {
register(new PlayerCommandActionType(taskScheduler)); register(new PlayerCommandActionType(taskScheduler));
register(new SwitchServerActionType(bungeeConnector)); register(new SwitchServerActionType(bungeeConnector));
register(new MessageActionType(adventure, textSerializer)); register(new MessageActionType(adventure, textSerializer));
register(new PlayerChatActionType());
} }
public void register(InteractionActionType<?> type) { public void register(InteractionActionType<?> type) {

@ -1,6 +1,8 @@
package lol.pyr.znpcsplus.interaction; package lol.pyr.znpcsplus.interaction;
import lol.pyr.director.adventure.command.CommandContext;
import lol.pyr.znpcsplus.api.interaction.InteractionType; import lol.pyr.znpcsplus.api.interaction.InteractionType;
import net.kyori.adventure.text.Component;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import java.util.UUID; import java.util.UUID;
@ -29,4 +31,6 @@ public abstract class InteractionAction {
} }
public abstract void run(Player player); 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; 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.api.interaction.InteractionType;
import lol.pyr.znpcsplus.interaction.InteractionAction;
import lol.pyr.znpcsplus.scheduling.TaskScheduler; import lol.pyr.znpcsplus.scheduling.TaskScheduler;
import lol.pyr.znpcsplus.util.PapiUtil; 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.Bukkit;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
@ -23,6 +29,27 @@ public class ConsoleCommandAction extends InteractionAction {
scheduler.runSyncGlobal(() -> Bukkit.dispatchCommand(Bukkit.getConsoleSender(), PapiUtil.set(player, cmd))); 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() { public String getCommand() {
return command; return command;
} }

@ -1,9 +1,15 @@
package lol.pyr.znpcsplus.interaction.message; package lol.pyr.znpcsplus.interaction.message;
import lol.pyr.director.adventure.command.CommandContext;
import lol.pyr.znpcsplus.api.interaction.InteractionType; import lol.pyr.znpcsplus.api.interaction.InteractionType;
import lol.pyr.znpcsplus.interaction.InteractionAction; import lol.pyr.znpcsplus.interaction.InteractionAction;
import lol.pyr.znpcsplus.util.PapiUtil; import lol.pyr.znpcsplus.util.PapiUtil;
import net.kyori.adventure.platform.bukkit.BukkitAudiences; 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 net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
@ -26,6 +32,27 @@ public class MessageAction extends InteractionAction {
adventure.player(player).sendMessage(textSerializer.deserialize(PapiUtil.set(player, msg))); 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() { public String getMessage() {
return message; return message;
} }

@ -1,7 +1,13 @@
package lol.pyr.znpcsplus.interaction.playerchat; package lol.pyr.znpcsplus.interaction.playerchat;
import lol.pyr.director.adventure.command.CommandContext;
import lol.pyr.znpcsplus.api.interaction.InteractionType; import lol.pyr.znpcsplus.api.interaction.InteractionType;
import lol.pyr.znpcsplus.interaction.InteractionAction; 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; import org.bukkit.entity.Player;
public class PlayerChatAction extends InteractionAction { public class PlayerChatAction extends InteractionAction {
@ -18,6 +24,27 @@ public class PlayerChatAction extends InteractionAction {
.replace("{uuid}", player.getUniqueId().toString())); .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() { public String getMessage() {
return message; return message;
} }

@ -1,9 +1,15 @@
package lol.pyr.znpcsplus.interaction.playercommand; package lol.pyr.znpcsplus.interaction.playercommand;
import lol.pyr.director.adventure.command.CommandContext;
import lol.pyr.znpcsplus.api.interaction.InteractionType; import lol.pyr.znpcsplus.api.interaction.InteractionType;
import lol.pyr.znpcsplus.interaction.InteractionAction; import lol.pyr.znpcsplus.interaction.InteractionAction;
import lol.pyr.znpcsplus.scheduling.TaskScheduler; import lol.pyr.znpcsplus.scheduling.TaskScheduler;
import lol.pyr.znpcsplus.util.PapiUtil; 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; import org.bukkit.entity.Player;
public class PlayerCommandAction extends InteractionAction { public class PlayerCommandAction extends InteractionAction {
@ -22,6 +28,27 @@ public class PlayerCommandAction extends InteractionAction {
scheduler.schedulePlayerCommand(player, PapiUtil.set(player, cmd)); 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() { public String getCommand() {
return command; return command;
} }

@ -1,8 +1,14 @@
package lol.pyr.znpcsplus.interaction.switchserver; 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.api.interaction.InteractionType;
import lol.pyr.znpcsplus.interaction.InteractionAction;
import lol.pyr.znpcsplus.util.BungeeConnector; 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; import org.bukkit.entity.Player;
public class SwitchServerAction extends InteractionAction { public class SwitchServerAction extends InteractionAction {
@ -20,6 +26,27 @@ public class SwitchServerAction extends InteractionAction {
bungeeConnector.sendPlayer(player, server); 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() { public String getServer() {
return server; return server;
} }