Add BlockFace aka direction to disguise options

This commit is contained in:
libraryaddict 2014-09-15 01:22:05 +12:00
parent 9f72a3940e
commit babe5554ab
2 changed files with 115 additions and 101 deletions

View File

@ -2,6 +2,7 @@ package me.libraryaddict.disguise.commands;
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;
@ -13,6 +14,7 @@ import me.libraryaddict.disguise.utilities.BaseDisguiseCommand;
import org.apache.commons.lang.StringUtils; import org.apache.commons.lang.StringUtils;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import org.bukkit.block.BlockFace;
import org.bukkit.command.Command; import org.bukkit.command.Command;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
@ -112,6 +114,8 @@ public class DisguiseHelpCommand extends BaseDisguiseCommand {
"org.bukkit.entity.Villager$Profession").getEnumConstants())); "org.bukkit.entity.Villager$Profession").getEnumConstants()));
} catch (Exception ex) { } catch (Exception ex) {
} }
enumHelp.add(new EnumHelp("Direction", "Directions", ChatColor.RED + "/disguisehelp Directions " + ChatColor.GREEN
+ "- View the four directions usable on player setsleeping disguise", Arrays.copyOf(BlockFace.values(), 4)));
} }
@Override @Override
@ -206,6 +210,8 @@ public class DisguiseHelpCommand extends BaseDisguiseCommand {
valueType = "Potion effect"; valueType = "Potion effect";
} else if (c == int[].class) { } else if (c == int[].class) {
valueType = "number,number,number..."; valueType = "number,number,number...";
} else if (c == BlockFace.class) {
valueType = "direction";
} }
if (valueType != null) { if (valueType != null) {
ChatColor methodColor = ChatColor.YELLOW; ChatColor methodColor = ChatColor.YELLOW;

View File

@ -16,6 +16,7 @@ import me.libraryaddict.disguise.disguisetypes.PlayerDisguise;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.block.BlockFace;
import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.entity.Ageable; import org.bukkit.entity.Ageable;
@ -467,7 +468,6 @@ public abstract class BaseDisguiseCommand implements CommandExecutor {
} }
methodName = methodToUse.getName(); methodName = methodToUse.getName();
Class<?>[] types = methodToUse.getParameterTypes(); Class<?>[] types = methodToUse.getParameterTypes();
if (types.length == 1) {
Class param = types[0]; Class param = types[0];
if (boolean.class == param) { if (boolean.class == param) {
// Parse to boolean // Parse to boolean
@ -574,6 +574,14 @@ public abstract class BaseDisguiseCommand implements CommandExecutor {
} }
} }
value = values; value = values;
} else if (param == BlockFace.class) {
try {
BlockFace face = BlockFace.valueOf(valueString.toUpperCase());
if (face.ordinal() > 3)
throw new Exception();
value = face;
} catch (Exception ex) {
throw parseToException("a direction (north, east, south, west)", valueString, methodName);
} }
} }
} }