Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions src/main/java/org/mvplugins/multiverse/portals/MVPortal.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import org.mvplugins.multiverse.core.teleportation.BlockSafety;
import org.mvplugins.multiverse.core.world.LoadedMultiverseWorld;
import org.mvplugins.multiverse.core.world.WorldManager;
import org.mvplugins.multiverse.external.vavr.control.Try;
import org.mvplugins.multiverse.portals.config.PortalsConfig;
import org.mvplugins.multiverse.portals.enums.PortalType;
import org.bukkit.Location;
Expand Down Expand Up @@ -290,6 +291,29 @@ public boolean setDestination(DestinationInstance<?, ?> newDestination) {
.getOrNull();
}

/**
*
* @param checkDestinationSafety
* @return
*
* @since 5.1
*/
@ApiStatus.AvailableSince("5.1")
public Try<Void> setCheckDestinationSafety(boolean checkDestinationSafety) {
return this.configHandle.set(configNodes.checkDestinationSafety, checkDestinationSafety);
}

/**
*
* @return
*
* @since 5.1
*/
@ApiStatus.AvailableSince("5.1")
public boolean getCheckDestinationSafety() {
return this.configHandle.get(configNodes.checkDestinationSafety);
}

public Location getSafePlayerSpawnLocation() {
PortalLocation pl = this.location;
double portalWidth = Math.abs((pl.getMaximum().getBlockX()) - pl.getMinimum().getBlockX()) + 1;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,10 @@ private <N extends Node> N node(N node) {
.toTry())
.build());

final ConfigNode<Boolean> checkDestinationSafety = node(ConfigNode.builder("check-destination-safety", Boolean.class)
.defaultValue(true)
.build());

final ConfigNode<Double> version = node(ConfigNode.builder("version", Double.class)
.defaultValue(0.0)
.hidden()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ public void playerPortal(PlayerPortalEvent event) {
return;
}

if (portalDest.checkTeleportSafety()) {
if (portal.getCheckDestinationSafety() && portalDest.checkTeleportSafety()) {
Location safeLocation = blockSafety.findSafeSpawnLocation(portalDest.getLocation(event.getPlayer()).getOrNull());
if (safeLocation == null) {
event.setCancelled(true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ public void playerMove(PlayerMoveEvent event) {
price > 0D ? "been charged" : "earned",
economist.formatPrice(price, currency),
portal.getName()));
helper.performTeleport(event.getPlayer(), event.getTo(), ps, d);
helper.performTeleport(event.getPlayer(), event.getTo(), ps, d, portal.getCheckDestinationSafety());
}
} else {
p.sendMessage(economist.getNSFMessage(currency,
Expand All @@ -164,7 +164,7 @@ public void playerMove(PlayerMoveEvent event) {
MVPortalEvent portalEvent = new MVPortalEvent(d, event.getPlayer(), portal);
this.plugin.getServer().getPluginManager().callEvent(portalEvent);
if (!portalEvent.isCancelled()) {
helper.performTeleport(event.getPlayer(), event.getTo(), ps, d);
helper.performTeleport(event.getPlayer(), event.getTo(), ps, d, portal.getCheckDestinationSafety());
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import com.dumptruckman.minecraft.util.Logging;
import org.bukkit.Material;
import org.bukkit.event.Listener;
import org.mvplugins.multiverse.core.destination.DestinationInstance;
import org.mvplugins.multiverse.core.economy.MVEconomist;
import org.mvplugins.multiverse.core.permissions.CorePermissionsChecker;
import org.mvplugins.multiverse.core.teleportation.LocationManipulation;
Expand Down Expand Up @@ -101,7 +102,9 @@ public void vehicleMove(VehicleMoveEvent event) {
}
}

safetyTeleporter.to(portal.getDestination())
DestinationInstance<?, ?> destination = portal.getDestination();
safetyTeleporter.to(destination)
.checkSafety(portal.getCheckDestinationSafety() && destination.checkTeleportSafety())
.passengerMode(PassengerModes.RETAIN_ALL)
.teleportSingle(vehicle)
.onSuccess(() -> Logging.finer("Successfully teleported vehicle %s using portal %s",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
import org.bukkit.entity.Player;

@Service
public class PlayerListenerHelper {
final class PlayerListenerHelper {

private final AsyncSafetyTeleporter safetyTeleporter;

Expand All @@ -34,8 +34,10 @@ void stateFailure(String playerName, String portalName) {
playerName, portalName));
}

void performTeleport(Player player, Location to, PortalPlayerSession ps, DestinationInstance<?, ?> destination) {
safetyTeleporter.to(destination).teleport(player)
void performTeleport(Player player, Location to, PortalPlayerSession ps, DestinationInstance<?, ?> destination, boolean checkSafety) {
safetyTeleporter.to(destination)
.checkSafety(checkSafety && destination.checkTeleportSafety())
.teleportSingle(player)
.onSuccess(() -> {
ps.playerDidTeleport(to);
ps.setTeleportTime(new Date());
Expand Down
Loading