Пример #1
0
  public void reset() {
    SimpleCommandMap cmap = MagicStuff.getCommandMap();
    Map<String, org.bukkit.command.Command> rcmap = MagicStuff.getKnownCommandsRawMap();

    commandMap.clear();

    if (cmap == null) {
      System.err.println("Command support failed to initialize!");
      return;
    }

    for (org.bukkit.command.Command cmd : bukkitCommands) {
      rcmap.remove(cmd.getName());
      cmd.unregister(cmap);
    }
    bukkitCommands.clear();
  }
Пример #2
0
  @Override
  public ScriptLineHandler handleLine(ScriptLine line, boolean hasChildren) {
    SimpleCommandMap cmap = MagicStuff.getCommandMap();

    String[] commandSpec = line.line.split("\\s+");
    String name = commandSpec[0];
    Argument[] args;
    boolean catchAll = false;
    String catchAllName = null;

    if (commandSpec.length > 1 && commandSpec[commandSpec.length - 1].startsWith("*")) {
      catchAll = true;
      if (commandSpec[commandSpec.length - 1].length() > 1)
        catchAllName = commandSpec[commandSpec.length - 1].substring(1);
      args = new Argument[commandSpec.length - 2];
    } else args = new Argument[commandSpec.length - 1];

    StringBuilder logSB = new StringBuilder();

    for (int i = 1; i < commandSpec.length - (catchAll ? 1 : 0); i++) {
      Argument arg = Argument.get(commandSpec[i]);
      if (arg == null) {
        LogUtil.error(
            "Please prefix command arguments with # for number, & for player, % for any word, or [a-z] for a specific word, not "
                + commandSpec[i].substring(0, 1));
        //				failed = true;
        //				continue entryLoop;
        return null;
      }
      args[i - 1] = arg;
      logSB.append(" " + arg.name + "(" + arg.type + ")");
    }
    if (catchAll) {
      logSB.append(" *");
      if (catchAllName != null) logSB.append(catchAllName);
    }

    CommandInfo command = new CommandInfo(name, args, catchAll, catchAllName);
    LogUtil.info("Command [" + command.name + "]: " + logSB.toString());
    //		command.routines = RoutineAliaser.parseRoutines(commandEntry.getValue(), command.eventInfo);
    //		if (command.routines == null)
    //		{
    //			failed = true;
    //			continue;
    //		}

    List<CommandInfo> cmds = commandMap.get(name);
    if (cmds == null) {
      cmds = new ArrayList<CommandInfo>();
      commandMap.put(name, cmds);
    }
    cmds.add(command);

    // only add command interceptor the first time
    if (cmds.size() == 1) {
      MDCommand mdcommand = new MDCommand(command.name);
      cmap.register("md", mdcommand);
      bukkitCommands.add(mdcommand);
    }

    return command.routines.getLineHandler(command.eventInfo);
  }