/** * Gets this spawn position as a {@link Location} object, if the world is * available. * * @return The position object, if available. */ public Optional<Location<World>> asLocation() { Optional<World> world = Sponge.getServer().getWorld(getWorldUniqueId()); if (!world.isPresent()) { return Optional.empty(); } return Optional.of(new Location<>(world.get(), getPosition())); }
public static org.spongepowered.api.world.Location<World> getLocation(Location location) { Collection<World> worlds = Sponge.getServer().getWorlds(); World world = Sponge.getServer().getWorld(location.getWorld()).orElse(worlds.toArray(new World[worlds.size()])[0]); return new org.spongepowered.api.world.Location<>(world, location.getX(), location.getY(), location.getZ()); }
/** * Create a Sponge world from a WorldEdit world. * * @param world the WorldEdit world * @return a Sponge world */ public static org.spongepowered.api.world.World adapt(World world) { checkNotNull(world); if (world instanceof SpongeWorld) { return ((SpongeWorld) world).getWorld(); } else { org.spongepowered.api.world.World match = Sponge.getServer().getWorld(world.getName()).orElse(null); if (match != null) { return match; } else { throw new IllegalArgumentException("Can't find a Sponge world for " + world); } } }
/** * Sets the location of this entity to a new position in a world which does * not have to be loaded (but must at least be enabled). * * <p>If the target world is loaded then this is equivalent to setting the * location via {@link TargetedLocationData}.</p> * * <p>If the target world is unloaded but is enabled according to its * {@link WorldArchetype#isEnabled()} then this will first load the world * before transferring the entity to that world.</p> * * <p>If the target world is unloaded and not enabled then the transfer * will fail.</p> * * @param uuid The UUID of the target world to transfer to * @param position The position in the target world * @return True if the teleport was successful */ default boolean transferToWorld(UUID uuid, Vector3d position) { return Sponge.getServer().getWorld(uuid) .map(world -> transferToWorld(world, position)) .orElse(false); }
/** * Sets the location of this entity to a new position in a world which does * not have to be loaded (but must at least be enabled). * * <p>If the target world is loaded then this is equivalent to * setting the location via {@link TargetedLocationData}.</p> * * <p>If the target world is unloaded but is enabled according to its * {@link WorldArchetype#isEnabled()} then this will first load the world * before transferring the entity to that world.</p> * * <p>If the target world is unloaded and not enabled then the transfer * will fail.</p> * * @param worldName The name of the world to transfer to * @param position The position in the target world * @return True if the teleport was successful */ default boolean transferToWorld(String worldName, Vector3d position) { return Sponge.getServer().getWorld(worldName) .map(world -> transferToWorld(world, position)) .orElse(false); }
Optional<World> targetWorld = Sponge.getGame().getServer().getWorld(targetWorldProps.getUniqueId()); Vector3d vector = (Vector3d) vec; return new Location<>(targetWorld.get(), vector);
@Override public Optional<World> getLive() { return Sponge.getServer().getWorld(uuid); }
public static World getWorld(String world) { if (StringMan.isEqual(world, last)) { return lastWorld; } Optional<World> optional = Sponge.getServer().getWorld(world); if (!optional.isPresent()) { last = null; return lastWorld = null; } last = world; return lastWorld = optional.get(); }
public static Location<World> locationFromString(String string) { String[] parts = RegexUtil.COMMA_PATTERN.split(string); if(parts.length < 4) return null; World world = Sponge.getGame().getServer().getWorld(parts[0]).orElse(null); if(world == null) return null; double x = Double.parseDouble(parts[1]); double y = Double.parseDouble(parts[2]); double z = Double.parseDouble(parts[3]); return world.getLocation(x, y, z); }
@Override public void unload(String worldName, boolean safe) { Optional<World> world = Sponge.getServer().getWorld(worldName); if (world.isPresent()) { Sponge.getServer().unloadWorld(world.get()); } }
/** * Gets this spawn position as a {@link Location} object, if the world is * available. * * @return The position object, if available. */ public Optional<Location<World>> asLocation() { Optional<World> world = Sponge.getServer().getWorld(getWorldUniqueId()); if (!world.isPresent()) { return Optional.empty(); } return Optional.of(new Location<>(world.get(), getPosition())); }
@Override public Optional<Chunk> getLive() { if (world.isLoaded()) { return Sponge.getServer().getWorld(uuid).flatMap(w -> w.getChunk(pos)); } else { return Optional.empty(); } }
@Override public boolean worldExist(String worldName) { return ((SpongeLoader)loader).getGame().getServer().getWorld(worldName) != null; }
/** * Sets the location of this entity to a new position in a world which does * not have to be loaded (but must at least be enabled). * * <p>If the target world is loaded then this is equivalent to * setting the location via {@link TargetedLocationData}.</p> * * <p>If the target world is unloaded but is enabled according to its * {@link WorldArchetype#isEnabled()} then this will first load the world * before transferring the entity to that world.</p> * * <p>If the target world is unloaded and not enabled then the transfer * will fail.</p> * * @param worldName The name of the world to transfer to * @param position The position in the target world * @return True if the teleport was successful */ default boolean transferToWorld(String worldName, Vector3d position) { return Sponge.getServer().getWorld(worldName) .map(world -> transferToWorld(world, position)) .orElse(false); }
/** * Sets the location of this entity to a new position in a world which does * not have to be loaded (but must at least be enabled). * * <p>If the target world is loaded then this is equivalent to * setting the location via {@link TargetedLocationData}.</p> * * <p>If the target world is unloaded but is enabled according to its * {@link WorldArchetype#isEnabled()} then this will first load the world * before transferring the entity to that world.</p> * * <p>If the target world is unloaded and not enabled then the transfer * will fail.</p> * * @param uuid The UUID of the target world to transfer to * @param position The position in the target world * @return True if the teleport was successful */ default boolean transferToWorld(UUID uuid, Vector3d position) { return Sponge.getServer().getWorld(uuid) .map(world -> transferToWorld(world, position)) .orElse(false); }
@Override protected Optional<Home> buildContent(DataView content) throws InvalidDataException { if (!content.contains(Home.WORLD_QUERY, Home.POSITION_QUERY, Home.ROTATION_QUERY, Home.NAME_QUERY)) { return Optional.empty(); } World world = Sponge.getServer().getWorld(content.getObject(Home.WORLD_QUERY, UUID.class).get()).orElseThrow(InvalidDataException::new); Vector3d position = content.getObject(Home.POSITION_QUERY, Vector3d.class).get(); Vector3d rotation = content.getObject(Home.ROTATION_QUERY, Vector3d.class).get(); String name = content.getString(Home.NAME_QUERY).get(); Transform<World> transform = new Transform<>(world, position, rotation); return Optional.of(new Home(transform, name)); }
public static Location<World> toSponge(SerializedBlockLocation location) { Optional<World> world = Sponge.getServer().getWorld(UUID.fromString(location.getWorld())); if (!world.isPresent()) { throw new IllegalStateException(); } return new Location<>(world.get(), location.getX(), location.getY(), location.getZ()); } }
public Optional<Location<World>> getSpawnLocation() { Server server = Sponge.getServer(); if (worldName == null) { worldName = server.getDefaultWorldName(); } return server.getWorld(worldName).map(world -> { if (defaultSpawn) { return world.getSpawnLocation(); } return world.getLocation(coordX, coordY, coordZ); }); } }
@Override public Home translate(final DataView content) throws InvalidDataException { content.getInt(Queries.CONTENT_VERSION).ifPresent(version -> { if (version != CONTENT_VERSION) { throw new InvalidDataException("Version incompatible: " + version); } }); if (!content.contains(Home.WORLD_QUERY, Home.POSITION_QUERY, Home.ROTATION_QUERY, Home.NAME_QUERY)) { throw new InvalidDataException("Incomplete data"); } World world = Sponge.getServer().getWorld(content.getObject(Home.WORLD_QUERY, UUID.class).get()) .orElseThrow(InvalidDataException::new); Vector3d position = content.getObject(Home.POSITION_QUERY, Vector3d.class).get(); Vector3d rotation = content.getObject(Home.ROTATION_QUERY, Vector3d.class).get(); String name = content.getString(Home.NAME_QUERY).get(); Transform<World> transform = new Transform<>(world, position, rotation); return new Home(transform, name); }
public void onChangeBlock(ChangeBlockEvent event) { List<Transaction<BlockSnapshot>> transactions = event.getTransactions(); Transaction<BlockSnapshot> first = transactions.get(0); BlockSnapshot original = first.getOriginal(); Optional<World> world = SpongeMain.THIS.getServer().getWorld(original.getWorldUniqueId()); String worldName = world.get().getName(); Location loc = SpongeUtil.getLocation(worldName, original.getPosition()); PlotArea area = loc.getPlotArea(); if (area == null) { return; } Plot plot = area.getPlot(loc); if (plot == null) { if (!loc.isPlotArea()) { return; } event.setCancelled(true); return; } event.filter(loc1 -> !SpongeUtil.getLocation(worldName, loc1).isPlotRoad()); }