3
0
Mirror von https://github.com/PaperMC/Velocity.git synchronisiert 2024-11-17 05:20:14 +01:00

Better case-insensitivity.

Dieser Commit ist enthalten in:
Andrew Steinborn 2018-08-05 17:14:39 -04:00
Ursprung a778825152
Commit 48822fe55c
2 geänderte Dateien mit 12 neuen und 14 gelöschten Zeilen

Datei anzeigen

@ -29,10 +29,7 @@ import java.nio.file.NoSuchFileException;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.security.KeyPair;
import java.util.Collection;
import java.util.Map;
import java.util.Optional;
import java.util.UUID;
import java.util.*;
import java.util.concurrent.ConcurrentHashMap;
public class VelocityServer implements ProxyServer {
@ -119,11 +116,12 @@ public class VelocityServer implements ProxyServer {
}
public boolean registerConnection(ConnectedPlayer connection) {
if (connectionsByName.putIfAbsent(connection.getUsername(), connection) != null) {
String lowerName = connection.getUsername().toLowerCase(Locale.US);
if (connectionsByName.putIfAbsent(lowerName, connection) != null) {
return false;
}
if (connectionsByUuid.putIfAbsent(connection.getUniqueId(), connection) != null) {
connectionsByName.remove(connection.getUsername(), connection);
connectionsByName.remove(lowerName, connection);
return false;
}
return true;
@ -137,7 +135,7 @@ public class VelocityServer implements ProxyServer {
@Override
public Optional<Player> getPlayer(@Nonnull String username) {
Preconditions.checkNotNull(username, "username");
return Optional.ofNullable(connectionsByName.get(username));
return Optional.ofNullable(connectionsByName.get(username.toLowerCase(Locale.US)));
}
@Override

Datei anzeigen

@ -4,10 +4,7 @@ import com.google.common.base.Preconditions;
import com.google.common.collect.ImmutableList;
import com.velocitypowered.api.server.ServerInfo;
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
import java.util.Optional;
import java.util.*;
import java.util.concurrent.locks.ReadWriteLock;
import java.util.concurrent.locks.ReentrantReadWriteLock;
@ -17,9 +14,10 @@ public class ServerMap {
public Optional<ServerInfo> getServer(String server) {
Preconditions.checkNotNull(server, "server");
String lowerName = server.toLowerCase(Locale.US);
lock.readLock().lock();
try {
return Optional.ofNullable(servers.get(server.toLowerCase()));
return Optional.ofNullable(servers.get(lowerName));
} finally {
lock.readLock().unlock();
}
@ -36,9 +34,10 @@ public class ServerMap {
public void register(ServerInfo server) {
Preconditions.checkNotNull(server, "server");
String lowerName = server.getName().toLowerCase(Locale.US);
lock.writeLock().lock();
try {
Preconditions.checkArgument(servers.putIfAbsent(server.getName(), server) == null, "Server with name %s already registered", server.getName());
Preconditions.checkArgument(servers.putIfAbsent(lowerName, server) == null, "Server with name %s already registered", server.getName());
} finally {
lock.writeLock().unlock();
}
@ -46,9 +45,10 @@ public class ServerMap {
public void unregister(ServerInfo server) {
Preconditions.checkNotNull(server, "server");
String lowerName = server.getName().toLowerCase(Locale.US);
lock.writeLock().lock();
try {
Preconditions.checkArgument(servers.remove(server.getName(), server), "Server with this name is not registered!");
Preconditions.checkArgument(servers.remove(lowerName, server), "Server with this name is not registered!");
} finally {
lock.writeLock().unlock();
}