Current work

This commit is contained in:
libraryaddict
2017-06-19 21:23:02 +12:00
parent f4bc7ef3a4
commit cba8cb417c
24 changed files with 622 additions and 486 deletions

View File

@@ -1,31 +1,29 @@
package me.libraryaddict.disguise.commands;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import org.apache.commons.lang.StringUtils;
import org.bukkit.ChatColor;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.command.TabCompleter;
import me.libraryaddict.disguise.disguisetypes.FlagWatcher;
import me.libraryaddict.disguise.disguisetypes.watchers.LivingWatcher;
import me.libraryaddict.disguise.utilities.DisguiseParser;
import me.libraryaddict.disguise.utilities.DisguiseParser.DisguisePerm;
import me.libraryaddict.disguise.utilities.ReflectionFlagWatchers;
import me.libraryaddict.disguise.utilities.ReflectionFlagWatchers.ParamInfo;
import me.libraryaddict.disguise.utilities.TranslateType;
import org.apache.commons.lang.StringUtils;
import org.bukkit.ChatColor;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.command.TabCompleter;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
public class DisguiseHelpCommand extends DisguiseBaseCommand implements TabCompleter {
@Override
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
for (String node : new String[] {
"disguise", "disguiseradius", "disguiseentity", "disguiseplayer"
}) {
for (String node : new String[]{"disguise", "disguiseradius", "disguiseentity", "disguiseplayer"}) {
HashMap<DisguisePerm, HashMap<ArrayList<String>, Boolean>> permMap = DisguiseParser.getPermissions(sender,
"libsdisguises." + node + ".");
@@ -33,8 +31,7 @@ public class DisguiseHelpCommand extends DisguiseBaseCommand implements TabCompl
if (args.length == 0) {
sendCommandUsage(sender, null);
return true;
}
else {
} else {
ParamInfo help = null;
for (ParamInfo s : ReflectionFlagWatchers.getParamInfos()) {
@@ -47,20 +44,28 @@ public class DisguiseHelpCommand extends DisguiseBaseCommand implements TabCompl
}
if (help != null) {
sender.sendMessage(ChatColor.RED + help.getName() + ": " + ChatColor.GREEN
+ StringUtils.join(help.getEnums(""), ChatColor.RED + ", " + ChatColor.GREEN));
if (help.isEnums()) {
sender.sendMessage(
ChatColor.RED + help.getName() + ": " + ChatColor.GREEN + StringUtils.join(
help.getEnums(""), ChatColor.RED + ", " + ChatColor.GREEN));
} else {
sender.sendMessage(
ChatColor.RED + help.getName() + ": " + ChatColor.GREEN + help.getDescription());
}
return true;
}
DisguisePerm type = DisguiseParser.getDisguisePerm(args[0]);
if (type == null) {
sender.sendMessage(ChatColor.RED + "Cannot find the disguise " + args[0]);
sender.sendMessage(
TranslateType.MESSAGE.get(ChatColor.RED + "Cannot find the disguise ") + args[0]);
return true;
}
if (!permMap.containsKey(type)) {
sender.sendMessage(ChatColor.RED + "You do not have permission for that disguise!");
sender.sendMessage(TranslateType.MESSAGE.get(
ChatColor.RED + "You do not have permission for " + "that disguise!"));
return true;
}
@@ -80,8 +85,7 @@ public class DisguiseHelpCommand extends DisguiseBaseCommand implements TabCompl
allowed = true;
break;
}
}
else if (!key.contains(method.getName().toLowerCase())) {
} else if (!key.contains(method.getName().toLowerCase())) {
allowed = true;
break;
}
@@ -105,13 +109,12 @@ public class DisguiseHelpCommand extends DisguiseBaseCommand implements TabCompl
if (declaring == LivingWatcher.class) {
methodColor = ChatColor.AQUA;
}
else if (!(FlagWatcher.class.isAssignableFrom(declaring)) || declaring == FlagWatcher.class) {
} else if (!(FlagWatcher.class.isAssignableFrom(
declaring)) || declaring == FlagWatcher.class) {
methodColor = ChatColor.GRAY;
}
String str = method.getName() + ChatColor.DARK_RED + "(" + ChatColor.GREEN + info.getName()
+ ChatColor.DARK_RED + ")";
String str = method.getName() + ChatColor.DARK_RED + "(" + ChatColor.GREEN + info.getName() + ChatColor.DARK_RED + ")";
map.put(str, methodColor);
methods.add(str);
@@ -131,12 +134,13 @@ public class DisguiseHelpCommand extends DisguiseBaseCommand implements TabCompl
methods.add(ChatColor.RED + "No options with permission to use");
}
sender.sendMessage(ChatColor.DARK_RED + type.toReadable() + " options: "
+ StringUtils.join(methods, ChatColor.DARK_RED + ", "));
sender.sendMessage(ChatColor.DARK_RED + type.toReadable() + TranslateType.MESSAGE.get(
" options: ") + StringUtils.join(methods, ChatColor.DARK_RED + ", "));
if (ignored > 0) {
sender.sendMessage(ChatColor.RED + "Ignored " + ignored
+ " options you do not have permission to use. Add 'show' to view unusable options.");
sender.sendMessage(String.format(TranslateType.MESSAGE.get(
ChatColor.RED + "Ignored %s" + " options you do not have permission to use. Add " + "'show' to view unusable options."),
ignored));
}
return true;
@@ -144,18 +148,16 @@ public class DisguiseHelpCommand extends DisguiseBaseCommand implements TabCompl
}
}
sender.sendMessage(ChatColor.RED + "You are forbidden to use this command.");
sender.sendMessage(TranslateType.MESSAGE.get(ChatColor.RED + "You are forbidden to use this command."));
return true;
}
@Override
public List<String> onTabComplete(CommandSender sender, Command cmd, String label, String[] origArgs) {
ArrayList<String> tabs = new ArrayList<String>();
ArrayList<String> tabs = new ArrayList<>();
String[] args = getArgs(origArgs);
for (String node : new String[] {
"disguise", "disguiseradius", "disguiseentity", "disguiseplayer"
}) {
for (String node : new String[]{"disguise", "disguiseradius", "disguiseentity", "disguiseplayer"}) {
HashMap<DisguisePerm, HashMap<ArrayList<String>, Boolean>> perms = DisguiseParser.getPermissions(sender,
"libsdisguises." + node + ".");
@@ -170,8 +172,7 @@ public class DisguiseHelpCommand extends DisguiseBaseCommand implements TabCompl
for (ParamInfo s : ReflectionFlagWatchers.getParamInfos()) {
tabs.add(s.getName().replaceAll(" ", ""));
}
}
else if (DisguiseParser.getDisguisePerm(args[0]) == null) {
} else if (DisguiseParser.getDisguisePerm(args[0]) == null) {
tabs.add("Show");
}
}
@@ -183,13 +184,14 @@ public class DisguiseHelpCommand extends DisguiseBaseCommand implements TabCompl
* Send the player the information
*/
@Override
protected void sendCommandUsage(CommandSender sender, HashMap<DisguisePerm, HashMap<ArrayList<String>, Boolean>> map) {
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");
protected void sendCommandUsage(CommandSender sender,
HashMap<DisguisePerm, HashMap<ArrayList<String>, Boolean>> map) {
sender.sendMessage(TranslateType.MESSAGE.get(
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"));
for (ParamInfo s : ReflectionFlagWatchers.getParamInfos()) {
sender.sendMessage(ChatColor.RED + "/disguisehelp " + s.getName().replaceAll(" ", "") + ChatColor.GREEN + " - "
+ s.getDescription());
sender.sendMessage(TranslateType.MESSAGE.get(ChatColor.RED + "/disguisehelp " + s.getName().replaceAll(" ",
"") + ChatColor.GREEN + " - " + s.getDescription()));
}
}
}