Skip to content

Commit

Permalink
Merge pull request #60 from Andre601/feature/velocity-v3
Browse files Browse the repository at this point in the history
Support Velocity 3.0.0
  • Loading branch information
Andre601 authored May 31, 2021
2 parents 7912189 + 28385c6 commit 06cefb1
Show file tree
Hide file tree
Showing 9 changed files with 48 additions and 42 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@

import java.nio.file.Path;
import java.util.List;
import java.util.Locale;

public class BungeeCore extends Plugin implements PluginCore{

Expand Down Expand Up @@ -77,16 +78,19 @@ public Path getPath(){

@Override
public ProxyPlatform getProxyPlatform(){
try{
Class.forName("dev._21studios.flamecord.FlameCord");
return ProxyPlatform.FLAMECORD;
}catch(ClassNotFoundException ignored){
try{
Class.forName("io.github.waterfallmc.waterfall.conf.WaterfallConfiguration");
switch(getProxy().getName().toLowerCase(Locale.ROOT)){
case "flamecord":
return ProxyPlatform.FLAMECORD;

case "travertine":
return ProxyPlatform.TRAVERTINE;

case "waterfall":
return ProxyPlatform.WATERFALL;
}catch(ClassNotFoundException ignored1){

case "bungeecord":
default:
return ProxyPlatform.BUNGEECORD;
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,14 @@

public enum ProxyPlatform{

// BungeeCord and forks
BUNGEECORD ("BungeeCord"),
FLAMECORD ("FlameCord"),
TRAVERTINE ("Travertine"),
WATERFALL ("Waterfall"),
VELOCITY ("Velocity 2"),

// Velocity
VELOCITY ("Velocity 3"),
VELOCITY_LEGACY("Velocity");

private final String name;
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>

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

<maven.compiler.target>11</maven.compiler.target>
Expand Down
2 changes: 1 addition & 1 deletion velocity/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
<dependency>
<groupId>com.velocitypowered</groupId>
<artifactId>velocity-api</artifactId>
<version>2.0.0-SNAPSHOT</version>
<version>3.0.0-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
import com.google.inject.Inject;
import com.velocitypowered.api.command.CommandMeta;
import com.velocitypowered.api.event.Subscribe;
import com.velocitypowered.api.event.lifecycle.ProxyInitializeEvent;
import com.velocitypowered.api.event.proxy.ProxyInitializeEvent;
import com.velocitypowered.api.plugin.annotation.DataDirectory;
import com.velocitypowered.api.proxy.ProxyServer;
import com.velocitypowered.api.proxy.server.ServerPing;
Expand All @@ -48,7 +48,7 @@ public class VelocityCore implements PluginCore{

private OneVersionRemake core;

@Inject // TODO: Re-Add Metrics.Factory factory once Velocity 2 supports it
@Inject // TODO: Re-Add Metrics.Factory factory once Velocity 3 supports it
public VelocityCore(ProxyServer proxy, @DataDirectory Path path){
this.logger = new VelocityLogger(LoggerFactory.getLogger("OneVersionRemake"));
this.proxy = proxy;
Expand All @@ -64,12 +64,12 @@ public void initialize(ProxyInitializeEvent event){

@Override
public void loadCommands(){
CommandMeta commandMeta = getProxy().commandManager()
.createMetaBuilder("oneversionremake")
CommandMeta commandMeta = getProxy().getCommandManager()
.metaBuilder("oneversionremake")
.aliases("ovr")
.build();

getProxy().commandManager().register(commandMeta, new CmdOneVersionRemake(this));
getProxy().getCommandManager().register(commandMeta, new CmdOneVersionRemake(this));
}

@Override
Expand All @@ -80,6 +80,7 @@ public void loadEventListeners(){

@Override
public void loadMetrics(){
getProxyLogger().info("Metrics currently not available. Skipping setup...");
// TODO: Re-Add Metrics once available for Velocity 2
//Metrics metrics = factory.make(this, 10341);

Expand Down Expand Up @@ -119,7 +120,7 @@ public String getVersion(){

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

public ProxyServer getProxy(){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,8 @@
import com.andre601.oneversionremake.core.enums.ProtocolVersion;
import com.andre601.oneversionremake.velocity.VelocityCore;
import com.velocitypowered.api.event.PostOrder;
import com.velocitypowered.api.event.ResultedEvent;
import com.velocitypowered.api.event.Subscribe;
import com.velocitypowered.api.event.player.PreLoginEvent;
import com.velocitypowered.api.event.connection.PreLoginEvent;

import java.util.Collections;
import java.util.List;
Expand All @@ -35,7 +34,7 @@ public class VelocityLoginListener{

public VelocityLoginListener(VelocityCore plugin){
this.plugin = plugin;
plugin.getProxy().eventManager().register(plugin, this);
plugin.getProxy().getEventManager().register(plugin, this);
}

@Subscribe(order = PostOrder.FIRST)
Expand All @@ -44,23 +43,23 @@ public void onPreLogin(PreLoginEvent event){
List<String> kickMessage = plugin.getConfigHandler().getStringList("Messages", "Kick");

boolean majorOnly = plugin.getConfigHandler().getBoolean(false, "Protocol", "MajorOnly");
int userProtocol = event.connection().protocolVersion().protocol();
int userProtocol = event.getConnection().getProtocolVersion().getProtocol();
if(serverProtocols.isEmpty())
return;

if(!serverProtocols.contains(userProtocol)){
if(kickMessage.isEmpty())
kickMessage = Collections.singletonList("&cThis Server is running MC {version}! Please change your client version.");
ResultedEvent.ComponentResult result = PreLoginEvent.ComponentResult.denied(
Parser.toTextComponent(kickMessage, serverProtocols, userProtocol, majorOnly));

PreLoginEvent.PreLoginComponentResult result = PreLoginEvent.PreLoginComponentResult
.denied(Parser.toTextComponent(kickMessage, serverProtocols, userProtocol, majorOnly));

event.setResult(result);

if(plugin.getConfigHandler().getBoolean(true, "Protocol", "LogDenial")){
plugin.getProxyLogger().info(String.format(
"Denied login for Player %s with MC version %s (Protocol Version %d)",
event.username(),
event.getUsername(),
ProtocolVersion.getFriendlyName(userProtocol),
userProtocol
));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
import com.andre601.oneversionremake.velocity.VelocityCore;
import com.velocitypowered.api.event.PostOrder;
import com.velocitypowered.api.event.Subscribe;
import com.velocitypowered.api.event.connection.ProxyPingEvent;
import com.velocitypowered.api.event.proxy.ProxyPingEvent;
import com.velocitypowered.api.proxy.server.ServerPing;

import java.util.Comparator;
Expand All @@ -34,17 +34,17 @@ public class VelocityPingListener{

public VelocityPingListener(VelocityCore plugin){
this.plugin = plugin;
plugin.getProxy().eventManager().register(plugin, this);
plugin.getProxy().getEventManager().register(plugin, this);
}

@Subscribe(order = PostOrder.FIRST)
public void onProxyPing(ProxyPingEvent event){
ServerPing ping = event.ping();
ServerPing.Version protocolVersion = ping.version();
ServerPing ping = event.getPing();
ServerPing.Version protocolVersion = ping.getVersion();
if(protocolVersion == null)
return;

int userProtocol = protocolVersion.protocol();
int userProtocol = protocolVersion.getProtocol();

List<Integer> serverProtocols = plugin.getConfigHandler().getIntList("Protocol", "Versions");

Expand Down
12 changes: 0 additions & 12 deletions velocity/src/main/resources/velocity-plugin-info.json

This file was deleted.

10 changes: 10 additions & 0 deletions velocity/src/main/resources/velocity-plugin.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"id": "oneversionremake",
"name": "OneVersionRemake",
"version": "${project.version}",
"description": "${project.description}",
"authors": [
"Andre_601"
],
"main": "com.andre601.oneversionremake.velocity.VelocityCore"
}

0 comments on commit 06cefb1

Please sign in to comment.