Cleaned up code. The configuration classes were also renamed as they did much more than just configuration.

This commit is contained in:
sk89q 2011-05-20 08:35:37 -07:00
parent 8de6ce9868
commit c75d612541
14 changed files with 475 additions and 383 deletions

View File

@ -22,7 +22,9 @@
import java.util.List;
import org.bukkit.block.Block;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.Server;
import org.bukkit.World;
import com.sk89q.worldedit.BlockVector;
@ -34,18 +36,54 @@ public class BukkitUtil {
private BukkitUtil() {
}
/**
* Converts the location of a Bukkit block to a WorldEdit vector.
*
* @param block
* @return
*/
public static BlockVector toVector(Block block) {
return new BlockVector(block.getX(), block.getY(), block.getZ());
}
/**
* Converts a Bukkit location to a WorldEdit vector.
*
* @param loc
* @return
*/
public static Vector toVector(Location loc) {
return new Vector(loc.getX(), loc.getY(), loc.getZ());
}
/**
* Converts a Bukkit vector to a WorldEdit vector.
*
* @param vector
* @return
*/
public static Vector toVector(org.bukkit.util.Vector vector) {
return new Vector(vector.getX(), vector.getY(), vector.getZ());
}
/**
* Converts a WorldEdit vector to a Bukkit location.
*
* @param world
* @param vec
* @return
*/
public static Location toLocation(World world, Vector vec) {
return new Location(world, vec.getX(), vec.getY(), vec.getZ());
}
/**
* Matches one player based on name.
*
* @param server
* @param name
* @return
*/
public static Player matchSinglePlayer(Server server, String name) {
List<Player> players = server.matchPlayer(name);
if (players.size() == 0) {
@ -54,8 +92,51 @@ public static Player matchSinglePlayer(Server server, String name) {
return players.get(0);
}
public static Location toLocation(World world, Vector vec) {
return new Location(world, vec.getX(), vec.getY(), vec.getZ());
/**
* Drops a sign item and removes a sign.
*
* @param block
*/
public static void dropSign(Block block) {
block.setTypeId(0);
block.getWorld().dropItemNaturally(block.getLocation(),
new ItemStack(Material.SIGN));
}
/**
* Sets the given block to fluid water.
* Used by addSpongeWater()
*
* @param world
* @param ox
* @param oy
* @param oz
*/
public static void setBlockToWater(World world, int ox, int oy, int oz) {
Block block = world.getBlockAt(ox, oy, oz);
int id = block.getTypeId();
if (id == 0) {
block.setTypeId(8);
}
}
/**
* Checks if the given block is water
*
* @param world
* @param ox
* @param oy
* @param oz
* @return
*/
public static boolean isBlockWater(World world, int ox, int oy, int oz) {
Block block = world.getBlockAt(ox, oy, oz);
int id = block.getTypeId();
if (id == 8 || id == 9) {
return true;
} else {
return false;
}
}
}

View File

@ -36,7 +36,7 @@
* @author sk89q
* @author Michael
*/
public class ConfigurationManager {
public class GlobalStateManager {
/**
* Reference to the plugin.
@ -46,7 +46,7 @@ public class ConfigurationManager {
/**
* Holds configurations for different worlds.
*/
private Map<String, WorldConfiguration> worlds;
private Map<String, WorldStateManager> worlds;
/**
* List of people with god mode.
@ -65,9 +65,9 @@ public class ConfigurationManager {
*
* @param plugin
*/
public ConfigurationManager(WorldGuardPlugin plugin) {
public GlobalStateManager(WorldGuardPlugin plugin) {
this.plugin = plugin;
this.worlds = new HashMap<String, WorldConfiguration>();
this.worlds = new HashMap<String, WorldStateManager>();
}
/**
@ -103,12 +103,12 @@ public void unload() {
* @param world
* @return
*/
public WorldConfiguration get(World world) {
public WorldStateManager get(World world) {
String worldName = world.getName();
WorldConfiguration config = worlds.get(worldName);
WorldStateManager config = worlds.get(worldName);
if (config == null) {
config = new WorldConfiguration(plugin, worldName);
config = new WorldStateManager(plugin, worldName);
worlds.put(worldName, config);
}
@ -121,7 +121,7 @@ public WorldConfiguration get(World world) {
* @param player
*/
public void forgetPlayer(LocalPlayer player) {
for (Map.Entry<String, WorldConfiguration> entry
for (Map.Entry<String, WorldStateManager> entry
: worlds.entrySet()) {
// The blacklist needs to forget players

View File

@ -111,13 +111,13 @@ private void appendReportHeader(WorldGuardPlugin plugin) {
appendln();
}
private void appendGlobalConfiguration(ConfigurationManager config) {
private void appendGlobalConfiguration(GlobalStateManager config) {
appendHeader("Global Configuration");
LogListBlock log = new LogListBlock();
LogListBlock configLog = log.putChild("Configuration");
Class<? extends ConfigurationManager> cls = config.getClass();
Class<? extends GlobalStateManager> cls = config.getClass();
for (Field field : cls.getFields()) {
try {
Object val = field.get(config);
@ -241,7 +241,7 @@ private void appendWorldInformation(List<World> worlds) {
}
private void appendWorldConfigurations(WorldGuardPlugin plugin, List<World> worlds,
GlobalRegionManager regionMgr, ConfigurationManager mgr) {
GlobalRegionManager regionMgr, GlobalStateManager mgr) {
appendHeader("World Configurations");
LogListBlock log = new LogListBlock();
@ -262,9 +262,9 @@ private void appendWorldConfigurations(WorldGuardPlugin plugin, List<World> worl
infoLog.put("Regions file", (new File(plugin.getDataFolder(), "worlds/"
+ world.getName() + "/regions.yml")).getAbsoluteFile());
WorldConfiguration config = mgr.get(world);
WorldStateManager config = mgr.get(world);
Class<? extends WorldConfiguration> cls = config.getClass();
Class<? extends WorldStateManager> cls = config.getClass();
for (Field field : cls.getFields()) {
try {
Object val = field.get(config);

View File

@ -0,0 +1,124 @@
// $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.bukkit;
import static com.sk89q.worldguard.bukkit.BukkitUtil.*;
import org.bukkit.World;
public class SpongeUtil {
/**
* Remove water around a sponge.
*
* @param plugin
* @param world
* @param ox
* @param oy
* @param oz
*/
public static void clearSpongeWater(WorldGuardPlugin plugin, World world, int ox, int oy, int oz) {
GlobalStateManager cfg = plugin.getGlobalConfiguration();
WorldStateManager wcfg = cfg.get(world);
for (int cx = -wcfg.spongeRadius; cx <= wcfg.spongeRadius; cx++) {
for (int cy = -wcfg.spongeRadius; cy <= wcfg.spongeRadius; cy++) {
for (int cz = -wcfg.spongeRadius; cz <= wcfg.spongeRadius; cz++) {
if (isBlockWater(world, ox + cx, oy + cy, oz + cz)) {
world.getBlockAt(ox + cx, oy + cy, oz + cz).setTypeId(0);
}
}
}
}
}
/**
* Add water around a sponge.
*
* @param plugin
* @param world
* @param ox
* @param oy
* @param oz
*/
public static void addSpongeWater(WorldGuardPlugin plugin, World world, int ox, int oy, int oz) {
GlobalStateManager cfg = plugin.getGlobalConfiguration();
WorldStateManager wcfg = cfg.get(world);
// The negative x edge
int cx = ox - wcfg.spongeRadius - 1;
for (int cy = oy - wcfg.spongeRadius - 1; cy <= oy + wcfg.spongeRadius + 1; cy++) {
for (int cz = oz - wcfg.spongeRadius - 1; cz <= oz + wcfg.spongeRadius + 1; cz++) {
if (isBlockWater(world, cx, cy, cz)) {
setBlockToWater(world, cx + 1, cy, cz);
}
}
}
// The positive x edge
cx = ox + wcfg.spongeRadius + 1;
for (int cy = oy - wcfg.spongeRadius - 1; cy <= oy + wcfg.spongeRadius + 1; cy++) {
for (int cz = oz - wcfg.spongeRadius - 1; cz <= oz + wcfg.spongeRadius + 1; cz++) {
if (isBlockWater(world, cx, cy, cz)) {
setBlockToWater(world, cx - 1, cy, cz);
}
}
}
// The negative y edge
int cy = oy - wcfg.spongeRadius - 1;
for (cx = ox - wcfg.spongeRadius - 1; cx <= ox + wcfg.spongeRadius + 1; cx++) {
for (int cz = oz - wcfg.spongeRadius - 1; cz <= oz + wcfg.spongeRadius + 1; cz++) {
if (isBlockWater(world, cx, cy, cz)) {
setBlockToWater(world, cx, cy + 1, cz);
}
}
}
// The positive y edge
cy = oy + wcfg.spongeRadius + 1;
for (cx = ox - wcfg.spongeRadius - 1; cx <= ox + wcfg.spongeRadius + 1; cx++) {
for (int cz = oz - wcfg.spongeRadius - 1; cz <= oz + wcfg.spongeRadius + 1; cz++) {
if (isBlockWater(world, cx, cy, cz)) {
setBlockToWater(world, cx, cy - 1, cz);
}
}
}
// The negative z edge
int cz = oz - wcfg.spongeRadius - 1;
for (cx = ox - wcfg.spongeRadius - 1; cx <= ox + wcfg.spongeRadius + 1; cx++) {
for (cy = oy - wcfg.spongeRadius - 1; cy <= oy + wcfg.spongeRadius + 1; cy++) {
if (isBlockWater(world, cx, cy, cz)) {
setBlockToWater(world, cx, cy, cz + 1);
}
}
}
// The positive z edge
cz = oz + wcfg.spongeRadius + 1;
for (cx = ox - wcfg.spongeRadius - 1; cx <= ox + wcfg.spongeRadius + 1; cx++) {
for (cy = oy - wcfg.spongeRadius - 1; cy <= oy + wcfg.spongeRadius + 1; cy++) {
if (isBlockWater(world, cx, cy, cz)) {
setBlockToWater(world, cx, cy, cz - 1);
}
}
}
}
}

View File

@ -36,16 +36,19 @@
import com.sk89q.worldguard.blacklist.events.*;
import com.sk89q.worldguard.protection.ApplicableRegionSet;
import static com.sk89q.worldguard.bukkit.BukkitUtil.*;
public class WorldGuardBlockListener extends BlockListener {
import static com.sk89q.worldguard.bukkit.SpongeUtil.*;
/**
* Plugin.
* The listener for block events.
*
* @author sk89q
*/
public class WorldGuardBlockListener extends BlockListener {
private WorldGuardPlugin plugin;
/**
* Construct the object;
* Construct the object.
*
* @param plugin
*/
@ -53,8 +56,10 @@ public WorldGuardBlockListener(WorldGuardPlugin plugin) {
this.plugin = plugin;
}
/**
* Register events.
*/
public void registerEvents() {
PluginManager pm = plugin.getServer().getPluginManager();
pm.registerEvent(Event.Type.BLOCK_DAMAGE, this, Priority.High, plugin);
@ -69,11 +74,23 @@ public void registerEvents() {
pm.registerEvent(Event.Type.SNOW_FORM, this, Priority.High, plugin);
}
protected WorldConfiguration getWorldConfig(World world) {
/**
* Get the world configuration given a world.
*
* @param world
* @return
*/
protected WorldStateManager getWorldConfig(World world) {
return plugin.getGlobalConfiguration().get(world);
}
protected WorldConfiguration getWorldConfig(Player player) {
/**
* Get the world configuration given a player.
*
* @param player
* @return
*/
protected WorldStateManager getWorldConfig(Player player) {
return plugin.getGlobalConfiguration().get(player.getWorld());
}
@ -110,7 +127,7 @@ public void onBlockBreak(BlockBreakEvent event) {
}
Player player = event.getPlayer();
WorldConfiguration wcfg = getWorldConfig(player);
WorldStateManager wcfg = getWorldConfig(player);
if (!wcfg.itemDurability) {
ItemStack held = player.getItemInHand();
@ -167,8 +184,8 @@ public void onBlockFromTo(BlockFromToEvent event) {
boolean isWater = blockFrom.getTypeId() == 8 || blockFrom.getTypeId() == 9;
boolean isLava = blockFrom.getTypeId() == 10 || blockFrom.getTypeId() == 11;
ConfigurationManager cfg = plugin.getGlobalConfiguration();
WorldConfiguration wcfg = cfg.get(event.getBlock().getWorld());
GlobalStateManager cfg = plugin.getGlobalConfiguration();
WorldStateManager wcfg = cfg.get(event.getBlock().getWorld());
if (wcfg.simulateSponge && isWater) {
int ox = blockTo.getX();
@ -249,8 +266,8 @@ public void onBlockIgnite(BlockIgniteEvent event) {
Block block = event.getBlock();
World world = block.getWorld();
ConfigurationManager cfg = plugin.getGlobalConfiguration();
WorldConfiguration wcfg = cfg.get(world);
GlobalStateManager cfg = plugin.getGlobalConfiguration();
WorldStateManager wcfg = cfg.get(world);
boolean isFireSpread = cause == IgniteCause.SPREAD;
@ -332,9 +349,7 @@ public void onBlockIgnite(BlockIgniteEvent event) {
}
/**
* Called when a block is destroyed from burning
*
* @param event Relevant event details
* Called when a block is destroyed from burning.
*/
@Override
public void onBlockBurn(BlockBurnEvent event) {
@ -343,8 +358,8 @@ public void onBlockBurn(BlockBurnEvent event) {
return;
}
ConfigurationManager cfg = plugin.getGlobalConfiguration();
WorldConfiguration wcfg = cfg.get(event.getBlock().getWorld());
GlobalStateManager cfg = plugin.getGlobalConfiguration();
WorldStateManager wcfg = cfg.get(event.getBlock().getWorld());
if (wcfg.disableFireSpread) {
event.setCancelled(true);
@ -385,9 +400,7 @@ public void onBlockBurn(BlockBurnEvent event) {
}
/**
* Called when block physics occurs
*
* @param event Relevant event details
* Called when block physics occurs.
*/
@Override
public void onBlockPhysics(BlockPhysicsEvent event) {
@ -396,8 +409,8 @@ public void onBlockPhysics(BlockPhysicsEvent event) {
return;
}
ConfigurationManager cfg = plugin.getGlobalConfiguration();
WorldConfiguration wcfg = cfg.get(event.getBlock().getWorld());
GlobalStateManager cfg = plugin.getGlobalConfiguration();
WorldStateManager wcfg = cfg.get(event.getBlock().getWorld());
int id = event.getChangedTypeId();
@ -418,9 +431,7 @@ public void onBlockPhysics(BlockPhysicsEvent event) {
}
/**
* Called when a player places a block
*
* @param event Relevant event details
* Called when a player places a block.
*/
@Override
public void onBlockPlace(BlockPlaceEvent event) {
@ -433,8 +444,8 @@ public void onBlockPlace(BlockPlaceEvent event) {
Player player = event.getPlayer();
World world = blockPlaced.getWorld();
ConfigurationManager cfg = plugin.getGlobalConfiguration();
WorldConfiguration wcfg = cfg.get(world);
GlobalStateManager cfg = plugin.getGlobalConfiguration();
WorldStateManager wcfg = cfg.get(world);
if (wcfg.useRegions) {
if (!plugin.getGlobalRegionManager().canBuild(player, blockPlaced.getLocation())) {
@ -470,16 +481,12 @@ public void onBlockPlace(BlockPlaceEvent event) {
int oy = blockPlaced.getY();
int oz = blockPlaced.getZ();
clearSpongeWater(world, ox, oy, oz);
clearSpongeWater(plugin, world, ox, oy, oz);
}
}
/**
* Called when redstone changes
* From: the source of the redstone change
* To: The redstone dust that changed
*
* @param event Relevant event details
* Called when redstone changes.
*/
@Override
public void onBlockRedstoneChange(BlockRedstoneEvent event) {
@ -487,8 +494,8 @@ public void onBlockRedstoneChange(BlockRedstoneEvent event) {
Block blockTo = event.getBlock();
World world = blockTo.getWorld();
ConfigurationManager cfg = plugin.getGlobalConfiguration();
WorldConfiguration wcfg = cfg.get(world);
GlobalStateManager cfg = plugin.getGlobalConfiguration();
WorldStateManager wcfg = cfg.get(world);
if (wcfg.simulateSponge && wcfg.redstoneSponges) {
int ox = blockTo.getX();
@ -501,10 +508,10 @@ public void onBlockRedstoneChange(BlockRedstoneEvent event) {
Block sponge = world.getBlockAt(ox + cx, oy + cy, oz + cz);
if (sponge.getTypeId() == 19
&& sponge.isBlockIndirectlyPowered()) {
clearSpongeWater(world, ox + cx, oy + cy, oz + cz);
clearSpongeWater(plugin, world, ox + cx, oy + cy, oz + cz);
} else if (sponge.getTypeId() == 19
&& !sponge.isBlockIndirectlyPowered()) {
addSpongeWater(world, ox + cx, oy + cy, oz + cz);
addSpongeWater(plugin, world, ox + cx, oy + cy, oz + cz);
}
}
}
@ -521,7 +528,7 @@ public void onBlockRedstoneChange(BlockRedstoneEvent event) {
public void onSignChange(SignChangeEvent event) {
Player player = event.getPlayer();
WorldConfiguration wcfg = getWorldConfig(player);
WorldStateManager wcfg = getWorldConfig(player);
if (wcfg.signChestProtection) {
if (event.getLine(0).equalsIgnoreCase("[Lock]")) {
@ -578,157 +585,18 @@ public void onSignChange(SignChangeEvent event) {
}
}
/**
* Called when snow is formed.
*/
@Override
public void onSnowForm(SnowFormEvent event) {
if (event.isCancelled()) {
return;
}
if (!plugin.getGlobalRegionManager().allows(DefaultFlag.SNOW_FALL, event.getBlock().getLocation())) {
if (!plugin.getGlobalRegionManager().allows(DefaultFlag.SNOW_FALL,
event.getBlock().getLocation())) {
event.setCancelled(true);
}
}
/**
* Drops a sign item and removes a sign.
*
* @param block
*/
private void dropSign(Block block) {
block.setTypeId(0);
block.getWorld().dropItemNaturally(block.getLocation(),
new ItemStack(Material.SIGN));
}
/**
* Remove water around a sponge.
*
* @param world
* @param ox
* @param oy
* @param oz
*/
private void clearSpongeWater(World world, int ox, int oy, int oz) {
ConfigurationManager cfg = plugin.getGlobalConfiguration();
WorldConfiguration wcfg = cfg.get(world);
for (int cx = -wcfg.spongeRadius; cx <= wcfg.spongeRadius; cx++) {
for (int cy = -wcfg.spongeRadius; cy <= wcfg.spongeRadius; cy++) {
for (int cz = -wcfg.spongeRadius; cz <= wcfg.spongeRadius; cz++) {
if (isBlockWater(world, ox + cx, oy + cy, oz + cz)) {
world.getBlockAt(ox + cx, oy + cy, oz + cz).setTypeId(0);
}
}
}
}
}
/**
* Add water around a sponge.
*
* @param world
* @param ox
* @param oy
* @param oz
*/
private void addSpongeWater(World world, int ox, int oy, int oz) {
ConfigurationManager cfg = plugin.getGlobalConfiguration();
WorldConfiguration wcfg = cfg.get(world);
// The negative x edge
int cx = ox - wcfg.spongeRadius - 1;
for (int cy = oy - wcfg.spongeRadius - 1; cy <= oy + wcfg.spongeRadius + 1; cy++) {
for (int cz = oz - wcfg.spongeRadius - 1; cz <= oz + wcfg.spongeRadius + 1; cz++) {
if (isBlockWater(world, cx, cy, cz)) {
setBlockToWater(world, cx + 1, cy, cz);
}
}
}
// The positive x edge
cx = ox + wcfg.spongeRadius + 1;
for (int cy = oy - wcfg.spongeRadius - 1; cy <= oy + wcfg.spongeRadius + 1; cy++) {
for (int cz = oz - wcfg.spongeRadius - 1; cz <= oz + wcfg.spongeRadius + 1; cz++) {
if (isBlockWater(world, cx, cy, cz)) {
setBlockToWater(world, cx - 1, cy, cz);
}
}
}
// The negative y edge
int cy = oy - wcfg.spongeRadius - 1;
for (cx = ox - wcfg.spongeRadius - 1; cx <= ox + wcfg.spongeRadius + 1; cx++) {
for (int cz = oz - wcfg.spongeRadius - 1; cz <= oz + wcfg.spongeRadius + 1; cz++) {
if (isBlockWater(world, cx, cy, cz)) {
setBlockToWater(world, cx, cy + 1, cz);
}
}
}
// The positive y edge
cy = oy + wcfg.spongeRadius + 1;
for (cx = ox - wcfg.spongeRadius - 1; cx <= ox + wcfg.spongeRadius + 1; cx++) {
for (int cz = oz - wcfg.spongeRadius - 1; cz <= oz + wcfg.spongeRadius + 1; cz++) {
if (isBlockWater(world, cx, cy, cz)) {
setBlockToWater(world, cx, cy - 1, cz);
}
}
}
// The negative z edge
int cz = oz - wcfg.spongeRadius - 1;
for (cx = ox - wcfg.spongeRadius - 1; cx <= ox + wcfg.spongeRadius + 1; cx++) {
for (cy = oy - wcfg.spongeRadius - 1; cy <= oy + wcfg.spongeRadius + 1; cy++) {
if (isBlockWater(world, cx, cy, cz)) {
setBlockToWater(world, cx, cy, cz + 1);
}
}
}
// The positive z edge
cz = oz + wcfg.spongeRadius + 1;
for (cx = ox - wcfg.spongeRadius - 1; cx <= ox + wcfg.spongeRadius + 1; cx++) {
for (cy = oy - wcfg.spongeRadius - 1; cy <= oy + wcfg.spongeRadius + 1; cy++) {
if (isBlockWater(world, cx, cy, cz)) {
setBlockToWater(world, cx, cy, cz - 1);
}
}
}
}
/**
* Sets the given block to fluid water.
* Used by addSpongeWater()
*
* @param world
* @param ox
* @param oy
* @param oz
*/
private void setBlockToWater(World world, int ox, int oy, int oz) {
Block block = world.getBlockAt(ox, oy, oz);
int id = block.getTypeId();
if (id == 0) {
block.setTypeId(8);
}
}
/**
* Checks if the given block is water
*
* @param world
* @param ox
* @param oy
* @param oz
*/
private boolean isBlockWater(World world, int ox, int oy, int oz) {
Block block = world.getBlockAt(ox, oy, oz);
int id = block.getTypeId();
if (id == 8 || id == 9) {
return true;
} else {
return false;
}
}
}

View File

@ -18,32 +18,34 @@
*/
package com.sk89q.worldguard.bukkit;
import org.bukkit.block.Block;
import org.bukkit.event.Event.Priority;
import org.bukkit.event.Event;
import org.bukkit.plugin.PluginManager;
import static com.sk89q.worldguard.bukkit.BukkitUtil.toVector;
import org.bukkit.ChatColor;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.World;
import org.bukkit.block.Block;
import org.bukkit.entity.*;
import org.bukkit.event.block.BlockPlaceEvent;
import org.bukkit.event.Event;
import org.bukkit.event.Event.Priority;
import org.bukkit.event.entity.*;
import org.bukkit.event.entity.EntityDamageEvent.DamageCause;
import org.bukkit.event.painting.*;
import org.bukkit.event.painting.PaintingBreakByEntityEvent;
import org.bukkit.event.painting.PaintingBreakEvent;
import org.bukkit.event.painting.PaintingPlaceEvent;
import org.bukkit.plugin.PluginManager;
import com.sk89q.worldedit.Vector;
import com.sk89q.worldedit.blocks.BlockType;
import static com.sk89q.worldguard.bukkit.BukkitUtil.*;
import com.sk89q.worldguard.protection.ApplicableRegionSet;
import com.sk89q.worldguard.protection.flags.DefaultFlag;
import com.sk89q.worldguard.protection.managers.RegionManager;
import com.sk89q.worldguard.protection.ApplicableRegionSet;
public class WorldGuardEntityListener extends EntityListener {
/**
* Plugin.
* Listener for entity related events.
*
* @author sk89q
*/
public class WorldGuardEntityListener extends EntityListener {
private WorldGuardPlugin plugin;
/**
@ -55,8 +57,10 @@ public WorldGuardEntityListener(WorldGuardPlugin plugin) {
this.plugin = plugin;
}
/**
* Register events.
*/
public void registerEvents() {
PluginManager pm = plugin.getServer().getPluginManager();
pm.registerEvent(Event.Type.ENTITY_DAMAGE, this, Priority.High, plugin);
@ -69,14 +73,17 @@ public void registerEvents() {
pm.registerEvent(Event.Type.PAINTING_PLACE, this, Priority.High, plugin);
}
/**
* Called when an entity interacts with another object.
*/
@Override
public void onEntityInteract(EntityInteractEvent event) {
//bukkit doesn't actually throw this event yet, someone add a ticket to leaky
Entity entity = event.getEntity();
Block block = event.getBlock();
ConfigurationManager cfg = plugin.getGlobalConfiguration();
WorldConfiguration wcfg = cfg.get(entity.getWorld());
GlobalStateManager cfg = plugin.getGlobalConfiguration();
WorldStateManager wcfg = cfg.get(entity.getWorld());
if (block.getType() == Material.SOIL) {
if (entity instanceof Creature && wcfg.disableCreatureCropTrampling) {
@ -85,13 +92,17 @@ public void onEntityInteract(EntityInteractEvent event) {
}
}
public void onEntityDamageByBlock(EntityDamageByBlockEvent event) {
/**
* Called on entity damage by a block.
*
* @param event
*/
private void onEntityDamageByBlock(EntityDamageByBlockEvent event) {
Entity defender = event.getEntity();
DamageCause type = event.getCause();
ConfigurationManager cfg = plugin.getGlobalConfiguration();
WorldConfiguration wcfg = cfg.get(defender.getWorld());
GlobalStateManager cfg = plugin.getGlobalConfiguration();
WorldStateManager wcfg = cfg.get(defender.getWorld());
if (defender instanceof Wolf) {
if (wcfg.antiWolfDumbness && !(type == DamageCause.VOID)) {
@ -135,15 +146,20 @@ public void onEntityDamageByBlock(EntityDamageByBlockEvent event) {
}
}
public void onEntityDamageByEntity(EntityDamageByEntityEvent event) {
/**
* Called on entity damage by an entity.
*
* @param event
*/
private void onEntityDamageByEntity(EntityDamageByEntityEvent event) {
Entity attacker = event.getDamager();
Entity defender = event.getEntity();
if (defender instanceof Player) {
Player player = (Player) defender;
ConfigurationManager cfg = plugin.getGlobalConfiguration();
WorldConfiguration wcfg = cfg.get(player.getWorld());
GlobalStateManager cfg = plugin.getGlobalConfiguration();
WorldStateManager wcfg = cfg.get(player.getWorld());
if (cfg.hasGodMode(player)) {
event.setCancelled(true);
@ -202,15 +218,20 @@ public void onEntityDamageByEntity(EntityDamageByEntityEvent event) {
}
}
public void onEntityDamageByProjectile(EntityDamageByProjectileEvent event) {
/**
* Called on entity damage by a projectile.
*
* @param event
*/
private void onEntityDamageByProjectile(EntityDamageByProjectileEvent event) {
Entity defender = event.getEntity();
Entity attacker = event.getDamager();
if (defender instanceof Player) {
Player player = (Player) defender;
ConfigurationManager cfg = plugin.getGlobalConfiguration();
WorldConfiguration wcfg = cfg.get(player.getWorld());
GlobalStateManager cfg = plugin.getGlobalConfiguration();
WorldStateManager wcfg = cfg.get(player.getWorld());
if (cfg.hasGodMode(player)) {
event.setCancelled(true);
@ -244,9 +265,11 @@ public void onEntityDamageByProjectile(EntityDamageByProjectileEvent event) {
}
/**
* Called on entity damage.
*/
@Override
public void onEntityDamage(EntityDamageEvent event) {
if (event.isCancelled()) {
return;
}
@ -265,8 +288,8 @@ public void onEntityDamage(EntityDamageEvent event) {
Entity defender = event.getEntity();
DamageCause type = event.getCause();
ConfigurationManager cfg = plugin.getGlobalConfiguration();
WorldConfiguration wcfg = cfg.get(defender.getWorld());
GlobalStateManager cfg = plugin.getGlobalConfiguration();
WorldStateManager wcfg = cfg.get(defender.getWorld());
if (defender instanceof Wolf) {
if (wcfg.antiWolfDumbness) {
@ -326,17 +349,19 @@ public void onEntityDamage(EntityDamageEvent event) {
}
}
/**
* Called on entity explode.
*/
@Override
public void onEntityExplode(EntityExplodeEvent event) {
if (event.isCancelled()) {
return;
}
ConfigurationManager cfg = plugin.getGlobalConfiguration();
GlobalStateManager cfg = plugin.getGlobalConfiguration();
Location l = event.getLocation();
World world = l.getWorld();
WorldConfiguration wcfg = cfg.get(world);
WorldStateManager wcfg = cfg.get(world);
Entity ent = event.getEntity();
if (ent instanceof LivingEntity) {
@ -396,14 +421,17 @@ public void onEntityExplode(EntityExplodeEvent event) {
}
}
/**
* Called on creature spawn.
*/
@Override
public void onCreatureSpawn(CreatureSpawnEvent event) {
if (event.isCancelled()) {
return;
}
ConfigurationManager cfg = plugin.getGlobalConfiguration();
WorldConfiguration wcfg = cfg.get(event.getEntity().getWorld());
GlobalStateManager cfg = plugin.getGlobalConfiguration();
WorldStateManager wcfg = cfg.get(event.getEntity().getWorld());
//CreatureType creaType = (CreatureType) CreatureType.valueOf(event.getMobType().toString());
CreatureType creaType = event.getCreatureType();
@ -448,7 +476,7 @@ public void onCreatureSpawn(CreatureSpawnEvent event) {
}
/**
* Weather related entity events.
* Called on pig zap.
*/
@Override
public void onPigZap(PigZapEvent event) {
@ -456,22 +484,25 @@ public void onPigZap(PigZapEvent event) {
return;
}
ConfigurationManager cfg = plugin.getGlobalConfiguration();
WorldConfiguration wcfg = cfg.get(event.getEntity().getWorld());
GlobalStateManager cfg = plugin.getGlobalConfiguration();
WorldStateManager wcfg = cfg.get(event.getEntity().getWorld());
if (wcfg.disablePigZap) {
event.setCancelled(true);
}
}
/**
* Called on creeper power.
*/
@Override
public void onCreeperPower(CreeperPowerEvent event) {
if (event.isCancelled()) {
return;
}
ConfigurationManager cfg = plugin.getGlobalConfiguration();
WorldConfiguration wcfg = cfg.get(event.getEntity().getWorld());
GlobalStateManager cfg = plugin.getGlobalConfiguration();
WorldStateManager wcfg = cfg.get(event.getEntity().getWorld());
if (wcfg.disableCreeperPower) {
event.setCancelled(true);
@ -479,12 +510,7 @@ public void onCreeperPower(CreeperPowerEvent event) {
}
/**
* Painting related events
*/
/**
* Called when a painting is removed
*
* @param event Relevant event details
* Called when a painting is removed.
*/
@Override
public void onPaintingBreak(PaintingBreakEvent breakEvent) {
@ -495,16 +521,18 @@ public void onPaintingBreak(PaintingBreakEvent breakEvent) {
if (!(breakEvent instanceof PaintingBreakByEntityEvent)) {
return;
}
PaintingBreakByEntityEvent event = (PaintingBreakByEntityEvent) breakEvent;
if (!(event.getRemover() instanceof Player)) {
return;
}
Painting painting= event.getPainting();
Player player = (Player) event.getRemover();
World world = painting.getWorld();
ConfigurationManager cfg = plugin.getGlobalConfiguration();
WorldConfiguration wcfg = cfg.get(world);
GlobalStateManager cfg = plugin.getGlobalConfiguration();
WorldStateManager wcfg = cfg.get(world);
if (wcfg.useRegions) {
if (!plugin.getGlobalRegionManager().canBuild(player, painting.getLocation())) {
@ -515,14 +543,17 @@ public void onPaintingBreak(PaintingBreakEvent breakEvent) {
}
}
/**
* Called on painting place.
*/
@Override
public void onPaintingPlace(PaintingPlaceEvent event) {
Block placedOn = event.getBlock();
Player player = event.getPlayer();
World world = placedOn.getWorld();
ConfigurationManager cfg = plugin.getGlobalConfiguration();
WorldConfiguration wcfg = cfg.get(world);
GlobalStateManager cfg = plugin.getGlobalConfiguration();
WorldStateManager wcfg = cfg.get(world);
if (wcfg.useRegions) {
if (!plugin.getGlobalRegionManager().canBuild(player, placedOn.getLocation())) {
@ -532,6 +563,7 @@ public void onPaintingPlace(PaintingPlaceEvent event) {
}
}
}
/**
* Find a position for the player to stand that is not inside a block.
* Blocks above the player will be iteratively tested until there is

View File

@ -35,10 +35,7 @@
import org.bukkit.plugin.PluginManager;
import com.sk89q.worldedit.Vector;
import com.sk89q.worldguard.LocalPlayer;
import com.sk89q.worldguard.blacklist.events.BlockInteractBlacklistEvent;
import com.sk89q.worldguard.blacklist.events.ItemAcquireBlacklistEvent;
import com.sk89q.worldguard.blacklist.events.ItemDropBlacklistEvent;
import com.sk89q.worldguard.blacklist.events.ItemUseBlacklistEvent;
import com.sk89q.worldguard.blacklist.events.*;
import com.sk89q.worldguard.protection.ApplicableRegionSet;
import com.sk89q.worldguard.protection.flags.DefaultFlag;
import com.sk89q.worldguard.protection.flags.RegionGroupFlag.RegionGroup;
@ -46,13 +43,10 @@
import com.sk89q.worldguard.protection.regions.ProtectedRegion;
/**
* Handles all events thrown in relation to a Player
* Handles all events thrown in relation to a player.
*/
public class WorldGuardPlayerListener extends PlayerListener {
/**
* Plugin.
*/
private WorldGuardPlugin plugin;
/**
@ -64,7 +58,9 @@ public WorldGuardPlayerListener(WorldGuardPlugin plugin) {
this.plugin = plugin;
}
/**
* Register events.
*/
public void registerEvents() {
PluginManager pm = plugin.getServer().getPluginManager();
@ -81,10 +77,64 @@ public void registerEvents() {
pm.registerEvent(Event.Type.PLAYER_BED_ENTER, this, Priority.High, plugin);
}
/**
* Called when a player attempts to log in to the server.
*/
@Override
public void onPlayerLogin(PlayerLoginEvent event) {
Player player = event.getPlayer();
GlobalStateManager cfg = plugin.getGlobalConfiguration();
WorldStateManager wcfg = cfg.get(player.getWorld());
if (wcfg.enforceOneSession) {
String name = player.getName();
for (Player pl : plugin.getServer().getOnlinePlayers()) {
if (pl.getName().equalsIgnoreCase(name)) {
pl.kickPlayer("Logged in from another location.");
}
}
}
}
/**
* Called when a player joins a server.
*/
@Override
public void onPlayerJoin(PlayerJoinEvent event) {
Player player = event.getPlayer();
GlobalStateManager cfg = plugin.getGlobalConfiguration();
WorldStateManager wcfg = cfg.get(player.getWorld());
if (wcfg.fireSpreadDisableToggle) {
player.sendMessage(ChatColor.YELLOW
+ "Fire spread is currently globally disabled for this world.");
}
if (plugin.inGroup(player, "wg-invincible")) {
cfg.enableGodMode(player);
}
if (plugin.inGroup(player, "wg-amphibious")) {
cfg.enableAmphibiousMode(player);
}
}
/**
* Called when a player leaves a server.
*/
@Override
public void onPlayerQuit(PlayerQuitEvent event) {
Player player = event.getPlayer();
GlobalStateManager cfg = plugin.getGlobalConfiguration();
cfg.forgetPlayer(plugin.wrapPlayer(player));
}
/**
* Called when a player interacts with an item.
*
* @param event Relevant event details
*/
@Override
public void onPlayerInteract(PlayerInteractEvent event) {
@ -100,12 +150,13 @@ public void onPlayerInteract(PlayerInteractEvent event) {
handlePhysicalInteract(event);
}
}
/**
* Called when a player left clicks air.
*
* @param event
*/
public void handleAirLeftClick(PlayerInteractEvent event) {
private void handleAirLeftClick(PlayerInteractEvent event) {
// I don't think we have to do anything here yet.
return;
}
@ -115,7 +166,7 @@ public void handleAirLeftClick(PlayerInteractEvent event) {
*
* @param event
*/
public void handleBlockLeftClick(PlayerInteractEvent event) {
private void handleBlockLeftClick(PlayerInteractEvent event) {
if (event.isCancelled()) return;
Player player = event.getPlayer();
@ -123,8 +174,8 @@ public void handleBlockLeftClick(PlayerInteractEvent event) {
Material type = block.getType();
World world = player.getWorld();
ConfigurationManager cfg = plugin.getGlobalConfiguration();
WorldConfiguration wcfg = cfg.get(world);
GlobalStateManager cfg = plugin.getGlobalConfiguration();
WorldStateManager wcfg = cfg.get(world);
if (wcfg.useRegions) {
Vector pt = toVector(block);
@ -152,7 +203,7 @@ public void handleBlockLeftClick(PlayerInteractEvent event) {
*
* @param event
*/
public void handleAirRightClick(PlayerInteractEvent event) {
private void handleAirRightClick(PlayerInteractEvent event) {
if (event.isCancelled()) {
return;
}
@ -161,8 +212,8 @@ public void handleAirRightClick(PlayerInteractEvent event) {
World world = player.getWorld();
ItemStack item = player.getItemInHand();
ConfigurationManager cfg = plugin.getGlobalConfiguration();
WorldConfiguration wcfg = cfg.get(world);
GlobalStateManager cfg = plugin.getGlobalConfiguration();
WorldStateManager wcfg = cfg.get(world);
if (wcfg.getBlacklist() != null) {
if (!wcfg.getBlacklist().check(
@ -180,7 +231,7 @@ public void handleAirRightClick(PlayerInteractEvent event) {
*
* @param event
*/
public void handleBlockRightClick(PlayerInteractEvent event) {
private void handleBlockRightClick(PlayerInteractEvent event) {
if (event.isCancelled()) {
return;
}
@ -191,8 +242,8 @@ public void handleBlockRightClick(PlayerInteractEvent event) {
Player player = event.getPlayer();
ItemStack item = player.getItemInHand();
ConfigurationManager cfg = plugin.getGlobalConfiguration();
WorldConfiguration wcfg = cfg.get(world);
GlobalStateManager cfg = plugin.getGlobalConfiguration();
WorldStateManager wcfg = cfg.get(world);
if (wcfg.blockLighter && item.getType() == Material.FLINT_AND_STEEL) {
if (!plugin.hasPermission(player, "worldguard.lighter.override")) {
@ -389,7 +440,7 @@ public void handleBlockRightClick(PlayerInteractEvent event) {
*
* @param event
*/
public void handlePhysicalInteract(PlayerInteractEvent event) {
private void handlePhysicalInteract(PlayerInteractEvent event) {
if (event.isCancelled() == true) return;
Player player = event.getPlayer();
@ -397,8 +448,8 @@ public void handlePhysicalInteract(PlayerInteractEvent event) {
Material type = block.getType();
World world = player.getWorld();
ConfigurationManager cfg = plugin.getGlobalConfiguration();
WorldConfiguration wcfg = cfg.get(world);
GlobalStateManager cfg = plugin.getGlobalConfiguration();
WorldStateManager wcfg = cfg.get(world);
if (block.getType() == Material.SOIL && wcfg.disablePlayerCropTrampling) {
event.setCancelled(true);
@ -425,48 +476,7 @@ public void handlePhysicalInteract(PlayerInteractEvent event) {
}
/**
* Called when a player joins a server
*
* @param event Relevant event details
*/
@Override
public void onPlayerJoin(PlayerJoinEvent event) {
Player player = event.getPlayer();
ConfigurationManager cfg = plugin.getGlobalConfiguration();
WorldConfiguration wcfg = cfg.get(player.getWorld());
if (wcfg.fireSpreadDisableToggle) {
player.sendMessage(ChatColor.YELLOW
+ "Fire spread is currently globally disabled for this world.");
}
if (plugin.inGroup(player, "wg-invincible")) {
cfg.enableGodMode(player);
}
if (plugin.inGroup(player, "wg-amphibious")) {
cfg.enableAmphibiousMode(player);
}
}
/**
* Called when a player leaves a server
*
* @param event Relevant event details
*/
@Override
public void onPlayerQuit(PlayerQuitEvent event) {
Player player = event.getPlayer();
ConfigurationManager cfg = plugin.getGlobalConfiguration();
cfg.forgetPlayer(plugin.wrapPlayer(player));
}
/**
* Called when a player uses an item
*
* @param event Relevant event details
* Called when a player uses an item.
*//*
@Override
public void onPlayerItem(PlayerItemEvent event) {
@ -533,42 +543,16 @@ public void onPlayerItem(PlayerItemEvent event) {
}*/
/**
* Called when a player attempts to log in to the server
*
* @param event Relevant event details
*/
@Override
public void onPlayerLogin(PlayerLoginEvent event) {
Player player = event.getPlayer();
ConfigurationManager cfg = plugin.getGlobalConfiguration();
WorldConfiguration wcfg = cfg.get(player.getWorld());
if (wcfg.enforceOneSession) {
String name = player.getName();
for (Player pl : plugin.getServer().getOnlinePlayers()) {
if (pl.getName().equalsIgnoreCase(name)) {
pl.kickPlayer("Logged in from another location.");
}
}
}
}
/**
* Called when a player attempts to drop an item
*
* @param event Relevant event details
* Called when a player attempts to drop an item.
*/
@Override
public void onPlayerDropItem(PlayerDropItemEvent event) {
if (event.isCancelled()) {
return;
}
ConfigurationManager cfg = plugin.getGlobalConfiguration();
WorldConfiguration wcfg = cfg.get(event.getPlayer().getWorld());
GlobalStateManager cfg = plugin.getGlobalConfiguration();
WorldStateManager wcfg = cfg.get(event.getPlayer().getWorld());
if (wcfg.getBlacklist() != null) {
Item ci = event.getItemDrop();
@ -583,20 +567,16 @@ public void onPlayerDropItem(PlayerDropItemEvent event) {
}
/**
* Called when a player attempts to pickup an item
*
* @param event
* Relevant event details
* Called when a player attempts to pickup an item.
*/
@Override
public void onPlayerPickupItem(PlayerPickupItemEvent event) {
if (event.isCancelled()) {
return;
}
ConfigurationManager cfg = plugin.getGlobalConfiguration();
WorldConfiguration wcfg = cfg.get(event.getPlayer().getWorld());
GlobalStateManager cfg = plugin.getGlobalConfiguration();
WorldStateManager wcfg = cfg.get(event.getPlayer().getWorld());
if (wcfg.getBlacklist() != null) {
Item ci = event.getItem();
@ -618,8 +598,8 @@ public void onPlayerBucketFill(PlayerBucketFillEvent event) {
Player player = event.getPlayer();
World world = player.getWorld();
ConfigurationManager cfg = plugin.getGlobalConfiguration();
WorldConfiguration wcfg = cfg.get(world);
GlobalStateManager cfg = plugin.getGlobalConfiguration();
WorldStateManager wcfg = cfg.get(world);
if (!plugin.getGlobalRegionManager().canBuild(player, event.getBlockClicked())) {
player.sendMessage(ChatColor.DARK_RED + "You don't have permission for this area.");
@ -645,8 +625,8 @@ public void onPlayerBucketEmpty(PlayerBucketEmptyEvent event) {
Player player = event.getPlayer();
World world = player.getWorld();
ConfigurationManager cfg = plugin.getGlobalConfiguration();
WorldConfiguration wcfg = cfg.get(world);
GlobalStateManager cfg = plugin.getGlobalConfiguration();
WorldStateManager wcfg = cfg.get(world);
if (!plugin.getGlobalRegionManager().canBuild(player, event.getBlockClicked())) {
player.sendMessage(ChatColor.DARK_RED + "You don't have permission for this area.");
@ -664,13 +644,16 @@ public void onPlayerBucketEmpty(PlayerBucketEmptyEvent event) {
}
}
/**
* Called when a player is respawned.
*/
@Override
public void onPlayerRespawn(PlayerRespawnEvent event) {
Player player = event.getPlayer();
Location location = player.getLocation();
ConfigurationManager cfg = plugin.getGlobalConfiguration();
WorldConfiguration wcfg = cfg.get(player.getWorld());
GlobalStateManager cfg = plugin.getGlobalConfiguration();
WorldStateManager wcfg = cfg.get(player.getWorld());
if (wcfg.useRegions) {
Vector pt = toVector(location);
@ -709,8 +692,8 @@ public void onPlayerRespawn(PlayerRespawnEvent event) {
public void onItemHeldChange(PlayerItemHeldEvent event) {
Player player = event.getPlayer();
ConfigurationManager cfg = plugin.getGlobalConfiguration();
WorldConfiguration wcfg = cfg.get(player.getWorld());
GlobalStateManager cfg = plugin.getGlobalConfiguration();
WorldStateManager wcfg = cfg.get(player.getWorld());
if (wcfg.removeInfiniteStacks
&& !plugin.hasPermission(player, "worldguard.override.infinite-stack")) {
@ -723,6 +706,9 @@ public void onItemHeldChange(PlayerItemHeldEvent event) {
}
}
/**
* Called when a player enters a bed.
*/
@Override
public void onPlayerBedEnter(PlayerBedEnterEvent event) {
if (event.isCancelled()) {
@ -732,8 +718,8 @@ public void onPlayerBedEnter(PlayerBedEnterEvent event) {
Player player = event.getPlayer();
Location location = player.getLocation();
ConfigurationManager cfg = plugin.getGlobalConfiguration();
WorldConfiguration wcfg = cfg.get(player.getWorld());
GlobalStateManager cfg = plugin.getGlobalConfiguration();
WorldStateManager wcfg = cfg.get(player.getWorld());
if (wcfg.useRegions) {
Vector pt = toVector(location);

View File

@ -70,7 +70,7 @@ public class WorldGuardPlugin extends JavaPlugin {
/**
* Handles all configuration.
*/
protected final ConfigurationManager configuration;
protected final GlobalStateManager configuration;
/**
* Processes queries for permissions information. The permissions manager
@ -85,7 +85,7 @@ public class WorldGuardPlugin extends JavaPlugin {
* this merely instantiates the objects.
*/
public WorldGuardPlugin() {
configuration = new ConfigurationManager(this);
configuration = new GlobalStateManager(this);
globalRegionManager = new GlobalRegionManager(this);
final WorldGuardPlugin plugin = this;
@ -200,7 +200,7 @@ public GlobalRegionManager getGlobalRegionManager() {
*
* @return
*/
public ConfigurationManager getGlobalConfiguration() {
public GlobalStateManager getGlobalConfiguration() {
return configuration;
}

View File

@ -61,8 +61,8 @@ public void onWeatherChange(WeatherChangeEvent event) {
if (event.isCancelled()) {
return;
}
ConfigurationManager cfg = plugin.getGlobalConfiguration();
WorldConfiguration wcfg = cfg.get(event.getWorld());
GlobalStateManager cfg = plugin.getGlobalConfiguration();
WorldStateManager wcfg = cfg.get(event.getWorld());
if (event.toWeatherState()) {
if (wcfg.disableWeather) {
@ -81,8 +81,8 @@ public void onThunderChange(ThunderChangeEvent event) {
return;
}
ConfigurationManager cfg = plugin.getGlobalConfiguration();
WorldConfiguration wcfg = cfg.get(event.getWorld());
GlobalStateManager cfg = plugin.getGlobalConfiguration();
WorldStateManager wcfg = cfg.get(event.getWorld());
if (event.toThunderState()) {
if (wcfg.disableThunder) {
@ -101,8 +101,8 @@ public void onLightningStrike(LightningStrikeEvent event) {
return;
}
ConfigurationManager cfg = plugin.getGlobalConfiguration();
WorldConfiguration wcfg = cfg.get(event.getWorld());
GlobalStateManager cfg = plugin.getGlobalConfiguration();
WorldStateManager wcfg = cfg.get(event.getWorld());
if (wcfg.disallowedLightningBlocks.size() > 0) {
int targetId = event.getLightning().getLocation().getBlock().getTypeId();

View File

@ -42,7 +42,7 @@
* @author sk89q
* @author Michael
*/
public class WorldConfiguration {
public class WorldStateManager {
private static final Logger logger = Logger
.getLogger("Minecraft.WorldGuard");
@ -126,7 +126,7 @@ public class WorldConfiguration {
* @param plugin
* @param worldName
*/
public WorldConfiguration(WorldGuardPlugin plugin, String worldName) {
public WorldStateManager(WorldGuardPlugin plugin, String worldName) {
File baseFolder = new File(plugin.getDataFolder(), "worlds/" + worldName);
configFile = new File(baseFolder, "config.yml");
blacklistFile = new File(baseFolder, "blacklist.txt");

View File

@ -27,7 +27,7 @@
import com.sk89q.minecraft.util.commands.CommandContext;
import com.sk89q.minecraft.util.commands.CommandException;
import com.sk89q.minecraft.util.commands.CommandPermissions;
import com.sk89q.worldguard.bukkit.ConfigurationManager;
import com.sk89q.worldguard.bukkit.GlobalStateManager;
import com.sk89q.worldguard.bukkit.WorldGuardPlugin;
import com.sk89q.worldedit.blocks.ItemType;
@ -39,7 +39,7 @@ public class GeneralCommands {
flags = "s", min = 0, max = 1)
public static void god(CommandContext args, WorldGuardPlugin plugin,
CommandSender sender) throws CommandException {
ConfigurationManager config = plugin.getGlobalConfiguration();
GlobalStateManager config = plugin.getGlobalConfiguration();
Iterable<Player> targets = null;
boolean included = false;
@ -87,7 +87,7 @@ public static void god(CommandContext args, WorldGuardPlugin plugin,
flags = "s", min = 0, max = 1)
public static void ungod(CommandContext args, WorldGuardPlugin plugin,
CommandSender sender) throws CommandException {
ConfigurationManager config = plugin.getGlobalConfiguration();
GlobalStateManager config = plugin.getGlobalConfiguration();
Iterable<Player> targets = null;
boolean included = false;

View File

@ -32,7 +32,7 @@
import com.sk89q.worldedit.bukkit.WorldEditPlugin;
import com.sk89q.worldedit.bukkit.selections.*;
import com.sk89q.worldguard.LocalPlayer;
import com.sk89q.worldguard.bukkit.WorldConfiguration;
import com.sk89q.worldguard.bukkit.WorldStateManager;
import com.sk89q.worldguard.bukkit.WorldGuardPlugin;
import com.sk89q.worldguard.domains.DefaultDomain;
import com.sk89q.worldguard.protection.ApplicableRegionSet;
@ -234,7 +234,7 @@ public static void claim(CommandContext args, WorldGuardPlugin plugin,
region.setOwners(RegionUtil.parseDomainString(args.getSlice(1), 1));
}
WorldConfiguration wcfg = plugin.getGlobalConfiguration().get(player.getWorld());
WorldStateManager wcfg = plugin.getGlobalConfiguration().get(player.getWorld());
RegionManager mgr = plugin.getGlobalRegionManager().get(sel.getWorld());
// Check whether the player has created too many regions
@ -454,6 +454,7 @@ public static void list(CommandContext args, WorldGuardPlugin plugin,
if (args.argsLength() > 0 && args.getString(0).startsWith(".")) {
name = args.getString(0).substring(1).toLowerCase();
argl = 1;
if (name.equals("me") || name.isEmpty() ||
name.equals(plugin.checkPlayer(sender).getDisplayName().toLowerCase())) {
plugin.checkPermission(sender, "worldguard.region.list.own");

View File

@ -23,7 +23,7 @@
import org.bukkit.World;
import org.bukkit.command.CommandSender;
import com.sk89q.minecraft.util.commands.*;
import com.sk89q.worldguard.bukkit.WorldConfiguration;
import com.sk89q.worldguard.bukkit.WorldStateManager;
import com.sk89q.worldguard.bukkit.WorldGuardPlugin;
public class ToggleCommands {
@ -43,7 +43,7 @@ public static void stopFire(CommandContext args, WorldGuardPlugin plugin,
world = plugin.matchWorld(sender, args.getString(0));
}
WorldConfiguration wcfg = plugin.getGlobalConfiguration().get(world);
WorldStateManager wcfg = plugin.getGlobalConfiguration().get(world);
if (!wcfg.fireSpreadDisableToggle) {
plugin.getServer().broadcastMessage(
@ -74,7 +74,7 @@ public static void allowFire(CommandContext args, WorldGuardPlugin plugin,
world = plugin.matchWorld(sender, args.getString(0));
}
WorldConfiguration wcfg = plugin.getGlobalConfiguration().get(world);
WorldStateManager wcfg = plugin.getGlobalConfiguration().get(world);
if (wcfg.fireSpreadDisableToggle) {
plugin.getServer().broadcastMessage(ChatColor.YELLOW

View File

@ -21,8 +21,8 @@
import static com.sk89q.worldguard.bukkit.BukkitUtil.toVector;
import com.sk89q.worldguard.LocalPlayer;
import com.sk89q.worldguard.bukkit.BukkitUtil;
import com.sk89q.worldguard.bukkit.ConfigurationManager;
import com.sk89q.worldguard.bukkit.WorldConfiguration;
import com.sk89q.worldguard.bukkit.GlobalStateManager;
import com.sk89q.worldguard.bukkit.WorldStateManager;
import com.sk89q.worldguard.bukkit.WorldGuardPlugin;
import com.sk89q.worldguard.protection.databases.YAMLDatabase;
import com.sk89q.worldguard.protection.flags.StateFlag;
@ -57,7 +57,7 @@ public class GlobalRegionManager {
/**
* Reference to the global configuration.
*/
private ConfigurationManager config;
private GlobalStateManager config;
/**
* Map of managers per-world.
@ -241,7 +241,7 @@ public boolean canBuild(Player player, Block block) {
*/
public boolean canBuild(Player player, Location loc) {
World world = loc.getWorld();
WorldConfiguration worldConfig = config.get(world);
WorldStateManager worldConfig = config.get(world);
if (!worldConfig.useRegions) {
return true;
@ -270,7 +270,7 @@ public boolean canBuild(Player player, Location loc) {
*/
public boolean allows(StateFlag flag, Location loc) {
World world = loc.getWorld();
WorldConfiguration worldConfig = config.get(world);
WorldStateManager worldConfig = config.get(world);
if (!worldConfig.useRegions) {
return true;