mirror of
https://gitlab.com/SamB440/rpgregions-2.git
synced 2025-12-23 00:39:34 +00:00
Add check to ensure region exists
This commit is contained in:
@@ -8,6 +8,7 @@ import net.islandearth.rpgregions.api.integrations.IntegrationManager;
|
||||
import net.islandearth.rpgregions.managers.data.region.ConfiguredRegion;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.player.PlayerMoveEvent;
|
||||
|
||||
@@ -60,6 +61,14 @@ public class WorldGuardLegacyIntegration implements IntegrationManager {
|
||||
return plugin.getManagers().getRegionsCache().getConfiguredRegion(highest.getId());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean exists(World world, String region) {
|
||||
return WorldGuardPlugin.inst()
|
||||
.getRegionContainer()
|
||||
.get(world)
|
||||
.getRegions().containsKey(region);
|
||||
}
|
||||
|
||||
private Set<ProtectedRegion> getProtectedRegions(Location location) {
|
||||
return WorldGuardPlugin.inst()
|
||||
.getRegionContainer()
|
||||
|
||||
@@ -10,6 +10,7 @@ import net.islandearth.rpgregions.api.integrations.IntegrationManager;
|
||||
import net.islandearth.rpgregions.managers.data.region.ConfiguredRegion;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.player.PlayerMoveEvent;
|
||||
|
||||
@@ -61,7 +62,16 @@ public class WorldGuardIntegration implements IntegrationManager {
|
||||
if (highest == null) return null;
|
||||
return plugin.getManagers().getRegionsCache().getConfiguredRegion(highest.getId());
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean exists(World world, String region) {
|
||||
return WorldGuard.getInstance()
|
||||
.getPlatform()
|
||||
.getRegionContainer()
|
||||
.get(BukkitAdapter.adapt(world))
|
||||
.getRegions().containsKey(region);
|
||||
}
|
||||
|
||||
private Set<ProtectedRegion> getProtectedRegions(Location location) {
|
||||
return WorldGuard.getInstance()
|
||||
.getPlatform()
|
||||
|
||||
@@ -2,6 +2,7 @@ package net.islandearth.rpgregions.api.integrations;
|
||||
|
||||
import net.islandearth.rpgregions.managers.data.region.ConfiguredRegion;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.event.player.PlayerMoveEvent;
|
||||
|
||||
public interface IntegrationManager {
|
||||
@@ -26,4 +27,6 @@ public interface IntegrationManager {
|
||||
*/
|
||||
ConfiguredRegion getPrioritisedRegion(Location location);
|
||||
|
||||
boolean exists(World location, String region);
|
||||
|
||||
}
|
||||
|
||||
@@ -57,6 +57,11 @@ public class RPGRegionsCommand extends BaseCommand {
|
||||
public void onAdd(Player player, String[] args) {
|
||||
if (args.length == 1) {
|
||||
String region = args[0];
|
||||
if (!plugin.getManagers().getIntegrationManager().exists(player.getLocation().getWorld(), region)) {
|
||||
player.sendMessage(StringUtils.colour("&cThat region does not exist in your protection plugin."));
|
||||
return;
|
||||
}
|
||||
|
||||
int x = player.getLocation().getBlockX();
|
||||
int y = player.getLocation().getBlockY();
|
||||
int z = player.getLocation().getBlockZ();
|
||||
|
||||
Reference in New Issue
Block a user