Sort files and make 4 new options in the disguise class viewable with commands

This commit is contained in:
libraryaddict 2014-09-13 21:23:06 +12:00
parent ead0fd724c
commit 9be63e1cc8
3 changed files with 45 additions and 27 deletions

View File

@ -157,7 +157,7 @@ public class DisguiseHelpCommand extends BaseDisguiseCommand {
Class watcher = type.getWatcherClass(); Class watcher = type.getWatcherClass();
int ignored = 0; int ignored = 0;
try { try {
for (Method method : watcher.getMethods()) { for (Method method : this.getDisguiseWatcherMethods(watcher)) {
if (!method.getName().startsWith("get") && method.getParameterTypes().length == 1 if (!method.getName().startsWith("get") && method.getParameterTypes().length == 1
&& method.getAnnotation(Deprecated.class) == null) { && method.getAnnotation(Deprecated.class) == null) {
if (args.length < 2 || !args[1].equalsIgnoreCase("show")) { if (args.length < 2 || !args[1].equalsIgnoreCase("show")) {

View File

@ -157,6 +157,10 @@ public class FlagWatcher {
return armor; return armor;
} }
public String getCustomName() {
return (String) getValue(10, null);
}
protected TargetedDisguise getDisguise() { protected TargetedDisguise getDisguise() {
return disguise; return disguise;
} }
@ -190,6 +194,10 @@ public class FlagWatcher {
return watchableObjects; return watchableObjects;
} }
public boolean hasCustomName() {
return getCustomName() != null;
}
protected boolean hasValue(int no) { protected boolean hasValue(int no) {
return entityValues.containsKey(no); return entityValues.containsKey(no);
} }
@ -198,6 +206,10 @@ public class FlagWatcher {
return getFlag(0); return getFlag(0);
} }
public boolean isCustomNameVisible() {
return (Byte) getValue(11, (byte) 0) == 1;
}
public boolean isEntityAnimationsAdded() { public boolean isEntityAnimationsAdded() {
return addEntityAnimations; return addEntityAnimations;
} }
@ -206,31 +218,6 @@ public class FlagWatcher {
return getFlag(5); 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() { public boolean isRightClicking() {
return getFlag(4); return getFlag(4);
} }
@ -305,6 +292,19 @@ public class FlagWatcher {
sendData(0); 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) { private void setFlag(int byteValue, boolean flag) {
modifiedEntityAnimations.add(byteValue); modifiedEntityAnimations.add(byteValue);
byte b0 = (Byte) getValue(0, (byte) 0); byte b0 = (Byte) getValue(0, (byte) 0);

View File

@ -2,12 +2,14 @@ package me.libraryaddict.disguise.utilities;
import java.lang.reflect.Method; import java.lang.reflect.Method;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections; import java.util.Collections;
import java.util.HashMap; import java.util.HashMap;
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.DisguiseType; import me.libraryaddict.disguise.disguisetypes.DisguiseType;
import me.libraryaddict.disguise.disguisetypes.FlagWatcher;
import me.libraryaddict.disguise.disguisetypes.MiscDisguise; import me.libraryaddict.disguise.disguisetypes.MiscDisguise;
import me.libraryaddict.disguise.disguisetypes.MobDisguise; import me.libraryaddict.disguise.disguisetypes.MobDisguise;
import me.libraryaddict.disguise.disguisetypes.PlayerDisguise; import me.libraryaddict.disguise.disguisetypes.PlayerDisguise;
@ -68,6 +70,21 @@ public abstract class BaseDisguiseCommand implements CommandExecutor {
} }
} }
protected Method[] getDisguiseWatcherMethods(Class<? extends FlagWatcher> 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 * 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]; String[] newArgs = new String[args.length - toSkip];
System.arraycopy(args, toSkip, newArgs, 0, args.length - toSkip); System.arraycopy(args, toSkip, newArgs, 0, args.length - toSkip);
args = newArgs; args = newArgs;
Method[] methods = this.getDisguiseWatcherMethods(disguise.getWatcher().getClass());
for (int i = 0; i < args.length; i += 2) { for (int i = 0; i < args.length; i += 2) {
String methodName = args[i]; String methodName = args[i];
String valueString = (args.length - 1 == i ? null : args[i + 1]); String valueString = (args.length - 1 == i ? null : args[i + 1]);
Method methodToUse = null; Method methodToUse = null;
Object value = null; Object value = null;
for (Method method : disguise.getWatcher().getClass().getMethods()) { for (Method method : methods) {
if (!method.getName().startsWith("get") && method.getName().equalsIgnoreCase(methodName) if (!method.getName().startsWith("get") && method.getName().equalsIgnoreCase(methodName)
&& method.getAnnotation(Deprecated.class) == null && method.getParameterTypes().length == 1) { && method.getAnnotation(Deprecated.class) == null && method.getParameterTypes().length == 1) {
methodToUse = method; methodToUse = method;