From 73f2ad3843658a3a3f3010935d01c671f54004b9 Mon Sep 17 00:00:00 2001 From: Ben Woo <30431861+benwoo1110@users.noreply.github.com> Date: Tue, 17 Aug 2021 20:54:26 +0800 Subject: [PATCH 1/2] Properly allow turning off safe teleport for portal destination. --- .../MultiversePortals/MVPortal.java | 15 ++++++--- .../PortalPlayerSession.java | 4 +++ .../destination/PortalDestination.java | 2 +- .../enums/SetProperties.java | 2 +- .../listeners/MVPPlayerListener.java | 9 +++-- .../listeners/MVPPlayerMoveListener.java | 12 +++---- .../listeners/PlayerListenerHelper.java | 33 ++++++++++++------- 7 files changed, 50 insertions(+), 27 deletions(-) diff --git a/src/main/java/com/onarandombox/MultiversePortals/MVPortal.java b/src/main/java/com/onarandombox/MultiversePortals/MVPortal.java index e4087c6e..9e76b1d1 100644 --- a/src/main/java/com/onarandombox/MultiversePortals/MVPortal.java +++ b/src/main/java/com/onarandombox/MultiversePortals/MVPortal.java @@ -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)); } @@ -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; } diff --git a/src/main/java/com/onarandombox/MultiversePortals/PortalPlayerSession.java b/src/main/java/com/onarandombox/MultiversePortals/PortalPlayerSession.java index 226a28dd..a45d9c42 100644 --- a/src/main/java/com/onarandombox/MultiversePortals/PortalPlayerSession.java +++ b/src/main/java/com/onarandombox/MultiversePortals/PortalPlayerSession.java @@ -335,4 +335,8 @@ private String formatCooldownTime(long cooldownMs) { return (cooldownMs / 1000) + "s"; } + + public Player getPlayer() { + return player; + } } diff --git a/src/main/java/com/onarandombox/MultiversePortals/destination/PortalDestination.java b/src/main/java/com/onarandombox/MultiversePortals/destination/PortalDestination.java index 9c74e4cd..e0c14f4b 100644 --- a/src/main/java/com/onarandombox/MultiversePortals/destination/PortalDestination.java +++ b/src/main/java/com/onarandombox/MultiversePortals/destination/PortalDestination.java @@ -145,7 +145,7 @@ public Vector getVelocity() { @Override public boolean useSafeTeleporter() { - return this.portal.useSafeTeleporter(); + return true; } } diff --git a/src/main/java/com/onarandombox/MultiversePortals/enums/SetProperties.java b/src/main/java/com/onarandombox/MultiversePortals/enums/SetProperties.java index 4feccb5f..309ac390 100644 --- a/src/main/java/com/onarandombox/MultiversePortals/enums/SetProperties.java +++ b/src/main/java/com/onarandombox/MultiversePortals/enums/SetProperties.java @@ -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; } diff --git a/src/main/java/com/onarandombox/MultiversePortals/listeners/MVPPlayerListener.java b/src/main/java/com/onarandombox/MultiversePortals/listeners/MVPPlayerListener.java index 00824e46..d7ea5005 100644 --- a/src/main/java/com/onarandombox/MultiversePortals/listeners/MVPPlayerListener.java +++ b/src/main/java/com/onarandombox/MultiversePortals/listeners/MVPPlayerListener.java @@ -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()); diff --git a/src/main/java/com/onarandombox/MultiversePortals/listeners/MVPPlayerMoveListener.java b/src/main/java/com/onarandombox/MultiversePortals/listeners/MVPPlayerMoveListener.java index 8f8aafed..dc0bf8d2 100644 --- a/src/main/java/com/onarandombox/MultiversePortals/listeners/MVPPlayerMoveListener.java +++ b/src/main/java/com/onarandombox/MultiversePortals/listeners/MVPPlayerMoveListener.java @@ -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; @@ -93,11 +89,13 @@ public void playerMove(PlayerMoveEvent event) { return; } + Logging.warning("Getting location..."); Location destLocation = d.getLocation(p); if (destLocation == null) { Logging.fine("Unable to teleport player because destination is null!"); return; } + Logging.warning("Got location."); if (!this.plugin.getCore().getMVWorldManager().isMVWorld(destLocation.getWorld())) { Logging.fine("Unable to teleport player because the destination world is not managed by Multiverse!"); @@ -112,7 +110,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) { @@ -152,7 +150,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, @@ -164,7 +162,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); } } } diff --git a/src/main/java/com/onarandombox/MultiversePortals/listeners/PlayerListenerHelper.java b/src/main/java/com/onarandombox/MultiversePortals/listeners/PlayerListenerHelper.java index da64c278..bf03a59b 100644 --- a/src/main/java/com/onarandombox/MultiversePortals/listeners/PlayerListenerHelper.java +++ b/src/main/java/com/onarandombox/MultiversePortals/listeners/PlayerListenerHelper.java @@ -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; @@ -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()); } From 70680dc354ec470195efa45734e42b9cac7c2bb0 Mon Sep 17 00:00:00 2001 From: Ben Woo <30431861+benwoo1110@users.noreply.github.com> Date: Tue, 17 Aug 2021 21:16:22 +0800 Subject: [PATCH 2/2] Remove unnecessary log message. --- .../MultiversePortals/listeners/MVPPlayerMoveListener.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/main/java/com/onarandombox/MultiversePortals/listeners/MVPPlayerMoveListener.java b/src/main/java/com/onarandombox/MultiversePortals/listeners/MVPPlayerMoveListener.java index dc0bf8d2..a9fde736 100644 --- a/src/main/java/com/onarandombox/MultiversePortals/listeners/MVPPlayerMoveListener.java +++ b/src/main/java/com/onarandombox/MultiversePortals/listeners/MVPPlayerMoveListener.java @@ -89,13 +89,11 @@ public void playerMove(PlayerMoveEvent event) { return; } - Logging.warning("Getting location..."); Location destLocation = d.getLocation(p); if (destLocation == null) { Logging.fine("Unable to teleport player because destination is null!"); return; } - Logging.warning("Got location."); if (!this.plugin.getCore().getMVWorldManager().isMVWorld(destLocation.getWorld())) { Logging.fine("Unable to teleport player because the destination world is not managed by Multiverse!");