diff --git a/ProtocolLib/src/main/java/com/comphenix/protocol/wrappers/WrappedGameProfile.java b/ProtocolLib/src/main/java/com/comphenix/protocol/wrappers/WrappedGameProfile.java index b2b023f9..ba623f2f 100644 --- a/ProtocolLib/src/main/java/com/comphenix/protocol/wrappers/WrappedGameProfile.java +++ b/ProtocolLib/src/main/java/com/comphenix/protocol/wrappers/WrappedGameProfile.java @@ -8,7 +8,6 @@ import com.comphenix.protocol.reflect.accessors.Accessors; import com.comphenix.protocol.reflect.accessors.ConstructorAccessor; import com.comphenix.protocol.reflect.accessors.FieldAccessor; import com.google.common.base.Objects; -import com.google.common.base.Strings; import net.minecraft.util.com.mojang.authlib.GameProfile; @@ -29,6 +28,9 @@ public class WrappedGameProfile extends AbstractWrapper { /** * Construct a new game profile with the given properties. + *

+ * Note that this constructor is very lenient when parsing UUIDs for backwards compatibility reasons. + * Thus - "", " ", "0" and "0-0-0-0" are all equivalent to the the UUID "00000000-0000-0000-0000-000000000000". * @param id - the UUID of the player. * @param name - the name of the player. */ @@ -43,8 +45,14 @@ public class WrappedGameProfile extends AbstractWrapper { } } - private UUID parseUUID(String id, String name) { + private static UUID parseUUID(String id, String name) { + if (id == null) + return null; + try { + // Interpret as zero + if (StringUtils.isBlank(id)) + id = "0"; int missing = 4 - StringUtils.countMatches(id, "-"); // Lenient - add missing data @@ -59,14 +67,16 @@ public class WrappedGameProfile extends AbstractWrapper { /** * Construct a new game profile with the given properties. - * @param uuid - the UUID of the player. - * @param name - the name of the player. + *

+ * Note that at least one of the parameters must be non-null. + * @param uuid - the UUID of the player, or NULL. + * @param name - the name of the player, or NULL. */ public WrappedGameProfile(UUID uuid, String name) { super(GameProfile.class); if (CREATE_STRING_STRING != null) { - setHandle(CREATE_STRING_STRING.invoke(uuid.toString(), name)); + setHandle(CREATE_STRING_STRING.invoke(uuid != null ? uuid.toString() : null, name)); } else { setHandle(new GameProfile(uuid, name)); } diff --git a/ProtocolLib/src/test/java/com/comphenix/protocol/wrappers/WrappedGameProfileTest.java b/ProtocolLib/src/test/java/com/comphenix/protocol/wrappers/WrappedGameProfileTest.java new file mode 100644 index 00000000..20af71f0 --- /dev/null +++ b/ProtocolLib/src/test/java/com/comphenix/protocol/wrappers/WrappedGameProfileTest.java @@ -0,0 +1,29 @@ +package com.comphenix.protocol.wrappers; + +import static org.junit.Assert.*; + +import org.junit.BeforeClass; +import org.junit.Test; + +import com.comphenix.protocol.BukkitInitialization; + +public class WrappedGameProfileTest { + @BeforeClass + public static void initializeBukkit() throws IllegalAccessException { + BukkitInitialization.initializePackage(); + } + + @Test + public void testSkinUpdate() { + final String nullUUID = "00000000-0000-0000-0000-000000000000"; + assertEquals(null, new WrappedGameProfile((String)null, "Test").getId()); + assertEquals(nullUUID, new WrappedGameProfile("", "Test").getId()); + assertEquals(nullUUID, new WrappedGameProfile("0", "Test").getId()); + assertEquals(nullUUID, new WrappedGameProfile("00-0", "Test").getId()); + } + + @Test(expected = IllegalArgumentException.class) + public void testNullFailure() { + new WrappedGameProfile((String)null, null); + } +}