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;
|
2014-06-05 01:45:17 +02:00
|
|
|
import java.util.HashMap;
|
|
|
|
|
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;
|
2014-06-04 23:35:53 +02:00
|
|
|
import me.libraryaddict.disguise.disguisetypes.FlagWatcher;
|
|
|
|
import me.libraryaddict.disguise.disguisetypes.watchers.LivingWatcher;
|
2013-11-22 21:10:20 +01:00
|
|
|
import me.libraryaddict.disguise.utilities.BaseDisguiseCommand;
|
2013-11-22 20:52:15 +01:00
|
|
|
|
2013-11-05 16:16:46 +01:00
|
|
|
import org.apache.commons.lang.StringUtils;
|
|
|
|
import org.bukkit.ChatColor;
|
|
|
|
import org.bukkit.command.Command;
|
|
|
|
import org.bukkit.command.CommandSender;
|
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 {
|
2013-11-22 16:21:03 +01:00
|
|
|
private class EnumHelp {
|
|
|
|
private String enumDescription;
|
2013-11-22 20:52:15 +01:00
|
|
|
private String enumName;
|
2013-11-22 16:21:03 +01:00
|
|
|
private String[] enums;
|
|
|
|
private String readableEnum;
|
|
|
|
|
|
|
|
public EnumHelp(String enumName, String enumReadable, String enumDescription, Enum[] enums) {
|
|
|
|
String[] strings = new String[enums.length];
|
|
|
|
for (int i = 0; i < strings.length; i++) {
|
|
|
|
strings[i] = toReadable(enums[i].name());
|
|
|
|
}
|
|
|
|
this.enumName = enumName;
|
|
|
|
this.enumDescription = enumDescription;
|
|
|
|
this.enums = strings;
|
|
|
|
this.readableEnum = enumReadable;
|
|
|
|
}
|
|
|
|
|
|
|
|
public EnumHelp(String enumName, String enumReadable, String enumDescription, String[] enums) {
|
|
|
|
this.enumName = enumName;
|
|
|
|
this.enumDescription = enumDescription;
|
|
|
|
this.enums = enums;
|
|
|
|
this.readableEnum = enumReadable;
|
|
|
|
}
|
|
|
|
|
|
|
|
public String getEnumDescription() {
|
|
|
|
return enumDescription;
|
|
|
|
}
|
|
|
|
|
2013-11-22 20:52:15 +01:00
|
|
|
public String getEnumName() {
|
|
|
|
return enumName;
|
|
|
|
}
|
|
|
|
|
2013-11-22 16:21:03 +01:00
|
|
|
public String[] getEnums() {
|
|
|
|
return enums;
|
|
|
|
}
|
2013-11-22 20:52:15 +01:00
|
|
|
|
|
|
|
public String getReadableEnum() {
|
|
|
|
return readableEnum;
|
|
|
|
}
|
2013-11-22 16:21:03 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
private ArrayList<EnumHelp> enumHelp = new ArrayList<EnumHelp>();
|
|
|
|
|
|
|
|
public DisguiseHelpCommand() {
|
|
|
|
try {
|
|
|
|
enumHelp.add(new EnumHelp("AnimalColor", "Animal colors", ChatColor.RED + "/disguisehelp AnimalColors "
|
|
|
|
+ ChatColor.GREEN + "- View all the colors you can use for a animal color", AnimalColor.values()));
|
|
|
|
} catch (Exception ex) {
|
|
|
|
ex.printStackTrace();
|
|
|
|
}
|
2013-11-23 21:10:28 +01:00
|
|
|
try {
|
|
|
|
enumHelp.add(new EnumHelp("Art", "Arts", ChatColor.RED + "/disguisehelp Art " + ChatColor.GREEN
|
|
|
|
+ "- View all the painting arts you can use on a painting disguise", (Enum[]) Class.forName("org.bukkit.Art")
|
|
|
|
.getEnumConstants()));
|
|
|
|
} catch (Exception ex) {
|
|
|
|
}
|
2013-11-22 16:21:03 +01:00
|
|
|
try {
|
|
|
|
enumHelp.add(new EnumHelp("HorseColor", "Horse colors", ChatColor.RED + "/disguisehelp HorseColors "
|
|
|
|
+ ChatColor.GREEN + "- View all the colors you can use for a horses color", (Enum[]) Class.forName(
|
|
|
|
"org.bukkit.entity.Horse$Color").getEnumConstants()));
|
|
|
|
} catch (Exception ex) {
|
|
|
|
}
|
|
|
|
try {
|
|
|
|
enumHelp.add(new EnumHelp("HorseStyle", "Horse styles", ChatColor.RED + "/disguisehelp HorseStyles "
|
|
|
|
+ ChatColor.GREEN + "- View all the styles you can use for a horses style", (Enum[]) Class.forName(
|
|
|
|
"org.bukkit.entity.Horse$Style").getEnumConstants()));
|
|
|
|
} catch (Exception ex) {
|
|
|
|
}
|
|
|
|
try {
|
|
|
|
enumHelp.add(new EnumHelp("OcelotType", "Ocelot types", ChatColor.RED + "/disguisehelp OcelotTypes "
|
|
|
|
+ ChatColor.GREEN + "- View all the ocelot types you can use for ocelots", (Enum[]) Class.forName(
|
|
|
|
"org.bukkit.entity.Ocelot$Type").getEnumConstants()));
|
|
|
|
} catch (Exception ex) {
|
|
|
|
}
|
|
|
|
try {
|
|
|
|
ArrayList<String> enumReturns = new ArrayList<String>();
|
|
|
|
for (PotionEffectType potionType : PotionEffectType.values()) {
|
|
|
|
if (potionType != null)
|
|
|
|
enumReturns.add(toReadable(potionType.getName()) + ChatColor.RED + "(" + ChatColor.GREEN + potionType.getId()
|
|
|
|
+ ChatColor.RED + ")");
|
|
|
|
}
|
|
|
|
enumHelp.add(new EnumHelp("PotionEffect", "PotionEffect", ChatColor.RED + "/disguisehelp PotionEffect "
|
|
|
|
+ ChatColor.GREEN + "- View all the potion effects you can set", enumReturns.toArray(new String[enumReturns
|
|
|
|
.size()])));
|
|
|
|
} catch (Exception ex) {
|
|
|
|
ex.printStackTrace();
|
|
|
|
}
|
2013-11-23 21:10:28 +01:00
|
|
|
try {
|
|
|
|
enumHelp.add(new EnumHelp("Profession", "Villager professions", ChatColor.RED + "/disguisehelp Professions "
|
|
|
|
+ ChatColor.GREEN + "- View all the professions you can set on a villager", (Enum[]) Class.forName(
|
|
|
|
"org.bukkit.entity.Villager$Profession").getEnumConstants()));
|
|
|
|
} catch (Exception ex) {
|
|
|
|
}
|
2013-11-22 16:21:03 +01:00
|
|
|
}
|
2013-11-05 16:16:46 +01:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
|
|
|
|
for (String node : new String[] { "disguise", "disguiseradius", "disguiseentity", "disguiseplayer" }) {
|
2014-06-14 10:45:19 +02:00
|
|
|
HashMap<DisguiseType, HashMap<ArrayList<String>, Boolean>> permMap = getPermissions(sender, "libsdisguises." + node
|
|
|
|
+ ".");
|
|
|
|
if (!permMap.isEmpty()) {
|
2013-11-05 16:16:46 +01:00
|
|
|
if (args.length == 0) {
|
2014-06-14 10:16:48 +02:00
|
|
|
sendCommandUsage(sender, null);
|
2013-11-05 16:16:46 +01:00
|
|
|
return true;
|
|
|
|
} else {
|
2013-11-22 16:21:03 +01:00
|
|
|
EnumHelp help = null;
|
|
|
|
for (EnumHelp s : enumHelp) {
|
|
|
|
if (args[0].equalsIgnoreCase(s.getEnumName()) || args[0].equalsIgnoreCase(s.getEnumName() + "s")) {
|
|
|
|
help = s;
|
|
|
|
break;
|
2013-11-06 09:28:35 +01:00
|
|
|
}
|
2013-11-06 09:30:14 +01:00
|
|
|
}
|
2013-11-22 16:21:03 +01:00
|
|
|
if (help != null) {
|
|
|
|
sender.sendMessage(ChatColor.RED + help.getReadableEnum() + ": " + ChatColor.GREEN
|
|
|
|
+ StringUtils.join(help.getEnums(), 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;
|
|
|
|
}
|
2014-06-14 10:45:19 +02:00
|
|
|
if (!permMap.containsKey(type)) {
|
|
|
|
sender.sendMessage(ChatColor.RED + "You do not have permission for that disguise!");
|
|
|
|
return true;
|
|
|
|
}
|
2013-11-05 17:41:34 +01:00
|
|
|
ArrayList<String> methods = new ArrayList<String>();
|
2014-06-05 01:45:17 +02:00
|
|
|
HashMap<String, ChatColor> map = new HashMap<String, ChatColor>();
|
2013-11-05 17:41:34 +01:00
|
|
|
Class watcher = type.getWatcherClass();
|
2014-06-15 04:52:45 +02:00
|
|
|
int ignored = 0;
|
2013-11-05 17:41:34 +01:00
|
|
|
try {
|
2014-09-13 11:23:06 +02:00
|
|
|
for (Method method : this.getDisguiseWatcherMethods(watcher)) {
|
2013-11-17 16:29:38 +01:00
|
|
|
if (!method.getName().startsWith("get") && method.getParameterTypes().length == 1
|
|
|
|
&& method.getAnnotation(Deprecated.class) == null) {
|
2014-06-14 10:45:19 +02:00
|
|
|
if (args.length < 2 || !args[1].equalsIgnoreCase("show")) {
|
|
|
|
boolean allowed = false;
|
|
|
|
for (ArrayList<String> key : permMap.get(type).keySet()) {
|
|
|
|
if (permMap.get(type).get(key)) {
|
|
|
|
if (key.contains("*") || key.contains(method.getName().toLowerCase())) {
|
|
|
|
allowed = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
} else if (!key.contains(method.getName().toLowerCase())) {
|
|
|
|
allowed = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!allowed) {
|
2014-06-15 04:52:45 +02:00
|
|
|
ignored++;
|
2014-06-14 10:45:19 +02:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
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) {
|
2014-06-04 23:35:53 +02:00
|
|
|
valueType = "Decimal";
|
2013-11-06 07:01:31 +01:00
|
|
|
} else if (AnimalColor.class == c) {
|
|
|
|
valueType = "Color";
|
|
|
|
} else if (ItemStack.class == c) {
|
2014-06-04 23:35:53 +02:00
|
|
|
valueType = "Item (id:damage)";
|
2013-11-06 07:01:31 +01:00
|
|
|
} else if (ItemStack[].class == c) {
|
2014-06-04 23:35:53 +02:00
|
|
|
valueType = "4 items (id:damage,id,...)";
|
2013-11-22 16:21:03 +01:00
|
|
|
} else if (c.getSimpleName().equals("Style")) {
|
2013-11-06 09:28:35 +01:00
|
|
|
valueType = "Horse Style";
|
2013-11-22 16:21:03 +01:00
|
|
|
} else if (c.getSimpleName().equals("Color")) {
|
2013-11-06 09:28:35 +01:00
|
|
|
valueType = "Horse Color";
|
2013-11-22 16:21:03 +01:00
|
|
|
} else if (c.getSimpleName().equals("Type")) {
|
2013-11-06 09:28:35 +01:00
|
|
|
valueType = "Ocelot type";
|
2013-11-22 16:21:03 +01:00
|
|
|
} else if (c.getSimpleName().equals("Profession")) {
|
2013-11-06 09:28:35 +01:00
|
|
|
valueType = "Villager Profession";
|
2013-11-06 10:23:46 +01:00
|
|
|
} else if (PotionEffectType.class == c) {
|
2014-06-04 23:35:53 +02:00
|
|
|
valueType = "Potion effect";
|
2014-07-14 02:25:37 +02:00
|
|
|
} else if (c == int[].class) {
|
|
|
|
valueType = "number,number,number...";
|
2013-11-05 17:41:34 +01:00
|
|
|
}
|
|
|
|
if (valueType != null) {
|
2014-06-04 23:35:53 +02:00
|
|
|
ChatColor methodColor = ChatColor.YELLOW;
|
|
|
|
Class<?> declaring = method.getDeclaringClass();
|
|
|
|
if (declaring == LivingWatcher.class) {
|
|
|
|
methodColor = ChatColor.AQUA;
|
2014-09-13 11:18:18 +02:00
|
|
|
} else if (!(declaring.isAssignableFrom(FlagWatcher.class)) || declaring == FlagWatcher.class) {
|
2014-06-04 23:35:53 +02:00
|
|
|
methodColor = ChatColor.GRAY;
|
|
|
|
}
|
2014-06-05 01:45:17 +02:00
|
|
|
String str = method.getName() + ChatColor.DARK_RED + "(" + ChatColor.GREEN + valueType
|
|
|
|
+ ChatColor.DARK_RED + ")";
|
|
|
|
map.put(str, methodColor);
|
|
|
|
methods.add(str);
|
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);
|
2014-06-05 01:45:17 +02:00
|
|
|
for (int i = 0; i < methods.size(); i++) {
|
|
|
|
methods.set(i, map.get(methods.get(i)) + methods.get(i));
|
|
|
|
}
|
2014-06-14 10:45:19 +02:00
|
|
|
if (methods.isEmpty()) {
|
2014-06-14 11:16:11 +02:00
|
|
|
methods.add(ChatColor.RED + "No options with permission to use");
|
2014-06-14 10:45:19 +02:00
|
|
|
}
|
2013-11-05 17:42:34 +01:00
|
|
|
sender.sendMessage(ChatColor.DARK_RED + type.toReadable() + " options: "
|
|
|
|
+ StringUtils.join(methods, ChatColor.DARK_RED + ", "));
|
2014-06-15 04:52:45 +02:00
|
|
|
if (ignored > 0) {
|
|
|
|
sender.sendMessage(ChatColor.RED + "Ignored " + ignored
|
|
|
|
+ " options you do not have permission to view. Add 'show' to view unusable options.");
|
|
|
|
}
|
2013-11-05 17:41:34 +01:00
|
|
|
return true;
|
2013-11-05 16:16:46 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2014-06-01 17:52:54 +02:00
|
|
|
sender.sendMessage(ChatColor.RED + "You are forbidden to use this command.");
|
2013-11-05 16:16:46 +01:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Send the player the information
|
|
|
|
*/
|
2014-06-14 10:16:48 +02:00
|
|
|
protected void sendCommandUsage(CommandSender sender, HashMap<DisguiseType, HashMap<ArrayList<String>, Boolean>> map) {
|
2014-06-14 10:45:19 +02:00
|
|
|
sender.sendMessage(ChatColor.RED
|
|
|
|
+ "/disguisehelp <DisguiseType> "
|
|
|
|
+ ChatColor.GREEN
|
|
|
|
+ "- View the options you can set on a disguise. Add 'show' to reveal the options you don't have permission to use");
|
2013-11-22 16:21:03 +01:00
|
|
|
for (EnumHelp s : enumHelp) {
|
|
|
|
sender.sendMessage(s.getEnumDescription());
|
|
|
|
}
|
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
|
|
|
}
|