Properly interface ServerInfo class.
This commit is contained in:
@@ -6,13 +6,21 @@ import io.netty.channel.ChannelFutureListener;
|
||||
import io.netty.channel.ChannelOption;
|
||||
import io.netty.channel.socket.nio.NioSocketChannel;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.Objects;
|
||||
import java.util.Queue;
|
||||
import java.util.concurrent.ConcurrentLinkedQueue;
|
||||
import lombok.Getter;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.Synchronized;
|
||||
import net.md_5.bungee.api.Callback;
|
||||
import net.md_5.bungee.api.CommandSender;
|
||||
import net.md_5.bungee.api.ProxyServer;
|
||||
import net.md_5.bungee.api.ServerPing;
|
||||
import net.md_5.bungee.api.config.ServerInfo;
|
||||
import net.md_5.bungee.api.connection.ProxiedPlayer;
|
||||
import net.md_5.bungee.api.connection.Server;
|
||||
import net.md_5.bungee.connection.PingHandler;
|
||||
import net.md_5.bungee.netty.HandlerBoss;
|
||||
@@ -20,15 +28,55 @@ import net.md_5.bungee.netty.PipelineUtils;
|
||||
import net.md_5.bungee.packet.DefinedPacket;
|
||||
import net.md_5.bungee.packet.PacketFAPluginMessage;
|
||||
|
||||
public class BungeeServerInfo extends ServerInfo
|
||||
@RequiredArgsConstructor
|
||||
public class BungeeServerInfo implements ServerInfo
|
||||
{
|
||||
|
||||
@Getter
|
||||
private final String name;
|
||||
@Getter
|
||||
private final InetSocketAddress address;
|
||||
private final Collection<ProxiedPlayer> players = new ArrayList<>();
|
||||
@Getter
|
||||
private final boolean restricted;
|
||||
@Getter
|
||||
private final Queue<DefinedPacket> packetQueue = new ConcurrentLinkedQueue<>();
|
||||
|
||||
public BungeeServerInfo(String name, InetSocketAddress address, boolean restricted)
|
||||
@Synchronized("players")
|
||||
public void addPlayer(ProxiedPlayer player)
|
||||
{
|
||||
super( name, address, restricted );
|
||||
players.add( player );
|
||||
}
|
||||
|
||||
@Synchronized("players")
|
||||
public void removePlayer(ProxiedPlayer player)
|
||||
{
|
||||
players.remove( player );
|
||||
}
|
||||
|
||||
@Synchronized("players")
|
||||
@Override
|
||||
public Collection<ProxiedPlayer> getPlayers()
|
||||
{
|
||||
return Collections.unmodifiableCollection( players );
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canAccess(CommandSender player)
|
||||
{
|
||||
return !restricted || player.hasPermission( "bungeecord.server." + name );
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj)
|
||||
{
|
||||
return ( obj instanceof ServerInfo ) && Objects.equals( getAddress(), ( (ServerInfo) obj ).getAddress() );
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode()
|
||||
{
|
||||
return address.hashCode();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@@ -6,7 +6,6 @@ import java.util.concurrent.TimeUnit;
|
||||
import lombok.Getter;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.Setter;
|
||||
import net.md_5.bungee.api.config.ServerInfo;
|
||||
import net.md_5.bungee.api.connection.Server;
|
||||
import net.md_5.bungee.packet.Packet1Login;
|
||||
import net.md_5.bungee.packet.PacketFAPluginMessage;
|
||||
@@ -19,7 +18,7 @@ public class ServerConnection implements Server
|
||||
@Getter
|
||||
private final Channel ch;
|
||||
@Getter
|
||||
private final ServerInfo info;
|
||||
private final BungeeServerInfo info;
|
||||
@Getter
|
||||
private final Packet1Login loginPacket;
|
||||
@Getter
|
||||
|
@@ -36,7 +36,7 @@ public class ServerConnector extends PacketHandler
|
||||
private final ProxyServer bungee;
|
||||
private Channel ch;
|
||||
private final UserConnection user;
|
||||
private final ServerInfo target;
|
||||
private final BungeeServerInfo target;
|
||||
private State thisState = State.ENCRYPT_REQUEST;
|
||||
|
||||
private enum State
|
||||
|
@@ -118,7 +118,10 @@ public final class UserConnection implements ProxiedPlayer
|
||||
{
|
||||
ServerConnectEvent event = new ServerConnectEvent( this, info );
|
||||
ProxyServer.getInstance().getPluginManager().callEvent( event );
|
||||
final ServerInfo target = event.getTarget(); // Update in case the event changed target
|
||||
|
||||
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
|
||||
|
||||
if ( getServer() != null && Objects.equals( getServer().getInfo(), target ) )
|
||||
{
|
||||
sendMessage( ChatColor.RED + "Cannot connect to server you are already on!" );
|
||||
|
@@ -9,12 +9,12 @@ import io.netty.handler.timeout.ReadTimeoutHandler;
|
||||
import io.netty.util.AttributeKey;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import net.md_5.bungee.BungeeCord;
|
||||
import net.md_5.bungee.BungeeServerInfo;
|
||||
import net.md_5.bungee.ServerConnector;
|
||||
import net.md_5.bungee.UserConnection;
|
||||
import net.md_5.bungee.connection.InitialHandler;
|
||||
import net.md_5.bungee.api.ProxyServer;
|
||||
import net.md_5.bungee.api.config.ListenerInfo;
|
||||
import net.md_5.bungee.api.config.ServerInfo;
|
||||
import net.md_5.bungee.protocol.PacketDefinitions;
|
||||
|
||||
public class PipelineUtils
|
||||
@@ -22,7 +22,7 @@ public class PipelineUtils
|
||||
|
||||
public static final AttributeKey<ListenerInfo> LISTENER = new AttributeKey<>( "ListerInfo" );
|
||||
public static final AttributeKey<UserConnection> USER = new AttributeKey<>( "User" );
|
||||
public static final AttributeKey<ServerInfo> TARGET = new AttributeKey<>( "Target" );
|
||||
public static final AttributeKey<BungeeServerInfo> TARGET = new AttributeKey<>( "Target" );
|
||||
public static final ChannelInitializer<Channel> SERVER_CHILD = new ChannelInitializer<Channel>()
|
||||
{
|
||||
@Override
|
||||
|
Reference in New Issue
Block a user