diff --git a/api/src/main/java/net/md_5/bungee/Util.java b/api/src/main/java/net/md_5/bungee/Util.java index 86a00555f8..cb84917ee6 100644 --- a/api/src/main/java/net/md_5/bungee/Util.java +++ b/api/src/main/java/net/md_5/bungee/Util.java @@ -1,6 +1,7 @@ package net.md_5.bungee; import com.google.common.base.Joiner; +import com.google.common.primitives.UnsignedLongs; import java.net.InetSocketAddress; import java.net.URI; import java.net.URISyntaxException; @@ -78,6 +79,6 @@ public static String format(Iterable objects, String separators) */ public static UUID getUUID(String uuid) { - return UUID.fromString( uuid.substring( 0, 8 ) + "-" + uuid.substring( 8, 12 ) + "-" + uuid.substring( 12, 16 ) + "-" + uuid.substring( 16, 20 ) + "-" + uuid.substring( 20, 32 ) ); + return new UUID( UnsignedLongs.parseUnsignedLong( uuid.substring( 0, 16 ), 16 ), UnsignedLongs.parseUnsignedLong( uuid.substring( 16 ), 16 ) ); } } diff --git a/api/src/main/java/net/md_5/bungee/api/plugin/PluginManager.java b/api/src/main/java/net/md_5/bungee/api/plugin/PluginManager.java index 05dbe4995f..afa98ed9af 100644 --- a/api/src/main/java/net/md_5/bungee/api/plugin/PluginManager.java +++ b/api/src/main/java/net/md_5/bungee/api/plugin/PluginManager.java @@ -16,6 +16,7 @@ import java.util.Iterator; import java.util.LinkedHashMap; import java.util.List; +import java.util.Locale; import java.util.Map; import java.util.Set; import java.util.Stack; @@ -75,10 +76,10 @@ public PluginManager(ProxyServer proxy) */ public void registerCommand(Plugin plugin, Command command) { - commandMap.put( command.getName().toLowerCase(), command ); + commandMap.put( command.getName().toLowerCase( Locale.ROOT ), command ); for ( String alias : command.getAliases() ) { - commandMap.put( alias.toLowerCase(), command ); + commandMap.put( alias.toLowerCase( Locale.ROOT ), command ); } commandsByPlugin.put( plugin, command ); } @@ -126,12 +127,12 @@ public boolean dispatchCommand(CommandSender sender, String commandLine, List onTabComplete(CommandSender sender, String[] args) { - final String lastArg = ( args.length > 0 ) ? args[args.length - 1].toLowerCase() : ""; + final String lastArg = ( args.length > 0 ) ? args[args.length - 1].toLowerCase( Locale.ROOT ) : ""; return Iterables.transform( Iterables.filter( ProxyServer.getInstance().getPlayers(), new Predicate() { @Override public boolean apply(ProxiedPlayer player) { - return player.getName().toLowerCase().startsWith( lastArg ); + return player.getName().toLowerCase( Locale.ROOT ).startsWith( lastArg ); } } ), new Function() { diff --git a/api/src/main/java/net/md_5/bungee/util/CaseInsensitiveHashingStrategy.java b/api/src/main/java/net/md_5/bungee/util/CaseInsensitiveHashingStrategy.java index e757f7e0a6..72882d1a09 100644 --- a/api/src/main/java/net/md_5/bungee/util/CaseInsensitiveHashingStrategy.java +++ b/api/src/main/java/net/md_5/bungee/util/CaseInsensitiveHashingStrategy.java @@ -1,6 +1,7 @@ package net.md_5.bungee.util; import gnu.trove.strategy.HashingStrategy; +import java.util.Locale; class CaseInsensitiveHashingStrategy implements HashingStrategy { @@ -10,12 +11,12 @@ class CaseInsensitiveHashingStrategy implements HashingStrategy @Override public int computeHashCode(Object object) { - return ( (String) object ).toLowerCase().hashCode(); + return ( (String) object ).toLowerCase( Locale.ROOT ).hashCode(); } @Override public boolean equals(Object o1, Object o2) { - return o1.equals( o2 ) || ( o1 instanceof String && o2 instanceof String && ( (String) o1 ).toLowerCase().equals( ( (String) o2 ).toLowerCase() ) ); + return o1.equals( o2 ) || ( o1 instanceof String && o2 instanceof String && ( (String) o1 ).toLowerCase( Locale.ROOT ).equals( ( (String) o2 ).toLowerCase( Locale.ROOT ) ) ); } } diff --git a/api/src/test/java/net/md_5/bungee/util/UUIDTest.java b/api/src/test/java/net/md_5/bungee/util/UUIDTest.java new file mode 100644 index 0000000000..9f2d58ed9c --- /dev/null +++ b/api/src/test/java/net/md_5/bungee/util/UUIDTest.java @@ -0,0 +1,29 @@ +package net.md_5.bungee.util; + +import java.util.UUID; +import net.md_5.bungee.Util; +import org.junit.Assert; +import org.junit.Test; + +public class UUIDTest +{ + + @Test + public void testSingle() + { + UUID uuid = UUID.fromString( "af74a02d-19cb-445b-b07f-6866a861f783" ); + UUID uuid1 = Util.getUUID( "af74a02d19cb445bb07f6866a861f783" ); + Assert.assertEquals( uuid, uuid1 ); + } + + @Test + public void testMany() + { + for ( int i = 0; i < 1000; i++ ) + { + UUID expected = UUID.randomUUID(); + UUID actual = Util.getUUID( expected.toString().replace( "-", "" ) ); + Assert.assertEquals( "Could not parse UUID " + expected, expected, actual ); + } + } +} diff --git a/chat/src/main/java/net/md_5/bungee/api/ChatColor.java b/chat/src/main/java/net/md_5/bungee/api/ChatColor.java index cd88bd4700..9f0536c44c 100644 --- a/chat/src/main/java/net/md_5/bungee/api/ChatColor.java +++ b/chat/src/main/java/net/md_5/bungee/api/ChatColor.java @@ -1,6 +1,7 @@ package net.md_5.bungee.api; import java.util.HashMap; +import java.util.Locale; import java.util.Map; import java.util.regex.Pattern; import lombok.Getter; diff --git a/module/cmd-send/src/main/java/net/md_5/bungee/module/cmd/send/CommandSend.java b/module/cmd-send/src/main/java/net/md_5/bungee/module/cmd/send/CommandSend.java index 87c473a117..d802654ea1 100644 --- a/module/cmd-send/src/main/java/net/md_5/bungee/module/cmd/send/CommandSend.java +++ b/module/cmd-send/src/main/java/net/md_5/bungee/module/cmd/send/CommandSend.java @@ -2,6 +2,7 @@ import com.google.common.collect.ImmutableSet; import java.util.HashSet; +import java.util.Locale; import java.util.Set; import net.md_5.bungee.api.ChatColor; import net.md_5.bungee.api.CommandSender; @@ -97,10 +98,10 @@ public Iterable onTabComplete(CommandSender sender, String[] args) Set matches = new HashSet<>(); if ( args.length == 1 ) { - String search = args[0].toLowerCase(); + String search = args[0].toLowerCase( Locale.ROOT ); for ( ProxiedPlayer player : ProxyServer.getInstance().getPlayers() ) { - if ( player.getName().toLowerCase().startsWith( search ) ) + if ( player.getName().toLowerCase( Locale.ROOT ).startsWith( search ) ) { matches.add( player.getName() ); } @@ -115,10 +116,10 @@ public Iterable onTabComplete(CommandSender sender, String[] args) } } else { - String search = args[1].toLowerCase(); + String search = args[1].toLowerCase( Locale.ROOT ); for ( String server : ProxyServer.getInstance().getServers().keySet() ) { - if ( server.toLowerCase().startsWith( search ) ) + if ( server.toLowerCase( Locale.ROOT ).startsWith( search ) ) { matches.add( server ); } diff --git a/module/cmd-server/src/main/java/net/md_5/bungee/module/cmd/server/CommandServer.java b/module/cmd-server/src/main/java/net/md_5/bungee/module/cmd/server/CommandServer.java index 416c54e3a9..2767241002 100644 --- a/module/cmd-server/src/main/java/net/md_5/bungee/module/cmd/server/CommandServer.java +++ b/module/cmd-server/src/main/java/net/md_5/bungee/module/cmd/server/CommandServer.java @@ -4,6 +4,7 @@ import com.google.common.base.Predicate; import com.google.common.collect.Iterables; import java.util.Collections; +import java.util.Locale; import java.util.Map; import net.md_5.bungee.api.ChatColor; import net.md_5.bungee.api.CommandSender; @@ -86,12 +87,12 @@ public Iterable onTabComplete(final CommandSender sender, final String[] { return ( args.length > 1 ) ? Collections.EMPTY_LIST : Iterables.transform( Iterables.filter( ProxyServer.getInstance().getServers().values(), new Predicate() { - private final String lower = ( args.length == 0 ) ? "" : args[0].toLowerCase(); + private final String lower = ( args.length == 0 ) ? "" : args[0].toLowerCase( Locale.ROOT ); @Override public boolean apply(ServerInfo input) { - return input.getName().toLowerCase().startsWith( lower ) && input.canAccess( sender ); + return input.getName().toLowerCase( Locale.ROOT ).startsWith( lower ) && input.canAccess( sender ); } } ), new Function() { diff --git a/proxy/src/main/java/net/md_5/bungee/BungeeCord.java b/proxy/src/main/java/net/md_5/bungee/BungeeCord.java index 6c38fab0ba..9402f3d35a 100644 --- a/proxy/src/main/java/net/md_5/bungee/BungeeCord.java +++ b/proxy/src/main/java/net/md_5/bungee/BungeeCord.java @@ -733,7 +733,7 @@ public Collection matchPlayer(final String partialName) @Override public boolean apply(ProxiedPlayer input) { - return ( input == null ) ? false : input.getName().toLowerCase().startsWith( partialName.toLowerCase() ); + return ( input == null ) ? false : input.getName().toLowerCase( Locale.ROOT ).startsWith( partialName.toLowerCase( Locale.ROOT ) ); } } ) ); } 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 0dbda34dbd..89f66eddb9 100644 --- a/proxy/src/main/java/net/md_5/bungee/ServerConnector.java +++ b/proxy/src/main/java/net/md_5/bungee/ServerConnector.java @@ -1,17 +1,14 @@ package net.md_5.bungee; +import com.google.common.base.Preconditions; +import io.netty.buffer.ByteBuf; +import io.netty.buffer.ByteBufAllocator; import java.util.Arrays; +import java.util.Locale; import java.util.Queue; import java.util.Set; import java.util.UUID; -import com.google.common.base.Preconditions; - -import io.netty.buffer.ByteBuf; -import io.netty.buffer.ByteBufAllocator; - -import java.util.logging.Level; - import lombok.Getter; import lombok.RequiredArgsConstructor; import net.md_5.bungee.api.ChatColor; @@ -333,11 +330,13 @@ public void handle(EncryptionRequest encryptionRequest) throws Exception @Override public void handle(Kick kick) throws Exception { - ServerInfo def = user.updateAndGetNextServer(target); - ServerKickEvent event = new ServerKickEvent(user, target, ComponentSerializer.parse(kick.getMessage()), def, ServerKickEvent.State.CONNECTING); - if (event.getKickReason().toLowerCase().contains("outdated") && def != null) + ServerInfo def = user.updateAndGetNextServer( target ); + ServerKickEvent event = new ServerKickEvent( user, target, ComponentSerializer.parse( kick.getMessage() ), def, ServerKickEvent.State.CONNECTING ); + if ( event.getKickReason().toLowerCase( Locale.ROOT ).contains( "outdated" ) && def != null ) + { // Pre cancel the event if we are going to try another server event.setCancelled(true); + } bungee.getPluginManager().callEvent(event); if (event.isCancelled() && event.getCancelServer() != null) { diff --git a/proxy/src/main/java/net/md_5/bungee/conf/YamlConfig.java b/proxy/src/main/java/net/md_5/bungee/conf/YamlConfig.java index 408312fd69..e15c24c140 100644 --- a/proxy/src/main/java/net/md_5/bungee/conf/YamlConfig.java +++ b/proxy/src/main/java/net/md_5/bungee/conf/YamlConfig.java @@ -15,6 +15,7 @@ import java.util.HashSet; import java.util.LinkedHashMap; import java.util.List; +import java.util.Locale; import java.util.Map; import java.util.logging.Level; import lombok.RequiredArgsConstructor; @@ -243,7 +244,7 @@ public Collection getListeners() InetSocketAddress address = Util.getAddr( host ); Map forced = new CaseInsensitiveMap<>( get( "forced_hosts", forcedDef, val ) ); String tabListName = get( "tab_list", "GLOBAL_PING", val ); - DefaultTabList value = DefaultTabList.valueOf( tabListName.toUpperCase() ); + DefaultTabList value = DefaultTabList.valueOf( tabListName.toUpperCase( Locale.ROOT ) ); if ( value == null ) { value = DefaultTabList.GLOBAL_PING;