diff --git a/src/main/java/net/knarcraft/stargate/config/StargateConfig.java b/src/main/java/net/knarcraft/stargate/config/StargateConfig.java index 23cb4b7..de57922 100644 --- a/src/main/java/net/knarcraft/stargate/config/StargateConfig.java +++ b/src/main/java/net/knarcraft/stargate/config/StargateConfig.java @@ -434,12 +434,15 @@ public final class StargateConfig { } else { portalFolder = replacePluginFolderPath(portalFolder); } + Stargate.debug("StargateConfig::loadConfig", "Portal folder is " + portalFolder); + gateFolder = (String) configOptions.get(ConfigOption.GATE_FOLDER); if (gateFolder.isEmpty()) { gateFolder = dataFolderPath + "/gates/"; } else { gateFolder = replacePluginFolderPath(gateFolder); } + Stargate.debug("StargateConfig::loadConfig", "Gate folder is " + gateFolder); //If users have an outdated config, assume they also need to update their default gates if (isMigrating) { @@ -466,7 +469,7 @@ public final class StargateConfig { private String replacePluginFolderPath(@NotNull String input) { Pattern pattern = Pattern.compile("(?i)^plugins[\\\\\\/]Stargate"); Matcher matcher = pattern.matcher(input); - if (matcher.matches()) { + if (matcher.find()) { return dataFolderPath + matcher.replaceAll(""); } else { return input; diff --git a/src/main/java/net/knarcraft/stargate/utility/GateReader.java b/src/main/java/net/knarcraft/stargate/utility/GateReader.java index f57c6c0..fc1803a 100644 --- a/src/main/java/net/knarcraft/stargate/utility/GateReader.java +++ b/src/main/java/net/knarcraft/stargate/utility/GateReader.java @@ -4,6 +4,7 @@ import net.knarcraft.stargate.Stargate; import net.knarcraft.stargate.config.material.BukkitMaterialSpecifier; import net.knarcraft.stargate.config.material.MaterialSpecifier; import org.bukkit.Material; +import org.bukkit.configuration.InvalidConfigurationException; import org.jetbrains.annotations.NotNull; import java.util.ArrayList; @@ -108,11 +109,11 @@ public final class GateReader { * @param line

The line to read

* @param characterMaterialMap

The character to material map to store to

* @param config

The config value map to store to

- * @throws Exception

If an invalid material is encountered

+ * @throws InvalidConfigurationException

If an invalid material is encountered

*/ private static void readGateConfigValue(@NotNull String line, @NotNull Map> characterMaterialMap, - @NotNull Map config) throws Exception { + @NotNull Map config) throws InvalidConfigurationException { String[] split = line.split("="); String key = split[0].trim(); String value = split[1].trim(); @@ -125,7 +126,7 @@ public final class GateReader { if (!materials.isEmpty()) { characterMaterialMap.put(symbol, materials); } else { - throw new Exception("Invalid material in line: " + line); + throw new InvalidConfigurationException("Invalid material in line: " + line); } } else { //Read a normal config value diff --git a/src/main/java/net/knarcraft/stargate/utility/PermissionHelper.java b/src/main/java/net/knarcraft/stargate/utility/PermissionHelper.java index ea36003..93c0862 100644 --- a/src/main/java/net/knarcraft/stargate/utility/PermissionHelper.java +++ b/src/main/java/net/knarcraft/stargate/utility/PermissionHelper.java @@ -53,13 +53,31 @@ public final class PermissionHelper { return; } + // Check if the player is able to open the portal + if (canNotOpen(player, portal, destination)) { + return; + } + + //Open the portal + portal.getPortalOpener().openPortal(player, false); + } + + /** + * Checks whether something prevents the player from opening the given portal to the given destination + * + * @param player

The player trying to open the portal

+ * @param portal

The portal to open

+ * @param destination

The destination the player is attempting to open

+ * @return

True if the player cannot open the portal

+ */ + private static boolean canNotOpen(Player player, Portal portal, Portal destination) { //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) { if (!portal.getOptions().isSilent()) { Stargate.getMessageSender().sendErrorMessage(player, Stargate.getString(Message.ACCESS_DENIED)); } - return; + return true; } //Check if the player can use the private gate @@ -67,7 +85,7 @@ public final class PermissionHelper { if (!portal.getOptions().isSilent()) { Stargate.getMessageSender().sendErrorMessage(player, Stargate.getString(Message.ACCESS_DENIED)); } - return; + return true; } //Destination is currently in use by another player, blocking teleportation @@ -75,11 +93,10 @@ public final class PermissionHelper { if (!portal.getOptions().isSilent()) { Stargate.getMessageSender().sendErrorMessage(player, Stargate.getString(Message.DESTINATION_BLOCKED)); } - return; + return true; } - //Open the portal - portal.getPortalOpener().openPortal(player, false); + return false; } /** @@ -109,26 +126,27 @@ public final class PermissionHelper { public static boolean cannotAccessPortal(@NotNull Player player, @NotNull Portal entrancePortal, @Nullable Portal destination) { boolean deny = false; + String route = "PermissionHelper::cannotAccessPortal"; if (entrancePortal.getOptions().isBungee()) { if (!PermissionHelper.canAccessServer(player, entrancePortal.getCleanNetwork())) { //If the portal is a bungee portal, and the player cannot access the server, deny - Stargate.debug("cannotAccessPortal", "Cannot access server"); + Stargate.debug(route, "Cannot access server"); deny = true; } } else if (PermissionHelper.cannotAccessNetwork(player, entrancePortal.getCleanNetwork())) { //If the player does not have access to the network, deny - Stargate.debug("cannotAccessPortal", "Cannot access network"); + Stargate.debug(route, "Cannot access network"); deny = true; } else { if (destination == null) { //If there is no destination, deny - Stargate.debug("cannotAccessPortal", "Portal has no destination"); + Stargate.debug(route, "Portal has no destination"); deny = true; } else if (destination.getWorld() != null && PermissionHelper.cannotAccessWorld(player, destination.getWorld().getName())) { //If the player does not have access to the portal's world, deny - Stargate.debug("cannotAccessPortal", "Cannot access world"); + Stargate.debug(route, "Cannot access world"); deny = true; } } diff --git a/src/main/java/net/knarcraft/stargate/utility/PortalFileHelper.java b/src/main/java/net/knarcraft/stargate/utility/PortalFileHelper.java index bfc8d8f..0fd620d 100644 --- a/src/main/java/net/knarcraft/stargate/utility/PortalFileHelper.java +++ b/src/main/java/net/knarcraft/stargate/utility/PortalFileHelper.java @@ -59,14 +59,14 @@ public final class PortalFileHelper { if (portal.getWorld() == null) { Stargate.logSevere(String.format("Could not save portal %s because its world is null", portal.getName())); - continue; + } else { + String worldName = portal.getWorld().getName(); + if (!worldName.equalsIgnoreCase(world.getName())) { + continue; + } + //Save the portal + savePortal(bufferedWriter, portal); } - String worldName = portal.getWorld().getName(); - if (!worldName.equalsIgnoreCase(world.getName())) { - continue; - } - //Save the portal - savePortal(bufferedWriter, portal); } bufferedWriter.close();