mirror of
https://github.com/SpigotMC/BungeeCord.git
synced 2024-11-27 20:59:12 +01:00
Return a Users UUID as a UUID object whilst keeping support for returning as a String
This commit is contained in:
parent
a4dd0dba88
commit
13848def72
@ -2,6 +2,7 @@ package net.md_5.bungee;
|
||||
|
||||
import com.google.common.base.Joiner;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* Series of utility classes to perform various operations.
|
||||
@ -63,4 +64,15 @@ public class Util
|
||||
{
|
||||
return Joiner.on( separators ).join( objects );
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts a String to a UUID
|
||||
*
|
||||
* @param uuid The string to be converted
|
||||
* @return The result
|
||||
*/
|
||||
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 ) );
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,7 @@
|
||||
package net.md_5.bungee.api.connection;
|
||||
|
||||
import java.net.InetSocketAddress;
|
||||
import java.util.UUID;
|
||||
import net.md_5.bungee.api.config.ListenerInfo;
|
||||
|
||||
/**
|
||||
@ -41,9 +42,18 @@ public interface PendingConnection extends Connection
|
||||
* Get this connection's UUID, if set.
|
||||
*
|
||||
* @return the UUID
|
||||
* @deprecated In favour of {@link #getUniqueId()}
|
||||
*/
|
||||
@Deprecated
|
||||
String getUUID();
|
||||
|
||||
/**
|
||||
* Get this connection's UUID, if set.
|
||||
*
|
||||
* @return the UUID
|
||||
*/
|
||||
UUID getUniqueId();
|
||||
|
||||
/**
|
||||
* Get this connection's online mode.
|
||||
*
|
||||
|
@ -4,6 +4,7 @@ import net.md_5.bungee.api.Callback;
|
||||
import net.md_5.bungee.api.CommandSender;
|
||||
import net.md_5.bungee.api.config.ServerInfo;
|
||||
import net.md_5.bungee.api.tab.TabListHandler;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* Represents a player who's connection is being connected to somewhere else,
|
||||
@ -117,6 +118,15 @@ public interface ProxiedPlayer extends Connection, CommandSender
|
||||
* Get this connection's UUID, if set.
|
||||
*
|
||||
* @return the UUID
|
||||
* @deprecated In favour of {@link #getUniqueId()}
|
||||
*/
|
||||
@Deprecated
|
||||
String getUUID();
|
||||
|
||||
/**
|
||||
* Get this connection's UUID, if set.
|
||||
*
|
||||
* @return the UUID
|
||||
*/
|
||||
UUID getUniqueId();
|
||||
}
|
||||
|
@ -14,6 +14,7 @@ import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
import java.util.Objects;
|
||||
import java.util.UUID;
|
||||
import java.util.logging.Level;
|
||||
import lombok.Getter;
|
||||
import lombok.NonNull;
|
||||
@ -401,7 +402,7 @@ public final class UserConnection implements ProxiedPlayer
|
||||
@Override
|
||||
public Collection<String> getPermissions()
|
||||
{
|
||||
return Collections.unmodifiableCollection(permissions);
|
||||
return Collections.unmodifiableCollection( permissions );
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -421,4 +422,10 @@ public final class UserConnection implements ProxiedPlayer
|
||||
{
|
||||
return getPendingConnection().getUUID();
|
||||
}
|
||||
|
||||
@Override
|
||||
public UUID getUniqueId()
|
||||
{
|
||||
return getPendingConnection().getUniqueId();
|
||||
}
|
||||
}
|
||||
|
@ -8,6 +8,7 @@ import java.net.URLEncoder;
|
||||
import java.security.MessageDigest;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
import java.util.logging.Level;
|
||||
import javax.crypto.SecretKey;
|
||||
import lombok.Getter;
|
||||
@ -81,7 +82,7 @@ public class InitialHandler extends PacketHandler implements PendingConnection
|
||||
@Getter
|
||||
private InetSocketAddress virtualHost;
|
||||
@Getter
|
||||
private String UUID;
|
||||
private UUID uniqueId;
|
||||
|
||||
private enum State
|
||||
{
|
||||
@ -320,7 +321,7 @@ public class InitialHandler extends PacketHandler implements PendingConnection
|
||||
LoginResult obj = BungeeCord.getInstance().gson.fromJson( result, LoginResult.class );
|
||||
if ( obj != null )
|
||||
{
|
||||
UUID = obj.getId();
|
||||
uniqueId = Util.getUUID( obj.getId() );
|
||||
finish();
|
||||
return;
|
||||
}
|
||||
@ -366,11 +367,11 @@ public class InitialHandler extends PacketHandler implements PendingConnection
|
||||
{
|
||||
if ( ch.getHandle().isActive() )
|
||||
{
|
||||
if ( UUID == null )
|
||||
if ( uniqueId == null )
|
||||
{
|
||||
UUID = java.util.UUID.nameUUIDFromBytes( ( "OfflinePlayer:" + getName() ).getBytes( Charsets.UTF_8 ) ).toString();
|
||||
uniqueId = java.util.UUID.nameUUIDFromBytes( ( "OfflinePlayer:" + getName() ).getBytes( Charsets.UTF_8 ) );
|
||||
}
|
||||
unsafe.sendPacket( new LoginSuccess( UUID, getName() ) );
|
||||
unsafe.sendPacket( new LoginSuccess( uniqueId.toString(), getName() ) );
|
||||
ch.setProtocol( Protocol.GAME );
|
||||
|
||||
UserConnection userCon = new UserConnection( bungee, ch, getName(), InitialHandler.this );
|
||||
@ -466,6 +467,12 @@ public class InitialHandler extends PacketHandler implements PendingConnection
|
||||
this.onlineMode = onlineMode;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getUUID()
|
||||
{
|
||||
return uniqueId.toString().replaceAll( "-", "" );
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user