mirror of
https://github.com/EngineHub/WorldGuard.git
synced 2024-12-01 06:53:36 +01:00
Added proper support for global regions and a region ID validation regex.
This commit is contained in:
parent
949c6599b3
commit
521ecd438e
@ -55,7 +55,15 @@ public static void define(CommandContext args, WorldGuardPlugin plugin,
|
|||||||
|
|
||||||
Player player = plugin.checkPlayer(sender);
|
Player player = plugin.checkPlayer(sender);
|
||||||
WorldEditPlugin worldEdit = plugin.getWorldEdit();
|
WorldEditPlugin worldEdit = plugin.getWorldEdit();
|
||||||
String id = args.getString(0).replace(".", "");
|
String id = args.getString(0);
|
||||||
|
|
||||||
|
if (!ProtectedRegion.isValidId(id)) {
|
||||||
|
throw new CommandException("Invalid region ID specified!");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (id.equalsIgnoreCase("__global__")) {
|
||||||
|
throw new CommandException("A region cannot be named __global__");
|
||||||
|
}
|
||||||
|
|
||||||
// Attempt to get the player's selection from WorldEdit
|
// Attempt to get the player's selection from WorldEdit
|
||||||
Selection sel = worldEdit.getSelection(player);
|
Selection sel = worldEdit.getSelection(player);
|
||||||
@ -111,6 +119,10 @@ public static void redefine(CommandContext args, WorldGuardPlugin plugin,
|
|||||||
LocalPlayer localPlayer = plugin.wrapPlayer(player);
|
LocalPlayer localPlayer = plugin.wrapPlayer(player);
|
||||||
String id = args.getString(0);
|
String id = args.getString(0);
|
||||||
|
|
||||||
|
if (id.equalsIgnoreCase("__global__")) {
|
||||||
|
throw new CommandException("The region cannot be named __global__");
|
||||||
|
}
|
||||||
|
|
||||||
RegionManager mgr = plugin.getGlobalRegionManager().get(world);
|
RegionManager mgr = plugin.getGlobalRegionManager().get(world);
|
||||||
ProtectedRegion existing = mgr.getRegion(id);
|
ProtectedRegion existing = mgr.getRegion(id);
|
||||||
|
|
||||||
@ -182,7 +194,15 @@ public static void claim(CommandContext args, WorldGuardPlugin plugin,
|
|||||||
Player player = plugin.checkPlayer(sender);
|
Player player = plugin.checkPlayer(sender);
|
||||||
LocalPlayer localPlayer = plugin.wrapPlayer(player);
|
LocalPlayer localPlayer = plugin.wrapPlayer(player);
|
||||||
WorldEditPlugin worldEdit = plugin.getWorldEdit();
|
WorldEditPlugin worldEdit = plugin.getWorldEdit();
|
||||||
String id = args.getString(0).replace(".", "");
|
String id = args.getString(0);
|
||||||
|
|
||||||
|
if (!ProtectedRegion.isValidId(id)) {
|
||||||
|
throw new CommandException("Invalid region ID specified!");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (id.equalsIgnoreCase("__global__")) {
|
||||||
|
throw new CommandException("A region cannot be named __global__");
|
||||||
|
}
|
||||||
|
|
||||||
// Attempt to get the player's selection from WorldEdit
|
// Attempt to get the player's selection from WorldEdit
|
||||||
Selection sel = worldEdit.getSelection(player);
|
Selection sel = worldEdit.getSelection(player);
|
||||||
@ -310,6 +330,10 @@ public static void info(CommandContext args, WorldGuardPlugin plugin,
|
|||||||
id = args.getString(1).toLowerCase();
|
id = args.getString(1).toLowerCase();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!ProtectedRegion.isValidId(id)) {
|
||||||
|
throw new CommandException("Invalid region ID specified!");
|
||||||
|
}
|
||||||
|
|
||||||
RegionManager mgr = plugin.getGlobalRegionManager().get(world);
|
RegionManager mgr = plugin.getGlobalRegionManager().get(world);
|
||||||
|
|
||||||
if (!mgr.hasRegion(id)) {
|
if (!mgr.hasRegion(id)) {
|
||||||
@ -435,8 +459,13 @@ public static void flag(CommandContext args, WorldGuardPlugin plugin,
|
|||||||
ProtectedRegion region = mgr.getRegion(id);
|
ProtectedRegion region = mgr.getRegion(id);
|
||||||
|
|
||||||
if (region == null) {
|
if (region == null) {
|
||||||
|
if (id.equalsIgnoreCase("__global__")) {
|
||||||
|
region = new GlobalProtectedRegion(id);
|
||||||
|
mgr.addRegion(region);
|
||||||
|
} else {
|
||||||
throw new CommandException("Could not find a region by that ID.");
|
throw new CommandException("Could not find a region by that ID.");
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (region.isOwner(localPlayer)) {
|
if (region.isOwner(localPlayer)) {
|
||||||
plugin.checkPermission(sender, "worldguard.region.flag.own");
|
plugin.checkPermission(sender, "worldguard.region.flag.own");
|
||||||
@ -518,6 +547,10 @@ public static void setPriority(CommandContext args, WorldGuardPlugin plugin,
|
|||||||
String id = args.getString(0);
|
String id = args.getString(0);
|
||||||
int priority = args.getInteger(1);
|
int priority = args.getInteger(1);
|
||||||
|
|
||||||
|
if (id.equalsIgnoreCase("__global__")) {
|
||||||
|
throw new CommandException("The region cannot be named __global__");
|
||||||
|
}
|
||||||
|
|
||||||
RegionManager mgr = plugin.getGlobalRegionManager().get(world);
|
RegionManager mgr = plugin.getGlobalRegionManager().get(world);
|
||||||
ProtectedRegion region = mgr.getRegion(id);
|
ProtectedRegion region = mgr.getRegion(id);
|
||||||
|
|
||||||
@ -560,6 +593,10 @@ public static void setParent(CommandContext args, WorldGuardPlugin plugin,
|
|||||||
String id = args.getString(0);
|
String id = args.getString(0);
|
||||||
String parentId = args.getString(1);
|
String parentId = args.getString(1);
|
||||||
|
|
||||||
|
if (id.equalsIgnoreCase("__global__")) {
|
||||||
|
throw new CommandException("The region cannot be named __global__");
|
||||||
|
}
|
||||||
|
|
||||||
RegionManager mgr = plugin.getGlobalRegionManager().get(world);
|
RegionManager mgr = plugin.getGlobalRegionManager().get(world);
|
||||||
ProtectedRegion region = mgr.getRegion(id);
|
ProtectedRegion region = mgr.getRegion(id);
|
||||||
ProtectedRegion parent = mgr.getRegion(parentId);
|
ProtectedRegion parent = mgr.getRegion(parentId);
|
||||||
|
@ -33,6 +33,7 @@
|
|||||||
import com.sk89q.worldguard.domains.DefaultDomain;
|
import com.sk89q.worldguard.domains.DefaultDomain;
|
||||||
import com.sk89q.worldguard.protection.flags.DefaultFlag;
|
import com.sk89q.worldguard.protection.flags.DefaultFlag;
|
||||||
import com.sk89q.worldguard.protection.flags.Flag;
|
import com.sk89q.worldguard.protection.flags.Flag;
|
||||||
|
import com.sk89q.worldguard.protection.regions.GlobalProtectedRegion;
|
||||||
import com.sk89q.worldguard.protection.regions.ProtectedCuboidRegion;
|
import com.sk89q.worldguard.protection.regions.ProtectedCuboidRegion;
|
||||||
import com.sk89q.worldguard.protection.regions.ProtectedPolygonalRegion;
|
import com.sk89q.worldguard.protection.regions.ProtectedPolygonalRegion;
|
||||||
import com.sk89q.worldguard.protection.regions.ProtectedRegion;
|
import com.sk89q.worldguard.protection.regions.ProtectedRegion;
|
||||||
@ -86,6 +87,8 @@ public void load() throws IOException {
|
|||||||
Integer maxY = checkNonNull(node.getInt("max-y"));
|
Integer maxY = checkNonNull(node.getInt("max-y"));
|
||||||
List<BlockVector2D> points = node.getBlockVector2dList("points", null);
|
List<BlockVector2D> points = node.getBlockVector2dList("points", null);
|
||||||
region = new ProtectedPolygonalRegion(id, points, minY, maxY);
|
region = new ProtectedPolygonalRegion(id, points, minY, maxY);
|
||||||
|
} else if (type.equals("global")) {
|
||||||
|
region = new GlobalProtectedRegion(id);
|
||||||
} else {
|
} else {
|
||||||
logger.warning("Unknown region type for region '" + id + '"');
|
logger.warning("Unknown region type for region '" + id + '"');
|
||||||
continue;
|
continue;
|
||||||
@ -181,6 +184,8 @@ public void save() throws IOException {
|
|||||||
}
|
}
|
||||||
|
|
||||||
node.setProperty("points", points);
|
node.setProperty("points", points);
|
||||||
|
} else if (region instanceof GlobalProtectedRegion) {
|
||||||
|
node.setProperty("type", "global");
|
||||||
} else {
|
} else {
|
||||||
node.setProperty("type", region.getClass().getCanonicalName());
|
node.setProperty("type", region.getClass().getCanonicalName());
|
||||||
}
|
}
|
||||||
|
@ -28,6 +28,7 @@
|
|||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents a region of any shape and size that can be protected.
|
* Represents a region of any shape and size that can be protected.
|
||||||
@ -35,6 +36,9 @@
|
|||||||
* @author sk89q
|
* @author sk89q
|
||||||
*/
|
*/
|
||||||
public abstract class ProtectedRegion implements Comparable<ProtectedRegion> {
|
public abstract class ProtectedRegion implements Comparable<ProtectedRegion> {
|
||||||
|
|
||||||
|
private static final Pattern idPattern = Pattern.compile("^[A-Za-z0-9_,'\\-\\+/]{1,}$");
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Holds the region's ID.
|
* Holds the region's ID.
|
||||||
*/
|
*/
|
||||||
@ -343,6 +347,16 @@ public abstract List<ProtectedRegion> getIntersectingRegions(
|
|||||||
List<ProtectedRegion> regions)
|
List<ProtectedRegion> regions)
|
||||||
throws UnsupportedIntersectionException;
|
throws UnsupportedIntersectionException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks to see if the given ID is accurate.
|
||||||
|
*
|
||||||
|
* @param id
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public static boolean isValidId(String id) {
|
||||||
|
return idPattern.matcher(id).matches();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Thrown when setting a curParent would create a circular inheritance
|
* Thrown when setting a curParent would create a circular inheritance
|
||||||
* situation.
|
* situation.
|
||||||
|
Loading…
Reference in New Issue
Block a user