/
codebase/src/net/sourceforge/pain/admin/console/command/
codebase/src/net/sourceforge/pain/data/role/
codebase/src/net/sourceforge/pain/network/console/telnet/
codebase/src/net/sourceforge/pain/network/guitool/
codebase/src/net/sourceforge/pain/plugin/
codebase/src/net/sourceforge/pain/util/
db/src/net/sourceforge/pain/util/
gui/
gui/lib/
gui/src/net/sourceforge/pain/tools/guitool/dbbrowse/
gui/src/net/sourceforge/pain/tools/guitool/dialog/
gui/src/net/sourceforge/pain/tools/guitool/menu/
gui/src/net/sourceforge/pain/tools/guitool/resources/
gui/src/net/sourceforge/pain/tools/guitool/resources/images/
gui/src/net/sourceforge/pain/tools/guitool/resources/images/explorer/
mudlibs/tinylib/
mudlibs/tinylib/area/
mudlibs/tinylib/etc/
mudlibs/tinylib/src/net/sourceforge/pain/tinylib/
mudlibs/tinylib/src/net/sourceforge/pain/tinylib/data/affect/
mudlibs/tinylib/src/net/sourceforge/pain/tinylib/data/prototype/
mudlibs/tinylib/src/net/sourceforge/pain/tinylib/data/trigger/
mudlibs/tinylib/src/net/sourceforge/pain/tinylib/logic/affect/
mudlibs/tinylib/src/net/sourceforge/pain/tinylib/logic/event/
mudlibs/tinylib/src/net/sourceforge/pain/tinylib/logic/event/deploy/
mudlibs/tinylib/src/net/sourceforge/pain/tinylib/logic/event/guitool/
mudlibs/tinylib/src/net/sourceforge/pain/tinylib/logic/event/guitool/event/
mudlibs/tinylib/src/net/sourceforge/pain/tinylib/logic/fn/util/
mudlibs/tinylib/src/net/sourceforge/pain/tinylib/logic/trigger/
mudlibs/tinylib/src/net/sourceforge/pain/tinylib/logic/trigger/impl/
mudlibs/tinylib/src/net/sourceforge/pain/tinylib/plugin/command/
mudlibs/tinylib/src/net/sourceforge/pain/tinylib/plugin/reset/
mudlibs/tinylib/src/net/sourceforge/pain/tinylib/plugin/shutdown/
mudlibs/tinylib/src/net/sourceforge/pain/tinylib/plugin/social/
mudlibs/tinylib/src/net/sourceforge/pain/tinylib/util/
tests/
tests/src/
tests/src/net/sourceforge/pain/db/data/
package net.sourceforge.pain.tinylib.logic.event.console.command;

import net.sourceforge.pain.tinylib.data.type.*;
import net.sourceforge.pain.tinylib.logic.event.console.*;
import net.sourceforge.pain.tinylib.logic.fn.*;
import net.sourceforge.pain.tinylib.logic.fn.util.*;
import net.sourceforge.pain.tinylib.plugin.command.*;

import java.util.*;

public final class ShowGrants extends GrantedCommand {

    public void processCommand() {
        String playerName = commandParams;
        if (playerName == null) {
            showHelp();
            return;
        }
        final Player target = ("self".equals(playerName)) ? player : GlobalFindFn.findPlayerByName(playerName);
        if (target == null) {
            MessageOutFn.outln(console, "No player found with name {c" + Utils.formatName(playerName) + "{x");
            return;
        }
        boolean granted = isShowGrants();
        final Set commandsSet = granted ? target.getGrantedCommands() : target.getRejectedCommands();
        MessageOutFn.outln(console, (granted ? "Granted" : "Rejected") + " commands for " + target.getInteractiveName());
        if (commandsSet.isEmpty()) {
            MessageOutFn.outln(console, "Not found.");
        } else if (commandsSet.contains("_all")) {
            // only implementor has grant "_all".
            // Using this constant we simplify initial world creation script.
            MessageOutFn.outln(console, "All available commands allowed!");
        } else {
            CommandMapper commandMapper = ConsoleInputEvent.getCommandMapper();
            StringBuffer b = new StringBuffer(100);
            for (Iterator it = commandsSet.iterator(); it.hasNext();) {
                b.delete(0, b.length());
                String commandClass = (String) it.next();
                Set commands = commandMapper.getAllCommandsForClassName(commandClass);
                if (commands == null || commands.isEmpty()) {
                    b.append("No command names mapped");
                } else {
                    for (Iterator it2 = commands.iterator(); it2.hasNext();) {
                        String commandName = (String) it2.next();
                        if (b.length() > 0) {
                            b.append(", ");
                        }
                        b.append("{c").append(commandName).append("{x");
                    }
                }
                MessageOutFn.outln(console, "Class: {c" + commandClass + "{x Commands:" + b);
            }
            final int n = commandsSet.size();
            MessageOutFn.outln(console, "Found: " + n + " unique " + LangUtil.s(n, "command") + " in list");
        }

    }

    public void showHelp() {
        if (isShowGrants()) {
            MessageOutFn.outln(console, command.name + ": shows granted commands to player");
            MessageOutFn.outln(console, "Usage: " + command.name + " <player_name> ");
        } else { // REJECTS
            MessageOutFn.outln(console, command.name + ": shows rejected to player commands");
            MessageOutFn.outln(console, "Usage: " + command.name + " <player_name> ");

        }
    }

    private boolean isShowGrants() {
        return "GRANTS".equals(command.tag);
    }
}