Skip to content
This repository has been archived by the owner on Jul 15, 2022. It is now read-only.

Commit

Permalink
Merge branch 'SpigotMC-master'
Browse files Browse the repository at this point in the history
  • Loading branch information
sleiss committed Oct 28, 2018
2 parents 51671e7 + 228a43e commit 367a127
Show file tree
Hide file tree
Showing 11 changed files with 63 additions and 27 deletions.
3 changes: 2 additions & 1 deletion api/src/main/java/net/md_5/bungee/Util.java
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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 ) );
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 );
}
Expand Down Expand Up @@ -126,12 +127,12 @@ public boolean dispatchCommand(CommandSender sender, String commandLine, List<St
{
String[] split = commandLine.split( " ", -1 );
// Check for chat that only contains " "
if ( split.length == 0 )
if ( split.length == 0 || split[0].isEmpty() )
{
return false;
}

String commandName = split[0].toLowerCase();
String commandName = split[0].toLowerCase( Locale.ROOT );
if ( sender instanceof ProxiedPlayer && proxy.getDisabledCommands().contains( commandName ) )
{
return false;
Expand Down
5 changes: 3 additions & 2 deletions api/src/main/java/net/md_5/bungee/command/PlayerCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.google.common.base.Function;
import com.google.common.base.Predicate;
import com.google.common.collect.Iterables;
import java.util.Locale;
import net.md_5.bungee.api.CommandSender;
import net.md_5.bungee.api.ProxyServer;
import net.md_5.bungee.api.connection.ProxiedPlayer;
Expand All @@ -29,13 +30,13 @@ public PlayerCommand(String name, String permission, String... aliases)
@Override
public Iterable<String> 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<ProxiedPlayer>()
{
@Override
public boolean apply(ProxiedPlayer player)
{
return player.getName().toLowerCase().startsWith( lastArg );
return player.getName().toLowerCase( Locale.ROOT ).startsWith( lastArg );
}
} ), new Function<ProxiedPlayer, String>()
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package net.md_5.bungee.util;

import gnu.trove.strategy.HashingStrategy;
import java.util.Locale;

class CaseInsensitiveHashingStrategy implements HashingStrategy
{
Expand All @@ -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 ) ) );
}
}
29 changes: 29 additions & 0 deletions api/src/test/java/net/md_5/bungee/util/UUIDTest.java
Original file line number Diff line number Diff line change
@@ -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 );
}
}
}
1 change: 1 addition & 0 deletions chat/src/main/java/net/md_5/bungee/api/ChatColor.java
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -97,10 +98,10 @@ public Iterable<String> onTabComplete(CommandSender sender, String[] args)
Set<String> 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() );
}
Expand All @@ -115,10 +116,10 @@ public Iterable<String> 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 );
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -86,12 +87,12 @@ public Iterable<String> onTabComplete(final CommandSender sender, final String[]
{
return ( args.length > 1 ) ? Collections.EMPTY_LIST : Iterables.transform( Iterables.filter( ProxyServer.getInstance().getServers().values(), new Predicate<ServerInfo>()
{
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<ServerInfo, String>()
{
Expand Down
2 changes: 1 addition & 1 deletion proxy/src/main/java/net/md_5/bungee/BungeeCord.java
Original file line number Diff line number Diff line change
Expand Up @@ -733,7 +733,7 @@ public Collection<ProxiedPlayer> 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 ) );
}
} ) );
}
Expand Down
19 changes: 9 additions & 10 deletions proxy/src/main/java/net/md_5/bungee/ServerConnector.java
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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)
{
Expand Down
3 changes: 2 additions & 1 deletion proxy/src/main/java/net/md_5/bungee/conf/YamlConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -243,7 +244,7 @@ public Collection<ListenerInfo> getListeners()
InetSocketAddress address = Util.getAddr( host );
Map<String, String> 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;
Expand Down

0 comments on commit 367a127

Please sign in to comment.