package me.libraryaddict.disguise.commands; import me.libraryaddict.disguise.utilities.parser.DisguiseParser; import me.libraryaddict.disguise.utilities.parser.DisguisePerm; import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; import org.bukkit.scoreboard.Team; import java.util.*; /** * @author libraryaddict */ public abstract class DisguiseBaseCommand implements CommandExecutor { protected ArrayList filterTabs(ArrayList list, String[] origArgs) { if (origArgs.length == 0) return list; Iterator 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(); } return new ArrayList<>(new HashSet<>(list)); } protected String getDisplayName(CommandSender player) { Team team = ((Player) player).getScoreboard().getEntryTeam(player.getName()); return (team == null ? "" : team.getPrefix()) + player.getName() + (team == null ? "" : team.getSuffix()); } protected ArrayList getAllowedDisguises( HashMap, Boolean>> hashMap) { ArrayList allowedDisguises = new ArrayList<>(); for (DisguisePerm type : hashMap.keySet()) { if (type.isUnknown()) continue; allowedDisguises.add(type.toReadable().replaceAll(" ", "_")); } Collections.sort(allowedDisguises, String.CASE_INSENSITIVE_ORDER); return allowedDisguises; } protected String[] getArgs(String[] args) { ArrayList newArgs = new ArrayList<>(); 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]); } public final String getPermNode() { if (this instanceof DisguiseCommand) { return "disguise"; } else if (this instanceof DisguiseEntityCommand) { return "disguiseentity"; } else if (this instanceof DisguisePlayerCommand) { return "disguiseplayer"; } else if (this instanceof DisguiseRadiusCommand) { return "disguiseradius"; } else if (this instanceof DisguiseModifyCommand) { return "disguisemodify"; } else if (this instanceof DisguiseModifyEntityCommand) { return "disguisemodifyentity"; } else if (this instanceof DisguiseModifyPlayerCommand) { return "disguisemodifyplayer"; } else if (this instanceof DisguiseModifyRadiusCommand) { return "disguisemodifyradius"; } else { throw new UnsupportedOperationException("Unknown disguise command, perm node not found"); } } protected HashMap, Boolean>> getPermissions(CommandSender sender) { return DisguiseParser.getPermissions(sender, "libsdisguises." + getPermNode() + "."); } protected boolean isNumeric(String string) { try { Integer.parseInt(string); return true; } catch (Exception ex) { return false; } } public boolean passesCheck(CommandSender sender, HashMap, Boolean> theirPermissions, ArrayList usedOptions) { return DisguiseParser.passesCheck(sender, theirPermissions, usedOptions); } protected abstract void sendCommandUsage(CommandSender sender, HashMap, Boolean>> map); }