package me.libraryaddict.disguise.commands; import me.libraryaddict.disguise.DisguiseConfig; import me.libraryaddict.disguise.utilities.LibsMsg; import me.libraryaddict.disguise.utilities.LibsPremium; import org.bukkit.Bukkit; import org.bukkit.ChatColor; import org.bukkit.command.Command; import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandSender; import org.bukkit.command.TabCompleter; import java.util.ArrayList; import java.util.Iterator; import java.util.List; public class LibsDisguisesCommand implements CommandExecutor, TabCompleter { 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 list; } 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]); } @Override public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { if (args.length == 0) { sender.sendMessage(ChatColor.DARK_GREEN + "This server is running " + "Lib's Disguises v" + Bukkit.getPluginManager().getPlugin("LibsDisguises").getDescription().getVersion() + " by libraryaddict, formerly maintained " + "by Byteflux and NavidK0." + (sender.hasPermission("libsdisguises.reload") ? "\nUse " + ChatColor.GREEN + "/libsdisguises " + "reload" + ChatColor.DARK_GREEN + " to reload the config. All disguises will be blown by doing this" + "." : "")); if (LibsPremium.isPremium()) { sender.sendMessage(ChatColor.DARK_GREEN + "This server supports the plugin developer!"); } } else if (args.length > 0) { if (sender.hasPermission("libsdisguises.reload")) { if (args[0].equalsIgnoreCase("reload")) { DisguiseConfig.loadConfig(); sender.sendMessage(LibsMsg.RELOADED_CONFIG.get()); return true; } else { sender.sendMessage(LibsMsg.LIBS_RELOAD_WRONG.get()); } } else { sender.sendMessage(LibsMsg.NO_PERM.get()); } } return true; } @Override public List onTabComplete(CommandSender sender, Command cmd, String label, String[] origArgs) { ArrayList tabs = new ArrayList<>(); String[] args = getArgs(origArgs); if (args.length == 0) tabs.add("Reload"); return filterTabs(tabs, origArgs); } }