/** * Sets the location of this entity using a safe one from * {@link TeleportHelper#getSafeLocation(Location)}. This is equivalent to a * teleport and also moves this entity's passengers. * * @param location The location to set * @return True if location was set successfully, false if location couldn't * be set as no safe location was found or * {@link org.spongepowered.api.event.entity.MoveEntityEvent.Teleport} * was cancelled. */ default boolean setLocationSafely(Location<World> location) { return Sponge.getGame().getTeleportHelper() .getSafeLocation(location) .map(this::setLocation) .orElse(false); }
/** * Sets the location using a safe one from * {@link TeleportHelper#getSafeLocation(Location)} and the rotation of this * entity. * * <p>The format of the rotation is represented by:</p> * * <p>{@code x -> pitch}, {@code y -> yaw}, {@code z -> roll}</p> * * @param location The location to set * @param rotation The rotation to set * @return True if location was set successfully, false if either location * couldn't be set as no safe location was found or * {@link org.spongepowered.api.event.entity.MoveEntityEvent.Teleport} * was cancelled */ default boolean setLocationAndRotationSafely(Location<World> location, Vector3d rotation) { return Sponge.getGame().getTeleportHelper() .getSafeLocation(location) .map(safe -> this.setLocationAndRotation(safe, rotation)) .orElse(false); }
/** * Sets the location using a safe one from * {@link TeleportHelper#getSafeLocation(Location)} and the rotation of this * entity. {@link RelativePositions} listed inside the EnumSet are * considered relative. * * <p>The format of the rotation is represented by:</p> * * <p>{@code x -> pitch}, {@code y -> yaw}, {@code z -> roll}</p> * * @param location The location to set * @param rotation The rotation to set * @param relativePositions The coordinates to set relatively * @return True if location was set successfully, false if either location * couldn't be set as no safe location was found or * {@link org.spongepowered.api.event.entity.MoveEntityEvent.Teleport} * was cancelled */ default boolean setLocationAndRotationSafely(Location<World> location, Vector3d rotation, EnumSet<RelativePositions> relativePositions) { return Sponge.getGame().getTeleportHelper() .getSafeLocation(location) .map(safe -> this.setLocationAndRotation(safe, rotation, relativePositions)) .orElse(false); }
/** * Sets the location of this entity using a safe one from * {@link TeleportHelper#getSafeLocation(Location)}. This is equivalent to a * teleport and also moves this entity's passengers. * * @param location The location to set * @return True if location was set successfully, false if location couldn't * be set as no safe location was found or * {@link org.spongepowered.api.event.entity.MoveEntityEvent.Teleport} * was cancelled. */ default boolean setLocationSafely(Location<World> location) { return Sponge.getGame().getTeleportHelper() .getSafeLocation(location) .map(this::setLocation) .orElse(false); }
/** * Sets the location using a safe one from * {@link TeleportHelper#getSafeLocation(Location)} and the rotation of this * entity. * * <p>The format of the rotation is represented by:</p> * * <ul><code>x -> pitch</code>, <code>y -> yaw</code>, <code>z -> roll * </code></ul> * * @param location The location to set * @param rotation The rotation to set * @return True if location was set successfully, false if either location * couldn't be set as no safe location was found or * {@link org.spongepowered.api.event.entity.MoveEntityEvent.Teleport} * was cancelled */ default boolean setLocationAndRotationSafely(Location<World> location, Vector3d rotation) { return Sponge.getGame().getTeleportHelper() .getSafeLocation(location) .map(safe -> this.setLocationAndRotation(safe, rotation)) .orElse(false); }
/** * Sets the location using a safe one from * {@link TeleportHelper#getSafeLocation(Location)} and the rotation of this * entity. {@link RelativePositions} listed inside the EnumSet are * considered relative. * * <p>The format of the rotation is represented by:</p> * * <ul><code>x -> pitch</code>, <code>y -> yaw</code>, <code>z -> roll * </code></ul> * * @param location The location to set * @param rotation The rotation to set * @param relativePositions The coordinates to set relatively * @return True if location was set successfully, false if either location * couldn't be set as no safe location was found or * {@link org.spongepowered.api.event.entity.MoveEntityEvent.Teleport} * was cancelled */ default boolean setLocationAndRotationSafely(Location<World> location, Vector3d rotation, EnumSet<RelativePositions> relativePositions) { return Sponge.getGame().getTeleportHelper() .getSafeLocation(location) .map(safe -> this.setLocationAndRotation(safe, rotation, relativePositions)) .orElse(false); }
@Listener public void onDismount(RideEntityEvent.Dismount event, @First Player player) { if (event.getTargetEntity() instanceof ArmorStand) { Chair<?> chair = getChair(event.getTargetEntity()); if (chair != null) { player.sendMessage(Text.of(TextColors.YELLOW, "You stand up!")); Sponge.getScheduler().createTaskBuilder().execute(() -> { removeChair(chair, false); if (!exitAtEntry.getValue()) { Sponge.getGame().getTeleportHelper().getSafeLocation(chair.chairLocation).ifPresent(player::setLocation); } }).submit(CraftBookPlugin.inst()); } } }
Location<World> safeLocation = Sponge.getGame().getTeleportHelper().getSafeLocation(destinationLocation).orElse(null); if (safeLocation != null) { player.setLocation(safeLocation);