fix gameprofile stuff
This commit is contained in:
parent
307f636761
commit
3589884678
|
@ -9,7 +9,9 @@ import com.comphenix.protocol.reflect.accessors.Accessors;
|
||||||
import com.comphenix.protocol.reflect.accessors.ConstructorAccessor;
|
import com.comphenix.protocol.reflect.accessors.ConstructorAccessor;
|
||||||
import com.comphenix.protocol.reflect.accessors.FieldAccessor;
|
import com.comphenix.protocol.reflect.accessors.FieldAccessor;
|
||||||
import com.comphenix.protocol.reflect.accessors.MethodAccessor;
|
import com.comphenix.protocol.reflect.accessors.MethodAccessor;
|
||||||
|
import com.comphenix.protocol.reflect.instances.MinecraftGenerator;
|
||||||
import com.comphenix.protocol.utility.MinecraftReflection;
|
import com.comphenix.protocol.utility.MinecraftReflection;
|
||||||
|
import com.comphenix.protocol.utility.MinecraftVersion;
|
||||||
import com.comphenix.protocol.wrappers.collection.ConvertedMultimap;
|
import com.comphenix.protocol.wrappers.collection.ConvertedMultimap;
|
||||||
import com.google.common.base.Objects;
|
import com.google.common.base.Objects;
|
||||||
import com.google.common.collect.Multimap;
|
import com.google.common.collect.Multimap;
|
||||||
|
@ -112,15 +114,7 @@ public class WrappedGameProfile extends AbstractWrapper {
|
||||||
*/
|
*/
|
||||||
@Deprecated
|
@Deprecated
|
||||||
public WrappedGameProfile(String id, String name) {
|
public WrappedGameProfile(String id, String name) {
|
||||||
super(GAME_PROFILE);
|
this(parseUUID(id), name);
|
||||||
|
|
||||||
if (CREATE_STRING_STRING != null) {
|
|
||||||
setHandle(CREATE_STRING_STRING.invoke(id, name));
|
|
||||||
} else if (CREATE_UUID_STRING != null) {
|
|
||||||
setHandle(CREATE_UUID_STRING.invoke(parseUUID(id), name));
|
|
||||||
} else {
|
|
||||||
throw new IllegalArgumentException("Unsupported GameProfile constructor.");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -137,7 +131,17 @@ public class WrappedGameProfile extends AbstractWrapper {
|
||||||
if (CREATE_STRING_STRING != null) {
|
if (CREATE_STRING_STRING != null) {
|
||||||
setHandle(CREATE_STRING_STRING.invoke(uuid != null ? uuid.toString() : null, name));
|
setHandle(CREATE_STRING_STRING.invoke(uuid != null ? uuid.toString() : null, name));
|
||||||
} else if (CREATE_UUID_STRING != null) {
|
} else if (CREATE_UUID_STRING != null) {
|
||||||
setHandle(CREATE_UUID_STRING.invoke(uuid, name));
|
if (MinecraftVersion.CONFIG_PHASE_PROTOCOL_UPDATE.atOrAbove()) {
|
||||||
|
// 1.20.2+ requires all fields to have a value: null uuid -> UUID(0,0), null name -> empty name
|
||||||
|
// it's not allowed to pass null for both, so we need to pre-check that
|
||||||
|
if (uuid == null && (name == null || name.isEmpty())) {
|
||||||
|
throw new IllegalArgumentException("Name and ID cannot both be blank");
|
||||||
|
}
|
||||||
|
|
||||||
|
setHandle(CREATE_UUID_STRING.invoke(uuid == null ? MinecraftGenerator.SYS_UUID : uuid, name == null ? "" : name));
|
||||||
|
} else {
|
||||||
|
setHandle(CREATE_UUID_STRING.invoke(uuid, name));
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
throw new IllegalArgumentException("Unsupported GameProfile constructor.");
|
throw new IllegalArgumentException("Unsupported GameProfile constructor.");
|
||||||
}
|
}
|
||||||
|
@ -197,6 +201,10 @@ public class WrappedGameProfile extends AbstractWrapper {
|
||||||
uuid = parseUUID(getId());
|
uuid = parseUUID(getId());
|
||||||
} else if (GET_ID != null) {
|
} else if (GET_ID != null) {
|
||||||
uuid = (UUID) GET_ID.invoke(handle);
|
uuid = (UUID) GET_ID.invoke(handle);
|
||||||
|
if (MinecraftVersion.CONFIG_PHASE_PROTOCOL_UPDATE.atOrAbove() && MinecraftGenerator.SYS_UUID.equals(uuid)) {
|
||||||
|
// see CraftPlayerProfile
|
||||||
|
uuid = null;
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
throw new IllegalStateException("Unsupported getId() method");
|
throw new IllegalStateException("Unsupported getId() method");
|
||||||
}
|
}
|
||||||
|
@ -224,7 +232,7 @@ public class WrappedGameProfile extends AbstractWrapper {
|
||||||
if (GET_UUID_STRING != null) {
|
if (GET_UUID_STRING != null) {
|
||||||
return (String) GET_UUID_STRING.get(handle);
|
return (String) GET_UUID_STRING.get(handle);
|
||||||
} else if (GET_ID != null) {
|
} else if (GET_ID != null) {
|
||||||
UUID uuid = (UUID) GET_ID.invoke(handle);
|
UUID uuid = getUUID();
|
||||||
return uuid != null ? uuid.toString() : null;
|
return uuid != null ? uuid.toString() : null;
|
||||||
} else {
|
} else {
|
||||||
throw new IllegalStateException("Unsupported getId() method");
|
throw new IllegalStateException("Unsupported getId() method");
|
||||||
|
@ -238,7 +246,12 @@ public class WrappedGameProfile extends AbstractWrapper {
|
||||||
*/
|
*/
|
||||||
public String getName() {
|
public String getName() {
|
||||||
if (GET_NAME != null) {
|
if (GET_NAME != null) {
|
||||||
return (String) GET_NAME.invoke(handle);
|
String name = (String) GET_NAME.invoke(handle);
|
||||||
|
if (MinecraftVersion.CONFIG_PHASE_PROTOCOL_UPDATE.atOrAbove() && name != null && name.isEmpty()) {
|
||||||
|
// see CraftPlayerProfile
|
||||||
|
name = null;
|
||||||
|
}
|
||||||
|
return name;
|
||||||
} else {
|
} else {
|
||||||
throw new IllegalStateException("Unsupported getName() method");
|
throw new IllegalStateException("Unsupported getName() method");
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,6 +5,7 @@ import java.security.PublicKey;
|
||||||
import com.comphenix.protocol.reflect.accessors.Accessors;
|
import com.comphenix.protocol.reflect.accessors.Accessors;
|
||||||
import com.comphenix.protocol.reflect.accessors.ConstructorAccessor;
|
import com.comphenix.protocol.reflect.accessors.ConstructorAccessor;
|
||||||
import com.comphenix.protocol.reflect.accessors.MethodAccessor;
|
import com.comphenix.protocol.reflect.accessors.MethodAccessor;
|
||||||
|
import com.comphenix.protocol.utility.MinecraftVersion;
|
||||||
import com.google.common.base.Objects;
|
import com.google.common.base.Objects;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -36,16 +37,23 @@ public class WrappedSignedProperty extends AbstractWrapper {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
CONSTRUCTOR = Accessors.getConstructorAccessor(PROPERTY, String.class, String.class, String.class);
|
CONSTRUCTOR = Accessors.getConstructorAccessor(PROPERTY, String.class, String.class, String.class);
|
||||||
GET_NAME = Accessors.getMethodAccessor(PROPERTY, "getName");
|
|
||||||
GET_SIGNATURE = Accessors.getMethodAccessor(PROPERTY, "getSignature");
|
|
||||||
GET_VALUE = Accessors.getMethodAccessor(PROPERTY, "getValue");
|
|
||||||
HAS_SIGNATURE = Accessors.getMethodAccessor(PROPERTY, "hasSignature");
|
HAS_SIGNATURE = Accessors.getMethodAccessor(PROPERTY, "hasSignature");
|
||||||
IS_SIGNATURE_VALID = Accessors.getMethodAccessor(PROPERTY, "isSignatureValid", PublicKey.class);
|
IS_SIGNATURE_VALID = Accessors.getMethodAccessor(PROPERTY, "isSignatureValid", PublicKey.class);
|
||||||
|
|
||||||
|
if (MinecraftVersion.CONFIG_PHASE_PROTOCOL_UPDATE.atOrAbove()) {
|
||||||
|
GET_NAME = Accessors.getMethodAccessorOrNull(PROPERTY, "name");
|
||||||
|
GET_SIGNATURE = Accessors.getMethodAccessor(PROPERTY, "signature");
|
||||||
|
GET_VALUE = Accessors.getMethodAccessor(PROPERTY, "value");
|
||||||
|
} else {
|
||||||
|
GET_NAME = Accessors.getMethodAccessorOrNull(PROPERTY, "getName");
|
||||||
|
GET_SIGNATURE = Accessors.getMethodAccessor(PROPERTY, "getSignature");
|
||||||
|
GET_VALUE = Accessors.getMethodAccessor(PROPERTY, "getValue");
|
||||||
|
}
|
||||||
} catch (Throwable ex) {
|
} catch (Throwable ex) {
|
||||||
throw new RuntimeException("Failed to obtain methods for Property.", ex);
|
throw new RuntimeException("Failed to obtain methods for Property.", ex);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Construct a new wrapped signed property from the given values.
|
* Construct a new wrapped signed property from the given values.
|
||||||
* @param name - the name of the property.
|
* @param name - the name of the property.
|
||||||
|
|
Loading…
Reference in New Issue