2016-05-18 01:27:04 +02:00
|
|
|
package me.libraryaddict.disguise.commands;
|
|
|
|
|
2018-10-05 01:04:30 +02:00
|
|
|
import me.libraryaddict.disguise.utilities.parser.DisguiseParser;
|
|
|
|
import me.libraryaddict.disguise.utilities.parser.DisguisePerm;
|
2018-10-23 23:13:13 +02:00
|
|
|
import me.libraryaddict.disguise.utilities.parser.DisguisePermissions;
|
2016-05-18 01:27:04 +02:00
|
|
|
import org.bukkit.command.CommandExecutor;
|
|
|
|
import org.bukkit.command.CommandSender;
|
2017-08-06 02:23:47 +02:00
|
|
|
import org.bukkit.entity.Player;
|
|
|
|
import org.bukkit.scoreboard.Team;
|
2016-05-18 01:27:04 +02:00
|
|
|
|
2018-10-05 01:04:30 +02:00
|
|
|
import java.util.*;
|
|
|
|
|
2016-05-18 01:27:04 +02:00
|
|
|
/**
|
|
|
|
* @author libraryaddict
|
|
|
|
*/
|
2016-11-28 22:47:48 +01:00
|
|
|
public abstract class DisguiseBaseCommand implements CommandExecutor {
|
2018-10-23 23:13:13 +02:00
|
|
|
private static final Map<Class<? extends DisguiseBaseCommand>, String> disguiseCommands;
|
|
|
|
|
|
|
|
static {
|
|
|
|
HashMap<Class<? extends DisguiseBaseCommand>, String> map = new HashMap<>();
|
|
|
|
|
|
|
|
map.put(DisguiseCommand.class, "Disguise");
|
|
|
|
map.put(DisguiseEntityCommand.class, "DisguiseEntity");
|
|
|
|
map.put(DisguisePlayerCommand.class, "DisguisePlayer");
|
|
|
|
map.put(DisguiseRadiusCommand.class, "DisguiseRadius");
|
|
|
|
map.put(DisguiseModifyCommand.class, "DisguiseModify");
|
|
|
|
map.put(DisguiseModifyEntityCommand.class, "DisguiseModifyEntity");
|
|
|
|
map.put(DisguiseModifyPlayerCommand.class, "DisguiseModifyPlayer");
|
|
|
|
map.put(DisguiseModifyRadiusCommand.class, "DisguiseModifyRadius");
|
|
|
|
|
|
|
|
disguiseCommands = map;
|
|
|
|
}
|
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-08-06 02:23:47 +02:00
|
|
|
protected String getDisplayName(CommandSender player) {
|
|
|
|
Team team = ((Player) player).getScoreboard().getEntryTeam(player.getName());
|
|
|
|
|
|
|
|
return (team == null ? "" : team.getPrefix()) + player.getName() + (team == null ? "" : team.getSuffix());
|
|
|
|
}
|
|
|
|
|
2018-10-23 23:13:13 +02:00
|
|
|
protected ArrayList<String> getAllowedDisguises(DisguisePermissions permissions) {
|
2016-05-18 01:27:04 +02:00
|
|
|
ArrayList<String> allowedDisguises = new ArrayList<>();
|
2016-06-14 20:40:45 +02:00
|
|
|
|
2018-10-23 23:13:13 +02:00
|
|
|
for (DisguisePerm type : permissions.getAllowed()) {
|
2016-11-30 18:38:43 +01:00
|
|
|
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
|
|
|
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
|
|
|
}
|
|
|
|
|
2018-10-23 23:13:13 +02:00
|
|
|
protected static final Map<Class<? extends DisguiseBaseCommand>, String> getCommandNames() {
|
|
|
|
return disguiseCommands;
|
|
|
|
}
|
|
|
|
|
2017-02-19 15:53:03 +01:00
|
|
|
public final String getPermNode() {
|
2018-10-23 23:13:13 +02:00
|
|
|
String name = getCommandNames().get(this.getClass());
|
|
|
|
|
|
|
|
if (name == null) {
|
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
|
|
|
}
|
2018-10-23 23:13:13 +02:00
|
|
|
|
|
|
|
return name;
|
2016-11-28 22:47:48 +01:00
|
|
|
}
|
|
|
|
|
2018-10-23 23:13:13 +02:00
|
|
|
protected DisguisePermissions getPermissions(CommandSender sender) {
|
|
|
|
return DisguiseParser.getPermissions(sender, getPermNode());
|
2016-05-18 01:27:04 +02:00
|
|
|
}
|
|
|
|
|
2018-10-23 23:13:13 +02:00
|
|
|
protected boolean isInteger(String string) {
|
2016-11-25 13:07:02 +01:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-10-23 23:13:13 +02:00
|
|
|
protected abstract void sendCommandUsage(CommandSender sender, DisguisePermissions disguisePermissions);
|
2016-05-18 01:27:04 +02:00
|
|
|
}
|