From 682d835961cb13e23f6f2e05db93951fe3a3c725 Mon Sep 17 00:00:00 2001 From: BONNe Date: Fri, 30 Sep 2022 14:34:28 +0300 Subject: [PATCH] Add all dimension checks for methods. --- .../teleports/AbstractTeleportListener.java | 49 +++++++++++++------ 1 file changed, 33 insertions(+), 16 deletions(-) diff --git a/src/main/java/world/bentobox/bentobox/listeners/teleports/AbstractTeleportListener.java b/src/main/java/world/bentobox/bentobox/listeners/teleports/AbstractTeleportListener.java index fa618b899..bb8638cc9 100644 --- a/src/main/java/world/bentobox/bentobox/listeners/teleports/AbstractTeleportListener.java +++ b/src/main/java/world/bentobox/bentobox/listeners/teleports/AbstractTeleportListener.java @@ -19,6 +19,7 @@ import java.util.*; import world.bentobox.bentobox.BentoBox; import world.bentobox.bentobox.api.addons.GameModeAddon; import world.bentobox.bentobox.database.objects.Island; +import world.bentobox.bentobox.util.Util; /** @@ -88,9 +89,11 @@ public abstract class AbstractTeleportListener */ protected boolean isMakePortals(GameModeAddon gameMode, World.Environment environment) { - return environment.equals(World.Environment.NETHER) ? - gameMode.getWorldSettings().isMakeNetherPortals() : - gameMode.getWorldSettings().isMakeEndPortals(); + return switch (environment) { + case NETHER -> gameMode.getWorldSettings().isMakeNetherPortals(); + case THE_END -> gameMode.getWorldSettings().isMakeEndPortals(); + default -> false; + }; } @@ -98,14 +101,16 @@ public abstract class AbstractTeleportListener * Check if nether or end are generated * * @param overWorld - game world - * @param env - environment + * @param environment - environment * @return true or false */ - protected boolean isAllowedInConfig(World overWorld, World.Environment env) + protected boolean isAllowedInConfig(World overWorld, World.Environment environment) { - return env.equals(World.Environment.NETHER) ? - this.plugin.getIWM().isNetherGenerate(overWorld) : - this.plugin.getIWM().isEndGenerate(overWorld); + return switch (environment) { + case NETHER -> this.plugin.getIWM().isNetherGenerate(overWorld); + case THE_END -> this.plugin.getIWM().isEndGenerate(overWorld); + default -> true; + }; } @@ -117,7 +122,11 @@ public abstract class AbstractTeleportListener */ protected boolean isAllowedOnServer(World.Environment environment) { - return environment.equals(World.Environment.NETHER) ? Bukkit.getAllowNether() : Bukkit.getAllowEnd(); + return switch (environment) { + case NETHER -> Bukkit.getAllowNether(); + case THE_END -> Bukkit.getAllowEnd(); + default -> true; + }; } @@ -130,9 +139,11 @@ public abstract class AbstractTeleportListener */ protected boolean isIslandWorld(World overWorld, World.Environment environment) { - return environment.equals(World.Environment.NETHER) ? - this.plugin.getIWM().isNetherIslands(overWorld) : - this.plugin.getIWM().isEndIslands(overWorld); + return switch (environment) { + case NETHER -> this.plugin.getIWM().isNetherIslands(overWorld); + case THE_END -> this.plugin.getIWM().isEndIslands(overWorld); + default -> true; + }; } @@ -145,9 +156,11 @@ public abstract class AbstractTeleportListener */ protected World getNetherEndWorld(World overWorld, World.Environment environment) { - return environment.equals(World.Environment.NETHER) ? - this.plugin.getIWM().getNetherWorld(overWorld) : - this.plugin.getIWM().getEndWorld(overWorld); + return switch (environment) { + case NETHER -> this.plugin.getIWM().getNetherWorld(overWorld); + case THE_END -> this.plugin.getIWM().getEndWorld(overWorld); + default -> Util.getWorld(overWorld); + }; } @@ -160,7 +173,11 @@ public abstract class AbstractTeleportListener */ protected boolean hasPartnerIsland(Island island, World.Environment environment) { - return environment.equals(World.Environment.NETHER) ? island.hasNetherIsland() : island.hasEndIsland(); + return switch (environment) { + case NETHER -> island.hasNetherIsland(); + case THE_END -> island.hasEndIsland(); + default -> true; + }; }