mirror of
https://gitlab.com/SamB440/rpgregions-2.git
synced 2025-12-23 16:59:32 +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 net.islandearth.rpgregions.managers.data.region.ConfiguredRegion;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
|
import org.bukkit.World;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.event.player.PlayerMoveEvent;
|
import org.bukkit.event.player.PlayerMoveEvent;
|
||||||
|
|
||||||
@@ -60,6 +61,14 @@ public class WorldGuardLegacyIntegration implements IntegrationManager {
|
|||||||
return plugin.getManagers().getRegionsCache().getConfiguredRegion(highest.getId());
|
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) {
|
private Set<ProtectedRegion> getProtectedRegions(Location location) {
|
||||||
return WorldGuardPlugin.inst()
|
return WorldGuardPlugin.inst()
|
||||||
.getRegionContainer()
|
.getRegionContainer()
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ import net.islandearth.rpgregions.api.integrations.IntegrationManager;
|
|||||||
import net.islandearth.rpgregions.managers.data.region.ConfiguredRegion;
|
import net.islandearth.rpgregions.managers.data.region.ConfiguredRegion;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
|
import org.bukkit.World;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.event.player.PlayerMoveEvent;
|
import org.bukkit.event.player.PlayerMoveEvent;
|
||||||
|
|
||||||
@@ -62,6 +63,15 @@ public class WorldGuardIntegration implements IntegrationManager {
|
|||||||
return plugin.getManagers().getRegionsCache().getConfiguredRegion(highest.getId());
|
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) {
|
private Set<ProtectedRegion> getProtectedRegions(Location location) {
|
||||||
return WorldGuard.getInstance()
|
return WorldGuard.getInstance()
|
||||||
.getPlatform()
|
.getPlatform()
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package net.islandearth.rpgregions.api.integrations;
|
|||||||
|
|
||||||
import net.islandearth.rpgregions.managers.data.region.ConfiguredRegion;
|
import net.islandearth.rpgregions.managers.data.region.ConfiguredRegion;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
|
import org.bukkit.World;
|
||||||
import org.bukkit.event.player.PlayerMoveEvent;
|
import org.bukkit.event.player.PlayerMoveEvent;
|
||||||
|
|
||||||
public interface IntegrationManager {
|
public interface IntegrationManager {
|
||||||
@@ -26,4 +27,6 @@ public interface IntegrationManager {
|
|||||||
*/
|
*/
|
||||||
ConfiguredRegion getPrioritisedRegion(Location location);
|
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) {
|
public void onAdd(Player player, String[] args) {
|
||||||
if (args.length == 1) {
|
if (args.length == 1) {
|
||||||
String region = args[0];
|
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 x = player.getLocation().getBlockX();
|
||||||
int y = player.getLocation().getBlockY();
|
int y = player.getLocation().getBlockY();
|
||||||
int z = player.getLocation().getBlockZ();
|
int z = player.getLocation().getBlockZ();
|
||||||
|
|||||||
Reference in New Issue
Block a user