From 23303952b45a295c238fd4ec21b9136aff611c78 Mon Sep 17 00:00:00 2001 From: riking Date: Wed, 4 Jun 2014 08:33:30 -0700 Subject: [PATCH 1/9] Eh, let's just remove the shift by 0. Also doc the method --- .../disguise/disguisetypes/watchers/LivingWatcher.java | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/me/libraryaddict/disguise/disguisetypes/watchers/LivingWatcher.java b/src/me/libraryaddict/disguise/disguisetypes/watchers/LivingWatcher.java index 12e6b5f8..073f43d2 100644 --- a/src/me/libraryaddict/disguise/disguisetypes/watchers/LivingWatcher.java +++ b/src/me/libraryaddict/disguise/disguisetypes/watchers/LivingWatcher.java @@ -85,6 +85,11 @@ public class LivingWatcher extends FlagWatcher { return (Byte) getValue(8, (byte) 0) == 1; } + /** + * This method constructs the insane potion effect format used by Vanilla. + * + * @return potion value to send in packet + */ private int getPotions() { int m = 3694022; @@ -101,7 +106,7 @@ public class LivingWatcher extends FlagWatcher { int n = (Integer) potionNo.invoke(list[localMobEffect]); f1 += (n >> 16 & 0xFF) / 255.0F; f2 += (n >> 8 & 0xFF) / 255.0F; - f3 += (n >> 0 & 0xFF) / 255.0F; + f3 += (n & 0xFF) / 255.0F; f4 += 1.0F; } } catch (Exception ex) { From bb0ac727bfef71a60f25a5e3fb2c958d953ae287 Mon Sep 17 00:00:00 2001 From: riking Date: Wed, 4 Jun 2014 09:17:47 -0700 Subject: [PATCH 2/9] Remove more redundant actions --- src/me/libraryaddict/disguise/disguisetypes/FlagWatcher.java | 4 ++-- .../disguise/disguisetypes/watchers/MinecartWatcher.java | 4 ++-- src/me/libraryaddict/disguise/utilities/PacketsManager.java | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/me/libraryaddict/disguise/disguisetypes/FlagWatcher.java b/src/me/libraryaddict/disguise/disguisetypes/FlagWatcher.java index b24f2b1b..1cc2c388 100644 --- a/src/me/libraryaddict/disguise/disguisetypes/FlagWatcher.java +++ b/src/me/libraryaddict/disguise/disguisetypes/FlagWatcher.java @@ -55,7 +55,7 @@ public class FlagWatcher { } private byte addEntityAnimations(byte originalValue, byte entityValue) { - byte valueByte = (Byte) originalValue; + byte valueByte = originalValue; for (int i = 0; i < 6; i++) { if ((entityValue & 1 << i) != 0 && !modifiedEntityAnimations.contains(i)) { valueByte = (byte) (valueByte | 1 << i); @@ -66,7 +66,7 @@ public class FlagWatcher { } public FlagWatcher clone(Disguise owningDisguise) { - FlagWatcher cloned = null; + FlagWatcher cloned; try { cloned = getClass().getConstructor(Disguise.class).newInstance(getDisguise()); } catch (Exception e) { diff --git a/src/me/libraryaddict/disguise/disguisetypes/watchers/MinecartWatcher.java b/src/me/libraryaddict/disguise/disguisetypes/watchers/MinecartWatcher.java index e8622f3d..eeab69cd 100644 --- a/src/me/libraryaddict/disguise/disguisetypes/watchers/MinecartWatcher.java +++ b/src/me/libraryaddict/disguise/disguisetypes/watchers/MinecartWatcher.java @@ -12,7 +12,7 @@ public class MinecartWatcher extends FlagWatcher { } public ItemStack getBlockInCart() { - int id = (Integer) getValue(20, 0) & '\uffff'; + int id = (Integer) getValue(20, 0) & 0xffff; int data = (Integer) getValue(20, 0) >> 16; return new ItemStack(id, 1, (short) data); } @@ -32,7 +32,7 @@ public class MinecartWatcher extends FlagWatcher { public void setBlockInCart(ItemStack item) { int id = item.getTypeId(); int data = item.getDurability(); - setValue(20, (int) (id & '\uffff' | data << 16)); + setValue(20, (int) (id & 0xffff | data << 16)); sendData(20); setViewBlockInCart(true); } diff --git a/src/me/libraryaddict/disguise/utilities/PacketsManager.java b/src/me/libraryaddict/disguise/utilities/PacketsManager.java index 6e2d7ee2..97d4b154 100644 --- a/src/me/libraryaddict/disguise/utilities/PacketsManager.java +++ b/src/me/libraryaddict/disguise/utilities/PacketsManager.java @@ -748,7 +748,7 @@ public class PacketsManager { StructureModifier mods = packet.getModifier(); mods.write(0, observer.getEntityId()); List watchableList = new ArrayList(); - byte b = (byte) (0 | 1 << 5); + byte b = (byte) 1 << 5; if (observer.isSprinting()) b = (byte) (b | 1 << 3); watchableList.add(new WrappedWatchableObject(0, b)); From 1207d70d6e9a84ad45f2b4c31c1e7014d262cf49 Mon Sep 17 00:00:00 2001 From: riking Date: Wed, 4 Jun 2014 09:18:05 -0700 Subject: [PATCH 3/9] Dedent parseDisguise() method for-loop --- .../utilities/BaseDisguiseCommand.java | 236 +++++++++--------- 1 file changed, 118 insertions(+), 118 deletions(-) diff --git a/src/me/libraryaddict/disguise/utilities/BaseDisguiseCommand.java b/src/me/libraryaddict/disguise/utilities/BaseDisguiseCommand.java index 6fb61f8e..a4866133 100644 --- a/src/me/libraryaddict/disguise/utilities/BaseDisguiseCommand.java +++ b/src/me/libraryaddict/disguise/utilities/BaseDisguiseCommand.java @@ -279,130 +279,130 @@ public abstract class BaseDisguiseCommand implements CommandExecutor { if (!method.getName().startsWith("get") && method.getName().equalsIgnoreCase(methodName) && method.getAnnotation(Deprecated.class) == null && method.getParameterTypes().length == 1) { methodToUse = method; - methodName = method.getName(); - Class[] types = method.getParameterTypes(); - if (types.length == 1) { - Class param = types[0]; - // Parse to number - if (int.class == param) { - if (isNumeric(valueString)) { - value = (int) Integer.parseInt(valueString); - } else { - throw parseToException("number", valueString, methodName); - } - // Parse to boolean - } else if (float.class == param || double.class == param) { - if (isDouble(valueString)) { - float obj = Float.parseFloat(valueString); - if (param == float.class) { - value = (float) obj; - } else if (param == int.class) { - value = (int) obj; - } else if (param == double.class) { - value = (double) obj; - } - } else { - throw parseToException("number.0", valueString, methodName); - } - // Parse to boolean - } else if (boolean.class == param) { - if (!("true".equalsIgnoreCase(valueString) || "false".equalsIgnoreCase(valueString))) - throw parseToException("true/false", valueString, methodName); - value = (boolean) "true".equalsIgnoreCase(valueString); - // Parse to string - } else if (param == String.class) { - value = ChatColor.translateAlternateColorCodes('&', valueString); - // Parse to animal color - } else if (param == AnimalColor.class) { - try { - value = AnimalColor.valueOf(valueString.toUpperCase()); - } catch (Exception ex) { - throw parseToException("animal color", valueString, methodName); - } - // Parse to itemstack - } else if (param == ItemStack.class) { - try { - value = parseToItemstack(valueString); - } catch (Exception ex) { - throw new Exception(String.format(ex.getMessage(), methodName)); - } - // Parse to itemstack array - } else if (param == ItemStack[].class) { - ItemStack[] items = new ItemStack[4]; - String[] split = valueString.split(","); - if (split.length == 4) { - for (int a = 0; a < 4; a++) { - try { - ItemStack item = parseToItemstack(split[a]); - items[a] = item; - } catch (Exception ex) { - throw parseToException("item ID,ID,ID,ID" + ChatColor.RED + " or " + ChatColor.GREEN - + "ID:Data,ID:Data,ID:Data,ID:Data combo", valueString, methodName); - } - } - } else { - throw parseToException("item ID,ID,ID,ID" + ChatColor.RED + " or " + ChatColor.GREEN - + "ID:Data,ID:Data,ID:Data,ID:Data combo", valueString, methodName); - } - value = items; - // Parse to horse color - } else if (param.getSimpleName().equals("Color")) { - try { - value = param.getMethod("valueOf", String.class).invoke(null, valueString.toUpperCase()); - } catch (Exception ex) { - throw parseToException("a horse color", valueString, methodName); - } - // Parse to horse style - } else if (param.getSimpleName().equals("Style")) { - try { - value = param.getMethod("valueOf", String.class).invoke(null, valueString.toUpperCase()); - } catch (Exception ex) { - throw parseToException("a horse style", valueString, methodName); - } - // Parse to villager profession - } else if (param.getSimpleName().equals("Profession")) { - try { - value = param.getMethod("valueOf", String.class).invoke(null, valueString.toUpperCase()); - } catch (Exception ex) { - throw parseToException("a villager profession", valueString, methodName); - } - // Parse to ocelot type - } else if (param.getSimpleName().equals("Art")) { - try { - value = param.getMethod("valueOf", String.class).invoke(null, valueString.toUpperCase()); - } catch (Exception ex) { - ex.printStackTrace(); - throw parseToException("a painting art", valueString, methodName); - } - // Parse to ocelot type - } else if (param.getSimpleName().equals("Type")) { - try { - value = param.getMethod("valueOf", String.class).invoke(null, valueString.toUpperCase()); - } catch (Exception ex) { - throw parseToException("a ocelot type", valueString, methodName); - } - - // Parse to potion effect - } else if (param == PotionEffectType.class) { - try { - PotionEffectType potionType = PotionEffectType.getByName(valueString.toUpperCase()); - if (potionType == null && isNumeric(valueString)) { - potionType = PotionEffectType.getById(Integer.parseInt(valueString)); - } - if (potionType == null) - throw new Exception(); - value = potionType; - } catch (Exception ex) { - throw parseToException("a potioneffect type", valueString, methodName); - } - } - } break; } } if (methodToUse == null) { throw new Exception(ChatColor.RED + "Cannot find the option " + methodName); } + methodName = methodToUse.getName(); + Class[] types = methodToUse.getParameterTypes(); + if (types.length == 1) { + Class param = types[0]; + // Parse to number + if (int.class == param) { + if (isNumeric(valueString)) { + value = (int) Integer.parseInt(valueString); + } else { + throw parseToException("number", valueString, methodName); + } + // Parse to boolean + } else if (float.class == param || double.class == param) { + if (isDouble(valueString)) { + float obj = Float.parseFloat(valueString); + if (param == float.class) { + value = (float) obj; + } else if (param == int.class) { + value = (int) obj; + } else if (param == double.class) { + value = (double) obj; + } + } else { + throw parseToException("number.0", valueString, methodName); + } + // Parse to boolean + } else if (boolean.class == param) { + if (!("true".equalsIgnoreCase(valueString) || "false".equalsIgnoreCase(valueString))) + throw parseToException("true/false", valueString, methodName); + value = (boolean) "true".equalsIgnoreCase(valueString); + // Parse to string + } else if (param == String.class) { + value = ChatColor.translateAlternateColorCodes('&', valueString); + // Parse to animal color + } else if (param == AnimalColor.class) { + try { + value = AnimalColor.valueOf(valueString.toUpperCase()); + } catch (Exception ex) { + throw parseToException("animal color", valueString, methodName); + } + // Parse to itemstack + } else if (param == ItemStack.class) { + try { + value = parseToItemstack(valueString); + } catch (Exception ex) { + throw new Exception(String.format(ex.getMessage(), methodName)); + } + // Parse to itemstack array + } else if (param == ItemStack[].class) { + ItemStack[] items = new ItemStack[4]; + String[] split = valueString.split(","); + if (split.length == 4) { + for (int a = 0; a < 4; a++) { + try { + ItemStack item = parseToItemstack(split[a]); + items[a] = item; + } catch (Exception ex) { + throw parseToException("item ID,ID,ID,ID" + ChatColor.RED + " or " + ChatColor.GREEN + + "ID:Data,ID:Data,ID:Data,ID:Data combo", valueString, methodName); + } + } + } else { + throw parseToException("item ID,ID,ID,ID" + ChatColor.RED + " or " + ChatColor.GREEN + + "ID:Data,ID:Data,ID:Data,ID:Data combo", valueString, methodName); + } + value = items; + // Parse to horse color + } else if (param.getSimpleName().equals("Color")) { + try { + value = param.getMethod("valueOf", String.class).invoke(null, valueString.toUpperCase()); + } catch (Exception ex) { + throw parseToException("a horse color", valueString, methodName); + } + // Parse to horse style + } else if (param.getSimpleName().equals("Style")) { + try { + value = param.getMethod("valueOf", String.class).invoke(null, valueString.toUpperCase()); + } catch (Exception ex) { + throw parseToException("a horse style", valueString, methodName); + } + // Parse to villager profession + } else if (param.getSimpleName().equals("Profession")) { + try { + value = param.getMethod("valueOf", String.class).invoke(null, valueString.toUpperCase()); + } catch (Exception ex) { + throw parseToException("a villager profession", valueString, methodName); + } + // Parse to ocelot type + } else if (param.getSimpleName().equals("Art")) { + try { + value = param.getMethod("valueOf", String.class).invoke(null, valueString.toUpperCase()); + } catch (Exception ex) { + ex.printStackTrace(); + throw parseToException("a painting art", valueString, methodName); + } + // Parse to ocelot type + } else if (param.getSimpleName().equals("Type")) { + try { + value = param.getMethod("valueOf", String.class).invoke(null, valueString.toUpperCase()); + } catch (Exception ex) { + throw parseToException("a ocelot type", valueString, methodName); + } + + // Parse to potion effect + } else if (param == PotionEffectType.class) { + try { + PotionEffectType potionType = PotionEffectType.getByName(valueString.toUpperCase()); + if (potionType == null && isNumeric(valueString)) { + potionType = PotionEffectType.getById(Integer.parseInt(valueString)); + } + if (potionType == null) + throw new Exception(); + value = potionType; + } catch (Exception ex) { + throw parseToException("a potioneffect type", valueString, methodName); + } + } + } if (!usedOptions.contains(methodName.toLowerCase())) { usedOptions.add(methodName.toLowerCase()); } From 983026a89805c2920c2490f58bf4aaa611ae9689 Mon Sep 17 00:00:00 2001 From: riking Date: Wed, 4 Jun 2014 09:27:04 -0700 Subject: [PATCH 4/9] Make a callValueOf() method to reduce code repetition --- .../utilities/BaseDisguiseCommand.java | 73 ++++++++----------- 1 file changed, 29 insertions(+), 44 deletions(-) diff --git a/src/me/libraryaddict/disguise/utilities/BaseDisguiseCommand.java b/src/me/libraryaddict/disguise/utilities/BaseDisguiseCommand.java index a4866133..dfa80f19 100644 --- a/src/me/libraryaddict/disguise/utilities/BaseDisguiseCommand.java +++ b/src/me/libraryaddict/disguise/utilities/BaseDisguiseCommand.java @@ -289,58 +289,55 @@ public abstract class BaseDisguiseCommand implements CommandExecutor { Class[] types = methodToUse.getParameterTypes(); if (types.length == 1) { Class param = types[0]; - // Parse to number if (int.class == param) { + // Parse to integer if (isNumeric(valueString)) { value = (int) Integer.parseInt(valueString); } else { throw parseToException("number", valueString, methodName); } - // Parse to boolean } else if (float.class == param || double.class == param) { + // Parse to number if (isDouble(valueString)) { float obj = Float.parseFloat(valueString); if (param == float.class) { value = (float) obj; - } else if (param == int.class) { - value = (int) obj; } else if (param == double.class) { value = (double) obj; } } else { throw parseToException("number.0", valueString, methodName); } - // Parse to boolean } else if (boolean.class == param) { + // Parse to boolean if (!("true".equalsIgnoreCase(valueString) || "false".equalsIgnoreCase(valueString))) throw parseToException("true/false", valueString, methodName); value = (boolean) "true".equalsIgnoreCase(valueString); - // Parse to string } else if (param == String.class) { + // Parse to string value = ChatColor.translateAlternateColorCodes('&', valueString); - // Parse to animal color } else if (param == AnimalColor.class) { + // Parse to animal color try { value = AnimalColor.valueOf(valueString.toUpperCase()); } catch (Exception ex) { throw parseToException("animal color", valueString, methodName); } - // Parse to itemstack } else if (param == ItemStack.class) { + // Parse to itemstack try { value = parseToItemstack(valueString); } catch (Exception ex) { throw new Exception(String.format(ex.getMessage(), methodName)); } - // Parse to itemstack array } else if (param == ItemStack[].class) { + // Parse to itemstack array ItemStack[] items = new ItemStack[4]; String[] split = valueString.split(","); if (split.length == 4) { for (int a = 0; a < 4; a++) { try { - ItemStack item = parseToItemstack(split[a]); - items[a] = item; + items[a] = parseToItemstack(split[a]); } catch (Exception ex) { throw parseToException("item ID,ID,ID,ID" + ChatColor.RED + " or " + ChatColor.GREEN + "ID:Data,ID:Data,ID:Data,ID:Data combo", valueString, methodName); @@ -351,45 +348,23 @@ public abstract class BaseDisguiseCommand implements CommandExecutor { + "ID:Data,ID:Data,ID:Data,ID:Data combo", valueString, methodName); } value = items; - // Parse to horse color } else if (param.getSimpleName().equals("Color")) { - try { - value = param.getMethod("valueOf", String.class).invoke(null, valueString.toUpperCase()); - } catch (Exception ex) { - throw parseToException("a horse color", valueString, methodName); - } - // Parse to horse style + // Parse to horse color + value = callValueOf(param, valueString, methodName, "a horse color"); } else if (param.getSimpleName().equals("Style")) { - try { - value = param.getMethod("valueOf", String.class).invoke(null, valueString.toUpperCase()); - } catch (Exception ex) { - throw parseToException("a horse style", valueString, methodName); - } - // Parse to villager profession + // Parse to horse style + value = callValueOf(param, valueString, methodName, "a horse style"); } else if (param.getSimpleName().equals("Profession")) { - try { - value = param.getMethod("valueOf", String.class).invoke(null, valueString.toUpperCase()); - } catch (Exception ex) { - throw parseToException("a villager profession", valueString, methodName); - } - // Parse to ocelot type + // Parse to villager profession + value = callValueOf(param, valueString, methodName, "a villager profession"); } else if (param.getSimpleName().equals("Art")) { - try { - value = param.getMethod("valueOf", String.class).invoke(null, valueString.toUpperCase()); - } catch (Exception ex) { - ex.printStackTrace(); - throw parseToException("a painting art", valueString, methodName); - } - // Parse to ocelot type + // Parse to art type + value = callValueOf(param, valueString, methodName, "a painting art"); } else if (param.getSimpleName().equals("Type")) { - try { - value = param.getMethod("valueOf", String.class).invoke(null, valueString.toUpperCase()); - } catch (Exception ex) { - throw parseToException("a ocelot type", valueString, methodName); - } - - // Parse to potion effect + // Parse to ocelot type + value = callValueOf(param, valueString, methodName, "a ocelot type"); } else if (param == PotionEffectType.class) { + // Parse to potion effect try { PotionEffectType potionType = PotionEffectType.getByName(valueString.toUpperCase()); if (potionType == null && isNumeric(valueString)) { @@ -413,6 +388,16 @@ public abstract class BaseDisguiseCommand implements CommandExecutor { return disguise; } + private Object callValueOf(Class param, String valueString, String methodName, String description) throws Exception { + Object value; + try { + value = param.getMethod("valueOf", String.class).invoke(null, valueString.toUpperCase()); + } catch (Exception ex) { + throw parseToException(description, valueString, methodName); + } + return value; + } + private void doCheck(HashSet> optionPermissions, ArrayList usedOptions) throws Exception { if (!optionPermissions.isEmpty()) { boolean hasPermission = true; From 0d8dce4538de13b728c36abda9627a8ef57a234b Mon Sep 17 00:00:00 2001 From: riking Date: Wed, 4 Jun 2014 09:43:29 -0700 Subject: [PATCH 5/9] Prefer storing the methods instead of getting them every time --- .../disguise/disguisetypes/DisguiseType.java | 25 ++++++++++++++----- 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/src/me/libraryaddict/disguise/disguisetypes/DisguiseType.java b/src/me/libraryaddict/disguise/disguisetypes/DisguiseType.java index 9dcb6f7f..0949ace1 100644 --- a/src/me/libraryaddict/disguise/disguisetypes/DisguiseType.java +++ b/src/me/libraryaddict/disguise/disguisetypes/DisguiseType.java @@ -133,6 +133,8 @@ public enum DisguiseType { ZOMBIE_VILLAGER; + private static Method isVillager, getVariant, getSkeletonType; + static { // We set the entity type in this so that we can safely ignore disguisetypes which don't exist in older versions of MC. // Without erroring up everything. @@ -167,6 +169,20 @@ public enum DisguiseType { // This version of craftbukkit doesn't have the disguise. } } + try { + isVillager = org.bukkit.entity.Zombie.class.getMethod("isVillager"); + } catch (Throwable ignored) { + // This version doesn't have villagers + } + try { + getVariant = org.bukkit.entity.Horse.class.getMethod("getVariant"); + } catch (Throwable ignored) { + // This version doesn't have horses + } + try { + getSkeletonType = org.bukkit.entity.Skeleton.class.getMethod("getSkeletonType"); + } catch (Throwable ignored) { + } } public static DisguiseType getType(Entity entity) { @@ -174,18 +190,16 @@ public enum DisguiseType { switch (disguiseType) { case ZOMBIE: try { - Method isVillager = entity.getClass().getMethod("isVillager"); if ((Boolean) isVillager.invoke(entity)) { disguiseType = DisguiseType.ZOMBIE_VILLAGER; } - } catch (NoSuchMethodException ex) { } catch (Exception ex) { ex.printStackTrace(); } break; case HORSE: try { - Object variant = entity.getClass().getMethod("getVariant").invoke(entity); + Object variant = getVariant.invoke(entity); disguiseType = DisguiseType.valueOf(((Enum) variant).name()); } catch (Exception ex) { ex.printStackTrace(); @@ -193,11 +207,10 @@ public enum DisguiseType { break; case SKELETON: try { - Object type = entity.getClass().getMethod("getSkeletonType").invoke(entity); - if (((Enum) type).name().equals("WITHER")) { + Object type = getSkeletonType.invoke(entity); + if (type == org.bukkit.entity.Skeleton.SkeletonType.WITHER) { disguiseType = DisguiseType.WITHER_SKELETON; } - } catch (NoSuchMethodException ex) { } catch (Exception ex) { ex.printStackTrace(); } From 5a288c586e7e5aebf015955eb8fd2d9c284257d6 Mon Sep 17 00:00:00 2001 From: riking Date: Wed, 4 Jun 2014 12:10:51 -0700 Subject: [PATCH 6/9] Fix Horse's Rearing parameter --- .../disguise/disguisetypes/watchers/HorseWatcher.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/me/libraryaddict/disguise/disguisetypes/watchers/HorseWatcher.java b/src/me/libraryaddict/disguise/disguisetypes/watchers/HorseWatcher.java index effcb792..53b7738d 100644 --- a/src/me/libraryaddict/disguise/disguisetypes/watchers/HorseWatcher.java +++ b/src/me/libraryaddict/disguise/disguisetypes/watchers/HorseWatcher.java @@ -138,7 +138,7 @@ public class HorseWatcher extends AgeableWatcher { } public void setRearing(boolean rear) { - setFlag(64, true); + setFlag(64, rear); } public void setSaddled(boolean saddled) { From 2ec2cbfb1c54608a2ef0aeb629adb5e1e7072afa Mon Sep 17 00:00:00 2001 From: riking Date: Wed, 4 Jun 2014 14:35:53 -0700 Subject: [PATCH 7/9] Some help improvements - color yellow if method is specific --- .../commands/DisguiseHelpCommand.java | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/src/me/libraryaddict/disguise/commands/DisguiseHelpCommand.java b/src/me/libraryaddict/disguise/commands/DisguiseHelpCommand.java index c48efb11..9b56258b 100644 --- a/src/me/libraryaddict/disguise/commands/DisguiseHelpCommand.java +++ b/src/me/libraryaddict/disguise/commands/DisguiseHelpCommand.java @@ -5,6 +5,8 @@ import java.util.ArrayList; import java.util.Collections; import me.libraryaddict.disguise.disguisetypes.AnimalColor; import me.libraryaddict.disguise.disguisetypes.DisguiseType; +import me.libraryaddict.disguise.disguisetypes.FlagWatcher; +import me.libraryaddict.disguise.disguisetypes.watchers.LivingWatcher; import me.libraryaddict.disguise.utilities.BaseDisguiseCommand; import org.apache.commons.lang.StringUtils; @@ -161,13 +163,13 @@ public class DisguiseHelpCommand extends BaseDisguiseCommand { } else if (int.class == c) { valueType = "Number"; } else if (float.class == c || double.class == c) { - valueType = "Number.0"; + valueType = "Decimal"; } else if (AnimalColor.class == c) { valueType = "Color"; } else if (ItemStack.class == c) { - valueType = "Item ID with optional :Durability"; + valueType = "Item (id:damage)"; } else if (ItemStack[].class == c) { - valueType = "Item ID,ID,ID,ID with optional :Durability"; + valueType = "4 items (id:damage,id,...)"; } else if (c.getSimpleName().equals("Style")) { valueType = "Horse Style"; } else if (c.getSimpleName().equals("Color")) { @@ -177,10 +179,17 @@ public class DisguiseHelpCommand extends BaseDisguiseCommand { } else if (c.getSimpleName().equals("Profession")) { valueType = "Villager Profession"; } else if (PotionEffectType.class == c) { - valueType = "Potioneffect"; + valueType = "Potion effect"; } if (valueType != null) { - methods.add(ChatColor.RED + method.getName() + ChatColor.DARK_RED + "(" + ChatColor.GREEN + ChatColor methodColor = ChatColor.YELLOW; + Class declaring = method.getDeclaringClass(); + if (declaring == LivingWatcher.class) { + methodColor = ChatColor.AQUA; + } else if (declaring == FlagWatcher.class) { + methodColor = ChatColor.GRAY; + } + methods.add(methodColor + method.getName() + ChatColor.DARK_RED + "(" + ChatColor.GREEN + valueType + ChatColor.DARK_RED + ")"); } } From d645004abd3ea3d2c58b41eb40b3a87ccd3fed90 Mon Sep 17 00:00:00 2001 From: riking Date: Wed, 4 Jun 2014 14:40:00 -0700 Subject: [PATCH 8/9] Revert "Eh, let's just remove the shift by 0. Also doc the method" This reverts commit 23303952b45a295c238fd4ec21b9136aff611c78. --- .../disguise/disguisetypes/watchers/LivingWatcher.java | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/src/me/libraryaddict/disguise/disguisetypes/watchers/LivingWatcher.java b/src/me/libraryaddict/disguise/disguisetypes/watchers/LivingWatcher.java index 073f43d2..12e6b5f8 100644 --- a/src/me/libraryaddict/disguise/disguisetypes/watchers/LivingWatcher.java +++ b/src/me/libraryaddict/disguise/disguisetypes/watchers/LivingWatcher.java @@ -85,11 +85,6 @@ public class LivingWatcher extends FlagWatcher { return (Byte) getValue(8, (byte) 0) == 1; } - /** - * This method constructs the insane potion effect format used by Vanilla. - * - * @return potion value to send in packet - */ private int getPotions() { int m = 3694022; @@ -106,7 +101,7 @@ public class LivingWatcher extends FlagWatcher { int n = (Integer) potionNo.invoke(list[localMobEffect]); f1 += (n >> 16 & 0xFF) / 255.0F; f2 += (n >> 8 & 0xFF) / 255.0F; - f3 += (n & 0xFF) / 255.0F; + f3 += (n >> 0 & 0xFF) / 255.0F; f4 += 1.0F; } } catch (Exception ex) { From 3ebf54c192aa8493b0621a720d85ffeb3a3e9fa5 Mon Sep 17 00:00:00 2001 From: riking Date: Wed, 4 Jun 2014 15:16:45 -0700 Subject: [PATCH 9/9] Fix FQN in DisguiseType --- .../disguise/disguisetypes/DisguiseType.java | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/me/libraryaddict/disguise/disguisetypes/DisguiseType.java b/src/me/libraryaddict/disguise/disguisetypes/DisguiseType.java index 0949ace1..38cea936 100644 --- a/src/me/libraryaddict/disguise/disguisetypes/DisguiseType.java +++ b/src/me/libraryaddict/disguise/disguisetypes/DisguiseType.java @@ -5,6 +5,9 @@ import java.lang.reflect.Method; import org.apache.commons.lang.StringUtils; import org.bukkit.entity.Entity; import org.bukkit.entity.EntityType; +import org.bukkit.entity.Horse; +import org.bukkit.entity.Skeleton; +import org.bukkit.entity.Zombie; public enum DisguiseType { ARROW(60), @@ -170,17 +173,16 @@ public enum DisguiseType { } } try { - isVillager = org.bukkit.entity.Zombie.class.getMethod("isVillager"); + isVillager = Zombie.class.getMethod("isVillager"); } catch (Throwable ignored) { - // This version doesn't have villagers } try { - getVariant = org.bukkit.entity.Horse.class.getMethod("getVariant"); + getVariant = Horse.class.getMethod("getVariant"); } catch (Throwable ignored) { - // This version doesn't have horses + // Pre-1.6, but that isn't even supported } try { - getSkeletonType = org.bukkit.entity.Skeleton.class.getMethod("getSkeletonType"); + getSkeletonType = Skeleton.class.getMethod("getSkeletonType"); } catch (Throwable ignored) { } } @@ -208,7 +210,7 @@ public enum DisguiseType { case SKELETON: try { Object type = getSkeletonType.invoke(entity); - if (type == org.bukkit.entity.Skeleton.SkeletonType.WITHER) { + if (type == Skeleton.SkeletonType.WITHER) { disguiseType = DisguiseType.WITHER_SKELETON; } } catch (Exception ex) {