Archiviert
13
0

Properly handle WrappedGameProfile during packet cloning.

Dieser Commit ist enthalten in:
Kristian S. Stangeland 2014-01-17 23:58:04 +01:00
Ursprung 90548f1092
Commit d70e9d28d4
4 geänderte Dateien mit 36 neuen und 3 gelöschten Zeilen

Datei anzeigen

@ -258,6 +258,6 @@ public class AggregateCloner implements Cloner {
} }
// Damn - failure // Damn - failure
throw new IllegalArgumentException("Cannot clone " + source + ": No cloner is sutable."); throw new IllegalArgumentException("Cannot clone " + source + ": No cloner is suitable.");
} }
} }

Datei anzeigen

@ -30,6 +30,7 @@ import java.util.UUID;
import javax.crypto.SecretKey; import javax.crypto.SecretKey;
import com.comphenix.protocol.utility.MinecraftReflection;
import com.google.common.primitives.Primitives; import com.google.common.primitives.Primitives;
/** /**
@ -79,6 +80,12 @@ public class ImmutableDetector implements Cloner {
if (clazz.equals(type)) if (clazz.equals(type))
return true; return true;
// Check for known immutable classes in 1.7.2
if (MinecraftReflection.isUsingNetty()) {
if (type.equals(MinecraftReflection.getGameProfileClass())) {
return true;
}
}
// Probably not // Probably not
return false; return false;
} }

Datei anzeigen

@ -0,0 +1,26 @@
package com.comphenix.protocol.wrappers;
import org.junit.BeforeClass;
import org.junit.Test;
import static org.junit.Assert.*;
import com.comphenix.protocol.BukkitInitialization;
import com.comphenix.protocol.reflect.cloning.AggregateCloner;
public class CloningTest {
@BeforeClass
public static void initializeBukkit() throws IllegalAccessException {
BukkitInitialization.initializePackage();
}
@Test
public void cloneGameProfile() {
WrappedGameProfile profile = new WrappedGameProfile("id", "name");
WrappedGameProfile copy = WrappedGameProfile.fromHandle(
AggregateCloner.DEFAULT.clone(profile.getHandle())
);
assertEquals(profile, copy);
}
}

Datei anzeigen

@ -13,7 +13,7 @@ import org.junit.BeforeClass;
import org.junit.Test; import org.junit.Test;
import com.comphenix.protocol.BukkitInitialization; import com.comphenix.protocol.BukkitInitialization;
import com.comphenix.protocol.Packets; import com.comphenix.protocol.PacketType;
import com.comphenix.protocol.events.PacketContainer; import com.comphenix.protocol.events.PacketContainer;
import com.comphenix.protocol.wrappers.WrappedAttributeModifier.Operation; import com.comphenix.protocol.wrappers.WrappedAttributeModifier.Operation;
import com.google.common.collect.Lists; import com.google.common.collect.Lists;
@ -48,7 +48,7 @@ public class WrappedAttributeTest {
attribute = WrappedAttribute.newBuilder(). attribute = WrappedAttribute.newBuilder().
attributeKey("generic.attackDamage"). attributeKey("generic.attackDamage").
baseValue(2). baseValue(2).
packet(new PacketContainer(Packets.Server.UPDATE_ATTRIBUTES)). packet(new PacketContainer(PacketType.Play.Server.UPDATE_ATTRIBUTES)).
modifiers(Lists.newArrayList(constantModifier, doubleModifier)). modifiers(Lists.newArrayList(constantModifier, doubleModifier)).
build(); build();
} }