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