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()); } }
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; }
@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()); } } }