Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Properly allow turning off safe teleport. #636

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
15 changes: 11 additions & 4 deletions src/main/java/com/onarandombox/MultiversePortals/MVPortal.java
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,6 @@ public boolean setProperty(String property, String value) {
return this.setDestination(value);
}


if (property.equalsIgnoreCase("curr") || property.equalsIgnoreCase("currency")) {
return this.setCurrency(Material.matchMaterial(value));
}
Expand All @@ -387,25 +386,33 @@ public boolean setProperty(String property, String value) {
if (property.equalsIgnoreCase("owner")) {
return this.setOwner(value);
}

if (property.equalsIgnoreCase("safe")) {
try {
this.setUseSafeTeleporter(Boolean.parseBoolean(value));
return true;
} catch (Exception e) {

} catch (Exception ignored) {
}
}

if (property.equalsIgnoreCase("telenonplayers")) {
try {
this.setTeleportNonPlayers(Boolean.parseBoolean(value));
return true;
} catch (Exception e) {
} catch (Exception ignored) {
}
}

if (property.equalsIgnoreCase("handlerscript")) {
this.setHandlerScript(value);
return true;
}

if (property.equalsIgnoreCase("safeteleport")) {
this.setUseSafeTeleporter(Boolean.parseBoolean(value));
return true;
}

return false;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -335,4 +335,8 @@ private String formatCooldownTime(long cooldownMs) {

return (cooldownMs / 1000) + "s";
}

public Player getPlayer() {
return player;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ public Vector getVelocity() {

@Override
public boolean useSafeTeleporter() {
return this.portal.useSafeTeleporter();
return true;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@
package com.onarandombox.MultiversePortals.enums;

public enum SetProperties {
destination, dest, owner, loc, location, price, currency, curr, safe, telenonplayers, handlerscript
destination, dest, owner, loc, location, price, currency, curr, safe, telenonplayers, handlerscript, safeteleport;
}
Original file line number Diff line number Diff line change
Expand Up @@ -258,9 +258,14 @@ public void playerPortal(PlayerPortalEvent event) {
}

event.setTo(destLocation);
if (portalDest.useSafeTeleporter()) {
if (portal.useSafeTeleporter()) {
SafeTTeleporter teleporter = this.plugin.getCore().getSafeTTeleporter();
event.setTo(teleporter.getSafeLocation(event.getPlayer(), portalDest));
Location safeLocation = teleporter.getSafeLocation(event.getPlayer(), portalDest);
if (safeLocation == null) {
Logging.fine("Player denied teleportation as no safe location is found.");
return;
}
event.setTo(safeLocation);
}

PortalPlayerSession ps = this.plugin.getPortalSession(event.getPlayer());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,8 @@

package com.onarandombox.MultiversePortals.listeners;

import java.util.Date;
import java.util.logging.Level;

import com.dumptruckman.minecraft.util.Logging;
import com.onarandombox.MultiverseCore.api.MVDestination;
import com.onarandombox.MultiverseCore.api.MultiverseWorld;
import com.onarandombox.MultiverseCore.destination.InvalidDestination;
import com.onarandombox.MultiverseCore.utils.MVEconomist;
import com.onarandombox.MultiversePortals.MVPortal;
Expand Down Expand Up @@ -112,7 +108,7 @@ public void playerMove(PlayerMoveEvent event) {
try {
if (helper.scriptPortal(event.getPlayer(), d, portal, ps)) {
// Portal handled by script
helper.performTeleport(event.getPlayer(), event.getTo(), ps, d);
helper.performTeleport(ps, d);
}
return;
} catch (IllegalStateException ignore) {
Expand Down Expand Up @@ -152,7 +148,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(ps, d);
}
} else {
p.sendMessage(economist.getNSFMessage(currency,
Expand All @@ -164,7 +160,7 @@ public void playerMove(PlayerMoveEvent event) {
MVPortalEvent portalEvent = new MVPortalEvent(d, event.getPlayer(), agent, portal);
this.plugin.getServer().getPluginManager().callEvent(portalEvent);
if (!portalEvent.isCancelled()) {
helper.performTeleport(event.getPlayer(), event.getTo(), ps, d);
helper.performTeleport(ps, d);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,11 @@

import java.io.File;
import java.util.Date;
import java.util.logging.Level;

import com.dumptruckman.minecraft.util.Logging;
import com.google.common.base.Strings;
import com.onarandombox.MultiverseCore.api.MVDestination;
import com.onarandombox.MultiverseCore.api.SafeTTeleporter;
import com.onarandombox.MultiverseCore.enums.TeleportResult;
import com.onarandombox.MultiverseCore.utils.MVTravelAgent;
import com.onarandombox.MultiversePortals.MVPortal;
import com.onarandombox.MultiversePortals.MultiversePortals;
import com.onarandombox.MultiversePortals.PortalPlayerSession;
Expand Down Expand Up @@ -37,17 +35,28 @@ void stateFailure(String playerName, String portalName) {
playerName, portalName));
}

void performTeleport(Player player, Location to, PortalPlayerSession ps, MVDestination d) {
if (!plugin.getCore().getMVConfig().getEnforceAccess() || (d.getRequiredPermission() == null)
|| (d.getRequiredPermission().length() == 0) || player.hasPermission(d.getRequiredPermission())) {
SafeTTeleporter playerTeleporter = this.plugin.getCore().getSafeTTeleporter();
TeleportResult result = playerTeleporter.safelyTeleport(player, player, d);
if (result == TeleportResult.SUCCESS) {
ps.playerDidTeleport(to);
ps.setTeleportTime(new Date());
this.stateSuccess(player.getDisplayName(), d.getName());
void performTeleport(PortalPlayerSession ps, MVDestination d) {
Player player = ps.getPlayer();
if (!plugin.getCore().getMVConfig().getEnforceAccess()
|| Strings.isNullOrEmpty(d.getRequiredPermission())
|| player.hasPermission(d.getRequiredPermission())) {

Location targetLocation = d.getLocation(player);
if (ps.getStandingInPortal().useSafeTeleporter()) {
SafeTTeleporter playerTeleporter = this.plugin.getCore().getSafeTTeleporter();
targetLocation = playerTeleporter.getSafeLocation(player, d);
}

if (targetLocation == null) {
this.stateFailure(player.getDisplayName(), d.getName());
return;
}

player.teleport(targetLocation);
ps.playerDidTeleport(targetLocation);
ps.setTeleportTime(new Date());
this.stateSuccess(player.getDisplayName(), d.getName());
return;
}
this.stateFailure(player.getDisplayName(), d.getName());
}
Expand Down