Proper equals on servers
This commit is contained in:
parent
5d1a2c59a7
commit
5592f81e97
@ -4,6 +4,7 @@ import java.net.InetSocketAddress;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.Objects;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.Synchronized;
|
||||
@ -95,4 +96,19 @@ public abstract class ServerInfo
|
||||
{
|
||||
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()
|
||||
{
|
||||
int hash = 7;
|
||||
hash = 73 * hash + Objects.hashCode( getClass() );
|
||||
hash = 73 * hash + Objects.hashCode( getAddress() );
|
||||
return hash;
|
||||
}
|
||||
}
|
||||
|
@ -4,6 +4,7 @@ import com.google.common.base.Preconditions;
|
||||
import com.google.common.io.ByteArrayDataOutput;
|
||||
import com.google.common.io.ByteStreams;
|
||||
import io.netty.channel.Channel;
|
||||
import java.util.Objects;
|
||||
import java.util.Queue;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import net.md_5.bungee.api.ChatColor;
|
||||
@ -165,7 +166,7 @@ public class ServerConnector extends PacketHandler
|
||||
public void handle(PacketFFKick kick) throws Exception
|
||||
{
|
||||
ServerInfo def = bungee.getServerInfo( user.getPendingConnection().getListener().getFallbackServer() );
|
||||
if ( target == def )
|
||||
if ( Objects.equals( target, def) )
|
||||
{
|
||||
def = null;
|
||||
}
|
||||
|
@ -13,6 +13,7 @@ import java.net.InetSocketAddress;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.logging.Level;
|
||||
import lombok.AccessLevel;
|
||||
import lombok.Getter;
|
||||
@ -100,13 +101,7 @@ public final class UserConnection implements ProxiedPlayer
|
||||
@Override
|
||||
public void connect(ServerInfo target)
|
||||
{
|
||||
if ( getServer() != null && getServer().getInfo() == target )
|
||||
{
|
||||
sendMessage( ChatColor.RED + "Cannot connect to server you are already on!" );
|
||||
} else
|
||||
{
|
||||
connect( target, false );
|
||||
}
|
||||
connect( target, false );
|
||||
}
|
||||
|
||||
public void connectNow(ServerInfo target)
|
||||
@ -121,10 +116,9 @@ 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
|
||||
if ( getServer() != null && getServer().getInfo() == target )
|
||||
if ( getServer() != null && Objects.equals( getServer().getInfo(), target ) )
|
||||
{
|
||||
sendMessage( ChatColor.RED + "Cannot connect to server you are already on!" );
|
||||
return;
|
||||
}
|
||||
new Bootstrap()
|
||||
.channel( NioSocketChannel.class )
|
||||
|
@ -4,6 +4,7 @@ import com.google.common.io.ByteArrayDataInput;
|
||||
import com.google.common.io.ByteArrayDataOutput;
|
||||
import com.google.common.io.ByteStreams;
|
||||
import io.netty.channel.Channel;
|
||||
import java.util.Objects;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import net.md_5.bungee.EntityMap;
|
||||
import net.md_5.bungee.ServerConnection;
|
||||
@ -314,7 +315,7 @@ public class DownstreamBridge extends PacketHandler
|
||||
public void handle(PacketFFKick kick) throws Exception
|
||||
{
|
||||
ServerInfo def = bungee.getServerInfo( con.getPendingConnection().getListener().getFallbackServer() );
|
||||
if ( server.getInfo() == def )
|
||||
if ( Objects.equals( server.getInfo(), def ) )
|
||||
{
|
||||
def = null;
|
||||
}
|
||||
|
@ -38,6 +38,7 @@ public class BungeeScheduler implements TaskScheduler
|
||||
Set<ScheduledTask> toRemove = new HashSet<>();
|
||||
for ( ScheduledTask task : tasks.valueCollection() )
|
||||
{
|
||||
// TODO: proper checking?
|
||||
if ( task.getOwner() == plugin )
|
||||
{
|
||||
toRemove.add( task );
|
||||
|
Loading…
Reference in New Issue
Block a user