Archiviert
13
0

Interpret the empty string as 0-0-0-0-0 as well.

Dieser Commit ist enthalten in:
Kristian S. Stangeland 2014-04-14 17:49:04 +02:00
Ursprung a65eac6471
Commit c1890cb256
2 geänderte Dateien mit 44 neuen und 5 gelöschten Zeilen

Datei anzeigen

@ -8,7 +8,6 @@ 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.google.common.base.Objects; import com.google.common.base.Objects;
import com.google.common.base.Strings;
import net.minecraft.util.com.mojang.authlib.GameProfile; 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. * Construct a new game profile with the given properties.
* <p>
* 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 id - the UUID of the player.
* @param name - the name 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 { try {
// Interpret as zero
if (StringUtils.isBlank(id))
id = "0";
int missing = 4 - StringUtils.countMatches(id, "-"); int missing = 4 - StringUtils.countMatches(id, "-");
// Lenient - add missing data // Lenient - add missing data
@ -59,14 +67,16 @@ public class WrappedGameProfile extends AbstractWrapper {
/** /**
* Construct a new game profile with the given properties. * Construct a new game profile with the given properties.
* @param uuid - the UUID of the player. * <p>
* @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) { public WrappedGameProfile(UUID uuid, String name) {
super(GameProfile.class); super(GameProfile.class);
if (CREATE_STRING_STRING != null) { 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 { } else {
setHandle(new GameProfile(uuid, name)); setHandle(new GameProfile(uuid, name));
} }

Datei anzeigen

@ -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);
}
}