public static void unregisterCommand(String commandName) {
   CommandMap commandMap = getCommandMap();
   if (commandMap != null) {
     Command command = commandMap.getCommand(commandName.toLowerCase());
     if (command != null) {
       unregisterCommand(command, commandMap);
     }
   }
 }
Esempio n. 2
0
 /**
  * Get a command, include server commands [subject to change].
  *
  * @param alias
  * @return
  */
 public static Command getCommand(final String alias) {
   final String lcAlias = alias.trim().toLowerCase();
   final CommandMap map = getCommandMap();
   if (map != null) {
     return map.getCommand(lcAlias);
   } else {
     // TODO: maybe match versus plugin commands.
     return null;
   }
 }
  public static void scan() {
    CommandMap commandMap = getCommandMap();
    if (commandMap == null) {
      TFM_Log.severe("Error loading commandMap.");
      return;
    }
    COMMAND_LIST.clear();
    COMMAND_LIST.addAll(getCommands());

    for (TFM_CommandInfo commandInfo : COMMAND_LIST) {
      TFM_DynamicCommand dynamicCommand = new TFM_DynamicCommand(commandInfo);

      Command existing = commandMap.getCommand(dynamicCommand.getName());
      if (existing != null) {
        unregisterCommand(existing, commandMap);
      }

      commandMap.register(TotalFreedomMod.plugin.getDescription().getName(), dynamicCommand);
    }

    TFM_Log.info("TFM commands loaded.");
  }
  public final void load() {
    blockedCommands.clear();

    final CommandMap commandMap = TFM_CommandLoader.getInstance().getCommandMap();
    if (commandMap == null) {
      TFM_Log.severe("Error loading commandMap.");
      return;
    }

    List<String> _blockedCommands = (List<String>) TFM_ConfigEntry.BLOCKED_COMMANDS.getList();
    for (String rawEntry : _blockedCommands) {
      final String[] parts = rawEntry.split(":");
      if (parts.length < 3 || parts.length > 4) {
        continue;
      }

      final CommandBlockerRank rank = CommandBlockerRank.fromToken(parts[0]);
      if (rank == null) {
        continue;
      }

      final CommandBlockerAction action = CommandBlockerAction.fromToken(parts[1]);
      if (action == null) {
        continue;
      }

      String command = parts[2];
      if (command == null || command.isEmpty()) {
        continue;
      }
      final Matcher matcher = COMMAND_PATTERN.matcher(command);
      if (matcher.find()) {
        command = matcher.group(1);
        if (command == null) {
          continue;
        } else {
          command = command.toLowerCase().trim();
        }
      } else {
        continue;
      }

      String message = null;
      if (parts.length == 4) {
        message = parts[3];
      }

      final CommandBlockerEntry blockedCommandEntry =
          new CommandBlockerEntry(rank, action, command, message);

      final Command bukkitCommand = commandMap.getCommand(command);
      if (bukkitCommand == null) {
        // TFM_Log.info("Blocking unknown command: " + blockedCommandEntry.getCommand());
        blockedCommands.put(blockedCommandEntry.getCommand(), blockedCommandEntry);
      } else {
        blockedCommandEntry.setCommand(bukkitCommand.getName().toLowerCase());

        // TFM_Log.info("Blocking command: " + blockedCommandEntry.getCommand());
        blockedCommands.put(blockedCommandEntry.getCommand(), blockedCommandEntry);

        for (String alias : bukkitCommand.getAliases()) {
          // TFM_Log.info("Blocking alias: " + alias.toLowerCase() + " of " +
          // blockedCommandEntry.getCommand());
          blockedCommands.put(alias.toLowerCase(), blockedCommandEntry);
        }
      }
    }

    TFM_Log.info("Loaded " + blockedCommands.size() + " blocked commands.");
  }