From b413a9f187770d3c9d36e45bb3f8f2195b5e62eb Mon Sep 17 00:00:00 2001 From: Andre601 <11576465+Andre601@users.noreply.github.com> Date: Mon, 17 May 2021 22:09:49 +0200 Subject: [PATCH 1/4] First step at properly supporting Velocity 2 --- .../bungeecord/BungeeCore.java | 7 ++++ bungeecord/src/main/resources/plugin.yml | 1 + .../core/OneVersionRemake.java | 34 ++++++++++++++++++- .../core/interfaces/PluginCore.java | 2 ++ pom.xml | 3 ++ .../velocity/VelocityCore.java | 5 +++ .../src/main/resources/velocity-plugin.json | 2 +- velocity/pom.xml | 1 + .../velocity/VelocityCore.java | 5 +++ .../main/resources/velocity-plugin-info.json | 12 +++++++ 10 files changed, 70 insertions(+), 2 deletions(-) create mode 100644 velocity/src/main/resources/velocity-plugin-info.json diff --git a/bungeecord/src/main/java/com/andre601/oneversionremake/bungeecord/BungeeCore.java b/bungeecord/src/main/java/com/andre601/oneversionremake/bungeecord/BungeeCore.java index 92dc93a..cf31164 100644 --- a/bungeecord/src/main/java/com/andre601/oneversionremake/bungeecord/BungeeCore.java +++ b/bungeecord/src/main/java/com/andre601/oneversionremake/bungeecord/BungeeCore.java @@ -105,6 +105,13 @@ public String getVersion(){ return core.getVersion(); } + @Override + public String getProxyVersion(){ + String[] version = getProxy().getVersion().split(":"); + + return String.format("%s (Build #%s)", version[2], version[4]); + } + public ServerPing.PlayerInfo[] getPlayers(List lines, List serverProtocols, int userProtocol, boolean majorOnly){ return core.getPlayers(ServerPing.PlayerInfo.class, lines, serverProtocols, userProtocol, majorOnly) .toArray(new ServerPing.PlayerInfo[0]); diff --git a/bungeecord/src/main/resources/plugin.yml b/bungeecord/src/main/resources/plugin.yml index 80aa039..5d7ae86 100644 --- a/bungeecord/src/main/resources/plugin.yml +++ b/bungeecord/src/main/resources/plugin.yml @@ -1,6 +1,7 @@ name: OneVersionRemake author: Andre_601 version: ${project.version} +description: ${project.description} main: com.andre601.oneversionremake.bungeecord.BungeeCore diff --git a/core/src/main/java/com/andre601/oneversionremake/core/OneVersionRemake.java b/core/src/main/java/com/andre601/oneversionremake/core/OneVersionRemake.java index 0968161..ae1638d 100644 --- a/core/src/main/java/com/andre601/oneversionremake/core/OneVersionRemake.java +++ b/core/src/main/java/com/andre601/oneversionremake/core/OneVersionRemake.java @@ -20,6 +20,7 @@ import com.andre601.oneversionremake.core.commands.CommandHandler; import com.andre601.oneversionremake.core.enums.ProtocolVersion; +import com.andre601.oneversionremake.core.enums.ProxyPlatform; import com.andre601.oneversionremake.core.files.ConfigHandler; import com.andre601.oneversionremake.core.interfaces.PluginCore; import com.andre601.oneversionremake.core.interfaces.ProxyLogger; @@ -118,6 +119,14 @@ public List getPlayers(Class clazz, List lines, List private void start(){ loadVersion(); + + if((pluginCore.getProxyPlatform() != ProxyPlatform.BUNGEECORD) && (pluginCore.getProxyPlatform() != ProxyPlatform.WATERFALL)){ + if((isNewVelocity() && isLegacyPlugin()) || (!isNewVelocity() && !isLegacyPlugin())){ + printIncompatabilityWarning(); + return; + } + } + printBanner(); if(configHandler.loadConfig()){ @@ -168,7 +177,7 @@ private void printBanner(){ getProxyLogger().info("\\____/ |___/_/ |_|"); getProxyLogger().info(""); getProxyLogger().info("OneVersionRemake v" + getVersion()); - getProxyLogger().info("Platform: " + pluginCore.getProxyPlatform().getName()); + getProxyLogger().info("Platform: " + pluginCore.getProxyPlatform().getName() + " v" + pluginCore.getProxyVersion()); getProxyLogger().info(""); } @@ -186,6 +195,15 @@ private void printWarning(){ getProxyLogger().warn("================================================================================"); } + private void printIncompatabilityWarning(){ + getProxyLogger().warn("================================================================================"); + getProxyLogger().warn("WARNING!"); + getProxyLogger().warn("You're using Velocity 2 while the plugin itself is for Velocity 1.1.0!"); + getProxyLogger().warn(""); + getProxyLogger().warn("The Legacy-plugin is incompatible with Velocity 2 and will be disabled..."); + getProxyLogger().warn("================================================================================"); + } + private void loadVersion(){ try(InputStream is = getClass().getResourceAsStream("/core.properties")){ Properties properties = new Properties(); @@ -197,4 +215,18 @@ private void loadVersion(){ version = "UNKNOWN"; } } + + private boolean isNewVelocity(){ + try{ + int maj = Integer.parseInt(pluginCore.getProxyVersion().split("\\.")[0]); + + return maj >= 2; + }catch(NumberFormatException ex){ + return false; + } + } + + private boolean isLegacyPlugin(){ + return pluginCore.getProxyPlatform() == ProxyPlatform.VELOCITY_LEGACY; + } } diff --git a/core/src/main/java/com/andre601/oneversionremake/core/interfaces/PluginCore.java b/core/src/main/java/com/andre601/oneversionremake/core/interfaces/PluginCore.java index 8d13792..793c111 100644 --- a/core/src/main/java/com/andre601/oneversionremake/core/interfaces/PluginCore.java +++ b/core/src/main/java/com/andre601/oneversionremake/core/interfaces/PluginCore.java @@ -43,4 +43,6 @@ public interface PluginCore{ CommandHandler getCommandHandler(); String getVersion(); + + String getProxyVersion(); } diff --git a/pom.xml b/pom.xml index 4088349..1935f2a 100644 --- a/pom.xml +++ b/pom.xml @@ -11,7 +11,10 @@ UTF-8 + 3.5.0 + Only allow specific client versions on your Network. + 11 11 diff --git a/velocity-legacy/src/main/java/com/andre601/oneversionremake/velocity/VelocityCore.java b/velocity-legacy/src/main/java/com/andre601/oneversionremake/velocity/VelocityCore.java index a78e673..a4b90f5 100644 --- a/velocity-legacy/src/main/java/com/andre601/oneversionremake/velocity/VelocityCore.java +++ b/velocity-legacy/src/main/java/com/andre601/oneversionremake/velocity/VelocityCore.java @@ -121,6 +121,11 @@ public String getVersion(){ return core.getVersion(); } + @Override + public String getProxyVersion(){ + return getProxy().getVersion().getVersion(); + } + public ProxyServer getProxy(){ return proxy; } diff --git a/velocity-legacy/src/main/resources/velocity-plugin.json b/velocity-legacy/src/main/resources/velocity-plugin.json index f361246..a677775 100644 --- a/velocity-legacy/src/main/resources/velocity-plugin.json +++ b/velocity-legacy/src/main/resources/velocity-plugin.json @@ -2,7 +2,7 @@ "id": "oneversionremake", "name": "OneVersionRemake", "version": "${project.version}", - "description": "Block connections from Players with versions not matching your Network's.", + "description": "${project.description}", "authors": [ "Andre_601" ], diff --git a/velocity/pom.xml b/velocity/pom.xml index f4c5290..e9da545 100644 --- a/velocity/pom.xml +++ b/velocity/pom.xml @@ -25,6 +25,7 @@ velocity jar ${plugin.version} + ${plugin.description} parent diff --git a/velocity/src/main/java/com/andre601/oneversionremake/velocity/VelocityCore.java b/velocity/src/main/java/com/andre601/oneversionremake/velocity/VelocityCore.java index d50b025..7e1cbd7 100644 --- a/velocity/src/main/java/com/andre601/oneversionremake/velocity/VelocityCore.java +++ b/velocity/src/main/java/com/andre601/oneversionremake/velocity/VelocityCore.java @@ -121,6 +121,11 @@ public String getVersion(){ return core.getVersion(); } + @Override + public String getProxyVersion(){ + return getProxy().version().version(); + } + public ProxyServer getProxy(){ return proxy; } diff --git a/velocity/src/main/resources/velocity-plugin-info.json b/velocity/src/main/resources/velocity-plugin-info.json new file mode 100644 index 0000000..633e040 --- /dev/null +++ b/velocity/src/main/resources/velocity-plugin-info.json @@ -0,0 +1,12 @@ +[ + { + "id": "oneversionremake", + "name": "OneVersionRemake", + "version": "${project.version}", + "description": "${project.description}", + "authors": [ + "Andre_601" + ], + "main": "com.andre601.oneversionremake.velocity.VelocityCore" + } +] From 4273259417b0846361b7b5416896948b6cbe7169 Mon Sep 17 00:00:00 2001 From: Andre601 <11576465+Andre601@users.noreply.github.com> Date: Mon, 17 May 2021 22:12:58 +0200 Subject: [PATCH 2/4] This isn't needed actually... Velocity 1.x plugins wouldn't load in Velocity 2 and vice-versa. --- .../core/OneVersionRemake.java | 32 ------------------- 1 file changed, 32 deletions(-) diff --git a/core/src/main/java/com/andre601/oneversionremake/core/OneVersionRemake.java b/core/src/main/java/com/andre601/oneversionremake/core/OneVersionRemake.java index ae1638d..5606228 100644 --- a/core/src/main/java/com/andre601/oneversionremake/core/OneVersionRemake.java +++ b/core/src/main/java/com/andre601/oneversionremake/core/OneVersionRemake.java @@ -20,7 +20,6 @@ import com.andre601.oneversionremake.core.commands.CommandHandler; import com.andre601.oneversionremake.core.enums.ProtocolVersion; -import com.andre601.oneversionremake.core.enums.ProxyPlatform; import com.andre601.oneversionremake.core.files.ConfigHandler; import com.andre601.oneversionremake.core.interfaces.PluginCore; import com.andre601.oneversionremake.core.interfaces.ProxyLogger; @@ -119,14 +118,6 @@ public List getPlayers(Class clazz, List lines, List private void start(){ loadVersion(); - - if((pluginCore.getProxyPlatform() != ProxyPlatform.BUNGEECORD) && (pluginCore.getProxyPlatform() != ProxyPlatform.WATERFALL)){ - if((isNewVelocity() && isLegacyPlugin()) || (!isNewVelocity() && !isLegacyPlugin())){ - printIncompatabilityWarning(); - return; - } - } - printBanner(); if(configHandler.loadConfig()){ @@ -195,15 +186,6 @@ private void printWarning(){ getProxyLogger().warn("================================================================================"); } - private void printIncompatabilityWarning(){ - getProxyLogger().warn("================================================================================"); - getProxyLogger().warn("WARNING!"); - getProxyLogger().warn("You're using Velocity 2 while the plugin itself is for Velocity 1.1.0!"); - getProxyLogger().warn(""); - getProxyLogger().warn("The Legacy-plugin is incompatible with Velocity 2 and will be disabled..."); - getProxyLogger().warn("================================================================================"); - } - private void loadVersion(){ try(InputStream is = getClass().getResourceAsStream("/core.properties")){ Properties properties = new Properties(); @@ -215,18 +197,4 @@ private void loadVersion(){ version = "UNKNOWN"; } } - - private boolean isNewVelocity(){ - try{ - int maj = Integer.parseInt(pluginCore.getProxyVersion().split("\\.")[0]); - - return maj >= 2; - }catch(NumberFormatException ex){ - return false; - } - } - - private boolean isLegacyPlugin(){ - return pluginCore.getProxyPlatform() == ProxyPlatform.VELOCITY_LEGACY; - } } From 98d48087378df69674fba88bbf066ff85cbe2fdb Mon Sep 17 00:00:00 2001 From: Andre601 <11576465+Andre601@users.noreply.github.com> Date: Tue, 18 May 2021 10:25:26 +0200 Subject: [PATCH 3/4] Remove Metrics from Velocity module (Not supported yet) --- .../oneversionremake/velocity/VelocityCore.java | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/velocity/src/main/java/com/andre601/oneversionremake/velocity/VelocityCore.java b/velocity/src/main/java/com/andre601/oneversionremake/velocity/VelocityCore.java index 7e1cbd7..1f41aad 100644 --- a/velocity/src/main/java/com/andre601/oneversionremake/velocity/VelocityCore.java +++ b/velocity/src/main/java/com/andre601/oneversionremake/velocity/VelocityCore.java @@ -35,8 +35,6 @@ import com.velocitypowered.api.plugin.annotation.DataDirectory; import com.velocitypowered.api.proxy.ProxyServer; import com.velocitypowered.api.proxy.server.ServerPing; -import org.bstats.charts.DrilldownPie; -import org.bstats.velocity.Metrics; import org.slf4j.LoggerFactory; import java.nio.file.Path; @@ -48,17 +46,13 @@ public class VelocityCore implements PluginCore{ private final ProxyServer proxy; private final Path path; - private final Metrics.Factory factory; - private OneVersionRemake core; - @Inject - public VelocityCore(ProxyServer proxy, @DataDirectory Path path, Metrics.Factory factory){ + @Inject // TODO: Re-Add Metrics.Factory factory once Velocity 2 supports it + public VelocityCore(ProxyServer proxy, @DataDirectory Path path){ this.logger = new VelocityLogger(LoggerFactory.getLogger("OneVersionRemake")); this.proxy = proxy; this.path = path; - - this.factory = factory; } @Subscribe @@ -86,9 +80,11 @@ public void loadEventListeners(){ @Override public void loadMetrics(){ - Metrics metrics = factory.make(this, 10341); + // TODO: Re-Add Metrics once available for Velocity 2 + //Metrics metrics = factory.make(this, 10341); + + //metrics.addCustomChart(new DrilldownPie("allowed_protocols", () -> core.getPieMap())); - metrics.addCustomChart(new DrilldownPie("allowed_protocols", () -> core.getPieMap())); } @Override From 6247b26528eb624fbdecbdc71f1c970917f69daa Mon Sep 17 00:00:00 2001 From: Andre601 <11576465+Andre601@users.noreply.github.com> Date: Tue, 18 May 2021 10:26:04 +0200 Subject: [PATCH 4/4] Bump version --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 1935f2a..01672d4 100644 --- a/pom.xml +++ b/pom.xml @@ -12,7 +12,7 @@ UTF-8 - 3.5.0 + 3.5.1 Only allow specific client versions on your Network. 11