Add support for spawn_egg durability value in Minecraft 1.11.

This commit is contained in:
Ali Moghnieh 2016-12-02 17:02:04 +00:00
parent c919eba206
commit 5fda1d018b
No known key found for this signature in database
GPG Key ID: F09D3A1BAF2E6D70
2 changed files with 15 additions and 2 deletions

View File

@ -21,6 +21,7 @@ public class ReflUtil {
public static final NMSVersion V1_8_R3 = NMSVersion.fromString("v1_8_R3");
public static final NMSVersion V1_9_R1 = NMSVersion.fromString("v1_9_R1");
public static final NMSVersion V1_10_R1 = NMSVersion.fromString("v1_10_R1");
public static final NMSVersion V1_11_R1 = NMSVersion.fromString("v1_11_R1");
private static NMSVersion nmsVersionObject;
private static String nmsVersion;

View File

@ -16,6 +16,8 @@
*******************************************************************************/
package net.ess3.nms.refl;
import net.ess3.nms.refl.ReflUtil.NMSVersion;
import org.bukkit.Material;
import org.bukkit.entity.EntityType;
import org.bukkit.inventory.ItemStack;
@ -93,7 +95,13 @@ public class SpawnEggRefl {
}
Object id = NBTTagCompoundConstructor.newInstance();
Method tagSetString = ReflUtil.getMethodCached(NBTTagCompoundClass, "setString", String.class, String.class);
tagSetString.invoke(id, "id", type.getName());
String idString = type.getName();
if (ReflUtil.getNmsVersionObject().isHigherThanOrEqualTo(ReflUtil.V1_11_R1)) {
// 1.11 requires domain prefix of minecraft.
idString = "minecraft:" + idString;
}
tagSetString.invoke(id, "id", idString);
Method tagSetTag = ReflUtil.getMethodCached(NBTTagCompoundClass, "set", String.class, NBTTagCompoundClass.getSuperclass());
tagSetTag.invoke(tagCompound, "EntityTag", id);
@ -128,8 +136,12 @@ public class SpawnEggRefl {
Object entityTag = tagGetCompound.invoke(tagCompound, "EntityTag");
Method tagGetString = ReflUtil.getMethodCached(entityTag.getClass(), "getString", String.class);
String idString = (String) tagGetString.invoke(entityTag, "id");
if (ReflUtil.getNmsVersionObject().isHigherThanOrEqualTo(ReflUtil.V1_11_R1)) {
idString = idString.split("minecraft:")[1];
}
@SuppressWarnings("deprecation")
EntityType type = EntityType.fromName((String) tagGetString.invoke(entityTag, "id"));
EntityType type = EntityType.fromName(idString);
if (type != null) {
return new SpawnEggRefl(type);
} else {