mirror of
https://github.com/EngineHub/WorldGuard.git
synced 2024-11-27 21:15:57 +01:00
added multiworld support for regions and json region database
This commit is contained in:
parent
4505bb6f4e
commit
f61a9ab5cc
@ -14,7 +14,7 @@
|
|||||||
<include name="Bukkit.jar" />
|
<include name="Bukkit.jar" />
|
||||||
<include name="WorldEdit.jar" />
|
<include name="WorldEdit.jar" />
|
||||||
<include name="prtree.jar" />
|
<include name="prtree.jar" />
|
||||||
<include name="json-simple-1.1.jar" />
|
<include name="gson-1.7-SNAPSHOT.jar" />
|
||||||
</fileset>
|
</fileset>
|
||||||
|
|
||||||
<target name="init">
|
<target name="init">
|
||||||
@ -47,7 +47,7 @@
|
|||||||
<copy tofile="${build.dir}/defaults/blacklist.txt" file="blacklist.txt"/>
|
<copy tofile="${build.dir}/defaults/blacklist.txt" file="blacklist.txt"/>
|
||||||
<jar jarfile="${dist.dir}/WorldGuard.jar" basedir="${build.dir}" manifest="manifest.mf">
|
<jar jarfile="${dist.dir}/WorldGuard.jar" basedir="${build.dir}" manifest="manifest.mf">
|
||||||
<zipgroupfileset dir="lib" includes="prtree.jar" />
|
<zipgroupfileset dir="lib" includes="prtree.jar" />
|
||||||
<zipgroupfileset dir="lib" includes="json-simple-1.1.jar" />
|
<zipgroupfileset dir="lib" includes="gson-1.7-SNAPSHOT.jar" />
|
||||||
</jar>
|
</jar>
|
||||||
</target>
|
</target>
|
||||||
|
|
||||||
|
BIN
lib/gson-1.7-SNAPSHOT.jar
Normal file
BIN
lib/gson-1.7-SNAPSHOT.jar
Normal file
Binary file not shown.
Binary file not shown.
@ -27,7 +27,7 @@ dist.javadoc.dir=${dist.dir}/javadoc
|
|||||||
endorsed.classpath=
|
endorsed.classpath=
|
||||||
excludes=
|
excludes=
|
||||||
file.reference.Bukkit.jar=lib/Bukkit.jar
|
file.reference.Bukkit.jar=lib/Bukkit.jar
|
||||||
file.reference.json-simple-1.1.jar=lib\\json-simple-1.1.jar
|
file.reference.gson-1.7-SNAPSHOT.jar=lib\\gson-1.7-SNAPSHOT.jar
|
||||||
file.reference.prtree.jar=lib/prtree.jar
|
file.reference.prtree.jar=lib/prtree.jar
|
||||||
file.reference.truezip.jar=lib/truezip.jar
|
file.reference.truezip.jar=lib/truezip.jar
|
||||||
file.reference.WorldEdit.jar=lib/WorldEdit.jar
|
file.reference.WorldEdit.jar=lib/WorldEdit.jar
|
||||||
@ -38,7 +38,7 @@ javac.classpath=\
|
|||||||
${file.reference.prtree.jar}:\
|
${file.reference.prtree.jar}:\
|
||||||
${file.reference.truezip.jar}:\
|
${file.reference.truezip.jar}:\
|
||||||
${file.reference.WorldEdit.jar}:\
|
${file.reference.WorldEdit.jar}:\
|
||||||
${file.reference.json-simple-1.1.jar}
|
${file.reference.gson-1.7-SNAPSHOT.jar}
|
||||||
# Space-separated list of extra javac options
|
# Space-separated list of extra javac options
|
||||||
javac.compilerargs=
|
javac.compilerargs=
|
||||||
javac.deprecation=false
|
javac.deprecation=false
|
||||||
|
@ -19,6 +19,7 @@
|
|||||||
|
|
||||||
package com.sk89q.worldguard.bukkit;
|
package com.sk89q.worldguard.bukkit;
|
||||||
|
|
||||||
|
import com.sk89q.worldguard.protection.regionmanager.RegionManager;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import org.bukkit.block.Block;
|
import org.bukkit.block.Block;
|
||||||
@ -35,7 +36,7 @@
|
|||||||
import com.sk89q.worldguard.LocalPlayer;
|
import com.sk89q.worldguard.LocalPlayer;
|
||||||
import com.sk89q.worldguard.blacklist.events.*;
|
import com.sk89q.worldguard.blacklist.events.*;
|
||||||
import com.sk89q.worldguard.protection.ApplicableRegionSet;
|
import com.sk89q.worldguard.protection.ApplicableRegionSet;
|
||||||
import com.sk89q.worldguard.protection.AreaFlags;
|
import com.sk89q.worldguard.protection.regions.AreaFlags;
|
||||||
import static com.sk89q.worldguard.bukkit.BukkitUtil.*;
|
import static com.sk89q.worldguard.bukkit.BukkitUtil.*;
|
||||||
|
|
||||||
public class WorldGuardBlockListener extends BlockListener {
|
public class WorldGuardBlockListener extends BlockListener {
|
||||||
@ -70,10 +71,8 @@ public void onBlockDamage(BlockDamageEvent event) {
|
|||||||
|
|
||||||
if (plugin.useRegions && blockDamaged.getType() == Material.CAKE_BLOCK) {
|
if (plugin.useRegions && blockDamaged.getType() == Material.CAKE_BLOCK) {
|
||||||
Vector pt = toVector(blockDamaged);
|
Vector pt = toVector(blockDamaged);
|
||||||
LocalPlayer localPlayer = plugin.wrapPlayer(player);
|
|
||||||
|
|
||||||
if (!plugin.hasPermission(player, "/regionbypass")
|
if (!plugin.canBuild(player, pt)) {
|
||||||
&& !plugin.regionManager.getApplicableRegions(pt).canBuild(localPlayer)) {
|
|
||||||
player.sendMessage(ChatColor.DARK_RED + "You're not invited to this tea party!");
|
player.sendMessage(ChatColor.DARK_RED + "You're not invited to this tea party!");
|
||||||
|
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
@ -105,10 +104,8 @@ public void onBlockBreak(BlockBreakEvent event) {
|
|||||||
|
|
||||||
if (plugin.useRegions) {
|
if (plugin.useRegions) {
|
||||||
Vector pt = BukkitUtil.toVector(event.getBlock());
|
Vector pt = BukkitUtil.toVector(event.getBlock());
|
||||||
LocalPlayer localPlayer = plugin.wrapPlayer(player);
|
|
||||||
|
if (!plugin.canBuild(player, pt)) {
|
||||||
if (!plugin.hasPermission(player, "/regionbypass")
|
|
||||||
&& !plugin.regionManager.getApplicableRegions(pt).canBuild(localPlayer)) {
|
|
||||||
player.sendMessage(ChatColor.DARK_RED + "You don't have permission for this area.");
|
player.sendMessage(ChatColor.DARK_RED + "You don't have permission for this area.");
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
return;
|
return;
|
||||||
@ -274,26 +271,26 @@ public void onBlockIgnite(BlockIgniteEvent event) {
|
|||||||
LocalPlayer localPlayer = plugin.wrapPlayer(player);
|
LocalPlayer localPlayer = plugin.wrapPlayer(player);
|
||||||
|
|
||||||
if (cause == IgniteCause.FLINT_AND_STEEL
|
if (cause == IgniteCause.FLINT_AND_STEEL
|
||||||
&& !plugin.regionManager.getApplicableRegions(pt).canBuild(localPlayer)) {
|
&& !plugin.globalRegionManager.getApplicableRegions(pt).canBuild(localPlayer)) {
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (cause == IgniteCause.FLINT_AND_STEEL
|
if (cause == IgniteCause.FLINT_AND_STEEL
|
||||||
&& !plugin.regionManager.getApplicableRegions(pt)
|
&& !plugin.globalRegionManager.getApplicableRegions(pt)
|
||||||
.allowsFlag(AreaFlags.FLAG_LIGHTER)) {
|
.allowsFlag(AreaFlags.FLAG_LIGHTER)) {
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
f (isFireSpread && !plugin.regionManager.getApplicableRegions(pt)
|
f (isFireSpread && !plugin.globalRegionManager.getApplicableRegions(pt)
|
||||||
.allowsFlag(AreaFlags.FLAG_FIRE_SPREAD)) {
|
.allowsFlag(AreaFlags.FLAG_FIRE_SPREAD)) {
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (cause == IgniteCause.LAVA && !plugin.regionManager.getApplicableRegions(pt)
|
if (cause == IgniteCause.LAVA && !plugin.globalRegionManager.getApplicableRegions(pt)
|
||||||
.allowsFlag(AreaFlags.FLAG_LAVA_FIRE)) {
|
.allowsFlag(AreaFlags.FLAG_LAVA_FIRE)) {
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
return;
|
return;
|
||||||
@ -391,10 +388,11 @@ public void onBlockInteract(BlockInteractEvent event) {
|
|||||||
if (plugin.useRegions) {
|
if (plugin.useRegions) {
|
||||||
Vector pt = toVector(block);
|
Vector pt = toVector(block);
|
||||||
LocalPlayer localPlayer = plugin.wrapPlayer(player);
|
LocalPlayer localPlayer = plugin.wrapPlayer(player);
|
||||||
|
RegionManager mgr = plugin.getGlobalRegionManager().getRegionmanager(player.getWorld().getName());
|
||||||
|
|
||||||
if (!plugin.hasPermission(player, "/regionbypass")
|
if (!plugin.hasPermission(player, "/regionbypass")
|
||||||
&& !plugin.regionManager.getApplicableRegions(pt).allowsFlag(AreaFlags.FLAG_CHEST_ACCESS)
|
&& !mgr.getApplicableRegions(pt).allowsFlag(AreaFlags.FLAG_CHEST_ACCESS)
|
||||||
&& !plugin.regionManager.getApplicableRegions(pt).canBuild(localPlayer)) {
|
&& !mgr.getApplicableRegions(pt).canBuild(localPlayer)) {
|
||||||
player.sendMessage(ChatColor.DARK_RED + "You don't have permission for this area.");
|
player.sendMessage(ChatColor.DARK_RED + "You don't have permission for this area.");
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
return;
|
return;
|
||||||
@ -433,10 +431,8 @@ public void onBlockPlace(BlockPlaceEvent event) {
|
|||||||
|
|
||||||
if (plugin.useRegions) {
|
if (plugin.useRegions) {
|
||||||
Vector pt = toVector(blockPlaced);
|
Vector pt = toVector(blockPlaced);
|
||||||
LocalPlayer localPlayer = plugin.wrapPlayer(player);
|
|
||||||
|
|
||||||
if (!plugin.hasPermission(player, "/regionbypass")
|
if (!plugin.canBuild(player, pt)) {
|
||||||
&& !plugin.regionManager.getApplicableRegions(pt).canBuild(localPlayer)) {
|
|
||||||
player.sendMessage(ChatColor.DARK_RED + "You don't have permission for this area.");
|
player.sendMessage(ChatColor.DARK_RED + "You don't have permission for this area.");
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
return;
|
return;
|
||||||
@ -478,8 +474,10 @@ public void onBlockRightClick(BlockRightClickEvent event) {
|
|||||||
|
|
||||||
if (plugin.useRegions && event.getItemInHand().getTypeId() == plugin.regionWand) {
|
if (plugin.useRegions && event.getItemInHand().getTypeId() == plugin.regionWand) {
|
||||||
Vector pt = toVector(blockClicked);
|
Vector pt = toVector(blockClicked);
|
||||||
ApplicableRegionSet app = plugin.regionManager.getApplicableRegions(pt);
|
|
||||||
List<String> regions = plugin.regionManager.getApplicableRegionsIDs(pt);
|
RegionManager mgr = plugin.getGlobalRegionManager().getRegionmanager(player.getWorld().getName());
|
||||||
|
ApplicableRegionSet app = mgr.getApplicableRegions(pt);
|
||||||
|
List<String> regions = mgr.getApplicableRegionsIDs(pt);
|
||||||
|
|
||||||
if (regions.size() > 0) {
|
if (regions.size() > 0) {
|
||||||
player.sendMessage(ChatColor.YELLOW + "Can you build? "
|
player.sendMessage(ChatColor.YELLOW + "Can you build? "
|
||||||
@ -504,10 +502,8 @@ public void onBlockRightClick(BlockRightClickEvent event) {
|
|||||||
if (plugin.useRegions && type == Material.CAKE_BLOCK) {
|
if (plugin.useRegions && type == Material.CAKE_BLOCK) {
|
||||||
|
|
||||||
Vector pt = toVector(blockClicked);
|
Vector pt = toVector(blockClicked);
|
||||||
LocalPlayer localPlayer = plugin.wrapPlayer(player);
|
|
||||||
|
|
||||||
if (!plugin.hasPermission(player, "/regionbypass")
|
if (!plugin.canBuild(player, pt)) {
|
||||||
&& !plugin.regionManager.getApplicableRegions(pt).canBuild(localPlayer)) {
|
|
||||||
player.sendMessage(ChatColor.DARK_RED + "You don't have permission for this area.");
|
player.sendMessage(ChatColor.DARK_RED + "You don't have permission for this area.");
|
||||||
|
|
||||||
byte newData = (byte) (blockClicked.getData() - 1);
|
byte newData = (byte) (blockClicked.getData() - 1);
|
||||||
|
@ -19,6 +19,7 @@
|
|||||||
|
|
||||||
package com.sk89q.worldguard.bukkit;
|
package com.sk89q.worldguard.bukkit;
|
||||||
|
|
||||||
|
import com.sk89q.worldguard.protection.regionmanager.RegionManager;
|
||||||
import org.bukkit.ChatColor;
|
import org.bukkit.ChatColor;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
import org.bukkit.World;
|
import org.bukkit.World;
|
||||||
@ -32,7 +33,7 @@
|
|||||||
import org.bukkit.event.entity.EntityDamageEvent.DamageCause;
|
import org.bukkit.event.entity.EntityDamageEvent.DamageCause;
|
||||||
import com.sk89q.worldedit.Vector;
|
import com.sk89q.worldedit.Vector;
|
||||||
import com.sk89q.worldedit.blocks.BlockType;
|
import com.sk89q.worldedit.blocks.BlockType;
|
||||||
import com.sk89q.worldguard.protection.AreaFlags;
|
import com.sk89q.worldguard.protection.regions.AreaFlags;
|
||||||
import static com.sk89q.worldguard.bukkit.BukkitUtil.*;
|
import static com.sk89q.worldguard.bukkit.BukkitUtil.*;
|
||||||
|
|
||||||
public class WorldGuardEntityListener extends EntityListener {
|
public class WorldGuardEntityListener extends EntityListener {
|
||||||
@ -91,8 +92,9 @@ public void onEntityDamageByEntity(EntityDamageByEntityEvent event) {
|
|||||||
if (attacker != null && attacker instanceof Player) {
|
if (attacker != null && attacker instanceof Player) {
|
||||||
if (plugin.useRegions) {
|
if (plugin.useRegions) {
|
||||||
Vector pt = toVector(defender.getLocation());
|
Vector pt = toVector(defender.getLocation());
|
||||||
|
RegionManager mgr = plugin.getGlobalRegionManager().getRegionmanager(player.getWorld().getName());
|
||||||
if (!plugin.regionManager.getApplicableRegions(pt)
|
|
||||||
|
if (!mgr.getApplicableRegions(pt)
|
||||||
.allowsFlag(AreaFlags.FLAG_PVP)) {
|
.allowsFlag(AreaFlags.FLAG_PVP)) {
|
||||||
((Player)attacker).sendMessage(ChatColor.DARK_RED + "You are in a no-PvP area.");
|
((Player)attacker).sendMessage(ChatColor.DARK_RED + "You are in a no-PvP area.");
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
@ -109,15 +111,16 @@ public void onEntityDamageByEntity(EntityDamageByEntityEvent event) {
|
|||||||
|
|
||||||
if (plugin.useRegions) {
|
if (plugin.useRegions) {
|
||||||
Vector pt = toVector(defender.getLocation());
|
Vector pt = toVector(defender.getLocation());
|
||||||
|
RegionManager mgr = plugin.getGlobalRegionManager().getRegionmanager(player.getWorld().getName());
|
||||||
if (!plugin.regionManager.getApplicableRegions(pt)
|
|
||||||
|
if (!mgr.getApplicableRegions(pt)
|
||||||
.allowsFlag(AreaFlags.FLAG_MOB_DAMAGE)) {
|
.allowsFlag(AreaFlags.FLAG_MOB_DAMAGE)) {
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (attacker instanceof Creeper) {
|
if (attacker instanceof Creeper) {
|
||||||
if (!plugin.regionManager.getApplicableRegions(pt)
|
if (!mgr.getApplicableRegions(pt)
|
||||||
.allowsFlag(AreaFlags.FLAG_CREEPER_EXPLOSION)) {
|
.allowsFlag(AreaFlags.FLAG_CREEPER_EXPLOSION)) {
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
return;
|
return;
|
||||||
@ -144,8 +147,9 @@ public void onEntityDamageByProjectile(EntityDamageByProjectileEvent event) {
|
|||||||
if (attacker != null && attacker instanceof Player) {
|
if (attacker != null && attacker instanceof Player) {
|
||||||
if (plugin.useRegions) {
|
if (plugin.useRegions) {
|
||||||
Vector pt = toVector(defender.getLocation());
|
Vector pt = toVector(defender.getLocation());
|
||||||
|
RegionManager mgr = plugin.getGlobalRegionManager().getRegionmanager(player.getWorld().getName());
|
||||||
if (!plugin.regionManager.getApplicableRegions(pt)
|
|
||||||
|
if (!mgr.getApplicableRegions(pt)
|
||||||
.allowsFlag(AreaFlags.FLAG_PVP)) {
|
.allowsFlag(AreaFlags.FLAG_PVP)) {
|
||||||
((Player)attacker).sendMessage(ChatColor.DARK_RED + "You are in a no-PvP area.");
|
((Player)attacker).sendMessage(ChatColor.DARK_RED + "You are in a no-PvP area.");
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
@ -156,8 +160,9 @@ public void onEntityDamageByProjectile(EntityDamageByProjectileEvent event) {
|
|||||||
if (attacker != null && attacker instanceof Skeleton) {
|
if (attacker != null && attacker instanceof Skeleton) {
|
||||||
if (plugin.useRegions) {
|
if (plugin.useRegions) {
|
||||||
Vector pt = toVector(defender.getLocation());
|
Vector pt = toVector(defender.getLocation());
|
||||||
|
RegionManager mgr = plugin.getGlobalRegionManager().getRegionmanager(player.getWorld().getName());
|
||||||
if (!plugin.regionManager.getApplicableRegions(pt)
|
|
||||||
|
if (!mgr.getApplicableRegions(pt)
|
||||||
.allowsFlag(AreaFlags.FLAG_MOB_DAMAGE)) {
|
.allowsFlag(AreaFlags.FLAG_MOB_DAMAGE)) {
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
return;
|
return;
|
||||||
@ -254,8 +259,9 @@ public void onEntityExplode(EntityExplodeEvent event) {
|
|||||||
|
|
||||||
if (plugin.useRegions) {
|
if (plugin.useRegions) {
|
||||||
Vector pt = toVector(event.getEntity().getLocation());
|
Vector pt = toVector(event.getEntity().getLocation());
|
||||||
|
RegionManager mgr = plugin.getGlobalRegionManager().getRegionmanager(event.getEntity().getWorld().getName());
|
||||||
|
|
||||||
if (!plugin.regionManager.getApplicableRegions(pt)
|
if (!mgr.getApplicableRegions(pt)
|
||||||
.allowsFlag(AreaFlags.FLAG_CREEPER_EXPLOSION)) {
|
.allowsFlag(AreaFlags.FLAG_CREEPER_EXPLOSION)) {
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
return;
|
return;
|
||||||
@ -269,8 +275,9 @@ public void onEntityExplode(EntityExplodeEvent event) {
|
|||||||
|
|
||||||
if (plugin.useRegions && event.getEntity() != null) {
|
if (plugin.useRegions && event.getEntity() != null) {
|
||||||
Vector pt = toVector(event.getEntity().getLocation());
|
Vector pt = toVector(event.getEntity().getLocation());
|
||||||
|
RegionManager mgr = plugin.getGlobalRegionManager().getRegionmanager(event.getEntity().getWorld().getName());
|
||||||
if (!plugin.regionManager.getApplicableRegions(pt)
|
|
||||||
|
if (!mgr.getApplicableRegions(pt)
|
||||||
.allowsFlag(AreaFlags.FLAG_TNT)) {
|
.allowsFlag(AreaFlags.FLAG_TNT)) {
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
return;
|
return;
|
||||||
|
@ -19,6 +19,7 @@
|
|||||||
|
|
||||||
package com.sk89q.worldguard.bukkit;
|
package com.sk89q.worldguard.bukkit;
|
||||||
|
|
||||||
|
import com.sk89q.worldguard.protection.regionmanager.RegionManager;
|
||||||
import com.sk89q.worldguard.blacklist.events.ItemAcquireBlacklistEvent;
|
import com.sk89q.worldguard.blacklist.events.ItemAcquireBlacklistEvent;
|
||||||
import org.bukkit.entity.Item;
|
import org.bukkit.entity.Item;
|
||||||
import com.sk89q.worldguard.blacklist.events.ItemDropBlacklistEvent;
|
import com.sk89q.worldguard.blacklist.events.ItemDropBlacklistEvent;
|
||||||
@ -30,7 +31,7 @@
|
|||||||
import com.sk89q.worldedit.Vector;
|
import com.sk89q.worldedit.Vector;
|
||||||
import com.sk89q.worldguard.*;
|
import com.sk89q.worldguard.*;
|
||||||
import com.sk89q.worldguard.blacklist.events.ItemUseBlacklistEvent;
|
import com.sk89q.worldguard.blacklist.events.ItemUseBlacklistEvent;
|
||||||
import com.sk89q.worldguard.protection.AreaFlags;
|
import com.sk89q.worldguard.protection.regions.AreaFlags;
|
||||||
import static com.sk89q.worldguard.bukkit.BukkitUtil.*;
|
import static com.sk89q.worldguard.bukkit.BukkitUtil.*;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -116,10 +117,8 @@ public void onPlayerItem(PlayerItemEvent event) {
|
|||||||
|
|
||||||
if (plugin.useRegions && !event.isBlock() && block != null) {
|
if (plugin.useRegions && !event.isBlock() && block != null) {
|
||||||
Vector pt = toVector(block.getRelative(event.getBlockFace()));
|
Vector pt = toVector(block.getRelative(event.getBlockFace()));
|
||||||
LocalPlayer localPlayer = plugin.wrapPlayer(player);
|
|
||||||
|
if (!plugin.canBuild(player, pt)) {
|
||||||
if (!plugin.hasPermission(player, "/regionbypass")
|
|
||||||
&& !plugin.regionManager.getApplicableRegions(pt).canBuild(localPlayer)) {
|
|
||||||
player.sendMessage(ChatColor.DARK_RED
|
player.sendMessage(ChatColor.DARK_RED
|
||||||
+ "You don't have permission for this area.");
|
+ "You don't have permission for this area.");
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
@ -139,8 +138,9 @@ public void onPlayerItem(PlayerItemEvent event) {
|
|||||||
|
|
||||||
if (plugin.useRegions && item != null && block != null && item.getTypeId() == 259) {
|
if (plugin.useRegions && item != null && block != null && item.getTypeId() == 259) {
|
||||||
Vector pt = toVector(block.getRelative(event.getBlockFace()));
|
Vector pt = toVector(block.getRelative(event.getBlockFace()));
|
||||||
|
RegionManager mgr = plugin.getGlobalRegionManager().getRegionmanager(player.getWorld().getName());
|
||||||
if (!plugin.regionManager.getApplicableRegions(pt)
|
|
||||||
|
if (!mgr.getApplicableRegions(pt)
|
||||||
.allowsFlag(AreaFlags.FLAG_LIGHTER)) {
|
.allowsFlag(AreaFlags.FLAG_LIGHTER)) {
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
return;
|
return;
|
||||||
|
@ -19,8 +19,11 @@
|
|||||||
|
|
||||||
package com.sk89q.worldguard.bukkit;
|
package com.sk89q.worldguard.bukkit;
|
||||||
|
|
||||||
|
|
||||||
|
import com.sk89q.worldguard.protection.dbs.CSVDatabase;
|
||||||
|
import com.sk89q.worldguard.protection.regions.ProtectedCuboidRegion;
|
||||||
|
import com.sk89q.worldguard.protection.regionmanager.RegionManager;
|
||||||
import static com.sk89q.worldguard.bukkit.BukkitUtil.matchSinglePlayer;
|
import static com.sk89q.worldguard.bukkit.BukkitUtil.matchSinglePlayer;
|
||||||
import static com.sk89q.worldguard.bukkit.BukkitUtil.toVector;
|
|
||||||
import java.io.*;
|
import java.io.*;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.logging.*;
|
import java.util.logging.*;
|
||||||
@ -31,14 +34,12 @@
|
|||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.ChatColor;
|
import org.bukkit.ChatColor;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
import org.bukkit.Server;
|
|
||||||
import org.bukkit.event.Event.Priority;
|
import org.bukkit.event.Event.Priority;
|
||||||
import org.bukkit.event.Event;
|
import org.bukkit.event.Event;
|
||||||
import org.bukkit.event.Listener;
|
import org.bukkit.event.Listener;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
import org.bukkit.plugin.Plugin;
|
import org.bukkit.plugin.Plugin;
|
||||||
import org.bukkit.plugin.PluginDescriptionFile;
|
import org.bukkit.plugin.PluginDescriptionFile;
|
||||||
import org.bukkit.plugin.PluginLoader;
|
|
||||||
import org.bukkit.plugin.java.JavaPlugin;
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
import org.bukkit.util.config.Configuration;
|
import org.bukkit.util.config.Configuration;
|
||||||
import com.sk89q.bukkit.migration.PermissionsResolverManager;
|
import com.sk89q.bukkit.migration.PermissionsResolverManager;
|
||||||
@ -49,7 +50,6 @@
|
|||||||
import com.sk89q.worldedit.Vector;
|
import com.sk89q.worldedit.Vector;
|
||||||
import com.sk89q.worldedit.blocks.ItemType;
|
import com.sk89q.worldedit.blocks.ItemType;
|
||||||
import com.sk89q.worldedit.bukkit.BukkitWorld;
|
import com.sk89q.worldedit.bukkit.BukkitWorld;
|
||||||
import com.sk89q.worldedit.bukkit.WorldEditAPI;
|
|
||||||
import com.sk89q.worldedit.bukkit.WorldEditPlugin;
|
import com.sk89q.worldedit.bukkit.WorldEditPlugin;
|
||||||
import com.sk89q.worldedit.regions.Region;
|
import com.sk89q.worldedit.regions.Region;
|
||||||
import com.sk89q.worldguard.LocalPlayer;
|
import com.sk89q.worldguard.LocalPlayer;
|
||||||
@ -58,8 +58,12 @@
|
|||||||
import com.sk89q.worldguard.blacklist.loggers.*;
|
import com.sk89q.worldguard.blacklist.loggers.*;
|
||||||
import com.sk89q.worldguard.domains.DefaultDomain;
|
import com.sk89q.worldguard.domains.DefaultDomain;
|
||||||
import com.sk89q.worldguard.protection.*;
|
import com.sk89q.worldguard.protection.*;
|
||||||
import com.sk89q.worldguard.protection.AreaFlags.State;
|
import com.sk89q.worldguard.protection.regionmanager.GlobalRegionManager;
|
||||||
import com.sk89q.worldguard.protection.ProtectedRegion.CircularInheritanceException;
|
import com.sk89q.worldguard.protection.regions.AreaFlags;
|
||||||
|
import com.sk89q.worldguard.protection.regions.AreaFlags.State;
|
||||||
|
import com.sk89q.worldguard.protection.regions.ProtectedRegion;
|
||||||
|
import com.sk89q.worldguard.protection.regions.ProtectedRegion.CircularInheritanceException;
|
||||||
|
import org.bukkit.World;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Plugin for Bukkit.
|
* Plugin for Bukkit.
|
||||||
@ -81,12 +85,10 @@ public class WorldGuardPlugin extends JavaPlugin {
|
|||||||
|
|
||||||
private PermissionsResolverServerListener permsListener;
|
private PermissionsResolverServerListener permsListener;
|
||||||
private PermissionsResolverManager perms;
|
private PermissionsResolverManager perms;
|
||||||
|
|
||||||
Blacklist blacklist;
|
Blacklist blacklist;
|
||||||
|
|
||||||
GlobalFlags globalFlags = new GlobalFlags();
|
GlobalRegionManager globalRegionManager;
|
||||||
RegionManager regionManager = new FlatRegionManager(globalFlags);
|
|
||||||
ProtectionDatabase regionLoader;
|
|
||||||
|
|
||||||
Set<String> invinciblePlayers = new HashSet<String>();
|
Set<String> invinciblePlayers = new HashSet<String>();
|
||||||
Set<String> amphibiousPlayers = new HashSet<String>();
|
Set<String> amphibiousPlayers = new HashSet<String>();
|
||||||
@ -158,7 +160,8 @@ public void onEnable() {
|
|||||||
createDefaultConfiguration("config.yml");
|
createDefaultConfiguration("config.yml");
|
||||||
createDefaultConfiguration("blacklist.txt");
|
createDefaultConfiguration("blacklist.txt");
|
||||||
|
|
||||||
regionLoader = new CSVDatabase(new File(folder, "regions.txt"));
|
globalRegionManager = new GlobalRegionManager(this);
|
||||||
|
|
||||||
perms = new PermissionsResolverManager(getConfiguration(), getServer(),
|
perms = new PermissionsResolverManager(getConfiguration(), getServer(),
|
||||||
"WorldGuard", logger);
|
"WorldGuard", logger);
|
||||||
permsListener = new PermissionsResolverServerListener(perms);
|
permsListener = new PermissionsResolverServerListener(perms);
|
||||||
@ -316,6 +319,8 @@ public void loadConfiguration() {
|
|||||||
|
|
||||||
useRegions = config.getBoolean("regions.enable", true);
|
useRegions = config.getBoolean("regions.enable", true);
|
||||||
regionWand = config.getInt("regions.wand", 287);
|
regionWand = config.getInt("regions.wand", 287);
|
||||||
|
|
||||||
|
GlobalFlags globalFlags = new GlobalFlags();
|
||||||
globalFlags.canBuild = config.getBoolean("regions.default.build", true);
|
globalFlags.canBuild = config.getBoolean("regions.default.build", true);
|
||||||
globalFlags.canAccessChests = config.getBoolean("regions.default.chest-access", false);
|
globalFlags.canAccessChests = config.getBoolean("regions.default.chest-access", false);
|
||||||
globalFlags.canPvP = config.getBoolean("regions.default.pvp", true);
|
globalFlags.canPvP = config.getBoolean("regions.default.pvp", true);
|
||||||
@ -323,16 +328,35 @@ public void loadConfiguration() {
|
|||||||
globalFlags.canTnt = config.getBoolean("regions.default.tnt", true);
|
globalFlags.canTnt = config.getBoolean("regions.default.tnt", true);
|
||||||
globalFlags.allowCreeper = config.getBoolean("regions.default.creeper", true);
|
globalFlags.allowCreeper = config.getBoolean("regions.default.creeper", true);
|
||||||
globalFlags.allowMobDamage = config.getBoolean("regions.default.mobdamage", true);
|
globalFlags.allowMobDamage = config.getBoolean("regions.default.mobdamage", true);
|
||||||
|
globalRegionManager.setGlobalFlags(globalFlags);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
regionLoader.load();
|
File CSVfile = new File(this.getDataFolder(), "regions.txt");
|
||||||
regionManager.setRegions(regionLoader.getRegions());
|
if (CSVfile.exists()) {
|
||||||
|
|
||||||
|
logger.info("WorldGuard: Converting old regions.txt to new format....");
|
||||||
|
|
||||||
|
World w = this.getServer().getWorlds().get(0);
|
||||||
|
RegionManager mgr = globalRegionManager.getRegionmanager(w.getName());
|
||||||
|
|
||||||
|
CSVDatabase db = new CSVDatabase(CSVfile);
|
||||||
|
db.load();
|
||||||
|
|
||||||
|
for (Map.Entry<String, ProtectedRegion> entry : db.getRegions().entrySet()) {
|
||||||
|
mgr.addRegion(entry.getValue());
|
||||||
|
}
|
||||||
|
|
||||||
|
mgr.save();
|
||||||
|
CSVfile.renameTo(new File(this.getDataFolder(), "region.txt.old"));
|
||||||
|
|
||||||
|
logger.info("WorldGuard: Done.");
|
||||||
|
}
|
||||||
} catch (FileNotFoundException e) {
|
} catch (FileNotFoundException e) {
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
logger.warning("WorldGuard: Failed to load regions: "
|
logger.warning("WorldGuard: Failed to load regions: "
|
||||||
+ e.getMessage());
|
+ e.getMessage());
|
||||||
}
|
}
|
||||||
|
|
||||||
// Console log configuration
|
// Console log configuration
|
||||||
boolean logConsole = config.getBoolean("blacklist.logging.console.enable", true);
|
boolean logConsole = config.getBoolean("blacklist.logging.console.enable", true);
|
||||||
|
|
||||||
@ -780,9 +804,10 @@ private boolean handleRegionCommand(Player player, String action, String[] args)
|
|||||||
String id = args[0].toLowerCase();
|
String id = args[0].toLowerCase();
|
||||||
|
|
||||||
WorldEditPlugin worldEdit = (WorldEditPlugin)wePlugin;
|
WorldEditPlugin worldEdit = (WorldEditPlugin)wePlugin;
|
||||||
|
World w = player.getWorld();
|
||||||
|
|
||||||
LocalSession session = worldEdit.getSession(player);
|
LocalSession session = worldEdit.getSession(player);
|
||||||
Region weRegion = session.getSelection(new BukkitWorld(player.getWorld()));
|
Region weRegion = session.getSelection(new BukkitWorld(w));
|
||||||
|
|
||||||
BlockVector min = weRegion.getMinimumPoint().toBlockVector();
|
BlockVector min = weRegion.getMinimumPoint().toBlockVector();
|
||||||
BlockVector max = weRegion.getMaximumPoint().toBlockVector();
|
BlockVector max = weRegion.getMaximumPoint().toBlockVector();
|
||||||
@ -791,8 +816,9 @@ private boolean handleRegionCommand(Player player, String action, String[] args)
|
|||||||
if (args.length >= 2) {
|
if (args.length >= 2) {
|
||||||
region.setOwners(parseDomainString(args, 1));
|
region.setOwners(parseDomainString(args, 1));
|
||||||
}
|
}
|
||||||
regionManager.addRegion(region);
|
RegionManager mgr = globalRegionManager.getRegionmanager(w.getName());
|
||||||
regionLoader.save(regionManager);
|
mgr.addRegion(region);
|
||||||
|
mgr.save();
|
||||||
player.sendMessage(ChatColor.YELLOW + "Region saved as " + id + ".");
|
player.sendMessage(ChatColor.YELLOW + "Region saved as " + id + ".");
|
||||||
} catch (IncompleteRegionException e) {
|
} catch (IncompleteRegionException e) {
|
||||||
player.sendMessage(ChatColor.RED + "You must first define an area in WorldEdit.");
|
player.sendMessage(ChatColor.RED + "You must first define an area in WorldEdit.");
|
||||||
@ -810,8 +836,9 @@ private boolean handleRegionCommand(Player player, String action, String[] args)
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
String id = args[0].toLowerCase();
|
String id = args[0].toLowerCase();
|
||||||
|
RegionManager mgr = globalRegionManager.getRegionmanager(player.getWorld().getName());
|
||||||
|
|
||||||
ProtectedRegion existing = regionManager.getRegion(id);
|
ProtectedRegion existing = mgr.getRegion(id);
|
||||||
|
|
||||||
if (existing != null) {
|
if (existing != null) {
|
||||||
if (!existing.getOwners().contains(wrapPlayer(player))) {
|
if (!existing.getOwners().contains(wrapPlayer(player))) {
|
||||||
@ -830,15 +857,15 @@ private boolean handleRegionCommand(Player player, String action, String[] args)
|
|||||||
|
|
||||||
ProtectedRegion region = new ProtectedCuboidRegion(id, min, max);
|
ProtectedRegion region = new ProtectedCuboidRegion(id, min, max);
|
||||||
|
|
||||||
if (regionManager.overlapsUnownedRegion(region, wrapPlayer(player))) {
|
if (mgr.overlapsUnownedRegion(region, wrapPlayer(player))) {
|
||||||
player.sendMessage(ChatColor.RED + "This region overlaps with someone else's region.");
|
player.sendMessage(ChatColor.RED + "This region overlaps with someone else's region.");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
region.getOwners().addPlayer(player.getName());
|
region.getOwners().addPlayer(player.getName());
|
||||||
|
|
||||||
regionManager.addRegion(region);
|
mgr.addRegion(region);
|
||||||
regionLoader.save(regionManager);
|
mgr.save();
|
||||||
player.sendMessage(ChatColor.YELLOW + "Region saved as " + id + ".");
|
player.sendMessage(ChatColor.YELLOW + "Region saved as " + id + ".");
|
||||||
} catch (IncompleteRegionException e) {
|
} catch (IncompleteRegionException e) {
|
||||||
player.sendMessage(ChatColor.RED + "You must first define an area in WorldEdit.");
|
player.sendMessage(ChatColor.RED + "You must first define an area in WorldEdit.");
|
||||||
@ -858,7 +885,8 @@ private boolean handleRegionCommand(Player player, String action, String[] args)
|
|||||||
String id = args[0].toLowerCase();
|
String id = args[0].toLowerCase();
|
||||||
String flagStr = args[1];
|
String flagStr = args[1];
|
||||||
String stateStr = args[2];
|
String stateStr = args[2];
|
||||||
ProtectedRegion region = regionManager.getRegion(id);
|
RegionManager mgr = globalRegionManager.getRegionmanager(player.getWorld().getName());
|
||||||
|
ProtectedRegion region = mgr.getRegion(id);
|
||||||
|
|
||||||
if (region == null) {
|
if (region == null) {
|
||||||
player.sendMessage(ChatColor.RED + "Could not find a region by that ID.");
|
player.sendMessage(ChatColor.RED + "Could not find a region by that ID.");
|
||||||
@ -893,7 +921,7 @@ private boolean handleRegionCommand(Player player, String action, String[] args)
|
|||||||
|
|
||||||
AreaFlags flags = region.getFlags();
|
AreaFlags flags = region.getFlags();
|
||||||
flags.set(flagStr, state);
|
flags.set(flagStr, state);
|
||||||
regionLoader.save(regionManager);
|
mgr.save();
|
||||||
player.sendMessage(ChatColor.YELLOW + "Region '" + id + "' updated.");
|
player.sendMessage(ChatColor.YELLOW + "Region '" + id + "' updated.");
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
player.sendMessage(ChatColor.RED + "Region database failed to save: "
|
player.sendMessage(ChatColor.RED + "Region database failed to save: "
|
||||||
@ -911,8 +939,9 @@ private boolean handleRegionCommand(Player player, String action, String[] args)
|
|||||||
|
|
||||||
String id = args[0].toLowerCase();
|
String id = args[0].toLowerCase();
|
||||||
String parentId = args.length > 1 ? args[1].toLowerCase() : null;
|
String parentId = args.length > 1 ? args[1].toLowerCase() : null;
|
||||||
|
RegionManager mgr = globalRegionManager.getRegionmanager(player.getWorld().getName());
|
||||||
ProtectedRegion region = regionManager.getRegion(id);
|
|
||||||
|
ProtectedRegion region = mgr.getRegion(id);
|
||||||
|
|
||||||
if (region == null) {
|
if (region == null) {
|
||||||
player.sendMessage(ChatColor.RED + "Could not find a region with ID: " + id);
|
player.sendMessage(ChatColor.RED + "Could not find a region with ID: " + id);
|
||||||
@ -929,7 +958,7 @@ private boolean handleRegionCommand(Player player, String action, String[] args)
|
|||||||
|
|
||||||
// Set a parent
|
// Set a parent
|
||||||
if (parentId != null) {
|
if (parentId != null) {
|
||||||
parent = regionManager.getRegion(parentId);
|
parent = mgr.getRegion(parentId);
|
||||||
|
|
||||||
if (parent == null) {
|
if (parent == null) {
|
||||||
player.sendMessage(ChatColor.RED + "Could not find a region with ID: " + parentId);
|
player.sendMessage(ChatColor.RED + "Could not find a region with ID: " + parentId);
|
||||||
@ -946,7 +975,7 @@ private boolean handleRegionCommand(Player player, String action, String[] args)
|
|||||||
try {
|
try {
|
||||||
region.setParent(parent);
|
region.setParent(parent);
|
||||||
|
|
||||||
regionLoader.save(regionManager);
|
mgr.save();
|
||||||
player.sendMessage(ChatColor.YELLOW + "Region '" + id + "' updated.");
|
player.sendMessage(ChatColor.YELLOW + "Region '" + id + "' updated.");
|
||||||
} catch (CircularInheritanceException e) {
|
} catch (CircularInheritanceException e) {
|
||||||
player.sendMessage(ChatColor.RED + "Circular inheritance detected. The operation failed.");
|
player.sendMessage(ChatColor.RED + "Circular inheritance detected. The operation failed.");
|
||||||
@ -961,15 +990,16 @@ private boolean handleRegionCommand(Player player, String action, String[] args)
|
|||||||
if (action.equalsIgnoreCase("info")) {
|
if (action.equalsIgnoreCase("info")) {
|
||||||
checkRegionPermission(player, "/regioninfo");
|
checkRegionPermission(player, "/regioninfo");
|
||||||
checkArgs(args, 1, 1, "/region info <id>");
|
checkArgs(args, 1, 1, "/region info <id>");
|
||||||
|
|
||||||
|
RegionManager mgr = globalRegionManager.getRegionmanager(player.getWorld().getName());
|
||||||
String id = args[0].toLowerCase();
|
String id = args[0].toLowerCase();
|
||||||
if (!regionManager.hasRegion(id)) {
|
if (!mgr.hasRegion(id)) {
|
||||||
player.sendMessage(ChatColor.RED + "A region with ID '"
|
player.sendMessage(ChatColor.RED + "A region with ID '"
|
||||||
+ id + "' doesn't exist.");
|
+ id + "' doesn't exist.");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
ProtectedRegion region = regionManager.getRegion(id);
|
ProtectedRegion region = mgr.getRegion(id);
|
||||||
AreaFlags flags = region.getFlags();
|
AreaFlags flags = region.getFlags();
|
||||||
DefaultDomain owners = region.getOwners();
|
DefaultDomain owners = region.getOwners();
|
||||||
DefaultDomain members = region.getMembers();
|
DefaultDomain members = region.getMembers();
|
||||||
@ -1010,15 +1040,16 @@ private boolean handleRegionCommand(Player player, String action, String[] args)
|
|||||||
checkArgs(args, 2, -1, "/region add[member|owner] <id> [player1 [group1 [players/groups...]]]");
|
checkArgs(args, 2, -1, "/region add[member|owner] <id> [player1 [group1 [players/groups...]]]");
|
||||||
|
|
||||||
boolean isOwner = action.equalsIgnoreCase("addowner");
|
boolean isOwner = action.equalsIgnoreCase("addowner");
|
||||||
|
RegionManager mgr = globalRegionManager.getRegionmanager(player.getWorld().getName());
|
||||||
|
|
||||||
String id = args[0].toLowerCase();
|
String id = args[0].toLowerCase();
|
||||||
if (!regionManager.hasRegion(id)) {
|
if (!mgr.hasRegion(id)) {
|
||||||
player.sendMessage(ChatColor.RED + "A region with ID '"
|
player.sendMessage(ChatColor.RED + "A region with ID '"
|
||||||
+ id + "' doesn't exist.");
|
+ id + "' doesn't exist.");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
ProtectedRegion existing = regionManager.getRegion(id);
|
ProtectedRegion existing = mgr.getRegion(id);
|
||||||
|
|
||||||
if (!canUseRegionCommand(player, "/regiondefine")
|
if (!canUseRegionCommand(player, "/regiondefine")
|
||||||
&& !existing.isOwner(wrapPlayer(player))) {
|
&& !existing.isOwner(wrapPlayer(player))) {
|
||||||
@ -1033,7 +1064,7 @@ private boolean handleRegionCommand(Player player, String action, String[] args)
|
|||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
regionLoader.save(regionManager);
|
mgr.save();
|
||||||
player.sendMessage(ChatColor.YELLOW + "Region updated!");
|
player.sendMessage(ChatColor.YELLOW + "Region updated!");
|
||||||
player.sendMessage(ChatColor.GRAY + "Current owners: "
|
player.sendMessage(ChatColor.GRAY + "Current owners: "
|
||||||
+ existing.getOwners().toUserFriendlyString());
|
+ existing.getOwners().toUserFriendlyString());
|
||||||
@ -1054,15 +1085,16 @@ private boolean handleRegionCommand(Player player, String action, String[] args)
|
|||||||
checkArgs(args, 2, -1, "/region removeowner <id> [owner1 [owner2 [owners...]]]");
|
checkArgs(args, 2, -1, "/region removeowner <id> [owner1 [owner2 [owners...]]]");
|
||||||
|
|
||||||
boolean isOwner = action.equalsIgnoreCase("removeowner");
|
boolean isOwner = action.equalsIgnoreCase("removeowner");
|
||||||
|
RegionManager mgr = globalRegionManager.getRegionmanager(player.getWorld().getName());
|
||||||
|
|
||||||
String id = args[0].toLowerCase();
|
String id = args[0].toLowerCase();
|
||||||
if (!regionManager.hasRegion(id)) {
|
if (!mgr.hasRegion(id)) {
|
||||||
player.sendMessage(ChatColor.RED + "A region with ID '"
|
player.sendMessage(ChatColor.RED + "A region with ID '"
|
||||||
+ id + "' doesn't exist.");
|
+ id + "' doesn't exist.");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
ProtectedRegion existing = regionManager.getRegion(id);
|
ProtectedRegion existing = mgr.getRegion(id);
|
||||||
|
|
||||||
if (!canUseRegionCommand(player, "/regiondefine")
|
if (!canUseRegionCommand(player, "/regiondefine")
|
||||||
&& !existing.isOwner(wrapPlayer(player))) {
|
&& !existing.isOwner(wrapPlayer(player))) {
|
||||||
@ -1077,7 +1109,7 @@ private boolean handleRegionCommand(Player player, String action, String[] args)
|
|||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
regionLoader.save(regionManager);
|
mgr.save();
|
||||||
player.sendMessage(ChatColor.YELLOW + "Region updated!");
|
player.sendMessage(ChatColor.YELLOW + "Region updated!");
|
||||||
player.sendMessage(ChatColor.GRAY + "Current owners: "
|
player.sendMessage(ChatColor.GRAY + "Current owners: "
|
||||||
+ existing.getOwners().toUserFriendlyString());
|
+ existing.getOwners().toUserFriendlyString());
|
||||||
@ -1104,8 +1136,9 @@ private boolean handleRegionCommand(Player player, String action, String[] args)
|
|||||||
page = 0;
|
page = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Map<String,ProtectedRegion> regions = regionManager.getRegions();
|
RegionManager mgr = globalRegionManager.getRegionmanager(player.getWorld().getName());
|
||||||
|
Map<String,ProtectedRegion> regions = mgr.getRegions();
|
||||||
int size = regions.size();
|
int size = regions.size();
|
||||||
int pages = (int)Math.ceil(size / (float)CMD_LIST_SIZE);
|
int pages = (int)Math.ceil(size / (float)CMD_LIST_SIZE);
|
||||||
|
|
||||||
@ -1139,13 +1172,15 @@ private boolean handleRegionCommand(Player player, String action, String[] args)
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
String id = args[0].toLowerCase();
|
String id = args[0].toLowerCase();
|
||||||
if (!regionManager.hasRegion(id)) {
|
RegionManager mgr = globalRegionManager.getRegionmanager(player.getWorld().getName());
|
||||||
|
|
||||||
|
if (!mgr.hasRegion(id)) {
|
||||||
player.sendMessage(ChatColor.RED + "A region with ID '"
|
player.sendMessage(ChatColor.RED + "A region with ID '"
|
||||||
+ id + "' doesn't exist.");
|
+ id + "' doesn't exist.");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
ProtectedRegion existing = regionManager.getRegion(id);
|
ProtectedRegion existing = mgr.getRegion(id);
|
||||||
|
|
||||||
if (!canUseRegionCommand(player, "/regiondelete")
|
if (!canUseRegionCommand(player, "/regiondelete")
|
||||||
&& !existing.isOwner(wrapPlayer(player))) {
|
&& !existing.isOwner(wrapPlayer(player))) {
|
||||||
@ -1153,8 +1188,8 @@ private boolean handleRegionCommand(Player player, String action, String[] args)
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
regionManager.removeRegion(id);
|
mgr.removeRegion(id);
|
||||||
regionLoader.save(regionManager);
|
mgr.save();
|
||||||
player.sendMessage(ChatColor.YELLOW + "Region removed!");
|
player.sendMessage(ChatColor.YELLOW + "Region removed!");
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
player.sendMessage(ChatColor.RED + "Region database failed to save: "
|
player.sendMessage(ChatColor.RED + "Region database failed to save: "
|
||||||
@ -1169,7 +1204,8 @@ private boolean handleRegionCommand(Player player, String action, String[] args)
|
|||||||
checkArgs(args, 0, 0, "/region save");
|
checkArgs(args, 0, 0, "/region save");
|
||||||
|
|
||||||
try {
|
try {
|
||||||
regionLoader.save(regionManager);
|
RegionManager mgr = globalRegionManager.getRegionmanager(player.getWorld().getName());
|
||||||
|
mgr.save();
|
||||||
player.sendMessage(ChatColor.YELLOW + "Region database saved to file!");
|
player.sendMessage(ChatColor.YELLOW + "Region database saved to file!");
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
player.sendMessage(ChatColor.RED + "Region database failed to save: "
|
player.sendMessage(ChatColor.RED + "Region database failed to save: "
|
||||||
@ -1184,7 +1220,8 @@ private boolean handleRegionCommand(Player player, String action, String[] args)
|
|||||||
checkArgs(args, 0, 0, "/region load");
|
checkArgs(args, 0, 0, "/region load");
|
||||||
|
|
||||||
try {
|
try {
|
||||||
regionLoader.load(regionManager);
|
RegionManager mgr = globalRegionManager.getRegionmanager(player.getWorld().getName());
|
||||||
|
mgr.load();
|
||||||
player.sendMessage(ChatColor.YELLOW + "Region database loaded from file!");
|
player.sendMessage(ChatColor.YELLOW + "Region database loaded from file!");
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
player.sendMessage(ChatColor.RED + "Region database failed to load: "
|
player.sendMessage(ChatColor.RED + "Region database failed to load: "
|
||||||
@ -1341,35 +1378,49 @@ private void checkArgs(String[] args, int min, int max, String help)
|
|||||||
*
|
*
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public RegionManager getRegionManager() {
|
public GlobalRegionManager getGlobalRegionManager() {
|
||||||
return regionManager;
|
return globalRegionManager;
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the region loader.
|
|
||||||
*
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
public ProtectionDatabase getRegionLoader() {
|
|
||||||
return regionLoader;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean canBuild(Player player, int x, int y, int z) {
|
public boolean canBuild(Player player, int x, int y, int z) {
|
||||||
|
|
||||||
if (useRegions) {
|
if (useRegions) {
|
||||||
Vector pt = new Vector(x, y, z);
|
Vector pt = new Vector(x, y, z);
|
||||||
LocalPlayer localPlayer = wrapPlayer(player);
|
LocalPlayer localPlayer = wrapPlayer(player);
|
||||||
|
|
||||||
if (!hasPermission(player, "/regionbypass")
|
if (!hasPermission(player, "/regionbypass")) {
|
||||||
&& !regionManager.getApplicableRegions(pt).canBuild(localPlayer)) {
|
RegionManager mgr = globalRegionManager.getRegionmanager(player.getWorld().getName());
|
||||||
return false;
|
|
||||||
|
if (!mgr.getApplicableRegions(pt).canBuild(localPlayer)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean canBuild(Player player, Vector pt) {
|
||||||
|
|
||||||
|
if (useRegions) {
|
||||||
|
LocalPlayer localPlayer = wrapPlayer(player);
|
||||||
|
|
||||||
|
if (!hasPermission(player, "/regionbypass")) {
|
||||||
|
RegionManager mgr = globalRegionManager.getRegionmanager(player.getWorld().getName());
|
||||||
|
|
||||||
|
if (!mgr.getApplicableRegions(pt).canBuild(localPlayer)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
} else {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
boolean inGroup(Player player, String group) {
|
boolean inGroup(Player player, String group) {
|
||||||
try {
|
try {
|
||||||
return perms.inGroup(player.getName(), group);
|
return perms.inGroup(player.getName(), group);
|
||||||
|
@ -19,13 +19,15 @@
|
|||||||
|
|
||||||
package com.sk89q.worldguard.protection;
|
package com.sk89q.worldguard.protection;
|
||||||
|
|
||||||
|
import com.sk89q.worldguard.protection.regions.ProtectedRegion;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import com.sk89q.worldedit.Vector;
|
import com.sk89q.worldedit.Vector;
|
||||||
import com.sk89q.worldguard.LocalPlayer;
|
import com.sk89q.worldguard.LocalPlayer;
|
||||||
import com.sk89q.worldguard.protection.AreaFlags.State;
|
import com.sk89q.worldguard.protection.regions.AreaFlags;
|
||||||
|
import com.sk89q.worldguard.protection.regions.AreaFlags.State;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents a set of regions and their rules as applied to one point.
|
* Represents a set of regions and their rules as applied to one point.
|
||||||
|
@ -19,6 +19,7 @@
|
|||||||
|
|
||||||
package com.sk89q.worldguard.protection;
|
package com.sk89q.worldguard.protection;
|
||||||
|
|
||||||
|
import com.sk89q.worldguard.protection.regions.ProtectedRegion;
|
||||||
import java.util.Comparator;
|
import java.util.Comparator;
|
||||||
|
|
||||||
class DescendingPriorityComparator implements Comparator<ProtectedRegion> {
|
class DescendingPriorityComparator implements Comparator<ProtectedRegion> {
|
||||||
|
@ -1,112 +0,0 @@
|
|||||||
// $Id$
|
|
||||||
/*
|
|
||||||
* WorldGuard
|
|
||||||
* Copyright (C) 2010 sk89q <http://www.sk89q.com>
|
|
||||||
*
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package com.sk89q.worldguard.protection;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
import com.sk89q.worldedit.Vector;
|
|
||||||
import com.sk89q.worldguard.LocalPlayer;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* An interface for getting, setting, and looking up regions. The most
|
|
||||||
* simple implementation uses a flat list and iterates through the entire
|
|
||||||
* list to look for applicable regions, but a more complicated (and more
|
|
||||||
* efficient) implementation may use space partitioning techniques.
|
|
||||||
*
|
|
||||||
* @author sk89q
|
|
||||||
*/
|
|
||||||
public interface RegionManager {
|
|
||||||
/**
|
|
||||||
* Get a list of protected regions.
|
|
||||||
*
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
public Map<String, ProtectedRegion> getRegions();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Set a list of protected regions.
|
|
||||||
*
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
public void setRegions(Map<String,ProtectedRegion> regions);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Adds a region.
|
|
||||||
*
|
|
||||||
* @param id
|
|
||||||
* @param region
|
|
||||||
*/
|
|
||||||
public void addRegion(ProtectedRegion region);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Return whether a region exists by an ID.
|
|
||||||
*
|
|
||||||
* @param id
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
public boolean hasRegion(String id);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get a region by its ID.
|
|
||||||
*
|
|
||||||
* @param id
|
|
||||||
*/
|
|
||||||
public ProtectedRegion getRegion(String id);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Removes a region, including inheriting children.
|
|
||||||
*
|
|
||||||
* @param id
|
|
||||||
*/
|
|
||||||
public void removeRegion(String id);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get an object for a point for rules to be applied with.
|
|
||||||
*
|
|
||||||
* @param pt
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
public ApplicableRegionSet getApplicableRegions(Vector pt);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get a list of region IDs that contain a point.
|
|
||||||
*
|
|
||||||
* @param pt
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
public List<String> getApplicableRegionsIDs(Vector pt);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns true if the provided region overlaps with any other region that
|
|
||||||
* is not owned by the player.
|
|
||||||
*
|
|
||||||
* @param region
|
|
||||||
* @param player
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
public boolean overlapsUnownedRegion(ProtectedRegion region, LocalPlayer player);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the number of regions.
|
|
||||||
*
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
public int size();
|
|
||||||
}
|
|
@ -17,8 +17,10 @@
|
|||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package com.sk89q.worldguard.protection;
|
package com.sk89q.worldguard.protection.dbs;
|
||||||
|
|
||||||
|
import com.sk89q.worldguard.protection.regions.ProtectedCuboidRegion;
|
||||||
|
import com.sk89q.worldguard.protection.regionmanager.RegionManager;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.LinkedHashMap;
|
import java.util.LinkedHashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
@ -31,8 +33,10 @@
|
|||||||
import com.sk89q.worldedit.BlockVector;
|
import com.sk89q.worldedit.BlockVector;
|
||||||
import com.sk89q.worldedit.Vector;
|
import com.sk89q.worldedit.Vector;
|
||||||
import com.sk89q.worldguard.domains.DefaultDomain;
|
import com.sk89q.worldguard.domains.DefaultDomain;
|
||||||
import com.sk89q.worldguard.protection.AreaFlags.State;
|
import com.sk89q.worldguard.protection.regions.AreaFlags;
|
||||||
import com.sk89q.worldguard.protection.ProtectedRegion.CircularInheritanceException;
|
import com.sk89q.worldguard.protection.regions.AreaFlags.State;
|
||||||
|
import com.sk89q.worldguard.protection.regions.ProtectedRegion;
|
||||||
|
import com.sk89q.worldguard.protection.regions.ProtectedRegion.CircularInheritanceException;
|
||||||
import com.sk89q.worldguard.util.ArrayReader;
|
import com.sk89q.worldguard.util.ArrayReader;
|
||||||
|
|
||||||
/**
|
/**
|
109
src/com/sk89q/worldguard/protection/dbs/JSONContainer.java
Normal file
109
src/com/sk89q/worldguard/protection/dbs/JSONContainer.java
Normal file
@ -0,0 +1,109 @@
|
|||||||
|
// $Id$
|
||||||
|
/*
|
||||||
|
* WorldGuard
|
||||||
|
* Copyright (C) 2010 sk89q <http://www.sk89q.com>
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.sk89q.worldguard.protection.dbs;
|
||||||
|
|
||||||
|
import com.sk89q.worldguard.domains.DefaultDomain;
|
||||||
|
import com.sk89q.worldguard.protection.regions.AreaFlags;
|
||||||
|
import com.sk89q.worldguard.protection.regions.ProtectedRegion;
|
||||||
|
import com.sk89q.worldguard.protection.regions.ProtectedPolygonalRegion;
|
||||||
|
import com.sk89q.worldguard.protection.regions.ProtectedCuboidRegion;
|
||||||
|
import com.sk89q.worldguard.protection.regions.ProtectedRegion.CircularInheritanceException;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author Redecouverte
|
||||||
|
*/
|
||||||
|
public class JSONContainer {
|
||||||
|
|
||||||
|
private static Logger logger = Logger.getLogger("Minecraft.WorldGuard");
|
||||||
|
|
||||||
|
private HashMap<String,ProtectedCuboidRegion> cRegions;
|
||||||
|
private HashMap<String,ProtectedPolygonalRegion> pRegions;
|
||||||
|
|
||||||
|
public JSONContainer(Map<String,ProtectedRegion> regions)
|
||||||
|
{
|
||||||
|
|
||||||
|
this.cRegions = new HashMap<String,ProtectedCuboidRegion>();
|
||||||
|
this.pRegions = new HashMap<String,ProtectedPolygonalRegion>();
|
||||||
|
|
||||||
|
for (Map.Entry<String,ProtectedRegion> entry : regions.entrySet()) {
|
||||||
|
String id = entry.getKey();
|
||||||
|
ProtectedRegion region = entry.getValue();
|
||||||
|
region.setParentId();
|
||||||
|
|
||||||
|
if(region instanceof ProtectedCuboidRegion)
|
||||||
|
{
|
||||||
|
cRegions.put(id, (ProtectedCuboidRegion)region);
|
||||||
|
}
|
||||||
|
else if(region instanceof ProtectedPolygonalRegion)
|
||||||
|
{
|
||||||
|
pRegions.put(id, (ProtectedPolygonalRegion)region);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
logger.info("regions of type '" + region.getClass().toString() + "' are not supported for saving, yet.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public Map<String, ProtectedRegion> getRegions() {
|
||||||
|
HashMap<String, ProtectedRegion> ret = new HashMap<String, ProtectedRegion>();
|
||||||
|
ret.putAll(this.cRegions);
|
||||||
|
ret.putAll(this.pRegions);
|
||||||
|
|
||||||
|
for (Map.Entry<String, ProtectedRegion> entry : ret.entrySet()) {
|
||||||
|
String id = entry.getKey();
|
||||||
|
ProtectedRegion region = entry.getValue();
|
||||||
|
|
||||||
|
String parentId = region.getParentId();
|
||||||
|
if (parentId != null) {
|
||||||
|
try {
|
||||||
|
region.setParent(ret.get(parentId));
|
||||||
|
} catch (CircularInheritanceException ex) {
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
try {
|
||||||
|
region.setParent(null);
|
||||||
|
} catch (CircularInheritanceException ex) {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if(region.getOwners() == null)
|
||||||
|
{
|
||||||
|
region.setOwners(new DefaultDomain());
|
||||||
|
}
|
||||||
|
else if(region.getMembers() == null)
|
||||||
|
{
|
||||||
|
region.setMembers(new DefaultDomain());
|
||||||
|
}
|
||||||
|
else if(region.getFlags() == null)
|
||||||
|
{
|
||||||
|
region.setFlags(new AreaFlags());
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
}
|
168
src/com/sk89q/worldguard/protection/dbs/JSONDatabase.java
Normal file
168
src/com/sk89q/worldguard/protection/dbs/JSONDatabase.java
Normal file
@ -0,0 +1,168 @@
|
|||||||
|
// $Id$
|
||||||
|
/*
|
||||||
|
* WorldGuard
|
||||||
|
* Copyright (C) 2010 sk89q <http://www.sk89q.com>
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.sk89q.worldguard.protection.dbs;
|
||||||
|
|
||||||
|
import com.sk89q.worldguard.protection.dbs.ProtectionDatabase;
|
||||||
|
import com.sk89q.worldguard.protection.dbs.JSONContainer;
|
||||||
|
import com.sk89q.worldguard.protection.regionmanager.RegionManager;
|
||||||
|
import com.google.gson.Gson;
|
||||||
|
import com.google.gson.reflect.TypeToken;
|
||||||
|
import com.sk89q.worldedit.BlockVector;
|
||||||
|
import com.sk89q.worldguard.protection.regions.ProtectedRegion;
|
||||||
|
import java.io.BufferedInputStream;
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.FileInputStream;
|
||||||
|
import java.io.FileReader;
|
||||||
|
import java.io.FileWriter;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.lang.String;
|
||||||
|
import java.lang.reflect.Type;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Represents a protected area database that uses JSON files.
|
||||||
|
*
|
||||||
|
* @author Redecouverte
|
||||||
|
*/
|
||||||
|
public class JSONDatabase implements ProtectionDatabase {
|
||||||
|
private static Logger logger = Logger.getLogger("Minecraft.WorldGuard");
|
||||||
|
|
||||||
|
/**
|
||||||
|
* References the json db folder.
|
||||||
|
*/
|
||||||
|
private File file;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Holds the list of regions.
|
||||||
|
*/
|
||||||
|
private Map<String,ProtectedRegion> regions;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Construct the database with a path to a file. No file is read or
|
||||||
|
* written at this time.
|
||||||
|
*
|
||||||
|
* @param file
|
||||||
|
*/
|
||||||
|
public JSONDatabase(File file) {
|
||||||
|
this.file = file;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Helper function to read a file into a String
|
||||||
|
*/
|
||||||
|
private static String readFileAsString(File file) throws java.io.IOException {
|
||||||
|
byte[] buffer = new byte[(int) file.length()];
|
||||||
|
BufferedInputStream f = null;
|
||||||
|
try {
|
||||||
|
f = new BufferedInputStream(new FileInputStream(file.getAbsolutePath()));
|
||||||
|
f.read(buffer);
|
||||||
|
} finally {
|
||||||
|
if (f != null) {
|
||||||
|
try {
|
||||||
|
f.close();
|
||||||
|
} catch (IOException ignored) {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return new String(buffer);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Load the database from file.
|
||||||
|
*/
|
||||||
|
public void load() throws IOException {
|
||||||
|
|
||||||
|
Gson gson = new Gson();
|
||||||
|
JSONContainer jContainer = gson.fromJson(readFileAsString(file), JSONContainer.class);
|
||||||
|
this.regions = jContainer.getRegions();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Saves the database.
|
||||||
|
*/
|
||||||
|
public void save() throws IOException {
|
||||||
|
|
||||||
|
Gson gson = new Gson();
|
||||||
|
String jsonData = gson.toJson(new JSONContainer(this.regions), JSONContainer.class);
|
||||||
|
writeStringToFile(jsonData, this.file);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Writes a String to a file.
|
||||||
|
*
|
||||||
|
* @throws IOException
|
||||||
|
*/
|
||||||
|
public static void writeStringToFile(String string, File file) throws IOException {
|
||||||
|
FileWriter writer = null;
|
||||||
|
|
||||||
|
try {
|
||||||
|
writer = new FileWriter(file);
|
||||||
|
writer.write(string);
|
||||||
|
} finally {
|
||||||
|
try {
|
||||||
|
if (writer != null) {
|
||||||
|
writer.close();
|
||||||
|
}
|
||||||
|
} catch (IOException e) {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Load the list of regions into a region manager.
|
||||||
|
*
|
||||||
|
* @throws IOException
|
||||||
|
*/
|
||||||
|
public void load(RegionManager manager) throws IOException {
|
||||||
|
load();
|
||||||
|
manager.setRegions(regions);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Save the list of regions from a region manager.
|
||||||
|
*
|
||||||
|
* @throws IOException
|
||||||
|
*/
|
||||||
|
public void save(RegionManager manager) throws IOException {
|
||||||
|
regions = manager.getRegions();
|
||||||
|
save();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get a list of protected regions.
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public Map<String,ProtectedRegion> getRegions() {
|
||||||
|
return regions;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get a list of protected regions.
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public void setRegions(Map<String,ProtectedRegion> regions) {
|
||||||
|
this.regions = regions;
|
||||||
|
}
|
||||||
|
}
|
@ -1,68 +1,70 @@
|
|||||||
// $Id$
|
// $Id$
|
||||||
/*
|
/*
|
||||||
* WorldGuard
|
* WorldGuard
|
||||||
* Copyright (C) 2010 sk89q <http://www.sk89q.com>
|
* Copyright (C) 2010 sk89q <http://www.sk89q.com>
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify
|
* This program is free software: you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU General Public License as published by
|
* it under the terms of the GNU General Public License as published by
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
* (at your option) any later version.
|
* (at your option) any later version.
|
||||||
*
|
*
|
||||||
* This program is distributed in the hope that it will be useful,
|
* This program is distributed in the hope that it will be useful,
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
* GNU General Public License for more details.
|
* GNU General Public License for more details.
|
||||||
*
|
*
|
||||||
* You should have received a copy of the GNU General Public License
|
* You should have received a copy of the GNU General Public License
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package com.sk89q.worldguard.protection;
|
package com.sk89q.worldguard.protection.dbs;
|
||||||
|
|
||||||
import java.io.IOException;
|
import com.sk89q.worldguard.protection.regions.ProtectedRegion;
|
||||||
import java.util.Map;
|
import com.sk89q.worldguard.protection.regionmanager.RegionManager;
|
||||||
|
import java.io.IOException;
|
||||||
/**
|
import java.util.Map;
|
||||||
* Represents a database to read and write lists of regions from and to.
|
|
||||||
*
|
/**
|
||||||
* @author sk89q
|
* Represents a database to read and write lists of regions from and to.
|
||||||
*/
|
*
|
||||||
public interface ProtectionDatabase {
|
* @author sk89q
|
||||||
/**
|
*/
|
||||||
* Load the list of regions. The method should not modify the list returned
|
public interface ProtectionDatabase {
|
||||||
* by getRegions() unless the load finishes successfully.
|
/**
|
||||||
*
|
* Load the list of regions. The method should not modify the list returned
|
||||||
* @throws IOException
|
* by getRegions() unless the load finishes successfully.
|
||||||
*/
|
*
|
||||||
public void load() throws IOException;
|
* @throws IOException
|
||||||
/**
|
*/
|
||||||
* Save the list of regions.
|
public void load() throws IOException;
|
||||||
*
|
/**
|
||||||
* @throws IOException
|
* Save the list of regions.
|
||||||
*/
|
*
|
||||||
public void save() throws IOException;
|
* @throws IOException
|
||||||
/**
|
*/
|
||||||
* Load the list of regions into a region manager.
|
public void save() throws IOException;
|
||||||
*
|
/**
|
||||||
* @throws IOException
|
* Load the list of regions into a region manager.
|
||||||
*/
|
*
|
||||||
public void load(RegionManager manager) throws IOException;
|
* @throws IOException
|
||||||
/**
|
*/
|
||||||
* Save the list of regions from a region manager.
|
public void load(RegionManager manager) throws IOException;
|
||||||
*
|
/**
|
||||||
* @throws IOException
|
* Save the list of regions from a region manager.
|
||||||
*/
|
*
|
||||||
public void save(RegionManager manager) throws IOException;
|
* @throws IOException
|
||||||
/**
|
*/
|
||||||
* Get a list of regions.
|
public void save(RegionManager manager) throws IOException;
|
||||||
*
|
/**
|
||||||
* @return
|
* Get a list of regions.
|
||||||
*/
|
*
|
||||||
public Map<String,ProtectedRegion> getRegions();
|
* @return
|
||||||
/**
|
*/
|
||||||
* Set the list of regions.
|
public Map<String,ProtectedRegion> getRegions();
|
||||||
*
|
/**
|
||||||
* @param regions
|
* Set the list of regions.
|
||||||
*/
|
*
|
||||||
public void setRegions(Map<String,ProtectedRegion> regions);
|
* @param regions
|
||||||
}
|
*/
|
||||||
|
public void setRegions(Map<String,ProtectedRegion> regions);
|
||||||
|
}
|
@ -1,183 +1,208 @@
|
|||||||
// $Id$
|
// $Id$
|
||||||
/*
|
/*
|
||||||
* WorldGuard
|
* WorldGuard
|
||||||
* Copyright (C) 2010 sk89q <http://www.sk89q.com>
|
* Copyright (C) 2010 sk89q <http://www.sk89q.com>
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify
|
* This program is free software: you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU General Public License as published by
|
* it under the terms of the GNU General Public License as published by
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
* (at your option) any later version.
|
* (at your option) any later version.
|
||||||
*
|
*
|
||||||
* This program is distributed in the hope that it will be useful,
|
* This program is distributed in the hope that it will be useful,
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
* GNU General Public License for more details.
|
* GNU General Public License for more details.
|
||||||
*
|
*
|
||||||
* You should have received a copy of the GNU General Public License
|
* You should have received a copy of the GNU General Public License
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package com.sk89q.worldguard.protection;
|
package com.sk89q.worldguard.protection.regionmanager;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.io.IOException;
|
||||||
import java.util.List;
|
import java.util.ArrayList;
|
||||||
import java.util.Map;
|
import java.util.List;
|
||||||
import java.util.SortedMap;
|
import java.util.Map;
|
||||||
import java.util.TreeMap;
|
import java.util.SortedMap;
|
||||||
import com.sk89q.worldedit.Vector;
|
import java.util.TreeMap;
|
||||||
import com.sk89q.worldguard.LocalPlayer;
|
import com.sk89q.worldedit.Vector;
|
||||||
|
import com.sk89q.worldguard.LocalPlayer;
|
||||||
/**
|
import com.sk89q.worldguard.protection.ApplicableRegionSet;
|
||||||
* A very simple implementation of the region manager that uses a flat list
|
import com.sk89q.worldguard.protection.GlobalFlags;
|
||||||
* and iterates through the list to identify applicable regions. This method
|
import com.sk89q.worldguard.protection.regions.ProtectedRegion;
|
||||||
* is not very efficient.
|
import com.sk89q.worldguard.protection.UnsupportedIntersectionException;
|
||||||
*
|
import com.sk89q.worldguard.protection.dbs.ProtectionDatabase;
|
||||||
* @author sk89q
|
import java.io.FileNotFoundException;
|
||||||
*/
|
import java.util.logging.Level;
|
||||||
public class FlatRegionManager implements RegionManager {
|
import java.util.logging.Logger;
|
||||||
/**
|
|
||||||
* List of protected regions.
|
/**
|
||||||
*/
|
* A very simple implementation of the region manager that uses a flat list
|
||||||
private Map<String,ProtectedRegion> regions;
|
* and iterates through the list to identify applicable regions. This method
|
||||||
/**
|
* is not very efficient.
|
||||||
* Global flags.
|
*
|
||||||
*/
|
* @author sk89q
|
||||||
private GlobalFlags global;
|
*/
|
||||||
|
public class FlatRegionManager extends RegionManager {
|
||||||
/**
|
/**
|
||||||
* Construct the manager.
|
* List of protected regions.
|
||||||
*/
|
*/
|
||||||
public FlatRegionManager(GlobalFlags global) {
|
private Map<String,ProtectedRegion> regions;
|
||||||
regions = new TreeMap<String,ProtectedRegion>();
|
|
||||||
this.global = global;
|
|
||||||
}
|
/**
|
||||||
|
* Construct the manager.
|
||||||
/**
|
*/
|
||||||
* Get a list of protected regions.
|
public FlatRegionManager(GlobalFlags global, ProtectionDatabase regionloader) throws IOException {
|
||||||
*
|
|
||||||
* @return
|
super(global, regionloader);
|
||||||
*/
|
regions = new TreeMap<String,ProtectedRegion>();
|
||||||
public Map<String,ProtectedRegion> getRegions() {
|
this.load();
|
||||||
return regions;
|
}
|
||||||
}
|
|
||||||
|
/**
|
||||||
/**
|
* Get a list of protected regions.
|
||||||
* Set a list of protected regions.
|
*
|
||||||
*
|
* @return
|
||||||
* @return
|
*/
|
||||||
*/
|
public Map<String,ProtectedRegion> getRegions() {
|
||||||
public void setRegions(Map<String,ProtectedRegion> regions) {
|
return regions;
|
||||||
this.regions = new TreeMap<String,ProtectedRegion>(regions);
|
}
|
||||||
}
|
|
||||||
|
/**
|
||||||
/**
|
* Set a list of protected regions.
|
||||||
* Adds a region.
|
*
|
||||||
*
|
* @return
|
||||||
* @param id
|
*/
|
||||||
* @param region
|
public void setRegions(Map<String,ProtectedRegion> regions) {
|
||||||
*/
|
this.regions = new TreeMap<String,ProtectedRegion>(regions);
|
||||||
public void addRegion(ProtectedRegion region) {
|
}
|
||||||
regions.put(region.getId(), region);
|
|
||||||
}
|
/**
|
||||||
|
* Adds a region.
|
||||||
/**
|
*
|
||||||
* Removes a region and its children.
|
* @param id
|
||||||
*
|
* @param region
|
||||||
* @param id
|
*/
|
||||||
*/
|
public void addRegion(ProtectedRegion region) {
|
||||||
public void removeRegion(String id) {
|
regions.put(region.getId(), region);
|
||||||
ProtectedRegion region = regions.get(id);
|
}
|
||||||
|
|
||||||
regions.remove(id);
|
/**
|
||||||
|
* Removes a region and its children.
|
||||||
if (region != null) {
|
*
|
||||||
for (Map.Entry<String, ProtectedRegion> entry : regions.entrySet()) {
|
* @param id
|
||||||
if (entry.getValue().getParent() == region) {
|
*/
|
||||||
removeRegion(entry.getKey());
|
public void removeRegion(String id) {
|
||||||
}
|
ProtectedRegion region = regions.get(id);
|
||||||
}
|
|
||||||
}
|
regions.remove(id);
|
||||||
}
|
|
||||||
|
if (region != null) {
|
||||||
/**
|
for (Map.Entry<String, ProtectedRegion> entry : regions.entrySet()) {
|
||||||
* Return whether a region exists by an ID.
|
if (entry.getValue().getParent() == region) {
|
||||||
*
|
removeRegion(entry.getKey());
|
||||||
* @param id
|
}
|
||||||
* @return
|
}
|
||||||
*/
|
}
|
||||||
public boolean hasRegion(String id) {
|
}
|
||||||
return regions.containsKey(id);
|
|
||||||
}
|
/**
|
||||||
|
* Return whether a region exists by an ID.
|
||||||
/**
|
*
|
||||||
* Get a region by its ID.
|
* @param id
|
||||||
*
|
* @return
|
||||||
* @param id
|
*/
|
||||||
*/
|
public boolean hasRegion(String id) {
|
||||||
public ProtectedRegion getRegion(String id) {
|
return regions.containsKey(id);
|
||||||
return regions.get(id);
|
}
|
||||||
}
|
|
||||||
|
/**
|
||||||
/**
|
* Get a region by its ID.
|
||||||
* Get an object for a point for rules to be applied with.
|
*
|
||||||
*
|
* @param id
|
||||||
* @param pt
|
*/
|
||||||
* @return
|
public ProtectedRegion getRegion(String id) {
|
||||||
*/
|
return regions.get(id);
|
||||||
public ApplicableRegionSet getApplicableRegions(Vector pt) {
|
}
|
||||||
return new ApplicableRegionSet(pt, regions.values().iterator(), global);
|
|
||||||
}
|
/**
|
||||||
|
* Get an object for a point for rules to be applied with.
|
||||||
/**
|
*
|
||||||
* Get a list of region IDs that contain a point.
|
* @param pt
|
||||||
*
|
* @return
|
||||||
* @param pt
|
*/
|
||||||
* @return
|
public ApplicableRegionSet getApplicableRegions(Vector pt) {
|
||||||
*/
|
return new ApplicableRegionSet(pt, regions.values().iterator(), global);
|
||||||
public List<String> getApplicableRegionsIDs(Vector pt) {
|
}
|
||||||
List<String> applicable = new ArrayList<String>();
|
|
||||||
|
/**
|
||||||
for (Map.Entry<String,ProtectedRegion> entry : regions.entrySet()) {
|
* Get a list of region IDs that contain a point.
|
||||||
if (entry.getValue().contains(pt)) {
|
*
|
||||||
applicable.add(entry.getKey());
|
* @param pt
|
||||||
}
|
* @return
|
||||||
}
|
*/
|
||||||
|
public List<String> getApplicableRegionsIDs(Vector pt) {
|
||||||
return applicable;
|
List<String> applicable = new ArrayList<String>();
|
||||||
}
|
|
||||||
|
for (Map.Entry<String,ProtectedRegion> entry : regions.entrySet()) {
|
||||||
/**
|
if (entry.getValue().contains(pt)) {
|
||||||
* Returns true if the provided region overlaps with any other region that
|
applicable.add(entry.getKey());
|
||||||
* is not owned by the player.
|
}
|
||||||
*
|
}
|
||||||
* @param region
|
|
||||||
* @param player
|
return applicable;
|
||||||
* @return
|
}
|
||||||
*/
|
|
||||||
public boolean overlapsUnownedRegion(ProtectedRegion region, LocalPlayer player) {
|
/**
|
||||||
for (ProtectedRegion other : regions.values()) {
|
* Returns true if the provided region overlaps with any other region that
|
||||||
if (other.getOwners().contains(player)) {
|
* is not owned by the player.
|
||||||
continue;
|
*
|
||||||
}
|
* @param region
|
||||||
|
* @param player
|
||||||
try {
|
* @return
|
||||||
if (ProtectedRegion.intersects(region, other)) {
|
*/
|
||||||
return true;
|
public boolean overlapsUnownedRegion(ProtectedRegion region, LocalPlayer player) {
|
||||||
}
|
for (ProtectedRegion other : regions.values()) {
|
||||||
} catch (UnsupportedIntersectionException e) {
|
if (other.getOwners().contains(player)) {
|
||||||
// TODO: Maybe do something here
|
continue;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
try {
|
||||||
return false;
|
if (ProtectedRegion.intersects(region, other)) {
|
||||||
}
|
return true;
|
||||||
|
}
|
||||||
/**
|
} catch (UnsupportedIntersectionException e) {
|
||||||
* Get the number of regions.
|
// TODO: Maybe do something here
|
||||||
*
|
}
|
||||||
* @return
|
}
|
||||||
*/
|
|
||||||
public int size() {
|
return false;
|
||||||
return regions.size();
|
}
|
||||||
}
|
|
||||||
}
|
/**
|
||||||
|
* Get the number of regions.
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public int size() {
|
||||||
|
return regions.size();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Save the list of regions.
|
||||||
|
*
|
||||||
|
* @throws IOException
|
||||||
|
*/
|
||||||
|
public void save() throws IOException
|
||||||
|
{
|
||||||
|
if(this.regionloader == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
regionloader.save(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,89 @@
|
|||||||
|
// $Id$
|
||||||
|
/*
|
||||||
|
* WorldGuard
|
||||||
|
* Copyright (C) 2010 sk89q <http://www.sk89q.com>
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
package com.sk89q.worldguard.protection.regionmanager;
|
||||||
|
|
||||||
|
import com.sk89q.worldguard.bukkit.WorldGuardPlugin;
|
||||||
|
import com.sk89q.worldguard.protection.GlobalFlags;
|
||||||
|
import com.sk89q.worldguard.protection.dbs.JSONDatabase;
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.FileNotFoundException;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.logging.Logger;
|
||||||
|
import org.bukkit.World;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author Redecouverte
|
||||||
|
*/
|
||||||
|
public class GlobalRegionManager {
|
||||||
|
|
||||||
|
private WorldGuardPlugin wg;
|
||||||
|
private HashMap<String, RegionManager> managers;
|
||||||
|
private GlobalFlags globalFlags;
|
||||||
|
private static final Logger logger = Logger.getLogger("Minecraft.WorldGuard");
|
||||||
|
|
||||||
|
public GlobalRegionManager(WorldGuardPlugin wg) {
|
||||||
|
|
||||||
|
this.wg = wg;
|
||||||
|
this.managers = new HashMap<String, RegionManager>();
|
||||||
|
this.globalFlags = new GlobalFlags();
|
||||||
|
|
||||||
|
for (World w : wg.getServer().getWorlds()) {
|
||||||
|
loadWorld(w.getName());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void loadWorld(String name) {
|
||||||
|
|
||||||
|
String filename = name + ".regions.json";
|
||||||
|
try {
|
||||||
|
managers.put(name, new FlatRegionManager(globalFlags, new JSONDatabase(new File(wg.getDataFolder(), filename))));
|
||||||
|
} catch (FileNotFoundException e) {
|
||||||
|
} catch (IOException e) {
|
||||||
|
logger.warning("WorldGuard: Failed to load regions from file " + filename + " : "
|
||||||
|
+ e.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public RegionManager getRegionmanager(String worldName) {
|
||||||
|
|
||||||
|
RegionManager ret = this.managers.get(worldName);
|
||||||
|
|
||||||
|
if (ret == null) {
|
||||||
|
if (wg.getServer().getWorld(worldName) != null) {
|
||||||
|
loadWorld(worldName);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setGlobalFlags(GlobalFlags globalflags) {
|
||||||
|
|
||||||
|
if (globalflags != null) {
|
||||||
|
this.globalFlags = globalflags;
|
||||||
|
for (Map.Entry<String, RegionManager> entry : managers.entrySet()) {
|
||||||
|
entry.getValue().setGlobalFlags(globalflags);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
@ -1,203 +1,218 @@
|
|||||||
// $Id$
|
// $Id$
|
||||||
/*
|
/*
|
||||||
* WorldGuard
|
* WorldGuard
|
||||||
* Copyright (C) 2010 sk89q <http://www.sk89q.com>
|
* Copyright (C) 2010 sk89q <http://www.sk89q.com>
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify
|
* This program is free software: you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU General Public License as published by
|
* it under the terms of the GNU General Public License as published by
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
* (at your option) any later version.
|
* (at your option) any later version.
|
||||||
*
|
*
|
||||||
* This program is distributed in the hope that it will be useful,
|
* This program is distributed in the hope that it will be useful,
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
* GNU General Public License for more details.
|
* GNU General Public License for more details.
|
||||||
*
|
*
|
||||||
* You should have received a copy of the GNU General Public License
|
* You should have received a copy of the GNU General Public License
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package com.sk89q.worldguard.protection;
|
package com.sk89q.worldguard.protection.regionmanager;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.TreeMap;
|
import java.util.TreeMap;
|
||||||
import org.khelekore.prtree.MBRConverter;
|
import org.khelekore.prtree.MBRConverter;
|
||||||
import org.khelekore.prtree.PRTree;
|
import org.khelekore.prtree.PRTree;
|
||||||
import com.sk89q.worldedit.Vector;
|
import com.sk89q.worldedit.Vector;
|
||||||
import com.sk89q.worldguard.LocalPlayer;
|
import com.sk89q.worldguard.LocalPlayer;
|
||||||
|
import com.sk89q.worldguard.protection.ApplicableRegionSet;
|
||||||
public class PRTreeRegionManager implements RegionManager {
|
import com.sk89q.worldguard.protection.GlobalFlags;
|
||||||
private static final int BRANCH_FACTOR = 30;
|
import com.sk89q.worldguard.protection.regions.ProtectedRegion;
|
||||||
|
import com.sk89q.worldguard.protection.regions.ProtectedRegionMBRConverter;
|
||||||
/**
|
import com.sk89q.worldguard.protection.UnsupportedIntersectionException;
|
||||||
* List of protected regions.
|
import com.sk89q.worldguard.protection.dbs.ProtectionDatabase;
|
||||||
*/
|
import java.io.IOException;
|
||||||
private Map<String,ProtectedRegion> regions;
|
import java.util.HashMap;
|
||||||
/**
|
|
||||||
* Global flags.
|
public class PRTreeRegionManager extends RegionManager {
|
||||||
*/
|
private static final int BRANCH_FACTOR = 30;
|
||||||
private GlobalFlags global;
|
|
||||||
|
/**
|
||||||
/**
|
* List of protected regions.
|
||||||
* Converter to get coordinates of the tree.
|
*/
|
||||||
*/
|
private Map<String,ProtectedRegion> regions;
|
||||||
private MBRConverter<ProtectedRegion> converter
|
|
||||||
= new ProtectedRegionMBRConverter();
|
/**
|
||||||
|
* Converter to get coordinates of the tree.
|
||||||
/**
|
*/
|
||||||
* Priority R-tree.
|
private MBRConverter<ProtectedRegion> converter
|
||||||
*/
|
= new ProtectedRegionMBRConverter();
|
||||||
private PRTree<ProtectedRegion> tree;
|
|
||||||
|
/**
|
||||||
/**
|
* Priority R-tree.
|
||||||
* Construct the manager.
|
*/
|
||||||
*/
|
private PRTree<ProtectedRegion> tree;
|
||||||
public PRTreeRegionManager(GlobalFlags global) {
|
|
||||||
regions = new TreeMap<String,ProtectedRegion>();
|
/**
|
||||||
tree = new PRTree<ProtectedRegion>(converter, BRANCH_FACTOR);
|
* Construct the manager.
|
||||||
this.global = global;
|
*/
|
||||||
}
|
public PRTreeRegionManager(GlobalFlags global, ProtectionDatabase regionloader) throws IOException {
|
||||||
|
super(global, regionloader);
|
||||||
/**
|
regions = new TreeMap<String,ProtectedRegion>();
|
||||||
* Get a list of protected regions.
|
tree = new PRTree<ProtectedRegion>(converter, BRANCH_FACTOR);
|
||||||
*
|
this.load();
|
||||||
* @return
|
}
|
||||||
*/
|
|
||||||
public Map<String,ProtectedRegion> getRegions() {
|
/**
|
||||||
return regions;
|
* Get a list of protected regions.
|
||||||
}
|
*
|
||||||
|
* @return
|
||||||
/**
|
*/
|
||||||
* Set a list of protected regions.
|
public Map<String,ProtectedRegion> getRegions() {
|
||||||
*
|
return regions;
|
||||||
* @return
|
}
|
||||||
*/
|
|
||||||
public void setRegions(Map<String,ProtectedRegion> regions) {
|
/**
|
||||||
this.regions = new TreeMap<String,ProtectedRegion>(regions);
|
* Set a list of protected regions.
|
||||||
tree = new PRTree<ProtectedRegion>(converter, BRANCH_FACTOR);
|
*
|
||||||
tree.load(regions.values());
|
* @return
|
||||||
}
|
*/
|
||||||
|
public void setRegions(Map<String,ProtectedRegion> regions) {
|
||||||
/**
|
this.regions = new TreeMap<String,ProtectedRegion>(regions);
|
||||||
* Adds a region.
|
tree = new PRTree<ProtectedRegion>(converter, BRANCH_FACTOR);
|
||||||
*
|
tree.load(regions.values());
|
||||||
* @param id
|
}
|
||||||
* @param region
|
|
||||||
*/
|
/**
|
||||||
public void addRegion(ProtectedRegion region) {
|
* Adds a region.
|
||||||
regions.put(region.getId(), region);
|
*
|
||||||
tree = new PRTree<ProtectedRegion>(converter, BRANCH_FACTOR);
|
* @param id
|
||||||
tree.load(regions.values());
|
* @param region
|
||||||
}
|
*/
|
||||||
|
public void addRegion(ProtectedRegion region) {
|
||||||
/**
|
regions.put(region.getId(), region);
|
||||||
* Return whether a region exists by an ID.
|
tree = new PRTree<ProtectedRegion>(converter, BRANCH_FACTOR);
|
||||||
*
|
tree.load(regions.values());
|
||||||
* @param id
|
}
|
||||||
* @return
|
|
||||||
*/
|
/**
|
||||||
public boolean hasRegion(String id) {
|
* Return whether a region exists by an ID.
|
||||||
return regions.containsKey(id);
|
*
|
||||||
}
|
* @param id
|
||||||
|
* @return
|
||||||
/**
|
*/
|
||||||
* Get a region by its ID.
|
public boolean hasRegion(String id) {
|
||||||
*
|
return regions.containsKey(id);
|
||||||
* @param id
|
}
|
||||||
*/
|
|
||||||
public ProtectedRegion getRegion(String id) {
|
/**
|
||||||
return regions.get(id);
|
* Get a region by its ID.
|
||||||
}
|
*
|
||||||
|
* @param id
|
||||||
/**
|
*/
|
||||||
* Removes a region and its children.
|
public ProtectedRegion getRegion(String id) {
|
||||||
*
|
return regions.get(id);
|
||||||
* @param id
|
}
|
||||||
*/
|
|
||||||
public void removeRegion(String id) {
|
/**
|
||||||
ProtectedRegion region = regions.get(id);
|
* Removes a region and its children.
|
||||||
|
*
|
||||||
regions.remove(id);
|
* @param id
|
||||||
|
*/
|
||||||
if (region != null) {
|
public void removeRegion(String id) {
|
||||||
for (Map.Entry<String, ProtectedRegion> entry : regions.entrySet()) {
|
ProtectedRegion region = regions.get(id);
|
||||||
if (entry.getValue().getParent() == region) {
|
|
||||||
removeRegion(entry.getKey());
|
regions.remove(id);
|
||||||
}
|
|
||||||
}
|
if (region != null) {
|
||||||
}
|
for (Map.Entry<String, ProtectedRegion> entry : regions.entrySet()) {
|
||||||
|
if (entry.getValue().getParent() == region) {
|
||||||
tree = new PRTree<ProtectedRegion>(converter, BRANCH_FACTOR);
|
removeRegion(entry.getKey());
|
||||||
tree.load(regions.values());
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
/**
|
|
||||||
* Get an object for a point for rules to be applied with.
|
tree = new PRTree<ProtectedRegion>(converter, BRANCH_FACTOR);
|
||||||
*
|
tree.load(regions.values());
|
||||||
* @param pt
|
}
|
||||||
* @return
|
|
||||||
*/
|
/**
|
||||||
public ApplicableRegionSet getApplicableRegions(Vector pt) {
|
* Get an object for a point for rules to be applied with.
|
||||||
return new ApplicableRegionSet(pt, regions.values().iterator(), global);
|
*
|
||||||
}
|
* @param pt
|
||||||
|
* @return
|
||||||
/**
|
*/
|
||||||
* Get a list of region IDs that contain a point.
|
public ApplicableRegionSet getApplicableRegions(Vector pt) {
|
||||||
*
|
return new ApplicableRegionSet(pt, regions.values().iterator(), global);
|
||||||
* @param pt
|
}
|
||||||
* @return
|
|
||||||
*/
|
/**
|
||||||
public List<String> getApplicableRegionsIDs(Vector pt) {
|
* Get a list of region IDs that contain a point.
|
||||||
List<String> applicable = new ArrayList<String>();
|
*
|
||||||
|
* @param pt
|
||||||
int x = pt.getBlockX();
|
* @return
|
||||||
int z = pt.getBlockZ();
|
*/
|
||||||
|
public List<String> getApplicableRegionsIDs(Vector pt) {
|
||||||
for (ProtectedRegion region : tree.find(x, z, x, z)) {
|
List<String> applicable = new ArrayList<String>();
|
||||||
if (region.contains(pt)) {
|
|
||||||
applicable.add(region.getId());
|
int x = pt.getBlockX();
|
||||||
}
|
int z = pt.getBlockZ();
|
||||||
}
|
|
||||||
|
for (ProtectedRegion region : tree.find(x, z, x, z)) {
|
||||||
return applicable;
|
if (region.contains(pt)) {
|
||||||
}
|
applicable.add(region.getId());
|
||||||
|
}
|
||||||
/**
|
}
|
||||||
* Returns true if the provided region overlaps with any other region that
|
|
||||||
* is not owned by the player.
|
return applicable;
|
||||||
*
|
}
|
||||||
* @param region
|
|
||||||
* @param player
|
/**
|
||||||
* @return
|
* Returns true if the provided region overlaps with any other region that
|
||||||
*/
|
* is not owned by the player.
|
||||||
public boolean overlapsUnownedRegion(ProtectedRegion region, LocalPlayer player) {
|
*
|
||||||
for (ProtectedRegion other : regions.values()) {
|
* @param region
|
||||||
if (other.getOwners().contains(player)) {
|
* @param player
|
||||||
continue;
|
* @return
|
||||||
}
|
*/
|
||||||
|
public boolean overlapsUnownedRegion(ProtectedRegion region, LocalPlayer player) {
|
||||||
try {
|
for (ProtectedRegion other : regions.values()) {
|
||||||
if (ProtectedRegion.intersects(region, other)) {
|
if (other.getOwners().contains(player)) {
|
||||||
return true;
|
continue;
|
||||||
}
|
}
|
||||||
} catch (UnsupportedIntersectionException e) {
|
|
||||||
// TODO: Maybe do something here
|
try {
|
||||||
}
|
if (ProtectedRegion.intersects(region, other)) {
|
||||||
}
|
return true;
|
||||||
|
}
|
||||||
return false;
|
} catch (UnsupportedIntersectionException e) {
|
||||||
}
|
// TODO: Maybe do something here
|
||||||
|
}
|
||||||
/**
|
}
|
||||||
* Get the number of regions.
|
|
||||||
*
|
return false;
|
||||||
* @return
|
}
|
||||||
*/
|
|
||||||
public int size() {
|
/**
|
||||||
return regions.size();
|
* Get the number of regions.
|
||||||
}
|
*
|
||||||
|
* @return
|
||||||
}
|
*/
|
||||||
|
public int size() {
|
||||||
|
return regions.size();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Save the list of regions.
|
||||||
|
*
|
||||||
|
* @throws IOException
|
||||||
|
*/
|
||||||
|
public void save() throws IOException
|
||||||
|
{
|
||||||
|
regionloader.save(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,181 @@
|
|||||||
|
// $Id$
|
||||||
|
/*
|
||||||
|
* WorldGuard
|
||||||
|
* Copyright (C) 2010 sk89q <http://www.sk89q.com>
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.sk89q.worldguard.protection.regionmanager;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import com.sk89q.worldedit.Vector;
|
||||||
|
import com.sk89q.worldguard.LocalPlayer;
|
||||||
|
import com.sk89q.worldguard.protection.ApplicableRegionSet;
|
||||||
|
import com.sk89q.worldguard.protection.GlobalFlags;
|
||||||
|
import com.sk89q.worldguard.protection.dbs.ProtectionDatabase;
|
||||||
|
import com.sk89q.worldguard.protection.regions.ProtectedRegion;
|
||||||
|
import java.io.FileNotFoundException;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* An abstract class for getting, setting, and looking up regions. The most
|
||||||
|
* simple implementation uses a flat list and iterates through the entire
|
||||||
|
* list to look for applicable regions, but a more complicated (and more
|
||||||
|
* efficient) implementation may use space partitioning techniques.
|
||||||
|
*
|
||||||
|
* @author sk89q
|
||||||
|
*/
|
||||||
|
public abstract class RegionManager {
|
||||||
|
|
||||||
|
private static final Logger logger = Logger.getLogger("Minecraft.WorldGuard");
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Global flags.
|
||||||
|
*/
|
||||||
|
protected GlobalFlags global;
|
||||||
|
|
||||||
|
|
||||||
|
protected ProtectionDatabase regionloader;
|
||||||
|
|
||||||
|
|
||||||
|
public RegionManager(GlobalFlags global, ProtectionDatabase regionloader)
|
||||||
|
{
|
||||||
|
this.global = global;
|
||||||
|
this.regionloader = regionloader;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Load the list of regions.
|
||||||
|
*
|
||||||
|
* @throws IOException
|
||||||
|
*/
|
||||||
|
public void load() throws IOException
|
||||||
|
{
|
||||||
|
if(this.regionloader == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
this.regionloader.load();
|
||||||
|
this.setRegions(this.regionloader.getRegions());
|
||||||
|
|
||||||
|
} catch (FileNotFoundException e) {
|
||||||
|
} catch (IOException e) {
|
||||||
|
logger.warning("WorldGuard: Failed to load regions: "
|
||||||
|
+ e.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Save the list of regions.
|
||||||
|
*
|
||||||
|
* @throws IOException
|
||||||
|
*/
|
||||||
|
public abstract void save() throws IOException;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get a list of protected regions.
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public abstract Map<String, ProtectedRegion> getRegions();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set a list of protected regions.
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public abstract void setRegions(Map<String,ProtectedRegion> regions);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Adds a region.
|
||||||
|
*
|
||||||
|
* @param id
|
||||||
|
* @param region
|
||||||
|
*/
|
||||||
|
public abstract void addRegion(ProtectedRegion region);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return whether a region exists by an ID.
|
||||||
|
*
|
||||||
|
* @param id
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public abstract boolean hasRegion(String id);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get a region by its ID.
|
||||||
|
*
|
||||||
|
* @param id
|
||||||
|
*/
|
||||||
|
public abstract ProtectedRegion getRegion(String id);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Removes a region, including inheriting children.
|
||||||
|
*
|
||||||
|
* @param id
|
||||||
|
*/
|
||||||
|
public abstract void removeRegion(String id);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get an object for a point for rules to be applied with.
|
||||||
|
*
|
||||||
|
* @param pt
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public abstract ApplicableRegionSet getApplicableRegions(Vector pt);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get a list of region IDs that contain a point.
|
||||||
|
*
|
||||||
|
* @param pt
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public abstract List<String> getApplicableRegionsIDs(Vector pt);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns true if the provided region overlaps with any other region that
|
||||||
|
* is not owned by the player.
|
||||||
|
*
|
||||||
|
* @param region
|
||||||
|
* @param player
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public abstract boolean overlapsUnownedRegion(ProtectedRegion region, LocalPlayer player);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the number of regions.
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public abstract int size();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the global flags.
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public void setGlobalFlags(GlobalFlags globalflags)
|
||||||
|
{
|
||||||
|
global = globalflags;
|
||||||
|
}
|
||||||
|
}
|
@ -1,145 +1,145 @@
|
|||||||
// $Id$
|
// $Id$
|
||||||
/*
|
/*
|
||||||
* WorldGuard
|
* WorldGuard
|
||||||
* Copyright (C) 2010 sk89q <http://www.sk89q.com>
|
* Copyright (C) 2010 sk89q <http://www.sk89q.com>
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify
|
* This program is free software: you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU General Public License as published by
|
* it under the terms of the GNU General Public License as published by
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
* (at your option) any later version.
|
* (at your option) any later version.
|
||||||
*
|
*
|
||||||
* This program is distributed in the hope that it will be useful,
|
* This program is distributed in the hope that it will be useful,
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
* GNU General Public License for more details.
|
* GNU General Public License for more details.
|
||||||
*
|
*
|
||||||
* You should have received a copy of the GNU General Public License
|
* You should have received a copy of the GNU General Public License
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package com.sk89q.worldguard.protection;
|
package com.sk89q.worldguard.protection.regions;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Holds the flags for a region.
|
* Holds the flags for a region.
|
||||||
*
|
*
|
||||||
* @author sk89q
|
* @author sk89q
|
||||||
*/
|
*/
|
||||||
public class AreaFlags {
|
public class AreaFlags {
|
||||||
public enum State {
|
public enum State {
|
||||||
NONE,
|
NONE,
|
||||||
ALLOW,
|
ALLOW,
|
||||||
DENY,
|
DENY,
|
||||||
};
|
};
|
||||||
|
|
||||||
public static final String FLAG_PASSTHROUGH = "z";
|
public static final String FLAG_PASSTHROUGH = "z";
|
||||||
public static final String FLAG_BUILD = "b";
|
public static final String FLAG_BUILD = "b";
|
||||||
public static final String FLAG_PVP = "p";
|
public static final String FLAG_PVP = "p";
|
||||||
public static final String FLAG_MOB_DAMAGE = "m";
|
public static final String FLAG_MOB_DAMAGE = "m";
|
||||||
public static final String FLAG_CREEPER_EXPLOSION = "c";
|
public static final String FLAG_CREEPER_EXPLOSION = "c";
|
||||||
public static final String FLAG_TNT = "t";
|
public static final String FLAG_TNT = "t";
|
||||||
public static final String FLAG_LIGHTER = "l";
|
public static final String FLAG_LIGHTER = "l";
|
||||||
public static final String FLAG_FIRE_SPREAD = "f";
|
public static final String FLAG_FIRE_SPREAD = "f";
|
||||||
public static final String FLAG_LAVA_FIRE = "F";
|
public static final String FLAG_LAVA_FIRE = "F";
|
||||||
public static final String FLAG_CHEST_ACCESS = "C";
|
public static final String FLAG_CHEST_ACCESS = "C";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the user-friendly name of a flag. If a name isn't known, then
|
* Get the user-friendly name of a flag. If a name isn't known, then
|
||||||
* the flag is returned unchanged.
|
* the flag is returned unchanged.
|
||||||
*
|
*
|
||||||
* @param flag
|
* @param flag
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public static String getFlagName(String flag) {
|
public static String getFlagName(String flag) {
|
||||||
if (flag.equals(FLAG_PASSTHROUGH)) {
|
if (flag.equals(FLAG_PASSTHROUGH)) {
|
||||||
return "passthrough";
|
return "passthrough";
|
||||||
} else if (flag.equals(FLAG_BUILD)) {
|
} else if (flag.equals(FLAG_BUILD)) {
|
||||||
return "build";
|
return "build";
|
||||||
} else if (flag.equals(FLAG_PVP)) {
|
} else if (flag.equals(FLAG_PVP)) {
|
||||||
return "PvP";
|
return "PvP";
|
||||||
} else if (flag.equals(FLAG_MOB_DAMAGE)) {
|
} else if (flag.equals(FLAG_MOB_DAMAGE)) {
|
||||||
return "mob damage";
|
return "mob damage";
|
||||||
} else if (flag.equals(FLAG_CREEPER_EXPLOSION)) {
|
} else if (flag.equals(FLAG_CREEPER_EXPLOSION)) {
|
||||||
return "creeper explosion";
|
return "creeper explosion";
|
||||||
} else if (flag.equals(FLAG_TNT)) {
|
} else if (flag.equals(FLAG_TNT)) {
|
||||||
return "TNT";
|
return "TNT";
|
||||||
} else if (flag.equals(FLAG_LIGHTER)) {
|
} else if (flag.equals(FLAG_LIGHTER)) {
|
||||||
return "lighter";
|
return "lighter";
|
||||||
} else if (flag.equals(FLAG_FIRE_SPREAD)) {
|
} else if (flag.equals(FLAG_FIRE_SPREAD)) {
|
||||||
return "fire spread";
|
return "fire spread";
|
||||||
} else if (flag.equals(FLAG_LAVA_FIRE)) {
|
} else if (flag.equals(FLAG_LAVA_FIRE)) {
|
||||||
return "lava fire spread";
|
return "lava fire spread";
|
||||||
} else if (flag.equals(FLAG_CHEST_ACCESS)) {
|
} else if (flag.equals(FLAG_CHEST_ACCESS)) {
|
||||||
return "chest access";
|
return "chest access";
|
||||||
} else {
|
} else {
|
||||||
return flag;
|
return flag;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets a flag from an alias. May return null.
|
* Gets a flag from an alias. May return null.
|
||||||
*
|
*
|
||||||
* @param name
|
* @param name
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public static String fromAlias(String name) {
|
public static String fromAlias(String name) {
|
||||||
if (name.equalsIgnoreCase("passthrough")) {
|
if (name.equalsIgnoreCase("passthrough")) {
|
||||||
return FLAG_PASSTHROUGH;
|
return FLAG_PASSTHROUGH;
|
||||||
} else if (name.equalsIgnoreCase("build")) {
|
} else if (name.equalsIgnoreCase("build")) {
|
||||||
return FLAG_BUILD;
|
return FLAG_BUILD;
|
||||||
} else if (name.equalsIgnoreCase("pvp")) {
|
} else if (name.equalsIgnoreCase("pvp")) {
|
||||||
return FLAG_PVP;
|
return FLAG_PVP;
|
||||||
} else if (name.equalsIgnoreCase("mobdamage")) {
|
} else if (name.equalsIgnoreCase("mobdamage")) {
|
||||||
return FLAG_MOB_DAMAGE;
|
return FLAG_MOB_DAMAGE;
|
||||||
} else if (name.equalsIgnoreCase("creeper")) {
|
} else if (name.equalsIgnoreCase("creeper")) {
|
||||||
return FLAG_CREEPER_EXPLOSION;
|
return FLAG_CREEPER_EXPLOSION;
|
||||||
} else if (name.equalsIgnoreCase("tnt")) {
|
} else if (name.equalsIgnoreCase("tnt")) {
|
||||||
return FLAG_TNT;
|
return FLAG_TNT;
|
||||||
} else if (name.equalsIgnoreCase("lighter")) {
|
} else if (name.equalsIgnoreCase("lighter")) {
|
||||||
return FLAG_LIGHTER;
|
return FLAG_LIGHTER;
|
||||||
} else if (name.equalsIgnoreCase("firespread")) {
|
} else if (name.equalsIgnoreCase("firespread")) {
|
||||||
return FLAG_FIRE_SPREAD;
|
return FLAG_FIRE_SPREAD;
|
||||||
} else if (name.equalsIgnoreCase("lavafirespread")) {
|
} else if (name.equalsIgnoreCase("lavafirespread")) {
|
||||||
return FLAG_LAVA_FIRE;
|
return FLAG_LAVA_FIRE;
|
||||||
} else if (name.equalsIgnoreCase("chest")) {
|
} else if (name.equalsIgnoreCase("chest")) {
|
||||||
return FLAG_CHEST_ACCESS;
|
return FLAG_CHEST_ACCESS;
|
||||||
} else {
|
} else {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private Map<String, State> states = new HashMap<String, State>();
|
private Map<String, State> states = new HashMap<String, State>();
|
||||||
|
|
||||||
public State get(String flag) {
|
public State get(String flag) {
|
||||||
State state = states.get(flag);
|
State state = states.get(flag);
|
||||||
if (state == null) {
|
if (state == null) {
|
||||||
return State.NONE;
|
return State.NONE;
|
||||||
}
|
}
|
||||||
return state;
|
return state;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void set(String flag, State state) {
|
public void set(String flag, State state) {
|
||||||
if (state == State.NONE) {
|
if (state == State.NONE) {
|
||||||
states.remove(flag);
|
states.remove(flag);
|
||||||
} else {
|
} else {
|
||||||
states.put(flag, state);
|
states.put(flag, state);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public Set<Map.Entry<String, State>> entrySet() {
|
public Set<Map.Entry<String, State>> entrySet() {
|
||||||
return states.entrySet();
|
return states.entrySet();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean equals(Object obj) {
|
public boolean equals(Object obj) {
|
||||||
if (!(obj instanceof AreaFlags)) {
|
if (!(obj instanceof AreaFlags)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
AreaFlags other = (AreaFlags)obj;
|
AreaFlags other = (AreaFlags)obj;
|
||||||
return other.states.equals(this);
|
return other.states.equals(this);
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -17,7 +17,7 @@
|
|||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package com.sk89q.worldguard.protection;
|
package com.sk89q.worldguard.protection.regions;
|
||||||
|
|
||||||
import com.sk89q.worldedit.*;
|
import com.sk89q.worldedit.*;
|
||||||
|
|
@ -1,132 +1,132 @@
|
|||||||
// $Id$
|
// $Id$
|
||||||
/*
|
/*
|
||||||
* WorldGuard
|
* WorldGuard
|
||||||
* Copyright (C) 2010 sk89q <http://www.sk89q.com>
|
* Copyright (C) 2010 sk89q <http://www.sk89q.com>
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify
|
* This program is free software: you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU General Public License as published by
|
* it under the terms of the GNU General Public License as published by
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
* (at your option) any later version.
|
* (at your option) any later version.
|
||||||
*
|
*
|
||||||
* This program is distributed in the hope that it will be useful,
|
* This program is distributed in the hope that it will be useful,
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
* GNU General Public License for more details.
|
* GNU General Public License for more details.
|
||||||
*
|
*
|
||||||
* You should have received a copy of the GNU General Public License
|
* You should have received a copy of the GNU General Public License
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package com.sk89q.worldguard.protection;
|
package com.sk89q.worldguard.protection.regions;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import com.sk89q.worldedit.BlockVector;
|
import com.sk89q.worldedit.BlockVector;
|
||||||
import com.sk89q.worldedit.BlockVector2D;
|
import com.sk89q.worldedit.BlockVector2D;
|
||||||
import com.sk89q.worldedit.Vector;
|
import com.sk89q.worldedit.Vector;
|
||||||
import com.sk89q.worldedit.Vector2D;
|
import com.sk89q.worldedit.Vector2D;
|
||||||
|
|
||||||
public class ProtectedPolygonalRegion extends ProtectedRegion {
|
public class ProtectedPolygonalRegion extends ProtectedRegion {
|
||||||
protected List<BlockVector2D> points;
|
protected List<BlockVector2D> points;
|
||||||
protected int minY;
|
protected int minY;
|
||||||
protected int maxY;
|
protected int maxY;
|
||||||
private BlockVector min;
|
private BlockVector min;
|
||||||
private BlockVector max;
|
private BlockVector max;
|
||||||
|
|
||||||
public ProtectedPolygonalRegion(String id, List<BlockVector2D> points, int minY, int maxY) {
|
public ProtectedPolygonalRegion(String id, List<BlockVector2D> points, int minY, int maxY) {
|
||||||
super(id);
|
super(id);
|
||||||
this.points = points;
|
this.points = points;
|
||||||
this.minY = minY;
|
this.minY = minY;
|
||||||
this.maxY = maxY;
|
this.maxY = maxY;
|
||||||
|
|
||||||
int minX = points.get(0).getBlockX();
|
int minX = points.get(0).getBlockX();
|
||||||
int minZ = points.get(0).getBlockZ();
|
int minZ = points.get(0).getBlockZ();
|
||||||
int maxX = points.get(0).getBlockX();
|
int maxX = points.get(0).getBlockX();
|
||||||
int maxZ = points.get(0).getBlockZ();
|
int maxZ = points.get(0).getBlockZ();
|
||||||
|
|
||||||
for (BlockVector2D v : points) {
|
for (BlockVector2D v : points) {
|
||||||
int x = v.getBlockX();
|
int x = v.getBlockX();
|
||||||
int z = v.getBlockZ();
|
int z = v.getBlockZ();
|
||||||
if (x < minX) minX = x;
|
if (x < minX) minX = x;
|
||||||
if (z < minZ) minZ = z;
|
if (z < minZ) minZ = z;
|
||||||
if (x > maxX) maxX = x;
|
if (x > maxX) maxX = x;
|
||||||
if (z > maxZ) maxZ = z;
|
if (z > maxZ) maxZ = z;
|
||||||
}
|
}
|
||||||
|
|
||||||
min = new BlockVector(minX, minY, minZ);
|
min = new BlockVector(minX, minY, minZ);
|
||||||
max = new BlockVector(maxX, maxY, maxZ);
|
max = new BlockVector(maxX, maxY, maxZ);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public BlockVector getMinimumPoint() {
|
public BlockVector getMinimumPoint() {
|
||||||
return min;
|
return min;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public BlockVector getMaximumPoint() {
|
public BlockVector getMaximumPoint() {
|
||||||
return max;
|
return max;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Checks to see if a point is inside this region.
|
* Checks to see if a point is inside this region.
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public boolean contains(Vector pt) {
|
public boolean contains(Vector pt) {
|
||||||
int targetX = pt.getBlockX(); //wide
|
int targetX = pt.getBlockX(); //wide
|
||||||
int targetY = pt.getBlockY(); //height
|
int targetY = pt.getBlockY(); //height
|
||||||
int targetZ = pt.getBlockZ(); //depth
|
int targetZ = pt.getBlockZ(); //depth
|
||||||
|
|
||||||
if (targetY < minY || targetY > maxY) {
|
if (targetY < minY || targetY > maxY) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
//Quick and dirty check.
|
//Quick and dirty check.
|
||||||
if(targetX < min.getBlockX() || targetX > max.getBlockX() || targetZ < min.getBlockZ() || targetZ > max.getBlockZ()){
|
if(targetX < min.getBlockX() || targetX > max.getBlockX() || targetZ < min.getBlockZ() || targetZ > max.getBlockZ()){
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
boolean inside = false;
|
boolean inside = false;
|
||||||
int npoints = points.size();
|
int npoints = points.size();
|
||||||
int xNew, zNew;
|
int xNew, zNew;
|
||||||
int xOld, zOld;
|
int xOld, zOld;
|
||||||
int x1, z1;
|
int x1, z1;
|
||||||
int x2, z2;
|
int x2, z2;
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
xOld = points.get(npoints - 1).getBlockX();
|
xOld = points.get(npoints - 1).getBlockX();
|
||||||
zOld = points.get(npoints - 1).getBlockZ();
|
zOld = points.get(npoints - 1).getBlockZ();
|
||||||
|
|
||||||
for (i = 0; i < npoints; i++) {
|
for (i = 0; i < npoints; i++) {
|
||||||
xNew = points.get(i).getBlockX();
|
xNew = points.get(i).getBlockX();
|
||||||
zNew = points.get(i).getBlockZ();
|
zNew = points.get(i).getBlockZ();
|
||||||
if (xNew > xOld) {
|
if (xNew > xOld) {
|
||||||
x1 = xOld;
|
x1 = xOld;
|
||||||
x2 = xNew;
|
x2 = xNew;
|
||||||
z1 = zOld;
|
z1 = zOld;
|
||||||
z2 = zNew;
|
z2 = zNew;
|
||||||
} else {
|
} else {
|
||||||
x1 = xNew;
|
x1 = xNew;
|
||||||
x2 = xOld;
|
x2 = xOld;
|
||||||
z1 = zNew;
|
z1 = zNew;
|
||||||
z2 = zOld;
|
z2 = zOld;
|
||||||
}
|
}
|
||||||
if ((xNew < targetX) == (targetX <= xOld)
|
if ((xNew < targetX) == (targetX <= xOld)
|
||||||
&& ((long) targetZ - (long) z1) * (long) (x2 - x1) <= ((long) z2 - (long) z1)
|
&& ((long) targetZ - (long) z1) * (long) (x2 - x1) <= ((long) z2 - (long) z1)
|
||||||
* (long) (targetX - x1)) {
|
* (long) (targetX - x1)) {
|
||||||
inside = !inside;
|
inside = !inside;
|
||||||
}
|
}
|
||||||
xOld = xNew;
|
xOld = xNew;
|
||||||
zOld = zNew;
|
zOld = zNew;
|
||||||
}
|
}
|
||||||
|
|
||||||
return inside;
|
return inside;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return the type of region as a user-friendly name.
|
* Return the type of region as a user-friendly name.
|
||||||
*
|
*
|
||||||
* @return type of region
|
* @return type of region
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public String getTypeName() {
|
public String getTypeName() {
|
||||||
return "polygon";
|
return "polygon";
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
@ -1,334 +1,361 @@
|
|||||||
// $Id$
|
// $Id$
|
||||||
/*
|
/*
|
||||||
* WorldGuard
|
* WorldGuard
|
||||||
* Copyright (C) 2010 sk89q <http://www.sk89q.com>
|
* Copyright (C) 2010 sk89q <http://www.sk89q.com>
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify
|
* This program is free software: you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU General Public License as published by
|
* it under the terms of the GNU General Public License as published by
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
* (at your option) any later version.
|
* (at your option) any later version.
|
||||||
*
|
*
|
||||||
* This program is distributed in the hope that it will be useful,
|
* This program is distributed in the hope that it will be useful,
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
* GNU General Public License for more details.
|
* GNU General Public License for more details.
|
||||||
*
|
*
|
||||||
* You should have received a copy of the GNU General Public License
|
* You should have received a copy of the GNU General Public License
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package com.sk89q.worldguard.protection;
|
package com.sk89q.worldguard.protection.regions;
|
||||||
|
|
||||||
import com.sk89q.worldedit.BlockVector;
|
import com.sk89q.worldedit.BlockVector;
|
||||||
import com.sk89q.worldedit.Vector;
|
import com.sk89q.worldedit.Vector;
|
||||||
import com.sk89q.worldguard.LocalPlayer;
|
import com.sk89q.worldguard.LocalPlayer;
|
||||||
import com.sk89q.worldguard.domains.DefaultDomain;
|
import com.sk89q.worldguard.domains.DefaultDomain;
|
||||||
|
import com.sk89q.worldguard.protection.UnsupportedIntersectionException;
|
||||||
/**
|
|
||||||
* Represents a region of any shape and size that can be protected.
|
/**
|
||||||
*
|
* Represents a region of any shape and size that can be protected.
|
||||||
* @author sk89q
|
*
|
||||||
*/
|
* @author sk89q
|
||||||
public abstract class ProtectedRegion implements Comparable<ProtectedRegion> {
|
*/
|
||||||
/**
|
public abstract class ProtectedRegion implements Comparable<ProtectedRegion> {
|
||||||
* Holds the region's ID.
|
/**
|
||||||
*/
|
* Holds the region's ID.
|
||||||
private String id;
|
*/
|
||||||
/**
|
private String id;
|
||||||
* Priority.
|
/**
|
||||||
*/
|
* Priority.
|
||||||
private int priority = 0;
|
*/
|
||||||
/**
|
private int priority = 0;
|
||||||
* Parent region.
|
/**
|
||||||
*/
|
* Holds the parent.
|
||||||
private ProtectedRegion parent;
|
*/
|
||||||
/**
|
private transient ProtectedRegion parent;
|
||||||
* List of owners.
|
/**
|
||||||
*/
|
* Holds the parent's Id. Used for serialization, don't touch it.
|
||||||
private DefaultDomain owners = new DefaultDomain();
|
*/
|
||||||
/**
|
private String parentId;
|
||||||
* List of members.
|
/**
|
||||||
*/
|
* List of owners.
|
||||||
private DefaultDomain members = new DefaultDomain();
|
*/
|
||||||
/**
|
private DefaultDomain owners = new DefaultDomain();
|
||||||
* Area flags.
|
/**
|
||||||
*/
|
* List of members.
|
||||||
private AreaFlags flags = new AreaFlags();
|
*/
|
||||||
/**
|
private DefaultDomain members = new DefaultDomain();
|
||||||
* Area message.
|
/**
|
||||||
*/
|
* Area flags.
|
||||||
private String enterMessage;
|
*/
|
||||||
/**
|
private AreaFlags flags = new AreaFlags();
|
||||||
* Area message.
|
/**
|
||||||
*/
|
* Area message.
|
||||||
private String leaveMessage;
|
*/
|
||||||
|
private String enterMessage;
|
||||||
/**
|
/**
|
||||||
* Construct a new instance of this region.
|
* Area message.
|
||||||
*
|
*/
|
||||||
* @param id
|
private String leaveMessage;
|
||||||
*/
|
|
||||||
public ProtectedRegion(String id) {
|
/**
|
||||||
this.id = id;
|
* Construct a new instance of this region.
|
||||||
}
|
*
|
||||||
|
* @param id
|
||||||
/**
|
*/
|
||||||
* @return the id
|
public ProtectedRegion(String id) {
|
||||||
*/
|
this.id = id;
|
||||||
public String getId() {
|
}
|
||||||
return id;
|
|
||||||
}
|
/**
|
||||||
|
* @return the id
|
||||||
/**
|
*/
|
||||||
* Get the lower point of the cuboid.
|
public String getId() {
|
||||||
*
|
return id;
|
||||||
* @return min point
|
}
|
||||||
*/
|
|
||||||
public abstract BlockVector getMinimumPoint();
|
/**
|
||||||
|
* @return the parentId.
|
||||||
/**
|
*/
|
||||||
* Get the upper point of the cuboid.
|
public String getParentId() {
|
||||||
*
|
this.setParentId();
|
||||||
* @return max point
|
return parentId;
|
||||||
*/
|
}
|
||||||
public abstract BlockVector getMaximumPoint();
|
|
||||||
|
/**
|
||||||
/**
|
* @set the parentId. Used for serialization, don't touch it.
|
||||||
* @return the priority
|
*/
|
||||||
*/
|
public void setParentId() {
|
||||||
public int getPriority() {
|
|
||||||
return priority;
|
if (this.parent != null) {
|
||||||
}
|
this.parentId = parent.getId();
|
||||||
|
} else {
|
||||||
/**
|
this.parentId = null;
|
||||||
* @param priority the priority to set
|
}
|
||||||
*/
|
}
|
||||||
public void setPriority(int priority) {
|
|
||||||
this.priority = priority;
|
/**
|
||||||
}
|
* Get the lower point of the cuboid.
|
||||||
|
*
|
||||||
/**
|
* @return min point
|
||||||
* @return the parent
|
*/
|
||||||
*/
|
public abstract BlockVector getMinimumPoint();
|
||||||
public ProtectedRegion getParent() {
|
|
||||||
return parent;
|
/**
|
||||||
}
|
* Get the upper point of the cuboid.
|
||||||
|
*
|
||||||
/**
|
* @return max point
|
||||||
* Set the parent. This checks to make sure that it will not result
|
*/
|
||||||
* in circular inheritance.
|
public abstract BlockVector getMaximumPoint();
|
||||||
*
|
|
||||||
* @param parent the parent to set
|
/**
|
||||||
* @throws CircularInheritanceException
|
* @return the priority
|
||||||
*/
|
*/
|
||||||
public void setParent(ProtectedRegion parent) throws CircularInheritanceException {
|
public int getPriority() {
|
||||||
if (parent == null) {
|
return priority;
|
||||||
this.parent = null;
|
}
|
||||||
return;
|
|
||||||
}
|
/**
|
||||||
|
* @param priority the priority to set
|
||||||
if (parent == this) {
|
*/
|
||||||
throw new CircularInheritanceException();
|
public void setPriority(int priority) {
|
||||||
}
|
this.priority = priority;
|
||||||
|
}
|
||||||
ProtectedRegion p = parent.getParent();
|
|
||||||
while (p != null) {
|
/**
|
||||||
if (p == this) {
|
* @return the parent
|
||||||
throw new CircularInheritanceException();
|
*/
|
||||||
}
|
public ProtectedRegion getParent() {
|
||||||
p = p.getParent();
|
return parent;
|
||||||
}
|
}
|
||||||
|
|
||||||
this.parent = parent;
|
/**
|
||||||
}
|
* Set the parent. This checks to make sure that it will not result
|
||||||
|
* in circular inheritance.
|
||||||
/**
|
*
|
||||||
* Se flags.
|
* @param parent the parent to set
|
||||||
* @param flags
|
* @throws CircularInheritanceException
|
||||||
*/
|
*/
|
||||||
public void setFlags(AreaFlags flags) {
|
public void setParent(ProtectedRegion parent) throws CircularInheritanceException {
|
||||||
this.flags = flags;
|
if (parent == null) {
|
||||||
}
|
this.parent = null;
|
||||||
|
return;
|
||||||
/**
|
}
|
||||||
* @return the enterMessage
|
|
||||||
*/
|
if (parent == this) {
|
||||||
public String getEnterMessage() {
|
throw new CircularInheritanceException();
|
||||||
return enterMessage;
|
}
|
||||||
}
|
|
||||||
|
ProtectedRegion p = parent.getParent();
|
||||||
/**
|
while (p != null) {
|
||||||
* @param enterMessage the enterMessage to set
|
if (p == this) {
|
||||||
*/
|
throw new CircularInheritanceException();
|
||||||
public void setEnterMessage(String enterMessage) {
|
}
|
||||||
this.enterMessage = enterMessage;
|
p = p.getParent();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
this.parent = parent;
|
||||||
* @return the leaveMessage
|
}
|
||||||
*/
|
|
||||||
public String getLeaveMessage() {
|
/**
|
||||||
return leaveMessage;
|
* Se flags.
|
||||||
}
|
* @param flags
|
||||||
|
*/
|
||||||
/**
|
public void setFlags(AreaFlags flags) {
|
||||||
* @param leaveMessage the leaveMessage to set
|
this.flags = flags;
|
||||||
*/
|
}
|
||||||
public void setLeaveMessage(String leaveMessage) {
|
|
||||||
this.leaveMessage = leaveMessage;
|
/**
|
||||||
}
|
* @return the enterMessage
|
||||||
|
*/
|
||||||
/**
|
public String getEnterMessage() {
|
||||||
* @return the owners
|
return enterMessage;
|
||||||
*/
|
}
|
||||||
public DefaultDomain getOwners() {
|
|
||||||
return owners;
|
/**
|
||||||
}
|
* @param enterMessage the enterMessage to set
|
||||||
|
*/
|
||||||
/**
|
public void setEnterMessage(String enterMessage) {
|
||||||
* @param owners the owners to set
|
this.enterMessage = enterMessage;
|
||||||
*/
|
}
|
||||||
public void setOwners(DefaultDomain owners) {
|
|
||||||
this.owners = owners;
|
/**
|
||||||
}
|
* @return the leaveMessage
|
||||||
|
*/
|
||||||
/**
|
public String getLeaveMessage() {
|
||||||
* @return the members
|
return leaveMessage;
|
||||||
*/
|
}
|
||||||
public DefaultDomain getMembers() {
|
|
||||||
return members;
|
/**
|
||||||
}
|
* @param leaveMessage the leaveMessage to set
|
||||||
|
*/
|
||||||
/**
|
public void setLeaveMessage(String leaveMessage) {
|
||||||
* @param owners the owners to set
|
this.leaveMessage = leaveMessage;
|
||||||
*/
|
}
|
||||||
public void setMembers(DefaultDomain members) {
|
|
||||||
this.members = members;
|
/**
|
||||||
}
|
* @return the owners
|
||||||
|
*/
|
||||||
/**
|
public DefaultDomain getOwners() {
|
||||||
* Checks whether a player is an owner of region or any of its parents.
|
|
||||||
*
|
return owners;
|
||||||
* @param player
|
}
|
||||||
* @return
|
|
||||||
*/
|
/**
|
||||||
public boolean isOwner(LocalPlayer player) {
|
* @param owners the owners to set
|
||||||
if (owners.contains(player)) {
|
*/
|
||||||
return true;
|
public void setOwners(DefaultDomain owners) {
|
||||||
}
|
this.owners = owners;
|
||||||
|
}
|
||||||
ProtectedRegion parent = getParent();
|
|
||||||
while (parent != null) {
|
/**
|
||||||
if (parent.getOwners().contains(player)) {
|
* @return the members
|
||||||
return true;
|
*/
|
||||||
}
|
public DefaultDomain getMembers() {
|
||||||
|
|
||||||
parent = parent.getParent();
|
return members;
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
/**
|
||||||
}
|
* @param owners the owners to set
|
||||||
|
*/
|
||||||
/**
|
public void setMembers(DefaultDomain members) {
|
||||||
* Checks whether a player is a member of the region or any of its parents.
|
this.members = members;
|
||||||
*
|
}
|
||||||
* @param player
|
|
||||||
* @return
|
/**
|
||||||
*/
|
* Checks whether a player is an owner of region or any of its parents.
|
||||||
public boolean isMember(LocalPlayer player) {
|
*
|
||||||
if (owners.contains(player) || members.contains(player)) {
|
* @param player
|
||||||
return true;
|
* @return
|
||||||
}
|
*/
|
||||||
|
public boolean isOwner(LocalPlayer player) {
|
||||||
ProtectedRegion parent = getParent();
|
if (owners.contains(player)) {
|
||||||
while (parent != null) {
|
return true;
|
||||||
if (parent.getOwners().contains(player)
|
}
|
||||||
|| parent.getMembers().contains(player)) {
|
|
||||||
return true;
|
ProtectedRegion parent = getParent();
|
||||||
}
|
while (parent != null) {
|
||||||
|
if (parent.getOwners().contains(player)) {
|
||||||
parent = parent.getParent();
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
parent = parent.getParent();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
return false;
|
||||||
* Get flags.
|
}
|
||||||
*
|
|
||||||
* @return
|
/**
|
||||||
*/
|
* Checks whether a player is a member of the region or any of its parents.
|
||||||
public AreaFlags getFlags() {
|
*
|
||||||
return flags;
|
* @param player
|
||||||
}
|
* @return
|
||||||
|
*/
|
||||||
/**
|
public boolean isMember(LocalPlayer player) {
|
||||||
* Check to see if a point is inside this region.
|
if (owners.contains(player) || members.contains(player)) {
|
||||||
*
|
return true;
|
||||||
* @param pt
|
}
|
||||||
* @return
|
|
||||||
*/
|
ProtectedRegion parent = getParent();
|
||||||
public abstract boolean contains(Vector pt);
|
while (parent != null) {
|
||||||
|
if (parent.getOwners().contains(player)
|
||||||
/**
|
|| parent.getMembers().contains(player)) {
|
||||||
* Compares to another region.
|
return true;
|
||||||
*
|
}
|
||||||
* @param other
|
|
||||||
* @return
|
parent = parent.getParent();
|
||||||
*/
|
}
|
||||||
public int compareTo(ProtectedRegion other) {
|
|
||||||
if (priority == other.priority) {
|
return false;
|
||||||
return 0;
|
}
|
||||||
} else if (priority > other.priority) {
|
|
||||||
return -1;
|
/**
|
||||||
} else {
|
* Get flags.
|
||||||
return 1;
|
*
|
||||||
}
|
* @return
|
||||||
}
|
*/
|
||||||
|
public AreaFlags getFlags() {
|
||||||
/**
|
return flags;
|
||||||
* Return the type of region as a user-friendly, lowercase name.
|
}
|
||||||
*
|
|
||||||
* @return type of region
|
/**
|
||||||
*/
|
* Check to see if a point is inside this region.
|
||||||
public abstract String getTypeName();
|
*
|
||||||
|
* @param pt
|
||||||
/**
|
* @return
|
||||||
* Checks if two region intersects.
|
*/
|
||||||
*
|
public abstract boolean contains(Vector pt);
|
||||||
* @param region1
|
|
||||||
* @param region2
|
/**
|
||||||
* @throws UnsupportedIntersectionException
|
* Compares to another region.
|
||||||
* @return
|
*
|
||||||
*/
|
* @param other
|
||||||
public static boolean intersects(ProtectedRegion region1, ProtectedRegion region2)
|
* @return
|
||||||
throws UnsupportedIntersectionException {
|
*/
|
||||||
if (region1 instanceof ProtectedCuboidRegion
|
public int compareTo(ProtectedRegion other) {
|
||||||
&& region2 instanceof ProtectedCuboidRegion) {
|
if (priority == other.priority) {
|
||||||
ProtectedCuboidRegion r1 = (ProtectedCuboidRegion)region1;
|
return 0;
|
||||||
ProtectedCuboidRegion r2 = (ProtectedCuboidRegion)region2;
|
} else if (priority > other.priority) {
|
||||||
BlockVector min1 = r1.getMinimumPoint();
|
return -1;
|
||||||
BlockVector max1 = r1.getMaximumPoint();
|
} else {
|
||||||
BlockVector min2 = r2.getMinimumPoint();
|
return 1;
|
||||||
BlockVector max2 = r2.getMaximumPoint();
|
}
|
||||||
|
}
|
||||||
return !(min1.getBlockX() > max2.getBlockX()
|
|
||||||
|| min1.getBlockY() > max2.getBlockY()
|
/**
|
||||||
|| min1.getBlockZ() > max2.getBlockZ()
|
* Return the type of region as a user-friendly, lowercase name.
|
||||||
|| max1.getBlockX() < min2.getBlockX()
|
*
|
||||||
|| max1.getBlockY() < min2.getBlockY()
|
* @return type of region
|
||||||
|| max1.getBlockZ() < min2.getBlockZ());
|
*/
|
||||||
} else {
|
public abstract String getTypeName();
|
||||||
throw new UnsupportedIntersectionException();
|
|
||||||
}
|
/**
|
||||||
}
|
* Checks if two region intersects.
|
||||||
|
*
|
||||||
/**
|
* @param region1
|
||||||
* Thrown when setting a parent would create a circular inheritance
|
* @param region2
|
||||||
* situation.
|
* @throws UnsupportedIntersectionException
|
||||||
*
|
* @return
|
||||||
*/
|
*/
|
||||||
public static class CircularInheritanceException extends Exception {
|
public static boolean intersects(ProtectedRegion region1, ProtectedRegion region2)
|
||||||
private static final long serialVersionUID = 7479613488496776022L;
|
throws UnsupportedIntersectionException {
|
||||||
}
|
if (region1 instanceof ProtectedCuboidRegion
|
||||||
}
|
&& region2 instanceof ProtectedCuboidRegion) {
|
||||||
|
ProtectedCuboidRegion r1 = (ProtectedCuboidRegion)region1;
|
||||||
|
ProtectedCuboidRegion r2 = (ProtectedCuboidRegion)region2;
|
||||||
|
BlockVector min1 = r1.getMinimumPoint();
|
||||||
|
BlockVector max1 = r1.getMaximumPoint();
|
||||||
|
BlockVector min2 = r2.getMinimumPoint();
|
||||||
|
BlockVector max2 = r2.getMaximumPoint();
|
||||||
|
|
||||||
|
return !(min1.getBlockX() > max2.getBlockX()
|
||||||
|
|| min1.getBlockY() > max2.getBlockY()
|
||||||
|
|| min1.getBlockZ() > max2.getBlockZ()
|
||||||
|
|| max1.getBlockX() < min2.getBlockX()
|
||||||
|
|| max1.getBlockY() < min2.getBlockY()
|
||||||
|
|| max1.getBlockZ() < min2.getBlockZ());
|
||||||
|
} else {
|
||||||
|
throw new UnsupportedIntersectionException();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Thrown when setting a parent would create a circular inheritance
|
||||||
|
* situation.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public static class CircularInheritanceException extends Exception {
|
||||||
|
private static final long serialVersionUID = 7479613488496776022L;
|
||||||
|
}
|
||||||
|
}
|
@ -1,41 +1,42 @@
|
|||||||
// $Id$
|
// $Id$
|
||||||
/*
|
/*
|
||||||
* WorldGuard
|
* WorldGuard
|
||||||
* Copyright (C) 2010 sk89q <http://www.sk89q.com>
|
* Copyright (C) 2010 sk89q <http://www.sk89q.com>
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify
|
* This program is free software: you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU General Public License as published by
|
* it under the terms of the GNU General Public License as published by
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
* (at your option) any later version.
|
* (at your option) any later version.
|
||||||
*
|
*
|
||||||
* This program is distributed in the hope that it will be useful,
|
* This program is distributed in the hope that it will be useful,
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
* GNU General Public License for more details.
|
* GNU General Public License for more details.
|
||||||
*
|
*
|
||||||
* You should have received a copy of the GNU General Public License
|
* You should have received a copy of the GNU General Public License
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package com.sk89q.worldguard.protection;
|
package com.sk89q.worldguard.protection.regions;
|
||||||
|
|
||||||
import org.khelekore.prtree.MBRConverter;
|
import com.sk89q.worldguard.protection.regions.ProtectedRegion;
|
||||||
|
import org.khelekore.prtree.MBRConverter;
|
||||||
public class ProtectedRegionMBRConverter implements MBRConverter<ProtectedRegion> {
|
|
||||||
public double getMinX(ProtectedRegion t) {
|
public class ProtectedRegionMBRConverter implements MBRConverter<ProtectedRegion> {
|
||||||
return t.getMinimumPoint().getBlockX();
|
public double getMinX(ProtectedRegion t) {
|
||||||
}
|
return t.getMinimumPoint().getBlockX();
|
||||||
|
}
|
||||||
public double getMinY(ProtectedRegion t) {
|
|
||||||
return t.getMinimumPoint().getBlockZ();
|
public double getMinY(ProtectedRegion t) {
|
||||||
}
|
return t.getMinimumPoint().getBlockZ();
|
||||||
|
}
|
||||||
public double getMaxX(ProtectedRegion t) {
|
|
||||||
return t.getMaximumPoint().getBlockX();
|
public double getMaxX(ProtectedRegion t) {
|
||||||
}
|
return t.getMaximumPoint().getBlockX();
|
||||||
|
}
|
||||||
public double getMaxY(ProtectedRegion t) {
|
|
||||||
return t.getMaximumPoint().getBlockZ();
|
public double getMaxY(ProtectedRegion t) {
|
||||||
}
|
return t.getMaximumPoint().getBlockZ();
|
||||||
|
}
|
||||||
}
|
|
||||||
|
}
|
@ -19,6 +19,11 @@
|
|||||||
|
|
||||||
package com.sk89q.worldguard.protection;
|
package com.sk89q.worldguard.protection;
|
||||||
|
|
||||||
|
import com.sk89q.worldguard.protection.regions.ProtectedRegion;
|
||||||
|
import com.sk89q.worldguard.protection.regions.ProtectedPolygonalRegion;
|
||||||
|
import com.sk89q.worldguard.protection.regions.ProtectedCuboidRegion;
|
||||||
|
import com.sk89q.worldguard.protection.regionmanager.RegionManager;
|
||||||
|
import com.sk89q.worldguard.protection.regionmanager.FlatRegionManager;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import static org.junit.Assert.*;
|
import static org.junit.Assert.*;
|
||||||
@ -27,7 +32,8 @@
|
|||||||
import com.sk89q.worldedit.Vector;
|
import com.sk89q.worldedit.Vector;
|
||||||
import com.sk89q.worldguard.TestPlayer;
|
import com.sk89q.worldguard.TestPlayer;
|
||||||
import com.sk89q.worldguard.domains.DefaultDomain;
|
import com.sk89q.worldguard.domains.DefaultDomain;
|
||||||
import com.sk89q.worldguard.protection.AreaFlags.State;
|
import com.sk89q.worldguard.protection.regions.AreaFlags;
|
||||||
|
import com.sk89q.worldguard.protection.regions.AreaFlags.State;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@ -50,7 +56,7 @@ public class ApplicableRegionSetTest {
|
|||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void setUp() throws Exception {
|
public void setUp() throws Exception {
|
||||||
manager = new FlatRegionManager(new GlobalFlags());
|
manager = new FlatRegionManager(new GlobalFlags(), null);
|
||||||
|
|
||||||
setUpPlayers();
|
setUpPlayers();
|
||||||
setUpCourtyardRegion();
|
setUpCourtyardRegion();
|
||||||
|
@ -19,6 +19,9 @@
|
|||||||
|
|
||||||
package com.sk89q.worldguard.protection;
|
package com.sk89q.worldguard.protection;
|
||||||
|
|
||||||
|
import com.sk89q.worldguard.protection.dbs.CSVDatabase;
|
||||||
|
import com.sk89q.worldguard.protection.regions.ProtectedRegion;
|
||||||
|
import com.sk89q.worldguard.protection.regions.ProtectedCuboidRegion;
|
||||||
import java.io.*;
|
import java.io.*;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
@ -28,7 +31,8 @@
|
|||||||
import static org.junit.Assert.*;
|
import static org.junit.Assert.*;
|
||||||
import com.sk89q.worldedit.BlockVector;
|
import com.sk89q.worldedit.BlockVector;
|
||||||
import com.sk89q.worldguard.domains.DefaultDomain;
|
import com.sk89q.worldguard.domains.DefaultDomain;
|
||||||
import com.sk89q.worldguard.protection.AreaFlags.State;
|
import com.sk89q.worldguard.protection.regions.AreaFlags;
|
||||||
|
import com.sk89q.worldguard.protection.regions.AreaFlags.State;
|
||||||
|
|
||||||
public class CSVDatabaseTest {
|
public class CSVDatabaseTest {
|
||||||
@Before
|
@Before
|
||||||
|
Loading…
Reference in New Issue
Block a user