2021-09-20 13:56:30 +02:00
|
|
|
package net.knarcraft.stargate.utility;
|
|
|
|
|
|
|
|
import net.knarcraft.stargate.Stargate;
|
2021-09-20 18:22:20 +02:00
|
|
|
import net.knarcraft.stargate.event.StargateAccessEvent;
|
2021-10-18 18:38:36 +02:00
|
|
|
import net.knarcraft.stargate.portal.PlayerTeleporter;
|
2021-09-20 13:56:30 +02:00
|
|
|
import net.knarcraft.stargate.portal.Portal;
|
|
|
|
import net.knarcraft.stargate.portal.PortalOption;
|
|
|
|
import org.bukkit.entity.Player;
|
2021-10-12 02:47:09 +02:00
|
|
|
import org.bukkit.event.player.PlayerMoveEvent;
|
2021-09-20 13:56:30 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Helper class for deciding which actions a player is allowed to perform
|
|
|
|
*/
|
|
|
|
public final class PermissionHelper {
|
|
|
|
|
|
|
|
private PermissionHelper() {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2021-09-20 18:22:20 +02:00
|
|
|
/**
|
|
|
|
* Opens a portal if the given player is allowed to, and if the portal is not already open
|
|
|
|
*
|
|
|
|
* @param player <p>The player opening the portal</p>
|
|
|
|
* @param portal <p>The portal to open</p>
|
|
|
|
*/
|
|
|
|
public static void openPortal(Player player, Portal portal) {
|
2021-10-20 16:09:35 +02:00
|
|
|
Portal destination = portal.getPortalActivator().getDestination();
|
2021-09-20 18:22:20 +02:00
|
|
|
|
2021-10-28 18:29:33 +02:00
|
|
|
//For an always open portal, no action is necessary
|
|
|
|
if (portal.getOptions().isAlwaysOn() || portal.getOptions().isRandom() || portal.getOptions().isBungee()) {
|
2021-09-20 18:22:20 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-10-28 18:29:33 +02:00
|
|
|
//Destination is invalid or the same portal. Send an error message
|
|
|
|
if (destination == null || destination == portal) {
|
2021-10-23 14:10:33 +02:00
|
|
|
Stargate.getMessageSender().sendErrorMessage(player, Stargate.getString("invalidMsg"));
|
2021-09-20 18:22:20 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-10-26 16:22:20 +02:00
|
|
|
//Portal is already open
|
2021-09-20 18:22:20 +02:00
|
|
|
if (portal.isOpen()) {
|
2021-10-28 18:29:33 +02:00
|
|
|
//Close the portal if this player opened the portal
|
2021-09-20 18:22:20 +02:00
|
|
|
if (portal.getActivePlayer() == player) {
|
2021-10-20 16:09:35 +02:00
|
|
|
portal.getPortalOpener().closePortal(false);
|
2021-09-20 18:22:20 +02:00
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-10-28 18:29:33 +02:00
|
|
|
//Deny access if another player has activated the portal, and it's still in use
|
|
|
|
if (!portal.getOptions().isFixed() && portal.getPortalActivator().isActive() &&
|
|
|
|
portal.getActivePlayer() != player) {
|
2021-10-23 14:10:33 +02:00
|
|
|
Stargate.getMessageSender().sendErrorMessage(player, Stargate.getString("denyMsg"));
|
2021-09-20 18:22:20 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
//Check if the player can use the private gate
|
2021-10-24 21:15:43 +02:00
|
|
|
if (portal.getOptions().isPrivate() && !PermissionHelper.canUsePrivatePortal(player, portal)) {
|
2021-10-23 14:10:33 +02:00
|
|
|
Stargate.getMessageSender().sendErrorMessage(player, Stargate.getString("denyMsg"));
|
2021-09-20 18:22:20 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-10-28 18:29:33 +02:00
|
|
|
//Destination is currently in use by another player, blocking teleportation
|
|
|
|
if (destination.isOpen() && !destination.getOptions().isAlwaysOn()) {
|
2021-10-23 14:10:33 +02:00
|
|
|
Stargate.getMessageSender().sendErrorMessage(player, Stargate.getString("blockMsg"));
|
2021-09-20 18:22:20 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-10-28 18:29:33 +02:00
|
|
|
//Open the portal
|
2021-10-20 16:09:35 +02:00
|
|
|
portal.getPortalOpener().openPortal(player, false);
|
2021-09-20 18:22:20 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2021-10-28 18:29:33 +02:00
|
|
|
* Creates a StargateAccessEvent and gets the updated deny value
|
2021-09-20 18:22:20 +02:00
|
|
|
*
|
2021-10-28 18:29:33 +02:00
|
|
|
* <p>The event is used for other plugins to bypass the permission checks.</p>
|
2021-09-20 18:22:20 +02:00
|
|
|
*
|
|
|
|
* @param player <p>The player trying to use the portal</p>
|
|
|
|
* @param portal <p>The portal the player is trying to use</p>
|
2021-10-28 18:29:33 +02:00
|
|
|
* @param deny <p>Whether the player's access has already been denied by a previous check</p>
|
2021-09-20 18:22:20 +02:00
|
|
|
* @return <p>False if the player should be allowed through the portal</p>
|
|
|
|
*/
|
2021-10-28 18:29:33 +02:00
|
|
|
public static boolean portalAccessDenied(Player player, Portal portal, boolean deny) {
|
2021-09-20 18:22:20 +02:00
|
|
|
StargateAccessEvent event = new StargateAccessEvent(player, portal, deny);
|
|
|
|
Stargate.server.getPluginManager().callEvent(event);
|
|
|
|
return event.getDeny();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Checks whether a given user cannot travel between two portals
|
|
|
|
*
|
|
|
|
* @param player <p>The player to check</p>
|
|
|
|
* @param entrancePortal <p>The portal the user wants to enter</p>
|
2021-10-28 18:29:33 +02:00
|
|
|
* @param destination <p>The portal the user wants to exit from</p>
|
2021-09-20 18:22:20 +02:00
|
|
|
* @return <p>False if the user is allowed to access the portal</p>
|
|
|
|
*/
|
|
|
|
public static boolean cannotAccessPortal(Player player, Portal entrancePortal, Portal destination) {
|
|
|
|
boolean deny = false;
|
2021-10-28 18:29:33 +02:00
|
|
|
|
|
|
|
if (entrancePortal.getOptions().isBungee()) {
|
|
|
|
if (!PermissionHelper.canAccessServer(player, entrancePortal.getNetwork())) {
|
|
|
|
//If the portal is a bungee portal, and the player cannot access the server, deny
|
|
|
|
Stargate.debug("cannotAccessPortal", "Cannot access server");
|
|
|
|
deny = true;
|
|
|
|
}
|
2021-09-20 18:22:20 +02:00
|
|
|
} else if (PermissionHelper.cannotAccessNetwork(player, entrancePortal.getNetwork())) {
|
2021-10-28 18:29:33 +02:00
|
|
|
//If the player does not have access to the network, deny
|
2021-09-20 18:22:20 +02:00
|
|
|
Stargate.debug("cannotAccessPortal", "Cannot access network");
|
|
|
|
deny = true;
|
2021-10-28 18:29:33 +02:00
|
|
|
} else if (PermissionHelper.cannotAccessWorld(player, destination.getWorld().getName())) {
|
|
|
|
//If the player does not have access to the portal's world, deny
|
2021-09-20 18:22:20 +02:00
|
|
|
Stargate.debug("cannotAccessPortal", "Cannot access world");
|
|
|
|
deny = true;
|
|
|
|
}
|
2021-10-28 18:29:33 +02:00
|
|
|
//Allow other plugins to override whether the player can access the portal
|
|
|
|
return portalAccessDenied(player, entrancePortal, deny);
|
2021-09-20 18:22:20 +02:00
|
|
|
}
|
|
|
|
|
2021-09-20 13:56:30 +02:00
|
|
|
/**
|
|
|
|
* Checks whether a player has the given permission
|
|
|
|
*
|
|
|
|
* <p>This is the same as player.hasPermission(), but this function allows for printing permission debugging info.</p>
|
|
|
|
*
|
2021-10-24 21:15:43 +02:00
|
|
|
* @param player <p>The player to check</p>
|
|
|
|
* @param permission <p>The permission to check</p>
|
2021-09-20 13:56:30 +02:00
|
|
|
* @return <p>True if the player has the permission</p>
|
|
|
|
*/
|
2021-10-24 21:15:43 +02:00
|
|
|
public static boolean hasPermission(Player player, String permission) {
|
2021-10-23 18:34:31 +02:00
|
|
|
if (Stargate.getStargateConfig().isPermissionDebuggingEnabled()) {
|
2021-10-28 18:29:33 +02:00
|
|
|
Stargate.debug("hasPerm::Permission(" + player.getName() + ")", permission + " => " +
|
2021-10-24 21:15:43 +02:00
|
|
|
player.hasPermission(permission));
|
2021-09-20 13:56:30 +02:00
|
|
|
}
|
2021-10-24 21:15:43 +02:00
|
|
|
return player.hasPermission(permission);
|
2021-09-20 13:56:30 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2021-10-28 18:29:33 +02:00
|
|
|
* Check if a player has been given a permission implicitly
|
2021-09-20 13:56:30 +02:00
|
|
|
*
|
2021-10-28 18:29:33 +02:00
|
|
|
* <p>This should be run if a player has a parent permission to check for the child permission. It is assumed the
|
|
|
|
* player has the child permission unless it's explicitly set to false.</p>
|
2021-09-20 13:56:30 +02:00
|
|
|
*
|
|
|
|
* @param player <p>The player to check</p>
|
|
|
|
* @param permission <p>The permission to check</p>
|
2021-10-28 18:29:33 +02:00
|
|
|
* @return <p>True if the player has the permission implicitly or explicitly</p>
|
2021-09-20 13:56:30 +02:00
|
|
|
*/
|
2021-10-28 18:29:33 +02:00
|
|
|
public static boolean hasPermissionImplicit(Player player, String permission) {
|
2021-09-20 13:56:30 +02:00
|
|
|
if (!player.isPermissionSet(permission)) {
|
2021-10-23 18:34:31 +02:00
|
|
|
if (Stargate.getStargateConfig().isPermissionDebuggingEnabled()) {
|
2021-10-28 18:29:33 +02:00
|
|
|
Stargate.debug("hasPermissionImplicit::Permission", permission + " => implicitly true");
|
2021-09-20 13:56:30 +02:00
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
2021-10-23 18:34:31 +02:00
|
|
|
if (Stargate.getStargateConfig().isPermissionDebuggingEnabled()) {
|
2021-10-28 18:29:33 +02:00
|
|
|
Stargate.debug("hasPermissionImplicit::Permission", permission + " => " +
|
|
|
|
player.hasPermission(permission));
|
2021-09-20 13:56:30 +02:00
|
|
|
}
|
|
|
|
return player.hasPermission(permission);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Checks whether a player can access the given world
|
2021-09-20 18:22:20 +02:00
|
|
|
*
|
2021-09-20 13:56:30 +02:00
|
|
|
* @param player <p>The player trying to access the world</p>
|
2021-09-20 18:22:20 +02:00
|
|
|
* @param world <p>The world the player is trying to access</p>
|
2021-09-20 13:56:30 +02:00
|
|
|
* @return <p>False if the player should be allowed to access the world</p>
|
|
|
|
*/
|
|
|
|
public static boolean cannotAccessWorld(Player player, String world) {
|
2021-10-28 18:29:33 +02:00
|
|
|
//The player can access all worlds
|
|
|
|
if (hasPermission(player, "stargate.world")) {
|
|
|
|
//Check if the world permission has been explicitly denied
|
|
|
|
return !hasPermissionImplicit(player, "stargate.world." + world);
|
2021-09-20 13:56:30 +02:00
|
|
|
}
|
2021-10-28 18:29:33 +02:00
|
|
|
//The player can access the destination world
|
2021-09-20 13:56:30 +02:00
|
|
|
return !hasPermission(player, "stargate.world." + world);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Checks whether a player can access the given network
|
|
|
|
*
|
|
|
|
* @param player <p>The player to check</p>
|
|
|
|
* @param network <p>The network to check</p>
|
|
|
|
* @return <p>True if the player is denied from accessing the network</p>
|
|
|
|
*/
|
|
|
|
public static boolean cannotAccessNetwork(Player player, String network) {
|
2021-10-28 18:29:33 +02:00
|
|
|
//The player can access all networks
|
|
|
|
if (hasPermission(player, "stargate.network")) {
|
|
|
|
//Check if the world permission has been explicitly denied
|
|
|
|
return !hasPermissionImplicit(player, "stargate.network." + network);
|
2021-09-20 13:56:30 +02:00
|
|
|
}
|
|
|
|
//Check if the player can access this network
|
|
|
|
if (hasPermission(player, "stargate.network." + network)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
//Is able to create personal gates (Assumption is made they can also access them)
|
|
|
|
String playerName = player.getName();
|
|
|
|
if (playerName.length() > 11) {
|
|
|
|
playerName = playerName.substring(0, 11);
|
|
|
|
}
|
|
|
|
return !network.equals(playerName) || !hasPermission(player, "stargate.create.personal");
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Checks whether a player can access the given bungee server
|
2021-09-20 18:22:20 +02:00
|
|
|
*
|
2021-09-20 13:56:30 +02:00
|
|
|
* @param player <p>The player trying to teleport</p>
|
|
|
|
* @param server <p>The server the player is trying to connect to</p>
|
|
|
|
* @return <p>True if the player is allowed to access the given server</p>
|
|
|
|
*/
|
|
|
|
public static boolean canAccessServer(Player player, String server) {
|
2021-10-28 18:29:33 +02:00
|
|
|
//The player can access all servers
|
|
|
|
if (hasPermission(player, "stargate.server")) {
|
|
|
|
//Check if the server permission has been explicitly denied
|
|
|
|
return hasPermissionImplicit(player, "stargate.server." + server);
|
2021-09-20 13:56:30 +02:00
|
|
|
}
|
2021-10-28 18:29:33 +02:00
|
|
|
//The player can access the destination server
|
2021-09-20 13:56:30 +02:00
|
|
|
return hasPermission(player, "stargate.server." + server);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Checks whether the given player can teleport the given stretch for free
|
|
|
|
*
|
|
|
|
* @param player <p>The player trying to teleport</p>
|
|
|
|
* @param src <p>The portal the player is entering</p>
|
|
|
|
* @param dest <p>The portal the player wants to teleport to</p>
|
|
|
|
* @return <p>True if the player can travel for free</p>
|
|
|
|
*/
|
|
|
|
public static boolean isFree(Player player, Portal src, Portal dest) {
|
2021-10-28 18:29:33 +02:00
|
|
|
//This portal is free
|
2021-10-08 01:26:12 +02:00
|
|
|
if (src.getOptions().isFree()) {
|
2021-09-20 13:56:30 +02:00
|
|
|
return true;
|
|
|
|
}
|
2021-10-28 18:29:33 +02:00
|
|
|
//Player can use this portal for free
|
|
|
|
if (hasPermission(player, "stargate.free.use")) {
|
2021-09-20 13:56:30 +02:00
|
|
|
return true;
|
|
|
|
}
|
2021-10-28 18:29:33 +02:00
|
|
|
//Don't charge for free destinations unless specified in the config
|
2021-10-23 03:56:59 +02:00
|
|
|
return dest != null && !Stargate.getEconomyConfig().chargeFreeDestination() && dest.getOptions().isFree();
|
2021-09-20 13:56:30 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Checks whether the player can see this gate (Hidden property check)
|
|
|
|
*
|
|
|
|
* <p>This decides if the player can see the gate on the network selection screen</p>
|
|
|
|
*
|
|
|
|
* @param player <p>The player to check</p>
|
|
|
|
* @param portal <p>The portal to check</p>
|
|
|
|
* @return <p>True if the given player can see the given portal</p>
|
|
|
|
*/
|
|
|
|
public static boolean canSeePortal(Player player, Portal portal) {
|
2021-10-28 18:29:33 +02:00
|
|
|
//The portal is not hidden
|
2021-10-08 01:26:12 +02:00
|
|
|
if (!portal.getOptions().isHidden()) {
|
2021-09-20 13:56:30 +02:00
|
|
|
return true;
|
|
|
|
}
|
2021-10-28 18:29:33 +02:00
|
|
|
//The player can see all hidden portals
|
|
|
|
if (hasPermission(player, "stargate.admin.hidden")) {
|
2021-09-20 13:56:30 +02:00
|
|
|
return true;
|
|
|
|
}
|
2021-10-28 18:29:33 +02:00
|
|
|
//The player is the owner of the portal
|
2021-09-20 13:56:30 +02:00
|
|
|
return portal.isOwner(player);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Checks if the given player is allowed to use the given private portal
|
|
|
|
*
|
|
|
|
* @param player <p>The player trying to use the portal</p>
|
|
|
|
* @param portal <p>The private portal used</p>
|
|
|
|
* @return <p>True if the player is allowed to use the portal</p>
|
|
|
|
*/
|
2021-10-24 21:15:43 +02:00
|
|
|
public static boolean canUsePrivatePortal(Player player, Portal portal) {
|
2021-09-20 13:56:30 +02:00
|
|
|
//Check if the player is the owner of the gate
|
|
|
|
if (portal.isOwner(player)) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
//The player is an admin with the ability to use private gates
|
2021-10-28 18:29:33 +02:00
|
|
|
return hasPermission(player, "stargate.admin.private");
|
2021-09-20 13:56:30 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Checks if the given player has access to the given portal option
|
|
|
|
*
|
|
|
|
* @param player <p>The player trying to use the option</p>
|
|
|
|
* @param option <p>The option the player is trying to use</p>
|
|
|
|
* @return <p>True if the player is allowed to create a portal with the given option</p>
|
|
|
|
*/
|
|
|
|
public static boolean canUseOption(Player player, PortalOption option) {
|
|
|
|
return hasPermission(player, option.getPermissionString());
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Checks if the given player is allowed to create gates on the given network
|
|
|
|
*
|
|
|
|
* @param player <p>The player trying to create a new gate</p>
|
|
|
|
* @param network <p>The network the player is trying to create a gate on</p>
|
|
|
|
* @return <p>True if the player is allowed to create the new gate</p>
|
|
|
|
*/
|
|
|
|
public static boolean canCreateNetworkGate(Player player, String network) {
|
2021-10-28 18:29:33 +02:00
|
|
|
//Check if the player is allowed to create a portal on any network
|
2021-09-20 13:56:30 +02:00
|
|
|
if (hasPermission(player, "stargate.create.network")) {
|
2021-10-28 18:29:33 +02:00
|
|
|
//Check if the network has been explicitly denied
|
|
|
|
return hasPermissionImplicit(player, "stargate.create.network." + network);
|
2021-09-20 13:56:30 +02:00
|
|
|
}
|
2021-10-28 18:29:33 +02:00
|
|
|
//Check if the player is allowed to create on this specific network
|
2021-09-20 13:56:30 +02:00
|
|
|
return hasPermission(player, "stargate.create.network." + network);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Checks whether the given player is allowed to create a personal gate
|
|
|
|
*
|
|
|
|
* @param player <p>The player trying to create the new gate</p>
|
|
|
|
* @return <p>True if the player is allowed</p>
|
|
|
|
*/
|
2021-10-24 21:15:43 +02:00
|
|
|
public static boolean canCreatePersonalPortal(Player player) {
|
2021-09-20 13:56:30 +02:00
|
|
|
return hasPermission(player, "stargate.create.personal");
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Checks if the given player can create a portal with the given gate layout
|
|
|
|
*
|
|
|
|
* @param player <p>The player trying to create a portal</p>
|
|
|
|
* @param gate <p>The gate type of the new portal</p>
|
|
|
|
* @return <p>True if the player is allowed to create a portal with the given gate layout</p>
|
|
|
|
*/
|
2021-10-24 21:15:43 +02:00
|
|
|
public static boolean canCreatePortal(Player player, String gate) {
|
2021-10-28 18:29:33 +02:00
|
|
|
//Check if the player is allowed to create all gates
|
2021-09-20 13:56:30 +02:00
|
|
|
if (hasPermission(player, "stargate.create.gate")) {
|
2021-10-28 18:29:33 +02:00
|
|
|
//Check if the gate type has been explicitly denied
|
|
|
|
return hasPermissionImplicit(player, "stargate.create.gate." + gate);
|
2021-09-20 13:56:30 +02:00
|
|
|
}
|
2021-10-28 18:29:33 +02:00
|
|
|
//Check if the player can create the specific gate type
|
2021-09-20 13:56:30 +02:00
|
|
|
return hasPermission(player, "stargate.create.gate." + gate);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Checks if the given player can destroy the given portal
|
|
|
|
*
|
|
|
|
* @param player <p>The player trying to destroy the portal</p>
|
|
|
|
* @param portal <p>The portal to destroy</p>
|
|
|
|
* @return <p>True if the player is allowed to destroy the portal</p>
|
|
|
|
*/
|
|
|
|
public static boolean canDestroyPortal(Player player, Portal portal) {
|
|
|
|
String network = portal.getNetwork();
|
2021-10-28 18:29:33 +02:00
|
|
|
|
|
|
|
//Use a special check for bungee portals
|
|
|
|
if (portal.getOptions().isBungee()) {
|
|
|
|
return hasPermission(player, "stargate.admin.bungee");
|
2021-09-20 13:56:30 +02:00
|
|
|
}
|
2021-10-28 18:29:33 +02:00
|
|
|
|
|
|
|
//Check if the player is allowed to destroy on all networks
|
2021-09-20 13:56:30 +02:00
|
|
|
if (hasPermission(player, "stargate.destroy.network")) {
|
2021-10-28 18:29:33 +02:00
|
|
|
//Check if the network has been explicitly denied
|
|
|
|
return hasPermissionImplicit(player, "stargate.destroy.network." + network);
|
2021-09-20 13:56:30 +02:00
|
|
|
}
|
2021-10-28 18:29:33 +02:00
|
|
|
//Check if the player is allowed to destroy on the network
|
2021-09-20 13:56:30 +02:00
|
|
|
if (hasPermission(player, "stargate.destroy.network." + network)) {
|
|
|
|
return true;
|
|
|
|
}
|
2021-10-28 18:29:33 +02:00
|
|
|
//Check if personal portal and if the player is allowed to destroy it
|
2021-09-20 13:56:30 +02:00
|
|
|
return portal.isOwner(player) && hasPermission(player, "stargate.destroy.personal");
|
|
|
|
}
|
|
|
|
|
2021-10-12 02:47:09 +02:00
|
|
|
/**
|
|
|
|
* Decide of the player can teleport through a portal
|
|
|
|
*
|
|
|
|
* @param entrancePortal <p>The portal the player is entering from</p>
|
|
|
|
* @param destination <p>The destination of the portal the player is inside</p>
|
|
|
|
* @param player <p>The player wanting to teleport</p>
|
|
|
|
* @param event <p>The move event causing the teleportation</p>
|
|
|
|
* @return <p>True if the player cannot teleport. False otherwise</p>
|
|
|
|
*/
|
|
|
|
public static boolean playerCannotTeleport(Portal entrancePortal, Portal destination, Player player, PlayerMoveEvent event) {
|
2021-10-28 18:29:33 +02:00
|
|
|
//No portal or not open
|
2021-10-12 02:47:09 +02:00
|
|
|
if (entrancePortal == null || !entrancePortal.isOpen()) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2021-10-28 18:29:33 +02:00
|
|
|
//Not open for this player
|
2021-10-20 16:09:35 +02:00
|
|
|
if (!entrancePortal.getPortalOpener().isOpenFor(player)) {
|
2021-10-23 14:10:33 +02:00
|
|
|
Stargate.getMessageSender().sendErrorMessage(player, Stargate.getString("denyMsg"));
|
2021-10-18 18:38:36 +02:00
|
|
|
new PlayerTeleporter(entrancePortal, player).teleport(entrancePortal, event);
|
2021-10-12 02:47:09 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
//No destination
|
|
|
|
if (!entrancePortal.getOptions().isBungee() && destination == null) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
//Player cannot access portal
|
|
|
|
if (PermissionHelper.cannotAccessPortal(player, entrancePortal, destination)) {
|
2021-10-23 14:10:33 +02:00
|
|
|
Stargate.getMessageSender().sendErrorMessage(player, Stargate.getString("denyMsg"));
|
2021-10-18 18:38:36 +02:00
|
|
|
new PlayerTeleporter(entrancePortal, player).teleport(entrancePortal, event);
|
2021-10-20 16:09:35 +02:00
|
|
|
entrancePortal.getPortalOpener().closePortal(false);
|
2021-10-12 02:47:09 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
//Player cannot pay for teleportation
|
2021-10-23 03:56:59 +02:00
|
|
|
int cost = Stargate.getEconomyConfig().getUseCost(player, entrancePortal, destination);
|
2021-10-12 02:47:09 +02:00
|
|
|
if (cost > 0) {
|
2021-10-15 19:25:31 +02:00
|
|
|
return EconomyHelper.cannotPayTeleportFee(entrancePortal, player, cost);
|
2021-10-12 02:47:09 +02:00
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2021-09-20 13:56:30 +02:00
|
|
|
}
|