@Override protected Iterable<String> getChoices(CommandSource source) { return Sponge.getGame().getServer().getAllWorldProperties().stream() .map(input -> input.getWorldName()) .collect(Collectors.toList()); }
@Nullable @Override public Object parseValue(CommandSource source, CommandArgs args) throws ArgumentParseException { final String next = args.peek(); if (next.startsWith("#")) { String specifier = next.substring(1); if (specifier.equalsIgnoreCase("first")) { args.next(); return Sponge.getGame().getServer().getAllWorldProperties().stream().filter(input -> input != null && input.isEnabled()) .collect(Collectors.toList()).iterator().next(); } else if (specifier.equalsIgnoreCase("me") && source instanceof Locatable) { args.next(); return ((Locatable) source).getWorld().getProperties(); } else { boolean firstOnly = false; if (specifier.endsWith(":first")) { firstOnly = true; specifier = specifier.substring(0, specifier.length() - 6); } args.next(); args.insertArg(specifier); @SuppressWarnings("unchecked") final DimensionType type = ((Iterable<DimensionType>) this.dimensionTypeElement.parseValue(source, args)).iterator().next(); Iterable<WorldProperties> ret = Sponge.getGame().getServer().getAllWorldProperties().stream().filter(input -> input != null && input.isEnabled() && input.getDimensionType().equals(type)).collect(Collectors.toList()); return firstOnly ? ret.iterator().next() : ret; } } return super.parseValue(source, args); }
@Override protected Iterable<String> getChoices(CommandSource source) { return Sponge.getGame().getServer().getAllWorldProperties().stream() .map(input -> input.getWorldName()) .collect(Collectors.toList()); }
public void updateWorlds() { WebAPI.runOnMain(() -> { worlds.clear(); // The worlds that are loaded on server start are overwritten by the world load event later // TODO: Sponge has a bug that makes the "getAllWorldProperties" method cache the world properties Collection<WorldProperties> unloadedWorlds = Sponge.getServer().getAllWorldProperties(); for (WorldProperties world : unloadedWorlds) { updateWorld(world); } }); }
@Nullable @Override public Object parseValue(CommandSource source, CommandArgs args) throws ArgumentParseException { final String next = args.peek(); if (next.startsWith("#")) { String specifier = next.substring(1); if (specifier.equalsIgnoreCase("first")) { args.next(); return Sponge.getGame().getServer().getAllWorldProperties().stream().filter(input -> input != null && input.isEnabled()) .collect(Collectors.toList()).iterator().next(); } else if (specifier.equalsIgnoreCase("me") && source instanceof Locatable) { args.next(); return ((Locatable) source).getWorld().getProperties(); } else { boolean firstOnly = false; if (specifier.endsWith(":first")) { firstOnly = true; specifier = specifier.substring(0, specifier.length() - 6); } args.next(); args.insertArg(specifier); @SuppressWarnings("unchecked") final DimensionType type = ((Iterable<DimensionType>) this.dimensionTypeElement.parseValue(source, args)).iterator().next(); Iterable<WorldProperties> ret = Sponge.getGame().getServer().getAllWorldProperties().stream().filter(input -> input != null && input.isEnabled() && input.getDimensionType().equals(type)).collect(Collectors.toList()); return firstOnly ? ret.iterator().next() : ret; } } return super.parseValue(source, args); }