public static CommandBlockerRank fromToken(String token) { for (CommandBlockerRank rank : CommandBlockerRank.values()) { if (rank.getToken().equalsIgnoreCase(token)) { return rank; } } return ANYONE; }
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."); }