2016-05-18 01:27:04 +02:00
|
|
|
package me.libraryaddict.disguise.commands;
|
|
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.Collections;
|
|
|
|
import java.util.HashMap;
|
2016-11-30 18:38:43 +01:00
|
|
|
import java.util.HashSet;
|
2016-11-28 15:01:06 +01:00
|
|
|
import java.util.Iterator;
|
2016-05-18 01:27:04 +02:00
|
|
|
|
|
|
|
import org.bukkit.command.CommandExecutor;
|
|
|
|
import org.bukkit.command.CommandSender;
|
|
|
|
|
2016-11-30 18:38:43 +01:00
|
|
|
import me.libraryaddict.disguise.utilities.DisguiseParser;
|
|
|
|
import me.libraryaddict.disguise.utilities.DisguiseParser.DisguisePerm;
|
2016-05-18 01:27:04 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @author libraryaddict
|
|
|
|
*/
|
2016-11-28 22:47:48 +01:00
|
|
|
public abstract class DisguiseBaseCommand implements CommandExecutor {
|
2016-11-28 15:01:06 +01:00
|
|
|
|
|
|
|
protected ArrayList<String> filterTabs(ArrayList<String> list, String[] origArgs) {
|
|
|
|
if (origArgs.length == 0)
|
|
|
|
return list;
|
|
|
|
|
|
|
|
Iterator<String> itel = list.iterator();
|
|
|
|
String label = origArgs[origArgs.length - 1].toLowerCase();
|
|
|
|
|
|
|
|
while (itel.hasNext()) {
|
|
|
|
String name = itel.next();
|
|
|
|
|
|
|
|
if (name.toLowerCase().startsWith(label))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
itel.remove();
|
|
|
|
}
|
|
|
|
|
2017-06-19 19:06:35 +02:00
|
|
|
return new ArrayList<>(new HashSet<>(list));
|
2016-11-28 15:01:06 +01:00
|
|
|
}
|
|
|
|
|
2017-06-11 23:36:54 +02:00
|
|
|
protected ArrayList<String> getAllowedDisguises(
|
|
|
|
HashMap<DisguisePerm, HashMap<ArrayList<String>, Boolean>> hashMap) {
|
2016-05-18 01:27:04 +02:00
|
|
|
ArrayList<String> allowedDisguises = new ArrayList<>();
|
2016-06-14 20:40:45 +02:00
|
|
|
|
2016-11-30 18:38:43 +01:00
|
|
|
for (DisguisePerm type : hashMap.keySet()) {
|
|
|
|
if (type.isUnknown())
|
|
|
|
continue;
|
|
|
|
|
|
|
|
allowedDisguises.add(type.toReadable().replaceAll(" ", "_"));
|
2016-05-18 01:27:04 +02:00
|
|
|
}
|
2016-06-14 20:40:45 +02:00
|
|
|
|
2016-05-18 01:27:04 +02:00
|
|
|
Collections.sort(allowedDisguises, String.CASE_INSENSITIVE_ORDER);
|
2016-06-14 20:40:45 +02:00
|
|
|
|
2016-05-18 01:27:04 +02:00
|
|
|
return allowedDisguises;
|
|
|
|
}
|
|
|
|
|
2016-11-28 15:01:06 +01:00
|
|
|
protected String[] getArgs(String[] args) {
|
2017-06-11 23:36:54 +02:00
|
|
|
ArrayList<String> newArgs = new ArrayList<>();
|
2016-11-28 15:01:06 +01:00
|
|
|
|
|
|
|
for (int i = 0; i < args.length - 1; i++) {
|
|
|
|
String s = args[i];
|
|
|
|
|
|
|
|
if (s.trim().isEmpty())
|
|
|
|
continue;
|
|
|
|
|
|
|
|
newArgs.add(s);
|
|
|
|
}
|
|
|
|
|
|
|
|
return newArgs.toArray(new String[0]);
|
2016-05-18 01:27:04 +02:00
|
|
|
}
|
|
|
|
|
2017-02-19 15:53:03 +01:00
|
|
|
public final String getPermNode() {
|
2016-11-28 22:47:48 +01:00
|
|
|
if (this instanceof DisguiseCommand) {
|
|
|
|
return "disguise";
|
2017-06-11 23:36:54 +02:00
|
|
|
} else if (this instanceof DisguiseEntityCommand) {
|
2016-11-28 22:47:48 +01:00
|
|
|
return "disguiseentity";
|
2017-06-11 23:36:54 +02:00
|
|
|
} else if (this instanceof DisguisePlayerCommand) {
|
2016-11-28 22:47:48 +01:00
|
|
|
return "disguiseplayer";
|
2017-06-11 23:36:54 +02:00
|
|
|
} else if (this instanceof DisguiseRadiusCommand) {
|
2016-11-28 22:47:48 +01:00
|
|
|
return "disguiseradius";
|
2017-06-11 23:36:54 +02:00
|
|
|
} else if (this instanceof DisguiseModifyCommand) {
|
2017-02-19 15:53:03 +01:00
|
|
|
return "disguisemodify";
|
2017-06-11 23:36:54 +02:00
|
|
|
} else if (this instanceof DisguiseModifyEntityCommand) {
|
2017-02-19 15:53:03 +01:00
|
|
|
return "disguisemodifyentity";
|
2017-06-11 23:36:54 +02:00
|
|
|
} else if (this instanceof DisguiseModifyPlayerCommand) {
|
2017-02-19 15:53:03 +01:00
|
|
|
return "disguisemodifyplayer";
|
2017-06-11 23:36:54 +02:00
|
|
|
} else if (this instanceof DisguiseModifyRadiusCommand) {
|
2017-02-19 15:53:03 +01:00
|
|
|
return "disguisemodifyradius";
|
2017-06-11 23:36:54 +02:00
|
|
|
} else {
|
2016-11-28 22:47:48 +01:00
|
|
|
throw new UnsupportedOperationException("Unknown disguise command, perm node not found");
|
2017-02-19 15:53:03 +01:00
|
|
|
}
|
2016-11-28 22:47:48 +01:00
|
|
|
}
|
|
|
|
|
2016-11-30 18:38:43 +01:00
|
|
|
protected HashMap<DisguisePerm, HashMap<ArrayList<String>, Boolean>> getPermissions(CommandSender sender) {
|
|
|
|
return DisguiseParser.getPermissions(sender, "libsdisguises." + getPermNode() + ".");
|
2016-05-18 01:27:04 +02:00
|
|
|
}
|
|
|
|
|
2016-11-25 13:07:02 +01:00
|
|
|
protected boolean isNumeric(String string) {
|
|
|
|
try {
|
2016-05-18 01:27:04 +02:00
|
|
|
Integer.parseInt(string);
|
|
|
|
return true;
|
|
|
|
}
|
2016-11-25 13:07:02 +01:00
|
|
|
catch (Exception ex) {
|
2016-05-18 01:27:04 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-11-30 18:56:11 +01:00
|
|
|
public boolean passesCheck(CommandSender sender, HashMap<ArrayList<String>, Boolean> theirPermissions,
|
|
|
|
ArrayList<String> usedOptions) {
|
|
|
|
return DisguiseParser.passesCheck(sender, theirPermissions, usedOptions);
|
2016-11-28 15:01:06 +01:00
|
|
|
}
|
|
|
|
|
2016-05-18 01:27:04 +02:00
|
|
|
protected abstract void sendCommandUsage(CommandSender sender,
|
2016-11-30 18:38:43 +01:00
|
|
|
HashMap<DisguisePerm, HashMap<ArrayList<String>, Boolean>> map);
|
2016-05-18 01:27:04 +02:00
|
|
|
}
|