diff --git a/api/src/main/java/net/md_5/bungee/api/config/ServerInfo.java b/api/src/main/java/net/md_5/bungee/api/config/ServerInfo.java index c9ada556..4ce34bb0 100644 --- a/api/src/main/java/net/md_5/bungee/api/config/ServerInfo.java +++ b/api/src/main/java/net/md_5/bungee/api/config/ServerInfo.java @@ -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; + } } diff --git a/proxy/src/main/java/net/md_5/bungee/ServerConnector.java b/proxy/src/main/java/net/md_5/bungee/ServerConnector.java index 2933ccaf..35574a17 100644 --- a/proxy/src/main/java/net/md_5/bungee/ServerConnector.java +++ b/proxy/src/main/java/net/md_5/bungee/ServerConnector.java @@ -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; } diff --git a/proxy/src/main/java/net/md_5/bungee/UserConnection.java b/proxy/src/main/java/net/md_5/bungee/UserConnection.java index 83b234c5..5f2e929e 100644 --- a/proxy/src/main/java/net/md_5/bungee/UserConnection.java +++ b/proxy/src/main/java/net/md_5/bungee/UserConnection.java @@ -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 ) diff --git a/proxy/src/main/java/net/md_5/bungee/connection/DownstreamBridge.java b/proxy/src/main/java/net/md_5/bungee/connection/DownstreamBridge.java index 6a77f527..994201e5 100644 --- a/proxy/src/main/java/net/md_5/bungee/connection/DownstreamBridge.java +++ b/proxy/src/main/java/net/md_5/bungee/connection/DownstreamBridge.java @@ -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; } diff --git a/proxy/src/main/java/net/md_5/bungee/scheduler/BungeeScheduler.java b/proxy/src/main/java/net/md_5/bungee/scheduler/BungeeScheduler.java index 920e11c9..fc7e73dd 100644 --- a/proxy/src/main/java/net/md_5/bungee/scheduler/BungeeScheduler.java +++ b/proxy/src/main/java/net/md_5/bungee/scheduler/BungeeScheduler.java @@ -38,6 +38,7 @@ public class BungeeScheduler implements TaskScheduler Set toRemove = new HashSet<>(); for ( ScheduledTask task : tasks.valueCollection() ) { + // TODO: proper checking? if ( task.getOwner() == plugin ) { toRemove.add( task );