Skip to content

Commit

Permalink
First step at properly supporting Velocity 2
Browse files Browse the repository at this point in the history
  • Loading branch information
Andre601 committed May 17, 2021
1 parent 5f478c1 commit b413a9f
Show file tree
Hide file tree
Showing 10 changed files with 70 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<String> lines, List<Integer> serverProtocols, int userProtocol, boolean majorOnly){
return core.getPlayers(ServerPing.PlayerInfo.class, lines, serverProtocols, userProtocol, majorOnly)
.toArray(new ServerPing.PlayerInfo[0]);
Expand Down
1 change: 1 addition & 0 deletions bungeecord/src/main/resources/plugin.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
name: OneVersionRemake
author: Andre_601
version: ${project.version}
description: ${project.description}

main: com.andre601.oneversionremake.bungeecord.BungeeCore

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -118,6 +119,14 @@ public <T> List<T> getPlayers(Class<T> clazz, List<String> lines, List<Integer>

private void start(){
loadVersion();

if((pluginCore.getProxyPlatform() != ProxyPlatform.BUNGEECORD) && (pluginCore.getProxyPlatform() != ProxyPlatform.WATERFALL)){
if((isNewVelocity() && isLegacyPlugin()) || (!isNewVelocity() && !isLegacyPlugin())){
printIncompatabilityWarning();
return;
}
}

printBanner();

if(configHandler.loadConfig()){
Expand Down Expand Up @@ -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("");
}

Expand All @@ -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();
Expand All @@ -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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,6 @@ public interface PluginCore{
CommandHandler getCommandHandler();

String getVersion();

String getProxyVersion();
}
3 changes: 3 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>

<plugin.version>3.5.0</plugin.version>
<plugin.description>Only allow specific client versions on your Network.</plugin.description>

<maven.compiler.target>11</maven.compiler.target>
<maven.compiler.source>11</maven.compiler.source>
</properties>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,11 @@ public String getVersion(){
return core.getVersion();
}

@Override
public String getProxyVersion(){
return getProxy().getVersion().getVersion();
}

public ProxyServer getProxy(){
return proxy;
}
Expand Down
2 changes: 1 addition & 1 deletion velocity-legacy/src/main/resources/velocity-plugin.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
],
Expand Down
1 change: 1 addition & 0 deletions velocity/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
<artifactId>velocity</artifactId>
<packaging>jar</packaging>
<version>${plugin.version}</version>
<description>${plugin.description}</description>

<parent>
<artifactId>parent</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,11 @@ public String getVersion(){
return core.getVersion();
}

@Override
public String getProxyVersion(){
return getProxy().version().version();
}

public ProxyServer getProxy(){
return proxy;
}
Expand Down
12 changes: 12 additions & 0 deletions velocity/src/main/resources/velocity-plugin-info.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
[
{
"id": "oneversionremake",
"name": "OneVersionRemake",
"version": "${project.version}",
"description": "${project.description}",
"authors": [
"Andre_601"
],
"main": "com.andre601.oneversionremake.velocity.VelocityCore"
}
]

0 comments on commit b413a9f

Please sign in to comment.