diff --git a/src/main/java/me/SuperRonanCraft/BetterRTP/player/rtp/RTP.java b/src/main/java/me/SuperRonanCraft/BetterRTP/player/rtp/RTP.java index 77752a8..c3a25bf 100644 --- a/src/main/java/me/SuperRonanCraft/BetterRTP/player/rtp/RTP.java +++ b/src/main/java/me/SuperRonanCraft/BetterRTP/player/rtp/RTP.java @@ -26,6 +26,7 @@ import java.util.concurrent.CompletableFuture; public class RTP { private final RTPTeleport teleport = new RTPTeleport(); + private final RTPSoftDepends softDepends = new RTPSoftDepends(); //Cache public HashMap customWorlds = new HashMap<>(); public HashMap overriden = new HashMap<>(); @@ -362,20 +363,8 @@ public class RTP { return null; } - @SuppressWarnings("all") private boolean checkDepends(Location loc) { - try { - if (getPl().getSettings().getsDepends().isWorldguard()) { - WorldGuardPlugin plugin = WGBukkit.getPlugin(); - RegionContainer container = plugin.getRegionContainer(); - RegionManager regions = container.get(loc.getWorld()); - // Check to make sure that "regions" is not null - return regions.getApplicableRegions(loc).size() == 0; - } - return !getPl().getSettings().getsDepends().isGriefprevention() || GriefPrevention.instance.dataStore.getClaimAt(loc, true, null) == null; - } catch (NoClassDefFoundError e) { - return true; - } + return softDepends.checkLocation(loc); } // Bad blocks, or bad biome diff --git a/src/main/java/me/SuperRonanCraft/BetterRTP/player/rtp/RTPSoftDepends.java b/src/main/java/me/SuperRonanCraft/BetterRTP/player/rtp/RTPSoftDepends.java new file mode 100644 index 0000000..169828b --- /dev/null +++ b/src/main/java/me/SuperRonanCraft/BetterRTP/player/rtp/RTPSoftDepends.java @@ -0,0 +1,46 @@ +package me.SuperRonanCraft.BetterRTP.player.rtp; + +import com.sk89q.worldguard.bukkit.RegionContainer; +import com.sk89q.worldguard.bukkit.WGBukkit; +import com.sk89q.worldguard.bukkit.WorldGuardPlugin; +import com.sk89q.worldguard.protection.managers.RegionManager; +import me.SuperRonanCraft.BetterRTP.Main; +import me.ryanhamshire.GriefPrevention.GriefPrevention; +import org.bukkit.Location; + +public class RTPSoftDepends { //Safe locations depending on enabled dependencies + + boolean checkLocation(Location loc) { + boolean worldguard = getWorlguard(loc); + boolean griefPrevention = getGriefprevention(loc); + return worldguard && griefPrevention; + } + + private boolean getWorlguard(Location loc) { + if (getPl().getSettings().getsDepends().isWorldguard()) + try { + WorldGuardPlugin plugin = WGBukkit.getPlugin(); + RegionContainer container = plugin.getRegionContainer(); + RegionManager regions = container.get(loc.getWorld()); + // Check to make sure that "regions" is not null + return (regions != null ? regions.getApplicableRegions(loc).size() : 0) == 0; + } catch (NoClassDefFoundError e) { + return true; + } + return true; + } + + private boolean getGriefprevention(Location loc) { + if (getPl().getSettings().getsDepends().isGriefprevention()) + try { + return GriefPrevention.instance.dataStore.getClaimAt(loc, true, null) == null; + } catch (NoClassDefFoundError e) { + return true; + } + return true; + } + + private Main getPl() { + return Main.getInstance(); + } +}