soft depends seperated from main RTP class

This commit is contained in:
SuperRonanCraft 2020-09-19 02:15:47 -04:00
parent 77a94812d5
commit 211d3609d4
2 changed files with 48 additions and 13 deletions

View File

@ -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<String, RTPWorld> customWorlds = new HashMap<>();
public HashMap<String, String> 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

View File

@ -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();
}
}