From 9be63e1cc8d430ee04badc7b0150e807fc2c4fe1 Mon Sep 17 00:00:00 2001 From: libraryaddict Date: Sat, 13 Sep 2014 21:23:06 +1200 Subject: [PATCH] Sort files and make 4 new options in the disguise class viewable with commands --- .../commands/DisguiseHelpCommand.java | 2 +- .../disguise/disguisetypes/FlagWatcher.java | 50 +++++++++---------- .../utilities/BaseDisguiseCommand.java | 20 +++++++- 3 files changed, 45 insertions(+), 27 deletions(-) diff --git a/src/me/libraryaddict/disguise/commands/DisguiseHelpCommand.java b/src/me/libraryaddict/disguise/commands/DisguiseHelpCommand.java index c6586be3..e997d0e5 100644 --- a/src/me/libraryaddict/disguise/commands/DisguiseHelpCommand.java +++ b/src/me/libraryaddict/disguise/commands/DisguiseHelpCommand.java @@ -157,7 +157,7 @@ public class DisguiseHelpCommand extends BaseDisguiseCommand { Class watcher = type.getWatcherClass(); int ignored = 0; try { - for (Method method : watcher.getMethods()) { + for (Method method : this.getDisguiseWatcherMethods(watcher)) { if (!method.getName().startsWith("get") && method.getParameterTypes().length == 1 && method.getAnnotation(Deprecated.class) == null) { if (args.length < 2 || !args[1].equalsIgnoreCase("show")) { diff --git a/src/me/libraryaddict/disguise/disguisetypes/FlagWatcher.java b/src/me/libraryaddict/disguise/disguisetypes/FlagWatcher.java index 0526a8cc..2d542a20 100644 --- a/src/me/libraryaddict/disguise/disguisetypes/FlagWatcher.java +++ b/src/me/libraryaddict/disguise/disguisetypes/FlagWatcher.java @@ -157,6 +157,10 @@ public class FlagWatcher { return armor; } + public String getCustomName() { + return (String) getValue(10, null); + } + protected TargetedDisguise getDisguise() { return disguise; } @@ -190,6 +194,10 @@ public class FlagWatcher { return watchableObjects; } + public boolean hasCustomName() { + return getCustomName() != null; + } + protected boolean hasValue(int no) { return entityValues.containsKey(no); } @@ -198,6 +206,10 @@ public class FlagWatcher { return getFlag(0); } + public boolean isCustomNameVisible() { + return (Byte) getValue(11, (byte) 0) == 1; + } + public boolean isEntityAnimationsAdded() { return addEntityAnimations; } @@ -206,31 +218,6 @@ public class FlagWatcher { return getFlag(5); } - public String getCustomName() { - return (String) getValue(10, null); - } - - public boolean hasCustomName() { - return getCustomName() != null; - } - - public boolean isCustomNameVisible() { - return (Byte) getValue(11, (byte) 0) == 1; - } - - public void setCustomName(String name) { - if (name != null && name.length() > 64) { - name = name.substring(0, 64); - } - setValue(10, name); - sendData(10); - } - - public void setCustomNameVisible(boolean display) { - setValue(11, (byte) (display ? 1 : 0)); - sendData(11); - } - public boolean isRightClicking() { return getFlag(4); } @@ -305,6 +292,19 @@ public class FlagWatcher { sendData(0); } + public void setCustomName(String name) { + if (name != null && name.length() > 64) { + name = name.substring(0, 64); + } + setValue(10, name); + sendData(10); + } + + public void setCustomNameVisible(boolean display) { + setValue(11, (byte) (display ? 1 : 0)); + sendData(11); + } + private void setFlag(int byteValue, boolean flag) { modifiedEntityAnimations.add(byteValue); byte b0 = (Byte) getValue(0, (byte) 0); diff --git a/src/me/libraryaddict/disguise/utilities/BaseDisguiseCommand.java b/src/me/libraryaddict/disguise/utilities/BaseDisguiseCommand.java index 9f25a587..ad682775 100644 --- a/src/me/libraryaddict/disguise/utilities/BaseDisguiseCommand.java +++ b/src/me/libraryaddict/disguise/utilities/BaseDisguiseCommand.java @@ -2,12 +2,14 @@ package me.libraryaddict.disguise.utilities; import java.lang.reflect.Method; import java.util.ArrayList; +import java.util.Arrays; import java.util.Collections; import java.util.HashMap; import me.libraryaddict.disguise.disguisetypes.AnimalColor; import me.libraryaddict.disguise.disguisetypes.Disguise; import me.libraryaddict.disguise.disguisetypes.DisguiseType; +import me.libraryaddict.disguise.disguisetypes.FlagWatcher; import me.libraryaddict.disguise.disguisetypes.MiscDisguise; import me.libraryaddict.disguise.disguisetypes.MobDisguise; import me.libraryaddict.disguise.disguisetypes.PlayerDisguise; @@ -68,6 +70,21 @@ public abstract class BaseDisguiseCommand implements CommandExecutor { } } + protected Method[] getDisguiseWatcherMethods(Class watcherClass) { + Method[] methods = watcherClass.getMethods(); + methods = Arrays.copyOf(methods, methods.length + 4); + int i = 4; + for (String methodName : new String[] { "setViewSelfDisguise", "setHideHeldItemFromSelf", "setHideArmorFromSelf", + "setHearSelfDisguise" }) { + try { + methods[methods.length - i--] = Disguise.class.getMethod(methodName, boolean.class); + } catch (Exception ex) { + ex.printStackTrace(); + } + } + return methods; + } + /** * Get perms for the node. Returns a hashmap of allowed disguisetypes and their options */ @@ -432,12 +449,13 @@ public abstract class BaseDisguiseCommand implements CommandExecutor { String[] newArgs = new String[args.length - toSkip]; System.arraycopy(args, toSkip, newArgs, 0, args.length - toSkip); args = newArgs; + Method[] methods = this.getDisguiseWatcherMethods(disguise.getWatcher().getClass()); for (int i = 0; i < args.length; i += 2) { String methodName = args[i]; String valueString = (args.length - 1 == i ? null : args[i + 1]); Method methodToUse = null; Object value = null; - for (Method method : disguise.getWatcher().getClass().getMethods()) { + for (Method method : methods) { if (!method.getName().startsWith("get") && method.getName().equalsIgnoreCase(methodName) && method.getAnnotation(Deprecated.class) == null && method.getParameterTypes().length == 1) { methodToUse = method;