Merge pull request #79 from Pyrbu/2.X

Merge 2.X changes into property system branch
This commit is contained in:
Pyr 2023-07-22 11:38:33 +02:00 committed by GitHub
commit f7a7b96648
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
22 changed files with 79 additions and 45 deletions

@ -1,8 +1,5 @@
package lol.pyr.znpcsplus.interaction; package lol.pyr.znpcsplus.api.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 org.bukkit.entity.Player;
import java.util.UUID; import java.util.UUID;
@ -31,6 +28,4 @@ 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);
} }

@ -2,10 +2,27 @@ package lol.pyr.znpcsplus.api.npc;
import lol.pyr.znpcsplus.api.entity.PropertyHolder; import lol.pyr.znpcsplus.api.entity.PropertyHolder;
import lol.pyr.znpcsplus.api.hologram.Hologram; import lol.pyr.znpcsplus.api.hologram.Hologram;
import lol.pyr.znpcsplus.api.interaction.InteractionAction;
import lol.pyr.znpcsplus.util.NpcLocation;
import org.bukkit.World;
import org.bukkit.entity.Player;
import java.util.List;
import java.util.UUID; import java.util.UUID;
public interface Npc extends PropertyHolder { public interface Npc extends PropertyHolder {
void setType(NpcType type);
NpcType getType();
NpcLocation getLocation();
void setLocation(NpcLocation location);
Hologram getHologram(); Hologram getHologram();
void setEnabled(boolean enabled);
boolean isEnabled();
UUID getUuid(); UUID getUuid();
World getWorld();
List<? extends InteractionAction> getActions();
boolean isVisibleTo(Player player);
void hide(Player player);
void show(Player player);
void respawn(Player player);
} }

@ -4,7 +4,7 @@ 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.ActionRegistry; import lol.pyr.znpcsplus.interaction.ActionRegistry;
import lol.pyr.znpcsplus.interaction.InteractionAction; import lol.pyr.znpcsplus.interaction.InteractionActionImpl;
import lol.pyr.znpcsplus.interaction.InteractionCommandHandler; import lol.pyr.znpcsplus.interaction.InteractionCommandHandler;
import lol.pyr.znpcsplus.npc.NpcEntryImpl; import lol.pyr.znpcsplus.npc.NpcEntryImpl;
import lol.pyr.znpcsplus.npc.NpcRegistryImpl; import lol.pyr.znpcsplus.npc.NpcRegistryImpl;
@ -42,7 +42,7 @@ public class ActionEditCommand implements CommandHandler {
context.send(Component.text("Invalid action type, available action types:\n" + context.send(Component.text("Invalid action type, available action types:\n" +
commands.stream().map(InteractionCommandHandler::getSubcommandName).collect(Collectors.joining(", ")), NamedTextColor.RED)); commands.stream().map(InteractionCommandHandler::getSubcommandName).collect(Collectors.joining(", ")), NamedTextColor.RED));
} }
InteractionAction newAction = this.commandHandler.parse(context); InteractionActionImpl newAction = this.commandHandler.parse(context);
entry.getNpc().editAction(index, newAction); entry.getNpc().editAction(index, newAction);
context.send(Component.text("Edited action with index " + index + " of Npc " + entry.getId(), NamedTextColor.GREEN)); context.send(Component.text("Edited action with index " + index + " of Npc " + entry.getId(), NamedTextColor.GREEN));
} }

