@Override protected Object getValue(String choice) throws IllegalArgumentException { Optional<WorldProperties> ret = Sponge.getGame().getServer().getWorldProperties(choice); if (!ret.isPresent()) { throw new IllegalArgumentException("Provided argument " + choice + " did not match a WorldProperties"); } return ret.get(); } }
@JsonIgnore @ApiModelProperty(hidden = true) public Optional<WorldProperties> getLiveProps() { return Sponge.getServer().getWorldProperties(uuid); }
@Override protected Object getValue(String choice) throws IllegalArgumentException { Optional<WorldProperties> ret = Sponge.getGame().getServer().getWorldProperties(choice); if (!ret.isPresent()) { throw new IllegalArgumentException("Provided argument " + choice + " did not match a WorldProperties"); } return ret.get(); } }
@Override public DataView update(DataView content) { if (!content.contains(Home.WORLD_QUERY, Home.POSITION_QUERY)) { throw new InvalidDataException("Invalid data for a home!"); } UUID uuid = content.getObject(Home.WORLD_QUERY, UUID.class).get(); Vector3d pos = content.getObject(Home.POSITION_QUERY, Vector3d.class).get(); String name = Sponge.getServer().getWorldProperties(uuid) .map(WorldProperties::getWorldName) .orElse(uuid.toString().substring(0, 9)); name = String.format("%s-%d,%d,%d", name, pos.getFloorX(), pos.getFloorY(), pos.getFloorZ()); content.set(Home.NAME_QUERY, name); return content; } }
/** * Gets a specific world by UUID. * * @param uuid The UUID of the world. * @return An optional containing the world, or empty if not found. */ public Optional<CachedWorld> getWorld(UUID uuid) { if (!worlds.containsKey(uuid)) { return Optional.empty(); } final CachedWorld res = worlds.get(uuid); if (res.isExpired()) { return Optional.of(WebAPI.runOnMain(() -> { Optional<World> world = Sponge.getServer().getWorld(uuid); if (world.isPresent()) return updateWorld(world.get()); Optional<WorldProperties> props = Sponge.getServer().getWorldProperties(uuid); if (!props.isPresent()) throw new InternalServerErrorException("Could not get world properties"); return updateWorld(props.get()); })); } else { return Optional.of(res); } }