mirror of
https://github.com/SpigotMC/BungeeCord.git
synced 2024-11-27 12:46:05 +01:00
#2466: Use switch in "BungeeCord" plugin message handling
This commit is contained in:
parent
5cf869df1a
commit
d8e293842f
@ -33,6 +33,7 @@
|
||||
|
||||
<!-- See http://checkstyle.sourceforge.net/config_filters.html -->
|
||||
<module name="SuppressionCommentFilter"/>
|
||||
<module name="SuppressWarningsHolder"/>
|
||||
|
||||
<!-- See http://checkstyle.sourceforge.net/config_imports.html -->
|
||||
<module name="AvoidStarImport"/>
|
||||
@ -84,4 +85,6 @@
|
||||
<module name="Indentation"/>
|
||||
<module name="UpperEll"/>
|
||||
</module>
|
||||
|
||||
<module name="SuppressWarningsFilter"/>
|
||||
</module>
|
||||
|
@ -248,6 +248,7 @@ public class DownstreamBridge extends PacketHandler
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("checkstyle:avoidnestedblocks")
|
||||
public void handle(PluginMessage pluginMessage) throws Exception
|
||||
{
|
||||
DataInput in = pluginMessage.getStream();
|
||||
@ -280,7 +281,9 @@ public class DownstreamBridge extends PacketHandler
|
||||
ByteArrayDataOutput out = ByteStreams.newDataOutput();
|
||||
String subChannel = in.readUTF();
|
||||
|
||||
if ( subChannel.equals( "ForwardToPlayer" ) )
|
||||
switch ( subChannel )
|
||||
{
|
||||
case "ForwardToPlayer":
|
||||
{
|
||||
ProxiedPlayer target = bungee.getPlayer( in.readUTF() );
|
||||
if ( target != null )
|
||||
@ -302,8 +305,9 @@ public class DownstreamBridge extends PacketHandler
|
||||
|
||||
// Null out stream, important as we don't want to send to ourselves
|
||||
out = null;
|
||||
break;
|
||||
}
|
||||
if ( subChannel.equals( "Forward" ) )
|
||||
case "Forward":
|
||||
{
|
||||
// Read data from server
|
||||
String target = in.readUTF();
|
||||
@ -321,8 +325,9 @@ public class DownstreamBridge extends PacketHandler
|
||||
// Null out stream, important as we don't want to send to ourselves
|
||||
out = null;
|
||||
|
||||
if ( target.equals( "ALL" ) )
|
||||
switch ( target )
|
||||
{
|
||||
case "ALL":
|
||||
for ( ServerInfo server : bungee.getServers().values() )
|
||||
{
|
||||
if ( server != this.server.getInfo() )
|
||||
@ -330,8 +335,8 @@ public class DownstreamBridge extends PacketHandler
|
||||
server.sendData( "BungeeCord", payload );
|
||||
}
|
||||
}
|
||||
} else if ( target.equals( "ONLINE" ) )
|
||||
{
|
||||
break;
|
||||
case "ONLINE":
|
||||
for ( ServerInfo server : bungee.getServers().values() )
|
||||
{
|
||||
if ( server != this.server.getInfo() )
|
||||
@ -339,24 +344,27 @@ public class DownstreamBridge extends PacketHandler
|
||||
server.sendData( "BungeeCord", payload, false );
|
||||
}
|
||||
}
|
||||
} else
|
||||
{
|
||||
break;
|
||||
default:
|
||||
ServerInfo server = bungee.getServerInfo( target );
|
||||
if ( server != null )
|
||||
{
|
||||
server.sendData( "BungeeCord", payload );
|
||||
}
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
if ( subChannel.equals( "Connect" ) )
|
||||
case "Connect":
|
||||
{
|
||||
ServerInfo server = bungee.getServerInfo( in.readUTF() );
|
||||
if ( server != null )
|
||||
{
|
||||
con.connect( server, ServerConnectEvent.Reason.PLUGIN_MESSAGE );
|
||||
}
|
||||
break;
|
||||
}
|
||||
if ( subChannel.equals( "ConnectOther" ) )
|
||||
case "ConnectOther":
|
||||
{
|
||||
ProxiedPlayer player = bungee.getPlayer( in.readUTF() );
|
||||
if ( player != null )
|
||||
@ -367,9 +375,9 @@ public class DownstreamBridge extends PacketHandler
|
||||
player.connect( server );
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
if ( subChannel.equals( "IP" ) )
|
||||
{
|
||||
case "IP":
|
||||
out.writeUTF( "IP" );
|
||||
if ( con.getSocketAddress() instanceof InetSocketAddress )
|
||||
{
|
||||
@ -380,8 +388,8 @@ public class DownstreamBridge extends PacketHandler
|
||||
out.writeUTF( "unix://" + ( (DomainSocketAddress) con.getSocketAddress() ).path() );
|
||||
out.writeInt( 0 );
|
||||
}
|
||||
}
|
||||
if ( subChannel.equals( "IPOther" ) )
|
||||
break;
|
||||
case "IPOther":
|
||||
{
|
||||
ProxiedPlayer player = bungee.getPlayer( in.readUTF() );
|
||||
if ( player != null )
|
||||
@ -399,8 +407,9 @@ public class DownstreamBridge extends PacketHandler
|
||||
out.writeInt( 0 );
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
if ( subChannel.equals( "PlayerCount" ) )
|
||||
case "PlayerCount":
|
||||
{
|
||||
String target = in.readUTF();
|
||||
out.writeUTF( "PlayerCount" );
|
||||
@ -417,8 +426,9 @@ public class DownstreamBridge extends PacketHandler
|
||||
out.writeInt( server.getPlayers().size() );
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
if ( subChannel.equals( "PlayerList" ) )
|
||||
case "PlayerList":
|
||||
{
|
||||
String target = in.readUTF();
|
||||
out.writeUTF( "PlayerList" );
|
||||
@ -435,13 +445,15 @@ public class DownstreamBridge extends PacketHandler
|
||||
out.writeUTF( Util.csv( server.getPlayers() ) );
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
if ( subChannel.equals( "GetServers" ) )
|
||||
case "GetServers":
|
||||
{
|
||||
out.writeUTF( "GetServers" );
|
||||
out.writeUTF( Util.csv( bungee.getServers().keySet() ) );
|
||||
break;
|
||||
}
|
||||
if ( subChannel.equals( "Message" ) )
|
||||
case "Message":
|
||||
{
|
||||
String target = in.readUTF();
|
||||
String message = in.readUTF();
|
||||
@ -459,8 +471,9 @@ public class DownstreamBridge extends PacketHandler
|
||||
player.sendMessage( message );
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
if ( subChannel.equals( "MessageRaw" ) )
|
||||
case "MessageRaw":
|
||||
{
|
||||
String target = in.readUTF();
|
||||
BaseComponent[] message = ComponentSerializer.parse( in.readUTF() );
|
||||
@ -478,18 +491,21 @@ public class DownstreamBridge extends PacketHandler
|
||||
player.sendMessage( message );
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
if ( subChannel.equals( "GetServer" ) )
|
||||
case "GetServer":
|
||||
{
|
||||
out.writeUTF( "GetServer" );
|
||||
out.writeUTF( server.getInfo().getName() );
|
||||
break;
|
||||
}
|
||||
if ( subChannel.equals( "UUID" ) )
|
||||
case "UUID":
|
||||
{
|
||||
out.writeUTF( "UUID" );
|
||||
out.writeUTF( con.getUUID() );
|
||||
break;
|
||||
}
|
||||
if ( subChannel.equals( "UUIDOther" ) )
|
||||
case "UUIDOther":
|
||||
{
|
||||
ProxiedPlayer player = bungee.getPlayer( in.readUTF() );
|
||||
if ( player != null )
|
||||
@ -498,8 +514,9 @@ public class DownstreamBridge extends PacketHandler
|
||||
out.writeUTF( player.getName() );
|
||||
out.writeUTF( player.getUUID() );
|
||||
}
|
||||
break;
|
||||
}
|
||||
if ( subChannel.equals( "ServerIP" ) )
|
||||
case "ServerIP":
|
||||
{
|
||||
ServerInfo info = bungee.getServerInfo( in.readUTF() );
|
||||
if ( info != null && !info.getAddress().isUnresolved() )
|
||||
@ -509,8 +526,9 @@ public class DownstreamBridge extends PacketHandler
|
||||
out.writeUTF( info.getAddress().getAddress().getHostAddress() );
|
||||
out.writeShort( info.getAddress().getPort() );
|
||||
}
|
||||
break;
|
||||
}
|
||||
if ( subChannel.equals( "KickPlayer" ) )
|
||||
case "KickPlayer":
|
||||
{
|
||||
ProxiedPlayer player = bungee.getPlayer( in.readUTF() );
|
||||
if ( player != null )
|
||||
@ -518,6 +536,8 @@ public class DownstreamBridge extends PacketHandler
|
||||
String kickReason = in.readUTF();
|
||||
player.disconnect( new TextComponent( kickReason ) );
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Check we haven't set out to null, and we have written data, if so reply back back along the BungeeCord channel
|
||||
|
Loading…
Reference in New Issue
Block a user