Example #1
0
 private void printWorldList(CommandSender sender, String world) {
   ChipFilter f = new WorldFilter();
   try {
     f.parse(sender, new String[] {world});
     printCircuitList(sender, f.filter(rc.chipManager().getAllChips().values()), null);
   } catch (IllegalArgumentException ie) {
     error(sender, ie.getMessage());
   }
 }
Example #2
0
  private Collection<Chip> filterCircuits(Collection<Chip> values, List<ChipFilter> filters) {
    Collection<Chip> chips = new ArrayList<>();
    chips.addAll(values);

    for (ChipFilter filter : filters) {
      chips = filter.filter(chips);
    }

    return chips;
  }
Example #3
0
  @Override
  public void run(CommandSender sender, Command command, String label, String[] args) {
    List<ChipFilter> filters = new ArrayList<>();
    if (args.length == 0) { // when player, list all chips in world. else, list all chips on server.
      if (sender instanceof Player) {
        printWorldList(sender, "this");
      } else printCircuitList(sender, rc.chipManager().getAllChips().values(), null);

    } else if (args.length == 1 && args[0].equalsIgnoreCase("all")) {
      printCircuitList(sender, rc.chipManager().getAllChips().values(), null);
    } else if (args.length == 1 && !(args[0].contains(":") || args[0].contains(";"))) {
      ChipFilter f = new WorldFilter();
      try {
        f.parse(sender, new String[] {args[0]});
        printCircuitList(sender, f.filter(rc.chipManager().getAllChips().values()), null);
      } catch (IllegalArgumentException ie) {
        error(sender, ie.getMessage());
      }
    } else {
      StringBuilder concat = new StringBuilder();
      for (String arg : args) concat.append(arg).append(" ");

      String sfilters = concat.toString().trim();
      String[] afilters = new Tokenizer(sfilters, ';').getTokens();

      try {
        for (String sf : afilters) {
          ChipFilter f = parseFilter(sender, sf);
          filters.add(f);
        }

        Collection<Chip> chips = filterCircuits(rc.chipManager().getAllChips().values(), filters);
        TreeMap<Integer, Chip> sorted = new TreeMap<>();
        for (Chip c : chips) sorted.put(c.id, c);
        if (chips.isEmpty()) info(sender, "There are no active chips that match the criteria.");
        else {
          printCircuitList(sender, sorted.values(), null);
        }
      } catch (IllegalArgumentException ie) {
        error(sender, ie.getMessage());
      }
    }
  }
Example #4
0
  private ChipFilter parseFilter(CommandSender sender, String sf) throws IllegalArgumentException {
    int colonIdx = sf.indexOf(":");
    if (colonIdx == -1) throw new IllegalArgumentException("Bad filter syntax: " + sf);

    String type = sf.substring(0, colonIdx).trim().toLowerCase();

    if (type.length() <= 1) throw new IllegalArgumentException("Bad filter syntax: " + sf);

    ChipFilter f;

    if ("location".startsWith(type)) {
      f = new LocationFilter();
    } else if ("chunk".startsWith(type)) {
      f = new ChunkFilter();
    } else if ("class".startsWith(type)) {
      f = new TypeFilter();
    } else throw new IllegalArgumentException("Unknown filter type: " + type);

    f.parse(sender, tokenizeFilter(sf.substring(colonIdx + 1)));

    return f;
  }