Improves some variable names and adds some comments
This commit is contained in:
@ -1,6 +1,7 @@
|
||||
package net.knarcraft.stargate.utility;
|
||||
|
||||
import net.knarcraft.stargate.Stargate;
|
||||
import net.knarcraft.stargate.event.StargateAccessEvent;
|
||||
import net.knarcraft.stargate.portal.Portal;
|
||||
import net.knarcraft.stargate.portal.PortalOption;
|
||||
import org.bukkit.entity.Player;
|
||||
@ -14,6 +15,102 @@ public final class PermissionHelper {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 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) {
|
||||
Portal destination = portal.getDestination();
|
||||
|
||||
//Always-open gate -- Do nothing
|
||||
if (portal.isAlwaysOn()) {
|
||||
return;
|
||||
}
|
||||
|
||||
//Random gate -- Do nothing
|
||||
if (portal.isRandom()) {
|
||||
return;
|
||||
}
|
||||
|
||||
//Invalid destination
|
||||
if ((destination == null) || (destination == portal)) {
|
||||
Stargate.sendErrorMessage(player, Stargate.getString("invalidMsg"));
|
||||
return;
|
||||
}
|
||||
|
||||
//Gate is already open
|
||||
if (portal.isOpen()) {
|
||||
// Close if this player opened the gate
|
||||
if (portal.getActivePlayer() == player) {
|
||||
portal.close(false);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
//Gate that someone else is using -- Deny access
|
||||
if ((!portal.isFixed()) && portal.isActive() && (portal.getActivePlayer() != player)) {
|
||||
Stargate.sendErrorMessage(player, Stargate.getString("denyMsg"));
|
||||
return;
|
||||
}
|
||||
|
||||
//Check if the player can use the private gate
|
||||
if (portal.isPrivate() && !PermissionHelper.canPrivate(player, portal)) {
|
||||
Stargate.sendErrorMessage(player, Stargate.getString("denyMsg"));
|
||||
return;
|
||||
}
|
||||
|
||||
//Destination blocked
|
||||
if ((destination.isOpen()) && (!destination.isAlwaysOn())) {
|
||||
Stargate.sendErrorMessage(player, Stargate.getString("blockMsg"));
|
||||
return;
|
||||
}
|
||||
|
||||
//Open gate
|
||||
portal.open(player, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a StargateAccessPortal and gives the result
|
||||
*
|
||||
* <p>The event is used for other plugins to bypass the permission checks</p>
|
||||
*
|
||||
* @param player <p>The player trying to use the portal</p>
|
||||
* @param portal <p>The portal the player is trying to use</p>
|
||||
* @param deny <p>Whether the player's access has already been denied by a check</p>
|
||||
* @return <p>False if the player should be allowed through the portal</p>
|
||||
*/
|
||||
public static boolean cannotAccessPortal(Player player, Portal portal, boolean deny) {
|
||||
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>
|
||||
* @param destination <p>The portal the user wants to exit</p>
|
||||
* @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;
|
||||
// Check if player has access to this server for Bungee gates
|
||||
if (entrancePortal.isBungee() && !PermissionHelper.canAccessServer(player, entrancePortal.getNetwork())) {
|
||||
Stargate.debug("cannotAccessPortal", "Cannot access server");
|
||||
deny = true;
|
||||
} else if (PermissionHelper.cannotAccessNetwork(player, entrancePortal.getNetwork())) {
|
||||
Stargate.debug("cannotAccessPortal", "Cannot access network");
|
||||
deny = true;
|
||||
} else if (!entrancePortal.isBungee() && PermissionHelper.cannotAccessWorld(player, destination.getWorld().getName())) {
|
||||
Stargate.debug("cannotAccessPortal", "Cannot access world");
|
||||
deny = true;
|
||||
}
|
||||
return cannotAccessPortal(player, entrancePortal, deny);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks whether a player has the given permission
|
||||
*
|
||||
@ -55,8 +152,9 @@ public final class PermissionHelper {
|
||||
|
||||
/**
|
||||
* Checks whether a player can access the given world
|
||||
*
|
||||
* @param player <p>The player trying to access the world</p>
|
||||
* @param world <p>The world the player is trying to access</p>
|
||||
* @param world <p>The world the player is trying to access</p>
|
||||
* @return <p>False if the player should be allowed to access the world</p>
|
||||
*/
|
||||
public static boolean cannotAccessWorld(Player player, String world) {
|
||||
@ -96,6 +194,7 @@ public final class PermissionHelper {
|
||||
|
||||
/**
|
||||
* Checks whether a player can access the given bungee server
|
||||
*
|
||||
* @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>
|
||||
|
Reference in New Issue
Block a user