mirror of
https://github.com/SpigotMC/BungeeCord.git
synced 2024-11-27 20:59:12 +01:00
Clean up code style surrounding bootstrap creation
This commit is contained in:
parent
57793e93f0
commit
8a70af5293
@ -223,13 +223,7 @@ public class BungeeCord extends ProxyServer
|
||||
{
|
||||
for ( final ListenerInfo info : config.getListeners() )
|
||||
{
|
||||
new ServerBootstrap()
|
||||
.channel( NioServerSocketChannel.class )
|
||||
.childAttr( PipelineUtils.LISTENER, info )
|
||||
.childHandler( PipelineUtils.SERVER_CHILD )
|
||||
.group( eventLoops )
|
||||
.localAddress( info.getHost() )
|
||||
.bind().addListener( new ChannelFutureListener()
|
||||
ChannelFutureListener listener = new ChannelFutureListener()
|
||||
{
|
||||
@Override
|
||||
public void operationComplete(ChannelFuture future) throws Exception
|
||||
@ -243,7 +237,14 @@ public class BungeeCord extends ProxyServer
|
||||
getLogger().log( Level.WARNING, "Could not bind to host " + info.getHost(), future.cause() );
|
||||
}
|
||||
}
|
||||
} );
|
||||
};
|
||||
new ServerBootstrap()
|
||||
.channel( NioServerSocketChannel.class )
|
||||
.childAttr( PipelineUtils.LISTENER, info )
|
||||
.childHandler( PipelineUtils.SERVER_CHILD )
|
||||
.group( eventLoops )
|
||||
.localAddress( info.getHost() )
|
||||
.bind().addListener( listener );
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -98,14 +98,7 @@ public class BungeeServerInfo implements ServerInfo
|
||||
@Override
|
||||
public void ping(final Callback<ServerPing> callback)
|
||||
{
|
||||
new Bootstrap()
|
||||
.channel( NioSocketChannel.class )
|
||||
.group( BungeeCord.getInstance().eventLoops )
|
||||
.handler( PipelineUtils.BASE )
|
||||
.option( ChannelOption.CONNECT_TIMEOUT_MILLIS, 5000 ) // TODO: Configurable
|
||||
.remoteAddress( getAddress() )
|
||||
.connect()
|
||||
.addListener( new ChannelFutureListener()
|
||||
ChannelFutureListener listener = new ChannelFutureListener()
|
||||
{
|
||||
@Override
|
||||
public void operationComplete(ChannelFuture future) throws Exception
|
||||
@ -118,6 +111,14 @@ public class BungeeServerInfo implements ServerInfo
|
||||
callback.done( null, future.cause() );
|
||||
}
|
||||
}
|
||||
} );
|
||||
};
|
||||
new Bootstrap()
|
||||
.channel( NioSocketChannel.class )
|
||||
.group( BungeeCord.getInstance().eventLoops )
|
||||
.handler( PipelineUtils.BASE )
|
||||
.option( ChannelOption.CONNECT_TIMEOUT_MILLIS, 5000 ) // TODO: Configurable
|
||||
.remoteAddress( getAddress() )
|
||||
.connect()
|
||||
.addListener( listener );
|
||||
}
|
||||
}
|
||||
|
@ -89,34 +89,34 @@ public final class UserConnection implements ProxiedPlayer
|
||||
@Getter
|
||||
private String displayName;
|
||||
/*========================================================================*/
|
||||
|
||||
|
||||
public void init()
|
||||
{
|
||||
this.displayName = name;
|
||||
|
||||
|
||||
Collection<String> g = bungee.getConfigurationAdapter().getGroups( name );
|
||||
for ( String s : g )
|
||||
{
|
||||
addGroups( s );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void sendPacket(DefinedPacket p)
|
||||
{
|
||||
ch.write( p );
|
||||
}
|
||||
|
||||
|
||||
public void sendPacket(byte[] b)
|
||||
{
|
||||
ch.write( b );
|
||||
}
|
||||
|
||||
|
||||
@Deprecated
|
||||
public boolean isActive()
|
||||
{
|
||||
return ch.getHandle().isActive();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void setDisplayName(String name)
|
||||
{
|
||||
@ -126,20 +126,20 @@ public final class UserConnection implements ProxiedPlayer
|
||||
displayName = name;
|
||||
bungee.getTabListHandler().onConnect( this );
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void connect(ServerInfo target)
|
||||
{
|
||||
connect( target, false );
|
||||
}
|
||||
|
||||
|
||||
public void connectNow(ServerInfo target)
|
||||
{
|
||||
sendPacket( Packet9Respawn.DIM1_SWITCH );
|
||||
sendPacket( Packet9Respawn.DIM2_SWITCH );
|
||||
connect( target );
|
||||
}
|
||||
|
||||
|
||||
public void connect(ServerInfo info, final boolean retry)
|
||||
{
|
||||
ServerConnectEvent event = new ServerConnectEvent( this, info );
|
||||
@ -147,7 +147,7 @@ public final class UserConnection implements ProxiedPlayer
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
Preconditions.checkArgument( event.getTarget() instanceof BungeeServerInfo, "BungeeCord can only connect to BungeeServerInfo instances" );
|
||||
final BungeeServerInfo target = (BungeeServerInfo) event.getTarget(); // Update in case the event changed target
|
||||
|
||||
@ -161,13 +161,10 @@ public final class UserConnection implements ProxiedPlayer
|
||||
sendMessage( ChatColor.RED + "Already connecting to this server!" );
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
pendingConnects.add( target );
|
||||
|
||||
new Bootstrap()
|
||||
.channel( NioSocketChannel.class )
|
||||
.group( BungeeCord.getInstance().eventLoops )
|
||||
.handler( new ChannelInitializer()
|
||||
|
||||
ChannelInitializer initializer = new ChannelInitializer()
|
||||
{
|
||||
@Override
|
||||
protected void initChannel(Channel ch) throws Exception
|
||||
@ -175,11 +172,8 @@ public final class UserConnection implements ProxiedPlayer
|
||||
PipelineUtils.BASE.initChannel( ch );
|
||||
ch.pipeline().get( HandlerBoss.class ).setHandler( new ServerConnector( bungee, UserConnection.this, target ) );
|
||||
}
|
||||
} )
|
||||
.localAddress( getPendingConnection().getListener().getHost() )
|
||||
.option( ChannelOption.CONNECT_TIMEOUT_MILLIS, 5000 ) // TODO: Configurable
|
||||
.remoteAddress( target.getAddress() )
|
||||
.connect().addListener( new ChannelFutureListener()
|
||||
};
|
||||
ChannelFutureListener listener = new ChannelFutureListener()
|
||||
{
|
||||
@Override
|
||||
public void operationComplete(ChannelFuture future) throws Exception
|
||||
@ -188,7 +182,7 @@ public final class UserConnection implements ProxiedPlayer
|
||||
{
|
||||
future.channel().close();
|
||||
pendingConnects.remove( target );
|
||||
|
||||
|
||||
ServerInfo def = ProxyServer.getInstance().getServers().get( getPendingConnection().getListener().getFallbackServer() );
|
||||
if ( retry & target != def && ( getServer() == null || def != getServer().getInfo() ) )
|
||||
{
|
||||
@ -206,9 +200,17 @@ public final class UserConnection implements ProxiedPlayer
|
||||
}
|
||||
}
|
||||
}
|
||||
} );
|
||||
};
|
||||
new Bootstrap()
|
||||
.channel( NioSocketChannel.class )
|
||||
.group( BungeeCord.getInstance().eventLoops )
|
||||
.handler( initializer )
|
||||
.localAddress( getPendingConnection().getListener().getHost() )
|
||||
.option( ChannelOption.CONNECT_TIMEOUT_MILLIS, 5000 ) // TODO: Configurable
|
||||
.remoteAddress( target.getAddress() )
|
||||
.connect().addListener( listener );
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public synchronized void disconnect(String reason)
|
||||
{
|
||||
@ -223,20 +225,20 @@ public final class UserConnection implements ProxiedPlayer
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void chat(String message)
|
||||
{
|
||||
Preconditions.checkState( server != null, "Not connected to server" );
|
||||
server.getCh().write( new Packet3Chat( message ) );
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void sendMessage(String message)
|
||||
{
|
||||
sendPacket( new Packet3Chat( message ) );
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void sendMessages(String... messages)
|
||||
{
|
||||
@ -245,25 +247,25 @@ public final class UserConnection implements ProxiedPlayer
|
||||
sendMessage( message );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void sendData(String channel, byte[] data)
|
||||
{
|
||||
sendPacket( new PacketFAPluginMessage( channel, data ) );
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public InetSocketAddress getAddress()
|
||||
{
|
||||
return (InetSocketAddress) ch.getHandle().remoteAddress();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Collection<String> getGroups()
|
||||
{
|
||||
return Collections.unmodifiableCollection( groups );
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void addGroups(String... groups)
|
||||
{
|
||||
@ -276,7 +278,7 @@ public final class UserConnection implements ProxiedPlayer
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void removeGroups(String... groups)
|
||||
{
|
||||
@ -289,13 +291,13 @@ public final class UserConnection implements ProxiedPlayer
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean hasPermission(String permission)
|
||||
{
|
||||
return bungee.getPluginManager().callEvent( new PermissionCheckEvent( this, permission, permissions.contains( permission ) ) ).hasPermission();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void setPermission(String permission, boolean value)
|
||||
{
|
||||
@ -307,19 +309,19 @@ public final class UserConnection implements ProxiedPlayer
|
||||
permissions.remove( permission );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
return name;
|
||||
}
|
||||
|
||||
|
||||
public void setClientEntityId(int clientEntityId)
|
||||
{
|
||||
Preconditions.checkState( this.clientEntityId == 0, "Client entityId already set!" );
|
||||
this.clientEntityId = clientEntityId;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void setTexturePack(TexturePackInfo pack)
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user