diff --git a/src/main/java/net/knarcraft/stargate/container/FromTheEndTeleportation.java b/src/main/java/net/knarcraft/stargate/container/FromTheEndTeleportation.java new file mode 100644 index 0000000..364dfff --- /dev/null +++ b/src/main/java/net/knarcraft/stargate/container/FromTheEndTeleportation.java @@ -0,0 +1,43 @@ +package net.knarcraft.stargate.container; + +import net.knarcraft.stargate.portal.Portal; +import org.bukkit.entity.Player; + +/** + * This class represents a player teleporting from the end to the over-world using an artificial end portal + */ +public class FromTheEndTeleportation { + + private final Player teleportingPlayer; + private final Portal exitPortal; + + /** + * Instantiates a new teleportation from the end + * + * @param teleportingPlayer
The teleporting player
+ * @param exitPortalThe portal to exit from
+ */ + public FromTheEndTeleportation(Player teleportingPlayer, Portal exitPortal) { + this.teleportingPlayer = teleportingPlayer; + this.exitPortal = exitPortal; + } + + /** + * Gets the teleporting player + * + * @returnThe teleporting player
+ */ + public Player getPlayer() { + return this.teleportingPlayer; + } + + /** + * Gets the portal to exit from + * + * @returnThe portal to exit from
+ */ + public Portal getExit() { + return this.exitPortal; + } + +} diff --git a/src/main/java/net/knarcraft/stargate/listener/PlayerEventListener.java b/src/main/java/net/knarcraft/stargate/listener/PlayerEventListener.java index 2b1ebbb..8dcfbfc 100644 --- a/src/main/java/net/knarcraft/stargate/listener/PlayerEventListener.java +++ b/src/main/java/net/knarcraft/stargate/listener/PlayerEventListener.java @@ -5,8 +5,6 @@ import net.knarcraft.stargate.container.BlockLocation; import net.knarcraft.stargate.portal.Portal; import net.knarcraft.stargate.portal.PortalHandler; import net.knarcraft.stargate.utility.BungeeHelper; -import net.knarcraft.stargate.utility.EconomyHandler; -import net.knarcraft.stargate.utility.EconomyHelper; import net.knarcraft.stargate.utility.MaterialHelper; import net.knarcraft.stargate.utility.PermissionHelper; import org.bukkit.GameMode; @@ -127,7 +125,7 @@ public class PlayerEventListener implements Listener { Portal destination = entrancePortal.getDestination(player); //Decide if the anything stops the player from teleport - if (!playerCanTeleport(entrancePortal, destination, player, event)) { + if (PermissionHelper.playerCannotTeleport(entrancePortal, destination, player, event)) { return false; } @@ -322,47 +320,4 @@ public class PlayerEventListener implements Listener { return true; } - /** - * Decide of the player can teleport through a portal - * - * @param entrancePortalThe portal the player is entering from
- * @param destinationThe destination of the portal the player is inside
- * @param playerThe player wanting to teleport
- * @param eventThe move event causing the teleportation
- * @returnTrue if the player can teleport. False otherwise
- */ - private boolean playerCanTeleport(Portal entrancePortal, Portal destination, Player player, PlayerMoveEvent event) { - // No portal or not open - if (entrancePortal == null || !entrancePortal.isOpen()) { - return false; - } - - // Not open for this player - if (!entrancePortal.isOpenFor(player)) { - Stargate.sendErrorMessage(player, Stargate.getString("denyMsg")); - entrancePortal.teleport(player, entrancePortal, event); - return false; - } - - //No destination - if (!entrancePortal.getOptions().isBungee() && destination == null) { - return false; - } - - //Player cannot access portal - if (PermissionHelper.cannotAccessPortal(player, entrancePortal, destination)) { - Stargate.sendErrorMessage(player, Stargate.getString("denyMsg")); - entrancePortal.teleport(player, entrancePortal, event); - entrancePortal.close(false); - return false; - } - - //Player cannot pay for teleportation - int cost = EconomyHandler.getUseCost(player, entrancePortal, destination); - if (cost > 0) { - return EconomyHelper.payTeleportFee(entrancePortal, player, cost); - } - return true; - } - } diff --git a/src/main/java/net/knarcraft/stargate/listener/PortalEventListener.java b/src/main/java/net/knarcraft/stargate/listener/PortalEventListener.java index 29e86ba..2932fe1 100644 --- a/src/main/java/net/knarcraft/stargate/listener/PortalEventListener.java +++ b/src/main/java/net/knarcraft/stargate/listener/PortalEventListener.java @@ -1,8 +1,9 @@ package net.knarcraft.stargate.listener; -import net.knarcraft.stargate.container.TwoTuple; +import net.knarcraft.stargate.container.FromTheEndTeleportation; import net.knarcraft.stargate.portal.Portal; import net.knarcraft.stargate.portal.PortalHandler; +import net.knarcraft.stargate.utility.PermissionHelper; import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.World; @@ -23,7 +24,7 @@ import java.util.List; */ public class PortalEventListener implements Listener { - private static final ListThe portal the player is entering from
+ * @param destinationThe destination of the portal the player is inside
+ * @param playerThe player wanting to teleport
+ * @param eventThe move event causing the teleportation
+ * @returnTrue if the player cannot teleport. False otherwise
+ */ + public static boolean playerCannotTeleport(Portal entrancePortal, Portal destination, Player player, PlayerMoveEvent event) { + // No portal or not open + if (entrancePortal == null || !entrancePortal.isOpen()) { + return true; + } + + // Not open for this player + if (!entrancePortal.isOpenFor(player)) { + Stargate.sendErrorMessage(player, Stargate.getString("denyMsg")); + entrancePortal.teleport(player, entrancePortal, event); + return true; + } + + //No destination + if (!entrancePortal.getOptions().isBungee() && destination == null) { + return true; + } + + //Player cannot access portal + if (PermissionHelper.cannotAccessPortal(player, entrancePortal, destination)) { + Stargate.sendErrorMessage(player, Stargate.getString("denyMsg")); + entrancePortal.teleport(player, entrancePortal, event); + entrancePortal.close(false); + return true; + } + + //Player cannot pay for teleportation + int cost = EconomyHandler.getUseCost(player, entrancePortal, destination); + if (cost > 0) { + return !EconomyHelper.payTeleportFee(entrancePortal, player, cost); + } + return false; + } + }