From 24c9ee300ddcfdd3be1e8dea037023b14b70eee2 Mon Sep 17 00:00:00 2001 From: Sekwah Date: Thu, 24 Oct 2024 06:43:45 +0100 Subject: [PATCH 01/13] feat: adding proxy tags --- build.gradle | 13 ++++ bungee/build.gradle | 11 +-- .../bungee/AdvancedPortalsBungeePlugin.java | 24 +++++++ .../bungee/BungeeInfoLogger.java | 28 ++++++++ .../advancedportals/bungee/EventListener.java | 41 +++++++++++ .../container/BungeeProxyContainer.java | 23 +++++++ .../container/BungeeProxyPlayerContainer.java | 18 +++++ .../container/BungeeProxyServerContainer.java | 12 ++++ bungee/src/main/resources/bungee.yml | 4 ++ core/build.gradle | 12 ---- .../core/AdvancedPortalsCore.java | 11 ++- .../advancedportals/core/CoreListeners.java | 2 +- .../advancedportals/core/ProxyMessages.java | 16 +++++ .../portal/ShowPortalSubCommand.java | 12 +++- .../core/network/ProxyCommandPacket.java | 27 ++++++++ .../core/network/ProxyTransferPacket.java | 30 ++++++++ .../core/repository/ConfigRepository.java | 2 + .../repository/impl/ConfigRepositoryImpl.java | 5 ++ .../repository/impl/PortalRepositoryImpl.java | 8 +++ .../core/serializeddata/config/Config.java | 2 + .../advancedportals/core/tags/BungeeTag.java | 5 -- .../advancedportals/core/tags/ProxyTag.java | 68 +++++++++++++++++++ proxycore/build.gradle | 28 ++++++++ .../proxycore/AdvancedPortalsProxyCore.java | 39 +++++++++++ .../connector/container/ProxyContainer.java | 8 +++ .../container/ProxyPlayerContainer.java | 5 ++ .../container/ProxyServerContainer.java | 4 ++ settings.gradle | 1 + version.txt | 2 +- 29 files changed, 425 insertions(+), 36 deletions(-) create mode 100644 bungee/src/main/java/com/sekwah/advancedportals/bungee/AdvancedPortalsBungeePlugin.java create mode 100644 bungee/src/main/java/com/sekwah/advancedportals/bungee/BungeeInfoLogger.java create mode 100644 bungee/src/main/java/com/sekwah/advancedportals/bungee/EventListener.java create mode 100644 bungee/src/main/java/com/sekwah/advancedportals/bungee/connector/container/BungeeProxyContainer.java create mode 100644 bungee/src/main/java/com/sekwah/advancedportals/bungee/connector/container/BungeeProxyPlayerContainer.java create mode 100644 bungee/src/main/java/com/sekwah/advancedportals/bungee/connector/container/BungeeProxyServerContainer.java create mode 100644 bungee/src/main/resources/bungee.yml create mode 100644 core/src/main/java/com/sekwah/advancedportals/core/ProxyMessages.java create mode 100644 core/src/main/java/com/sekwah/advancedportals/core/network/ProxyCommandPacket.java create mode 100644 core/src/main/java/com/sekwah/advancedportals/core/network/ProxyTransferPacket.java create mode 100644 core/src/main/java/com/sekwah/advancedportals/core/tags/ProxyTag.java create mode 100644 proxycore/build.gradle create mode 100644 proxycore/src/main/java/com/sekwah/advancedportals/proxycore/AdvancedPortalsProxyCore.java create mode 100644 proxycore/src/main/java/com/sekwah/advancedportals/proxycore/connector/container/ProxyContainer.java create mode 100644 proxycore/src/main/java/com/sekwah/advancedportals/proxycore/connector/container/ProxyPlayerContainer.java create mode 100644 proxycore/src/main/java/com/sekwah/advancedportals/proxycore/connector/container/ProxyServerContainer.java diff --git a/build.gradle b/build.gradle index 6e26ba03..932f08e2 100644 --- a/build.gradle +++ b/build.gradle @@ -158,3 +158,16 @@ tasks.register('copyPlugin') { } } } + +// Set SPIGOT_LOC to the location of your server and SPIGOT_JAR as the name of the jar file in the server you want to run +// DIReallyKnowWhatIAmDoingISwear is to remove the stupid pause spigot has at the start +tasks.register('runJar') { + doLast { + javaexec { + main "-jar" + args "${System.env.MC_SERVER_LOC}\\${System.env.MC_SERVER_JAR}.jar" + jvmArgs = ["-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=5005", "-DIReallyKnowWhatIAmDoingISwear=true"] + workingDir "${System.env.MC_SERVER_LOC}" + } + } +} diff --git a/bungee/build.gradle b/bungee/build.gradle index 80e0b85e..23138236 100644 --- a/bungee/build.gradle +++ b/bungee/build.gradle @@ -17,17 +17,12 @@ repositories { // includeLibs just says to include the library in the final jar dependencies { - //includeLibs group: 'com.google.code.gson', name: 'gson', version:'2.8.2' - implementation group: 'com.google.code.gson', name: 'gson', version: '2.8.9' - //includeLibs group: 'com.google.inject', name: 'guice', version:'4.0' - implementation group: 'com.google.inject', name: 'guice', version:'4.0' - implementation group: 'com.google.guava', name: 'guava', version: '33.2.0-jre' - - // For spigot api - implementation "org.spigotmc:spigot-api:1.16.1-R0.1-SNAPSHOT" // For bungee api implementation "net.md-5:bungeecord-api:1.15-SNAPSHOT" + + implementation project(":proxycore") + implementation project(":core") } jar { diff --git a/bungee/src/main/java/com/sekwah/advancedportals/bungee/AdvancedPortalsBungeePlugin.java b/bungee/src/main/java/com/sekwah/advancedportals/bungee/AdvancedPortalsBungeePlugin.java new file mode 100644 index 00000000..c28347ae --- /dev/null +++ b/bungee/src/main/java/com/sekwah/advancedportals/bungee/AdvancedPortalsBungeePlugin.java @@ -0,0 +1,24 @@ +package com.sekwah.advancedportals.bungee; + +import com.sekwah.advancedportals.bungee.connector.container.BungeeProxyContainer; +import com.sekwah.advancedportals.core.ProxyMessages; +import com.sekwah.advancedportals.proxycore.AdvancedPortalsProxyCore; +import net.md_5.bungee.api.plugin.Plugin; + +public class AdvancedPortalsBungeePlugin extends Plugin { + private AdvancedPortalsProxyCore proxyCore; + + @Override + public void onEnable() { + this.proxyCore = new AdvancedPortalsProxyCore(new BungeeInfoLogger(this), new BungeeProxyContainer(this)); + this.proxyCore.onEnable(); + getProxy().getPluginManager().registerListener(this, new EventListener(this, this.proxyCore)); + + getProxy().registerChannel(ProxyMessages.CHANNEL_NAME); + } + + @Override + public void onDisable() { + this.proxyCore.onDisable(); + } +} diff --git a/bungee/src/main/java/com/sekwah/advancedportals/bungee/BungeeInfoLogger.java b/bungee/src/main/java/com/sekwah/advancedportals/bungee/BungeeInfoLogger.java new file mode 100644 index 00000000..58086f95 --- /dev/null +++ b/bungee/src/main/java/com/sekwah/advancedportals/bungee/BungeeInfoLogger.java @@ -0,0 +1,28 @@ +package com.sekwah.advancedportals.bungee; + +import com.sekwah.advancedportals.core.util.InfoLogger; + +import java.util.logging.Level; + +public class BungeeInfoLogger extends InfoLogger { + private final AdvancedPortalsBungeePlugin plugin; + + public BungeeInfoLogger(AdvancedPortalsBungeePlugin plugin) { + this.plugin = plugin; + } + + @Override + public void warning(String s) { + plugin.getLogger().warning(s); + } + + @Override + public void info(String s) { + plugin.getLogger().info(s); + } + + @Override + public void error(Exception e) { + plugin.getLogger().log(Level.SEVERE, e.getMessage(), e); + } +} diff --git a/bungee/src/main/java/com/sekwah/advancedportals/bungee/EventListener.java b/bungee/src/main/java/com/sekwah/advancedportals/bungee/EventListener.java new file mode 100644 index 00000000..5ffc43f0 --- /dev/null +++ b/bungee/src/main/java/com/sekwah/advancedportals/bungee/EventListener.java @@ -0,0 +1,41 @@ +package com.sekwah.advancedportals.bungee; + +import com.sekwah.advancedportals.bungee.connector.container.BungeeProxyPlayerContainer; +import com.sekwah.advancedportals.bungee.connector.container.BungeeProxyServerContainer; +import com.sekwah.advancedportals.core.ProxyMessages; +import com.sekwah.advancedportals.proxycore.AdvancedPortalsProxyCore; +import net.md_5.bungee.api.connection.ProxiedPlayer; +import net.md_5.bungee.api.connection.Server; +import net.md_5.bungee.api.event.PluginMessageEvent; +import net.md_5.bungee.api.event.ServerConnectedEvent; +import net.md_5.bungee.api.plugin.Listener; +import net.md_5.bungee.event.EventHandler; + +public class EventListener implements Listener { + + + private final AdvancedPortalsBungeePlugin plugin; + private final AdvancedPortalsProxyCore proxyCore; + + public EventListener(AdvancedPortalsBungeePlugin plugin, AdvancedPortalsProxyCore proxyCore) { + this.plugin = plugin; + this.proxyCore = proxyCore; + } + + @EventHandler + public void onMessageReceived(PluginMessageEvent event) { + if(!event.getTag().equalsIgnoreCase(ProxyMessages.CHANNEL_NAME)) return; + event.setCancelled(true); + + if(!(event.getSender() instanceof Server)) return; + + if(event.getReceiver() instanceof ProxiedPlayer player) { + this.proxyCore.incomingMessage(new BungeeProxyPlayerContainer(player), event.getData()); + } + } + + @EventHandler + public void onServerConnected(ServerConnectedEvent event) { + this.proxyCore.onServerConnect(new BungeeProxyServerContainer(event.getServer()), new BungeeProxyPlayerContainer(event.getPlayer())); + } +} diff --git a/bungee/src/main/java/com/sekwah/advancedportals/bungee/connector/container/BungeeProxyContainer.java b/bungee/src/main/java/com/sekwah/advancedportals/bungee/connector/container/BungeeProxyContainer.java new file mode 100644 index 00000000..3aa2d3ee --- /dev/null +++ b/bungee/src/main/java/com/sekwah/advancedportals/bungee/connector/container/BungeeProxyContainer.java @@ -0,0 +1,23 @@ +package com.sekwah.advancedportals.bungee.connector.container; + +import com.sekwah.advancedportals.bungee.AdvancedPortalsBungeePlugin; +import com.sekwah.advancedportals.proxycore.connector.container.ProxyContainer; +import com.sekwah.advancedportals.proxycore.connector.container.ProxyPlayerContainer; + +public class BungeeProxyContainer implements ProxyContainer { + + private final AdvancedPortalsBungeePlugin plugin; + + public BungeeProxyContainer(AdvancedPortalsBungeePlugin plugin) { + this.plugin = plugin; + } + + @Override + public void invokeCommand(ProxyPlayerContainer proxyPlayer, String command) { + } + + @Override + public void transferPlayer(ProxyPlayerContainer proxyPlayer, String serverName) { + + } +} diff --git a/bungee/src/main/java/com/sekwah/advancedportals/bungee/connector/container/BungeeProxyPlayerContainer.java b/bungee/src/main/java/com/sekwah/advancedportals/bungee/connector/container/BungeeProxyPlayerContainer.java new file mode 100644 index 00000000..e4b742bc --- /dev/null +++ b/bungee/src/main/java/com/sekwah/advancedportals/bungee/connector/container/BungeeProxyPlayerContainer.java @@ -0,0 +1,18 @@ +package com.sekwah.advancedportals.bungee.connector.container; + +import com.sekwah.advancedportals.proxycore.connector.container.ProxyPlayerContainer; +import net.md_5.bungee.api.connection.ProxiedPlayer; + +public class BungeeProxyPlayerContainer implements ProxyPlayerContainer { + + private final ProxiedPlayer player; + + public BungeeProxyPlayerContainer(ProxiedPlayer player) { + this.player = player; + } + + public ProxiedPlayer getPlayer() { + return this.player; + } + +} diff --git a/bungee/src/main/java/com/sekwah/advancedportals/bungee/connector/container/BungeeProxyServerContainer.java b/bungee/src/main/java/com/sekwah/advancedportals/bungee/connector/container/BungeeProxyServerContainer.java new file mode 100644 index 00000000..aa9e2e12 --- /dev/null +++ b/bungee/src/main/java/com/sekwah/advancedportals/bungee/connector/container/BungeeProxyServerContainer.java @@ -0,0 +1,12 @@ +package com.sekwah.advancedportals.bungee.connector.container; + +import com.sekwah.advancedportals.proxycore.connector.container.ProxyServerContainer; +import net.md_5.bungee.api.connection.Server; + +public class BungeeProxyServerContainer implements ProxyServerContainer { + private final Server server; + + public BungeeProxyServerContainer(Server server) { + this.server = server; + } +} diff --git a/bungee/src/main/resources/bungee.yml b/bungee/src/main/resources/bungee.yml new file mode 100644 index 00000000..fea8c275 --- /dev/null +++ b/bungee/src/main/resources/bungee.yml @@ -0,0 +1,4 @@ +main: com.sekwah.advancedportals.bungee.AdvancedPortalsBungeePlugin +name: AdvancedPortals +version: ${pluginVersion} +author: sekwah41 \ No newline at end of file diff --git a/core/build.gradle b/core/build.gradle index eb429d6b..a96c2699 100644 --- a/core/build.gradle +++ b/core/build.gradle @@ -32,15 +32,3 @@ jar { } } -// Set SPIGOT_LOC to the location of your server and SPIGOT_JAR as the name of the jar file in the server you want to run -// DIReallyKnowWhatIAmDoingISwear is to remove the stupid pause spigot has at the start -tasks.register('runJar') { - doLast { - javaexec { - main "-jar" - args "${System.env.MC_SERVER_LOC}\\${System.env.MC_SERVER_JAR}.jar" - jvmArgs = ["-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=5005", "-DIReallyKnowWhatIAmDoingISwear=true"] - workingDir "${System.env.MC_SERVER_LOC}" - } - } -} diff --git a/core/src/main/java/com/sekwah/advancedportals/core/AdvancedPortalsCore.java b/core/src/main/java/com/sekwah/advancedportals/core/AdvancedPortalsCore.java index 505bbb72..70e8638c 100644 --- a/core/src/main/java/com/sekwah/advancedportals/core/AdvancedPortalsCore.java +++ b/core/src/main/java/com/sekwah/advancedportals/core/AdvancedPortalsCore.java @@ -2,7 +2,6 @@ import com.google.inject.Inject; import com.google.inject.Injector; -import com.google.inject.spi.Message; import com.sekwah.advancedportals.core.commands.CommandWithSubCommands; import com.sekwah.advancedportals.core.commands.SubCommand; import com.sekwah.advancedportals.core.commands.subcommands.desti.*; @@ -12,7 +11,6 @@ import com.sekwah.advancedportals.core.module.AdvancedPortalsModule; import com.sekwah.advancedportals.core.registry.TagRegistry; import com.sekwah.advancedportals.core.repository.ConfigRepository; -import com.sekwah.advancedportals.core.repository.IPlayerDataRepository; import com.sekwah.advancedportals.core.serializeddata.DataStorage; import com.sekwah.advancedportals.core.services.DestinationServices; import com.sekwah.advancedportals.core.services.PlayerDataServices; @@ -66,10 +64,6 @@ public class AdvancedPortalsCore { @Inject private GameScheduler gameScheduler; - // TEMP REMOVE THIS THIS IS JUST FOR DEV - @Inject - private IPlayerDataRepository tempDataRepository; - public AdvancedPortalsCore(String mcVersion, File dataStorageLoc, InfoLogger infoLogger, ServerContainer serverContainer) { @@ -126,6 +120,10 @@ public void onEnable() { private void registerChannels() { this.serverContainer.registerOutgoingChannel(BungeeTag.PACKET_CHANNEL); + if(this.configRepository.getEnableProxySupport()) { + this.serverContainer.registerOutgoingChannel(ProxyMessages.CHANNEL_NAME); + this.serverContainer.registerIncomingChannel(ProxyMessages.CHANNEL_NAME); + } } private void registerTags() { @@ -138,6 +136,7 @@ private void registerTags() { this.tagRegistry.registerTag(new PortalEventTag()); this.tagRegistry.registerTag(new MessageTag()); this.tagRegistry.registerTag(new BungeeTag()); + this.tagRegistry.registerTag(new ProxyTag()); } /** diff --git a/core/src/main/java/com/sekwah/advancedportals/core/CoreListeners.java b/core/src/main/java/com/sekwah/advancedportals/core/CoreListeners.java index fc38136f..06d2d773 100644 --- a/core/src/main/java/com/sekwah/advancedportals/core/CoreListeners.java +++ b/core/src/main/java/com/sekwah/advancedportals/core/CoreListeners.java @@ -56,7 +56,7 @@ public void playerLeave(PlayerContainer player) { } public void incomingMessage(PlayerContainer player, String channel, byte[] message) { - // TODO implement proxy handling + } public void tick() { diff --git a/core/src/main/java/com/sekwah/advancedportals/core/ProxyMessages.java b/core/src/main/java/com/sekwah/advancedportals/core/ProxyMessages.java new file mode 100644 index 00000000..c6e73f46 --- /dev/null +++ b/core/src/main/java/com/sekwah/advancedportals/core/ProxyMessages.java @@ -0,0 +1,16 @@ +package com.sekwah.advancedportals.core; + +/** + * messages going to the proxy will start with proxy: messages going to the server will start with server: + */ +public class ProxyMessages { + + public static String CHANNEL_NAME = "advancedportals:warp"; + + public static String PROXY_TRANSFER_DESTI = "proxy:transfer_desti"; + public static String PROXY_TRANSFER = "proxy:transfer"; + public static String PROXY_DESTI = "proxy:destination"; + public static String PROXY_COMMAND = "proxy:command"; + + public static String SERVER_DESTI = "server:destination"; +} diff --git a/core/src/main/java/com/sekwah/advancedportals/core/commands/subcommands/portal/ShowPortalSubCommand.java b/core/src/main/java/com/sekwah/advancedportals/core/commands/subcommands/portal/ShowPortalSubCommand.java index e37e8b60..0e7c6c3f 100644 --- a/core/src/main/java/com/sekwah/advancedportals/core/commands/subcommands/portal/ShowPortalSubCommand.java +++ b/core/src/main/java/com/sekwah/advancedportals/core/commands/subcommands/portal/ShowPortalSubCommand.java @@ -25,7 +25,7 @@ */ public class ShowPortalSubCommand implements SubCommand, SubCommand.SubCommandOnInit { - static final int SHOW_TICKS = 1010; + static final int SHOW_TICKS = 1050; boolean alternate_show_trigger = true; @@ -116,8 +116,14 @@ public void registered() { player.getWorldName()) && tempData.getPos2().getWorldName().equals( player.getWorldName())) { - debugVisuals(player, tempData.getPos1(), tempData.getPos2(), - SELECTION_COLOR, SHOW_TICKS); + int widthX = Math.abs(tempData.getPos1().getPosX() + - tempData.getPos2().getPosX()); + int widthY = Math.abs(tempData.getPos1().getPosY() - tempData.getPos2().getPosY()); + int widthZ = Math.abs(tempData.getPos1().getPosZ() - tempData.getPos2().getPosZ()); + int totalBlocks = widthX * widthY * widthZ; + if (totalBlocks <= config.getMaxTriggerVisualisationSize()) + debugVisuals(player, tempData.getPos1(), tempData.getPos2(), + SELECTION_COLOR, SHOW_TICKS); } if (tempData.getPos1() != null diff --git a/core/src/main/java/com/sekwah/advancedportals/core/network/ProxyCommandPacket.java b/core/src/main/java/com/sekwah/advancedportals/core/network/ProxyCommandPacket.java new file mode 100644 index 00000000..8a0fcb72 --- /dev/null +++ b/core/src/main/java/com/sekwah/advancedportals/core/network/ProxyCommandPacket.java @@ -0,0 +1,27 @@ +package com.sekwah.advancedportals.core.network; + +import com.google.common.io.ByteArrayDataInput; +import com.google.common.io.ByteArrayDataOutput; +import com.sekwah.advancedportals.core.ProxyMessages; + +public class ProxyCommandPacket { + + private final String command; + + public ProxyCommandPacket(String command) { + this.command = command; + } + + public static void encode(ProxyCommandPacket msg, ByteArrayDataOutput buffer) { + buffer.writeUTF(ProxyMessages.PROXY_COMMAND); + buffer.writeUTF(msg.command); + } + + public static ProxyCommandPacket decode(ByteArrayDataInput buffer) { + return new ProxyCommandPacket(buffer.readUTF()); + } + + public String getCommand() { + return command; + } +} diff --git a/core/src/main/java/com/sekwah/advancedportals/core/network/ProxyTransferPacket.java b/core/src/main/java/com/sekwah/advancedportals/core/network/ProxyTransferPacket.java new file mode 100644 index 00000000..9c22bf5e --- /dev/null +++ b/core/src/main/java/com/sekwah/advancedportals/core/network/ProxyTransferPacket.java @@ -0,0 +1,30 @@ +package com.sekwah.advancedportals.core.network; + +import com.google.common.io.ByteArrayDataInput; +import com.google.common.io.ByteArrayDataOutput; +import com.google.common.io.ByteStreams; +import com.sekwah.advancedportals.core.ProxyMessages; + +public class ProxyTransferPacket { + + private final String serverName; + + public ProxyTransferPacket(String serverName) { + this.serverName = serverName; + } + + public byte[] encode() { + ByteArrayDataOutput buffer = ByteStreams.newDataOutput(); + buffer.writeUTF(ProxyMessages.PROXY_TRANSFER); + buffer.writeUTF(this.serverName); + return buffer.toByteArray(); + } + + public static ProxyTransferPacket decode(ByteArrayDataInput buffer) { + return new ProxyTransferPacket(buffer.readUTF()); + } + + public String getServerName() { + return serverName; + } +} diff --git a/core/src/main/java/com/sekwah/advancedportals/core/repository/ConfigRepository.java b/core/src/main/java/com/sekwah/advancedportals/core/repository/ConfigRepository.java index be8a1e45..2f2bf385 100644 --- a/core/src/main/java/com/sekwah/advancedportals/core/repository/ConfigRepository.java +++ b/core/src/main/java/com/sekwah/advancedportals/core/repository/ConfigRepository.java @@ -45,4 +45,6 @@ public interface ConfigRepository { boolean warpMessageInChat(); String getWarpParticles(); + + boolean getEnableProxySupport(); } diff --git a/core/src/main/java/com/sekwah/advancedportals/core/repository/impl/ConfigRepositoryImpl.java b/core/src/main/java/com/sekwah/advancedportals/core/repository/impl/ConfigRepositoryImpl.java index 425b82b2..50d23fa2 100644 --- a/core/src/main/java/com/sekwah/advancedportals/core/repository/impl/ConfigRepositoryImpl.java +++ b/core/src/main/java/com/sekwah/advancedportals/core/repository/impl/ConfigRepositoryImpl.java @@ -95,6 +95,11 @@ public String getWarpParticles() { return this.config.warpParticles; } + @Override + public boolean getEnableProxySupport() { + return this.config.enableProxySupport; + } + @Override public void loadConfig(DataStorage dataStorage) { this.dataStorage = dataStorage; diff --git a/core/src/main/java/com/sekwah/advancedportals/core/repository/impl/PortalRepositoryImpl.java b/core/src/main/java/com/sekwah/advancedportals/core/repository/impl/PortalRepositoryImpl.java index eb030798..13778ddf 100644 --- a/core/src/main/java/com/sekwah/advancedportals/core/repository/impl/PortalRepositoryImpl.java +++ b/core/src/main/java/com/sekwah/advancedportals/core/repository/impl/PortalRepositoryImpl.java @@ -65,6 +65,14 @@ public List getAll() { for (String fileName : allFiles) { AdvancedPortal portal = dataStorage.loadFile( AdvancedPortal.class, fileLocation + fileName); + + if (portal != null) { + AdvancedPortalsCore.getInstance() + .getModule() + .getInjector() + .injectMembers(portal); + } + // Forces the name tag to be up-to-date on load String[] name = portal.getArgValues(NameTag.TAG_NAME); if (name != null && name.length > 0) { diff --git a/core/src/main/java/com/sekwah/advancedportals/core/serializeddata/config/Config.java b/core/src/main/java/com/sekwah/advancedportals/core/serializeddata/config/Config.java index a6442b67..bd321a01 100644 --- a/core/src/main/java/com/sekwah/advancedportals/core/serializeddata/config/Config.java +++ b/core/src/main/java/com/sekwah/advancedportals/core/serializeddata/config/Config.java @@ -39,4 +39,6 @@ public class Config { public boolean warpMessageInChat = false; public CommandPortalConfig commandPortals = new CommandPortalConfig(); + + public boolean enableProxySupport = false; } diff --git a/core/src/main/java/com/sekwah/advancedportals/core/tags/BungeeTag.java b/core/src/main/java/com/sekwah/advancedportals/core/tags/BungeeTag.java index ac2e54bd..f713e200 100644 --- a/core/src/main/java/com/sekwah/advancedportals/core/tags/BungeeTag.java +++ b/core/src/main/java/com/sekwah/advancedportals/core/tags/BungeeTag.java @@ -2,11 +2,8 @@ import com.google.common.io.ByteArrayDataOutput; import com.google.common.io.ByteStreams; -import com.google.inject.Inject; import com.sekwah.advancedportals.core.connector.containers.PlayerContainer; import com.sekwah.advancedportals.core.registry.TagTarget; -import com.sekwah.advancedportals.core.repository.ConfigRepository; -import com.sekwah.advancedportals.core.util.FriendlyDataOutput; import com.sekwah.advancedportals.core.util.Lang; import com.sekwah.advancedportals.core.warphandler.ActivationData; import com.sekwah.advancedportals.core.warphandler.Tag; @@ -16,8 +13,6 @@ public class BungeeTag implements Tag.Activation { public static final String PACKET_CHANNEL = "BungeeCord"; - @Inject - ConfigRepository configRepository; public static String TAG_NAME = "bungee"; diff --git a/core/src/main/java/com/sekwah/advancedportals/core/tags/ProxyTag.java b/core/src/main/java/com/sekwah/advancedportals/core/tags/ProxyTag.java new file mode 100644 index 00000000..36305c24 --- /dev/null +++ b/core/src/main/java/com/sekwah/advancedportals/core/tags/ProxyTag.java @@ -0,0 +1,68 @@ +package com.sekwah.advancedportals.core.tags; + +import com.google.common.io.ByteArrayDataOutput; +import com.google.common.io.ByteStreams; +import com.google.inject.Inject; +import com.sekwah.advancedportals.core.ProxyMessages; +import com.sekwah.advancedportals.core.connector.containers.PlayerContainer; +import com.sekwah.advancedportals.core.network.ProxyTransferPacket; +import com.sekwah.advancedportals.core.registry.TagTarget; +import com.sekwah.advancedportals.core.repository.ConfigRepository; +import com.sekwah.advancedportals.core.util.Lang; +import com.sekwah.advancedportals.core.warphandler.ActivationData; +import com.sekwah.advancedportals.core.warphandler.Tag; + +import java.util.Random; + +public class ProxyTag implements Tag.Activation { + + @Inject + ConfigRepository configRepository; + + public static String TAG_NAME = "proxy"; + + private final TagType[] tagTypes = + new TagType[] {TagType.PORTAL}; + + private final Random random = new Random(); + + @Override + public TagType[] getTagTypes() { + return tagTypes; + } + + @Override + public String getName() { + return TAG_NAME; + } + + @Override + public String[] getAliases() { + return null; + } + + @Override + public String description() { + return Lang.translate("tag.proxy.description"); + } + + @Override + public boolean preActivated(TagTarget target, PlayerContainer player, ActivationData activeData, String[] argData) { + return true; + } + + @Override + public void postActivated(TagTarget target, PlayerContainer player, ActivationData activationData, String[] argData) { + + } + + @Override + public boolean activated(TagTarget target, PlayerContainer player, ActivationData activeData, String[] argData) { + String selectedArg = argData[random.nextInt(argData.length)]; + + var packet = new ProxyTransferPacket(selectedArg); + player.sendPacket(ProxyMessages.CHANNEL_NAME, packet.encode()); + activeData.setWarpStatus(ActivationData.WarpedStatus.WARPED); + return true; + } +} diff --git a/proxycore/build.gradle b/proxycore/build.gradle new file mode 100644 index 00000000..5f3623b7 --- /dev/null +++ b/proxycore/build.gradle @@ -0,0 +1,28 @@ +apply plugin: 'maven-publish' +apply plugin: 'idea' +apply plugin: 'eclipse' + +configurations { + // configuration that holds jars to copy into lib + includeLibs +} + +repositories { + + maven { url "https://repo.maven.apache.org/maven2" } + maven { url "https://hub.spigotmc.org/nexus/content/repositories/snapshots/" } + maven { url "https://oss.sonatype.org/content/repositories/snapshots/" } +} + +// includeLibs just says to include the library in the final jar +dependencies { + // This is here just for referencing the proxy message strings + implementation project(":core") +} + +jar { + from configurations.includeLibs.collect { + it.isDirectory() ? it : zipTree(it) + } +} + diff --git a/proxycore/src/main/java/com/sekwah/advancedportals/proxycore/AdvancedPortalsProxyCore.java b/proxycore/src/main/java/com/sekwah/advancedportals/proxycore/AdvancedPortalsProxyCore.java new file mode 100644 index 00000000..b2161e2a --- /dev/null +++ b/proxycore/src/main/java/com/sekwah/advancedportals/proxycore/AdvancedPortalsProxyCore.java @@ -0,0 +1,39 @@ +package com.sekwah.advancedportals.proxycore; + +import com.sekwah.advancedportals.core.util.InfoLogger; +import com.sekwah.advancedportals.proxycore.connector.container.ProxyContainer; +import com.sekwah.advancedportals.proxycore.connector.container.ProxyPlayerContainer; +import com.sekwah.advancedportals.proxycore.connector.container.ProxyServerContainer; + +public class AdvancedPortalsProxyCore { + + private final InfoLogger logger; + private final ProxyContainer proxyContainer; + + public AdvancedPortalsProxyCore(InfoLogger logger, ProxyContainer proxyContainer) { + this.logger = logger; + this.proxyContainer = proxyContainer; + } + + public void onEnable() { + this.logger.info("\u00A7aSuccessfully enabled!"); + } + + public void onDisable() { + + this.logger.info("\u00A7cDisabling plugin!"); + } + + public void onServerConnect(ProxyServerContainer server, ProxyPlayerContainer player) { + + } + + /** + * Messages coming on the ProxyMessages.CHANNEL_NAME from the server, others will be filtered out before now. + * @param player + * @param message + */ + public void incomingMessage(ProxyPlayerContainer player, byte[] message) { + this.logger.info("Message received from server"); + } +} diff --git a/proxycore/src/main/java/com/sekwah/advancedportals/proxycore/connector/container/ProxyContainer.java b/proxycore/src/main/java/com/sekwah/advancedportals/proxycore/connector/container/ProxyContainer.java new file mode 100644 index 00000000..29b3d555 --- /dev/null +++ b/proxycore/src/main/java/com/sekwah/advancedportals/proxycore/connector/container/ProxyContainer.java @@ -0,0 +1,8 @@ +package com.sekwah.advancedportals.proxycore.connector.container; + +public interface ProxyContainer { + void invokeCommand(ProxyPlayerContainer proxyPlayer, String command); + + void transferPlayer(ProxyPlayerContainer proxyPlayer, String serverName); + +} diff --git a/proxycore/src/main/java/com/sekwah/advancedportals/proxycore/connector/container/ProxyPlayerContainer.java b/proxycore/src/main/java/com/sekwah/advancedportals/proxycore/connector/container/ProxyPlayerContainer.java new file mode 100644 index 00000000..ef4faeac --- /dev/null +++ b/proxycore/src/main/java/com/sekwah/advancedportals/proxycore/connector/container/ProxyPlayerContainer.java @@ -0,0 +1,5 @@ +package com.sekwah.advancedportals.proxycore.connector.container; + +public interface ProxyPlayerContainer { + +} diff --git a/proxycore/src/main/java/com/sekwah/advancedportals/proxycore/connector/container/ProxyServerContainer.java b/proxycore/src/main/java/com/sekwah/advancedportals/proxycore/connector/container/ProxyServerContainer.java new file mode 100644 index 00000000..1486bdff --- /dev/null +++ b/proxycore/src/main/java/com/sekwah/advancedportals/proxycore/connector/container/ProxyServerContainer.java @@ -0,0 +1,4 @@ +package com.sekwah.advancedportals.proxycore.connector.container; + +public interface ProxyServerContainer { +} diff --git a/settings.gradle b/settings.gradle index 803feaad..4a36b19d 100644 --- a/settings.gradle +++ b/settings.gradle @@ -1,6 +1,7 @@ rootProject.name = "Advanced-Portals" // Core modules include 'core' +include 'proxycore' include 'lang' // Implementations diff --git a/version.txt b/version.txt index 2003b639..3eefcb9d 100644 --- a/version.txt +++ b/version.txt @@ -1 +1 @@ -0.9.2 +1.0.0 From 31b525e31dee740e0cf9318bd46d4d4430e266fb Mon Sep 17 00:00:00 2001 From: Sekwah Date: Thu, 24 Oct 2024 17:46:32 +0100 Subject: [PATCH 02/13] wip: connecting the proxy --- .../advancedportals/bungee/AdvancedPortalsBungeePlugin.java | 3 ++- .../java/com/sekwah/advancedportals/bungee/EventListener.java | 2 ++ .../java/com/sekwah/advancedportals/core/ProxyMessages.java | 2 +- 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/bungee/src/main/java/com/sekwah/advancedportals/bungee/AdvancedPortalsBungeePlugin.java b/bungee/src/main/java/com/sekwah/advancedportals/bungee/AdvancedPortalsBungeePlugin.java index c28347ae..8bf80095 100644 --- a/bungee/src/main/java/com/sekwah/advancedportals/bungee/AdvancedPortalsBungeePlugin.java +++ b/bungee/src/main/java/com/sekwah/advancedportals/bungee/AdvancedPortalsBungeePlugin.java @@ -12,9 +12,10 @@ public class AdvancedPortalsBungeePlugin extends Plugin { public void onEnable() { this.proxyCore = new AdvancedPortalsProxyCore(new BungeeInfoLogger(this), new BungeeProxyContainer(this)); this.proxyCore.onEnable(); - getProxy().getPluginManager().registerListener(this, new EventListener(this, this.proxyCore)); getProxy().registerChannel(ProxyMessages.CHANNEL_NAME); + + getProxy().getPluginManager().registerListener(this, new EventListener(this, this.proxyCore)); } @Override diff --git a/bungee/src/main/java/com/sekwah/advancedportals/bungee/EventListener.java b/bungee/src/main/java/com/sekwah/advancedportals/bungee/EventListener.java index 5ffc43f0..6b170f0b 100644 --- a/bungee/src/main/java/com/sekwah/advancedportals/bungee/EventListener.java +++ b/bungee/src/main/java/com/sekwah/advancedportals/bungee/EventListener.java @@ -24,6 +24,7 @@ public EventListener(AdvancedPortalsBungeePlugin plugin, AdvancedPortalsProxyCor @EventHandler public void onMessageReceived(PluginMessageEvent event) { + this.plugin.getLogger().info("Message received " + event.getTag()); if(!event.getTag().equalsIgnoreCase(ProxyMessages.CHANNEL_NAME)) return; event.setCancelled(true); @@ -36,6 +37,7 @@ public void onMessageReceived(PluginMessageEvent event) { @EventHandler public void onServerConnected(ServerConnectedEvent event) { + this.plugin.getLogger().info("Server connected " + event.getServer().getInfo().getName()); this.proxyCore.onServerConnect(new BungeeProxyServerContainer(event.getServer()), new BungeeProxyPlayerContainer(event.getPlayer())); } } diff --git a/core/src/main/java/com/sekwah/advancedportals/core/ProxyMessages.java b/core/src/main/java/com/sekwah/advancedportals/core/ProxyMessages.java index c6e73f46..e47472d9 100644 --- a/core/src/main/java/com/sekwah/advancedportals/core/ProxyMessages.java +++ b/core/src/main/java/com/sekwah/advancedportals/core/ProxyMessages.java @@ -5,7 +5,7 @@ */ public class ProxyMessages { - public static String CHANNEL_NAME = "advancedportals:warp"; + public static String CHANNEL_NAME = "advancedportals"; public static String PROXY_TRANSFER_DESTI = "proxy:transfer_desti"; public static String PROXY_TRANSFER = "proxy:transfer"; From 5561964355af035e134b5f51a21cebbf0e06158e Mon Sep 17 00:00:00 2001 From: Sekwah Date: Fri, 25 Oct 2024 03:26:01 +0100 Subject: [PATCH 03/13] wip: fixing a few translations as well as making the proxy pick up the values --- .../advancedportals/bungee/EventListener.java | 2 -- .../container/BungeeProxyPlayerContainer.java | 10 +++++++++ .../advancedportals/core/ProxyMessages.java | 15 +++++++------ .../core/network/ProxyTransferPacket.java | 1 + .../advancedportals/core/tags/ProxyTag.java | 6 ++++++ lang/src/main/resources/lang/de_DE.lang | 2 +- lang/src/main/resources/lang/en_GB.lang | 5 ++++- lang/src/main/resources/lang/fr_FR.lang | 4 ++-- lang/src/main/resources/lang/hu_HU.lang | 2 +- proxycore/build.gradle | 1 + .../proxycore/AdvancedPortalsProxyCore.java | 21 ++++++++++++++++++- .../container/ProxyPlayerContainer.java | 3 ++- 12 files changed, 57 insertions(+), 15 deletions(-) diff --git a/bungee/src/main/java/com/sekwah/advancedportals/bungee/EventListener.java b/bungee/src/main/java/com/sekwah/advancedportals/bungee/EventListener.java index 6b170f0b..5ffc43f0 100644 --- a/bungee/src/main/java/com/sekwah/advancedportals/bungee/EventListener.java +++ b/bungee/src/main/java/com/sekwah/advancedportals/bungee/EventListener.java @@ -24,7 +24,6 @@ public EventListener(AdvancedPortalsBungeePlugin plugin, AdvancedPortalsProxyCor @EventHandler public void onMessageReceived(PluginMessageEvent event) { - this.plugin.getLogger().info("Message received " + event.getTag()); if(!event.getTag().equalsIgnoreCase(ProxyMessages.CHANNEL_NAME)) return; event.setCancelled(true); @@ -37,7 +36,6 @@ public void onMessageReceived(PluginMessageEvent event) { @EventHandler public void onServerConnected(ServerConnectedEvent event) { - this.plugin.getLogger().info("Server connected " + event.getServer().getInfo().getName()); this.proxyCore.onServerConnect(new BungeeProxyServerContainer(event.getServer()), new BungeeProxyPlayerContainer(event.getPlayer())); } } diff --git a/bungee/src/main/java/com/sekwah/advancedportals/bungee/connector/container/BungeeProxyPlayerContainer.java b/bungee/src/main/java/com/sekwah/advancedportals/bungee/connector/container/BungeeProxyPlayerContainer.java index e4b742bc..b151c6fd 100644 --- a/bungee/src/main/java/com/sekwah/advancedportals/bungee/connector/container/BungeeProxyPlayerContainer.java +++ b/bungee/src/main/java/com/sekwah/advancedportals/bungee/connector/container/BungeeProxyPlayerContainer.java @@ -15,4 +15,14 @@ public ProxiedPlayer getPlayer() { return this.player; } + @Override + public String getUUID() { + return this.player.getUniqueId().toString(); + } + + @Override + public String getName() { + return this.player.getName(); + } + } diff --git a/core/src/main/java/com/sekwah/advancedportals/core/ProxyMessages.java b/core/src/main/java/com/sekwah/advancedportals/core/ProxyMessages.java index e47472d9..1a350e99 100644 --- a/core/src/main/java/com/sekwah/advancedportals/core/ProxyMessages.java +++ b/core/src/main/java/com/sekwah/advancedportals/core/ProxyMessages.java @@ -5,12 +5,15 @@ */ public class ProxyMessages { - public static String CHANNEL_NAME = "advancedportals"; + /** + * Could split by channel messages we will handle it ourselves + */ + public static final String CHANNEL_NAME = "advancedportals:message"; - public static String PROXY_TRANSFER_DESTI = "proxy:transfer_desti"; - public static String PROXY_TRANSFER = "proxy:transfer"; - public static String PROXY_DESTI = "proxy:destination"; - public static String PROXY_COMMAND = "proxy:command"; + public static final String PROXY_TRANSFER_DESTI = "proxy:transfer_desti"; + public static final String PROXY_TRANSFER = "proxy:transfer"; + public static final String PROXY_DESTI = "proxy:destination"; + public static final String PROXY_COMMAND = "proxy:command"; - public static String SERVER_DESTI = "server:destination"; + public static final String SERVER_DESTI = "server:destination"; } diff --git a/core/src/main/java/com/sekwah/advancedportals/core/network/ProxyTransferPacket.java b/core/src/main/java/com/sekwah/advancedportals/core/network/ProxyTransferPacket.java index 9c22bf5e..53e86ee4 100644 --- a/core/src/main/java/com/sekwah/advancedportals/core/network/ProxyTransferPacket.java +++ b/core/src/main/java/com/sekwah/advancedportals/core/network/ProxyTransferPacket.java @@ -18,6 +18,7 @@ public byte[] encode() { buffer.writeUTF(ProxyMessages.PROXY_TRANSFER); buffer.writeUTF(this.serverName); return buffer.toByteArray(); + } public static ProxyTransferPacket decode(ByteArrayDataInput buffer) { diff --git a/core/src/main/java/com/sekwah/advancedportals/core/tags/ProxyTag.java b/core/src/main/java/com/sekwah/advancedportals/core/tags/ProxyTag.java index 36305c24..dee9193e 100644 --- a/core/src/main/java/com/sekwah/advancedportals/core/tags/ProxyTag.java +++ b/core/src/main/java/com/sekwah/advancedportals/core/tags/ProxyTag.java @@ -58,6 +58,12 @@ public void postActivated(TagTarget target, PlayerContainer player, ActivationDa @Override public boolean activated(TagTarget target, PlayerContainer player, ActivationData activeData, String[] argData) { + + if(!this.configRepository.getEnableProxySupport()) { + player.sendMessage(Lang.getNegativePrefix() + Lang.translate("tag.proxy.notenabled")); + return false; + } + String selectedArg = argData[random.nextInt(argData.length)]; var packet = new ProxyTransferPacket(selectedArg); diff --git a/lang/src/main/resources/lang/de_DE.lang b/lang/src/main/resources/lang/de_DE.lang index 4c26065e..67240437 100644 --- a/lang/src/main/resources/lang/de_DE.lang +++ b/lang/src/main/resources/lang/de_DE.lang @@ -56,7 +56,7 @@ command.help.invalidhelp= &e%1$s&c ist keine gültige Seitennummer oder Sub-Comm command.reload.help=Ladet die Portal-Dateien neu command.reload.detailedhelp=Lade alle Portal-Dateien von den Dateien im Dateiordner neu. -command.reload.reloaded= Alle Advanced Portals Dateien wurden neugeladet +command.reload.reloaded= Alle Advanced Portals-Daten wurden neu geladen. Einige Konfigurationswerte erfordern möglicherweise einen vollständigen Serverneustart oder ein Plugin-Reload, um wirksam zu werden. command.create.help=Erstellt Portale command.create.error= Beim Portal erstellen ist ein Fehler aufgetreten: diff --git a/lang/src/main/resources/lang/en_GB.lang b/lang/src/main/resources/lang/en_GB.lang index dd95c9e2..65b4dfc5 100644 --- a/lang/src/main/resources/lang/en_GB.lang +++ b/lang/src/main/resources/lang/en_GB.lang @@ -54,7 +54,7 @@ command.help.invalidhelp= Sorry but &e%1$s&c is not a valid page number or sub c command.reload.help=Reloads portal data command.reload.detailedhelp=Reloads all portal data from files in the data folder -command.reload.reloaded= All Advanced Portals data reloaded +command.reload.reloaded= All Advanced Portals data reloaded. Some config values may need a full server restart or a plugin reload to take effect. command.create.help=Creates portals command.create.error= There was a problem making the portal. @@ -189,3 +189,6 @@ tag.command.disabled= Command portals are &edisabled &con this server. Please co tag.command.op.disabled= Op command portals are &edisabled &con this server. Please contact a server admin if this is an issue. tag.command.console.disabled= Console command portals are &edisabled &con this server. Please contact a server admin if this is an issue. tag.command.permswildcard.disabled= Wildcard &e*&c permission command portals are &edisabled &con this server. Please contact a server admin if this is an issue. + +tag.proxy.notenabled= Proxy portals are currently &edisabled &con this server. Please contact a server admin to enable them. +tag.proxy.description= Sets the server destination of the portal. \ No newline at end of file diff --git a/lang/src/main/resources/lang/fr_FR.lang b/lang/src/main/resources/lang/fr_FR.lang index 8668cb34..01658751 100644 --- a/lang/src/main/resources/lang/fr_FR.lang +++ b/lang/src/main/resources/lang/fr_FR.lang @@ -37,7 +37,7 @@ translatedata.translationsoutdated=Certaines des traductions du fichier de tradu translatedata.replacecommand= Utilisez &e/portal transupdate&c pour copier un nouveau fichier par défaut de traduction &een_GB&c. translatedata.replaced= Un nouveau fichier &een_GB&a a bien été enregistré. -messageprefix.positive=&c[&7AdvancedPortals&c] +messageprefix.positive=&a[&7AdvancedPortals&a] messageprefix.negative=&c[&7AdvancedPortals&c] logger.pluginenable=Advanced portals a bien été activé ! @@ -53,7 +53,7 @@ command.help.invalidhelp= Désolé mais &e%1$s&c n'est pas une page ou sous comm command.reload.help=Recharge les fichiers command.reload.detailedhelp=Recharge toutes les données du portail à partir des fichiers du dossier de données. -command.reload.reloaded= Tous les fichiers ont bien été rechargés. +command.reload.reloaded= Toutes les données d'Advanced Portals ont été rechargées. Certaines valeurs de configuration peuvent nécessiter un redémarrage complet du serveur ou un rechargement du plugin pour prendre effet. command.create.help=Crée un portail command.create.error= Une erreur est survenue en créant le portail: diff --git a/lang/src/main/resources/lang/hu_HU.lang b/lang/src/main/resources/lang/hu_HU.lang index a4da968b..3da48647 100644 --- a/lang/src/main/resources/lang/hu_HU.lang +++ b/lang/src/main/resources/lang/hu_HU.lang @@ -53,7 +53,7 @@ command.help.invalidhelp= Sajnálom, de &e%1$s&c nem érvényes oldalszám vagy command.reload.help=Portál adat újratöltése command.reload.detailedhelp=Újratölt minden portáladatot az adatmappában található fájlokból -command.reload.reloaded= Minden Advanced Portals adat újratöltve +command.reload.reloaded= Minden Advanced Portals adat újratöltve. Egyes konfigurációs értékek teljes szerverújraindítást vagy a plugin újratöltését igényelhetik a hatályba lépéshez. command.create.help=Portál létrehozása command.create.error= Hiba történt a portál létrehozásában: diff --git a/proxycore/build.gradle b/proxycore/build.gradle index 5f3623b7..bf896d0a 100644 --- a/proxycore/build.gradle +++ b/proxycore/build.gradle @@ -18,6 +18,7 @@ repositories { dependencies { // This is here just for referencing the proxy message strings implementation project(":core") + implementation group: 'com.google.guava', name: 'guava', version: '33.2.0-jre' } jar { diff --git a/proxycore/src/main/java/com/sekwah/advancedportals/proxycore/AdvancedPortalsProxyCore.java b/proxycore/src/main/java/com/sekwah/advancedportals/proxycore/AdvancedPortalsProxyCore.java index b2161e2a..9e140fcc 100644 --- a/proxycore/src/main/java/com/sekwah/advancedportals/proxycore/AdvancedPortalsProxyCore.java +++ b/proxycore/src/main/java/com/sekwah/advancedportals/proxycore/AdvancedPortalsProxyCore.java @@ -1,5 +1,8 @@ package com.sekwah.advancedportals.proxycore; +import com.google.common.io.ByteStreams; +import com.sekwah.advancedportals.core.ProxyMessages; +import com.sekwah.advancedportals.core.network.ProxyTransferPacket; import com.sekwah.advancedportals.core.util.InfoLogger; import com.sekwah.advancedportals.proxycore.connector.container.ProxyContainer; import com.sekwah.advancedportals.proxycore.connector.container.ProxyPlayerContainer; @@ -34,6 +37,22 @@ public void onServerConnect(ProxyServerContainer server, ProxyPlayerContainer pl * @param message */ public void incomingMessage(ProxyPlayerContainer player, byte[] message) { - this.logger.info("Message received from server"); + this.logger.info("Message received from server via " + player.getName()); + + var buffer = ByteStreams.newDataInput(message); + var messageType = buffer.readUTF(); + + // Might be a bit overboard for some as they'll only have one value, but try to keep the decode behavior with + // the encode behavior in the packets + switch (messageType) { + case ProxyMessages.PROXY_TRANSFER: + var msg = ProxyTransferPacket.decode(buffer); + this.logger.info("Transfer request for " + player.getName() + " to " + msg.getServerName()); + this.proxyContainer.transferPlayer(player, msg.getServerName()); + break; + default: + this.logger.info("Unknown message type: " + messageType); + } + } } diff --git a/proxycore/src/main/java/com/sekwah/advancedportals/proxycore/connector/container/ProxyPlayerContainer.java b/proxycore/src/main/java/com/sekwah/advancedportals/proxycore/connector/container/ProxyPlayerContainer.java index ef4faeac..3fddfb5f 100644 --- a/proxycore/src/main/java/com/sekwah/advancedportals/proxycore/connector/container/ProxyPlayerContainer.java +++ b/proxycore/src/main/java/com/sekwah/advancedportals/proxycore/connector/container/ProxyPlayerContainer.java @@ -1,5 +1,6 @@ package com.sekwah.advancedportals.proxycore.connector.container; public interface ProxyPlayerContainer { - + String getUUID(); + String getName(); } From 1b8c5a691b6ed9655fbcae853e4eeaff7351dde3 Mon Sep 17 00:00:00 2001 From: Sekwah Date: Fri, 25 Oct 2024 04:11:57 +0100 Subject: [PATCH 04/13] wip: enable proxy commands --- .../container/BungeeProxyContainer.java | 17 ++++++++++++++++- .../core/network/ProxyCommandPacket.java | 7 +++++-- .../config/CommandPortalConfig.java | 1 + .../advancedportals/core/tags/CommandTag.java | 15 +++++++++++++++ lang/src/main/resources/lang/en_GB.lang | 1 + .../proxycore/AdvancedPortalsProxyCore.java | 19 ++++++++++++------- 6 files changed, 50 insertions(+), 10 deletions(-) diff --git a/bungee/src/main/java/com/sekwah/advancedportals/bungee/connector/container/BungeeProxyContainer.java b/bungee/src/main/java/com/sekwah/advancedportals/bungee/connector/container/BungeeProxyContainer.java index 3aa2d3ee..4d745fc8 100644 --- a/bungee/src/main/java/com/sekwah/advancedportals/bungee/connector/container/BungeeProxyContainer.java +++ b/bungee/src/main/java/com/sekwah/advancedportals/bungee/connector/container/BungeeProxyContainer.java @@ -1,8 +1,10 @@ package com.sekwah.advancedportals.bungee.connector.container; import com.sekwah.advancedportals.bungee.AdvancedPortalsBungeePlugin; +import com.sekwah.advancedportals.core.util.Lang; import com.sekwah.advancedportals.proxycore.connector.container.ProxyContainer; import com.sekwah.advancedportals.proxycore.connector.container.ProxyPlayerContainer; +import net.md_5.bungee.api.chat.TextComponent; public class BungeeProxyContainer implements ProxyContainer { @@ -14,10 +16,23 @@ public BungeeProxyContainer(AdvancedPortalsBungeePlugin plugin) { @Override public void invokeCommand(ProxyPlayerContainer proxyPlayer, String command) { + // Should never not be true but just to be safe + if(proxyPlayer instanceof BungeeProxyPlayerContainer playerContainer) { + plugin.getProxy().getPluginManager().dispatchCommand(playerContainer.getPlayer(), command); + } } @Override public void transferPlayer(ProxyPlayerContainer proxyPlayer, String serverName) { - + // Should never not be true but just to be safe + if(proxyPlayer instanceof BungeeProxyPlayerContainer playerContainer) { + var serverInfo = plugin.getProxy().getServerInfo(serverName); + var player = playerContainer.getPlayer(); + if(serverInfo == null) { + player.sendMessage(new TextComponent(Lang.convertColors("&cCould not find server: &e") + serverName)); + return; + } + player.connect(serverInfo); + } } } diff --git a/core/src/main/java/com/sekwah/advancedportals/core/network/ProxyCommandPacket.java b/core/src/main/java/com/sekwah/advancedportals/core/network/ProxyCommandPacket.java index 8a0fcb72..3c9b9fcd 100644 --- a/core/src/main/java/com/sekwah/advancedportals/core/network/ProxyCommandPacket.java +++ b/core/src/main/java/com/sekwah/advancedportals/core/network/ProxyCommandPacket.java @@ -2,6 +2,7 @@ import com.google.common.io.ByteArrayDataInput; import com.google.common.io.ByteArrayDataOutput; +import com.google.common.io.ByteStreams; import com.sekwah.advancedportals.core.ProxyMessages; public class ProxyCommandPacket { @@ -12,9 +13,11 @@ public ProxyCommandPacket(String command) { this.command = command; } - public static void encode(ProxyCommandPacket msg, ByteArrayDataOutput buffer) { + public byte[] encode() { + ByteArrayDataOutput buffer = ByteStreams.newDataOutput(); buffer.writeUTF(ProxyMessages.PROXY_COMMAND); - buffer.writeUTF(msg.command); + buffer.writeUTF(this.command); + return buffer.toByteArray(); } public static ProxyCommandPacket decode(ByteArrayDataInput buffer) { diff --git a/core/src/main/java/com/sekwah/advancedportals/core/serializeddata/config/CommandPortalConfig.java b/core/src/main/java/com/sekwah/advancedportals/core/serializeddata/config/CommandPortalConfig.java index ac6ee47e..372fcaa5 100644 --- a/core/src/main/java/com/sekwah/advancedportals/core/serializeddata/config/CommandPortalConfig.java +++ b/core/src/main/java/com/sekwah/advancedportals/core/serializeddata/config/CommandPortalConfig.java @@ -4,5 +4,6 @@ public class CommandPortalConfig { public boolean op = true; public boolean console = true; public boolean permsWildcard = true; + public boolean proxy = true; public boolean enabled = true; } diff --git a/core/src/main/java/com/sekwah/advancedportals/core/tags/CommandTag.java b/core/src/main/java/com/sekwah/advancedportals/core/tags/CommandTag.java index 458ba03e..a320a59e 100644 --- a/core/src/main/java/com/sekwah/advancedportals/core/tags/CommandTag.java +++ b/core/src/main/java/com/sekwah/advancedportals/core/tags/CommandTag.java @@ -1,7 +1,10 @@ package com.sekwah.advancedportals.core.tags; import com.google.inject.Inject; +import com.sekwah.advancedportals.core.ProxyMessages; import com.sekwah.advancedportals.core.connector.containers.PlayerContainer; +import com.sekwah.advancedportals.core.network.ProxyCommandPacket; +import com.sekwah.advancedportals.core.network.ProxyTransferPacket; import com.sekwah.advancedportals.core.registry.TagTarget; import com.sekwah.advancedportals.core.repository.ConfigRepository; import com.sekwah.advancedportals.core.util.Lang; @@ -84,6 +87,14 @@ public boolean preActivated(TagTarget target, PlayerContainer player, return false; } break; + case '%': + if (!commandPortals.proxy || !configRepository.getEnableProxySupport()) { + player.sendMessage( + Lang.getNegativePrefix() + + Lang.translate("tag.command.proxy.disabled")); + return false; + } + break; default: break; } @@ -116,6 +127,10 @@ public void postActivated(TagTarget target, PlayerContainer player, player.getUUID(), formattedCommand.substring(1), CommandLevel.PERMISSION_WILDCARD); break; + case '%': + var packet = new ProxyCommandPacket(formattedCommand.substring(1)); + player.sendPacket(ProxyMessages.CHANNEL_NAME, packet.encode()); + break; default: player.getServer().dispatchCommand(player.getUUID(), formattedCommand, diff --git a/lang/src/main/resources/lang/en_GB.lang b/lang/src/main/resources/lang/en_GB.lang index 65b4dfc5..b282768c 100644 --- a/lang/src/main/resources/lang/en_GB.lang +++ b/lang/src/main/resources/lang/en_GB.lang @@ -189,6 +189,7 @@ tag.command.disabled= Command portals are &edisabled &con this server. Please co tag.command.op.disabled= Op command portals are &edisabled &con this server. Please contact a server admin if this is an issue. tag.command.console.disabled= Console command portals are &edisabled &con this server. Please contact a server admin if this is an issue. tag.command.permswildcard.disabled= Wildcard &e*&c permission command portals are &edisabled &con this server. Please contact a server admin if this is an issue. +tag.command.proxy.disabled= Proxy command portals are &edisabled &con this server. Please contact a server admin if this is an issue. tag.proxy.notenabled= Proxy portals are currently &edisabled &con this server. Please contact a server admin to enable them. tag.proxy.description= Sets the server destination of the portal. \ No newline at end of file diff --git a/proxycore/src/main/java/com/sekwah/advancedportals/proxycore/AdvancedPortalsProxyCore.java b/proxycore/src/main/java/com/sekwah/advancedportals/proxycore/AdvancedPortalsProxyCore.java index 9e140fcc..d768fa31 100644 --- a/proxycore/src/main/java/com/sekwah/advancedportals/proxycore/AdvancedPortalsProxyCore.java +++ b/proxycore/src/main/java/com/sekwah/advancedportals/proxycore/AdvancedPortalsProxyCore.java @@ -2,8 +2,10 @@ import com.google.common.io.ByteStreams; import com.sekwah.advancedportals.core.ProxyMessages; +import com.sekwah.advancedportals.core.network.ProxyCommandPacket; import com.sekwah.advancedportals.core.network.ProxyTransferPacket; import com.sekwah.advancedportals.core.util.InfoLogger; +import com.sekwah.advancedportals.core.util.Lang; import com.sekwah.advancedportals.proxycore.connector.container.ProxyContainer; import com.sekwah.advancedportals.proxycore.connector.container.ProxyPlayerContainer; import com.sekwah.advancedportals.proxycore.connector.container.ProxyServerContainer; @@ -19,12 +21,11 @@ public AdvancedPortalsProxyCore(InfoLogger logger, ProxyContainer proxyContainer } public void onEnable() { - this.logger.info("\u00A7aSuccessfully enabled!"); + this.logger.info(Lang.convertColors("&aSuccessfully enabled!")); } public void onDisable() { - - this.logger.info("\u00A7cDisabling plugin!"); + this.logger.info(Lang.convertColors("&cDisabling plugin!")); } public void onServerConnect(ProxyServerContainer server, ProxyPlayerContainer player) { @@ -37,7 +38,6 @@ public void onServerConnect(ProxyServerContainer server, ProxyPlayerContainer pl * @param message */ public void incomingMessage(ProxyPlayerContainer player, byte[] message) { - this.logger.info("Message received from server via " + player.getName()); var buffer = ByteStreams.newDataInput(message); var messageType = buffer.readUTF(); @@ -46,9 +46,14 @@ public void incomingMessage(ProxyPlayerContainer player, byte[] message) { // the encode behavior in the packets switch (messageType) { case ProxyMessages.PROXY_TRANSFER: - var msg = ProxyTransferPacket.decode(buffer); - this.logger.info("Transfer request for " + player.getName() + " to " + msg.getServerName()); - this.proxyContainer.transferPlayer(player, msg.getServerName()); + var transferPacket = ProxyTransferPacket.decode(buffer); + this.logger.info("Transfer request for " + player.getName() + " to " + transferPacket.getServerName()); + this.proxyContainer.transferPlayer(player, transferPacket.getServerName()); + break; + case ProxyMessages.PROXY_COMMAND: + var commandPacket = ProxyCommandPacket.decode(buffer); + this.logger.info("Command request for " + player.getName() + " to run /" + commandPacket.getCommand()); + this.proxyContainer.invokeCommand(player, commandPacket.getCommand()); break; default: this.logger.info("Unknown message type: " + messageType); From 353c4da05a441c22834d41f5d1815832e21feeda Mon Sep 17 00:00:00 2001 From: Sekwah Date: Sat, 26 Oct 2024 02:46:53 +0100 Subject: [PATCH 05/13] wip: desti tags with proxy --- .../advancedportals/core/network/Packet.java | 5 +++ .../core/network/ProxyCommandPacket.java | 2 +- .../network/ProxyTransferDestiPacket.java | 38 +++++++++++++++++++ .../core/network/ProxyTransferPacket.java | 2 +- .../advancedportals/core/tags/DestiTag.java | 18 ++++++--- .../advancedportals/core/tags/NameTag.java | 6 --- .../core/tags/PortalEventTag.java | 6 --- .../advancedportals/core/tags/ProxyTag.java | 15 +++++++- .../advancedportals/core/warphandler/Tag.java | 9 ++--- .../proxycore/AdvancedPortalsProxyCore.java | 15 ++++++++ .../connector/container/ProxyJoinData.java | 12 ++++++ 11 files changed, 101 insertions(+), 27 deletions(-) create mode 100644 core/src/main/java/com/sekwah/advancedportals/core/network/Packet.java create mode 100644 core/src/main/java/com/sekwah/advancedportals/core/network/ProxyTransferDestiPacket.java create mode 100644 proxycore/src/main/java/com/sekwah/advancedportals/proxycore/connector/container/ProxyJoinData.java diff --git a/core/src/main/java/com/sekwah/advancedportals/core/network/Packet.java b/core/src/main/java/com/sekwah/advancedportals/core/network/Packet.java new file mode 100644 index 00000000..019b4e64 --- /dev/null +++ b/core/src/main/java/com/sekwah/advancedportals/core/network/Packet.java @@ -0,0 +1,5 @@ +package com.sekwah.advancedportals.core.network; + +public interface Packet { + byte[] encode(); +} diff --git a/core/src/main/java/com/sekwah/advancedportals/core/network/ProxyCommandPacket.java b/core/src/main/java/com/sekwah/advancedportals/core/network/ProxyCommandPacket.java index 3c9b9fcd..a9353868 100644 --- a/core/src/main/java/com/sekwah/advancedportals/core/network/ProxyCommandPacket.java +++ b/core/src/main/java/com/sekwah/advancedportals/core/network/ProxyCommandPacket.java @@ -5,7 +5,7 @@ import com.google.common.io.ByteStreams; import com.sekwah.advancedportals.core.ProxyMessages; -public class ProxyCommandPacket { +public class ProxyCommandPacket implements Packet { private final String command; diff --git a/core/src/main/java/com/sekwah/advancedportals/core/network/ProxyTransferDestiPacket.java b/core/src/main/java/com/sekwah/advancedportals/core/network/ProxyTransferDestiPacket.java new file mode 100644 index 00000000..6c04860b --- /dev/null +++ b/core/src/main/java/com/sekwah/advancedportals/core/network/ProxyTransferDestiPacket.java @@ -0,0 +1,38 @@ +package com.sekwah.advancedportals.core.network; + +import com.google.common.io.ByteArrayDataInput; +import com.google.common.io.ByteArrayDataOutput; +import com.google.common.io.ByteStreams; +import com.sekwah.advancedportals.core.ProxyMessages; + +public class ProxyTransferDestiPacket implements Packet { + + private final String serverName; + private final String destination; + + public ProxyTransferDestiPacket(String serverName, String destination) { + this.serverName = serverName; + this.destination = destination; + } + + public byte[] encode() { + ByteArrayDataOutput buffer = ByteStreams.newDataOutput(); + buffer.writeUTF(ProxyMessages.PROXY_TRANSFER_DESTI); + buffer.writeUTF(this.serverName); + buffer.writeUTF(this.destination); + return buffer.toByteArray(); + + } + + public static ProxyTransferDestiPacket decode(ByteArrayDataInput buffer) { + return new ProxyTransferDestiPacket(buffer.readUTF(), buffer.readUTF()); + } + + public String getServerName() { + return serverName; + } + + public String getDestination() { + return destination; + } +} diff --git a/core/src/main/java/com/sekwah/advancedportals/core/network/ProxyTransferPacket.java b/core/src/main/java/com/sekwah/advancedportals/core/network/ProxyTransferPacket.java index 53e86ee4..417d15fd 100644 --- a/core/src/main/java/com/sekwah/advancedportals/core/network/ProxyTransferPacket.java +++ b/core/src/main/java/com/sekwah/advancedportals/core/network/ProxyTransferPacket.java @@ -5,7 +5,7 @@ import com.google.common.io.ByteStreams; import com.sekwah.advancedportals.core.ProxyMessages; -public class ProxyTransferPacket { +public class ProxyTransferPacket implements Packet { private final String serverName; diff --git a/core/src/main/java/com/sekwah/advancedportals/core/tags/DestiTag.java b/core/src/main/java/com/sekwah/advancedportals/core/tags/DestiTag.java index 774f0895..9237272e 100644 --- a/core/src/main/java/com/sekwah/advancedportals/core/tags/DestiTag.java +++ b/core/src/main/java/com/sekwah/advancedportals/core/tags/DestiTag.java @@ -67,6 +67,10 @@ public boolean preActivated(TagTarget target, PlayerContainer player, activeData.setMetadata(TAG_NAME, selectedArg); + if(activeData.getMetadata(ProxyTag.TAG_NAME) != null) { + return true; + } + if(destinationServices.getDestination(selectedArg) == null) { player.sendMessage(Lang.getNegativePrefix() + Lang.translateInsertVariables("desti.error.notfound", selectedArg)); return false; @@ -92,6 +96,10 @@ public boolean preActivated(TagTarget target, PlayerContainer player, @Override public void postActivated(TagTarget target, PlayerContainer player, ActivationData activationData, String[] argData) { + if(activationData.getMetadata(ProxyTag.TAG_NAME) != null) { + return; + } + var selectedArg = activationData.getMetadata(TAG_NAME); Destination destination = destinationServices.getDestination(selectedArg); if (destination != null) { @@ -112,6 +120,10 @@ public void postActivated(TagTarget target, PlayerContainer player, @Override public boolean activated(TagTarget target, PlayerContainer player, ActivationData activationData, String[] argData) { + if(activationData.getMetadata(ProxyTag.TAG_NAME) != null) { + return true; + } + var selectedArg = activationData.getMetadata(TAG_NAME); Destination destination = destinationServices.getDestination(selectedArg); @@ -149,10 +161,4 @@ else if(this.configRepository.warpMessageInChat()) { public List autoComplete(String argData) { return destinationServices.getDestinationNames(); } - - @Nullable - @Override - public String splitString() { - return ","; - } } diff --git a/core/src/main/java/com/sekwah/advancedportals/core/tags/NameTag.java b/core/src/main/java/com/sekwah/advancedportals/core/tags/NameTag.java index 718795ac..7706d0af 100644 --- a/core/src/main/java/com/sekwah/advancedportals/core/tags/NameTag.java +++ b/core/src/main/java/com/sekwah/advancedportals/core/tags/NameTag.java @@ -48,12 +48,6 @@ public List autoComplete(String argData) { return null; } - @Nullable - @Override - public String splitString() { - return null; - } - @Override public boolean created(TagTarget target, PlayerContainer player, String[] argData) { diff --git a/core/src/main/java/com/sekwah/advancedportals/core/tags/PortalEventTag.java b/core/src/main/java/com/sekwah/advancedportals/core/tags/PortalEventTag.java index 25c17fcf..29362cf0 100644 --- a/core/src/main/java/com/sekwah/advancedportals/core/tags/PortalEventTag.java +++ b/core/src/main/java/com/sekwah/advancedportals/core/tags/PortalEventTag.java @@ -80,12 +80,6 @@ public List autoComplete(String argData) { return List.of("true", "false"); } - @Nullable - @Override - public String splitString() { - return ""; - } - @Override public Behaviour getDenyBehavior() { return Behaviour.SILENT; diff --git a/core/src/main/java/com/sekwah/advancedportals/core/tags/ProxyTag.java b/core/src/main/java/com/sekwah/advancedportals/core/tags/ProxyTag.java index dee9193e..f0004824 100644 --- a/core/src/main/java/com/sekwah/advancedportals/core/tags/ProxyTag.java +++ b/core/src/main/java/com/sekwah/advancedportals/core/tags/ProxyTag.java @@ -5,6 +5,7 @@ import com.google.inject.Inject; import com.sekwah.advancedportals.core.ProxyMessages; import com.sekwah.advancedportals.core.connector.containers.PlayerContainer; +import com.sekwah.advancedportals.core.network.ProxyTransferDestiPacket; import com.sekwah.advancedportals.core.network.ProxyTransferPacket; import com.sekwah.advancedportals.core.registry.TagTarget; import com.sekwah.advancedportals.core.repository.ConfigRepository; @@ -12,9 +13,10 @@ import com.sekwah.advancedportals.core.warphandler.ActivationData; import com.sekwah.advancedportals.core.warphandler.Tag; +import javax.annotation.Nullable; import java.util.Random; -public class ProxyTag implements Tag.Activation { +public class ProxyTag implements Tag.Activation, Tag.OrderPriority, Tag.Split { @Inject ConfigRepository configRepository; @@ -48,6 +50,8 @@ public String description() { @Override public boolean preActivated(TagTarget target, PlayerContainer player, ActivationData activeData, String[] argData) { + String selectedArg = argData[random.nextInt(argData.length)]; + activeData.setMetadata(TAG_NAME, selectedArg); return true; } @@ -66,9 +70,16 @@ public boolean activated(TagTarget target, PlayerContainer player, ActivationDat String selectedArg = argData[random.nextInt(argData.length)]; - var packet = new ProxyTransferPacket(selectedArg); + var desti = activeData.getMetadata(DestiTag.TAG_NAME); + + var packet = desti == null ? new ProxyTransferPacket(selectedArg) : new ProxyTransferDestiPacket(selectedArg, desti); player.sendPacket(ProxyMessages.CHANNEL_NAME, packet.encode()); activeData.setWarpStatus(ActivationData.WarpedStatus.WARPED); return true; } + + @Override + public Priority getPriority() { + return Priority.HIGHEST; + } } diff --git a/core/src/main/java/com/sekwah/advancedportals/core/warphandler/Tag.java b/core/src/main/java/com/sekwah/advancedportals/core/warphandler/Tag.java index 1b0883b0..0e7d1171 100644 --- a/core/src/main/java/com/sekwah/advancedportals/core/warphandler/Tag.java +++ b/core/src/main/java/com/sekwah/advancedportals/core/warphandler/Tag.java @@ -29,7 +29,7 @@ public interface Tag { */ enum TagType { PORTAL, DESTINATION } - enum Priority { LOWEST, LOW, NORMAL, HIGH, HIGHEST } + enum Priority { HIGHEST, HIGH, NORMAL, LOW, LOWEST } /** * Used to flag where the auto complete should show more or less info. @@ -65,9 +65,6 @@ interface AutoComplete extends Tag { */ @Nullable List autoComplete(String argData); - - @Nullable - String splitString(); } interface Split extends Tag { @@ -78,7 +75,9 @@ interface Split extends Tag { * @return null if the tag does not support splitting */ @Nullable - String splitString(); + default String splitString() { + return ","; + } } /** diff --git a/proxycore/src/main/java/com/sekwah/advancedportals/proxycore/AdvancedPortalsProxyCore.java b/proxycore/src/main/java/com/sekwah/advancedportals/proxycore/AdvancedPortalsProxyCore.java index d768fa31..f0efb6d8 100644 --- a/proxycore/src/main/java/com/sekwah/advancedportals/proxycore/AdvancedPortalsProxyCore.java +++ b/proxycore/src/main/java/com/sekwah/advancedportals/proxycore/AdvancedPortalsProxyCore.java @@ -3,18 +3,29 @@ import com.google.common.io.ByteStreams; import com.sekwah.advancedportals.core.ProxyMessages; import com.sekwah.advancedportals.core.network.ProxyCommandPacket; +import com.sekwah.advancedportals.core.network.ProxyTransferDestiPacket; import com.sekwah.advancedportals.core.network.ProxyTransferPacket; import com.sekwah.advancedportals.core.util.InfoLogger; import com.sekwah.advancedportals.core.util.Lang; import com.sekwah.advancedportals.proxycore.connector.container.ProxyContainer; +import com.sekwah.advancedportals.proxycore.connector.container.ProxyJoinData; import com.sekwah.advancedportals.proxycore.connector.container.ProxyPlayerContainer; import com.sekwah.advancedportals.proxycore.connector.container.ProxyServerContainer; +import java.util.HashMap; + public class AdvancedPortalsProxyCore { private final InfoLogger logger; private final ProxyContainer proxyContainer; + /** + * Keep a list of destinations players have been moved to + * + // TODO add a time to check against for this data to expire, and add a way to clean the data up every now and then + */ + public HashMap PlayerJoinMap = new HashMap<>(); + public AdvancedPortalsProxyCore(InfoLogger logger, ProxyContainer proxyContainer) { this.logger = logger; this.proxyContainer = proxyContainer; @@ -55,6 +66,10 @@ public void incomingMessage(ProxyPlayerContainer player, byte[] message) { this.logger.info("Command request for " + player.getName() + " to run /" + commandPacket.getCommand()); this.proxyContainer.invokeCommand(player, commandPacket.getCommand()); break; + case ProxyMessages.PROXY_TRANSFER_DESTI: + var transferDestiPacket = ProxyTransferDestiPacket.decode(buffer); + this.logger.info("Transfer request for " + player.getName() + " to " + transferDestiPacket.getServerName() + " with destination " + transferDestiPacket.getDestination()); + this.proxyContainer.transferPlayer(player, transferDestiPacket.getServerName()); default: this.logger.info("Unknown message type: " + messageType); } diff --git a/proxycore/src/main/java/com/sekwah/advancedportals/proxycore/connector/container/ProxyJoinData.java b/proxycore/src/main/java/com/sekwah/advancedportals/proxycore/connector/container/ProxyJoinData.java new file mode 100644 index 00000000..7c8d4469 --- /dev/null +++ b/proxycore/src/main/java/com/sekwah/advancedportals/proxycore/connector/container/ProxyJoinData.java @@ -0,0 +1,12 @@ +package com.sekwah.advancedportals.proxycore.connector.container; + +public class ProxyJoinData { + + private final String destination; + private final String serverName; + + public ProxyJoinData(String destination, String serverName) { + this.destination = destination; + this.serverName = serverName; + } +} From f72aea4bfe5ec010395cca5c4b55b456f3dc5ff6 Mon Sep 17 00:00:00 2001 From: Sekwah Date: Sat, 9 Nov 2024 02:34:17 +0000 Subject: [PATCH 06/13] chore: add version constant templating --- .versionrc.js | 65 ------------------- build.gradle | 13 ++++ core/build.gradle | 25 ++++++- .../advancedportals/core/BuildConstants.java | 5 ++ .../AdvancedPortalsVelocityPlugin.java | 25 +++++++ .../velocity/VelocityInfoLogger.java | 7 ++ 6 files changed, 72 insertions(+), 68 deletions(-) delete mode 100644 .versionrc.js create mode 100644 core/src/main/templates/com/sekwah/advancedportals/core/BuildConstants.java create mode 100644 velocity/src/main/java/com/sekwah/advancedportals/velocity/AdvancedPortalsVelocityPlugin.java create mode 100644 velocity/src/main/java/com/sekwah/advancedportals/velocity/VelocityInfoLogger.java diff --git a/.versionrc.js b/.versionrc.js deleted file mode 100644 index a5b60d29..00000000 --- a/.versionrc.js +++ /dev/null @@ -1,65 +0,0 @@ -let versionRegex = /(\nversion:\s)([0-9.-]+)/; -let velocityVersionRegex = /(\sversion\s=\s")([0-9.-]+)("\))/; - - -const ymlUpdater = { - updater: { - 'readVersion': (contents) => { - return versionRegex.exec(contents)[2]; - }, - 'writeVersion': (contents, version) => { - return contents.replace(versionRegex, `$1${version}`); - } - } -} - -const bungee = { - filename: 'src/main/resources/bungee.yml', - ...ymlUpdater, -} - -const spigotPlugin = { - filename: 'spigot/src/main/resources/plugin.yml', - ...ymlUpdater, -} - - -const gradleTracker = { - filename: 'gradle.properties', - updater: { - 'readVersion': (contents) => { - return versionRegex.exec(contents)[2]; - }, - 'writeVersion': (contents, version) => { - return contents.replace(versionRegex, `$1${version}`); - } - } -} - - -const velocity_plugin = { - filename: 'src/main/java/com/sekwah/advancedportals/velocity/AdvancedPortalsPlugin.java', - updater: { - 'readVersion': (contents) => { - return velocityVersionRegex.exec(contents)[2]; - }, - 'writeVersion': (contents, version) => { - return contents.replace(velocityVersionRegex, `$1${version}$3`); - } - } -} - -const files = [gradleTracker] // spigotPlugin, velocity_plugin, bungee - -module.exports = { - bumpFiles: files, - packageFiles: files, - // In case you need to force a version change (mostly due to change of scope of the update e.g. major now instead of patch) - //releaseAs: '1.0.0', - header:"# Changelog\n" + - "\n" + - "All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.\n" + - "\n" + - "For the release changelogs see [CHANGELOG.md](CHANGELOG.md) \n" + - "For the snapshot changelogs see [SNAPSHOT_CHANGELOG.md](SNAPSHOT_CHANGELOG.md)\n", -} diff --git a/build.gradle b/build.gradle index 932f08e2..e9ccd177 100644 --- a/build.gradle +++ b/build.gradle @@ -19,10 +19,12 @@ buildscript { plugins { id 'dev.s7a.gradle.minecraft.server' version '1.1.0' + id 'org.jetbrains.gradle.plugin.idea-ext' version '1.1.7' } allprojects { apply plugin: 'java' + apply plugin: 'idea' tasks.withType(JavaCompile).configureEach { options.encoding = 'UTF-8' @@ -171,3 +173,14 @@ tasks.register('runJar') { } } } + + +idea { + project { + settings { + taskTriggers { + afterSync(project(':core').tasks.named('generateTemplates')) + } + } + } +} diff --git a/core/build.gradle b/core/build.gradle index a96c2699..28d03766 100644 --- a/core/build.gradle +++ b/core/build.gradle @@ -1,6 +1,9 @@ -apply plugin: 'maven-publish' -apply plugin: 'idea' -apply plugin: 'eclipse' + +plugins { + id 'maven-publish' + id 'idea' + id 'eclipse' +} configurations { // configuration that holds jars to copy into lib @@ -32,3 +35,19 @@ jar { } } +def templateSource = file('src/main/templates') +def templateDest = layout.buildDirectory.dir('generated/sources/templates') + +def generateTemplates = tasks.register('generateTemplates', Copy) { task -> + def props = [ + 'version': project.version + ] + task.inputs.properties props + + task.from templateSource + task.into templateDest + task.expand props +} + +sourceSets.main.java.srcDir(generateTemplates.map { it.outputs }) + diff --git a/core/src/main/templates/com/sekwah/advancedportals/core/BuildConstants.java b/core/src/main/templates/com/sekwah/advancedportals/core/BuildConstants.java new file mode 100644 index 00000000..03a9c4d6 --- /dev/null +++ b/core/src/main/templates/com/sekwah/advancedportals/core/BuildConstants.java @@ -0,0 +1,5 @@ +package com.sekwah.advancedportals.core; + +public class BuildConstants { + public static final String VERSION = "${version}"; +} \ No newline at end of file diff --git a/velocity/src/main/java/com/sekwah/advancedportals/velocity/AdvancedPortalsVelocityPlugin.java b/velocity/src/main/java/com/sekwah/advancedportals/velocity/AdvancedPortalsVelocityPlugin.java new file mode 100644 index 00000000..88f273c3 --- /dev/null +++ b/velocity/src/main/java/com/sekwah/advancedportals/velocity/AdvancedPortalsVelocityPlugin.java @@ -0,0 +1,25 @@ +package com.sekwah.advancedportals.velocity; + +import com.google.inject.Inject; +import com.sekwah.advancedportals.core.BuildConstants; +import com.velocitypowered.api.proxy.ProxyServer; +import com.velocitypowered.api.plugin.Plugin; +import org.slf4j.Logger; + +@Plugin(authors = {"sekwah41"} ,id = "advancedportals", name = "Advanced Portals", + url = "https://www.spigotmc.org/resources/advanced-portals.14356/", + version = BuildConstants.VERSION) +public class AdvancedPortalsVelocityPlugin { + + private final Logger logger; + private final ProxyServer proxy; + + @Inject + public AdvancedPortalsVelocityPlugin(ProxyServer proxy, Logger logger) { + + this.proxy = proxy; + this.logger = logger; + + } + +} diff --git a/velocity/src/main/java/com/sekwah/advancedportals/velocity/VelocityInfoLogger.java b/velocity/src/main/java/com/sekwah/advancedportals/velocity/VelocityInfoLogger.java new file mode 100644 index 00000000..2d3a387c --- /dev/null +++ b/velocity/src/main/java/com/sekwah/advancedportals/velocity/VelocityInfoLogger.java @@ -0,0 +1,7 @@ +package com.sekwah.advancedportals.velocity; +import org.slf4j.Logger; + +public class VelocityInfoLogger { + + +} From 76ddfc1a2dd82ca40f1af70c580cb6fbb5760583 Mon Sep 17 00:00:00 2001 From: Sekwah Date: Sat, 9 Nov 2024 03:40:40 +0000 Subject: [PATCH 07/13] feat: add velocity color converter for logs --- velocity/build.gradle | 7 ++- .../AdvancedPortalsVelocityPlugin.java | 8 ++- .../velocity/VelocityInfoLogger.java | 28 +++++++++- .../velocity/connector/MinecraftToAnsi.java | 55 +++++++++++++++++++ .../container/VelocityProxyContainer.java | 16 ++++++ 5 files changed, 109 insertions(+), 5 deletions(-) create mode 100644 velocity/src/main/java/com/sekwah/advancedportals/velocity/connector/MinecraftToAnsi.java create mode 100644 velocity/src/main/java/com/sekwah/advancedportals/velocity/connector/container/VelocityProxyContainer.java diff --git a/velocity/build.gradle b/velocity/build.gradle index a7ec0fa0..8f0a91ef 100644 --- a/velocity/build.gradle +++ b/velocity/build.gradle @@ -7,12 +7,15 @@ configurations { repositories { maven { url "https://repo.maven.apache.org/maven2" } - maven { url 'https://papermc.io/repo/repository/maven-public/' } - maven { url "https://nexus.velocitypowered.com/repository/maven-public/" } + maven { + name 'papermc' + url 'https://repo.papermc.io/repository/maven-public/' + } } // includeLibs just says to include the library in the final jar dependencies { + implementation project(":proxycore") implementation project(":core") implementation("com.velocitypowered:velocity-api:3.1.0") diff --git a/velocity/src/main/java/com/sekwah/advancedportals/velocity/AdvancedPortalsVelocityPlugin.java b/velocity/src/main/java/com/sekwah/advancedportals/velocity/AdvancedPortalsVelocityPlugin.java index 88f273c3..a3d67777 100644 --- a/velocity/src/main/java/com/sekwah/advancedportals/velocity/AdvancedPortalsVelocityPlugin.java +++ b/velocity/src/main/java/com/sekwah/advancedportals/velocity/AdvancedPortalsVelocityPlugin.java @@ -2,6 +2,8 @@ import com.google.inject.Inject; import com.sekwah.advancedportals.core.BuildConstants; +import com.sekwah.advancedportals.proxycore.AdvancedPortalsProxyCore; +import com.sekwah.advancedportals.velocity.connector.container.VelocityProxyContainer; import com.velocitypowered.api.proxy.ProxyServer; import com.velocitypowered.api.plugin.Plugin; import org.slf4j.Logger; @@ -11,15 +13,17 @@ version = BuildConstants.VERSION) public class AdvancedPortalsVelocityPlugin { + private AdvancedPortalsProxyCore proxyCore; + private final Logger logger; private final ProxyServer proxy; @Inject public AdvancedPortalsVelocityPlugin(ProxyServer proxy, Logger logger) { - this.proxy = proxy; this.logger = logger; - + this.proxyCore = new AdvancedPortalsProxyCore(new VelocityInfoLogger(this.logger, this.proxy), new VelocityProxyContainer()); + this.proxyCore.onEnable(); } } diff --git a/velocity/src/main/java/com/sekwah/advancedportals/velocity/VelocityInfoLogger.java b/velocity/src/main/java/com/sekwah/advancedportals/velocity/VelocityInfoLogger.java index 2d3a387c..64150640 100644 --- a/velocity/src/main/java/com/sekwah/advancedportals/velocity/VelocityInfoLogger.java +++ b/velocity/src/main/java/com/sekwah/advancedportals/velocity/VelocityInfoLogger.java @@ -1,7 +1,33 @@ package com.sekwah.advancedportals.velocity; +import com.sekwah.advancedportals.core.util.InfoLogger; +import com.sekwah.advancedportals.velocity.connector.MinecraftToAnsi; +import com.velocitypowered.api.proxy.ProxyServer; +import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer; import org.slf4j.Logger; -public class VelocityInfoLogger { +public class VelocityInfoLogger extends InfoLogger { + private final Logger logger; + private final ProxyServer proxy; + private final LegacyComponentSerializer serializer = LegacyComponentSerializer.builder().character('&').hexCharacter('#').hexColors().build(); + public VelocityInfoLogger(Logger logger, ProxyServer proxy) { + this.logger = logger; + this.proxy = proxy; + } + + @Override + public void warning(String s) { + logger.warn(MinecraftToAnsi.convert(s)); + } + + @Override + public void info(String s) { + logger.info(MinecraftToAnsi.convert(s)); + } + + @Override + public void error(Exception e) { + logger.error(MinecraftToAnsi.convert("\u00A7c" + e.getMessage()), e); + } } diff --git a/velocity/src/main/java/com/sekwah/advancedportals/velocity/connector/MinecraftToAnsi.java b/velocity/src/main/java/com/sekwah/advancedportals/velocity/connector/MinecraftToAnsi.java new file mode 100644 index 00000000..822c5d4e --- /dev/null +++ b/velocity/src/main/java/com/sekwah/advancedportals/velocity/connector/MinecraftToAnsi.java @@ -0,0 +1,55 @@ +package com.sekwah.advancedportals.velocity.connector; + +import java.util.HashMap; +import java.util.Map; + +/** + * I believe later versions of velocity have some component handlers for this, and I could just send it to the server as components + * but ive decided to throw this in for now just to use the plugin logger. Also, to try to clone the bungee behavior as close as possible. + */ +public class MinecraftToAnsi { + + private static final Map minecraftToAnsiMap = new HashMap<>(); + + static { + minecraftToAnsiMap.put('0', "\u001B[30m"); // Black + minecraftToAnsiMap.put('1', "\u001B[34m"); // Dark Blue + minecraftToAnsiMap.put('2', "\u001B[32m"); // Dark Green + minecraftToAnsiMap.put('3', "\u001B[36m"); // Dark Aqua + minecraftToAnsiMap.put('4', "\u001B[31m"); // Dark Red + minecraftToAnsiMap.put('5', "\u001B[35m"); // Dark Purple + minecraftToAnsiMap.put('6', "\u001B[33m"); // Gold + minecraftToAnsiMap.put('7', "\u001B[37m"); // Gray + minecraftToAnsiMap.put('8', "\u001B[90m"); // Dark Gray + minecraftToAnsiMap.put('9', "\u001B[94m"); // Blue + minecraftToAnsiMap.put('a', "\u001B[92m"); // Green + minecraftToAnsiMap.put('b', "\u001B[96m"); // Aqua + minecraftToAnsiMap.put('c', "\u001B[91m"); // Red + minecraftToAnsiMap.put('d', "\u001B[95m"); // Light Purple + minecraftToAnsiMap.put('e', "\u001B[93m"); // Yellow + minecraftToAnsiMap.put('f', "\u001B[97m"); // White + minecraftToAnsiMap.put('k', "\u001B[5m"); // Obfuscated (Blinking) + minecraftToAnsiMap.put('l', "\u001B[1m"); // Bold + minecraftToAnsiMap.put('m', "\u001B[9m"); // Strikethrough + minecraftToAnsiMap.put('n', "\u001B[4m"); // Underline + minecraftToAnsiMap.put('o', "\u001B[3m"); // Italic + minecraftToAnsiMap.put('r', "\u001B[0m"); // Reset + } + + public static String convert(String text) { + StringBuilder result = new StringBuilder(); + for (int i = 0; i < text.length(); i++) { + if (text.charAt(i) == '\u00A7' && i + 1 < text.length()) { + char code = Character.toLowerCase(text.charAt(i + 1)); + String ansiCode = minecraftToAnsiMap.getOrDefault(code, ""); + result.append(ansiCode); + i++; + } else { + result.append(text.charAt(i)); + } + } + + result.append("\u001B[0m"); + return result.toString(); + } +} diff --git a/velocity/src/main/java/com/sekwah/advancedportals/velocity/connector/container/VelocityProxyContainer.java b/velocity/src/main/java/com/sekwah/advancedportals/velocity/connector/container/VelocityProxyContainer.java new file mode 100644 index 00000000..1e8b316f --- /dev/null +++ b/velocity/src/main/java/com/sekwah/advancedportals/velocity/connector/container/VelocityProxyContainer.java @@ -0,0 +1,16 @@ +package com.sekwah.advancedportals.velocity.connector.container; + +import com.sekwah.advancedportals.proxycore.connector.container.ProxyContainer; +import com.sekwah.advancedportals.proxycore.connector.container.ProxyPlayerContainer; + +public class VelocityProxyContainer implements ProxyContainer { + @Override + public void invokeCommand(ProxyPlayerContainer proxyPlayer, String command) { + + } + + @Override + public void transferPlayer(ProxyPlayerContainer proxyPlayer, String serverName) { + + } +} From d4f38a9eb6c4d94b9208a5b052a5f351dafb0394 Mon Sep 17 00:00:00 2001 From: Sekwah Date: Sat, 9 Nov 2024 04:11:13 +0000 Subject: [PATCH 08/13] feat: proxy tag now works for both velocity as well as bungee (minus desti working) --- .../proxycore/AdvancedPortalsProxyCore.java | 1 + .../AdvancedPortalsVelocityPlugin.java | 41 ++++++++++++++++++- .../container/VelocityProxyContainer.java | 21 +++++++++- .../VelocityProxyPlayerContainer.java | 27 ++++++++++++ .../VelocityProxyServerContainer.java | 10 +++++ 5 files changed, 97 insertions(+), 3 deletions(-) create mode 100644 velocity/src/main/java/com/sekwah/advancedportals/velocity/connector/container/VelocityProxyPlayerContainer.java create mode 100644 velocity/src/main/java/com/sekwah/advancedportals/velocity/connector/container/VelocityProxyServerContainer.java diff --git a/proxycore/src/main/java/com/sekwah/advancedportals/proxycore/AdvancedPortalsProxyCore.java b/proxycore/src/main/java/com/sekwah/advancedportals/proxycore/AdvancedPortalsProxyCore.java index f0efb6d8..721154b0 100644 --- a/proxycore/src/main/java/com/sekwah/advancedportals/proxycore/AdvancedPortalsProxyCore.java +++ b/proxycore/src/main/java/com/sekwah/advancedportals/proxycore/AdvancedPortalsProxyCore.java @@ -70,6 +70,7 @@ public void incomingMessage(ProxyPlayerContainer player, byte[] message) { var transferDestiPacket = ProxyTransferDestiPacket.decode(buffer); this.logger.info("Transfer request for " + player.getName() + " to " + transferDestiPacket.getServerName() + " with destination " + transferDestiPacket.getDestination()); this.proxyContainer.transferPlayer(player, transferDestiPacket.getServerName()); + break; default: this.logger.info("Unknown message type: " + messageType); } diff --git a/velocity/src/main/java/com/sekwah/advancedportals/velocity/AdvancedPortalsVelocityPlugin.java b/velocity/src/main/java/com/sekwah/advancedportals/velocity/AdvancedPortalsVelocityPlugin.java index a3d67777..476bd113 100644 --- a/velocity/src/main/java/com/sekwah/advancedportals/velocity/AdvancedPortalsVelocityPlugin.java +++ b/velocity/src/main/java/com/sekwah/advancedportals/velocity/AdvancedPortalsVelocityPlugin.java @@ -1,12 +1,23 @@ package com.sekwah.advancedportals.velocity; +import com.google.common.io.ByteArrayDataInput; +import com.google.common.io.ByteStreams; import com.google.inject.Inject; import com.sekwah.advancedportals.core.BuildConstants; +import com.sekwah.advancedportals.core.ProxyMessages; import com.sekwah.advancedportals.proxycore.AdvancedPortalsProxyCore; import com.sekwah.advancedportals.velocity.connector.container.VelocityProxyContainer; +import com.sekwah.advancedportals.velocity.connector.container.VelocityProxyPlayerContainer; +import com.sekwah.advancedportals.velocity.connector.container.VelocityProxyServerContainer; +import com.velocitypowered.api.event.Subscribe; +import com.velocitypowered.api.event.connection.PluginMessageEvent; +import com.velocitypowered.api.event.player.ServerPostConnectEvent; +import com.velocitypowered.api.event.proxy.ProxyInitializeEvent; import com.velocitypowered.api.proxy.ProxyServer; import com.velocitypowered.api.plugin.Plugin; +import com.velocitypowered.api.proxy.ServerConnection; import org.slf4j.Logger; +import com.velocitypowered.api.proxy.messages.LegacyChannelIdentifier; @Plugin(authors = {"sekwah41"} ,id = "advancedportals", name = "Advanced Portals", url = "https://www.spigotmc.org/resources/advanced-portals.14356/", @@ -18,12 +29,40 @@ public class AdvancedPortalsVelocityPlugin { private final Logger logger; private final ProxyServer proxy; + private LegacyChannelIdentifier AP_CHANNEL; + @Inject public AdvancedPortalsVelocityPlugin(ProxyServer proxy, Logger logger) { this.proxy = proxy; this.logger = logger; - this.proxyCore = new AdvancedPortalsProxyCore(new VelocityInfoLogger(this.logger, this.proxy), new VelocityProxyContainer()); + this.proxyCore = new AdvancedPortalsProxyCore(new VelocityInfoLogger(this.logger, this.proxy), new VelocityProxyContainer(this.proxy)); this.proxyCore.onEnable(); } + @Subscribe + public void onProxyInitialize(ProxyInitializeEvent event) { + AP_CHANNEL = new LegacyChannelIdentifier(ProxyMessages.CHANNEL_NAME); + + proxy.getChannelRegistrar().register(AP_CHANNEL); + } + + @Subscribe + public void onPluginMessage(PluginMessageEvent event) { + if (event.getIdentifier().equals(AP_CHANNEL)) { + if(event.getSource() instanceof ServerConnection serverConnection) { + this.proxyCore.incomingMessage(new VelocityProxyPlayerContainer(serverConnection.getPlayer()), event.getData()); + } + // So that client packets don't make it through to the servers, always trigger on this channel. + event.setResult(PluginMessageEvent.ForwardResult.handled()); + } + } + + + @Subscribe + public void postJoinEvent(ServerPostConnectEvent event) { + event.getPlayer().getCurrentServer().ifPresent(serverConnection -> { + this.proxyCore.onServerConnect(new VelocityProxyServerContainer(serverConnection.getServer()), new VelocityProxyPlayerContainer(event.getPlayer())); + }); + } + } diff --git a/velocity/src/main/java/com/sekwah/advancedportals/velocity/connector/container/VelocityProxyContainer.java b/velocity/src/main/java/com/sekwah/advancedportals/velocity/connector/container/VelocityProxyContainer.java index 1e8b316f..1cd38957 100644 --- a/velocity/src/main/java/com/sekwah/advancedportals/velocity/connector/container/VelocityProxyContainer.java +++ b/velocity/src/main/java/com/sekwah/advancedportals/velocity/connector/container/VelocityProxyContainer.java @@ -2,15 +2,32 @@ import com.sekwah.advancedportals.proxycore.connector.container.ProxyContainer; import com.sekwah.advancedportals.proxycore.connector.container.ProxyPlayerContainer; +import com.velocitypowered.api.proxy.ProxyServer; +import net.kyori.adventure.text.Component; public class VelocityProxyContainer implements ProxyContainer { + private final ProxyServer proxy; + + public VelocityProxyContainer(ProxyServer proxy) { + this.proxy = proxy; + } + @Override public void invokeCommand(ProxyPlayerContainer proxyPlayer, String command) { - + if(proxyPlayer instanceof VelocityProxyPlayerContainer playerContainer) { + this.proxy.getCommandManager().executeAsync(playerContainer.getPlayer(), command); + } } @Override public void transferPlayer(ProxyPlayerContainer proxyPlayer, String serverName) { - + if(proxyPlayer instanceof VelocityProxyPlayerContainer playerContainer) { + this.proxy.getServer(serverName).ifPresentOrElse( + server -> { + playerContainer.getPlayer().createConnectionRequest(server).fireAndForget(); + }, + () -> playerContainer.getPlayer().sendMessage(Component.text("Could not find server: " + serverName)) + ); + } } } diff --git a/velocity/src/main/java/com/sekwah/advancedportals/velocity/connector/container/VelocityProxyPlayerContainer.java b/velocity/src/main/java/com/sekwah/advancedportals/velocity/connector/container/VelocityProxyPlayerContainer.java new file mode 100644 index 00000000..6d162e8d --- /dev/null +++ b/velocity/src/main/java/com/sekwah/advancedportals/velocity/connector/container/VelocityProxyPlayerContainer.java @@ -0,0 +1,27 @@ +package com.sekwah.advancedportals.velocity.connector.container; + +import com.sekwah.advancedportals.proxycore.connector.container.ProxyPlayerContainer; +import com.velocitypowered.api.proxy.Player; + +public class VelocityProxyPlayerContainer implements ProxyPlayerContainer { + + private final Player player; + + public VelocityProxyPlayerContainer(Player player) { + this.player = player; + } + + @Override + public String getUUID() { + return player.getUniqueId().toString(); + } + + @Override + public String getName() { + return player.getUsername(); + } + + public Player getPlayer() { + return this.player; + } +} diff --git a/velocity/src/main/java/com/sekwah/advancedportals/velocity/connector/container/VelocityProxyServerContainer.java b/velocity/src/main/java/com/sekwah/advancedportals/velocity/connector/container/VelocityProxyServerContainer.java new file mode 100644 index 00000000..508bdf64 --- /dev/null +++ b/velocity/src/main/java/com/sekwah/advancedportals/velocity/connector/container/VelocityProxyServerContainer.java @@ -0,0 +1,10 @@ +package com.sekwah.advancedportals.velocity.connector.container; + +import com.sekwah.advancedportals.proxycore.connector.container.ProxyServerContainer; +import com.velocitypowered.api.proxy.server.RegisteredServer; + +public class VelocityProxyServerContainer implements ProxyServerContainer { + public VelocityProxyServerContainer(RegisteredServer currentServer) { + + } +} From 2a2a2668accdc4f8183539f0495f270ef10bf179 Mon Sep 17 00:00:00 2001 From: Sekwah Date: Sat, 9 Nov 2024 04:28:35 +0000 Subject: [PATCH 09/13] feat: send the destination data to the server --- .../advancedportals/bungee/EventListener.java | 6 ++++++ .../container/BungeeProxyServerContainer.java | 5 +++++ .../proxycore/AdvancedPortalsProxyCore.java | 17 +++++++++++------ .../connector/container/ProxyJoinData.java | 10 ++++++++-- .../container/ProxyServerContainer.java | 1 + .../velocity/AdvancedPortalsVelocityPlugin.java | 8 ++++++-- .../container/VelocityProxyServerContainer.java | 9 ++++++++- 7 files changed, 45 insertions(+), 11 deletions(-) diff --git a/bungee/src/main/java/com/sekwah/advancedportals/bungee/EventListener.java b/bungee/src/main/java/com/sekwah/advancedportals/bungee/EventListener.java index 5ffc43f0..605a3cce 100644 --- a/bungee/src/main/java/com/sekwah/advancedportals/bungee/EventListener.java +++ b/bungee/src/main/java/com/sekwah/advancedportals/bungee/EventListener.java @@ -6,6 +6,7 @@ import com.sekwah.advancedportals.proxycore.AdvancedPortalsProxyCore; import net.md_5.bungee.api.connection.ProxiedPlayer; import net.md_5.bungee.api.connection.Server; +import net.md_5.bungee.api.event.PlayerDisconnectEvent; import net.md_5.bungee.api.event.PluginMessageEvent; import net.md_5.bungee.api.event.ServerConnectedEvent; import net.md_5.bungee.api.plugin.Listener; @@ -38,4 +39,9 @@ public void onMessageReceived(PluginMessageEvent event) { public void onServerConnected(ServerConnectedEvent event) { this.proxyCore.onServerConnect(new BungeeProxyServerContainer(event.getServer()), new BungeeProxyPlayerContainer(event.getPlayer())); } + + @EventHandler + public void onDisconnect(PlayerDisconnectEvent event) { + this.proxyCore.onPlayerDisconnect(new BungeeProxyPlayerContainer(event.getPlayer())); + } } diff --git a/bungee/src/main/java/com/sekwah/advancedportals/bungee/connector/container/BungeeProxyServerContainer.java b/bungee/src/main/java/com/sekwah/advancedportals/bungee/connector/container/BungeeProxyServerContainer.java index aa9e2e12..53473d71 100644 --- a/bungee/src/main/java/com/sekwah/advancedportals/bungee/connector/container/BungeeProxyServerContainer.java +++ b/bungee/src/main/java/com/sekwah/advancedportals/bungee/connector/container/BungeeProxyServerContainer.java @@ -9,4 +9,9 @@ public class BungeeProxyServerContainer implements ProxyServerContainer { public BungeeProxyServerContainer(Server server) { this.server = server; } + + @Override + public String getServerName() { + return this.server.getInfo().getName(); + } } diff --git a/proxycore/src/main/java/com/sekwah/advancedportals/proxycore/AdvancedPortalsProxyCore.java b/proxycore/src/main/java/com/sekwah/advancedportals/proxycore/AdvancedPortalsProxyCore.java index 721154b0..c2af36cc 100644 --- a/proxycore/src/main/java/com/sekwah/advancedportals/proxycore/AdvancedPortalsProxyCore.java +++ b/proxycore/src/main/java/com/sekwah/advancedportals/proxycore/AdvancedPortalsProxyCore.java @@ -19,12 +19,7 @@ public class AdvancedPortalsProxyCore { private final InfoLogger logger; private final ProxyContainer proxyContainer; - /** - * Keep a list of destinations players have been moved to - * - // TODO add a time to check against for this data to expire, and add a way to clean the data up every now and then - */ - public HashMap PlayerJoinMap = new HashMap<>(); + public HashMap playerJoinMap = new HashMap<>(); public AdvancedPortalsProxyCore(InfoLogger logger, ProxyContainer proxyContainer) { this.logger = logger; @@ -40,7 +35,16 @@ public void onDisable() { } public void onServerConnect(ProxyServerContainer server, ProxyPlayerContainer player) { + if(this.playerJoinMap.containsKey(player.getUUID())) { + var joinData = this.playerJoinMap.get(player.getUUID()); + if(joinData.isExpired()) return; + this.logger.info("Sending desti data for " + player.getName() + " to " + server.getServerName() + " with destination " + joinData.destination); + this.playerJoinMap.remove(player.getUUID()); + } + } + public void onPlayerDisconnect(ProxyPlayerContainer player) { + this.playerJoinMap.remove(player.getUUID()); } /** @@ -70,6 +74,7 @@ public void incomingMessage(ProxyPlayerContainer player, byte[] message) { var transferDestiPacket = ProxyTransferDestiPacket.decode(buffer); this.logger.info("Transfer request for " + player.getName() + " to " + transferDestiPacket.getServerName() + " with destination " + transferDestiPacket.getDestination()); this.proxyContainer.transferPlayer(player, transferDestiPacket.getServerName()); + this.playerJoinMap.put(player.getUUID(), new ProxyJoinData(transferDestiPacket.getDestination(), transferDestiPacket.getServerName())); break; default: this.logger.info("Unknown message type: " + messageType); diff --git a/proxycore/src/main/java/com/sekwah/advancedportals/proxycore/connector/container/ProxyJoinData.java b/proxycore/src/main/java/com/sekwah/advancedportals/proxycore/connector/container/ProxyJoinData.java index 7c8d4469..f8dbfd09 100644 --- a/proxycore/src/main/java/com/sekwah/advancedportals/proxycore/connector/container/ProxyJoinData.java +++ b/proxycore/src/main/java/com/sekwah/advancedportals/proxycore/connector/container/ProxyJoinData.java @@ -2,11 +2,17 @@ public class ProxyJoinData { - private final String destination; - private final String serverName; + public final String destination; + public final String serverName; + public final long joinTime; public ProxyJoinData(String destination, String serverName) { this.destination = destination; this.serverName = serverName; + this.joinTime = System.currentTimeMillis(); + } + + public boolean isExpired() { + return System.currentTimeMillis() - this.joinTime > 1000 * 15; // 15 seconds } } diff --git a/proxycore/src/main/java/com/sekwah/advancedportals/proxycore/connector/container/ProxyServerContainer.java b/proxycore/src/main/java/com/sekwah/advancedportals/proxycore/connector/container/ProxyServerContainer.java index 1486bdff..b90fdc13 100644 --- a/proxycore/src/main/java/com/sekwah/advancedportals/proxycore/connector/container/ProxyServerContainer.java +++ b/proxycore/src/main/java/com/sekwah/advancedportals/proxycore/connector/container/ProxyServerContainer.java @@ -1,4 +1,5 @@ package com.sekwah.advancedportals.proxycore.connector.container; public interface ProxyServerContainer { + String getServerName(); } diff --git a/velocity/src/main/java/com/sekwah/advancedportals/velocity/AdvancedPortalsVelocityPlugin.java b/velocity/src/main/java/com/sekwah/advancedportals/velocity/AdvancedPortalsVelocityPlugin.java index 476bd113..d221bb04 100644 --- a/velocity/src/main/java/com/sekwah/advancedportals/velocity/AdvancedPortalsVelocityPlugin.java +++ b/velocity/src/main/java/com/sekwah/advancedportals/velocity/AdvancedPortalsVelocityPlugin.java @@ -1,7 +1,5 @@ package com.sekwah.advancedportals.velocity; -import com.google.common.io.ByteArrayDataInput; -import com.google.common.io.ByteStreams; import com.google.inject.Inject; import com.sekwah.advancedportals.core.BuildConstants; import com.sekwah.advancedportals.core.ProxyMessages; @@ -10,6 +8,7 @@ import com.sekwah.advancedportals.velocity.connector.container.VelocityProxyPlayerContainer; import com.sekwah.advancedportals.velocity.connector.container.VelocityProxyServerContainer; import com.velocitypowered.api.event.Subscribe; +import com.velocitypowered.api.event.connection.DisconnectEvent; import com.velocitypowered.api.event.connection.PluginMessageEvent; import com.velocitypowered.api.event.player.ServerPostConnectEvent; import com.velocitypowered.api.event.proxy.ProxyInitializeEvent; @@ -65,4 +64,9 @@ public void postJoinEvent(ServerPostConnectEvent event) { }); } + @Subscribe + public void onDisconnect(DisconnectEvent event) { + this.proxyCore.onPlayerDisconnect(new VelocityProxyPlayerContainer(event.getPlayer())); + } + } diff --git a/velocity/src/main/java/com/sekwah/advancedportals/velocity/connector/container/VelocityProxyServerContainer.java b/velocity/src/main/java/com/sekwah/advancedportals/velocity/connector/container/VelocityProxyServerContainer.java index 508bdf64..8c8d2447 100644 --- a/velocity/src/main/java/com/sekwah/advancedportals/velocity/connector/container/VelocityProxyServerContainer.java +++ b/velocity/src/main/java/com/sekwah/advancedportals/velocity/connector/container/VelocityProxyServerContainer.java @@ -4,7 +4,14 @@ import com.velocitypowered.api.proxy.server.RegisteredServer; public class VelocityProxyServerContainer implements ProxyServerContainer { - public VelocityProxyServerContainer(RegisteredServer currentServer) { + private final RegisteredServer server; + public VelocityProxyServerContainer(RegisteredServer server) { + this.server = server; + } + + @Override + public String getServerName() { + return this.server.getServerInfo().getName(); } } From f82c6261b55e7fe7531bbcbb44b642b30ddd2413 Mon Sep 17 00:00:00 2001 From: Sekwah Date: Sun, 10 Nov 2024 03:51:41 +0000 Subject: [PATCH 10/13] wip: sorting out the proxy messages for proxy tags --- .../container/BungeeProxyPlayerContainer.java | 5 +++ .../advancedportals/core/CoreListeners.java | 5 ++- .../advancedportals/core/ProxyMessages.java | 1 - .../core/network/ServerDestiPacket.java | 31 +++++++++++++++++++ .../proxycore/AdvancedPortalsProxyCore.java | 2 ++ .../container/ProxyPlayerContainer.java | 1 + .../AdvancedPortalsVelocityPlugin.java | 6 ++-- .../VelocityProxyPlayerContainer.java | 12 ++++++- 8 files changed, 57 insertions(+), 6 deletions(-) create mode 100644 core/src/main/java/com/sekwah/advancedportals/core/network/ServerDestiPacket.java diff --git a/bungee/src/main/java/com/sekwah/advancedportals/bungee/connector/container/BungeeProxyPlayerContainer.java b/bungee/src/main/java/com/sekwah/advancedportals/bungee/connector/container/BungeeProxyPlayerContainer.java index b151c6fd..a7a43694 100644 --- a/bungee/src/main/java/com/sekwah/advancedportals/bungee/connector/container/BungeeProxyPlayerContainer.java +++ b/bungee/src/main/java/com/sekwah/advancedportals/bungee/connector/container/BungeeProxyPlayerContainer.java @@ -1,5 +1,6 @@ package com.sekwah.advancedportals.bungee.connector.container; +import com.sekwah.advancedportals.core.ProxyMessages; import com.sekwah.advancedportals.proxycore.connector.container.ProxyPlayerContainer; import net.md_5.bungee.api.connection.ProxiedPlayer; @@ -25,4 +26,8 @@ public String getName() { return this.player.getName(); } + public void sendPluginMessage(byte[] data) { + this.player.getServer().sendData(ProxyMessages.CHANNEL_NAME, data); + } + } diff --git a/core/src/main/java/com/sekwah/advancedportals/core/CoreListeners.java b/core/src/main/java/com/sekwah/advancedportals/core/CoreListeners.java index 06d2d773..430eb1f1 100644 --- a/core/src/main/java/com/sekwah/advancedportals/core/CoreListeners.java +++ b/core/src/main/java/com/sekwah/advancedportals/core/CoreListeners.java @@ -56,7 +56,10 @@ public void playerLeave(PlayerContainer player) { } public void incomingMessage(PlayerContainer player, String channel, byte[] message) { - + // Log all the info + System.out.println("Message from " + player.getName() + " on channel " + channel + " with message " + new String(message)); + // Send a message to the player with the info + player.sendMessage("Message from " + player.getName() + " on channel " + channel + " with message " + new String(message)); } public void tick() { diff --git a/core/src/main/java/com/sekwah/advancedportals/core/ProxyMessages.java b/core/src/main/java/com/sekwah/advancedportals/core/ProxyMessages.java index 1a350e99..9fdb4fbe 100644 --- a/core/src/main/java/com/sekwah/advancedportals/core/ProxyMessages.java +++ b/core/src/main/java/com/sekwah/advancedportals/core/ProxyMessages.java @@ -12,7 +12,6 @@ public class ProxyMessages { public static final String PROXY_TRANSFER_DESTI = "proxy:transfer_desti"; public static final String PROXY_TRANSFER = "proxy:transfer"; - public static final String PROXY_DESTI = "proxy:destination"; public static final String PROXY_COMMAND = "proxy:command"; public static final String SERVER_DESTI = "server:destination"; diff --git a/core/src/main/java/com/sekwah/advancedportals/core/network/ServerDestiPacket.java b/core/src/main/java/com/sekwah/advancedportals/core/network/ServerDestiPacket.java new file mode 100644 index 00000000..02f1cd85 --- /dev/null +++ b/core/src/main/java/com/sekwah/advancedportals/core/network/ServerDestiPacket.java @@ -0,0 +1,31 @@ +package com.sekwah.advancedportals.core.network; + +import com.google.common.io.ByteArrayDataInput; +import com.google.common.io.ByteArrayDataOutput; +import com.google.common.io.ByteStreams; +import com.sekwah.advancedportals.core.ProxyMessages; + +public class ServerDestiPacket implements Packet { + + private final String destination; + + public ServerDestiPacket(String destination) { + this.destination = destination; + } + + public byte[] encode() { + ByteArrayDataOutput buffer = ByteStreams.newDataOutput(); + buffer.writeUTF(ProxyMessages.SERVER_DESTI); + buffer.writeUTF(this.destination); + return buffer.toByteArray(); + + } + + public static ServerDestiPacket decode(ByteArrayDataInput buffer) { + return new ServerDestiPacket(buffer.readUTF()); + } + + public String getDestination() { + return destination; + } +} diff --git a/proxycore/src/main/java/com/sekwah/advancedportals/proxycore/AdvancedPortalsProxyCore.java b/proxycore/src/main/java/com/sekwah/advancedportals/proxycore/AdvancedPortalsProxyCore.java index c2af36cc..e1d493e3 100644 --- a/proxycore/src/main/java/com/sekwah/advancedportals/proxycore/AdvancedPortalsProxyCore.java +++ b/proxycore/src/main/java/com/sekwah/advancedportals/proxycore/AdvancedPortalsProxyCore.java @@ -5,6 +5,7 @@ import com.sekwah.advancedportals.core.network.ProxyCommandPacket; import com.sekwah.advancedportals.core.network.ProxyTransferDestiPacket; import com.sekwah.advancedportals.core.network.ProxyTransferPacket; +import com.sekwah.advancedportals.core.network.ServerDestiPacket; import com.sekwah.advancedportals.core.util.InfoLogger; import com.sekwah.advancedportals.core.util.Lang; import com.sekwah.advancedportals.proxycore.connector.container.ProxyContainer; @@ -75,6 +76,7 @@ public void incomingMessage(ProxyPlayerContainer player, byte[] message) { this.logger.info("Transfer request for " + player.getName() + " to " + transferDestiPacket.getServerName() + " with destination " + transferDestiPacket.getDestination()); this.proxyContainer.transferPlayer(player, transferDestiPacket.getServerName()); this.playerJoinMap.put(player.getUUID(), new ProxyJoinData(transferDestiPacket.getDestination(), transferDestiPacket.getServerName())); + player.sendPluginMessage(new ServerDestiPacket(transferDestiPacket.getServerName()).encode()); break; default: this.logger.info("Unknown message type: " + messageType); diff --git a/proxycore/src/main/java/com/sekwah/advancedportals/proxycore/connector/container/ProxyPlayerContainer.java b/proxycore/src/main/java/com/sekwah/advancedportals/proxycore/connector/container/ProxyPlayerContainer.java index 3fddfb5f..c6cc1978 100644 --- a/proxycore/src/main/java/com/sekwah/advancedportals/proxycore/connector/container/ProxyPlayerContainer.java +++ b/proxycore/src/main/java/com/sekwah/advancedportals/proxycore/connector/container/ProxyPlayerContainer.java @@ -3,4 +3,5 @@ public interface ProxyPlayerContainer { String getUUID(); String getName(); + void sendPluginMessage(byte[] data); } diff --git a/velocity/src/main/java/com/sekwah/advancedportals/velocity/AdvancedPortalsVelocityPlugin.java b/velocity/src/main/java/com/sekwah/advancedportals/velocity/AdvancedPortalsVelocityPlugin.java index d221bb04..7fcf2d16 100644 --- a/velocity/src/main/java/com/sekwah/advancedportals/velocity/AdvancedPortalsVelocityPlugin.java +++ b/velocity/src/main/java/com/sekwah/advancedportals/velocity/AdvancedPortalsVelocityPlugin.java @@ -49,7 +49,7 @@ public void onProxyInitialize(ProxyInitializeEvent event) { public void onPluginMessage(PluginMessageEvent event) { if (event.getIdentifier().equals(AP_CHANNEL)) { if(event.getSource() instanceof ServerConnection serverConnection) { - this.proxyCore.incomingMessage(new VelocityProxyPlayerContainer(serverConnection.getPlayer()), event.getData()); + this.proxyCore.incomingMessage(new VelocityProxyPlayerContainer(serverConnection.getPlayer(), AP_CHANNEL), event.getData()); } // So that client packets don't make it through to the servers, always trigger on this channel. event.setResult(PluginMessageEvent.ForwardResult.handled()); @@ -60,13 +60,13 @@ public void onPluginMessage(PluginMessageEvent event) { @Subscribe public void postJoinEvent(ServerPostConnectEvent event) { event.getPlayer().getCurrentServer().ifPresent(serverConnection -> { - this.proxyCore.onServerConnect(new VelocityProxyServerContainer(serverConnection.getServer()), new VelocityProxyPlayerContainer(event.getPlayer())); + this.proxyCore.onServerConnect(new VelocityProxyServerContainer(serverConnection.getServer()), new VelocityProxyPlayerContainer(event.getPlayer(), AP_CHANNEL)); }); } @Subscribe public void onDisconnect(DisconnectEvent event) { - this.proxyCore.onPlayerDisconnect(new VelocityProxyPlayerContainer(event.getPlayer())); + this.proxyCore.onPlayerDisconnect(new VelocityProxyPlayerContainer(event.getPlayer(), AP_CHANNEL)); } } diff --git a/velocity/src/main/java/com/sekwah/advancedportals/velocity/connector/container/VelocityProxyPlayerContainer.java b/velocity/src/main/java/com/sekwah/advancedportals/velocity/connector/container/VelocityProxyPlayerContainer.java index 6d162e8d..5c648d5c 100644 --- a/velocity/src/main/java/com/sekwah/advancedportals/velocity/connector/container/VelocityProxyPlayerContainer.java +++ b/velocity/src/main/java/com/sekwah/advancedportals/velocity/connector/container/VelocityProxyPlayerContainer.java @@ -2,13 +2,17 @@ import com.sekwah.advancedportals.proxycore.connector.container.ProxyPlayerContainer; import com.velocitypowered.api.proxy.Player; +import com.velocitypowered.api.proxy.messages.LegacyChannelIdentifier; +import net.kyori.adventure.text.Component; public class VelocityProxyPlayerContainer implements ProxyPlayerContainer { private final Player player; + private final LegacyChannelIdentifier channel; - public VelocityProxyPlayerContainer(Player player) { + public VelocityProxyPlayerContainer(Player player, LegacyChannelIdentifier channel) { this.player = player; + this.channel = channel; } @Override @@ -21,6 +25,12 @@ public String getName() { return player.getUsername(); } + @Override + public void sendPluginMessage(byte[] data) { + player.sendMessage(Component.text("Sending plugin message")); + player.sendPluginMessage(channel, data); + } + public Player getPlayer() { return this.player; } From 4ea9721f6e9b3bb7568e489e1f4739e922abd699 Mon Sep 17 00:00:00 2001 From: Sekwah Date: Wed, 13 Nov 2024 01:08:10 +0000 Subject: [PATCH 11/13] wip: start handling the destinations --- .../advancedportals/core/CoreListeners.java | 20 +++++++++++++++---- .../proxycore/AdvancedPortalsProxyCore.java | 15 +++++++------- .../VelocityProxyPlayerContainer.java | 3 +-- 3 files changed, 25 insertions(+), 13 deletions(-) diff --git a/core/src/main/java/com/sekwah/advancedportals/core/CoreListeners.java b/core/src/main/java/com/sekwah/advancedportals/core/CoreListeners.java index 430eb1f1..8399fba8 100644 --- a/core/src/main/java/com/sekwah/advancedportals/core/CoreListeners.java +++ b/core/src/main/java/com/sekwah/advancedportals/core/CoreListeners.java @@ -1,15 +1,18 @@ package com.sekwah.advancedportals.core; +import com.google.common.io.ByteStreams; import com.google.inject.Inject; import com.sekwah.advancedportals.core.connector.containers.EntityContainer; import com.sekwah.advancedportals.core.connector.containers.PlayerContainer; import com.sekwah.advancedportals.core.connector.containers.WorldContainer; import com.sekwah.advancedportals.core.data.BlockAxis; import com.sekwah.advancedportals.core.data.Direction; +import com.sekwah.advancedportals.core.network.ServerDestiPacket; import com.sekwah.advancedportals.core.permissions.PortalPermissions; import com.sekwah.advancedportals.core.repository.ConfigRepository; import com.sekwah.advancedportals.core.serializeddata.BlockLocation; import com.sekwah.advancedportals.core.serializeddata.PlayerLocation; +import com.sekwah.advancedportals.core.services.DestinationServices; import com.sekwah.advancedportals.core.services.PlayerDataServices; import com.sekwah.advancedportals.core.services.PortalServices; import com.sekwah.advancedportals.core.util.GameScheduler; @@ -25,6 +28,9 @@ public class CoreListeners { @Inject private PortalServices portalServices; + @Inject + private DestinationServices destinationServices; + @Inject private ConfigRepository configRepository; @@ -56,10 +62,16 @@ public void playerLeave(PlayerContainer player) { } public void incomingMessage(PlayerContainer player, String channel, byte[] message) { - // Log all the info - System.out.println("Message from " + player.getName() + " on channel " + channel + " with message " + new String(message)); - // Send a message to the player with the info - player.sendMessage("Message from " + player.getName() + " on channel " + channel + " with message " + new String(message)); + var buffer = ByteStreams.newDataInput(message); + var messageType = buffer.readUTF(); + + switch (messageType) { + case ProxyMessages.SERVER_DESTI -> { + var serverDestiPacket = ServerDestiPacket.decode(buffer); + this.destinationServices.teleportToDestination(serverDestiPacket.getDestination(), player); + } + } + } public void tick() { diff --git a/proxycore/src/main/java/com/sekwah/advancedportals/proxycore/AdvancedPortalsProxyCore.java b/proxycore/src/main/java/com/sekwah/advancedportals/proxycore/AdvancedPortalsProxyCore.java index e1d493e3..cdcf27fa 100644 --- a/proxycore/src/main/java/com/sekwah/advancedportals/proxycore/AdvancedPortalsProxyCore.java +++ b/proxycore/src/main/java/com/sekwah/advancedportals/proxycore/AdvancedPortalsProxyCore.java @@ -61,25 +61,26 @@ public void incomingMessage(ProxyPlayerContainer player, byte[] message) { // Might be a bit overboard for some as they'll only have one value, but try to keep the decode behavior with // the encode behavior in the packets switch (messageType) { - case ProxyMessages.PROXY_TRANSFER: + case ProxyMessages.PROXY_TRANSFER -> { var transferPacket = ProxyTransferPacket.decode(buffer); this.logger.info("Transfer request for " + player.getName() + " to " + transferPacket.getServerName()); this.proxyContainer.transferPlayer(player, transferPacket.getServerName()); - break; - case ProxyMessages.PROXY_COMMAND: + } + case ProxyMessages.PROXY_COMMAND -> { var commandPacket = ProxyCommandPacket.decode(buffer); this.logger.info("Command request for " + player.getName() + " to run /" + commandPacket.getCommand()); this.proxyContainer.invokeCommand(player, commandPacket.getCommand()); - break; - case ProxyMessages.PROXY_TRANSFER_DESTI: + } + case ProxyMessages.PROXY_TRANSFER_DESTI -> { var transferDestiPacket = ProxyTransferDestiPacket.decode(buffer); this.logger.info("Transfer request for " + player.getName() + " to " + transferDestiPacket.getServerName() + " with destination " + transferDestiPacket.getDestination()); this.proxyContainer.transferPlayer(player, transferDestiPacket.getServerName()); this.playerJoinMap.put(player.getUUID(), new ProxyJoinData(transferDestiPacket.getDestination(), transferDestiPacket.getServerName())); player.sendPluginMessage(new ServerDestiPacket(transferDestiPacket.getServerName()).encode()); - break; - default: + } + default -> { this.logger.info("Unknown message type: " + messageType); + } } } diff --git a/velocity/src/main/java/com/sekwah/advancedportals/velocity/connector/container/VelocityProxyPlayerContainer.java b/velocity/src/main/java/com/sekwah/advancedportals/velocity/connector/container/VelocityProxyPlayerContainer.java index 5c648d5c..ca89ca3c 100644 --- a/velocity/src/main/java/com/sekwah/advancedportals/velocity/connector/container/VelocityProxyPlayerContainer.java +++ b/velocity/src/main/java/com/sekwah/advancedportals/velocity/connector/container/VelocityProxyPlayerContainer.java @@ -27,8 +27,7 @@ public String getName() { @Override public void sendPluginMessage(byte[] data) { - player.sendMessage(Component.text("Sending plugin message")); - player.sendPluginMessage(channel, data); + player.getCurrentServer().ifPresent(serverConnection -> serverConnection.sendPluginMessage(channel, data)); } public Player getPlayer() { From 70a94e76fe6fb69b6d3311dbbb9e2ab23f4ab783 Mon Sep 17 00:00:00 2001 From: Sekwah Date: Wed, 13 Nov 2024 02:03:45 +0000 Subject: [PATCH 12/13] wip: make the desti packets move you to the right location --- .../connector/container/BungeeProxyPlayerContainer.java | 2 +- .../java/com/sekwah/advancedportals/core/CoreListeners.java | 1 + .../advancedportals/proxycore/AdvancedPortalsProxyCore.java | 5 ++--- .../proxycore/connector/container/ProxyPlayerContainer.java | 2 +- .../connector/container/VelocityProxyPlayerContainer.java | 2 +- 5 files changed, 6 insertions(+), 6 deletions(-) diff --git a/bungee/src/main/java/com/sekwah/advancedportals/bungee/connector/container/BungeeProxyPlayerContainer.java b/bungee/src/main/java/com/sekwah/advancedportals/bungee/connector/container/BungeeProxyPlayerContainer.java index a7a43694..edceafa1 100644 --- a/bungee/src/main/java/com/sekwah/advancedportals/bungee/connector/container/BungeeProxyPlayerContainer.java +++ b/bungee/src/main/java/com/sekwah/advancedportals/bungee/connector/container/BungeeProxyPlayerContainer.java @@ -26,7 +26,7 @@ public String getName() { return this.player.getName(); } - public void sendPluginMessage(byte[] data) { + public void sendServerPluginMessage(byte[] data) { this.player.getServer().sendData(ProxyMessages.CHANNEL_NAME, data); } diff --git a/core/src/main/java/com/sekwah/advancedportals/core/CoreListeners.java b/core/src/main/java/com/sekwah/advancedportals/core/CoreListeners.java index 8399fba8..87f8a3d2 100644 --- a/core/src/main/java/com/sekwah/advancedportals/core/CoreListeners.java +++ b/core/src/main/java/com/sekwah/advancedportals/core/CoreListeners.java @@ -68,6 +68,7 @@ public void incomingMessage(PlayerContainer player, String channel, byte[] messa switch (messageType) { case ProxyMessages.SERVER_DESTI -> { var serverDestiPacket = ServerDestiPacket.decode(buffer); + System.out.println("Server desti packet: " + serverDestiPacket.getDestination() + " " + player.getName()); this.destinationServices.teleportToDestination(serverDestiPacket.getDestination(), player); } } diff --git a/proxycore/src/main/java/com/sekwah/advancedportals/proxycore/AdvancedPortalsProxyCore.java b/proxycore/src/main/java/com/sekwah/advancedportals/proxycore/AdvancedPortalsProxyCore.java index cdcf27fa..5e1f3c57 100644 --- a/proxycore/src/main/java/com/sekwah/advancedportals/proxycore/AdvancedPortalsProxyCore.java +++ b/proxycore/src/main/java/com/sekwah/advancedportals/proxycore/AdvancedPortalsProxyCore.java @@ -36,10 +36,11 @@ public void onDisable() { } public void onServerConnect(ProxyServerContainer server, ProxyPlayerContainer player) { + System.out.println("Server connect"); if(this.playerJoinMap.containsKey(player.getUUID())) { var joinData = this.playerJoinMap.get(player.getUUID()); if(joinData.isExpired()) return; - this.logger.info("Sending desti data for " + player.getName() + " to " + server.getServerName() + " with destination " + joinData.destination); + player.sendServerPluginMessage(new ServerDestiPacket(joinData.destination).encode()); this.playerJoinMap.remove(player.getUUID()); } } @@ -73,10 +74,8 @@ public void incomingMessage(ProxyPlayerContainer player, byte[] message) { } case ProxyMessages.PROXY_TRANSFER_DESTI -> { var transferDestiPacket = ProxyTransferDestiPacket.decode(buffer); - this.logger.info("Transfer request for " + player.getName() + " to " + transferDestiPacket.getServerName() + " with destination " + transferDestiPacket.getDestination()); this.proxyContainer.transferPlayer(player, transferDestiPacket.getServerName()); this.playerJoinMap.put(player.getUUID(), new ProxyJoinData(transferDestiPacket.getDestination(), transferDestiPacket.getServerName())); - player.sendPluginMessage(new ServerDestiPacket(transferDestiPacket.getServerName()).encode()); } default -> { this.logger.info("Unknown message type: " + messageType); diff --git a/proxycore/src/main/java/com/sekwah/advancedportals/proxycore/connector/container/ProxyPlayerContainer.java b/proxycore/src/main/java/com/sekwah/advancedportals/proxycore/connector/container/ProxyPlayerContainer.java index c6cc1978..878773d1 100644 --- a/proxycore/src/main/java/com/sekwah/advancedportals/proxycore/connector/container/ProxyPlayerContainer.java +++ b/proxycore/src/main/java/com/sekwah/advancedportals/proxycore/connector/container/ProxyPlayerContainer.java @@ -3,5 +3,5 @@ public interface ProxyPlayerContainer { String getUUID(); String getName(); - void sendPluginMessage(byte[] data); + void sendServerPluginMessage(byte[] data); } diff --git a/velocity/src/main/java/com/sekwah/advancedportals/velocity/connector/container/VelocityProxyPlayerContainer.java b/velocity/src/main/java/com/sekwah/advancedportals/velocity/connector/container/VelocityProxyPlayerContainer.java index ca89ca3c..fe80844c 100644 --- a/velocity/src/main/java/com/sekwah/advancedportals/velocity/connector/container/VelocityProxyPlayerContainer.java +++ b/velocity/src/main/java/com/sekwah/advancedportals/velocity/connector/container/VelocityProxyPlayerContainer.java @@ -26,7 +26,7 @@ public String getName() { } @Override - public void sendPluginMessage(byte[] data) { + public void sendServerPluginMessage(byte[] data) { player.getCurrentServer().ifPresent(serverConnection -> serverConnection.sendPluginMessage(channel, data)); } From c557b2a449a3e6b3bbce279d0a39f8e5fd9f90f6 Mon Sep 17 00:00:00 2001 From: Sekwah Date: Wed, 13 Nov 2024 10:57:22 +0000 Subject: [PATCH 13/13] wip: remove system out --- .../main/java/com/sekwah/advancedportals/core/CoreListeners.java | 1 - .../advancedportals/proxycore/AdvancedPortalsProxyCore.java | 1 - 2 files changed, 2 deletions(-) diff --git a/core/src/main/java/com/sekwah/advancedportals/core/CoreListeners.java b/core/src/main/java/com/sekwah/advancedportals/core/CoreListeners.java index 87f8a3d2..8399fba8 100644 --- a/core/src/main/java/com/sekwah/advancedportals/core/CoreListeners.java +++ b/core/src/main/java/com/sekwah/advancedportals/core/CoreListeners.java @@ -68,7 +68,6 @@ public void incomingMessage(PlayerContainer player, String channel, byte[] messa switch (messageType) { case ProxyMessages.SERVER_DESTI -> { var serverDestiPacket = ServerDestiPacket.decode(buffer); - System.out.println("Server desti packet: " + serverDestiPacket.getDestination() + " " + player.getName()); this.destinationServices.teleportToDestination(serverDestiPacket.getDestination(), player); } } diff --git a/proxycore/src/main/java/com/sekwah/advancedportals/proxycore/AdvancedPortalsProxyCore.java b/proxycore/src/main/java/com/sekwah/advancedportals/proxycore/AdvancedPortalsProxyCore.java index 5e1f3c57..cc880e2f 100644 --- a/proxycore/src/main/java/com/sekwah/advancedportals/proxycore/AdvancedPortalsProxyCore.java +++ b/proxycore/src/main/java/com/sekwah/advancedportals/proxycore/AdvancedPortalsProxyCore.java @@ -36,7 +36,6 @@ public void onDisable() { } public void onServerConnect(ProxyServerContainer server, ProxyPlayerContainer player) { - System.out.println("Server connect"); if(this.playerJoinMap.containsKey(player.getUUID())) { var joinData = this.playerJoinMap.get(player.getUUID()); if(joinData.isExpired()) return;