Renamed Silver to Gray, fixed colors sometimes being inaccurate #310
This commit is contained in:
		| @@ -1,35 +1,87 @@ | ||||
| package me.libraryaddict.disguise.disguisetypes; | ||||
|  | ||||
| public enum AnimalColor | ||||
| { | ||||
|     BLACK(15), BLUE(11), BROWN(12), CYAN(9), GRAY(7), GREEN(13), LIGHT_BLUE(3), LIME(5), MAGENTA(2), ORANGE(1), PINK(6), PURPLE( | ||||
|             10), RED(14), SILVER(8), WHITE(0), YELLOW(4); | ||||
| import org.bukkit.DyeColor; | ||||
| import org.bukkit.Material; | ||||
|  | ||||
|     public static AnimalColor getColor(int nmsId) | ||||
|     { | ||||
|         for (AnimalColor color : values()) | ||||
|         { | ||||
|             if (color.getId() == nmsId) | ||||
|             { | ||||
|                 return color; | ||||
| public enum AnimalColor { | ||||
|     BLACK(DyeColor.BLACK, Material.INK_SAC), | ||||
|     BLUE(DyeColor.BLUE, Material.LAPIS_LAZULI), | ||||
|     BROWN(DyeColor.BROWN, Material.COCOA_BEANS), | ||||
|     CYAN(DyeColor.CYAN, Material.CYAN_DYE), | ||||
|     GRAY(DyeColor.GRAY, Material.GRAY_DYE), | ||||
|     GREEN(DyeColor.GREEN, Material.CACTUS_GREEN), | ||||
|     LIGHT_BLUE(DyeColor.LIGHT_BLUE, Material.LIGHT_BLUE_DYE), | ||||
|     LIME(DyeColor.LIME, Material.LIME_DYE), | ||||
|     MAGENTA(DyeColor.MAGENTA, Material.MAGENTA_DYE), | ||||
|     ORANGE(DyeColor.ORANGE, Material.ORANGE_DYE), | ||||
|     PINK(DyeColor.PINK, Material.PINK_DYE), | ||||
|     PURPLE(DyeColor.PURPLE, Material.PURPLE_DYE), | ||||
|     RED(DyeColor.RED, Material.ROSE_RED), | ||||
|     LIGHT_GRAY(DyeColor.LIGHT_GRAY, Material.LIGHT_GRAY_DYE), | ||||
|     WHITE(DyeColor.WHITE, Material.BONE_MEAL), | ||||
|     YELLOW(DyeColor.YELLOW, Material.DANDELION_YELLOW); | ||||
|  | ||||
|     public static AnimalColor getColorByWool(int woolId) { | ||||
|         for (AnimalColor color : values()) { | ||||
|             if (woolId != color.getDyeColor().getWoolData()) { | ||||
|                 continue; | ||||
|             } | ||||
|  | ||||
|             return color; | ||||
|         } | ||||
|  | ||||
|         return null; | ||||
|     } | ||||
|  | ||||
|     private int value; | ||||
|     public static AnimalColor getColorByMaterial(Material material) { | ||||
|         for (AnimalColor color : values()) { | ||||
|             if (color.getDyeMaterial() != material) { | ||||
|                 continue; | ||||
|             } | ||||
|  | ||||
|     AnimalColor(int newValue) | ||||
|     { | ||||
|         value = newValue; | ||||
|             return color; | ||||
|         } | ||||
|  | ||||
|         return null; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * The color ID as defined by nms internals. | ||||
|      */ | ||||
|     public int getId() | ||||
|     { | ||||
|         return value; | ||||
|     public static AnimalColor getColorByDye(int dyeId) { | ||||
|         for (AnimalColor color : values()) { | ||||
|             if (dyeId != color.getDyeColor().getDyeData()) { | ||||
|                 continue; | ||||
|             } | ||||
|  | ||||
|             return color; | ||||
|         } | ||||
|  | ||||
|         return null; | ||||
|     } | ||||
|  | ||||
|     public static AnimalColor getColor(DyeColor dyeColor) { | ||||
|         for (AnimalColor color : values()) { | ||||
|             if (dyeColor != color.getDyeColor()) { | ||||
|                 continue; | ||||
|             } | ||||
|  | ||||
|             return color; | ||||
|         } | ||||
|  | ||||
|         return null; | ||||
|     } | ||||
|  | ||||
|     private DyeColor dyeColor; | ||||
|     private Material material; | ||||
|  | ||||
|     AnimalColor(DyeColor color, Material material) { | ||||
|         dyeColor = color; | ||||
|         this.material = material; | ||||
|     } | ||||
|  | ||||
|     public Material getDyeMaterial() { | ||||
|         return material; | ||||
|     } | ||||
|  | ||||
|     public DyeColor getDyeColor() { | ||||
|         return dyeColor; | ||||
|     } | ||||
| } | ||||
|   | ||||
| @@ -1,10 +1,10 @@ | ||||
| package me.libraryaddict.disguise.disguisetypes.watchers; | ||||
|  | ||||
| import org.bukkit.entity.Llama; | ||||
|  | ||||
| import me.libraryaddict.disguise.disguisetypes.AnimalColor; | ||||
| import me.libraryaddict.disguise.disguisetypes.Disguise; | ||||
| import me.libraryaddict.disguise.disguisetypes.MetaIndex; | ||||
| import org.bukkit.DyeColor; | ||||
| import org.bukkit.entity.Llama; | ||||
|  | ||||
| public class LlamaWatcher extends ChestedHorseWatcher { | ||||
|  | ||||
| @@ -21,13 +21,17 @@ public class LlamaWatcher extends ChestedHorseWatcher { | ||||
|         return Llama.Color.values()[getData(MetaIndex.LLAMA_COLOR)]; | ||||
|     } | ||||
|  | ||||
|     public void setCarpet(AnimalColor color) { | ||||
|         setData(MetaIndex.LLAMA_CARPET, color.getId()); | ||||
|     public void setCarpet(DyeColor dyeColor) { | ||||
|         setData(MetaIndex.LLAMA_CARPET, (int) dyeColor.getWoolData()); | ||||
|         sendData(MetaIndex.LLAMA_CARPET); | ||||
|     } | ||||
|  | ||||
|     public void setCarpet(AnimalColor color) { | ||||
|         setCarpet(color.getDyeColor()); | ||||
|     } | ||||
|  | ||||
|     public AnimalColor getCarpet() { | ||||
|         return AnimalColor.getColor(getData(MetaIndex.LLAMA_CARPET)); | ||||
|         return AnimalColor.getColorByWool(getData(MetaIndex.LLAMA_CARPET)); | ||||
|     } | ||||
|  | ||||
|     public void setStrength(int strength) { | ||||
| @@ -38,5 +42,4 @@ public class LlamaWatcher extends ChestedHorseWatcher { | ||||
|     public int getStrength() { | ||||
|         return getData(MetaIndex.LLAMA_STRENGTH); | ||||
|     } | ||||
|  | ||||
| } | ||||
|   | ||||
| @@ -1,10 +1,9 @@ | ||||
| package me.libraryaddict.disguise.disguisetypes.watchers; | ||||
|  | ||||
| import org.bukkit.DyeColor; | ||||
|  | ||||
| import me.libraryaddict.disguise.disguisetypes.AnimalColor; | ||||
| import me.libraryaddict.disguise.disguisetypes.Disguise; | ||||
| import me.libraryaddict.disguise.disguisetypes.MetaIndex; | ||||
| import org.bukkit.DyeColor; | ||||
|  | ||||
| public class SheepWatcher extends AgeableWatcher { | ||||
|  | ||||
| @@ -13,7 +12,7 @@ public class SheepWatcher extends AgeableWatcher { | ||||
|     } | ||||
|  | ||||
|     public AnimalColor getColor() { | ||||
|         return AnimalColor.getColor(((int) getData(MetaIndex.SHEEP_WOOL) & 15)); | ||||
|         return AnimalColor.getColorByWool(((int) getData(MetaIndex.SHEEP_WOOL) & 15)); | ||||
|     } | ||||
|  | ||||
|     public boolean isSheared() { | ||||
| @@ -21,7 +20,7 @@ public class SheepWatcher extends AgeableWatcher { | ||||
|     } | ||||
|  | ||||
|     public void setColor(AnimalColor color) { | ||||
|         setColor(DyeColor.getByWoolData((byte) color.getId())); | ||||
|         setColor(color.getDyeColor()); | ||||
|     } | ||||
|  | ||||
|     public void setColor(DyeColor color) { | ||||
|   | ||||
| @@ -52,7 +52,11 @@ public class ShulkerWatcher extends InsentientWatcher { | ||||
|     } | ||||
|  | ||||
|     public void setColor(AnimalColor color) { | ||||
|         setData(MetaIndex.SHULKER_COLOR, (byte) color.getId()); | ||||
|         setData(MetaIndex.SHULKER_COLOR, color.getDyeColor().getWoolData()); | ||||
|         sendData(MetaIndex.SHULKER_COLOR); | ||||
|     } | ||||
|  | ||||
|     public AnimalColor getColor() { | ||||
|         return AnimalColor.getColorByWool(getData(MetaIndex.SHULKER_COLOR)); | ||||
|     } | ||||
| } | ||||
|   | ||||
| @@ -1,22 +1,18 @@ | ||||
| package me.libraryaddict.disguise.disguisetypes.watchers; | ||||
|  | ||||
| import org.bukkit.DyeColor; | ||||
|  | ||||
| import me.libraryaddict.disguise.disguisetypes.AnimalColor; | ||||
| import me.libraryaddict.disguise.disguisetypes.Disguise; | ||||
| import me.libraryaddict.disguise.disguisetypes.MetaIndex; | ||||
| import org.bukkit.DyeColor; | ||||
|  | ||||
| public class WolfWatcher extends TameableWatcher | ||||
| { | ||||
| public class WolfWatcher extends TameableWatcher { | ||||
|  | ||||
|     public WolfWatcher(Disguise disguise) | ||||
|     { | ||||
|     public WolfWatcher(Disguise disguise) { | ||||
|         super(disguise); | ||||
|     } | ||||
|  | ||||
|     public AnimalColor getCollarColor() | ||||
|     { | ||||
|         return AnimalColor.getColor(getData(MetaIndex.WOLF_COLLAR)); | ||||
|     public AnimalColor getCollarColor() { | ||||
|         return AnimalColor.getColorByWool(getData(MetaIndex.WOLF_COLLAR)); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
| @@ -24,9 +20,8 @@ public class WolfWatcher extends TameableWatcher | ||||
|      * | ||||
|      * @return | ||||
|      */ | ||||
|     public float getDamageTaken() | ||||
|     { | ||||
|         return (float) getData(MetaIndex.WOLF_DAMAGE); | ||||
|     public float getDamageTaken() { | ||||
|         return getData(MetaIndex.WOLF_DAMAGE); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
| @@ -34,52 +29,42 @@ public class WolfWatcher extends TameableWatcher | ||||
|      * | ||||
|      * @param damage | ||||
|      */ | ||||
|     public void setDamageTaken(float damage) | ||||
|     { | ||||
|     public void setDamageTaken(float damage) { | ||||
|         setData(MetaIndex.WOLF_DAMAGE, damage); | ||||
|         sendData(MetaIndex.WOLF_DAMAGE); | ||||
|     } | ||||
|  | ||||
|     public boolean isBegging() | ||||
|     { | ||||
|         return (boolean) getData(MetaIndex.WOLF_BEGGING); | ||||
|     public boolean isBegging() { | ||||
|         return getData(MetaIndex.WOLF_BEGGING); | ||||
|     } | ||||
|  | ||||
|     public void setBegging(boolean begging) | ||||
|     { | ||||
|     public void setBegging(boolean begging) { | ||||
|         setData(MetaIndex.WOLF_BEGGING, begging); | ||||
|         sendData(MetaIndex.WOLF_BEGGING); | ||||
|     } | ||||
|  | ||||
|     public boolean isAngry() | ||||
|     { | ||||
|     public boolean isAngry() { | ||||
|         return isTameableFlag(2); | ||||
|     } | ||||
|  | ||||
|     public void setAngry(boolean angry) | ||||
|     { | ||||
|     public void setAngry(boolean angry) { | ||||
|         setTameableFlag(2, angry); | ||||
|     } | ||||
|  | ||||
|     public void setCollarColor(AnimalColor color) | ||||
|     { | ||||
|         setCollarColor(DyeColor.getByWoolData((byte) color.getId())); | ||||
|     public void setCollarColor(AnimalColor color) { | ||||
|         setCollarColor(color.getDyeColor()); | ||||
|     } | ||||
|  | ||||
|     public void setCollarColor(DyeColor newColor) | ||||
|     { | ||||
|         if (!isTamed()) | ||||
|         { | ||||
|     public void setCollarColor(DyeColor newColor) { | ||||
|         if (!isTamed()) { | ||||
|             setTamed(true); | ||||
|         } | ||||
|  | ||||
|         if (newColor.getWoolData() == getCollarColor().getId()) | ||||
|         { | ||||
|         if (newColor == getCollarColor().getDyeColor()) { | ||||
|             return; | ||||
|         } | ||||
|  | ||||
|         setData(MetaIndex.WOLF_COLLAR, (int) newColor.getDyeData()); | ||||
|         setData(MetaIndex.WOLF_COLLAR, (int) newColor.getWoolData()); | ||||
|         sendData(MetaIndex.WOLF_COLLAR); | ||||
|     } | ||||
|  | ||||
| } | ||||
|   | ||||
| @@ -13,8 +13,6 @@ import me.libraryaddict.disguise.disguisetypes.Disguise; | ||||
| import me.libraryaddict.disguise.disguisetypes.DisguiseType; | ||||
| import me.libraryaddict.disguise.disguisetypes.watchers.SheepWatcher; | ||||
| import me.libraryaddict.disguise.disguisetypes.watchers.WolfWatcher; | ||||
| import me.libraryaddict.disguise.utilities.DisguiseUtilities; | ||||
| import org.bukkit.Material; | ||||
| import org.bukkit.entity.*; | ||||
| import org.bukkit.inventory.ItemStack; | ||||
|  | ||||
| @@ -45,16 +43,22 @@ public class PacketListenerClientInteract extends PacketAdapter { | ||||
|  | ||||
|             for (ItemStack item : new ItemStack[]{observer.getInventory().getItemInMainHand(), | ||||
|                     observer.getInventory().getItemInOffHand()}) { | ||||
|                 if (item == null || item.getType() != Material.INK_SAC) | ||||
|                 if (item == null) { | ||||
|                     continue; | ||||
|                 } | ||||
|  | ||||
|                 AnimalColor color = AnimalColor.getColorByMaterial(item.getType()); | ||||
|  | ||||
|                 if (color == null) { | ||||
|                     continue; | ||||
|                 } | ||||
|  | ||||
|                 Disguise disguise = DisguiseAPI.getDisguise(observer, entity); | ||||
|  | ||||
|                 if (disguise == null || | ||||
|                         (disguise.getType() != DisguiseType.SHEEP && disguise.getType() != DisguiseType.WOLF)) | ||||
|                         (disguise.getType() != DisguiseType.SHEEP && disguise.getType() != DisguiseType.WOLF)) { | ||||
|                     continue; | ||||
|  | ||||
|                 AnimalColor color = AnimalColor.getColor(item.getDurability()); | ||||
|                 } | ||||
|  | ||||
|                 if (disguise.getType() == DisguiseType.SHEEP) { | ||||
|                     SheepWatcher watcher = (SheepWatcher) disguise.getWatcher(); | ||||
|   | ||||
		Reference in New Issue
	
	Block a user