Optimize throwing of CancelSendSignal's by storing a single instance.

This commit is contained in:
md_5 2014-02-08 09:36:41 +11:00
parent 4abffa9f24
commit 2eb2953442
4 changed files with 18 additions and 12 deletions

View File

@ -90,7 +90,7 @@ public class ServerConnector extends PacketHandler
ch.setProtocol( Protocol.GAME );
thisState = State.LOGIN;
throw new CancelSendSignal();
throw CancelSendSignal.INSTANCE;
}
@Override
@ -182,7 +182,7 @@ public class ServerConnector extends PacketHandler
thisState = State.FINISHED;
throw new CancelSendSignal();
throw CancelSendSignal.INSTANCE;
}
@Override
@ -203,7 +203,7 @@ public class ServerConnector extends PacketHandler
if ( event.isCancelled() && event.getCancelServer() != null )
{
user.connect( event.getCancelServer() );
throw new CancelSendSignal();
throw CancelSendSignal.INSTANCE;
}
String message = bungee.getTranslation( "connect_kick" ) + target.getName() + ": " + event.getKickReason();
@ -215,7 +215,7 @@ public class ServerConnector extends PacketHandler
user.sendMessage( message );
}
throw new CancelSendSignal();
throw CancelSendSignal.INSTANCE;
}
@Override

View File

@ -1,8 +1,14 @@
package net.md_5.bungee.connection;
import lombok.AccessLevel;
import lombok.NoArgsConstructor;
@NoArgsConstructor(access = AccessLevel.PRIVATE)
public class CancelSendSignal extends Error
{
public static final CancelSendSignal INSTANCE = CancelSendSignal.INSTANCE;
@Override
public Throwable initCause(Throwable cause)
{

View File

@ -97,7 +97,7 @@ public class DownstreamBridge extends PacketHandler
if ( !con.getTabList().onListUpdate( playerList.getUsername(), playerList.isOnline(), playerList.getPing() ) )
{
throw new CancelSendSignal();
throw CancelSendSignal.INSTANCE;
}
}
@ -196,7 +196,7 @@ public class DownstreamBridge extends PacketHandler
if ( bungee.getPluginManager().callEvent( event ).isCancelled() )
{
throw new CancelSendSignal();
throw CancelSendSignal.INSTANCE;
}
if ( pluginMessage.getTag().equals( "BungeeCord" ) )
@ -365,7 +365,7 @@ public class DownstreamBridge extends PacketHandler
con.disconnect0( event.getKickReasonComponent() ); // TODO: Prefix our own stuff.
}
server.setObsolete( true );
throw new CancelSendSignal();
throw CancelSendSignal.INSTANCE;
}
@Override

View File

@ -90,7 +90,7 @@ public class UpstreamBridge extends PacketHandler
con.getServer().unsafe().sendPacket( chat );
}
}
throw new CancelSendSignal();
throw CancelSendSignal.INSTANCE;
}
@Override
@ -104,7 +104,7 @@ public class UpstreamBridge extends PacketHandler
if ( !results.isEmpty() )
{
con.unsafe().sendPacket( new TabCompleteResponse( results.toArray( new String[ results.size() ] ) ) );
throw new CancelSendSignal();
throw CancelSendSignal.INSTANCE;
}
}
}
@ -120,18 +120,18 @@ public class UpstreamBridge extends PacketHandler
{
if ( pluginMessage.getTag().equals( "BungeeCord" ) )
{
throw new CancelSendSignal();
throw CancelSendSignal.INSTANCE;
}
// Hack around Forge race conditions
if ( pluginMessage.getTag().equals( "FML" ) && pluginMessage.getStream().readUnsignedByte() == 1 )
{
throw new CancelSendSignal();
throw CancelSendSignal.INSTANCE;
}
PluginMessageEvent event = new PluginMessageEvent( con, con.getServer(), pluginMessage.getTag(), pluginMessage.getData().clone() );
if ( bungee.getPluginManager().callEvent( event ).isCancelled() )
{
throw new CancelSendSignal();
throw CancelSendSignal.INSTANCE;
}
}