Esempio n. 1
0
 @Override
 public List<String> onTabComplete(
     CommandSender commandSender, Command command, String s, String[] strings) {
   if (commandSender instanceof Player
       && !Permissions.has((Player) commandSender, "MyPet.admin", false)) {
     return emptyList;
   }
   if (strings.length == 1) {
     if (optionsList.size() != commandOptions.keySet().size()) {
       optionsList = new ArrayList<>(commandOptions.keySet());
       Collections.sort(optionsList);
     }
     return optionsList;
   } else if (strings.length >= 1) {
     CommandOption co = commandOptions.get(strings[0]);
     if (co != null) {
       if (co instanceof CommandOptionTabCompleter) {
         return ((CommandOptionTabCompleter) co).onTabComplete(commandSender, strings);
       }
     }
   }
   return emptyList;
 }
Esempio n. 2
0
public class CommandAdmin implements CommandExecutor, TabCompleter {
  private static List<String> optionsList = new ArrayList<>();
  public static final List<String> emptyList =
      Collections.unmodifiableList(new ArrayList<String>());
  private static Map<String, CommandOption> commandOptions = new HashMap<>();

  public CommandAdmin() {
    commandOptions.put("name", new CommandOptionName());
    commandOptions.put("exp", new CommandOptionExp());
    commandOptions.put("respawn", new CommandOptionRespawn());
    commandOptions.put("reload", new CommandOptionReload());
    commandOptions.put("reloadskills", new CommandOptionReloadSkilltrees());
    commandOptions.put("skilltree", new CommandOptionSkilltree());
    commandOptions.put("create", new CommandOptionCreate());
    commandOptions.put("clone", new CommandOptionClone());
    commandOptions.put("remove", new CommandOptionRemove());
    commandOptions.put("cleanup", new CommandOptionCleanup());
    commandOptions.put("ticket", new CommandOptionTicket());
    commandOptions.put("switch", new CommandOptionSwitch());
    // commandOptions.put("test", new CommandOptionTest());

    commandOptions.put(
        "build",
        new CommandOption() {
          @Override
          public boolean onCommandOption(CommandSender sender, String[] parameter) {
            DebugLogger.info(
                "MyPet-" + MyPetVersion.getVersion() + "-b#" + MyPetVersion.getBuild());
            sender.sendMessage(
                "["
                    + ChatColor.AQUA
                    + "MyPet"
                    + ChatColor.RESET
                    + "] MyPet-"
                    + MyPetVersion.getVersion()
                    + "-b#"
                    + MyPetVersion.getBuild());
            return true;
          }
        });
  }

  public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
    if (sender instanceof Player) {
      if (!Permissions.has((Player) sender, "MyPet.admin", false)) {
        return true;
      }
    }

    if (args.length < 1) {
      sender.sendMessage(MyPetPlugin.getPlugin().getCommand("mypetadmin").getDescription());
      return false;
    }

    String[] parameter = Arrays.copyOfRange(args, 1, args.length);
    CommandOption option = commandOptions.get(args[0].toLowerCase());

    if (option != null) {
      return option.onCommandOption(sender, parameter);
    }
    return false;
  }

  @Override
  public List<String> onTabComplete(
      CommandSender commandSender, Command command, String s, String[] strings) {
    if (commandSender instanceof Player
        && !Permissions.has((Player) commandSender, "MyPet.admin", false)) {
      return emptyList;
    }
    if (strings.length == 1) {
      if (optionsList.size() != commandOptions.keySet().size()) {
        optionsList = new ArrayList<>(commandOptions.keySet());
        Collections.sort(optionsList);
      }
      return optionsList;
    } else if (strings.length >= 1) {
      CommandOption co = commandOptions.get(strings[0]);
      if (co != null) {
        if (co instanceof CommandOptionTabCompleter) {
          return ((CommandOptionTabCompleter) co).onTabComplete(commandSender, strings);
        }
      }
    }
    return emptyList;
  }
}