/
area/
classes/net/sourceforge/pain/logic/
classes/net/sourceforge/pain/logic/event/
classes/net/sourceforge/pain/logic/fn/util/
classes/net/sourceforge/pain/network/console/
classes/net/sourceforge/pain/plugin/
classes/net/sourceforge/pain/plugin/reset/
classes/net/sourceforge/pain/plugin/shutdown/
classes/net/sourceforge/pain/plugin/social/
classest/net/sourceforge/pain/db/data/
doc/
doc/paindb/resources/
src/net/sourceforge/pain/logic/
src/net/sourceforge/pain/logic/event/
src/net/sourceforge/pain/logic/fn/util/
src/net/sourceforge/pain/network/console/
src/net/sourceforge/pain/network/console/telnet/
src/net/sourceforge/pain/plugin/
src/net/sourceforge/pain/plugin/command/
src/net/sourceforge/pain/plugin/reset/
src/net/sourceforge/pain/plugin/shutdown/
src/net/sourceforge/pain/plugin/social/
src/net/sourceforge/pain/util/
tests/
tests/net/sourceforge/pain/db/data/
package net.sourceforge.pain.logic.event.console.command;

import net.sourceforge.pain.data.type.*;
import net.sourceforge.pain.logic.event.console.*;
import net.sourceforge.pain.logic.fn.*;
import net.sourceforge.pain.logic.fn.util.*;
import net.sourceforge.pain.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.getName());
		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);
	}
}