From bc70c76aec68a83431d6d1500d2d31a1c15f9963 Mon Sep 17 00:00:00 2001 From: xxDark Date: Sat, 12 Jan 2019 18:47:46 +0300 Subject: [PATCH] Some fixes (#165) --- .../proxy/command/VelocityCommandManager.java | 12 ++++++------ .../proxy/connection/MinecraftConnection.java | 7 +++++-- .../connection/backend/VelocityServerConnection.java | 2 +- .../network/http/SimpleHttpResponseCollector.java | 2 +- .../proxy/plugin/PluginClassLoader.java | 7 +++++++ .../proxy/plugin/VelocityPluginManager.java | 4 +--- 6 files changed, 21 insertions(+), 13 deletions(-) diff --git a/proxy/src/main/java/com/velocitypowered/proxy/command/VelocityCommandManager.java b/proxy/src/main/java/com/velocitypowered/proxy/command/VelocityCommandManager.java index c24f47dd6..0e649f942 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/command/VelocityCommandManager.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/command/VelocityCommandManager.java @@ -47,13 +47,13 @@ public class VelocityCommandManager implements CommandManager { } String alias = split[0]; - @SuppressWarnings("nullness") - String[] actualArgs = Arrays.copyOfRange(split, 1, split.length); Command command = commands.get(alias.toLowerCase(Locale.ENGLISH)); if (command == null) { return false; } + @SuppressWarnings("nullness") + String[] actualArgs = Arrays.copyOfRange(split, 1, split.length); try { if (!command.hasPermission(source, actualArgs)) { return false; @@ -103,14 +103,14 @@ public class VelocityCommandManager implements CommandManager { return availableCommands; } - @SuppressWarnings("nullness") - String[] actualArgs = Arrays.copyOfRange(split, 1, split.length); Command command = commands.get(alias.toLowerCase(Locale.ENGLISH)); if (command == null) { // No such command, so we can't offer any tab complete suggestions. return ImmutableList.of(); } + @SuppressWarnings("nullness") + String[] actualArgs = Arrays.copyOfRange(split, 1, split.length); try { if (!command.hasPermission(source, actualArgs)) { return ImmutableList.of(); @@ -140,14 +140,14 @@ public class VelocityCommandManager implements CommandManager { } String alias = split[0]; - @SuppressWarnings("nullness") - String[] actualArgs = Arrays.copyOfRange(split, 1, split.length); Command command = commands.get(alias.toLowerCase(Locale.ENGLISH)); if (command == null) { // No such command. return false; } + @SuppressWarnings("nullness") + String[] actualArgs = Arrays.copyOfRange(split, 1, split.length); try { return command.hasPermission(source, actualArgs); } catch (Exception e) { diff --git a/proxy/src/main/java/com/velocitypowered/proxy/connection/MinecraftConnection.java b/proxy/src/main/java/com/velocitypowered/proxy/connection/MinecraftConnection.java index a2ee67655..5a5fb4f8c 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/connection/MinecraftConnection.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/connection/MinecraftConnection.java @@ -24,7 +24,6 @@ import com.velocitypowered.proxy.protocol.netty.MinecraftCompressDecoder; import com.velocitypowered.proxy.protocol.netty.MinecraftCompressEncoder; import com.velocitypowered.proxy.protocol.netty.MinecraftDecoder; import com.velocitypowered.proxy.protocol.netty.MinecraftEncoder; -import com.velocitypowered.proxy.protocol.packet.Disconnect; import io.netty.buffer.ByteBuf; import io.netty.channel.Channel; import io.netty.channel.ChannelFutureListener; @@ -136,7 +135,11 @@ public class MinecraftConnection extends ChannelInboundHandlerAdapter { public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception { if (ctx.channel().isActive()) { if (sessionHandler != null) { - sessionHandler.exception(cause); + try { + sessionHandler.exception(cause); + } catch (Exception ex) { + logger.error("{}: exception handling exception", (association != null ? association : channel.remoteAddress()), cause); + } } if (association != null) { diff --git a/proxy/src/main/java/com/velocitypowered/proxy/connection/backend/VelocityServerConnection.java b/proxy/src/main/java/com/velocitypowered/proxy/connection/backend/VelocityServerConnection.java index 31b1869a0..b2afac997 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/connection/backend/VelocityServerConnection.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/connection/backend/VelocityServerConnection.java @@ -117,7 +117,7 @@ public class VelocityServerConnection implements MinecraftConnectionAssociation, // BungeeCord IP forwarding is simply a special injection after the "address" in the handshake, // separated by \0 (the null byte). In order, you send the original host, the player's IP, their // UUID (undashed), and if you are in online-mode, their login properties (from Mojang). - StringBuilder data = new StringBuilder(2048) + StringBuilder data = new StringBuilder() .append(registeredServer.getServerInfo().getAddress().getHostString()) .append('\0') .append(proxyPlayer.getRemoteAddress().getHostString()) diff --git a/proxy/src/main/java/com/velocitypowered/proxy/network/http/SimpleHttpResponseCollector.java b/proxy/src/main/java/com/velocitypowered/proxy/network/http/SimpleHttpResponseCollector.java index 54d74514f..5b911cf82 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/network/http/SimpleHttpResponseCollector.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/network/http/SimpleHttpResponseCollector.java @@ -13,7 +13,7 @@ import java.util.concurrent.CompletableFuture; class SimpleHttpResponseCollector extends ChannelInboundHandlerAdapter { - private final StringBuilder buffer = new StringBuilder(1024); + private final StringBuilder buffer = new StringBuilder(); private final CompletableFuture reply; private int httpCode; private boolean canKeepAlive; diff --git a/proxy/src/main/java/com/velocitypowered/proxy/plugin/PluginClassLoader.java b/proxy/src/main/java/com/velocitypowered/proxy/plugin/PluginClassLoader.java index 686056cd7..85908ecbf 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/plugin/PluginClassLoader.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/plugin/PluginClassLoader.java @@ -1,5 +1,6 @@ package com.velocitypowered.proxy.plugin; +import java.io.IOException; import java.net.MalformedURLException; import java.net.URL; import java.net.URLClassLoader; @@ -31,6 +32,12 @@ public class PluginClassLoader extends URLClassLoader { } } + @Override + public void close() throws IOException { + loaders.remove(this); + super.close(); + } + @Override protected Class loadClass(String name, boolean resolve) throws ClassNotFoundException { return loadClass0(name, resolve, true); diff --git a/proxy/src/main/java/com/velocitypowered/proxy/plugin/VelocityPluginManager.java b/proxy/src/main/java/com/velocitypowered/proxy/plugin/VelocityPluginManager.java index f23dfa66e..ad7b53103 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/plugin/VelocityPluginManager.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/plugin/VelocityPluginManager.java @@ -41,9 +41,7 @@ public class VelocityPluginManager implements PluginManager { private void registerPlugin(PluginContainer plugin) { plugins.put(plugin.getDescription().getId(), plugin); Optional instance = plugin.getInstance(); - if (instance.isPresent()) { - pluginInstances.put(instance.get(), plugin); - } + instance.ifPresent(o -> pluginInstances.put(o, plugin)); } /**