From d687e88e658a1da2e88d5f940f7b3107a24e98a5 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Wed, 13 Nov 2024 11:02:32 +0000 Subject: [PATCH] chore: pre-commit changes [skip ci] --- .../bungee/AdvancedPortalsBungeePlugin.java | 50 +++--- .../advancedportals/bungee/EventListener.java | 94 +++++----- .../container/BungeeProxyContainer.java | 76 ++++---- .../container/BungeeProxyPlayerContainer.java | 66 +++---- .../container/BungeeProxyServerContainer.java | 34 ++-- bungee/src/main/resources/bungee.yml | 8 +- core/build.gradle | 1 - .../advancedportals/core/ProxyMessages.java | 36 ++-- .../advancedportals/core/network/Packet.java | 10 +- .../core/network/ProxyCommandPacket.java | 60 +++---- .../network/ProxyTransferDestiPacket.java | 76 ++++---- .../core/network/ProxyTransferPacket.java | 62 +++---- .../core/network/ServerDestiPacket.java | 62 +++---- .../advancedportals/core/BuildConstants.java | 10 +- lang/src/main/resources/lang/en_GB.lang | 2 +- proxycore/build.gradle | 1 - .../proxycore/AdvancedPortalsProxyCore.java | 170 +++++++++--------- .../connector/container/ProxyContainer.java | 16 +- .../connector/container/ProxyJoinData.java | 36 ++-- .../container/ProxyPlayerContainer.java | 14 +- .../container/ProxyServerContainer.java | 10 +- .../AdvancedPortalsVelocityPlugin.java | 144 +++++++-------- .../velocity/VelocityInfoLogger.java | 66 +++---- .../velocity/connector/MinecraftToAnsi.java | 110 ++++++------ .../container/VelocityProxyContainer.java | 66 +++---- .../VelocityProxyPlayerContainer.java | 72 ++++---- .../VelocityProxyServerContainer.java | 34 ++-- 27 files changed, 692 insertions(+), 694 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 8bf80095..ebb37e07 100644 --- a/bungee/src/main/java/com/sekwah/advancedportals/bungee/AdvancedPortalsBungeePlugin.java +++ b/bungee/src/main/java/com/sekwah/advancedportals/bungee/AdvancedPortalsBungeePlugin.java @@ -1,25 +1,25 @@ -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().registerChannel(ProxyMessages.CHANNEL_NAME); - - getProxy().getPluginManager().registerListener(this, new EventListener(this, this.proxyCore)); - } - - @Override - public void onDisable() { - this.proxyCore.onDisable(); - } -} +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().registerChannel(ProxyMessages.CHANNEL_NAME); + + getProxy().getPluginManager().registerListener(this, new EventListener(this, this.proxyCore)); + } + + @Override + public void onDisable() { + this.proxyCore.onDisable(); + } +} 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 605a3cce..b8bf4ef1 100644 --- a/bungee/src/main/java/com/sekwah/advancedportals/bungee/EventListener.java +++ b/bungee/src/main/java/com/sekwah/advancedportals/bungee/EventListener.java @@ -1,47 +1,47 @@ -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.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; -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())); - } - - @EventHandler - public void onDisconnect(PlayerDisconnectEvent event) { - this.proxyCore.onPlayerDisconnect(new BungeeProxyPlayerContainer(event.getPlayer())); - } -} +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.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; +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())); + } + + @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/BungeeProxyContainer.java b/bungee/src/main/java/com/sekwah/advancedportals/bungee/connector/container/BungeeProxyContainer.java index 4d745fc8..a3fb6ad7 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,38 +1,38 @@ -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 { - - private final AdvancedPortalsBungeePlugin plugin; - - public BungeeProxyContainer(AdvancedPortalsBungeePlugin plugin) { - this.plugin = 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); - } - } -} +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 { + + private final AdvancedPortalsBungeePlugin plugin; + + public BungeeProxyContainer(AdvancedPortalsBungeePlugin plugin) { + this.plugin = 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/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 edceafa1..cead8dad 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,33 +1,33 @@ -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; - -public class BungeeProxyPlayerContainer implements ProxyPlayerContainer { - - private final ProxiedPlayer player; - - public BungeeProxyPlayerContainer(ProxiedPlayer player) { - this.player = player; - } - - public ProxiedPlayer getPlayer() { - return this.player; - } - - @Override - public String getUUID() { - return this.player.getUniqueId().toString(); - } - - @Override - public String getName() { - return this.player.getName(); - } - - public void sendServerPluginMessage(byte[] data) { - this.player.getServer().sendData(ProxyMessages.CHANNEL_NAME, data); - } - -} +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; + +public class BungeeProxyPlayerContainer implements ProxyPlayerContainer { + + private final ProxiedPlayer player; + + public BungeeProxyPlayerContainer(ProxiedPlayer player) { + this.player = player; + } + + public ProxiedPlayer getPlayer() { + return this.player; + } + + @Override + public String getUUID() { + return this.player.getUniqueId().toString(); + } + + @Override + public String getName() { + return this.player.getName(); + } + + public void sendServerPluginMessage(byte[] data) { + this.player.getServer().sendData(ProxyMessages.CHANNEL_NAME, data); + } + +} 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 53473d71..6ae4afff 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 @@ -1,17 +1,17 @@ -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; - } - - @Override - public String getServerName() { - return this.server.getInfo().getName(); - } -} +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; + } + + @Override + public String getServerName() { + return this.server.getInfo().getName(); + } +} diff --git a/bungee/src/main/resources/bungee.yml b/bungee/src/main/resources/bungee.yml index fea8c275..9f34093d 100644 --- a/bungee/src/main/resources/bungee.yml +++ b/bungee/src/main/resources/bungee.yml @@ -1,4 +1,4 @@ -main: com.sekwah.advancedportals.bungee.AdvancedPortalsBungeePlugin -name: AdvancedPortals -version: ${pluginVersion} -author: sekwah41 \ No newline at end of file +main: com.sekwah.advancedportals.bungee.AdvancedPortalsBungeePlugin +name: AdvancedPortals +version: ${pluginVersion} +author: sekwah41 diff --git a/core/build.gradle b/core/build.gradle index 28d03766..110aac5a 100644 --- a/core/build.gradle +++ b/core/build.gradle @@ -50,4 +50,3 @@ def generateTemplates = tasks.register('generateTemplates', Copy) { task -> } sourceSets.main.java.srcDir(generateTemplates.map { it.outputs }) - 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 9fdb4fbe..b7720b57 100644 --- a/core/src/main/java/com/sekwah/advancedportals/core/ProxyMessages.java +++ b/core/src/main/java/com/sekwah/advancedportals/core/ProxyMessages.java @@ -1,18 +1,18 @@ -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 { - - /** - * Could split by channel messages we will handle it ourselves - */ - public static final String CHANNEL_NAME = "advancedportals:message"; - - public static final String PROXY_TRANSFER_DESTI = "proxy:transfer_desti"; - public static final String PROXY_TRANSFER = "proxy:transfer"; - public static final String PROXY_COMMAND = "proxy:command"; - - public static final String SERVER_DESTI = "server:destination"; -} +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 { + + /** + * Could split by channel messages we will handle it ourselves + */ + public static final String CHANNEL_NAME = "advancedportals:message"; + + public static final String PROXY_TRANSFER_DESTI = "proxy:transfer_desti"; + public static final String PROXY_TRANSFER = "proxy:transfer"; + 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/Packet.java b/core/src/main/java/com/sekwah/advancedportals/core/network/Packet.java index 019b4e64..5d0212bd 100644 --- a/core/src/main/java/com/sekwah/advancedportals/core/network/Packet.java +++ b/core/src/main/java/com/sekwah/advancedportals/core/network/Packet.java @@ -1,5 +1,5 @@ -package com.sekwah.advancedportals.core.network; - -public interface Packet { - byte[] encode(); -} +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 a9353868..54dc171c 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 @@ -1,30 +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 ProxyCommandPacket implements Packet { - - private final String command; - - public ProxyCommandPacket(String command) { - this.command = command; - } - - public byte[] encode() { - ByteArrayDataOutput buffer = ByteStreams.newDataOutput(); - buffer.writeUTF(ProxyMessages.PROXY_COMMAND); - buffer.writeUTF(this.command); - return buffer.toByteArray(); - } - - public static ProxyCommandPacket decode(ByteArrayDataInput buffer) { - return new ProxyCommandPacket(buffer.readUTF()); - } - - public String getCommand() { - return command; - } -} +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 ProxyCommandPacket implements Packet { + + private final String command; + + public ProxyCommandPacket(String command) { + this.command = command; + } + + public byte[] encode() { + ByteArrayDataOutput buffer = ByteStreams.newDataOutput(); + buffer.writeUTF(ProxyMessages.PROXY_COMMAND); + buffer.writeUTF(this.command); + return buffer.toByteArray(); + } + + 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/ProxyTransferDestiPacket.java b/core/src/main/java/com/sekwah/advancedportals/core/network/ProxyTransferDestiPacket.java index 6c04860b..dc0c8224 100644 --- a/core/src/main/java/com/sekwah/advancedportals/core/network/ProxyTransferDestiPacket.java +++ b/core/src/main/java/com/sekwah/advancedportals/core/network/ProxyTransferDestiPacket.java @@ -1,38 +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; - } -} +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 417d15fd..435f4789 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 @@ -1,31 +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 ProxyTransferPacket implements Packet { - - 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; - } -} +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 implements Packet { + + 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/network/ServerDestiPacket.java b/core/src/main/java/com/sekwah/advancedportals/core/network/ServerDestiPacket.java index 02f1cd85..d390f687 100644 --- a/core/src/main/java/com/sekwah/advancedportals/core/network/ServerDestiPacket.java +++ b/core/src/main/java/com/sekwah/advancedportals/core/network/ServerDestiPacket.java @@ -1,31 +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; - } -} +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/core/src/main/templates/com/sekwah/advancedportals/core/BuildConstants.java b/core/src/main/templates/com/sekwah/advancedportals/core/BuildConstants.java index 03a9c4d6..fca4bb70 100644 --- a/core/src/main/templates/com/sekwah/advancedportals/core/BuildConstants.java +++ b/core/src/main/templates/com/sekwah/advancedportals/core/BuildConstants.java @@ -1,5 +1,5 @@ -package com.sekwah.advancedportals.core; - -public class BuildConstants { - public static final String VERSION = "${version}"; -} \ No newline at end of file +package com.sekwah.advancedportals.core; + +public class BuildConstants { + public static final String VERSION = "${version}"; +} diff --git a/lang/src/main/resources/lang/en_GB.lang b/lang/src/main/resources/lang/en_GB.lang index 6b23cfef..6755aac0 100644 --- a/lang/src/main/resources/lang/en_GB.lang +++ b/lang/src/main/resources/lang/en_GB.lang @@ -195,4 +195,4 @@ tag.command.permswildcard.disabled= Wildcard &e*&c permission command portals ar 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 +tag.proxy.description= Sets the server destination of the portal. diff --git a/proxycore/build.gradle b/proxycore/build.gradle index bf896d0a..1b12be2f 100644 --- a/proxycore/build.gradle +++ b/proxycore/build.gradle @@ -26,4 +26,3 @@ jar { 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 index cc880e2f..eeceb0b9 100644 --- a/proxycore/src/main/java/com/sekwah/advancedportals/proxycore/AdvancedPortalsProxyCore.java +++ b/proxycore/src/main/java/com/sekwah/advancedportals/proxycore/AdvancedPortalsProxyCore.java @@ -1,85 +1,85 @@ -package com.sekwah.advancedportals.proxycore; - -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.network.ServerDestiPacket; -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; - - public HashMap playerJoinMap = new HashMap<>(); - - public AdvancedPortalsProxyCore(InfoLogger logger, ProxyContainer proxyContainer) { - this.logger = logger; - this.proxyContainer = proxyContainer; - } - - public void onEnable() { - this.logger.info(Lang.convertColors("&aSuccessfully enabled!")); - } - - public void onDisable() { - this.logger.info(Lang.convertColors("&cDisabling plugin!")); - } - - public void onServerConnect(ProxyServerContainer server, ProxyPlayerContainer player) { - if(this.playerJoinMap.containsKey(player.getUUID())) { - var joinData = this.playerJoinMap.get(player.getUUID()); - if(joinData.isExpired()) return; - player.sendServerPluginMessage(new ServerDestiPacket(joinData.destination).encode()); - this.playerJoinMap.remove(player.getUUID()); - } - } - - public void onPlayerDisconnect(ProxyPlayerContainer player) { - this.playerJoinMap.remove(player.getUUID()); - } - - /** - * 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) { - - 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 transferPacket = ProxyTransferPacket.decode(buffer); - this.logger.info("Transfer request for " + player.getName() + " to " + transferPacket.getServerName()); - this.proxyContainer.transferPlayer(player, transferPacket.getServerName()); - } - 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()); - } - case ProxyMessages.PROXY_TRANSFER_DESTI -> { - var transferDestiPacket = ProxyTransferDestiPacket.decode(buffer); - this.proxyContainer.transferPlayer(player, transferDestiPacket.getServerName()); - this.playerJoinMap.put(player.getUUID(), new ProxyJoinData(transferDestiPacket.getDestination(), transferDestiPacket.getServerName())); - } - default -> { - this.logger.info("Unknown message type: " + messageType); - } - } - - } -} +package com.sekwah.advancedportals.proxycore; + +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.network.ServerDestiPacket; +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; + + public HashMap playerJoinMap = new HashMap<>(); + + public AdvancedPortalsProxyCore(InfoLogger logger, ProxyContainer proxyContainer) { + this.logger = logger; + this.proxyContainer = proxyContainer; + } + + public void onEnable() { + this.logger.info(Lang.convertColors("&aSuccessfully enabled!")); + } + + public void onDisable() { + this.logger.info(Lang.convertColors("&cDisabling plugin!")); + } + + public void onServerConnect(ProxyServerContainer server, ProxyPlayerContainer player) { + if(this.playerJoinMap.containsKey(player.getUUID())) { + var joinData = this.playerJoinMap.get(player.getUUID()); + if(joinData.isExpired()) return; + player.sendServerPluginMessage(new ServerDestiPacket(joinData.destination).encode()); + this.playerJoinMap.remove(player.getUUID()); + } + } + + public void onPlayerDisconnect(ProxyPlayerContainer player) { + this.playerJoinMap.remove(player.getUUID()); + } + + /** + * 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) { + + 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 transferPacket = ProxyTransferPacket.decode(buffer); + this.logger.info("Transfer request for " + player.getName() + " to " + transferPacket.getServerName()); + this.proxyContainer.transferPlayer(player, transferPacket.getServerName()); + } + 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()); + } + case ProxyMessages.PROXY_TRANSFER_DESTI -> { + var transferDestiPacket = ProxyTransferDestiPacket.decode(buffer); + this.proxyContainer.transferPlayer(player, transferDestiPacket.getServerName()); + this.playerJoinMap.put(player.getUUID(), new ProxyJoinData(transferDestiPacket.getDestination(), transferDestiPacket.getServerName())); + } + default -> { + this.logger.info("Unknown message type: " + messageType); + } + } + + } +} 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 index 29b3d555..79eb1d91 100644 --- 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 @@ -1,8 +1,8 @@ -package com.sekwah.advancedportals.proxycore.connector.container; - -public interface ProxyContainer { - void invokeCommand(ProxyPlayerContainer proxyPlayer, String command); - - void transferPlayer(ProxyPlayerContainer proxyPlayer, String serverName); - -} +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/ProxyJoinData.java b/proxycore/src/main/java/com/sekwah/advancedportals/proxycore/connector/container/ProxyJoinData.java index f8dbfd09..16cbff12 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 @@ -1,18 +1,18 @@ -package com.sekwah.advancedportals.proxycore.connector.container; - -public class ProxyJoinData { - - 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 - } -} +package com.sekwah.advancedportals.proxycore.connector.container; + +public class ProxyJoinData { + + 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/ProxyPlayerContainer.java b/proxycore/src/main/java/com/sekwah/advancedportals/proxycore/connector/container/ProxyPlayerContainer.java index 878773d1..47a6982f 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,7 +1,7 @@ -package com.sekwah.advancedportals.proxycore.connector.container; - -public interface ProxyPlayerContainer { - String getUUID(); - String getName(); - void sendServerPluginMessage(byte[] data); -} +package com.sekwah.advancedportals.proxycore.connector.container; + +public interface ProxyPlayerContainer { + String getUUID(); + String getName(); + void sendServerPluginMessage(byte[] data); +} 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 b90fdc13..5ffaa5ba 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,5 +1,5 @@ -package com.sekwah.advancedportals.proxycore.connector.container; - -public interface ProxyServerContainer { - String getServerName(); -} +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 7fcf2d16..0b6b649b 100644 --- a/velocity/src/main/java/com/sekwah/advancedportals/velocity/AdvancedPortalsVelocityPlugin.java +++ b/velocity/src/main/java/com/sekwah/advancedportals/velocity/AdvancedPortalsVelocityPlugin.java @@ -1,72 +1,72 @@ -package com.sekwah.advancedportals.velocity; - -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.DisconnectEvent; -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/", - version = BuildConstants.VERSION) -public class AdvancedPortalsVelocityPlugin { - - private AdvancedPortalsProxyCore proxyCore; - - 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.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(), 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()); - } - } - - - @Subscribe - public void postJoinEvent(ServerPostConnectEvent event) { - event.getPlayer().getCurrentServer().ifPresent(serverConnection -> { - 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(), AP_CHANNEL)); - } - -} +package com.sekwah.advancedportals.velocity; + +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.DisconnectEvent; +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/", + version = BuildConstants.VERSION) +public class AdvancedPortalsVelocityPlugin { + + private AdvancedPortalsProxyCore proxyCore; + + 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.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(), 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()); + } + } + + + @Subscribe + public void postJoinEvent(ServerPostConnectEvent event) { + event.getPlayer().getCurrentServer().ifPresent(serverConnection -> { + 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(), AP_CHANNEL)); + } + +} 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 64150640..415eb8ac 100644 --- a/velocity/src/main/java/com/sekwah/advancedportals/velocity/VelocityInfoLogger.java +++ b/velocity/src/main/java/com/sekwah/advancedportals/velocity/VelocityInfoLogger.java @@ -1,33 +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 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); - } -} +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 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 index 822c5d4e..716a680f 100644 --- a/velocity/src/main/java/com/sekwah/advancedportals/velocity/connector/MinecraftToAnsi.java +++ b/velocity/src/main/java/com/sekwah/advancedportals/velocity/connector/MinecraftToAnsi.java @@ -1,55 +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(); - } -} +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 index 1cd38957..d983be9d 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 @@ -1,33 +1,33 @@ -package com.sekwah.advancedportals.velocity.connector.container; - -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)) - ); - } - } -} +package com.sekwah.advancedportals.velocity.connector.container; + +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 index fe80844c..3717f5c7 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 @@ -1,36 +1,36 @@ -package com.sekwah.advancedportals.velocity.connector.container; - -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, LegacyChannelIdentifier channel) { - this.player = player; - this.channel = channel; - } - - @Override - public String getUUID() { - return player.getUniqueId().toString(); - } - - @Override - public String getName() { - return player.getUsername(); - } - - @Override - public void sendServerPluginMessage(byte[] data) { - player.getCurrentServer().ifPresent(serverConnection -> serverConnection.sendPluginMessage(channel, data)); - } - - public Player getPlayer() { - return this.player; - } -} +package com.sekwah.advancedportals.velocity.connector.container; + +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, LegacyChannelIdentifier channel) { + this.player = player; + this.channel = channel; + } + + @Override + public String getUUID() { + return player.getUniqueId().toString(); + } + + @Override + public String getName() { + return player.getUsername(); + } + + @Override + public void sendServerPluginMessage(byte[] data) { + player.getCurrentServer().ifPresent(serverConnection -> serverConnection.sendPluginMessage(channel, data)); + } + + 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 index 8c8d2447..a983e415 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 @@ -1,17 +1,17 @@ -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 { - private final RegisteredServer server; - - public VelocityProxyServerContainer(RegisteredServer server) { - this.server = server; - } - - @Override - public String getServerName() { - return this.server.getServerInfo().getName(); - } -} +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 { + private final RegisteredServer server; + + public VelocityProxyServerContainer(RegisteredServer server) { + this.server = server; + } + + @Override + public String getServerName() { + return this.server.getServerInfo().getName(); + } +}