From 33a8c4354484f0f7dc73f9cf23bdf080687a743b Mon Sep 17 00:00:00 2001 From: I9hdkill Date: Fri, 26 Apr 2019 04:18:52 +0200 Subject: [PATCH] Enforce checkstyle --- .../java/net/md_5/bungee/api/ProxyConfig.java | 4 +- .../md_5/bungee/protocol/DefinedPacket.java | 2 +- .../bungee/protocol/packet/PluginMessage.java | 12 +-- .../protocol/packet/TabCompleteRequest.java | 12 +-- .../net/md_5/bungee/protocol/packet/Team.java | 2 +- .../net/md_5/bungee/BungeeCordLauncher.java | 10 +-- .../net/md_5/bungee/PlayerInfoSerializer.java | 2 +- .../java/net/md_5/bungee/ServerConnector.java | 80 ++++++++++--------- .../net/md_5/bungee/conf/Configuration.java | 6 +- .../bungee/connection/DownstreamBridge.java | 2 - .../md_5/bungee/forge/ForgeServerHandler.java | 2 +- .../bungee/module/TravisCiModuleSource.java | 10 +-- .../java/net/md_5/bungee/tab/TabList.java | 3 - 13 files changed, 71 insertions(+), 76 deletions(-) diff --git a/api/src/main/java/net/md_5/bungee/api/ProxyConfig.java b/api/src/main/java/net/md_5/bungee/api/ProxyConfig.java index 1e3873f91b..1d9fae17b2 100644 --- a/api/src/main/java/net/md_5/bungee/api/ProxyConfig.java +++ b/api/src/main/java/net/md_5/bungee/api/ProxyConfig.java @@ -78,12 +78,12 @@ public interface ProxyConfig * The favicon used for the server ping list. */ Favicon getFaviconObject(); - + /** * The server name for the server ping list. */ String getCustomServerName(); - + /** * Whether the server should handle packets before the player has connected to a server */ diff --git a/protocol/src/main/java/net/md_5/bungee/protocol/DefinedPacket.java b/protocol/src/main/java/net/md_5/bungee/protocol/DefinedPacket.java index 6540028bfa..78b9f96c5a 100644 --- a/protocol/src/main/java/net/md_5/bungee/protocol/DefinedPacket.java +++ b/protocol/src/main/java/net/md_5/bungee/protocol/DefinedPacket.java @@ -72,7 +72,7 @@ public static byte[] readArray(ByteBuf buf, int limit) buf.readBytes( ret ); return ret; } - + public static void writeArrayLegacy(byte[] b, ByteBuf buf, boolean allowExtended) { // (Integer.MAX_VALUE & 0x1FFF9A ) = 2097050 - Forge's current upper limit diff --git a/protocol/src/main/java/net/md_5/bungee/protocol/packet/PluginMessage.java b/protocol/src/main/java/net/md_5/bungee/protocol/packet/PluginMessage.java index d5d488e9dc..1b80112ce6 100644 --- a/protocol/src/main/java/net/md_5/bungee/protocol/packet/PluginMessage.java +++ b/protocol/src/main/java/net/md_5/bungee/protocol/packet/PluginMessage.java @@ -13,9 +13,9 @@ import lombok.Data; import lombok.EqualsAndHashCode; import lombok.NoArgsConstructor; -import net.md_5.bungee.protocol.MinecraftInput; import net.md_5.bungee.protocol.AbstractPacketHandler; import net.md_5.bungee.protocol.DefinedPacket; +import net.md_5.bungee.protocol.MinecraftInput; import net.md_5.bungee.protocol.ProtocolConstants; @Data @@ -72,11 +72,11 @@ public void read(ByteBuf buf, ProtocolConstants.Direction direction, int protoco { if ( protocolVersion < ProtocolConstants.MINECRAFT_1_8 ) { - tag = readString( buf ); + tag = readString( buf ); data = readArrayLegacy( buf ); } else { - tag = ( protocolVersion >= ProtocolConstants.MINECRAFT_1_13 ) ? MODERNISE.apply( readString( buf ) ) : readString( buf ); + tag = ( protocolVersion >= ProtocolConstants.MINECRAFT_1_13 ) ? MODERNISE.apply( readString( buf ) ) : readString( buf ); int maxSize = direction == ProtocolConstants.Direction.TO_SERVER ? Short.MAX_VALUE : 0x100000; Preconditions.checkArgument( buf.readableBytes() < maxSize ); data = new byte[ buf.readableBytes() ]; @@ -89,11 +89,11 @@ public void write(ByteBuf buf, ProtocolConstants.Direction direction, int protoc { if ( protocolVersion < ProtocolConstants.MINECRAFT_1_8 ) { - writeString( tag, buf ); + writeString( tag, buf ); writeArrayLegacy( data, buf, allowExtendedPacket ); } else { - writeString( ( protocolVersion >= ProtocolConstants.MINECRAFT_1_13 ) ? MODERNISE.apply( tag ) : tag, buf ); + writeString( ( protocolVersion >= ProtocolConstants.MINECRAFT_1_13 ) ? MODERNISE.apply( tag ) : tag, buf ); buf.writeBytes( data ); } } @@ -108,7 +108,7 @@ public DataInput getStream() { return new DataInputStream( new ByteArrayInputStream( data ) ); } - + public MinecraftInput getMCStream() { return new MinecraftInput( Unpooled.wrappedBuffer( data ) ); diff --git a/protocol/src/main/java/net/md_5/bungee/protocol/packet/TabCompleteRequest.java b/protocol/src/main/java/net/md_5/bungee/protocol/packet/TabCompleteRequest.java index 4e9b5b7a25..4024b97910 100644 --- a/protocol/src/main/java/net/md_5/bungee/protocol/packet/TabCompleteRequest.java +++ b/protocol/src/main/java/net/md_5/bungee/protocol/packet/TabCompleteRequest.java @@ -39,8 +39,8 @@ public void read(ByteBuf buf, ProtocolConstants.Direction direction, int protoco { if ( protocolVersion >= ProtocolConstants.MINECRAFT_1_13 ) { - transactionId = readVarInt( buf ); - } + transactionId = readVarInt( buf ); + } cursor = readString( buf ); @@ -60,10 +60,10 @@ public void read(ByteBuf buf, ProtocolConstants.Direction direction, int protoco @Override public void write(ByteBuf buf, ProtocolConstants.Direction direction, int protocolVersion) { - if ( protocolVersion >= ProtocolConstants.MINECRAFT_1_13) - { - writeVarInt( transactionId, buf ); - } + if ( protocolVersion >= ProtocolConstants.MINECRAFT_1_13) + { + writeVarInt( transactionId, buf ); + } writeString( cursor, buf ); diff --git a/protocol/src/main/java/net/md_5/bungee/protocol/packet/Team.java b/protocol/src/main/java/net/md_5/bungee/protocol/packet/Team.java index 11d72c06ef..5e8bb2a948 100644 --- a/protocol/src/main/java/net/md_5/bungee/protocol/packet/Team.java +++ b/protocol/src/main/java/net/md_5/bungee/protocol/packet/Team.java @@ -100,7 +100,7 @@ public void write(ByteBuf buf, ProtocolConstants.Direction direction, int protoc { writeString( collisionRule, buf); } - + if ( protocolVersion >= ProtocolConstants.MINECRAFT_1_13 ) { writeVarInt( color, buf ); diff --git a/proxy/src/main/java/net/md_5/bungee/BungeeCordLauncher.java b/proxy/src/main/java/net/md_5/bungee/BungeeCordLauncher.java index 9bad64e9d2..231ec7ebfb 100644 --- a/proxy/src/main/java/net/md_5/bungee/BungeeCordLauncher.java +++ b/proxy/src/main/java/net/md_5/bungee/BungeeCordLauncher.java @@ -1,6 +1,10 @@ package net.md_5.bungee; +import com.google.gson.JsonIOException; +import com.google.gson.JsonObject; +import com.google.gson.JsonParser; +import com.google.gson.JsonSyntaxException; import java.io.IOException; import java.io.InputStreamReader; import java.net.URL; @@ -8,12 +12,6 @@ import java.security.Security; import java.util.Arrays; import java.util.concurrent.TimeUnit; - -import com.google.gson.JsonIOException; -import com.google.gson.JsonObject; -import com.google.gson.JsonParser; -import com.google.gson.JsonSyntaxException; - import joptsimple.OptionParser; import joptsimple.OptionSet; import net.md_5.bungee.api.ChatColor; diff --git a/proxy/src/main/java/net/md_5/bungee/PlayerInfoSerializer.java b/proxy/src/main/java/net/md_5/bungee/PlayerInfoSerializer.java index bba0641b08..4eba247810 100644 --- a/proxy/src/main/java/net/md_5/bungee/PlayerInfoSerializer.java +++ b/proxy/src/main/java/net/md_5/bungee/PlayerInfoSerializer.java @@ -19,7 +19,7 @@ public PlayerInfoSerializer(int protocol) { this.protocol = protocol; } - + @Override public ServerPing.PlayerInfo deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException { diff --git a/proxy/src/main/java/net/md_5/bungee/ServerConnector.java b/proxy/src/main/java/net/md_5/bungee/ServerConnector.java index 04718cf3f7..f49644852f 100644 --- a/proxy/src/main/java/net/md_5/bungee/ServerConnector.java +++ b/proxy/src/main/java/net/md_5/bungee/ServerConnector.java @@ -8,7 +8,6 @@ import java.util.Queue; import java.util.Set; import java.util.UUID; - import lombok.Getter; import lombok.RequiredArgsConstructor; import net.md_5.bungee.api.ChatColor; @@ -56,7 +55,7 @@ @RequiredArgsConstructor public class ServerConnector extends PacketHandler { - + private final ProxyServer bungee; private ChannelWrapper ch; private final UserConnection user; @@ -65,29 +64,31 @@ public class ServerConnector extends PacketHandler @Getter private ForgeServerHandler handshakeHandler; private boolean obsolete; - + private enum State { - + LOGIN_SUCCESS, ENCRYPT_RESPONSE, LOGIN, FINISHED; } - + @Override public void exception(Throwable t) throws Exception { - if (obsolete) + if (obsolete) { return; - + } + String message = "Exception Connecting:" + Util.exception(t); - if (user.getServer() == null) + if (user.getServer() == null) { user.disconnect(message); - else + } else { user.sendMessage(ChatColor.RED + message); + } } - + @Override public void connected(ChannelWrapper channel) throws Exception { @@ -139,13 +140,13 @@ public void connected(ChannelWrapper channel) throws Exception channel.setProtocol( Protocol.LOGIN ); channel.write( new LoginRequest( user.getName() ) ); } - + @Override public void disconnected(ChannelWrapper channel) throws Exception { user.getPendingConnects().remove(target); } - + @Override public void handle(PacketWrapper packet) throws Exception { @@ -161,7 +162,7 @@ public void handle(LoginSuccess loginSuccess) throws Exception Preconditions.checkState(thisState == State.LOGIN_SUCCESS, "Not expecting LOGIN_SUCCESS"); ch.setProtocol(Protocol.GAME); thisState = State.LOGIN; - + // Only reset the Forge client when: // 1) The user is switching servers (so has a current server) // 2) The handshake is complete @@ -175,18 +176,19 @@ public void handle(LoginSuccess loginSuccess) throws Exception // we need to switch to a modded connection. However, we always need to reset the // connection when we have a modded server regardless of where we go - doing it // here makes sense. - if (user.getServer() != null && user.getForgeClientHandler().isHandshakeComplete() && user.getServer().isForgeServer()) + if (user.getServer() != null && user.getForgeClientHandler().isHandshakeComplete() && user.getServer().isForgeServer()) { user.getForgeClientHandler().resetHandshake(); - + } + throw CancelSendSignal.INSTANCE; } - + @Override public void handle(SetCompression setCompression) throws Exception { ch.setCompressionThreshold(setCompression.getThreshold()); } - + @Override public void handle(Login login) throws Exception { @@ -201,8 +203,9 @@ public void handle(Login login) throws Exception Queue packetQueue = target.getPacketQueue(); synchronized (packetQueue) { - while (!packetQueue.isEmpty()) + while (!packetQueue.isEmpty()) { ch.write(packetQueue.poll()); + } } for ( PluginMessage message : user.getPendingConnection().getRelayMessages() ) @@ -219,16 +222,16 @@ public void handle(Login login) throws Exception { user.getForgeClientHandler().setHandshakeComplete(); } - + if (user.getServer() == null) { // Once again, first connection user.setClientEntityId( login.getEntityId() ); user.setServerEntityId( login.getEntityId() ); - + // Set tab list size, this sucks balls, TODO: what shall we do about packet mutability // Forge allows dimension ID's > 127 - + Login modLogin; if ( handshakeHandler != null && handshakeHandler.isServerForge() ) { @@ -256,14 +259,14 @@ public void handle(Login login) throws Exception user.unsafe().sendPacket( new PluginMessage( user.getPendingConnection().getVersion() >= ProtocolConstants.MINECRAFT_1_13 ? "minecraft:brand" : "MC|Brand", DefinedPacket.toArray( brand ), handshakeHandler.isServerForge() ) ); brand.release(); } - + user.setDimension( login.getDimension() ); } else { user.getServer().setObsolete(true); user.getTabListHandler().onServerChange(); - + Scoreboard serverScoreboard = user.getServerSentScoreboard(); for ( Objective objective : serverScoreboard.getObjectives() ) { @@ -277,7 +280,7 @@ public void handle(Login login) throws Exception for ( Team team : serverScoreboard.getTeams() ) user.unsafe().sendPacket(new net.md_5.bungee.protocol.packet.Team(team.getName())); serverScoreboard.clear(); - + for (UUID bossbar : user.getSentBossBars()) // Send remove bossbar packet user.unsafe().sendPacket(new net.md_5.bungee.protocol.packet.BossBar(bossbar, 1)); @@ -299,7 +302,7 @@ public void handle(Login login) throws Exception // Remove from old servers user.getServer().disconnect("Quitting"); } - + // TODO: Fix this? if (!user.isActive()) { @@ -308,30 +311,30 @@ public void handle(Login login) throws Exception bungee.getLogger().warning("No client connected for pending server!"); return; } - + // Add to new server // TODO: Move this to the connected() method of DownstreamBridge target.addPlayer(user); user.getPendingConnects().remove(target); user.setServerJoinQueue(null); user.setDimensionChange(false); - + user.setServer(server); ch.getHandle().pipeline().get(HandlerBoss.class).setHandler(new DownstreamBridge(bungee, user, server)); - + bungee.getPluginManager().callEvent(new ServerSwitchEvent(user)); - + thisState = State.FINISHED; - + throw CancelSendSignal.INSTANCE; } - + @Override public void handle(EncryptionRequest encryptionRequest) throws Exception { throw new QuietException( "Server is online mode!" ); } - + @Override public void handle(Kick kick) throws Exception { @@ -349,16 +352,17 @@ public void handle(Kick kick) throws Exception user.connect( event.getCancelServer(), ServerConnectEvent.Reason.KICK_REDIRECT ); throw CancelSendSignal.INSTANCE; } - + String message = bungee.getTranslation("connect_kick", target.getName(), event.getKickReason()); - if (user.isDimensionChange()) + if (user.isDimensionChange()) { user.disconnect(message); - else + } else { user.sendMessage(message); - + } + throw CancelSendSignal.INSTANCE; } - + @Override public void handle(PluginMessage pluginMessage) throws Exception { @@ -406,7 +410,7 @@ public void handle(PluginMessage pluginMessage) throws Exception // This includes any REGISTER messages we intercepted earlier. user.unsafe().sendPacket( pluginMessage ); } - + @Override public String toString() { diff --git a/proxy/src/main/java/net/md_5/bungee/conf/Configuration.java b/proxy/src/main/java/net/md_5/bungee/conf/Configuration.java index 3d70a9bf72..787ba11602 100644 --- a/proxy/src/main/java/net/md_5/bungee/conf/Configuration.java +++ b/proxy/src/main/java/net/md_5/bungee/conf/Configuration.java @@ -161,8 +161,8 @@ public String getCustomServerName() return customServerName; } - @Override - public boolean getAlwaysHandlePackets() { + @Override + public boolean getAlwaysHandlePackets() { return alwaysHandlePackets; - } + } } diff --git a/proxy/src/main/java/net/md_5/bungee/connection/DownstreamBridge.java b/proxy/src/main/java/net/md_5/bungee/connection/DownstreamBridge.java index 5efde9483e..eb6a82c96d 100644 --- a/proxy/src/main/java/net/md_5/bungee/connection/DownstreamBridge.java +++ b/proxy/src/main/java/net/md_5/bungee/connection/DownstreamBridge.java @@ -58,8 +58,6 @@ import net.md_5.bungee.protocol.packet.TabCompleteResponse; import net.md_5.bungee.tab.TabList; -import net.md_5.bungee.protocol.ProtocolConstants; - @RequiredArgsConstructor public class DownstreamBridge extends PacketHandler diff --git a/proxy/src/main/java/net/md_5/bungee/forge/ForgeServerHandler.java b/proxy/src/main/java/net/md_5/bungee/forge/ForgeServerHandler.java index 61921130d5..bb631a388b 100644 --- a/proxy/src/main/java/net/md_5/bungee/forge/ForgeServerHandler.java +++ b/proxy/src/main/java/net/md_5/bungee/forge/ForgeServerHandler.java @@ -81,7 +81,7 @@ public void setServerAsForgeServer() { serverForge = true; } - + /** * Returns whether the handshake is complete. diff --git a/proxy/src/main/java/net/md_5/bungee/module/TravisCiModuleSource.java b/proxy/src/main/java/net/md_5/bungee/module/TravisCiModuleSource.java index fd40cf934c..54252e8b14 100644 --- a/proxy/src/main/java/net/md_5/bungee/module/TravisCiModuleSource.java +++ b/proxy/src/main/java/net/md_5/bungee/module/TravisCiModuleSource.java @@ -1,13 +1,11 @@ package net.md_5.bungee.module; +import com.google.common.io.ByteStreams; +import com.google.common.io.Files; import java.io.IOException; import java.net.URL; import java.net.URLConnection; - -import com.google.common.io.ByteStreams; -import com.google.common.io.Files; - import lombok.Data; import net.md_5.bungee.Util; @@ -15,7 +13,7 @@ @Data public class TravisCiModuleSource implements ModuleSource { - + @Override public void retrieve(ModuleSpec module, ModuleVersion version) { @@ -27,7 +25,7 @@ public void retrieve(ModuleSpec module, ModuleVersion version) // 15 second timeout at various stages con.setConnectTimeout(15000); con.setReadTimeout(15000); - + Files.write(ByteStreams.toByteArray(con.getInputStream()), module.getFile()); System.out.println("Download complete"); } diff --git a/proxy/src/main/java/net/md_5/bungee/tab/TabList.java b/proxy/src/main/java/net/md_5/bungee/tab/TabList.java index 0f19bd1f18..7d79ef7bcc 100644 --- a/proxy/src/main/java/net/md_5/bungee/tab/TabList.java +++ b/proxy/src/main/java/net/md_5/bungee/tab/TabList.java @@ -3,11 +3,8 @@ import lombok.RequiredArgsConstructor; import net.md_5.bungee.BungeeCord; import net.md_5.bungee.UserConnection; -import net.md_5.bungee.api.chat.BaseComponent; -import net.md_5.bungee.api.chat.TextComponent; import net.md_5.bungee.api.connection.ProxiedPlayer; import net.md_5.bungee.connection.LoginResult; -import net.md_5.bungee.protocol.ProtocolConstants; import net.md_5.bungee.protocol.packet.PlayerListItem; @RequiredArgsConstructor