From 76035f19d4935eeb6925fad0fa2d7cc02c97933f Mon Sep 17 00:00:00 2001
From: Andre601 <11576465+Andre601@users.noreply.github.com>
Date: Sun, 16 May 2021 19:32:30 +0200
Subject: [PATCH] Support Velocity 2.x ~ Velocity 1.x is now shared under the
velocity-legacy module
---
pom.xml | 3 +-
velocity-legacy/pom.xml | 130 +++++++++++++++++
.../velocity/VelocityCore.java | 132 ++++++++++++++++++
.../commands/CmdOneVersionRemake.java | 39 ++++++
.../velocity/commands/VelocitySender.java | 54 +++++++
.../listener/VelocityLoginListener.java | 69 +++++++++
.../listener/VelocityPingListener.java | 87 ++++++++++++
.../velocity/logging/VelocityLogger.java | 46 ++++++
.../src/main/resources/velocity-plugin.json | 0
velocity/pom.xml | 8 +-
.../velocity/VelocityCore.java | 12 +-
.../listener/VelocityLoginListener.java | 17 +--
.../listener/VelocityPingListener.java | 14 +-
13 files changed, 585 insertions(+), 26 deletions(-)
create mode 100644 velocity-legacy/pom.xml
create mode 100644 velocity-legacy/src/main/java/com/andre601/oneversionremake/velocity/VelocityCore.java
create mode 100644 velocity-legacy/src/main/java/com/andre601/oneversionremake/velocity/commands/CmdOneVersionRemake.java
create mode 100644 velocity-legacy/src/main/java/com/andre601/oneversionremake/velocity/commands/VelocitySender.java
create mode 100644 velocity-legacy/src/main/java/com/andre601/oneversionremake/velocity/listener/VelocityLoginListener.java
create mode 100644 velocity-legacy/src/main/java/com/andre601/oneversionremake/velocity/listener/VelocityPingListener.java
create mode 100644 velocity-legacy/src/main/java/com/andre601/oneversionremake/velocity/logging/VelocityLogger.java
rename {velocity => velocity-legacy}/src/main/resources/velocity-plugin.json (100%)
diff --git a/pom.xml b/pom.xml
index 3cccdb1..53f183b 100644
--- a/pom.xml
+++ b/pom.xml
@@ -18,7 +18,8 @@
core
- velocity
+ velocity-legacy
bungeecord
+ velocity
\ No newline at end of file
diff --git a/velocity-legacy/pom.xml b/velocity-legacy/pom.xml
new file mode 100644
index 0000000..20f2bba
--- /dev/null
+++ b/velocity-legacy/pom.xml
@@ -0,0 +1,130 @@
+
+
+
+
+ 4.0.0
+
+ velocity-legacy
+ jar
+ ${plugin.version}
+
+
+ parent
+ com.andre601.oneversionremake
+ parent
+
+
+
+
+ velocity
+ https://nexus.velocitypowered.com/repository/maven-public
+
+
+ sonatype
+ https://oss.sonatype.org/content/repositories/snapshots
+
+
+
+
+
+ com.andre601.oneversionremake
+ core
+ ${project.version}
+ compile
+
+
+ com.velocitypowered
+ velocity-api
+ 1.1.5
+ provided
+
+
+ net.kyori
+ adventure-text-minimessage
+ 4.0.0-SNAPSHOT
+ compile
+
+
+ org.bstats
+ bstats-velocity
+ 2.2.1
+ compile
+
+
+ org.spongepowered
+ configurate-yaml
+ 4.1.1
+
+
+
+
+ OneVersionRemake-Velocity-legacy-${project.version}
+
+
+ true
+ ${project.basedir}/src/main/resources
+
+
+
+
+ org.apache.maven.plugins
+ maven-compiler-plugin
+ 3.8.1
+
+
+ org.apache.maven.plugins
+ maven-shade-plugin
+ 3.2.4
+
+ true
+
+
+ org.spongepowered.configurate
+ com.andre601.oneversionremake.velocity.dependencies.configurate
+
+
+ org.bstats
+ com.andre601.oneversionremake.velocity.dependencies.bstats
+
+
+
+
+ *:*
+
+ META-INF/*.SF
+ META-INF/*.RSA
+ META-INF/versions/16/
+
+
+
+
+
+
+ package
+
+ shade
+
+
+
+
+
+
+
\ No newline at end of file
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
new file mode 100644
index 0000000..fac9337
--- /dev/null
+++ b/velocity-legacy/src/main/java/com/andre601/oneversionremake/velocity/VelocityCore.java
@@ -0,0 +1,132 @@
+/*
+ * Copyright 2020 - 2021 Andre601
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
+ * documentation files (the "Software"), to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software,
+ * and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in all copies or substantial
+ * portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
+ * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+ * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+ * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
+ * OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+package com.andre601.oneversionremake.velocity;
+
+import com.andre601.oneversionremake.core.OneVersionRemake;
+import com.andre601.oneversionremake.core.commands.CommandHandler;
+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;
+import com.andre601.oneversionremake.velocity.commands.CmdOneVersionRemake;
+import com.andre601.oneversionremake.velocity.listener.VelocityLoginListener;
+import com.andre601.oneversionremake.velocity.listener.VelocityPingListener;
+import com.andre601.oneversionremake.velocity.logging.VelocityLogger;
+import com.google.inject.Inject;
+import com.velocitypowered.api.command.CommandMeta;
+import com.velocitypowered.api.event.Subscribe;
+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;
+import org.bstats.charts.DrilldownPie;
+import org.bstats.velocity.Metrics;
+import org.slf4j.LoggerFactory;
+
+import java.nio.file.Path;
+import java.util.List;
+
+public class VelocityCore implements PluginCore{
+
+ private final ProxyLogger logger;
+ 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){
+ this.logger = new VelocityLogger(LoggerFactory.getLogger("OneVersionRemake"));
+ this.proxy = proxy;
+ this.path = path;
+
+ this.factory = factory;
+ }
+
+ @Subscribe
+ public void initialize(ProxyInitializeEvent event){
+ this.core = new OneVersionRemake(this);
+ }
+
+ // PluginCore stuff
+
+ @Override
+ public void loadCommands(){
+ CommandMeta commandMeta = getProxy().getCommandManager()
+ .metaBuilder("oneversionremake")
+ .aliases("ovr")
+ .build();
+
+ getProxy().getCommandManager().register(commandMeta, new CmdOneVersionRemake(this));
+ }
+
+ @Override
+ public void loadEventListeners(){
+ new VelocityLoginListener(this);
+ new VelocityPingListener(this);
+ }
+
+ @Override
+ public void loadMetrics(){
+ Metrics metrics = factory.make(this, 10341);
+
+ metrics.addCustomChart(new DrilldownPie("allowed_protocols", () -> core.getPieMap()));
+ }
+
+ @Override
+ public Path getPath(){
+ return path;
+ }
+
+ @Override
+ public ProxyPlatform getProxyPlatform(){
+ return ProxyPlatform.VELOCITY;
+ }
+
+ @Override
+ public ProxyLogger getProxyLogger(){
+ return logger;
+ }
+
+ @Override
+ public ConfigHandler getConfigHandler(){
+ return core.getConfigHandler();
+ }
+
+ @Override
+ public CommandHandler getCommandHandler(){
+ return core.getCommandHandler();
+ }
+
+ @Override
+ public String getVersion(){
+ return core.getVersion();
+ }
+
+ public ProxyServer getProxy(){
+ return proxy;
+ }
+
+ public ServerPing.SamplePlayer[] getPlayers(List lines, List serverProtocols, int userProtocol, boolean majorOnly){
+ return core.getPlayers(ServerPing.SamplePlayer.class, lines, serverProtocols, userProtocol, majorOnly)
+ .toArray(new ServerPing.SamplePlayer[0]);
+ }
+}
diff --git a/velocity-legacy/src/main/java/com/andre601/oneversionremake/velocity/commands/CmdOneVersionRemake.java b/velocity-legacy/src/main/java/com/andre601/oneversionremake/velocity/commands/CmdOneVersionRemake.java
new file mode 100644
index 0000000..920f1fa
--- /dev/null
+++ b/velocity-legacy/src/main/java/com/andre601/oneversionremake/velocity/commands/CmdOneVersionRemake.java
@@ -0,0 +1,39 @@
+/*
+ * Copyright 2020 - 2021 Andre601
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
+ * documentation files (the "Software"), to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software,
+ * and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in all copies or substantial
+ * portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
+ * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+ * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+ * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
+ * OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+package com.andre601.oneversionremake.velocity.commands;
+
+import com.andre601.oneversionremake.velocity.VelocityCore;
+import com.velocitypowered.api.command.SimpleCommand;
+
+public class CmdOneVersionRemake implements SimpleCommand{
+
+ private final VelocityCore plugin;
+
+ public CmdOneVersionRemake(VelocityCore plugin){
+ this.plugin = plugin;
+ }
+
+ @Override
+ public void execute(Invocation invocation){
+ VelocitySender sender = new VelocitySender(invocation.source());
+ String[] args = invocation.arguments();
+
+ plugin.getCommandHandler().handle(sender, args);
+ }
+}
diff --git a/velocity-legacy/src/main/java/com/andre601/oneversionremake/velocity/commands/VelocitySender.java b/velocity-legacy/src/main/java/com/andre601/oneversionremake/velocity/commands/VelocitySender.java
new file mode 100644
index 0000000..ac674ca
--- /dev/null
+++ b/velocity-legacy/src/main/java/com/andre601/oneversionremake/velocity/commands/VelocitySender.java
@@ -0,0 +1,54 @@
+/*
+ * Copyright 2020 - 2021 Andre601
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
+ * documentation files (the "Software"), to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software,
+ * and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in all copies or substantial
+ * portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
+ * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+ * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+ * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
+ * OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+package com.andre601.oneversionremake.velocity.commands;
+
+import com.andre601.oneversionremake.core.CommandPermissions;
+import com.andre601.oneversionremake.core.interfaces.CmdSender;
+import com.velocitypowered.api.command.CommandSource;
+import net.kyori.adventure.text.Component;
+import net.kyori.adventure.text.format.NamedTextColor;
+
+public class VelocitySender implements CmdSender{
+
+ private final CommandSource sender;
+
+ public VelocitySender(CommandSource sender){
+ this.sender = sender;
+ }
+
+ @Override
+ public boolean hasPermission(String permission){
+ return sender.hasPermission(permission) || sender.hasPermission(CommandPermissions.ADMIN);
+ }
+
+ @Override
+ public void sendMsg(){
+ sendMsg("");
+ }
+
+ @Override
+ public void sendMsg(String msg, Object... args){
+ sendMsg(NamedTextColor.WHITE, msg, args);
+ }
+
+ @Override
+ public void sendMsg(NamedTextColor color, String msg, Object... args){
+ sender.sendMessage(Component.text(String.format(msg, args)).color(color));
+ }
+}
diff --git a/velocity-legacy/src/main/java/com/andre601/oneversionremake/velocity/listener/VelocityLoginListener.java b/velocity-legacy/src/main/java/com/andre601/oneversionremake/velocity/listener/VelocityLoginListener.java
new file mode 100644
index 0000000..abbc7f0
--- /dev/null
+++ b/velocity-legacy/src/main/java/com/andre601/oneversionremake/velocity/listener/VelocityLoginListener.java
@@ -0,0 +1,69 @@
+/*
+ * Copyright 2020 - 2021 Andre601
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
+ * documentation files (the "Software"), to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software,
+ * and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in all copies or substantial
+ * portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
+ * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+ * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+ * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
+ * OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+package com.andre601.oneversionremake.velocity.listener;
+
+import com.andre601.oneversionremake.core.Parser;
+import com.andre601.oneversionremake.core.enums.ProtocolVersion;
+import com.andre601.oneversionremake.velocity.VelocityCore;
+import com.velocitypowered.api.event.PostOrder;
+import com.velocitypowered.api.event.Subscribe;
+import com.velocitypowered.api.event.connection.PreLoginEvent;
+
+import java.util.Collections;
+import java.util.List;
+
+public class VelocityLoginListener{
+
+ private final VelocityCore plugin;
+
+ public VelocityLoginListener(VelocityCore plugin){
+ this.plugin = plugin;
+ plugin.getProxy().getEventManager().register(plugin, this);
+ }
+
+ @Subscribe(order = PostOrder.FIRST)
+ public void onPreLogin(PreLoginEvent event){
+ List serverProtocols = plugin.getConfigHandler().getIntList("Protocol", "Versions");
+ List kickMessage = plugin.getConfigHandler().getStringList("Messages", "Kick");
+
+ boolean majorOnly = plugin.getConfigHandler().getBoolean(false, "Protocol", "MajorOnly");
+ 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.");
+
+ 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.getUsername(),
+ ProtocolVersion.getFriendlyName(userProtocol),
+ userProtocol
+ ));
+ }
+ }
+ }
+}
diff --git a/velocity-legacy/src/main/java/com/andre601/oneversionremake/velocity/listener/VelocityPingListener.java b/velocity-legacy/src/main/java/com/andre601/oneversionremake/velocity/listener/VelocityPingListener.java
new file mode 100644
index 0000000..bd60e76
--- /dev/null
+++ b/velocity-legacy/src/main/java/com/andre601/oneversionremake/velocity/listener/VelocityPingListener.java
@@ -0,0 +1,87 @@
+/*
+ * Copyright 2020 - 2021 Andre601
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
+ * documentation files (the "Software"), to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software,
+ * and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in all copies or substantial
+ * portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
+ * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+ * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+ * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
+ * OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+package com.andre601.oneversionremake.velocity.listener;
+
+import com.andre601.oneversionremake.core.Parser;
+import com.andre601.oneversionremake.velocity.VelocityCore;
+import com.velocitypowered.api.event.PostOrder;
+import com.velocitypowered.api.event.Subscribe;
+import com.velocitypowered.api.event.proxy.ProxyPingEvent;
+import com.velocitypowered.api.proxy.server.ServerPing;
+
+import java.util.Comparator;
+import java.util.List;
+
+public class VelocityPingListener{
+
+ private final VelocityCore plugin;
+
+ public VelocityPingListener(VelocityCore plugin){
+ this.plugin = plugin;
+ plugin.getProxy().getEventManager().register(plugin, this);
+ }
+
+ @Subscribe(order = PostOrder.FIRST)
+ public void onProxyPing(ProxyPingEvent event){
+ ServerPing ping = event.getPing();
+ ServerPing.Version protocolVersion = ping.getVersion();
+ if(protocolVersion == null)
+ return;
+
+ int userProtocol = protocolVersion.getProtocol();
+
+ List serverProtocols = plugin.getConfigHandler().getIntList("Protocol", "Versions");
+
+ if(serverProtocols.isEmpty())
+ return;
+
+ serverProtocols.sort(Comparator.reverseOrder());
+
+ boolean majorOnly = plugin.getConfigHandler().getBoolean(false, "Protocol", "MajorOnly");
+
+ String playerCount = plugin.getConfigHandler().getString("", "Messages", "PlayerCount");
+ List motd = plugin.getConfigHandler().getStringList("Messages", "Motd");
+ List hoverMessage = plugin.getConfigHandler().getStringList("Messages", "Hover");
+
+ if(!serverProtocols.contains(userProtocol)){
+ ServerPing.Builder builder = ping.asBuilder();
+
+ if(!hoverMessage.isEmpty()){
+ ServerPing.SamplePlayer[] players = plugin.getPlayers(hoverMessage, serverProtocols, userProtocol, majorOnly);
+ if(players != null)
+ builder.samplePlayers(players);
+ }
+
+ if(!playerCount.isEmpty()){
+ playerCount = Parser.toString(playerCount, serverProtocols, userProtocol, majorOnly);
+
+ builder.version(new ServerPing.Version(serverProtocols.get(0), playerCount));
+ }
+
+ if(!motd.isEmpty()){
+ if(motd.size() > 2)
+ motd = motd.subList(0, 1);
+
+ builder.description(Parser.toTextComponent(motd, serverProtocols, userProtocol, majorOnly));
+ }
+
+ event.setPing(builder.build());
+ }
+ }
+}
diff --git a/velocity-legacy/src/main/java/com/andre601/oneversionremake/velocity/logging/VelocityLogger.java b/velocity-legacy/src/main/java/com/andre601/oneversionremake/velocity/logging/VelocityLogger.java
new file mode 100644
index 0000000..291ad5c
--- /dev/null
+++ b/velocity-legacy/src/main/java/com/andre601/oneversionremake/velocity/logging/VelocityLogger.java
@@ -0,0 +1,46 @@
+/*
+ * Copyright 2020 - 2021 Andre601
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
+ * documentation files (the "Software"), to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software,
+ * and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in all copies or substantial
+ * portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
+ * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+ * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+ * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
+ * OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+package com.andre601.oneversionremake.velocity.logging;
+
+import com.andre601.oneversionremake.core.interfaces.ProxyLogger;
+import org.slf4j.Logger;
+
+public class VelocityLogger implements ProxyLogger{
+
+ private final Logger logger;
+
+ public VelocityLogger(Logger logger){
+ this.logger = logger;
+ }
+
+ @Override
+ public void info(String msg){
+ logger.info(msg);
+ }
+
+ @Override
+ public void warn(String msg){
+ logger.warn(msg);
+ }
+
+ @Override
+ public void warn(String msg, Throwable throwable){
+ logger.warn(msg, throwable);
+ }
+}
diff --git a/velocity/src/main/resources/velocity-plugin.json b/velocity-legacy/src/main/resources/velocity-plugin.json
similarity index 100%
rename from velocity/src/main/resources/velocity-plugin.json
rename to velocity-legacy/src/main/resources/velocity-plugin.json
diff --git a/velocity/pom.xml b/velocity/pom.xml
index 7090db2..f4c5290 100644
--- a/velocity/pom.xml
+++ b/velocity/pom.xml
@@ -25,13 +25,13 @@
velocity
jar
${plugin.version}
-
+
parent
com.andre601.oneversionremake
parent
-
+
velocity
@@ -42,7 +42,7 @@
https://oss.sonatype.org/content/repositories/snapshots
-
+
com.andre601.oneversionremake
@@ -53,7 +53,7 @@
com.velocitypowered
velocity-api
- 1.1.5
+ 2.0.0-SNAPSHOT
provided
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 fac9337..d50b025 100644
--- a/velocity/src/main/java/com/andre601/oneversionremake/velocity/VelocityCore.java
+++ b/velocity/src/main/java/com/andre601/oneversionremake/velocity/VelocityCore.java
@@ -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.proxy.ProxyInitializeEvent;
+import com.velocitypowered.api.event.lifecycle.ProxyInitializeEvent;
import com.velocitypowered.api.plugin.annotation.DataDirectory;
import com.velocitypowered.api.proxy.ProxyServer;
import com.velocitypowered.api.proxy.server.ServerPing;
@@ -70,12 +70,12 @@ public void initialize(ProxyInitializeEvent event){
@Override
public void loadCommands(){
- CommandMeta commandMeta = getProxy().getCommandManager()
- .metaBuilder("oneversionremake")
+ CommandMeta commandMeta = getProxy().commandManager()
+ .createMetaBuilder("oneversionremake")
.aliases("ovr")
.build();
- getProxy().getCommandManager().register(commandMeta, new CmdOneVersionRemake(this));
+ getProxy().commandManager().register(commandMeta, new CmdOneVersionRemake(this));
}
@Override
@@ -87,7 +87,7 @@ public void loadEventListeners(){
@Override
public void loadMetrics(){
Metrics metrics = factory.make(this, 10341);
-
+
metrics.addCustomChart(new DrilldownPie("allowed_protocols", () -> core.getPieMap()));
}
@@ -127,6 +127,6 @@ public ProxyServer getProxy(){
public ServerPing.SamplePlayer[] getPlayers(List lines, List serverProtocols, int userProtocol, boolean majorOnly){
return core.getPlayers(ServerPing.SamplePlayer.class, lines, serverProtocols, userProtocol, majorOnly)
- .toArray(new ServerPing.SamplePlayer[0]);
+ .toArray(new ServerPing.SamplePlayer[0]);
}
}
diff --git a/velocity/src/main/java/com/andre601/oneversionremake/velocity/listener/VelocityLoginListener.java b/velocity/src/main/java/com/andre601/oneversionremake/velocity/listener/VelocityLoginListener.java
index abbc7f0..03c790a 100644
--- a/velocity/src/main/java/com/andre601/oneversionremake/velocity/listener/VelocityLoginListener.java
+++ b/velocity/src/main/java/com/andre601/oneversionremake/velocity/listener/VelocityLoginListener.java
@@ -22,8 +22,9 @@
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.connection.PreLoginEvent;
+import com.velocitypowered.api.event.player.PreLoginEvent;
import java.util.Collections;
import java.util.List;
@@ -34,32 +35,32 @@ public class VelocityLoginListener{
public VelocityLoginListener(VelocityCore plugin){
this.plugin = plugin;
- plugin.getProxy().getEventManager().register(plugin, this);
+ plugin.getProxy().eventManager().register(plugin, this);
}
@Subscribe(order = PostOrder.FIRST)
public void onPreLogin(PreLoginEvent event){
List serverProtocols = plugin.getConfigHandler().getIntList("Protocol", "Versions");
List kickMessage = plugin.getConfigHandler().getStringList("Messages", "Kick");
-
+
boolean majorOnly = plugin.getConfigHandler().getBoolean(false, "Protocol", "MajorOnly");
- int userProtocol = event.getConnection().getProtocolVersion().getProtocol();
+ int userProtocol = event.connection().protocolVersion().protocol();
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.");
-
- PreLoginEvent.PreLoginComponentResult result = PreLoginEvent.PreLoginComponentResult
- .denied(Parser.toTextComponent(kickMessage, serverProtocols, userProtocol, majorOnly));
+
+ ResultedEvent.ComponentResult result = PreLoginEvent.ComponentResult.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.getUsername(),
+ event.username(),
ProtocolVersion.getFriendlyName(userProtocol),
userProtocol
));
diff --git a/velocity/src/main/java/com/andre601/oneversionremake/velocity/listener/VelocityPingListener.java b/velocity/src/main/java/com/andre601/oneversionremake/velocity/listener/VelocityPingListener.java
index bd60e76..4987618 100644
--- a/velocity/src/main/java/com/andre601/oneversionremake/velocity/listener/VelocityPingListener.java
+++ b/velocity/src/main/java/com/andre601/oneversionremake/velocity/listener/VelocityPingListener.java
@@ -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.proxy.ProxyPingEvent;
+import com.velocitypowered.api.event.connection.ProxyPingEvent;
import com.velocitypowered.api.proxy.server.ServerPing;
import java.util.Comparator;
@@ -34,25 +34,25 @@ public class VelocityPingListener{
public VelocityPingListener(VelocityCore plugin){
this.plugin = plugin;
- plugin.getProxy().getEventManager().register(plugin, this);
+ plugin.getProxy().eventManager().register(plugin, this);
}
@Subscribe(order = PostOrder.FIRST)
public void onProxyPing(ProxyPingEvent event){
- ServerPing ping = event.getPing();
- ServerPing.Version protocolVersion = ping.getVersion();
+ ServerPing ping = event.ping();
+ ServerPing.Version protocolVersion = ping.version();
if(protocolVersion == null)
return;
- int userProtocol = protocolVersion.getProtocol();
-
+ int userProtocol = protocolVersion.protocol();
+
List serverProtocols = plugin.getConfigHandler().getIntList("Protocol", "Versions");
if(serverProtocols.isEmpty())
return;
serverProtocols.sort(Comparator.reverseOrder());
-
+
boolean majorOnly = plugin.getConfigHandler().getBoolean(false, "Protocol", "MajorOnly");
String playerCount = plugin.getConfigHandler().getString("", "Messages", "PlayerCount");