From 26442f2e3e4d66cdec403a72bd9d1fac4debf9a5 Mon Sep 17 00:00:00 2001 From: D3v1s0m Date: Tue, 11 Jun 2024 21:29:38 +0530 Subject: [PATCH 1/7] expose action registry to api and added action factory --- .../java/lol/pyr/znpcsplus/api/NpcApi.java | 14 ++++++ .../znpcsplus/api/entity/PropertyHolder.java | 1 + .../api/interaction/ActionFactory.java | 10 ++++ .../api/interaction/ActionRegistry.java | 7 +++ .../interaction/InteractionActionType.java | 2 +- .../java/lol/pyr/znpcsplus/api/npc/Npc.java | 25 ++++++++++ .../java/lol/pyr/znpcsplus/ZNpcsPlus.java | 14 +++--- .../java/lol/pyr/znpcsplus/ZNpcsPlusApi.java | 21 +++++++- .../commands/action/ActionAddCommand.java | 6 +-- .../commands/action/ActionEditCommand.java | 10 ++-- .../commands/action/ActionListCommand.java | 7 ++- .../citizens/model/traits/CommandTrait.java | 4 +- .../fancynpcs/FancyNpcsImporter.java | 2 +- .../conversion/znpcs/ZNpcImporter.java | 10 ++-- .../interaction/ActionFactoryImpl.java | 48 +++++++++++++++++++ ...nRegistry.java => ActionRegistryImpl.java} | 7 +-- .../InteractionCommandHandler.java | 3 +- .../ConsoleCommandActionType.java | 2 +- .../interaction/message/MessageAction.java | 2 +- .../message/MessageActionType.java | 6 +-- .../playerchat/PlayerChatActionType.java | 6 +-- .../PlayerCommandActionType.java | 2 +- .../switchserver/SwitchServerAction.java | 2 +- .../switchserver/SwitchServerActionType.java | 6 +-- .../java/lol/pyr/znpcsplus/npc/NpcImpl.java | 21 ++++---- .../pyr/znpcsplus/npc/NpcRegistryImpl.java | 8 ++-- .../pyr/znpcsplus/storage/NpcStorageType.java | 10 ++-- .../znpcsplus/storage/mysql/MySQLStorage.java | 6 +-- .../storage/sqlite/SQLiteStorage.java | 6 +-- .../znpcsplus/storage/yaml/YamlStorage.java | 6 +-- 30 files changed, 203 insertions(+), 71 deletions(-) create mode 100644 api/src/main/java/lol/pyr/znpcsplus/api/interaction/ActionFactory.java create mode 100644 api/src/main/java/lol/pyr/znpcsplus/api/interaction/ActionRegistry.java rename {plugin/src/main/java/lol/pyr/znpcsplus => api/src/main/java/lol/pyr/znpcsplus/api}/interaction/InteractionActionType.java (76%) create mode 100644 plugin/src/main/java/lol/pyr/znpcsplus/interaction/ActionFactoryImpl.java rename plugin/src/main/java/lol/pyr/znpcsplus/interaction/{ActionRegistry.java => ActionRegistryImpl.java} (95%) diff --git a/api/src/main/java/lol/pyr/znpcsplus/api/NpcApi.java b/api/src/main/java/lol/pyr/znpcsplus/api/NpcApi.java index fe25878..b32c050 100644 --- a/api/src/main/java/lol/pyr/znpcsplus/api/NpcApi.java +++ b/api/src/main/java/lol/pyr/znpcsplus/api/NpcApi.java @@ -1,6 +1,8 @@ package lol.pyr.znpcsplus.api; import lol.pyr.znpcsplus.api.entity.EntityPropertyRegistry; +import lol.pyr.znpcsplus.api.interaction.ActionFactory; +import lol.pyr.znpcsplus.api.interaction.ActionRegistry; import lol.pyr.znpcsplus.api.npc.NpcRegistry; import lol.pyr.znpcsplus.api.npc.NpcTypeRegistry; import lol.pyr.znpcsplus.api.skin.SkinDescriptorFactory; @@ -27,6 +29,18 @@ public interface NpcApi { */ EntityPropertyRegistry getPropertyRegistry(); + /** + * Gets the action registry. + * @return the action registry + */ + ActionRegistry getActionRegistry(); + + /** + * Gets the action factory. + * @return the action factory + */ + ActionFactory getActionFactory(); + /** * Gets the skin descriptor factory. * @return the skin descriptor factory diff --git a/api/src/main/java/lol/pyr/znpcsplus/api/entity/PropertyHolder.java b/api/src/main/java/lol/pyr/znpcsplus/api/entity/PropertyHolder.java index 1180375..5de5ea9 100644 --- a/api/src/main/java/lol/pyr/znpcsplus/api/entity/PropertyHolder.java +++ b/api/src/main/java/lol/pyr/znpcsplus/api/entity/PropertyHolder.java @@ -48,6 +48,7 @@ public interface PropertyHolder { * when using item properties, read https://github.com/Pyrbu/ZNPCsPlus/pull/129#issuecomment-1948777764 * * @param key Unique key representing a property + * @return the {@link ItemStack} associated with the provided property key and this holder */ ItemStack getItemProperty(EntityProperty key); diff --git a/api/src/main/java/lol/pyr/znpcsplus/api/interaction/ActionFactory.java b/api/src/main/java/lol/pyr/znpcsplus/api/interaction/ActionFactory.java new file mode 100644 index 0000000..b896c5f --- /dev/null +++ b/api/src/main/java/lol/pyr/znpcsplus/api/interaction/ActionFactory.java @@ -0,0 +1,10 @@ +package lol.pyr.znpcsplus.api.interaction; + +@SuppressWarnings("unused") +public interface ActionFactory { + InteractionAction createConsoleCommandAction(String command, InteractionType interactionType, long cooldown, long delay); + InteractionAction createMessageAction(String message, InteractionType interactionType, long cooldown, long delay); + InteractionAction createPlayerChatAction(String message, InteractionType interactionType, long cooldown, long delay); + InteractionAction createPlayerCommandAction(String command, InteractionType interactionType, long cooldown, long delay); + InteractionAction createSwitchServerAction(String server, InteractionType interactionType, long cooldown, long delay); +} diff --git a/api/src/main/java/lol/pyr/znpcsplus/api/interaction/ActionRegistry.java b/api/src/main/java/lol/pyr/znpcsplus/api/interaction/ActionRegistry.java new file mode 100644 index 0000000..6f5cedb --- /dev/null +++ b/api/src/main/java/lol/pyr/znpcsplus/api/interaction/ActionRegistry.java @@ -0,0 +1,7 @@ +package lol.pyr.znpcsplus.api.interaction; + +public interface ActionRegistry { + void register(InteractionActionType type); + + void unregister(Class clazz); +} diff --git a/plugin/src/main/java/lol/pyr/znpcsplus/interaction/InteractionActionType.java b/api/src/main/java/lol/pyr/znpcsplus/api/interaction/InteractionActionType.java similarity index 76% rename from plugin/src/main/java/lol/pyr/znpcsplus/interaction/InteractionActionType.java rename to api/src/main/java/lol/pyr/znpcsplus/api/interaction/InteractionActionType.java index d8b6303..d8289fa 100644 --- a/plugin/src/main/java/lol/pyr/znpcsplus/interaction/InteractionActionType.java +++ b/api/src/main/java/lol/pyr/znpcsplus/api/interaction/InteractionActionType.java @@ -1,4 +1,4 @@ -package lol.pyr.znpcsplus.interaction; +package lol.pyr.znpcsplus.api.interaction; public interface InteractionActionType { String serialize(T obj); diff --git a/api/src/main/java/lol/pyr/znpcsplus/api/npc/Npc.java b/api/src/main/java/lol/pyr/znpcsplus/api/npc/Npc.java index 540cd05..4c3f61d 100644 --- a/api/src/main/java/lol/pyr/znpcsplus/api/npc/Npc.java +++ b/api/src/main/java/lol/pyr/znpcsplus/api/npc/Npc.java @@ -75,6 +75,31 @@ public interface Npc extends PropertyHolder { */ List getActions(); + /** + * Removes an action from this NPC + * @param index The index of the action to remove + */ + void removeAction(int index); + + /** + * Adds an action to this NPC + * @param action The {@link InteractionAction} to add + */ + void addAction(InteractionAction action); + + /** + * Edits an action for this NPC + * @param index The index of the action to edit + * @param action The {@link InteractionAction} to set + */ + void editAction(int index, InteractionAction action); + + + /** + * Clears all actions from this NPC + */ + void clearActions(); + /** * Gets if this NPC is visible to a player * @param player The {@link Player} to check diff --git a/plugin/src/main/java/lol/pyr/znpcsplus/ZNpcsPlus.java b/plugin/src/main/java/lol/pyr/znpcsplus/ZNpcsPlus.java index 4729f6f..c689923 100644 --- a/plugin/src/main/java/lol/pyr/znpcsplus/ZNpcsPlus.java +++ b/plugin/src/main/java/lol/pyr/znpcsplus/ZNpcsPlus.java @@ -27,7 +27,8 @@ import lol.pyr.znpcsplus.config.ConfigManager; import lol.pyr.znpcsplus.conversion.DataImporterRegistry; import lol.pyr.znpcsplus.entity.EntityPropertyImpl; import lol.pyr.znpcsplus.entity.EntityPropertyRegistryImpl; -import lol.pyr.znpcsplus.interaction.ActionRegistry; +import lol.pyr.znpcsplus.interaction.ActionFactoryImpl; +import lol.pyr.znpcsplus.interaction.ActionRegistryImpl; import lol.pyr.znpcsplus.interaction.InteractionPacketListener; import lol.pyr.znpcsplus.npc.*; import lol.pyr.znpcsplus.packets.*; @@ -117,7 +118,9 @@ public class ZNpcsPlus { PacketFactory packetFactory = setupPacketFactory(scheduler, propertyRegistry, configManager); propertyRegistry.registerTypes(bootstrap, packetFactory, textSerializer); - ActionRegistry actionRegistry = new ActionRegistry(); + BungeeConnector bungeeConnector = new BungeeConnector(bootstrap); + ActionRegistryImpl actionRegistry = new ActionRegistryImpl(); + ActionFactoryImpl actionFactory = new ActionFactoryImpl(scheduler, adventure, textSerializer, bungeeConnector); NpcTypeRegistryImpl typeRegistry = new NpcTypeRegistryImpl(); NpcRegistryImpl npcRegistry = new NpcRegistryImpl(configManager, this, packetFactory, actionRegistry, scheduler, typeRegistry, propertyRegistry, textSerializer); @@ -125,8 +128,7 @@ public class ZNpcsPlus { UserManager userManager = new UserManager(); shutdownTasks.add(userManager::shutdown); - - BungeeConnector bungeeConnector = new BungeeConnector(bootstrap); + DataImporterRegistry importerRegistry = new DataImporterRegistry(configManager, adventure, scheduler, packetFactory, textSerializer, typeRegistry, getDataFolder().getParentFile(), propertyRegistry, skinCache, npcRegistry, bungeeConnector); @@ -177,7 +179,7 @@ public class ZNpcsPlus { } } - NpcApiProvider.register(bootstrap, new ZNpcsPlusApi(npcRegistry, typeRegistry, propertyRegistry, skinCache)); + NpcApiProvider.register(bootstrap, new ZNpcsPlusApi(npcRegistry, typeRegistry, propertyRegistry, actionRegistry, actionFactory, skinCache)); log(ChatColor.WHITE + " * Loading complete! (" + (System.currentTimeMillis() - before) + "ms)"); log(""); @@ -227,7 +229,7 @@ public class ZNpcsPlus { } private void registerCommands(NpcRegistryImpl npcRegistry, MojangSkinCache skinCache, BukkitAudiences adventure, - ActionRegistry actionRegistry, NpcTypeRegistryImpl typeRegistry, + ActionRegistryImpl actionRegistry, NpcTypeRegistryImpl typeRegistry, EntityPropertyRegistryImpl propertyRegistry, DataImporterRegistry importerRegistry, ConfigManager configManager) { diff --git a/plugin/src/main/java/lol/pyr/znpcsplus/ZNpcsPlusApi.java b/plugin/src/main/java/lol/pyr/znpcsplus/ZNpcsPlusApi.java index 1a81e03..ef9c8ee 100644 --- a/plugin/src/main/java/lol/pyr/znpcsplus/ZNpcsPlusApi.java +++ b/plugin/src/main/java/lol/pyr/znpcsplus/ZNpcsPlusApi.java @@ -2,10 +2,14 @@ package lol.pyr.znpcsplus; import lol.pyr.znpcsplus.api.NpcApi; import lol.pyr.znpcsplus.api.entity.EntityPropertyRegistry; +import lol.pyr.znpcsplus.api.interaction.ActionFactory; +import lol.pyr.znpcsplus.api.interaction.ActionRegistry; import lol.pyr.znpcsplus.api.npc.NpcRegistry; import lol.pyr.znpcsplus.api.npc.NpcTypeRegistry; import lol.pyr.znpcsplus.api.skin.SkinDescriptorFactory; import lol.pyr.znpcsplus.entity.EntityPropertyRegistryImpl; +import lol.pyr.znpcsplus.interaction.ActionFactoryImpl; +import lol.pyr.znpcsplus.interaction.ActionRegistryImpl; import lol.pyr.znpcsplus.npc.NpcRegistryImpl; import lol.pyr.znpcsplus.npc.NpcTypeRegistryImpl; import lol.pyr.znpcsplus.skin.SkinDescriptorFactoryImpl; @@ -15,12 +19,16 @@ public class ZNpcsPlusApi implements NpcApi { private final NpcRegistryImpl npcRegistry; private final NpcTypeRegistryImpl typeRegistry; private final EntityPropertyRegistryImpl propertyRegistry; + private final ActionRegistryImpl actionRegistry; + private final ActionFactoryImpl actionFactory; private final SkinDescriptorFactoryImpl skinDescriptorFactory; - public ZNpcsPlusApi(NpcRegistryImpl npcRegistry, NpcTypeRegistryImpl typeRegistry, EntityPropertyRegistryImpl propertyRegistry, MojangSkinCache skinCache) { + public ZNpcsPlusApi(NpcRegistryImpl npcRegistry, NpcTypeRegistryImpl typeRegistry, EntityPropertyRegistryImpl propertyRegistry, ActionRegistryImpl actionRegistry, ActionFactoryImpl actionFactory, MojangSkinCache skinCache) { this.npcRegistry = npcRegistry; this.typeRegistry = typeRegistry; this.propertyRegistry = propertyRegistry; + this.actionRegistry = actionRegistry; + this.actionFactory = actionFactory; this.skinDescriptorFactory = new SkinDescriptorFactoryImpl(skinCache); } @@ -39,6 +47,17 @@ public class ZNpcsPlusApi implements NpcApi { return propertyRegistry; } + @Override + public ActionRegistry getActionRegistry() { + return actionRegistry; + } + + @Override + public ActionFactory getActionFactory() { + return actionFactory; + } + + @Override public SkinDescriptorFactory getSkinDescriptorFactory() { return skinDescriptorFactory; diff --git a/plugin/src/main/java/lol/pyr/znpcsplus/commands/action/ActionAddCommand.java b/plugin/src/main/java/lol/pyr/znpcsplus/commands/action/ActionAddCommand.java index 1d4efba..09b0749 100644 --- a/plugin/src/main/java/lol/pyr/znpcsplus/commands/action/ActionAddCommand.java +++ b/plugin/src/main/java/lol/pyr/znpcsplus/commands/action/ActionAddCommand.java @@ -3,7 +3,7 @@ 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.ActionRegistry; +import lol.pyr.znpcsplus.interaction.ActionRegistryImpl; import lol.pyr.znpcsplus.interaction.InteractionCommandHandler; import lol.pyr.znpcsplus.npc.NpcRegistryImpl; import net.kyori.adventure.text.Component; @@ -15,9 +15,9 @@ import java.util.stream.Collectors; public class ActionAddCommand implements CommandHandler { private final NpcRegistryImpl npcRegistry; - private final ActionRegistry actionRegistry; + private final ActionRegistryImpl actionRegistry; - public ActionAddCommand(NpcRegistryImpl npcRegistry, ActionRegistry actionRegistry) { + public ActionAddCommand(NpcRegistryImpl npcRegistry, ActionRegistryImpl actionRegistry) { this.npcRegistry = npcRegistry; this.actionRegistry = actionRegistry; } diff --git a/plugin/src/main/java/lol/pyr/znpcsplus/commands/action/ActionEditCommand.java b/plugin/src/main/java/lol/pyr/znpcsplus/commands/action/ActionEditCommand.java index 6bf1e21..0b0eafe 100644 --- a/plugin/src/main/java/lol/pyr/znpcsplus/commands/action/ActionEditCommand.java +++ b/plugin/src/main/java/lol/pyr/znpcsplus/commands/action/ActionEditCommand.java @@ -3,8 +3,8 @@ 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.ActionRegistry; -import lol.pyr.znpcsplus.interaction.InteractionActionImpl; +import lol.pyr.znpcsplus.api.interaction.InteractionAction; +import lol.pyr.znpcsplus.interaction.ActionRegistryImpl; import lol.pyr.znpcsplus.interaction.InteractionCommandHandler; import lol.pyr.znpcsplus.npc.NpcEntryImpl; import lol.pyr.znpcsplus.npc.NpcRegistryImpl; @@ -18,11 +18,11 @@ import java.util.stream.Stream; public class ActionEditCommand implements CommandHandler { private final NpcRegistryImpl npcRegistry; - private final ActionRegistry actionRegistry; + private final ActionRegistryImpl actionRegistry; private InteractionCommandHandler commandHandler = null; - public ActionEditCommand(NpcRegistryImpl npcRegistry, ActionRegistry actionRegistry) { + public ActionEditCommand(NpcRegistryImpl npcRegistry, ActionRegistryImpl actionRegistry) { this.npcRegistry = npcRegistry; this.actionRegistry = actionRegistry; } @@ -42,7 +42,7 @@ public class ActionEditCommand implements CommandHandler { context.send(Component.text("Invalid action type, available action types:\n" + commands.stream().map(InteractionCommandHandler::getSubcommandName).collect(Collectors.joining(", ")), NamedTextColor.RED)); } - InteractionActionImpl newAction = this.commandHandler.parse(context); + InteractionAction newAction = this.commandHandler.parse(context); entry.getNpc().editAction(index, newAction); context.send(Component.text("Edited action with index " + index + " of Npc " + entry.getId(), NamedTextColor.GREEN)); } 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 c4e0170..fe12bd9 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,6 +3,7 @@ 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.api.interaction.InteractionAction; import lol.pyr.znpcsplus.interaction.InteractionActionImpl; import lol.pyr.znpcsplus.npc.NpcEntryImpl; import lol.pyr.znpcsplus.npc.NpcRegistryImpl; @@ -21,10 +22,12 @@ public class ActionListCommand implements CommandHandler { public void run(CommandContext context) throws CommandExecutionException { context.setUsage(context.getLabel() + " action list "); NpcEntryImpl entry = context.parse(NpcEntryImpl.class); - List actions = entry.getNpc().getActions(); + 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)); + if (actions.get(i) instanceof InteractionActionImpl) { + context.send(((InteractionActionImpl) actions.get(i)).getInfo(entry.getId(), i, context)); + } } } diff --git a/plugin/src/main/java/lol/pyr/znpcsplus/conversion/citizens/model/traits/CommandTrait.java b/plugin/src/main/java/lol/pyr/znpcsplus/conversion/citizens/model/traits/CommandTrait.java index 08c2ee0..e6629f8 100644 --- a/plugin/src/main/java/lol/pyr/znpcsplus/conversion/citizens/model/traits/CommandTrait.java +++ b/plugin/src/main/java/lol/pyr/znpcsplus/conversion/citizens/model/traits/CommandTrait.java @@ -1,8 +1,8 @@ package lol.pyr.znpcsplus.conversion.citizens.model.traits; +import lol.pyr.znpcsplus.api.interaction.InteractionAction; import lol.pyr.znpcsplus.api.interaction.InteractionType; import lol.pyr.znpcsplus.conversion.citizens.model.SectionCitizensTrait; -import lol.pyr.znpcsplus.interaction.InteractionActionImpl; import lol.pyr.znpcsplus.interaction.consolecommand.ConsoleCommandAction; import lol.pyr.znpcsplus.interaction.playercommand.PlayerCommandAction; import lol.pyr.znpcsplus.npc.NpcImpl; @@ -35,7 +35,7 @@ public class CommandTrait extends SectionCitizensTrait { int cooldown = commandSection.getInt("cooldown", 0); int delay = commandSection.getInt("delay", 0); if (command != null) { - InteractionActionImpl action; + InteractionAction action; if (isPlayerCommand) { action = new PlayerCommandAction(scheduler, command, clickType, cooldown, delay); } else { diff --git a/plugin/src/main/java/lol/pyr/znpcsplus/conversion/fancynpcs/FancyNpcsImporter.java b/plugin/src/main/java/lol/pyr/znpcsplus/conversion/fancynpcs/FancyNpcsImporter.java index c264300..b5c981a 100644 --- a/plugin/src/main/java/lol/pyr/znpcsplus/conversion/fancynpcs/FancyNpcsImporter.java +++ b/plugin/src/main/java/lol/pyr/znpcsplus/conversion/fancynpcs/FancyNpcsImporter.java @@ -143,7 +143,7 @@ public class FancyNpcsImporter implements DataImporter { if (!messages.isEmpty()) { long cooldown = npcSection.getLong("interactionCooldown", 0); for (String message : messages) { - npc.addAction(new MessageAction(adventure, message, InteractionType.ANY_CLICK, textSerializer, cooldown, 0)); + npc.addAction(new MessageAction(adventure, textSerializer, message, InteractionType.ANY_CLICK, cooldown, 0)); } } String id = npcSection.getString("name"); diff --git a/plugin/src/main/java/lol/pyr/znpcsplus/conversion/znpcs/ZNpcImporter.java b/plugin/src/main/java/lol/pyr/znpcsplus/conversion/znpcs/ZNpcImporter.java index fa763c4..dccf704 100644 --- a/plugin/src/main/java/lol/pyr/znpcsplus/conversion/znpcs/ZNpcImporter.java +++ b/plugin/src/main/java/lol/pyr/znpcsplus/conversion/znpcs/ZNpcImporter.java @@ -4,6 +4,7 @@ import com.google.gson.Gson; import com.google.gson.GsonBuilder; import com.google.gson.JsonElement; import com.google.gson.JsonParser; +import lol.pyr.znpcsplus.api.interaction.InteractionAction; import lol.pyr.znpcsplus.api.interaction.InteractionType; import lol.pyr.znpcsplus.api.skin.SkinDescriptor; import lol.pyr.znpcsplus.config.ConfigManager; @@ -12,7 +13,6 @@ import lol.pyr.znpcsplus.conversion.znpcs.model.*; import lol.pyr.znpcsplus.entity.EntityPropertyImpl; import lol.pyr.znpcsplus.entity.EntityPropertyRegistryImpl; import lol.pyr.znpcsplus.hologram.HologramImpl; -import lol.pyr.znpcsplus.interaction.InteractionActionImpl; import lol.pyr.znpcsplus.interaction.consolecommand.ConsoleCommandAction; import lol.pyr.znpcsplus.interaction.message.MessageAction; import lol.pyr.znpcsplus.interaction.playerchat.PlayerChatAction; @@ -146,7 +146,7 @@ public class ZNpcImporter implements DataImporter { for (String line : lines) { // Create a new message action for each line of text - InteractionActionImpl action = new MessageAction(adventure, line, InteractionType.ANY_CLICK, textSerializer, 0, totalDelay); + InteractionAction action = new MessageAction(adventure, textSerializer, line, InteractionType.ANY_CLICK, 0, totalDelay); npc.addAction(action); } } @@ -222,7 +222,7 @@ public class ZNpcImporter implements DataImporter { throw new IllegalArgumentException("Couldn't adapt znpcs click type: " + clickType); } - private InteractionActionImpl adaptAction(String type, InteractionType clickType, String parameter, int cooldown) { + private InteractionAction adaptAction(String type, InteractionType clickType, String parameter, int cooldown) { switch (type.toLowerCase()) { case "cmd": return new PlayerCommandAction(taskScheduler, parameter, clickType, cooldown * 1000L, 0); @@ -231,9 +231,9 @@ public class ZNpcImporter implements DataImporter { case "chat": return new PlayerChatAction(taskScheduler, parameter, clickType, cooldown * 1000L, 0); case "message": - return new MessageAction(adventure, parameter, clickType, textSerializer, cooldown * 1000L, 0); + return new MessageAction(adventure, textSerializer, parameter, clickType, cooldown * 1000L, 0); case "server": - return new SwitchServerAction(parameter, clickType, cooldown * 1000L, 0, bungeeConnector); + return new SwitchServerAction(bungeeConnector, parameter, clickType, cooldown * 1000L, 0); } throw new IllegalArgumentException("Couldn't adapt znpcs click action: " + type); } diff --git a/plugin/src/main/java/lol/pyr/znpcsplus/interaction/ActionFactoryImpl.java b/plugin/src/main/java/lol/pyr/znpcsplus/interaction/ActionFactoryImpl.java new file mode 100644 index 0000000..1e58967 --- /dev/null +++ b/plugin/src/main/java/lol/pyr/znpcsplus/interaction/ActionFactoryImpl.java @@ -0,0 +1,48 @@ +package lol.pyr.znpcsplus.interaction; + +import lol.pyr.znpcsplus.api.interaction.ActionFactory; +import lol.pyr.znpcsplus.api.interaction.InteractionAction; +import lol.pyr.znpcsplus.api.interaction.InteractionType; +import lol.pyr.znpcsplus.interaction.consolecommand.ConsoleCommandAction; +import lol.pyr.znpcsplus.interaction.message.MessageAction; +import lol.pyr.znpcsplus.interaction.playerchat.PlayerChatAction; +import lol.pyr.znpcsplus.interaction.playercommand.PlayerCommandAction; +import lol.pyr.znpcsplus.interaction.switchserver.SwitchServerAction; +import lol.pyr.znpcsplus.scheduling.TaskScheduler; +import lol.pyr.znpcsplus.util.BungeeConnector; +import net.kyori.adventure.platform.bukkit.BukkitAudiences; +import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer; + +public class ActionFactoryImpl implements ActionFactory { + private final TaskScheduler scheduler; + private final BukkitAudiences adventure; + private final LegacyComponentSerializer textSerializer; + private final BungeeConnector bungeeConnector; + + public ActionFactoryImpl(TaskScheduler scheduler, BukkitAudiences adventure, LegacyComponentSerializer textSerializer, BungeeConnector bungeeConnector) { + this.scheduler = scheduler; + this.adventure = adventure; + this.textSerializer = textSerializer; + this.bungeeConnector = bungeeConnector; + } + + public InteractionAction createConsoleCommandAction(String command, InteractionType interactionType, long cooldown, long delay) { + return new ConsoleCommandAction(this.scheduler, command, interactionType, cooldown, delay); + } + + public InteractionAction createMessageAction(String message, InteractionType interactionType, long cooldown, long delay) { + return new MessageAction(this.adventure, textSerializer, message, interactionType, cooldown, delay); + } + + public InteractionAction createPlayerChatAction(String message, InteractionType interactionType, long cooldown, long delay) { + return new PlayerChatAction(this.scheduler, message, interactionType, cooldown, delay); + } + + public InteractionAction createPlayerCommandAction(String command, InteractionType interactionType, long cooldown, long delay) { + return new PlayerCommandAction(this.scheduler, command, interactionType, cooldown, delay); + } + + public InteractionAction createSwitchServerAction(String server, InteractionType interactionType, long cooldown, long delay) { + return new SwitchServerAction(bungeeConnector, server, interactionType, cooldown, delay); + } +} diff --git a/plugin/src/main/java/lol/pyr/znpcsplus/interaction/ActionRegistry.java b/plugin/src/main/java/lol/pyr/znpcsplus/interaction/ActionRegistryImpl.java similarity index 95% rename from plugin/src/main/java/lol/pyr/znpcsplus/interaction/ActionRegistry.java rename to plugin/src/main/java/lol/pyr/znpcsplus/interaction/ActionRegistryImpl.java index dacc909..b08ae1c 100644 --- a/plugin/src/main/java/lol/pyr/znpcsplus/interaction/ActionRegistry.java +++ b/plugin/src/main/java/lol/pyr/znpcsplus/interaction/ActionRegistryImpl.java @@ -1,6 +1,6 @@ package lol.pyr.znpcsplus.interaction; -import lol.pyr.znpcsplus.api.interaction.InteractionAction; +import lol.pyr.znpcsplus.api.interaction.*; import lol.pyr.znpcsplus.interaction.consolecommand.ConsoleCommandActionType; import lol.pyr.znpcsplus.interaction.message.MessageActionType; import lol.pyr.znpcsplus.interaction.playerchat.PlayerChatActionType; @@ -17,12 +17,9 @@ import java.util.List; import java.util.Map; import java.util.stream.Collectors; -public class ActionRegistry { +public class ActionRegistryImpl implements ActionRegistry { private final Map, InteractionActionType> serializerMap = new HashMap<>(); - public ActionRegistry() { - } - public void registerTypes(TaskScheduler taskScheduler, BukkitAudiences adventure, LegacyComponentSerializer textSerializer, BungeeConnector bungeeConnector) { register(new ConsoleCommandActionType(taskScheduler)); register(new PlayerCommandActionType(taskScheduler)); diff --git a/plugin/src/main/java/lol/pyr/znpcsplus/interaction/InteractionCommandHandler.java b/plugin/src/main/java/lol/pyr/znpcsplus/interaction/InteractionCommandHandler.java index b99b37d..93d1fbc 100644 --- a/plugin/src/main/java/lol/pyr/znpcsplus/interaction/InteractionCommandHandler.java +++ b/plugin/src/main/java/lol/pyr/znpcsplus/interaction/InteractionCommandHandler.java @@ -3,6 +3,7 @@ package lol.pyr.znpcsplus.interaction; 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.api.interaction.InteractionAction; import lol.pyr.znpcsplus.npc.NpcEntryImpl; import lol.pyr.znpcsplus.npc.NpcImpl; import net.kyori.adventure.text.Component; @@ -11,7 +12,7 @@ import net.kyori.adventure.text.format.NamedTextColor; public interface InteractionCommandHandler extends CommandHandler { String getSubcommandName(); - InteractionActionImpl parse(CommandContext context) throws CommandExecutionException; + InteractionAction parse(CommandContext context) throws CommandExecutionException; void appendUsage(CommandContext context); @Override diff --git a/plugin/src/main/java/lol/pyr/znpcsplus/interaction/consolecommand/ConsoleCommandActionType.java b/plugin/src/main/java/lol/pyr/znpcsplus/interaction/consolecommand/ConsoleCommandActionType.java index 2461dc1..725f4fa 100644 --- a/plugin/src/main/java/lol/pyr/znpcsplus/interaction/consolecommand/ConsoleCommandActionType.java +++ b/plugin/src/main/java/lol/pyr/znpcsplus/interaction/consolecommand/ConsoleCommandActionType.java @@ -4,7 +4,7 @@ import lol.pyr.director.adventure.command.CommandContext; import lol.pyr.director.common.command.CommandExecutionException; import lol.pyr.znpcsplus.api.interaction.InteractionType; import lol.pyr.znpcsplus.interaction.InteractionActionImpl; -import lol.pyr.znpcsplus.interaction.InteractionActionType; +import lol.pyr.znpcsplus.api.interaction.InteractionActionType; import lol.pyr.znpcsplus.interaction.InteractionCommandHandler; import lol.pyr.znpcsplus.scheduling.TaskScheduler; 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 2382275..051bea5 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 @@ -17,7 +17,7 @@ public class MessageAction extends InteractionActionImpl { private final String message; private final LegacyComponentSerializer textSerializer; - public MessageAction(BukkitAudiences adventure, String message, InteractionType interactionType, LegacyComponentSerializer textSerializer, long cooldown, long delay) { + public MessageAction(BukkitAudiences adventure, LegacyComponentSerializer textSerializer, String message, InteractionType interactionType, long cooldown, long delay) { super(cooldown, delay, interactionType); this.adventure = adventure; this.message = message; diff --git a/plugin/src/main/java/lol/pyr/znpcsplus/interaction/message/MessageActionType.java b/plugin/src/main/java/lol/pyr/znpcsplus/interaction/message/MessageActionType.java index 5a004ac..54dbfae 100644 --- a/plugin/src/main/java/lol/pyr/znpcsplus/interaction/message/MessageActionType.java +++ b/plugin/src/main/java/lol/pyr/znpcsplus/interaction/message/MessageActionType.java @@ -4,7 +4,7 @@ import lol.pyr.director.adventure.command.CommandContext; import lol.pyr.director.common.command.CommandExecutionException; import lol.pyr.znpcsplus.api.interaction.InteractionType; import lol.pyr.znpcsplus.interaction.InteractionActionImpl; -import lol.pyr.znpcsplus.interaction.InteractionActionType; +import lol.pyr.znpcsplus.api.interaction.InteractionActionType; import lol.pyr.znpcsplus.interaction.InteractionCommandHandler; import net.kyori.adventure.platform.bukkit.BukkitAudiences; import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer; @@ -32,7 +32,7 @@ public class MessageActionType implements InteractionActionType, public MessageAction deserialize(String str) { String[] split = str.split(";"); InteractionType type = split.length > 2 ? InteractionType.valueOf(split[2]) : InteractionType.ANY_CLICK; - return new MessageAction(adventure, new String(Base64.getDecoder().decode(split[0]), StandardCharsets.UTF_8), type, textSerializer, Long.parseLong(split[1]), Long.parseLong(split.length > 3 ? split[3] : "0")); + return new MessageAction(adventure, textSerializer, new String(Base64.getDecoder().decode(split[0]), StandardCharsets.UTF_8), type, Long.parseLong(split[1]), Long.parseLong(split.length > 3 ? split[3] : "0")); } @Override @@ -56,7 +56,7 @@ public class MessageActionType implements InteractionActionType, long cooldown = (long) (context.parse(Double.class) * 1000D); long delay = (long) (context.parse(Integer.class) * 1D); String message = context.dumpAllArgs(); - return new MessageAction(adventure, message, type, textSerializer, cooldown, delay); + return new MessageAction(adventure, textSerializer, message, type, cooldown, delay); } @Override diff --git a/plugin/src/main/java/lol/pyr/znpcsplus/interaction/playerchat/PlayerChatActionType.java b/plugin/src/main/java/lol/pyr/znpcsplus/interaction/playerchat/PlayerChatActionType.java index c21ef83..a8ca987 100644 --- a/plugin/src/main/java/lol/pyr/znpcsplus/interaction/playerchat/PlayerChatActionType.java +++ b/plugin/src/main/java/lol/pyr/znpcsplus/interaction/playerchat/PlayerChatActionType.java @@ -2,9 +2,9 @@ package lol.pyr.znpcsplus.interaction.playerchat; import lol.pyr.director.adventure.command.CommandContext; import lol.pyr.director.common.command.CommandExecutionException; +import lol.pyr.znpcsplus.api.interaction.InteractionAction; +import lol.pyr.znpcsplus.api.interaction.InteractionActionType; import lol.pyr.znpcsplus.api.interaction.InteractionType; -import lol.pyr.znpcsplus.interaction.InteractionActionImpl; -import lol.pyr.znpcsplus.interaction.InteractionActionType; import lol.pyr.znpcsplus.interaction.InteractionCommandHandler; import lol.pyr.znpcsplus.scheduling.TaskScheduler; @@ -47,7 +47,7 @@ public class PlayerChatActionType implements InteractionActionType 2 ? InteractionType.valueOf(split[2]) : InteractionType.ANY_CLICK; - return new SwitchServerAction(new String(Base64.getDecoder().decode(split[0]), StandardCharsets.UTF_8), type, Long.parseLong(split[1]), Long.parseLong(split.length > 3 ? split[3] : "0"), bungeeConnector); + return new SwitchServerAction(bungeeConnector, new String(Base64.getDecoder().decode(split[0]), StandardCharsets.UTF_8), type, Long.parseLong(split[1]), Long.parseLong(split.length > 3 ? split[3] : "0")); } @Override @@ -53,7 +53,7 @@ public class SwitchServerActionType implements InteractionActionType, Object> propertyMap = new HashMap<>(); - private final List actions = new ArrayList<>(); + private final List actions = new ArrayList<>(); 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); @@ -200,23 +200,28 @@ public class NpcImpl extends Viewable implements Npc { return Collections.unmodifiableSet(propertyMap.keySet()).stream().filter(type::isAllowedProperty).collect(Collectors.toSet()); } - public List getActions() { + @Override + public List getActions() { return Collections.unmodifiableList(actions); } + @Override public void removeAction(int index) { actions.remove(index); } + @Override + public void addAction(InteractionAction action) { + actions.add(action); + } + + @Override public void clearActions() { actions.clear(); } - public void addAction(InteractionActionImpl action) { - actions.add(action); - } - - public void editAction(int index, InteractionActionImpl action) { + @Override + public void editAction(int index, InteractionAction action) { actions.set(index, action); } diff --git a/plugin/src/main/java/lol/pyr/znpcsplus/npc/NpcRegistryImpl.java b/plugin/src/main/java/lol/pyr/znpcsplus/npc/NpcRegistryImpl.java index bcdea13..45a50f9 100644 --- a/plugin/src/main/java/lol/pyr/znpcsplus/npc/NpcRegistryImpl.java +++ b/plugin/src/main/java/lol/pyr/znpcsplus/npc/NpcRegistryImpl.java @@ -2,6 +2,7 @@ package lol.pyr.znpcsplus.npc; import lol.pyr.znpcsplus.ZNpcsPlus; import lol.pyr.znpcsplus.api.entity.EntityProperty; +import lol.pyr.znpcsplus.api.interaction.InteractionAction; import lol.pyr.znpcsplus.api.npc.NpcEntry; import lol.pyr.znpcsplus.api.npc.NpcRegistry; import lol.pyr.znpcsplus.api.npc.NpcType; @@ -10,8 +11,7 @@ import lol.pyr.znpcsplus.entity.EntityPropertyRegistryImpl; import lol.pyr.znpcsplus.hologram.HologramItem; import lol.pyr.znpcsplus.hologram.HologramLine; import lol.pyr.znpcsplus.hologram.HologramText; -import lol.pyr.znpcsplus.interaction.ActionRegistry; -import lol.pyr.znpcsplus.interaction.InteractionActionImpl; +import lol.pyr.znpcsplus.interaction.ActionRegistryImpl; import lol.pyr.znpcsplus.packets.PacketFactory; import lol.pyr.znpcsplus.scheduling.TaskScheduler; import lol.pyr.znpcsplus.storage.NpcStorage; @@ -35,7 +35,7 @@ public class NpcRegistryImpl implements NpcRegistry { private final Map npcIdLookupMap = new HashMap<>(); private final Map npcUuidLookupMap = new HashMap<>(); - public NpcRegistryImpl(ConfigManager configManager, ZNpcsPlus plugin, PacketFactory packetFactory, ActionRegistry actionRegistry, TaskScheduler scheduler, NpcTypeRegistryImpl typeRegistry, EntityPropertyRegistryImpl propertyRegistry, LegacyComponentSerializer textSerializer) { + public NpcRegistryImpl(ConfigManager configManager, ZNpcsPlus plugin, PacketFactory packetFactory, ActionRegistryImpl actionRegistry, TaskScheduler scheduler, NpcTypeRegistryImpl typeRegistry, EntityPropertyRegistryImpl propertyRegistry, LegacyComponentSerializer textSerializer) { this.textSerializer = textSerializer; this.propertyRegistry = propertyRegistry; storage = configManager.getConfig().storageType().create(configManager, plugin, packetFactory, actionRegistry, typeRegistry, propertyRegistry, textSerializer); @@ -168,7 +168,7 @@ public class NpcRegistryImpl implements NpcRegistry { newNpc.getNpc().UNSAFE_setProperty(property, oldNpc.getNpc().getProperty(property)); } - for (InteractionActionImpl action : oldNpc.getNpc().getActions()) { + for (InteractionAction action : oldNpc.getNpc().getActions()) { newNpc.getNpc().addAction(action); } diff --git a/plugin/src/main/java/lol/pyr/znpcsplus/storage/NpcStorageType.java b/plugin/src/main/java/lol/pyr/znpcsplus/storage/NpcStorageType.java index 93c421b..5205dfc 100644 --- a/plugin/src/main/java/lol/pyr/znpcsplus/storage/NpcStorageType.java +++ b/plugin/src/main/java/lol/pyr/znpcsplus/storage/NpcStorageType.java @@ -3,7 +3,7 @@ package lol.pyr.znpcsplus.storage; import lol.pyr.znpcsplus.ZNpcsPlus; import lol.pyr.znpcsplus.config.ConfigManager; import lol.pyr.znpcsplus.entity.EntityPropertyRegistryImpl; -import lol.pyr.znpcsplus.interaction.ActionRegistry; +import lol.pyr.znpcsplus.interaction.ActionRegistryImpl; import lol.pyr.znpcsplus.npc.NpcTypeRegistryImpl; import lol.pyr.znpcsplus.packets.PacketFactory; import lol.pyr.znpcsplus.storage.mysql.MySQLStorage; @@ -16,13 +16,13 @@ import java.io.File; public enum NpcStorageType { YAML { @Override - public NpcStorage create(ConfigManager configManager, ZNpcsPlus plugin, PacketFactory packetFactory, ActionRegistry actionRegistry, NpcTypeRegistryImpl typeRegistry, EntityPropertyRegistryImpl propertyRegistry, LegacyComponentSerializer textSerializer) { + public NpcStorage create(ConfigManager configManager, ZNpcsPlus plugin, PacketFactory packetFactory, ActionRegistryImpl actionRegistry, NpcTypeRegistryImpl typeRegistry, EntityPropertyRegistryImpl propertyRegistry, LegacyComponentSerializer textSerializer) { return new YamlStorage(packetFactory, configManager, actionRegistry, typeRegistry, propertyRegistry, textSerializer, new File(plugin.getDataFolder(), "data")); } }, SQLITE { @Override - public NpcStorage create(ConfigManager configManager, ZNpcsPlus plugin, PacketFactory packetFactory, ActionRegistry actionRegistry, NpcTypeRegistryImpl typeRegistry, EntityPropertyRegistryImpl propertyRegistry, LegacyComponentSerializer textSerializer) { + public NpcStorage create(ConfigManager configManager, ZNpcsPlus plugin, PacketFactory packetFactory, ActionRegistryImpl actionRegistry, NpcTypeRegistryImpl typeRegistry, EntityPropertyRegistryImpl propertyRegistry, LegacyComponentSerializer textSerializer) { try { return new SQLiteStorage(packetFactory, configManager, actionRegistry, typeRegistry, propertyRegistry, textSerializer, new File(plugin.getDataFolder(), "znpcsplus.sqlite")); } catch (Exception e) { @@ -33,7 +33,7 @@ public enum NpcStorageType { }, MYSQL { @Override - public NpcStorage create(ConfigManager configManager, ZNpcsPlus plugin, PacketFactory packetFactory, ActionRegistry actionRegistry, NpcTypeRegistryImpl typeRegistry, EntityPropertyRegistryImpl propertyRegistry, LegacyComponentSerializer textSerializer) { + public NpcStorage create(ConfigManager configManager, ZNpcsPlus plugin, PacketFactory packetFactory, ActionRegistryImpl actionRegistry, NpcTypeRegistryImpl typeRegistry, EntityPropertyRegistryImpl propertyRegistry, LegacyComponentSerializer textSerializer) { try { return new MySQLStorage(packetFactory, configManager, actionRegistry, typeRegistry, propertyRegistry, textSerializer); } catch (Exception e) { @@ -43,5 +43,5 @@ public enum NpcStorageType { } }; - public abstract NpcStorage create(ConfigManager configManager, ZNpcsPlus plugin, PacketFactory packetFactory, ActionRegistry actionRegistry, NpcTypeRegistryImpl typeRegistry, EntityPropertyRegistryImpl propertyRegistry, LegacyComponentSerializer textSerializer); + public abstract NpcStorage create(ConfigManager configManager, ZNpcsPlus plugin, PacketFactory packetFactory, ActionRegistryImpl actionRegistry, NpcTypeRegistryImpl typeRegistry, EntityPropertyRegistryImpl propertyRegistry, LegacyComponentSerializer textSerializer); } diff --git a/plugin/src/main/java/lol/pyr/znpcsplus/storage/mysql/MySQLStorage.java b/plugin/src/main/java/lol/pyr/znpcsplus/storage/mysql/MySQLStorage.java index 190b6b3..d1aa805 100644 --- a/plugin/src/main/java/lol/pyr/znpcsplus/storage/mysql/MySQLStorage.java +++ b/plugin/src/main/java/lol/pyr/znpcsplus/storage/mysql/MySQLStorage.java @@ -6,7 +6,7 @@ import lol.pyr.znpcsplus.entity.EntityPropertyImpl; import lol.pyr.znpcsplus.entity.EntityPropertyRegistryImpl; import lol.pyr.znpcsplus.entity.PropertySerializer; import lol.pyr.znpcsplus.hologram.HologramImpl; -import lol.pyr.znpcsplus.interaction.ActionRegistry; +import lol.pyr.znpcsplus.interaction.ActionRegistryImpl; import lol.pyr.znpcsplus.npc.NpcEntryImpl; import lol.pyr.znpcsplus.npc.NpcImpl; import lol.pyr.znpcsplus.npc.NpcTypeRegistryImpl; @@ -28,7 +28,7 @@ public class MySQLStorage implements NpcStorage { private final PacketFactory packetFactory; private final ConfigManager configManager; - private final ActionRegistry actionRegistry; + private final ActionRegistryImpl actionRegistry; private final NpcTypeRegistryImpl typeRegistry; private final EntityPropertyRegistryImpl propertyRegistry; private final LegacyComponentSerializer textSerializer; @@ -39,7 +39,7 @@ public class MySQLStorage implements NpcStorage { private final String TABLE_NPCS_HOLOGRAMS; private final String TABLE_NPCS_ACTIONS; - public MySQLStorage(PacketFactory packetFactory, ConfigManager configManager, ActionRegistry actionRegistry, NpcTypeRegistryImpl typeRegistry, EntityPropertyRegistryImpl propertyRegistry, LegacyComponentSerializer textSerializer) { + public MySQLStorage(PacketFactory packetFactory, ConfigManager configManager, ActionRegistryImpl actionRegistry, NpcTypeRegistryImpl typeRegistry, EntityPropertyRegistryImpl propertyRegistry, LegacyComponentSerializer textSerializer) { this.packetFactory = packetFactory; this.configManager = configManager; this.actionRegistry = actionRegistry; diff --git a/plugin/src/main/java/lol/pyr/znpcsplus/storage/sqlite/SQLiteStorage.java b/plugin/src/main/java/lol/pyr/znpcsplus/storage/sqlite/SQLiteStorage.java index 005169a..2eb004e 100644 --- a/plugin/src/main/java/lol/pyr/znpcsplus/storage/sqlite/SQLiteStorage.java +++ b/plugin/src/main/java/lol/pyr/znpcsplus/storage/sqlite/SQLiteStorage.java @@ -6,7 +6,7 @@ import lol.pyr.znpcsplus.entity.EntityPropertyImpl; import lol.pyr.znpcsplus.entity.EntityPropertyRegistryImpl; import lol.pyr.znpcsplus.entity.PropertySerializer; import lol.pyr.znpcsplus.hologram.HologramImpl; -import lol.pyr.znpcsplus.interaction.ActionRegistry; +import lol.pyr.znpcsplus.interaction.ActionRegistryImpl; import lol.pyr.znpcsplus.npc.NpcEntryImpl; import lol.pyr.znpcsplus.npc.NpcImpl; import lol.pyr.znpcsplus.npc.NpcTypeRegistryImpl; @@ -29,7 +29,7 @@ public class SQLiteStorage implements NpcStorage { private final PacketFactory packetFactory; private final ConfigManager configManager; - private final ActionRegistry actionRegistry; + private final ActionRegistryImpl actionRegistry; private final NpcTypeRegistryImpl typeRegistry; private final EntityPropertyRegistryImpl propertyRegistry; private final LegacyComponentSerializer textSerializer; @@ -40,7 +40,7 @@ public class SQLiteStorage implements NpcStorage { private final String TABLE_NPCS_HOLOGRAMS; private final String TABLE_NPCS_ACTIONS; - public SQLiteStorage(PacketFactory packetFactory, ConfigManager configManager, ActionRegistry actionRegistry, NpcTypeRegistryImpl typeRegistry, EntityPropertyRegistryImpl propertyRegistry, LegacyComponentSerializer textSerializer, File file) { + public SQLiteStorage(PacketFactory packetFactory, ConfigManager configManager, ActionRegistryImpl actionRegistry, NpcTypeRegistryImpl typeRegistry, EntityPropertyRegistryImpl propertyRegistry, LegacyComponentSerializer textSerializer, File file) { this.packetFactory = packetFactory; this.configManager = configManager; this.actionRegistry = actionRegistry; diff --git a/plugin/src/main/java/lol/pyr/znpcsplus/storage/yaml/YamlStorage.java b/plugin/src/main/java/lol/pyr/znpcsplus/storage/yaml/YamlStorage.java index 0bb08b8..55e46dd 100644 --- a/plugin/src/main/java/lol/pyr/znpcsplus/storage/yaml/YamlStorage.java +++ b/plugin/src/main/java/lol/pyr/znpcsplus/storage/yaml/YamlStorage.java @@ -6,7 +6,7 @@ import lol.pyr.znpcsplus.entity.EntityPropertyImpl; import lol.pyr.znpcsplus.entity.EntityPropertyRegistryImpl; import lol.pyr.znpcsplus.entity.PropertySerializer; import lol.pyr.znpcsplus.hologram.HologramImpl; -import lol.pyr.znpcsplus.interaction.ActionRegistry; +import lol.pyr.znpcsplus.interaction.ActionRegistryImpl; import lol.pyr.znpcsplus.npc.NpcEntryImpl; import lol.pyr.znpcsplus.npc.NpcImpl; import lol.pyr.znpcsplus.npc.NpcTypeRegistryImpl; @@ -29,13 +29,13 @@ public class YamlStorage implements NpcStorage { private final PacketFactory packetFactory; private final ConfigManager configManager; - private final ActionRegistry actionRegistry; + private final ActionRegistryImpl actionRegistry; private final NpcTypeRegistryImpl typeRegistry; private final EntityPropertyRegistryImpl propertyRegistry; private final LegacyComponentSerializer textSerializer; private final File folder; - public YamlStorage(PacketFactory packetFactory, ConfigManager configManager, ActionRegistry actionRegistry, NpcTypeRegistryImpl typeRegistry, EntityPropertyRegistryImpl propertyRegistry, LegacyComponentSerializer textSerializer, File folder) { + public YamlStorage(PacketFactory packetFactory, ConfigManager configManager, ActionRegistryImpl actionRegistry, NpcTypeRegistryImpl typeRegistry, EntityPropertyRegistryImpl propertyRegistry, LegacyComponentSerializer textSerializer, File folder) { this.packetFactory = packetFactory; this.configManager = configManager; this.actionRegistry = actionRegistry; From 4d54dd851288bde605ed87868e62f3263f7065c6 Mon Sep 17 00:00:00 2001 From: D3v1s0m Date: Tue, 11 Jun 2024 21:31:00 +0530 Subject: [PATCH 2/7] %blank% for empty hologram line --- .../java/lol/pyr/znpcsplus/hologram/HologramText.java | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/plugin/src/main/java/lol/pyr/znpcsplus/hologram/HologramText.java b/plugin/src/main/java/lol/pyr/znpcsplus/hologram/HologramText.java index 2c66aef..47e5e91 100644 --- a/plugin/src/main/java/lol/pyr/znpcsplus/hologram/HologramText.java +++ b/plugin/src/main/java/lol/pyr/znpcsplus/hologram/HologramText.java @@ -6,15 +6,25 @@ import lol.pyr.znpcsplus.entity.EntityPropertyRegistryImpl; import lol.pyr.znpcsplus.packets.PacketFactory; import lol.pyr.znpcsplus.util.NpcLocation; import net.kyori.adventure.text.Component; +import org.bukkit.entity.Player; public class HologramText extends HologramLine { + private static final Component BLANK = Component.text("%blank%"); + public HologramText(EntityPropertyRegistryImpl propertyRegistry, PacketFactory packetFactory, NpcLocation location, Component text) { super(text, packetFactory, EntityTypes.ARMOR_STAND, location); addProperty(propertyRegistry.getByName("name")); addProperty(propertyRegistry.getByName("invisible")); } + @Override + public void show(Player player) { + if (!getValue().equals(BLANK)) { + super.show(player); + } + } + @SuppressWarnings("unchecked") @Override public T getProperty(EntityProperty key) { From 7afadc15eae30a411210540a76726b022c425a41 Mon Sep 17 00:00:00 2001 From: D3v1s0m Date: Mon, 24 Jun 2024 16:24:21 +0530 Subject: [PATCH 3/7] small action command(s) fix --- .../java/lol/pyr/znpcsplus/interaction/ActionRegistryImpl.java | 1 + 1 file changed, 1 insertion(+) diff --git a/plugin/src/main/java/lol/pyr/znpcsplus/interaction/ActionRegistryImpl.java b/plugin/src/main/java/lol/pyr/znpcsplus/interaction/ActionRegistryImpl.java index b08ae1c..15bdb01 100644 --- a/plugin/src/main/java/lol/pyr/znpcsplus/interaction/ActionRegistryImpl.java +++ b/plugin/src/main/java/lol/pyr/znpcsplus/interaction/ActionRegistryImpl.java @@ -38,6 +38,7 @@ public class ActionRegistryImpl implements ActionRegistry { public List getCommands() { return serializerMap.values().stream() + .filter(type -> type instanceof InteractionActionImpl) .filter(type -> type instanceof InteractionCommandHandler) .map(type -> (InteractionCommandHandler) type) .collect(Collectors.toList()); From d9faee043ce36046eac5f476a1873047f354925f Mon Sep 17 00:00:00 2001 From: D3v1s0m Date: Mon, 24 Jun 2024 16:25:20 +0530 Subject: [PATCH 4/7] partial fix for help message --- plugin/src/main/resources/messages/root-hover/center.txt | 2 +- plugin/src/main/resources/messages/root-hover/setlocation.txt | 2 +- plugin/src/main/resources/messages/root-hover/setrotation.txt | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/plugin/src/main/resources/messages/root-hover/center.txt b/plugin/src/main/resources/messages/root-hover/center.txt index 0fa96f1..eb10c05 100644 --- a/plugin/src/main/resources/messages/root-hover/center.txt +++ b/plugin/src/main/resources/messages/root-hover/center.txt @@ -1,3 +1,3 @@ Usage » /npc center -Command used to move an npc to the center of the block it's currently occupying \ No newline at end of file +Command used to move an npc to the center of the block it''s currently occupying \ No newline at end of file diff --git a/plugin/src/main/resources/messages/root-hover/setlocation.txt b/plugin/src/main/resources/messages/root-hover/setlocation.txt index 7b085f6..94b16cc 100644 --- a/plugin/src/main/resources/messages/root-hover/setlocation.txt +++ b/plugin/src/main/resources/messages/root-hover/setlocation.txt @@ -1,3 +1,3 @@ Usage » /npc setlocation -Command used to manually adjust an npc's location \ No newline at end of file +Command used to manually adjust an npc''s location \ No newline at end of file diff --git a/plugin/src/main/resources/messages/root-hover/setrotation.txt b/plugin/src/main/resources/messages/root-hover/setrotation.txt index de1f808..ff97edf 100644 --- a/plugin/src/main/resources/messages/root-hover/setrotation.txt +++ b/plugin/src/main/resources/messages/root-hover/setrotation.txt @@ -1,3 +1,3 @@ Usage » /npc setrotation -Command used to manually adjust an npc's rotation \ No newline at end of file +Command used to manually adjust an npc''s rotation \ No newline at end of file From b8b4b3e17925bb882ece37fca88489debed28a95 Mon Sep 17 00:00:00 2001 From: D3v1s0m Date: Mon, 24 Jun 2024 16:26:02 +0530 Subject: [PATCH 5/7] update dependencies --- plugin/build.gradle | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/plugin/build.gradle b/plugin/build.gradle index 2d08b1e..a4ae386 100644 --- a/plugin/build.gradle +++ b/plugin/build.gradle @@ -16,17 +16,17 @@ processResources { } dependencies { - compileOnly "me.clip:placeholderapi:2.11.5" // Placeholder support + compileOnly "me.clip:placeholderapi:2.11.6" // Placeholder support implementation "com.google.code.gson:gson:2.10.1" // JSON parsing implementation "org.bstats:bstats-bukkit:3.0.2" // Plugin stats implementation "me.robertlit:SpigotResourcesAPI:2.0" // Spigot API wrapper for update checker implementation "com.github.retrooper.packetevents:spigot:2.3.0" // Packets implementation "space.arim.dazzleconf:dazzleconf-ext-snakeyaml:1.2.1" // Configs - implementation "lol.pyr:director-adventure:2.1.1" // Commands + implementation "lol.pyr:director-adventure:2.1.2" // Commands // Fancy text library - implementation "net.kyori:adventure-platform-bukkit:4.3.2" - implementation "net.kyori:adventure-text-minimessage:4.15.0" + implementation "net.kyori:adventure-platform-bukkit:4.3.3" + implementation "net.kyori:adventure-text-minimessage:4.17.0" implementation project(":api") } From f60cf7a018d892672aa4de37c7e1180ffc4e69fd Mon Sep 17 00:00:00 2001 From: D3v1s0m Date: Mon, 24 Jun 2024 16:28:12 +0530 Subject: [PATCH 6/7] add config option fake-enforce-secure-chat to disable secure chat popup --- .../java/lol/pyr/znpcsplus/ZNpcsPlus.java | 2 ++ .../lol/pyr/znpcsplus/config/MainConfig.java | 5 ++++ .../znpcsplus/user/ClientPacketListener.java | 30 +++++++++++++++++++ 3 files changed, 37 insertions(+) create mode 100644 plugin/src/main/java/lol/pyr/znpcsplus/user/ClientPacketListener.java diff --git a/plugin/src/main/java/lol/pyr/znpcsplus/ZNpcsPlus.java b/plugin/src/main/java/lol/pyr/znpcsplus/ZNpcsPlus.java index c689923..4991b16 100644 --- a/plugin/src/main/java/lol/pyr/znpcsplus/ZNpcsPlus.java +++ b/plugin/src/main/java/lol/pyr/znpcsplus/ZNpcsPlus.java @@ -43,6 +43,7 @@ import lol.pyr.znpcsplus.tasks.NpcProcessorTask; import lol.pyr.znpcsplus.tasks.ViewableHideOnLeaveListener; import lol.pyr.znpcsplus.updater.UpdateChecker; import lol.pyr.znpcsplus.updater.UpdateNotificationListener; +import lol.pyr.znpcsplus.user.ClientPacketListener; import lol.pyr.znpcsplus.user.UserListener; import lol.pyr.znpcsplus.user.UserManager; import lol.pyr.znpcsplus.util.*; @@ -141,6 +142,7 @@ public class ZNpcsPlus { typeRegistry.registerDefault(packetEvents, propertyRegistry); actionRegistry.registerTypes(scheduler, adventure, textSerializer, bungeeConnector); packetEvents.getEventManager().registerListener(new InteractionPacketListener(userManager, npcRegistry, typeRegistry, scheduler), PacketListenerPriority.MONITOR); + packetEvents.getEventManager().registerListener(new ClientPacketListener(configManager), PacketListenerPriority.LOWEST); new Metrics(bootstrap, 18244); pluginManager.registerEvents(new UserListener(userManager), bootstrap); diff --git a/plugin/src/main/java/lol/pyr/znpcsplus/config/MainConfig.java b/plugin/src/main/java/lol/pyr/znpcsplus/config/MainConfig.java index 7323e27..fee1ea7 100644 --- a/plugin/src/main/java/lol/pyr/znpcsplus/config/MainConfig.java +++ b/plugin/src/main/java/lol/pyr/znpcsplus/config/MainConfig.java @@ -73,4 +73,9 @@ public interface MainConfig { @ConfComments("The display name to use for npcs in the player list (aka tab)") @DefaultString("ZNPC[{id}]") String tabDisplayName(); + + @ConfKey("fake-enforce-secure-chat") + @ConfComments("Should the plugin fake the enforce secure chat packet to hide the popup?") + @DefaultBoolean(false) + boolean fakeEnforceSecureChat(); } diff --git a/plugin/src/main/java/lol/pyr/znpcsplus/user/ClientPacketListener.java b/plugin/src/main/java/lol/pyr/znpcsplus/user/ClientPacketListener.java new file mode 100644 index 0000000..9580597 --- /dev/null +++ b/plugin/src/main/java/lol/pyr/znpcsplus/user/ClientPacketListener.java @@ -0,0 +1,30 @@ +package lol.pyr.znpcsplus.user; + +import com.github.retrooper.packetevents.event.PacketListener; +import com.github.retrooper.packetevents.event.PacketSendEvent; +import com.github.retrooper.packetevents.protocol.packettype.PacketType; +import com.github.retrooper.packetevents.wrapper.play.server.WrapperPlayServerJoinGame; +import com.github.retrooper.packetevents.wrapper.play.server.WrapperPlayServerServerData; +import lol.pyr.znpcsplus.config.ConfigManager; + +public class ClientPacketListener implements PacketListener { + private final ConfigManager configManager; + + public ClientPacketListener(ConfigManager configManager) { + this.configManager = configManager; + } + + @Override + public void onPacketSend(PacketSendEvent event) { + if (!configManager.getConfig().fakeEnforceSecureChat()) return; + if (event.getPacketType() == PacketType.Play.Server.SERVER_DATA) { + WrapperPlayServerServerData packet = new WrapperPlayServerServerData(event); + packet.setEnforceSecureChat(true); + event.setByteBuf(packet.getBuffer()); + } else if (event.getPacketType() == PacketType.Play.Server.JOIN_GAME) { + WrapperPlayServerJoinGame packet = new WrapperPlayServerJoinGame(event); + packet.setEnforcesSecureChat(true); + event.setByteBuf(packet.getBuffer()); + } + } +} From d48de6382a35bf9407ecbfbd760e7650d1624927 Mon Sep 17 00:00:00 2001 From: D3v1s0m Date: Tue, 25 Jun 2024 01:16:03 +0530 Subject: [PATCH 7/7] fix action commands, ughh --- .../java/lol/pyr/znpcsplus/interaction/ActionRegistryImpl.java | 1 - 1 file changed, 1 deletion(-) diff --git a/plugin/src/main/java/lol/pyr/znpcsplus/interaction/ActionRegistryImpl.java b/plugin/src/main/java/lol/pyr/znpcsplus/interaction/ActionRegistryImpl.java index 15bdb01..b08ae1c 100644 --- a/plugin/src/main/java/lol/pyr/znpcsplus/interaction/ActionRegistryImpl.java +++ b/plugin/src/main/java/lol/pyr/znpcsplus/interaction/ActionRegistryImpl.java @@ -38,7 +38,6 @@ public class ActionRegistryImpl implements ActionRegistry { public List getCommands() { return serializerMap.values().stream() - .filter(type -> type instanceof InteractionActionImpl) .filter(type -> type instanceof InteractionCommandHandler) .map(type -> (InteractionCommandHandler) type) .collect(Collectors.toList());