Improves some variable names and adds some comments

This commit is contained in:
2021-09-20 18:22:20 +02:00
parent d24f35375a
commit 1e29db58b9
15 changed files with 310 additions and 210 deletions

View File

@ -48,7 +48,7 @@ public final class BungeeHelper {
dataOutputStream.writeBytes(message);
player.sendPluginMessage(Stargate.stargate, bungeeChannel, byteArrayOutputStream.toByteArray());
} catch (IOException ex) {
Stargate.log.severe(Stargate.getString("prefix") + "Error sending BungeeCord teleport packet");
Stargate.logger.severe(Stargate.getString("prefix") + "Error sending BungeeCord teleport packet");
ex.printStackTrace();
return false;
}
@ -72,7 +72,7 @@ public final class BungeeHelper {
player.sendPluginMessage(Stargate.stargate, bungeeChannel, byteArrayOutputStream.toByteArray());
byteArrayOutputStream.reset();
} catch (IOException ex) {
Stargate.log.severe(Stargate.getString("prefix") + "Error sending BungeeCord connect packet");
Stargate.logger.severe(Stargate.getString("prefix") + "Error sending BungeeCord connect packet");
ex.printStackTrace();
return false;
}
@ -99,7 +99,7 @@ public final class BungeeHelper {
data = new byte[dataLength];
dataInputStream.readFully(data);
} catch (IOException ex) {
Stargate.log.severe(Stargate.getString("prefix") + "Error receiving BungeeCord message");
Stargate.logger.severe(Stargate.getString("prefix") + "Error receiving BungeeCord message");
ex.printStackTrace();
return null;
}
@ -127,7 +127,7 @@ public final class BungeeHelper {
Portal destinationPortal = PortalHandler.getBungeeGate(destination);
// Specified an invalid gate. For now we'll just let them connect at their current location
if (destinationPortal == null) {
Stargate.log.info(Stargate.getString("prefix") + "Bungee gate " + destination + " does not exist");
Stargate.logger.info(Stargate.getString("prefix") + "Bungee gate " + destination + " does not exist");
return;
}
destinationPortal.teleport(player, destinationPortal, null);

View File

@ -152,10 +152,10 @@ public final class EconomyHandler {
EconomyHandler.vault = vault;
return true;
} else {
Stargate.log.info(Stargate.getString("prefix") + Stargate.getString("ecoLoadError"));
Stargate.logger.info(Stargate.getString("prefix") + Stargate.getString("ecoLoadError"));
}
} else {
Stargate.log.info(Stargate.getString("prefix") + Stargate.getString("vaultLoadError"));
Stargate.logger.info(Stargate.getString("prefix") + Stargate.getString("vaultLoadError"));
}
economyEnabled = false;
return false;

View File

@ -68,7 +68,7 @@ public final class EconomyHelper {
public static void sendObtainMessage(String portalName, Player portalOwner, int earnings) {
String obtainedMsg = Stargate.getString("ecoObtain");
obtainedMsg = replaceVars(obtainedMsg, portalName, earnings);
Stargate.sendMessage(portalOwner, obtainedMsg, false);
Stargate.sendSuccessMessage(portalOwner, obtainedMsg);
}
/**
@ -81,7 +81,7 @@ public final class EconomyHelper {
public static void sendDeductMessage(String portalName, Player player, int cost) {
String deductMsg = Stargate.getString("ecoDeduct");
deductMsg = replaceVars(deductMsg, portalName, cost);
Stargate.sendMessage(player, deductMsg, false);
Stargate.sendSuccessMessage(player, deductMsg);
}
/**
@ -94,7 +94,7 @@ public final class EconomyHelper {
public static void sendInsufficientFundsMessage(String portalName, Player player, int cost) {
String inFundMsg = Stargate.getString("ecoInFunds");
inFundMsg = replaceVars(inFundMsg, portalName, cost);
Stargate.sendMessage(player, inFundMsg);
Stargate.sendErrorMessage(player, inFundMsg);
}
/**
@ -107,7 +107,7 @@ public final class EconomyHelper {
public static void sendRefundMessage(String portalName, Player player, int cost) {
String refundMsg = Stargate.getString("ecoRefund");
refundMsg = replaceVars(refundMsg, portalName, -cost);
Stargate.sendMessage(player, refundMsg, false);
Stargate.sendSuccessMessage(player, refundMsg);
}
/**

View File

@ -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>