2013-11-05 16:16:46 +01:00
|
|
|
package me.libraryaddict.disguise.commands;
|
|
|
|
|
|
|
|
import java.lang.reflect.Method;
|
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.Collections;
|
|
|
|
import me.libraryaddict.disguise.BaseDisguiseCommand;
|
2013-11-06 07:01:31 +01:00
|
|
|
import me.libraryaddict.disguise.disguisetypes.AnimalColor;
|
2013-11-05 16:16:46 +01:00
|
|
|
import me.libraryaddict.disguise.disguisetypes.DisguiseType;
|
|
|
|
import org.apache.commons.lang.StringUtils;
|
|
|
|
import org.bukkit.ChatColor;
|
|
|
|
import org.bukkit.command.Command;
|
|
|
|
import org.bukkit.command.CommandSender;
|
2013-11-06 09:28:35 +01:00
|
|
|
import org.bukkit.entity.Horse.Color;
|
|
|
|
import org.bukkit.entity.Horse.Style;
|
|
|
|
import org.bukkit.entity.Ocelot.Type;
|
|
|
|
import org.bukkit.entity.Villager.Profession;
|
2013-11-06 07:01:31 +01:00
|
|
|
import org.bukkit.inventory.ItemStack;
|
2013-11-06 09:28:35 +01:00
|
|
|
import org.bukkit.potion.PotionEffectType;
|
2013-11-05 16:16:46 +01:00
|
|
|
|
|
|
|
public class DisguiseHelpCommand extends BaseDisguiseCommand {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
|
|
|
|
for (String node : new String[] { "disguise", "disguiseradius", "disguiseentity", "disguiseplayer" }) {
|
2013-11-19 10:48:33 +01:00
|
|
|
ArrayList<String> allowedDisguises = getAllowedDisguises(sender, "libsdisguises." + node + ".");
|
2013-11-05 16:16:46 +01:00
|
|
|
if (!allowedDisguises.isEmpty()) {
|
|
|
|
if (args.length == 0) {
|
2013-11-06 09:28:35 +01:00
|
|
|
sendCommandUsage(sender);
|
2013-11-05 16:16:46 +01:00
|
|
|
return true;
|
|
|
|
// sender.sendMessage(ChatColor.RED + "/disguisehelp <Disguise> <Option>");
|
|
|
|
} else {
|
2013-11-06 09:28:35 +01:00
|
|
|
Enum[] enums = null;
|
|
|
|
String enumName = null;
|
2013-11-06 09:30:14 +01:00
|
|
|
ArrayList<String> enumReturns = new ArrayList<String>();
|
2013-11-07 21:23:28 +01:00
|
|
|
if (args[0].equalsIgnoreCase("AnimalColor") || args[0].equalsIgnoreCase("AnimalColors")) {
|
2013-11-06 09:28:35 +01:00
|
|
|
enums = AnimalColor.values();
|
|
|
|
enumName = "Animal colors";
|
2013-11-07 21:23:28 +01:00
|
|
|
} else if (args[0].equalsIgnoreCase("HorseColor") || args[0].equalsIgnoreCase("HorseColors")) {
|
2013-11-06 09:28:35 +01:00
|
|
|
enums = Color.values();
|
|
|
|
enumName = "Horse colors";
|
2013-11-07 21:23:28 +01:00
|
|
|
} else if (args[0].equalsIgnoreCase("HorseStyle") || args[0].equalsIgnoreCase("HorseStyles")) {
|
2013-11-06 09:28:35 +01:00
|
|
|
enums = Style.values();
|
|
|
|
enumName = "Horse styles";
|
|
|
|
} else if (args[0].equalsIgnoreCase("OcelotType") || args[0].equalsIgnoreCase("OcelotTypes")) {
|
|
|
|
enums = Type.values();
|
|
|
|
enumName = "Ocelot types";
|
|
|
|
} else if (args[0].equalsIgnoreCase("Profession") || args[0].equalsIgnoreCase("Professions")) {
|
|
|
|
enums = Profession.values();
|
|
|
|
enumName = "Villager professions";
|
|
|
|
} else if (args[0].equalsIgnoreCase("PotionEffect") || args[0].equalsIgnoreCase("PotionEffects")) {
|
2013-11-07 21:23:28 +01:00
|
|
|
enumName = "PotionEffect";
|
2013-11-06 09:28:35 +01:00
|
|
|
for (PotionEffectType potionType : PotionEffectType.values()) {
|
|
|
|
if (potionType != null)
|
2013-11-06 09:30:14 +01:00
|
|
|
enumReturns.add(toReadable(potionType.getName()) + ChatColor.RED + "(" + ChatColor.GREEN
|
2013-11-06 09:28:35 +01:00
|
|
|
+ potionType.getId() + ChatColor.RED + ")");
|
2013-11-06 07:01:31 +01:00
|
|
|
}
|
2013-11-06 09:28:35 +01:00
|
|
|
}
|
|
|
|
if (enums != null) {
|
|
|
|
for (Enum enumType : enums) {
|
|
|
|
enumReturns.add(toReadable(enumType.name()));
|
|
|
|
}
|
2013-11-06 09:30:14 +01:00
|
|
|
}
|
|
|
|
if (!enumReturns.isEmpty()) {
|
2013-11-06 09:28:35 +01:00
|
|
|
sender.sendMessage(ChatColor.RED + enumName + ": " + ChatColor.GREEN
|
|
|
|
+ StringUtils.join(enumReturns, ChatColor.RED + ", " + ChatColor.GREEN));
|
2013-11-06 07:01:31 +01:00
|
|
|
return true;
|
|
|
|
}
|
2013-11-05 16:16:46 +01:00
|
|
|
DisguiseType type = null;
|
2013-11-05 17:41:34 +01:00
|
|
|
for (DisguiseType disguiseType : DisguiseType.values()) {
|
|
|
|
if (args[0].equalsIgnoreCase(disguiseType.name())
|
|
|
|
|| disguiseType.name().replace("_", "").equalsIgnoreCase(args[0])) {
|
|
|
|
type = disguiseType;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (type == null) {
|
2013-11-05 16:16:46 +01:00
|
|
|
sender.sendMessage(ChatColor.RED + "Cannot find the disguise " + args[0]);
|
|
|
|
return true;
|
|
|
|
}
|
2013-11-05 17:41:34 +01:00
|
|
|
ArrayList<String> methods = new ArrayList<String>();
|
|
|
|
Class watcher = type.getWatcherClass();
|
|
|
|
try {
|
|
|
|
for (Method method : watcher.getMethods()) {
|
2013-11-17 16:29:38 +01:00
|
|
|
if (!method.getName().startsWith("get") && method.getParameterTypes().length == 1
|
|
|
|
&& method.getAnnotation(Deprecated.class) == null) {
|
2013-11-05 17:41:34 +01:00
|
|
|
Class c = method.getParameterTypes()[0];
|
|
|
|
String valueType = null;
|
2013-11-07 21:32:24 +01:00
|
|
|
if (c == String.class) {
|
2013-11-05 17:41:34 +01:00
|
|
|
valueType = "String";
|
2013-11-07 21:32:24 +01:00
|
|
|
} else if (boolean.class == c) {
|
2013-11-05 17:41:34 +01:00
|
|
|
valueType = "True/False";
|
2013-11-07 21:32:24 +01:00
|
|
|
} else if (int.class == c) {
|
2013-11-05 17:41:34 +01:00
|
|
|
valueType = "Number";
|
2013-11-07 21:32:24 +01:00
|
|
|
} else if (float.class == c || double.class == c) {
|
|
|
|
valueType = "Number.0";
|
2013-11-06 07:01:31 +01:00
|
|
|
} else if (AnimalColor.class == c) {
|
|
|
|
valueType = "Color";
|
|
|
|
} else if (ItemStack.class == c) {
|
|
|
|
valueType = "Item ID with optional :Durability";
|
|
|
|
} else if (ItemStack[].class == c) {
|
|
|
|
valueType = "Item ID,ID,ID,ID with optional :Durability";
|
2013-11-06 09:28:35 +01:00
|
|
|
} else if (Style.class == c) {
|
|
|
|
valueType = "Horse Style";
|
|
|
|
} else if (Color.class == c) {
|
|
|
|
valueType = "Horse Color";
|
|
|
|
} else if (Type.class == c) {
|
|
|
|
valueType = "Ocelot type";
|
|
|
|
} else if (Profession.class == c) {
|
|
|
|
valueType = "Villager Profession";
|
2013-11-06 10:23:46 +01:00
|
|
|
} else if (PotionEffectType.class == c) {
|
2013-11-06 22:24:47 +01:00
|
|
|
valueType = "Potioneffect";
|
2013-11-05 17:41:34 +01:00
|
|
|
}
|
|
|
|
if (valueType != null) {
|
2013-11-06 07:01:31 +01:00
|
|
|
methods.add(ChatColor.RED + method.getName() + ChatColor.DARK_RED + "(" + ChatColor.GREEN
|
2013-11-05 17:41:34 +01:00
|
|
|
+ valueType + ChatColor.DARK_RED + ")");
|
2013-11-05 16:16:46 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2013-11-05 17:41:34 +01:00
|
|
|
} catch (Exception ex) {
|
|
|
|
ex.printStackTrace();
|
2013-11-05 16:16:46 +01:00
|
|
|
}
|
2013-11-05 17:41:34 +01:00
|
|
|
Collections.sort(methods, String.CASE_INSENSITIVE_ORDER);
|
2013-11-05 17:42:34 +01:00
|
|
|
sender.sendMessage(ChatColor.DARK_RED + type.toReadable() + " options: "
|
|
|
|
+ StringUtils.join(methods, ChatColor.DARK_RED + ", "));
|
2013-11-05 17:41:34 +01:00
|
|
|
return true;
|
2013-11-05 16:16:46 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2013-11-19 10:48:33 +01:00
|
|
|
sender.sendMessage(ChatColor.RED + "You are forbidden from using this command!");
|
2013-11-05 16:16:46 +01:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Send the player the information
|
|
|
|
*/
|
|
|
|
protected void sendCommandUsage(CommandSender sender) {
|
2013-11-06 09:28:35 +01:00
|
|
|
sender.sendMessage(ChatColor.RED + "/disguisehelp <DisguiseType> " + ChatColor.GREEN
|
|
|
|
+ "- View the options you can set on a disguise");
|
|
|
|
sender.sendMessage(ChatColor.RED + "/disguisehelp AnimalColors " + ChatColor.GREEN
|
|
|
|
+ "- View all the colors you can use for a animal color");
|
|
|
|
sender.sendMessage(ChatColor.RED + "/disguisehelp HorseColors " + ChatColor.GREEN
|
|
|
|
+ "- View all the colors you can use for a horses color");
|
|
|
|
sender.sendMessage(ChatColor.RED + "/disguisehelp HorseStyles " + ChatColor.GREEN
|
|
|
|
+ "- View all the styles you can use for a horses style");
|
|
|
|
sender.sendMessage(ChatColor.RED + "/disguisehelp OcelotTypes " + ChatColor.GREEN
|
|
|
|
+ "- View all the ocelot types you can use for ocelots");
|
|
|
|
sender.sendMessage(ChatColor.RED + "/disguisehelp Professions " + ChatColor.GREEN
|
|
|
|
+ "- View all the professions you can set on a villager");
|
|
|
|
sender.sendMessage(ChatColor.RED + "/disguisehelp PotionEffect " + ChatColor.GREEN
|
|
|
|
+ "- View all the potion effects you can set");
|
2013-11-05 16:16:46 +01:00
|
|
|
}
|
2013-11-06 10:11:31 +01:00
|
|
|
|
|
|
|
public String toReadable(String string) {
|
|
|
|
String[] split = string.split("_");
|
|
|
|
for (int i = 0; i < split.length; i++)
|
|
|
|
split[i] = split[i].substring(0, 1) + split[i].substring(1).toLowerCase();
|
|
|
|
return StringUtils.join(split, "_");
|
|
|
|
}
|
2013-11-05 16:16:46 +01:00
|
|
|
}
|