@ -3,7 +3,7 @@ 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.interaction.InteractionActionImpl;
import lol.pyr.znpcsplus.npc.NpcEntryImpl; import lol.pyr.znpcsplus.npc.NpcEntryImpl;
import lol.pyr.znpcsplus.npc.NpcRegistryImpl; import lol.pyr.znpcsplus.npc.NpcRegistryImpl;
@ -21,7 +21,7 @@ public class ActionListCommand implements CommandHandler {
public void run(CommandContext context) throws CommandExecutionException { public void run(CommandContext context) throws CommandExecutionException {
context.setUsage(context.getLabel() + " action list <id>"); context.setUsage(context.getLabel() + " action list <id>");
NpcEntryImpl entry = context.parse(NpcEntryImpl.class); NpcEntryImpl entry = context.parse(NpcEntryImpl.class);
List<InteractionAction> actions = entry.getNpc().getActions(); List<InteractionActionImpl> actions = entry.getNpc().getActions();
context.send("Actions of Npc " + entry.getId() + ":"); context.send("Actions of Npc " + entry.getId() + ":");
for (int i = 0; i < actions.size(); i++) { for (int i = 0; i < actions.size(); i++) {
context.send(actions.get(i).getInfo(entry.getId(), i, context)); context.send(actions.get(i).getInfo(entry.getId(), i, context));

@ -16,7 +16,7 @@ import lol.pyr.znpcsplus.conversion.znpcs.model.ZNpcsModel;
import lol.pyr.znpcsplus.entity.EntityPropertyImpl; import lol.pyr.znpcsplus.entity.EntityPropertyImpl;
import lol.pyr.znpcsplus.entity.EntityPropertyRegistryImpl; import lol.pyr.znpcsplus.entity.EntityPropertyRegistryImpl;
import lol.pyr.znpcsplus.hologram.HologramImpl; import lol.pyr.znpcsplus.hologram.HologramImpl;
import lol.pyr.znpcsplus.interaction.InteractionAction; import lol.pyr.znpcsplus.interaction.InteractionActionImpl;
import lol.pyr.znpcsplus.interaction.consolecommand.ConsoleCommandAction; import lol.pyr.znpcsplus.interaction.consolecommand.ConsoleCommandAction;
import lol.pyr.znpcsplus.interaction.message.MessageAction; import lol.pyr.znpcsplus.interaction.message.MessageAction;
import lol.pyr.znpcsplus.interaction.playerchat.PlayerChatAction; import lol.pyr.znpcsplus.interaction.playerchat.PlayerChatAction;
@ -148,7 +148,7 @@ public class ZNpcImporter implements DataImporter {
throw new IllegalArgumentException("Couldn't adapt znpcs click type: " + clickType); throw new IllegalArgumentException("Couldn't adapt znpcs click type: " + clickType);
} }
private InteractionAction adaptAction(String type, InteractionType clickType, String parameter, int delay) { private InteractionActionImpl adaptAction(String type, InteractionType clickType, String parameter, int delay) {
switch (type.toLowerCase()) { switch (type.toLowerCase()) {
case "cmd": case "cmd":
return new PlayerCommandAction(taskScheduler, parameter, clickType, delay * 1000L); return new PlayerCommandAction(taskScheduler, parameter, clickType, delay * 1000L);

@ -1,5 +1,6 @@
package lol.pyr.znpcsplus.interaction; package lol.pyr.znpcsplus.interaction;
import lol.pyr.znpcsplus.api.interaction.InteractionAction;
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.playerchat.PlayerChatActionType;

@ -0,0 +1,14 @@
package lol.pyr.znpcsplus.interaction;
import lol.pyr.director.adventure.command.CommandContext;
import lol.pyr.znpcsplus.api.interaction.InteractionAction;
import lol.pyr.znpcsplus.api.interaction.InteractionType;
import net.kyori.adventure.text.Component;
public abstract class InteractionActionImpl extends InteractionAction {
protected InteractionActionImpl(long delay, InteractionType interactionType) {
super(delay, interactionType);
}
public abstract Component getInfo(String id, int index, CommandContext context);
}

@ -11,7 +11,7 @@ import net.kyori.adventure.text.format.NamedTextColor;
public interface InteractionCommandHandler extends CommandHandler { public interface InteractionCommandHandler extends CommandHandler {
String getSubcommandName(); String getSubcommandName();
InteractionAction parse(CommandContext context) throws CommandExecutionException; InteractionActionImpl parse(CommandContext context) throws CommandExecutionException;
void appendUsage(CommandContext context); void appendUsage(CommandContext context);
@Override @Override

@ -5,6 +5,7 @@ import com.github.retrooper.packetevents.event.PacketReceiveEvent;
import com.github.retrooper.packetevents.protocol.packettype.PacketType; import com.github.retrooper.packetevents.protocol.packettype.PacketType;
import com.github.retrooper.packetevents.wrapper.play.client.WrapperPlayClientInteractEntity; import com.github.retrooper.packetevents.wrapper.play.client.WrapperPlayClientInteractEntity;
import lol.pyr.znpcsplus.api.event.NpcInteractEvent; import lol.pyr.znpcsplus.api.event.NpcInteractEvent;
import lol.pyr.znpcsplus.api.interaction.InteractionAction;
import lol.pyr.znpcsplus.api.interaction.InteractionType; import lol.pyr.znpcsplus.api.interaction.InteractionType;
import lol.pyr.znpcsplus.npc.NpcEntryImpl; import lol.pyr.znpcsplus.npc.NpcEntryImpl;
import lol.pyr.znpcsplus.npc.NpcImpl; import lol.pyr.znpcsplus.npc.NpcImpl;

@ -2,7 +2,7 @@ package lol.pyr.znpcsplus.interaction.consolecommand;
import lol.pyr.director.adventure.command.CommandContext; 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.InteractionActionImpl;
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.Component;
@ -12,7 +12,7 @@ import net.kyori.adventure.text.format.NamedTextColor;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
public class ConsoleCommandAction extends InteractionAction { public class ConsoleCommandAction extends InteractionActionImpl {
private final TaskScheduler scheduler; private final TaskScheduler scheduler;
private final String command; private final String command;
@ -35,7 +35,7 @@ public class ConsoleCommandAction extends InteractionAction {
.hoverEvent(HoverEvent.hoverEvent(HoverEvent.Action.SHOW_TEXT, .hoverEvent(HoverEvent.hoverEvent(HoverEvent.Action.SHOW_TEXT,
Component.text("Click to edit this action", NamedTextColor.GRAY))) Component.text("Click to edit this action", NamedTextColor.GRAY)))
.clickEvent(ClickEvent.clickEvent(ClickEvent.Action.SUGGEST_COMMAND, .clickEvent(ClickEvent.clickEvent(ClickEvent.Action.SUGGEST_COMMAND,
"/" + context.getLabel() + " action edit " + id + " " + index + " consolecommand " + " " + getInteractionType().name() + " " + getCooldown()/1000 + " " + command)) "/" + context.getLabel() + " action edit " + id + " " + index + " consolecommand " + getInteractionType().name() + " " + getCooldown()/1000 + " " + command))
.append(Component.text(" | ", NamedTextColor.GRAY)) .append(Component.text(" | ", NamedTextColor.GRAY))
.append(Component.text("[DELETE]", NamedTextColor.RED) .append(Component.text("[DELETE]", NamedTextColor.RED)
.hoverEvent(HoverEvent.hoverEvent(HoverEvent.Action.SHOW_TEXT, .hoverEvent(HoverEvent.hoverEvent(HoverEvent.Action.SHOW_TEXT,

@ -3,7 +3,7 @@ package lol.pyr.znpcsplus.interaction.consolecommand;
import lol.pyr.director.adventure.command.CommandContext; import lol.pyr.director.adventure.command.CommandContext;
import lol.pyr.director.common.command.CommandExecutionException; import lol.pyr.director.common.command.CommandExecutionException;
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.InteractionActionImpl;
import lol.pyr.znpcsplus.interaction.InteractionActionType; import lol.pyr.znpcsplus.interaction.InteractionActionType;
import lol.pyr.znpcsplus.interaction.InteractionCommandHandler; import lol.pyr.znpcsplus.interaction.InteractionCommandHandler;
import lol.pyr.znpcsplus.scheduling.TaskScheduler; import lol.pyr.znpcsplus.scheduling.TaskScheduler;
@ -48,7 +48,7 @@ public class ConsoleCommandActionType implements InteractionActionType<ConsoleCo
} }
@Override @Override
public InteractionAction parse(CommandContext context) throws CommandExecutionException { public InteractionActionImpl parse(CommandContext context) throws CommandExecutionException {
InteractionType type = context.parse(InteractionType.class); InteractionType type = context.parse(InteractionType.class);
long cooldown = (long) (context.parse(Double.class) * 1000D); long cooldown = (long) (context.parse(Double.class) * 1000D);
String command = context.dumpAllArgs(); String command = context.dumpAllArgs();

@ -2,7 +2,7 @@ package lol.pyr.znpcsplus.interaction.message;
import lol.pyr.director.adventure.command.CommandContext; 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.InteractionActionImpl;
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.Component;
@ -12,7 +12,7 @@ import net.kyori.adventure.text.format.NamedTextColor;
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;
public class MessageAction extends InteractionAction { public class MessageAction extends InteractionActionImpl {
private final BukkitAudiences adventure; private final BukkitAudiences adventure;
private final String message; private final String message;
private final LegacyComponentSerializer textSerializer; private final LegacyComponentSerializer textSerializer;

@ -3,7 +3,7 @@ package lol.pyr.znpcsplus.interaction.message;
import lol.pyr.director.adventure.command.CommandContext; import lol.pyr.director.adventure.command.CommandContext;
import lol.pyr.director.common.command.CommandExecutionException; import lol.pyr.director.common.command.CommandExecutionException;
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.InteractionActionImpl;
import lol.pyr.znpcsplus.interaction.InteractionActionType; import lol.pyr.znpcsplus.interaction.InteractionActionType;
import lol.pyr.znpcsplus.interaction.InteractionCommandHandler; import lol.pyr.znpcsplus.interaction.InteractionCommandHandler;
import net.kyori.adventure.platform.bukkit.BukkitAudiences; import net.kyori.adventure.platform.bukkit.BukkitAudiences;
@ -51,7 +51,7 @@ public class MessageActionType implements InteractionActionType<MessageAction>,
} }
@Override @Override
public InteractionAction parse(CommandContext context) throws CommandExecutionException { public InteractionActionImpl parse(CommandContext context) throws CommandExecutionException {
InteractionType type = context.parse(InteractionType.class); InteractionType type = context.parse(InteractionType.class);
long cooldown = (long) (context.parse(Double.class) * 1000D); long cooldown = (long) (context.parse(Double.class) * 1000D);
String message = context.dumpAllArgs(); String message = context.dumpAllArgs();

@ -2,7 +2,7 @@ package lol.pyr.znpcsplus.interaction.playerchat;
import lol.pyr.director.adventure.command.CommandContext; 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.InteractionActionImpl;
import lol.pyr.znpcsplus.scheduling.TaskScheduler; import lol.pyr.znpcsplus.scheduling.TaskScheduler;
import net.kyori.adventure.text.Component; import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.event.ClickEvent; import net.kyori.adventure.text.event.ClickEvent;
@ -10,7 +10,7 @@ import net.kyori.adventure.text.event.HoverEvent;
import net.kyori.adventure.text.format.NamedTextColor; import net.kyori.adventure.text.format.NamedTextColor;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
public class PlayerChatAction extends InteractionAction { public class PlayerChatAction extends InteractionActionImpl {
private final String message; private final String message;
private final TaskScheduler scheduler; private final TaskScheduler scheduler;
@ -33,7 +33,7 @@ public class PlayerChatAction extends InteractionAction {
.hoverEvent(HoverEvent.hoverEvent(HoverEvent.Action.SHOW_TEXT, .hoverEvent(HoverEvent.hoverEvent(HoverEvent.Action.SHOW_TEXT,
Component.text("Click to edit this action", NamedTextColor.GRAY))) Component.text("Click to edit this action", NamedTextColor.GRAY)))
.clickEvent(ClickEvent.clickEvent(ClickEvent.Action.SUGGEST_COMMAND, .clickEvent(ClickEvent.clickEvent(ClickEvent.Action.SUGGEST_COMMAND,
"/" + context.getLabel() + " action edit " + id + " " + index + " playerchat " + " " + getInteractionType().name() + " " + getCooldown()/1000 + " " + message)) "/" + context.getLabel() + " action edit " + id + " " + index + " playerchat " + getInteractionType().name() + " " + getCooldown()/1000 + " " + message))
.append(Component.text(" | ", NamedTextColor.GRAY)) .append(Component.text(" | ", NamedTextColor.GRAY))
.append(Component.text("[DELETE]", NamedTextColor.RED) .append(Component.text("[DELETE]", NamedTextColor.RED)
.hoverEvent(HoverEvent.hoverEvent(HoverEvent.Action.SHOW_TEXT, .hoverEvent(HoverEvent.hoverEvent(HoverEvent.Action.SHOW_TEXT,

@ -3,7 +3,7 @@ package lol.pyr.znpcsplus.interaction.playerchat;
import lol.pyr.director.adventure.command.CommandContext; import lol.pyr.director.adventure.command.CommandContext;
import lol.pyr.director.common.command.CommandExecutionException; import lol.pyr.director.common.command.CommandExecutionException;
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.InteractionActionImpl;
import lol.pyr.znpcsplus.interaction.InteractionActionType; import lol.pyr.znpcsplus.interaction.InteractionActionType;
import lol.pyr.znpcsplus.interaction.InteractionCommandHandler; import lol.pyr.znpcsplus.interaction.InteractionCommandHandler;
import lol.pyr.znpcsplus.scheduling.TaskScheduler; import lol.pyr.znpcsplus.scheduling.TaskScheduler;
@ -47,7 +47,7 @@ public class PlayerChatActionType implements InteractionActionType<PlayerChatAct
} }
@Override @Override
public InteractionAction parse(CommandContext context) throws CommandExecutionException { public InteractionActionImpl parse(CommandContext context) throws CommandExecutionException {
InteractionType type = context.parse(InteractionType.class); InteractionType type = context.parse(InteractionType.class);
long cooldown = (long) (context.parse(Double.class) * 1000D); long cooldown = (long) (context.parse(Double.class) * 1000D);
String message = context.dumpAllArgs(); String message = context.dumpAllArgs();

@ -2,7 +2,7 @@ package lol.pyr.znpcsplus.interaction.playercommand;
import lol.pyr.director.adventure.command.CommandContext; 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.InteractionActionImpl;
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.Component;
@ -11,7 +11,7 @@ import net.kyori.adventure.text.event.HoverEvent;
import net.kyori.adventure.text.format.NamedTextColor; import net.kyori.adventure.text.format.NamedTextColor;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
public class PlayerCommandAction extends InteractionAction { public class PlayerCommandAction extends InteractionActionImpl {
private final TaskScheduler scheduler; private final TaskScheduler scheduler;
private final String command; private final String command;
@ -34,7 +34,7 @@ public class PlayerCommandAction extends InteractionAction {
.hoverEvent(HoverEvent.hoverEvent(HoverEvent.Action.SHOW_TEXT, .hoverEvent(HoverEvent.hoverEvent(HoverEvent.Action.SHOW_TEXT,
Component.text("Click to edit this action", NamedTextColor.GRAY))) Component.text("Click to edit this action", NamedTextColor.GRAY)))
.clickEvent(ClickEvent.clickEvent(ClickEvent.Action.SUGGEST_COMMAND, .clickEvent(ClickEvent.clickEvent(ClickEvent.Action.SUGGEST_COMMAND,
"/" + context.getLabel() + " action edit " + id + " " + index + " playercommand " + " " + getInteractionType().name() + " " + getCooldown()/1000 + " " + command)) "/" + context.getLabel() + " action edit " + id + " " + index + " playercommand " + getInteractionType().name() + " " + getCooldown()/1000 + " " + command))
.append(Component.text(" | ", NamedTextColor.GRAY)) .append(Component.text(" | ", NamedTextColor.GRAY))
.append(Component.text("[DELETE]", NamedTextColor.RED) .append(Component.text("[DELETE]", NamedTextColor.RED)
.hoverEvent(HoverEvent.hoverEvent(HoverEvent.Action.SHOW_TEXT, .hoverEvent(HoverEvent.hoverEvent(HoverEvent.Action.SHOW_TEXT,

@ -3,7 +3,7 @@ package lol.pyr.znpcsplus.interaction.playercommand;
import lol.pyr.director.adventure.command.CommandContext; import lol.pyr.director.adventure.command.CommandContext;
import lol.pyr.director.common.command.CommandExecutionException; import lol.pyr.director.common.command.CommandExecutionException;
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.InteractionActionImpl;
import lol.pyr.znpcsplus.interaction.InteractionActionType; import lol.pyr.znpcsplus.interaction.InteractionActionType;
import lol.pyr.znpcsplus.interaction.InteractionCommandHandler; import lol.pyr.znpcsplus.interaction.InteractionCommandHandler;
import lol.pyr.znpcsplus.scheduling.TaskScheduler; import lol.pyr.znpcsplus.scheduling.TaskScheduler;
@ -48,7 +48,7 @@ public class PlayerCommandActionType implements InteractionActionType<PlayerComm
} }
@Override @Override
public InteractionAction parse(CommandContext context) throws CommandExecutionException { public InteractionActionImpl parse(CommandContext context) throws CommandExecutionException {
InteractionType type = context.parse(InteractionType.class); InteractionType type = context.parse(InteractionType.class);
long cooldown = (long) (context.parse(Double.class) * 1000D); long cooldown = (long) (context.parse(Double.class) * 1000D);
String command = context.dumpAllArgs(); String command = context.dumpAllArgs();

@ -2,7 +2,7 @@ package lol.pyr.znpcsplus.interaction.switchserver;
import lol.pyr.director.adventure.command.CommandContext; 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.InteractionActionImpl;
import lol.pyr.znpcsplus.util.BungeeConnector; import lol.pyr.znpcsplus.util.BungeeConnector;
import net.kyori.adventure.text.Component; import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.event.ClickEvent; import net.kyori.adventure.text.event.ClickEvent;
@ -10,7 +10,7 @@ import net.kyori.adventure.text.event.HoverEvent;
import net.kyori.adventure.text.format.NamedTextColor; import net.kyori.adventure.text.format.NamedTextColor;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
public class SwitchServerAction extends InteractionAction { public class SwitchServerAction extends InteractionActionImpl {
private final BungeeConnector bungeeConnector; private final BungeeConnector bungeeConnector;
private final String server; private final String server;
@ -32,7 +32,7 @@ public class SwitchServerAction extends InteractionAction {
.hoverEvent(HoverEvent.hoverEvent(HoverEvent.Action.SHOW_TEXT, .hoverEvent(HoverEvent.hoverEvent(HoverEvent.Action.SHOW_TEXT,
Component.text("Click to edit this action", NamedTextColor.GRAY))) Component.text("Click to edit this action", NamedTextColor.GRAY)))
.clickEvent(ClickEvent.clickEvent(ClickEvent.Action.SUGGEST_COMMAND, .clickEvent(ClickEvent.clickEvent(ClickEvent.Action.SUGGEST_COMMAND,
"/" + context.getLabel() + " action edit " + id + " " + index + " switcserver " + " " + getInteractionType().name() + " " + getCooldown()/1000 + " " + server)) "/" + context.getLabel() + " action edit " + id + " " + index + " switcserver " + getInteractionType().name() + " " + getCooldown()/1000 + " " + server))
.append(Component.text(" | ", NamedTextColor.GRAY)) .append(Component.text(" | ", NamedTextColor.GRAY))
.append(Component.text("[DELETE]", NamedTextColor.RED) .append(Component.text("[DELETE]", NamedTextColor.RED)
.hoverEvent(HoverEvent.hoverEvent(HoverEvent.Action.SHOW_TEXT, .hoverEvent(HoverEvent.hoverEvent(HoverEvent.Action.SHOW_TEXT,

@ -3,7 +3,7 @@ package lol.pyr.znpcsplus.interaction.switchserver;
import lol.pyr.director.adventure.command.CommandContext; import lol.pyr.director.adventure.command.CommandContext;
import lol.pyr.director.common.command.CommandExecutionException; import lol.pyr.director.common.command.CommandExecutionException;
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.InteractionActionImpl;
import lol.pyr.znpcsplus.interaction.InteractionActionType; import lol.pyr.znpcsplus.interaction.InteractionActionType;
import lol.pyr.znpcsplus.interaction.InteractionCommandHandler; import lol.pyr.znpcsplus.interaction.InteractionCommandHandler;
import lol.pyr.znpcsplus.util.BungeeConnector; import lol.pyr.znpcsplus.util.BungeeConnector;
@ -48,7 +48,7 @@ public class SwitchServerActionType implements InteractionActionType<SwitchServe
} }
@Override @Override
public InteractionAction parse(CommandContext context) throws CommandExecutionException { public InteractionActionImpl parse(CommandContext context) throws CommandExecutionException {
InteractionType type = context.parse(InteractionType.class); InteractionType type = context.parse(InteractionType.class);
long cooldown = (long) (context.parse(Double.class) * 1000D); long cooldown = (long) (context.parse(Double.class) * 1000D);
String server = context.dumpAllArgs(); String server = context.dumpAllArgs();

@ -3,12 +3,13 @@ package lol.pyr.znpcsplus.npc;
import com.github.retrooper.packetevents.protocol.entity.data.EntityData; import com.github.retrooper.packetevents.protocol.entity.data.EntityData;
import lol.pyr.znpcsplus.api.entity.EntityProperty; import lol.pyr.znpcsplus.api.entity.EntityProperty;
import lol.pyr.znpcsplus.api.npc.Npc; import lol.pyr.znpcsplus.api.npc.Npc;
import lol.pyr.znpcsplus.api.npc.NpcType;
import lol.pyr.znpcsplus.config.ConfigManager; import lol.pyr.znpcsplus.config.ConfigManager;
import lol.pyr.znpcsplus.entity.EntityPropertyImpl; import lol.pyr.znpcsplus.entity.EntityPropertyImpl;
import lol.pyr.znpcsplus.entity.EntityPropertyRegistryImpl; import lol.pyr.znpcsplus.entity.EntityPropertyRegistryImpl;
import lol.pyr.znpcsplus.entity.PacketEntity; import lol.pyr.znpcsplus.entity.PacketEntity;
import lol.pyr.znpcsplus.hologram.HologramImpl; import lol.pyr.znpcsplus.hologram.HologramImpl;
import lol.pyr.znpcsplus.interaction.InteractionAction; import lol.pyr.znpcsplus.interaction.InteractionActionImpl;
import lol.pyr.znpcsplus.packets.PacketFactory; import lol.pyr.znpcsplus.packets.PacketFactory;
import lol.pyr.znpcsplus.util.NpcLocation; import lol.pyr.znpcsplus.util.NpcLocation;
import lol.pyr.znpcsplus.util.Viewable; import lol.pyr.znpcsplus.util.Viewable;
@ -31,7 +32,7 @@ public class NpcImpl extends Viewable implements Npc {
private final UUID uuid; private final UUID uuid;
private final Map<EntityPropertyImpl<?>, Object> propertyMap = new HashMap<>(); private final Map<EntityPropertyImpl<?>, Object> propertyMap = new HashMap<>();
private final List<InteractionAction> actions = new ArrayList<>(); private final List<InteractionActionImpl> actions = new ArrayList<>();
protected NpcImpl(UUID uuid, EntityPropertyRegistryImpl propertyRegistry, ConfigManager configManager, LegacyComponentSerializer textSerializer, World world, NpcTypeImpl type, NpcLocation location, PacketFactory packetFactory) { protected NpcImpl(UUID uuid, EntityPropertyRegistryImpl propertyRegistry, ConfigManager configManager, LegacyComponentSerializer textSerializer, World world, NpcTypeImpl type, NpcLocation location, PacketFactory packetFactory) {
this(uuid, propertyRegistry, configManager, packetFactory, textSerializer, world.getName(), type, location); this(uuid, propertyRegistry, configManager, packetFactory, textSerializer, world.getName(), type, location);
@ -55,6 +56,11 @@ public class NpcImpl extends Viewable implements Npc {
UNSAFE_showAll(); UNSAFE_showAll();
} }
public void setType(NpcType type) {
if (type == null) throw new IllegalArgumentException("Npc Type cannot be null");
setType((NpcTypeImpl) type);
}
public NpcTypeImpl getType() { public NpcTypeImpl getType() {
return type; return type;
} }
@ -151,7 +157,7 @@ public class NpcImpl extends Viewable implements Npc {
return Collections.unmodifiableSet(propertyMap.keySet()); return Collections.unmodifiableSet(propertyMap.keySet());
} }
public List<InteractionAction> getActions() { public List<InteractionActionImpl> getActions() {
return Collections.unmodifiableList(actions); return Collections.unmodifiableList(actions);
} }
@ -159,11 +165,11 @@ public class NpcImpl extends Viewable implements Npc {
actions.remove(index); actions.remove(index);
} }
public void addAction(InteractionAction action) { public void addAction(InteractionActionImpl action) {
actions.add(action); actions.add(action);
} }
public void editAction(int index, InteractionAction action) { public void editAction(int index, InteractionActionImpl action) {
actions.set(index, action); actions.set(index, action);
} }
} }

@ -1,6 +1,6 @@
package lol.pyr.znpcsplus.user; package lol.pyr.znpcsplus.user;
import lol.pyr.znpcsplus.interaction.InteractionAction; import lol.pyr.znpcsplus.api.interaction.InteractionAction;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;

@ -3,11 +3,11 @@ package lol.pyr.znpcsplus.util;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import java.util.Collections; import java.util.Collections;
import java.util.HashSet;
import java.util.Set; import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
public abstract class Viewable { public abstract class Viewable {
private final Set<Player> viewers = new HashSet<>(); private final Set<Player> viewers = ConcurrentHashMap.newKeySet();
public void delete() { public void delete() {
UNSAFE_hideAll(); UNSAFE_hideAll();