From dedc04355831732c73fa30166424641414cb9877 Mon Sep 17 00:00:00 2001 From: libraryaddict Date: Tue, 28 Jun 2016 15:01:17 +1200 Subject: [PATCH] Fix enderman disguise --- .../disguise/disguisetypes/FlagType.java | 5 +-- .../watchers/EndermanWatcher.java | 35 ++++++++++++++----- 2 files changed, 29 insertions(+), 11 deletions(-) diff --git a/src/me/libraryaddict/disguise/disguisetypes/FlagType.java b/src/me/libraryaddict/disguise/disguisetypes/FlagType.java index 33269e2c..42dc104a 100644 --- a/src/me/libraryaddict/disguise/disguisetypes/FlagType.java +++ b/src/me/libraryaddict/disguise/disguisetypes/FlagType.java @@ -13,6 +13,7 @@ import org.bukkit.inventory.ItemStack; import org.bukkit.util.Vector; import com.comphenix.protocol.wrappers.BlockPosition; +import com.comphenix.protocol.wrappers.WrappedBlockData; import com.google.common.base.Optional; import me.libraryaddict.disguise.disguisetypes.watchers.AgeableWatcher; @@ -128,8 +129,8 @@ public class FlagType public static FlagType ENDERMAN_AGRESSIVE = new FlagType(EndermanWatcher.class, 1, false); - public static FlagType> ENDERMAN_ITEM = new FlagType>(EndermanWatcher.class, 0, - Optional.of(1)); + public static FlagType> ENDERMAN_ITEM = new FlagType>( + EndermanWatcher.class, 0, Optional. absent()); public static FlagType ENTITY_AIR_TICKS = new FlagType(FlagWatcher.class, 1, 0); diff --git a/src/me/libraryaddict/disguise/disguisetypes/watchers/EndermanWatcher.java b/src/me/libraryaddict/disguise/disguisetypes/watchers/EndermanWatcher.java index b1d3f47d..ecb0d84b 100644 --- a/src/me/libraryaddict/disguise/disguisetypes/watchers/EndermanWatcher.java +++ b/src/me/libraryaddict/disguise/disguisetypes/watchers/EndermanWatcher.java @@ -1,13 +1,13 @@ package me.libraryaddict.disguise.disguisetypes.watchers; -import org.apache.commons.lang3.tuple.Pair; +import org.bukkit.Material; import org.bukkit.inventory.ItemStack; +import com.comphenix.protocol.wrappers.WrappedBlockData; import com.google.common.base.Optional; import me.libraryaddict.disguise.disguisetypes.Disguise; import me.libraryaddict.disguise.disguisetypes.FlagType; -import me.libraryaddict.disguise.utilities.ReflectionManager; public class EndermanWatcher extends InsentientWatcher { @@ -20,13 +20,13 @@ public class EndermanWatcher extends InsentientWatcher @Override public ItemStack getItemInMainHand() { - Optional value = getValue(FlagType.ENDERMAN_ITEM); + Optional value = getValue(FlagType.ENDERMAN_ITEM); if (value.isPresent()) { - Pair pair = ReflectionManager.getFromCombinedId(value.get()); - int id = pair.getLeft(); - int data = pair.getRight(); + WrappedBlockData pair = value.get(); + Material id = pair.getType(); + int data = pair.getData(); return new ItemStack(id, 1, (short) data); } @@ -42,16 +42,33 @@ public class EndermanWatcher extends InsentientWatcher setItemInMainHand(itemstack.getTypeId(), itemstack.getDurability()); } + @Deprecated public void setItemInMainHand(int typeId) { setItemInMainHand(typeId, 0); } + public void setItemInMainHand(Material type) + { + setItemInMainHand(type, 0); + } + + public void setItemInMainHand(Material type, int data) + { + Optional optional; + + if (type == null) + optional = Optional. absent(); + else + optional = Optional. of(WrappedBlockData.createData(type, data)); + + setValue(FlagType.ENDERMAN_ITEM, optional); + } + + @Deprecated public void setItemInMainHand(int typeId, int data) { - int combined = ReflectionManager.getCombinedId(typeId, data); - - setValue(FlagType.ENDERMAN_ITEM, Optional.of(combined)); + setItemInMainHand(Material.getMaterial(typeId), data); } public boolean isAggressive()