Skip to content
This repository has been archived by the owner on Jul 15, 2022. It is now read-only.

Commit

Permalink
Enforce checkstyle
Browse files Browse the repository at this point in the history
  • Loading branch information
johnfriedrich committed Apr 26, 2019
1 parent adfe82d commit 33a8c43
Show file tree
Hide file tree
Showing 13 changed files with 71 additions and 76 deletions.
4 changes: 2 additions & 2 deletions api/src/main/java/net/md_5/bungee/api/ProxyConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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() ];
Expand All @@ -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 );
}
}
Expand All @@ -108,7 +108,7 @@ public DataInput getStream()
{
return new DataInputStream( new ByteArrayInputStream( data ) );
}

public MinecraftInput getMCStream()
{
return new MinecraftInput( Unpooled.wrappedBuffer( data ) );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 );

Expand All @@ -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 );

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
Expand Down
10 changes: 4 additions & 6 deletions proxy/src/main/java/net/md_5/bungee/BungeeCordLauncher.java
Original file line number Diff line number Diff line change
@@ -1,19 +1,17 @@
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;
import java.net.URLConnection;
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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public PlayerInfoSerializer(int protocol)
{
this.protocol = protocol;
}

@Override
public ServerPing.PlayerInfo deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException
{
Expand Down
80 changes: 42 additions & 38 deletions proxy/src/main/java/net/md_5/bungee/ServerConnector.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -56,7 +55,7 @@
@RequiredArgsConstructor
public class ServerConnector extends PacketHandler
{

private final ProxyServer bungee;
private ChannelWrapper ch;
private final UserConnection user;
Expand All @@ -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
{
Expand Down Expand Up @@ -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
{
Expand All @@ -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
Expand All @@ -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
{
Expand All @@ -201,8 +203,9 @@ public void handle(Login login) throws Exception
Queue<DefinedPacket> packetQueue = target.getPacketQueue();
synchronized (packetQueue)
{
while (!packetQueue.isEmpty())
while (!packetQueue.isEmpty()) {
ch.write(packetQueue.poll());
}
}

for ( PluginMessage message : user.getPendingConnection().getRelayMessages() )
Expand All @@ -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() )
{
Expand Down Expand Up @@ -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() )
{
Expand All @@ -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));
Expand All @@ -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())
{
Expand All @@ -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
{
Expand All @@ -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
{
Expand Down Expand Up @@ -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()
{
Expand Down
6 changes: 3 additions & 3 deletions proxy/src/main/java/net/md_5/bungee/conf/Configuration.java
Original file line number Diff line number Diff line change
Expand Up @@ -161,8 +161,8 @@ public String getCustomServerName()
return customServerName;
}

@Override
public boolean getAlwaysHandlePackets() {
@Override
public boolean getAlwaysHandlePackets() {
return alwaysHandlePackets;
}
}
}
Loading

0 comments on commit 33a8c43

Please sign in to comment.