Ejemplo n.º 1
0
    public Type matchAlias(String key) {
      if (hasAlias(key)) return getAlias(key);

      Type value = matchNonAlias(key);
      LogUtil.error("No matching " + name + " alias or value \"" + key + "\"");
      return value;
    }
Ejemplo n.º 2
0
    // @Override
    public Collection<InfoType> matchAlias(String key) {
      if (hasAlias(key)) return getAlias(key);

      boolean failFlag = false;
      List<InfoType> values = new ArrayList<InfoType>();
      if (key != null) {
        for (String valueString : key.split(",")) {
          InfoType value = matchNonAlias(valueString);
          if (value != null) values.add(value);
          else failFlag = true;
        }
      }
      if (!failFlag && !values.isEmpty()) return values;
      LogUtil.error("No matching " + name + " alias or value \"" + key + "\"");
      return getDefaultValue();
    }
Ejemplo n.º 3
0
    @Override
    public IRoutineBuilder getNew(Matcher matcher, ScriptLine scriptLine, EventInfo info) {
      boolean nearest = matcher.group(1).equalsIgnoreCase("est");
      IDataProvider<Entity> entityDP = DataProvider.parse(info, Entity.class, matcher.group(2));
      if (entityDP == null) return null;
      EntityType element = EntityType.getElementNamed(matcher.group(3));
      if (element == null) return null;
      IDataProvider<Integer> radius = DataProvider.parse(info, Integer.class, matcher.group(4));
      if (radius == null) return null;

      LogUtil.info(
          "Near" + (nearest ? "est" : "by") + ": " + entityDP + ", " + element + ", " + radius);

      EventInfo einfo = info.chain(myInfo);

      Nearby routine = new Nearby(scriptLine, nearest, entityDP, element, radius);
      return new NestedRoutineBuilder(routine, routine.routines, einfo);
    }
Ejemplo n.º 4
0
    @SuppressWarnings("unchecked")
    @Override
    public IRoutineBuilder getNew(Matcher matcher, ScriptLine scriptLine, EventInfo info) {
      StringMatcher sm = new StringMatcher(matcher.group(2));

      Taggable<?> taggable = Taggable.get(DataProvider.parse(info, null, sm.spawn()), info);
      if (taggable == null) return null;

      if (!sm.matchesFront(dotPattern)) return null;

      IDataProvider<String> tagNameDP =
          InterpolatedString.parseWord(InterpolatedString.word, sm.spawn(), info);
      if (tagNameDP == null) return null;

      if (!sm.isEmpty()) return null;

      Tag<?> tag = Tag.get(tagNameDP, matcher.group(1));
      if (tag == null) return null;

      LogUtil.info("Un" + matcher.group(1) + "tag: \"" + tag + "\" on " + taggable);
      return new RoutineBuilder(new Untag(scriptLine, tag, taggable));
    }
Ejemplo n.º 5
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);
  }