More progress.

This commit is contained in:
sk89q 2011-03-27 23:49:30 -07:00
parent fd8c827bf1
commit ede4873c6a
19 changed files with 687 additions and 538 deletions

View File

@ -46,6 +46,7 @@
<mkdir dir="${build.dir}/defaults"/>
<copy tofile="${build.dir}/defaults/global.yml" file="global.yml"/>
<copy tofile="${build.dir}/defaults/config.yml" file="config.yml"/>
<copy tofile="${build.dir}/defaults/config_world.yml" file="config_world.yml"/>
<copy tofile="${build.dir}/defaults/blacklist.txt" file="blacklist.txt"/>
<jar jarfile="${dist.dir}/WorldGuard.jar" basedir="${build.dir}" manifest="manifest.mf">
<zipgroupfileset dir="lib" includes="prtree.jar" />

84
config_world.yml Normal file
View File

@ -0,0 +1,84 @@
#
# WorldGuard's configuration file.
#
# This is the a per-world configuration file. It only affects one
# corresponding world.
#
# About editing this file:
# - DO NOT USE TABS. You MUST use spaces or Bukkit will complain. If
# you use an editor like Notepad++ (recommended for Windows users), you
# must configure it to "replace tabs with spaces." In Notepad++, this can
# be changed in Settings > Preferences > Language Menu.
# - Don't get rid of the indents. They are indented so some entries are
# in categories (like "enforce-single-session" is in the "protection"
# category.
# - If you want to check the format of this file before putting it
# into WorldGuard, paste it into http://yaml-online-parser.appspot.com/
# and see if it gives "ERROR:".
# - Lines starting with # are commentsand so they are ignored.
#
summary-on-start: on
protection:
enforce-single-session: on
item-durability: on
simulation:
sponge:
enable: on
redstone: off
radius: 3
physics:
no-physics-gravel: off
no-physics-sand: off
allow-portal-anywhere: off
disable-water-damage-blocks: []
ignition:
block-tnt: off
block-lighter: off
fire:
disable-all-fire-spread: off
disable-fire-spread-blocks: []
disable-lava-fire-spread: on
lava-spread-blocks: []
mobs:
block-creeper-explosions: off
block-creeper-block-damage: off
block-creature-spawn: []
spawn:
login-protection: 3
spawn-protection: 0
kick-on-death: off
exact-respawn: off
teleport-to-home-on-death: off
player-damage:
disable-fall-damage: off
disable-lava-damage: off
disable-fire-damage: off
disable-drowning-damage: off
disable-suffocation-damage: off
disable-contact-damage: off
teleport-on-suffocation: off
regions:
enable: on
wand: 287
max-claim-volume: 30000
claim-only-inside-existing-regions: off
max-region-count-per-player: 7
iconomy:
enable: on
buy-on-claim: on
# Price per block for buying on claim
buy-on-claim-price: 2
blacklist:
use-as-whitelist: off

View File

@ -72,6 +72,14 @@ public abstract class LocalPlayer {
*/
public abstract String[] getGroups();
/**
* Returns whether a player has permission.
*
* @param perm
* @return
*/
public abstract boolean hasPermission(String perm);
@Override
public boolean equals(Object obj) {
if (!(obj instanceof LocalPlayer)) {

View File

@ -69,4 +69,9 @@ public void printRaw(String msg) {
player.sendMessage(msg);
}
@Override
public boolean hasPermission(String perm) {
return plugin.hasPermission(player, perm);
}
}

View File

@ -0,0 +1,121 @@
// $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 com.sk89q.worldguard.LocalPlayer;
import com.sk89q.worldguard.blacklist.Blacklist;
import java.io.File;
import java.util.HashMap;
import java.util.Map;
import org.bukkit.World;
import org.bukkit.util.config.Configuration;
/**
* Represents the global configuration and also delegates configuration
* for individual worlds.
*
* @author sk89q
* @author Michael
*/
public class ConfigurationManager {
/**
* Reference to the plugin.
*/
private WorldGuardPlugin plugin;
/**
* Holds configurations for different worlds.
*/
private Map<String, WorldConfiguration> worlds;
public boolean suppressTickSyncWarnings;
/**
* Construct the object.
*
* @param plugin
*/
public ConfigurationManager(WorldGuardPlugin plugin) {
this.plugin = plugin;
this.worlds = new HashMap<String, WorldConfiguration>();
}
/**
* Load the configuration.
*/
public void load() {
// Create the default configuration file
WorldGuardPlugin.createDefaultConfiguration(
new File(plugin.getDataFolder(), "config.yml"), "config.yml");
Configuration config = plugin.getConfiguration();
config.load();
suppressTickSyncWarnings = config.getBoolean(
"suppress-tick-sync-warnings", false);
// Load configurations for each world
for (World world : plugin.getServer().getWorlds()) {
forWorld(world.getName());
}
}
/**
* Unload the configuration.
*/
public void unload() {
worlds.clear();
}
/**
* Get the configuration for a world.
*
* @param worldName
* @return
*/
public WorldConfiguration forWorld(String worldName) {
WorldConfiguration config = worlds.get(worldName);
if (config == null) {
config = new WorldConfiguration(plugin, worldName);
worlds.put(worldName, config);
}
return config;
}
/**
* Forget a player.
*
* @param player
*/
public void forgetPlayer(LocalPlayer player) {
for (Map.Entry<String, WorldConfiguration> entry
: worlds.entrySet()) {
// The blacklist needs to forget players
Blacklist bl = entry.getValue().getBlacklist();
if (bl != null) {
bl.forgetPlayer(player);
}
}
}
}

View File

@ -1,317 +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.bukkit;
import com.nijiko.coelho.iConomy.iConomy;
import com.sk89q.worldedit.Vector;
import com.sk89q.worldguard.LocalPlayer;
import com.sk89q.worldguard.TickSyncDelayLoggerFilter;
import com.sk89q.worldguard.blacklist.Blacklist;
import com.sk89q.worldguard.protection.databases.CSVDatabase;
import com.sk89q.worldguard.protection.managers.RegionManager;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import java.util.logging.Filter;
import java.util.logging.Logger;
import org.bukkit.World;
import org.bukkit.entity.Player;
import org.bukkit.util.config.Configuration;
/**
* Represents the global configuration and also delegates configuration
* for individual worlds.
*
* @author Michael
* @author sk89q
*/
public class GlobalConfiguration {
private static final Logger logger = Logger.getLogger("Minecraft.WorldGuard");
private WorldGuardPlugin plugin;
private Map<String, WorldConfiguration> worldConfig;
protected Set<String> invinciblePlayers = new HashSet<String>();
protected Set<String> amphibiousPlayers = new HashSet<String>();
private iConomy iConomy;
/**
* Construct the object.
*
* @param plugin
*/
public GlobalConfiguration(WorldGuardPlugin plugin) {
this.plugin = plugin;
this.worldConfig = new HashMap<String, WorldConfiguration>();
this.iConomy = null;
}
/**
* Get the configuration for a world.
*
* @param worldName
* @return
*/
public WorldConfiguration getWorldConfig(String worldName) {
WorldConfiguration ret = worldConfig.get(worldName);
if (ret == null) {
ret = createWorldConfig(worldName);
worldConfig.put(worldName, ret);
}
return ret;
}
/**
* Create the configuration for a world.
*
* @param worldName
* @return
*/
private WorldConfiguration createWorldConfig(String worldName) {
File baseFolder = new File(plugin.getDataFolder(), worldName);
File configFile = new File(baseFolder, "config.yml");
File blacklistFile = new File(baseFolder, "blacklist.txt");
return new WorldConfiguration(plugin, worldName, configFile, blacklistFile);
}
/**
* Load the configuration files.
*/
public void load() {
checkOldConfigFiles();
checkOldCSVDB();
Configuration config = plugin.getConfiguration();
boolean suppressTickSyncWarnings = config.getBoolean(
"suppress-tick-sync-warnings", false);
invinciblePlayers.clear();
amphibiousPlayers.clear();
// Build initial lists of users matching the criteria
for (Player player : plugin.getServer().getOnlinePlayers()) {
if (plugin.inGroup(player, "wg-invincible"))
invinciblePlayers.add(player.getName());
if (plugin.inGroup(player, "wg-amphibious"))
amphibiousPlayers.add(player.getName());
}
if (suppressTickSyncWarnings) {
Logger.getLogger("Minecraft").setFilter(
new TickSyncDelayLoggerFilter());
} else {
Filter filter = Logger.getLogger("Minecraft").getFilter();
if (filter != null && filter instanceof TickSyncDelayLoggerFilter) {
Logger.getLogger("Minecraft").setFilter(null);
}
}
loadWorldConfiguration();
}
public void unload() {
}
/**
* Load the configurations for the different worlds.
*/
private void loadWorldConfiguration() {
worldConfig.clear();
for (World w : plugin.getServer().getWorlds()) {
String worldName = w.getName();
worldConfig.put(worldName, createWorldConfig(worldName));
}
}
/**
* Check for old pre-4.x configuration files.
*/
private void checkOldConfigFiles() {
File oldFile = new File(plugin.getDataFolder(), "blacklist.txt");
if (oldFile.exists()) {
logger.warning("WorldGuard: blacklist.txt is outdated, please "
+ "reapply your configuration in <world>/blacklist.txt");
logger.warning("WorldGuard: blacklist.txt renamed to blacklist.txt.old");
oldFile.renameTo(new File(plugin.getDataFolder(),
"blacklist.txt.old"));
}
}
/**
* Check for old world databases from pre-4.x versions. Also convert them
* over to the new format.
*/
private void checkOldCSVDB() {
try {
File oldDatabase = new File(plugin.getDataFolder(), "regions.txt");
if (!oldDatabase.exists()) return;
logger.info("WorldGuard: The regions database has changed in 4.x. "
+ "Your old regions database will be converted to the new format "
+ "and set as your primarily world's database.");
logger.info("WorldGuard: Converting...");
// We're assuming that the regions
World w = plugin.getServer().getWorlds().get(0);
RegionManager mgr = plugin.getGlobalRegionManager()
.get(w.getName());
// First load up the old database using the CSV loader
CSVDatabase db = new CSVDatabase(oldDatabase);
db.load();
// Then save the new database
mgr.setRegions(db.getRegions());
mgr.save();
logger.info("WorldGuard: regions.txt has been renamed to regions.txt.old.");
oldDatabase.renameTo(new File(plugin.getDataFolder(), "regions.txt.old"));
} catch (FileNotFoundException e) {
} catch (IOException e) {
logger.warning("WorldGuard: Failed to load regions: "
+ e.getMessage());
}
}
/**
* Check if a player has permission to build at a location.
*
* @param player
* @param pt
* @return
*/
public boolean canBuild(Player player, Vector pt) {
if (getWorldConfig(player.getWorld().getName()).useRegions) {
LocalPlayer localPlayer = plugin.wrapPlayer(player);
if (!plugin.hasPermission(player, "region.bypass")) {
RegionManager mgr = plugin.getGlobalRegionManager()
.get(player.getWorld().getName());
if (!mgr.getApplicableRegions(pt).canBuild(localPlayer)) {
return false;
}
}
return true;
} else {
return true;
}
}
/**
* Check if a player has permission to build at a location.
*
* @param player
* @param x
* @param y
* @param z
* @return
*/
public boolean canBuild(Player player, int x, int y, int z) {
return canBuild(player, new Vector(x, y, z));
}
/**
* Check whether a player can breathe underwater.
*
* @param playerName
* @return
*/
public boolean isAmphibiousPlayer(String playerName) {
if (amphibiousPlayers.contains(playerName)) {
return true;
}
return false;
}
/**
* Check whether a player is invincible.
*
* @param playerName
* @return
*/
public boolean isInvinciblePlayer(String playerName) {
if (invinciblePlayers.contains(playerName)) {
return true;
}
return false;
}
public void addAmphibiousPlayer(String playerName) {
amphibiousPlayers.add(playerName);
}
public void addInvinciblePlayer(String playerName) {
invinciblePlayers.add(playerName);
}
public void removeAmphibiousPlayer(String playerName) {
amphibiousPlayers.remove(playerName);
}
public void removeInvinciblePlayer(String playerName) {
invinciblePlayers.remove(playerName);
}
/**
* Forget all players.
* @param player
*/
public void forgetPlayer(LocalPlayer player) {
for (Map.Entry<String, WorldConfiguration> entry : worldConfig
.entrySet()) {
Blacklist bl = entry.getValue().getBlacklist();
if (bl != null) {
bl.forgetPlayer(player);
}
}
}
public WorldGuardPlugin getWorldGuardPlugin() {
return this.plugin;
}
public iConomy getiConomy() {
return this.iConomy;
}
public void setiConomy(iConomy newVal) {
this.iConomy = newVal;
}
}

View File

@ -0,0 +1,154 @@
// $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 java.io.*;
import java.util.logging.Logger;
import org.bukkit.World;
import com.sk89q.worldguard.protection.databases.CSVDatabase;
import com.sk89q.worldguard.protection.managers.RegionManager;
/**
* Utility methods for porting from legacy versions.
*
* @author sk89q
*/
public class LegacyWorldGuardMigration {
/**
* Logger for messages.
*/
protected static final Logger logger = Logger.getLogger("Minecraft.WorldGuard");
/**
* Port over the blacklist.
*
* @param plugin
*/
public static void migrateBlacklist(WorldGuardPlugin plugin) {
World mainWorld = plugin.getServer().getWorlds().get(0);
String mainWorldName = mainWorld.getName();
String newPath = "worlds/" + mainWorldName + "/blacklist.txt";
File oldFile = new File(plugin.getDataFolder(), "blacklist.txt");
File newFile = new File(plugin.getDataFolder(), newPath);
if (!newFile.exists() && oldFile.exists()) {
logger.warning("WorldGuard: WorldGuard will now update your blacklist "
+ "from an older version of WorldGuard.");
// Need to make root directories
newFile.getParentFile().mkdirs();
if (copyFile(oldFile, newFile)) {
oldFile.renameTo(new File(plugin.getDataFolder(),
"blacklist.txt.old"));
} else {
logger.warning("WorldGuard: blacklist.txt has been converted " +
"for the main world at " + newPath + "");
logger.warning("WorldGuard: Your other worlds currently have no " +
"blacklist defined!");
}
}
}
/**
* Migrate region settings.
*
* @param plugin
*/
public static void migrateRegions(WorldGuardPlugin plugin) {
try {
File oldDatabase = new File(plugin.getDataFolder(), "regions.txt");
if (!oldDatabase.exists()) return;
logger.info("WorldGuard: The regions database has changed in 4.x. "
+ "Your old regions database will be converted to the new format "
+ "and set as your primarily world's database.");
World w = plugin.getServer().getWorlds().get(0);
RegionManager mgr = plugin.getGlobalRegionManager()
.get(w.getName());
// First load up the old database using the CSV loader
CSVDatabase db = new CSVDatabase(oldDatabase);
db.load();
// Then save the new database
mgr.setRegions(db.getRegions());
mgr.save();
oldDatabase.renameTo(new File(plugin.getDataFolder(), "regions.txt.old"));
logger.info("WorldGuard: Regions database converted!");
} catch (FileNotFoundException e) {
} catch (IOException e) {
logger.warning("WorldGuard: Failed to load regions: "
+ e.getMessage());
}
}
/**
* Copies a file.
*
* @param from
* @param to
* @return true if successful
*/
private static boolean copyFile(File from, File to) {
InputStream in = null;
OutputStream out = null;
try {
in = new FileInputStream(from);
out = new FileOutputStream(to);
byte[] buf = new byte[1024];
int len;
while ((len = in.read(buf)) > 0) {
out.write(buf, 0, len);
}
in.close();
out.close();
return true;
} catch (FileNotFoundException ex) {
} catch (IOException e) {
} finally {
if (in != null) {
try {
in.close();
} catch (IOException e) {
}
}
if (out != null) {
try {
out.close();
} catch (IOException e) {
}
}
}
return false;
}
}

View File

@ -35,7 +35,9 @@
import org.bukkit.util.config.Configuration;
/**
* Holds the configuration for individual worlds.
*
* @author sk89q
* @author Michael
*/
public class WorldConfiguration {
@ -95,17 +97,26 @@ public class WorldConfiguration {
/* Configuration data end */
public WorldConfiguration(WorldGuardPlugin wp, String worldName,
File configFile, File blacklistFile) {
this.plugin = wp;
this.worldName = worldName;
this.configFile = configFile;
this.blacklistFile = blacklistFile;
/**
* Construct the object.
*
* @param plugin
* @param worldName
*/
public WorldConfiguration(WorldGuardPlugin plugin, String worldName) {
File baseFolder = new File(plugin.getDataFolder(), "worlds/" + worldName);
configFile = new File(baseFolder, "config.yml");
blacklistFile = new File(baseFolder, "blacklist.txt");
WorldGuardPlugin.createDefaultConfiguration(configFile, "config.yml");
this.plugin = plugin;
this.worldName = worldName;
WorldGuardPlugin.createDefaultConfiguration(configFile, "config_world.yml");
WorldGuardPlugin.createDefaultConfiguration(blacklistFile, "blacklist.txt");
loadConfiguration();
logger.info("WorldGuard: Loaded configuration for world '" + worldName + '"');
}
/**

View File

@ -23,16 +23,9 @@
import org.bukkit.event.Event.Priority;
import org.bukkit.event.Event;
import org.bukkit.plugin.PluginManager;
import com.nijiko.coelho.iConomy.iConomy;
import com.nijiko.coelho.iConomy.system.Account;
import java.util.Iterator;
import java.util.List;
import org.bukkit.block.Block;
import org.bukkit.block.BlockState;
import org.bukkit.block.Sign;
import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
import org.bukkit.World;
import org.bukkit.event.block.*;
@ -41,10 +34,7 @@
import com.sk89q.worldedit.Vector;
import com.sk89q.worldguard.LocalPlayer;
import com.sk89q.worldguard.blacklist.events.*;
import com.sk89q.worldguard.domains.DefaultDomain;
import com.sk89q.worldguard.protection.ApplicableRegionSet;
import com.sk89q.worldguard.protection.regions.ProtectedRegion;
import static com.sk89q.worldguard.bukkit.BukkitUtil.*;
public class WorldGuardBlockListener extends BlockListener {
@ -93,13 +83,11 @@ public void onBlockDamage(BlockDamageEvent event) {
Player player = event.getPlayer();
Block blockDamaged = event.getBlock();
GlobalConfiguration cfg = plugin.getGlobalConfiguration();
WorldConfiguration wcfg = cfg.getWorldConfig(player.getWorld().getName());
ConfigurationManager cfg = plugin.getGlobalConfiguration();
WorldConfiguration wcfg = cfg.forWorld(player.getWorld().getName());
if (wcfg.useRegions && blockDamaged.getType() == Material.CAKE_BLOCK) {
Vector pt = toVector(blockDamaged);
if (!cfg.canBuild(player, pt)) {
if (!plugin.canBuild(player, blockDamaged.getLocation())) {
player.sendMessage(ChatColor.DARK_RED + "You're not invited to this tea party!");
event.setCancelled(true);
@ -122,8 +110,8 @@ public void onBlockBreak(BlockBreakEvent event) {
}
Player player = event.getPlayer();
GlobalConfiguration cfg = plugin.getGlobalConfiguration();
WorldConfiguration wcfg = cfg.getWorldConfig(player.getWorld().getName());
ConfigurationManager cfg = plugin.getGlobalConfiguration();
WorldConfiguration wcfg = cfg.forWorld(player.getWorld().getName());
if (!wcfg.itemDurability) {
ItemStack held = player.getItemInHand();
@ -134,9 +122,7 @@ public void onBlockBreak(BlockBreakEvent event) {
}
if (wcfg.useRegions) {
Vector pt = BukkitUtil.toVector(event.getBlock());
if (!cfg.canBuild(player, pt)) {
if (!plugin.canBuild(player, event.getBlock().getLocation())) {
player.sendMessage(ChatColor.DARK_RED + "You don't have permission for this area.");
event.setCancelled(true);
return;
@ -181,8 +167,8 @@ public void onBlockFlow(BlockFromToEvent event) {
boolean isWater = blockFrom.getTypeId() == 8 || blockFrom.getTypeId() == 9;
boolean isLava = blockFrom.getTypeId() == 10 || blockFrom.getTypeId() == 11;
GlobalConfiguration cfg = plugin.getGlobalConfiguration();
WorldConfiguration wcfg = cfg.getWorldConfig(event.getBlock().getWorld().getName());
ConfigurationManager cfg = plugin.getGlobalConfiguration();
WorldConfiguration wcfg = cfg.forWorld(event.getBlock().getWorld().getName());
if (wcfg.simulateSponge && isWater) {
int ox = blockTo.getX();
@ -270,8 +256,8 @@ public void onBlockIgnite(BlockIgniteEvent event) {
Block block = event.getBlock();
World world = block.getWorld();
GlobalConfiguration cfg = plugin.getGlobalConfiguration();
WorldConfiguration wcfg = cfg.getWorldConfig(world.getName());
ConfigurationManager cfg = plugin.getGlobalConfiguration();
WorldConfiguration wcfg = cfg.forWorld(world.getName());
boolean isFireSpread = cause == IgniteCause.SPREAD;
@ -358,8 +344,8 @@ public void onBlockBurn(BlockBurnEvent event) {
return;
}
GlobalConfiguration cfg = plugin.getGlobalConfiguration();
WorldConfiguration wcfg = cfg.getWorldConfig(event.getBlock().getWorld().getName());
ConfigurationManager cfg = plugin.getGlobalConfiguration();
WorldConfiguration wcfg = cfg.forWorld(event.getBlock().getWorld().getName());
if (wcfg.disableFireSpread) {
event.setCancelled(true);
@ -393,8 +379,8 @@ public void onBlockPhysics(BlockPhysicsEvent event) {
return;
}
GlobalConfiguration cfg = plugin.getGlobalConfiguration();
WorldConfiguration wcfg = cfg.getWorldConfig(event.getBlock().getWorld().getName());
ConfigurationManager cfg = plugin.getGlobalConfiguration();
WorldConfiguration wcfg = cfg.forWorld(event.getBlock().getWorld().getName());
int id = event.getChangedTypeId();
@ -497,13 +483,11 @@ public void onBlockPlace(BlockPlaceEvent event) {
Player player = event.getPlayer();
World world = blockPlaced.getWorld();
GlobalConfiguration cfg = plugin.getGlobalConfiguration();
WorldConfiguration wcfg = cfg.getWorldConfig(world.getName());
ConfigurationManager cfg = plugin.getGlobalConfiguration();
WorldConfiguration wcfg = cfg.forWorld(world.getName());
if (wcfg.useRegions) {
Vector pt = toVector(blockPlaced);
if (!cfg.canBuild(player, pt)) {
if (!plugin.canBuild(player, blockPlaced.getLocation())) {
player.sendMessage(ChatColor.DARK_RED + "You don't have permission for this area.");
event.setCancelled(true);
return;
@ -653,8 +637,8 @@ public void onBlockRedstoneChange(BlockRedstoneEvent event) {
Block blockTo = event.getBlock();
World world = blockTo.getWorld();
GlobalConfiguration cfg = plugin.getGlobalConfiguration();
WorldConfiguration wcfg = cfg.getWorldConfig(world.getName());
ConfigurationManager cfg = plugin.getGlobalConfiguration();
WorldConfiguration wcfg = cfg.forWorld(world.getName());
if (wcfg.simulateSponge && wcfg.redstoneSponges) {
int ox = blockTo.getX();
@ -690,8 +674,8 @@ public void onBlockRedstoneChange(BlockRedstoneEvent event) {
*/
private void clearSpongeWater(World world, int ox, int oy, int oz) {
GlobalConfiguration cfg = plugin.getGlobalConfiguration();
WorldConfiguration wcfg = cfg.getWorldConfig(world.getName());
ConfigurationManager cfg = plugin.getGlobalConfiguration();
WorldConfiguration wcfg = cfg.forWorld(world.getName());
for (int cx = -wcfg.spongeRadius; cx <= wcfg.spongeRadius; cx++) {
for (int cy = -wcfg.spongeRadius; cy <= wcfg.spongeRadius; cy++) {
@ -714,8 +698,8 @@ private void clearSpongeWater(World world, int ox, int oy, int oz) {
*/
private void addSpongeWater(World world, int ox, int oy, int oz) {
GlobalConfiguration cfg = plugin.getGlobalConfiguration();
WorldConfiguration wcfg = cfg.getWorldConfig(world.getName());
ConfigurationManager cfg = plugin.getGlobalConfiguration();
WorldConfiguration wcfg = cfg.forWorld(world.getName());
// The negative x edge
int cx = ox - wcfg.spongeRadius - 1;

View File

@ -74,13 +74,8 @@ public void onEntityDamageByBlock(EntityDamageByBlockEvent event) {
if (defender instanceof Player) {
Player player = (Player) defender;
GlobalConfiguration cfg = plugin.getGlobalConfiguration();
WorldConfiguration wcfg = cfg.getWorldConfig(player.getWorld().getName());
if (cfg.isInvinciblePlayer(player.getName())) {
event.setCancelled(true);
return;
}
ConfigurationManager cfg = plugin.getGlobalConfiguration();
WorldConfiguration wcfg = cfg.forWorld(player.getWorld().getName());
if (wcfg.disableLavaDamage && type == DamageCause.LAVA) {
event.setCancelled(true);
@ -102,13 +97,8 @@ public void onEntityDamageByEntity(EntityDamageByEntityEvent event) {
if (defender instanceof Player) {
Player player = (Player) defender;
GlobalConfiguration cfg = plugin.getGlobalConfiguration();
WorldConfiguration wcfg = cfg.getWorldConfig(player.getWorld().getName());
if (cfg.isInvinciblePlayer(player.getName())) {
event.setCancelled(true);
return;
}
ConfigurationManager cfg = plugin.getGlobalConfiguration();
WorldConfiguration wcfg = cfg.forWorld(player.getWorld().getName());
if (attacker != null && attacker instanceof Player) {
if (wcfg.useRegions) {
@ -158,13 +148,8 @@ public void onEntityDamageByProjectile(EntityDamageByProjectileEvent event) {
if (defender instanceof Player) {
Player player = (Player) defender;
GlobalConfiguration cfg = plugin.getGlobalConfiguration();
WorldConfiguration wcfg = cfg.getWorldConfig(player.getWorld().getName());
if (cfg.isInvinciblePlayer(player.getName())) {
event.setCancelled(true);
return;
}
ConfigurationManager cfg = plugin.getGlobalConfiguration();
WorldConfiguration wcfg = cfg.forWorld(player.getWorld().getName());
if (attacker != null && attacker instanceof Player) {
if (wcfg.useRegions) {
@ -217,13 +202,8 @@ public void onEntityDamage(EntityDamageEvent event) {
if (defender instanceof Player) {
Player player = (Player) defender;
GlobalConfiguration cfg = plugin.getGlobalConfiguration();
WorldConfiguration wcfg = cfg.getWorldConfig(player.getWorld().getName());
if (cfg.isInvinciblePlayer(player.getName())) {
event.setCancelled(true);
return;
}
ConfigurationManager cfg = plugin.getGlobalConfiguration();
WorldConfiguration wcfg = cfg.forWorld(player.getWorld().getName());
if (wcfg.disableFallDamage && type == DamageCause.FALL) {
event.setCancelled(true);
@ -251,12 +231,6 @@ public void onEntityDamage(EntityDamageEvent event) {
event.setCancelled(true);
return;
}
if (type == DamageCause.DROWNING
&& cfg.isAmphibiousPlayer(player.getName())) {
event.setCancelled(true);
return;
}
}
}
@ -267,9 +241,9 @@ public void onEntityExplode(EntityExplodeEvent event) {
return;
}
GlobalConfiguration cfg = plugin.getGlobalConfiguration();
ConfigurationManager cfg = plugin.getGlobalConfiguration();
Location l = event.getLocation();
WorldConfiguration wcfg = cfg.getWorldConfig(l.getWorld().getName());
WorldConfiguration wcfg = cfg.forWorld(l.getWorld().getName());
if (event.getEntity() instanceof LivingEntity) {
@ -317,8 +291,8 @@ public void onCreatureSpawn(CreatureSpawnEvent event) {
return;
}
GlobalConfiguration cfg = plugin.getGlobalConfiguration();
WorldConfiguration wcfg = cfg.getWorldConfig(event.getEntity().getWorld().getName());
ConfigurationManager cfg = plugin.getGlobalConfiguration();
WorldConfiguration wcfg = cfg.forWorld(event.getEntity().getWorld().getName());
//CreatureType creaType = (CreatureType) CreatureType.valueOf(event.getMobType().toString());
CreatureType creaType = event.getCreatureType();
@ -380,7 +354,7 @@ public void findFreePosition(Player player) {
loc.setX(x + 0.5);
loc.setY(y);
loc.setZ(z + 0.5);
player.teleportTo(loc);
player.teleport(loc);
}
return;

View File

@ -20,25 +20,14 @@
import static com.sk89q.worldguard.bukkit.BukkitUtil.toVector;
import org.bukkit.ChatColor;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.entity.Item;
import org.bukkit.entity.Player;
import org.bukkit.event.Event;
import org.bukkit.event.Event.Priority;
import org.bukkit.event.player.*;
import org.bukkit.inventory.ItemStack;
import org.bukkit.plugin.PluginManager;
import com.nijiko.coelho.iConomy.iConomy;
import com.sk89q.worldedit.Vector;
import com.sk89q.worldguard.LocalPlayer;
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.protection.ApplicableRegionSet;
import com.sk89q.worldguard.protection.flags.DefaultFlag;
import com.sk89q.worldguard.protection.managers.RegionManager;
/**
* Handles all events thrown in relation to a Player
@ -49,7 +38,6 @@ public class WorldGuardPlayerListener extends PlayerListener {
* Plugin.
*/
private WorldGuardPlugin plugin;
private boolean checkediConomy = false;
/**
* Construct the object;
@ -83,21 +71,13 @@ public void registerEvents() {
public void onPlayerJoin(PlayerEvent event) {
Player player = event.getPlayer();
GlobalConfiguration cfg = plugin.getGlobalConfiguration();
WorldConfiguration wcfg = cfg.getWorldConfig(player.getWorld().getName());
ConfigurationManager cfg = plugin.getGlobalConfiguration();
WorldConfiguration wcfg = cfg.forWorld(player.getWorld().getName());
if (wcfg.fireSpreadDisableToggle) {
player.sendMessage(ChatColor.YELLOW
+ "Fire spread is currently globally disabled.");
}
if (plugin.inGroup(player, "wg-invincible")) {
cfg.addInvinciblePlayer(player.getName());
}
if (plugin.inGroup(player, "wg-amphibious")) {
cfg.addAmphibiousPlayer(player.getName());
}
}
/**
@ -109,11 +89,7 @@ public void onPlayerJoin(PlayerEvent event) {
public void onPlayerQuit(PlayerEvent event) {
Player player = event.getPlayer();
GlobalConfiguration cfg = plugin.getGlobalConfiguration();
cfg.removeInvinciblePlayer(player.getName());
cfg.removeAmphibiousPlayer(player.getName());
ConfigurationManager cfg = plugin.getGlobalConfiguration();
cfg.forgetPlayer(plugin.wrapPlayer(player));
}
@ -195,8 +171,8 @@ public void onPlayerItem(PlayerItemEvent event) {
public void onPlayerLogin(PlayerLoginEvent event) {
Player player = event.getPlayer();
GlobalConfiguration cfg = plugin.getGlobalConfiguration();
WorldConfiguration wcfg = cfg.getWorldConfig(player.getWorld().getName());
ConfigurationManager cfg = plugin.getGlobalConfiguration();
WorldConfiguration wcfg = cfg.forWorld(player.getWorld().getName());
if (wcfg.enforceOneSession) {
String name = player.getName();
@ -207,15 +183,6 @@ public void onPlayerLogin(PlayerLoginEvent event) {
}
}
}
if (!checkediConomy) {
iConomy iconomy = (iConomy) plugin.getServer().getPluginManager().getPlugin("iConomy");
if (iconomy != null) {
plugin.getGlobalConfiguration().setiConomy(iconomy);
}
checkediConomy = true;
}
}
/**
@ -230,8 +197,8 @@ public void onPlayerDropItem(PlayerDropItemEvent event) {
return;
}
GlobalConfiguration cfg = plugin.getGlobalConfiguration();
WorldConfiguration wcfg = cfg.getWorldConfig(event.getPlayer().getWorld().getName());
ConfigurationManager cfg = plugin.getGlobalConfiguration();
WorldConfiguration wcfg = cfg.forWorld(event.getPlayer().getWorld().getName());
if (wcfg.getBlacklist() != null) {
Item ci = event.getItemDrop();
@ -257,8 +224,8 @@ public void onPlayerPickupItem(PlayerPickupItemEvent event) {
return;
}
GlobalConfiguration cfg = plugin.getGlobalConfiguration();
WorldConfiguration wcfg = cfg.getWorldConfig(event.getPlayer().getWorld().getName());
ConfigurationManager cfg = plugin.getGlobalConfiguration();
WorldConfiguration wcfg = cfg.forWorld(event.getPlayer().getWorld().getName());
if (wcfg.getBlacklist() != null) {
Item ci = event.getItem();

View File

@ -16,92 +16,77 @@
* 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 org.bukkit.ChatColor;
import org.bukkit.Location;
import org.bukkit.World;
import org.bukkit.World.Environment;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.command.ConsoleCommandSender;
import org.bukkit.entity.Player;
import org.bukkit.plugin.Plugin;
import org.bukkit.plugin.java.JavaPlugin;
import com.sk89q.bukkit.migration.PermissionsResolverManager;
import com.sk89q.bukkit.migration.PermissionsResolverServerListener;
import com.sk89q.minecraft.util.commands.CommandException;
import com.sk89q.minecraft.util.commands.CommandPermissionsException;
import com.sk89q.minecraft.util.commands.CommandsManager;
import com.sk89q.bukkit.migration.*;
import com.sk89q.minecraft.util.commands.*;
import com.sk89q.worldedit.bukkit.WorldEditPlugin;
import com.sk89q.worldguard.LocalPlayer;
import com.sk89q.worldguard.protection.GlobalRegionManager;
import com.sk89q.worldguard.protection.TimedFlagsTimer;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Iterator;
import java.util.List;
import com.sk89q.worldguard.TickSyncDelayLoggerFilter;
import com.sk89q.worldguard.bukkit.commands.ProtectionCommands;
import com.sk89q.worldguard.bukkit.commands.ToggleCommands;
import com.sk89q.worldguard.protection.*;
import com.sk89q.worldguard.protection.managers.RegionManager;
import java.io.*;
import java.util.*;
import java.util.logging.Filter;
import java.util.logging.Logger;
/**
* Plugin for Bukkit.
* The main class for WorldGuard as a Bukkit plugin.
*
* @author sk89q
*/
public class WorldGuardPlugin extends JavaPlugin {
/**
* Logger for messages.
*/
protected static final Logger logger = Logger.getLogger("Minecraft.WorldGuard");
/**
* List of commands.
* Manager for commands. This automatically handles nested commands,
* permissions checking, and a number of other fancy command things.
* We just set it up and register commands against it.
*/
protected CommandsManager<CommandSender> commands;
protected final CommandsManager<CommandSender> commands;
/**
* Handles the region databases for all worlds.
*/
protected GlobalRegionManager globalRegionManager;
protected final GlobalRegionManager globalRegionManager;
/**
* Handles all configuration.
*/
protected GlobalConfiguration configuration;
protected final ConfigurationManager configuration;
/**
* Processes queries for permissions information.
* Processes queries for permissions information. The permissions manager
* is from WorldEdit and it automatically handles looking up permissions
* systems and picking the right one. WorldGuard just needs to call
* the permission methods.
*/
protected PermissionsResolverManager perms;
/**
* Called on plugin enable.
* Construct objects. Actual loading occurs when the plugin is enabled, so
* this merely instantiates the objects.
*/
public void onEnable() {
getDataFolder().mkdirs();
public WorldGuardPlugin() {
configuration = new ConfigurationManager(this);
globalRegionManager = new GlobalRegionManager(this);
configuration = new GlobalConfiguration(this);
configuration.load();
globalRegionManager = new GlobalRegionManager();
for (World world : getServer().getWorlds()) {
globalRegionManager.load(world.getName());
}
// Register events
(new WorldGuardPlayerListener(this)).registerEvents();
(new WorldGuardBlockListener(this)).registerEvents();
(new WorldGuardEntityListener(this)).registerEvents();
(new WorldGuardVehicleListener(this)).registerEvents();
// 25 equals about 1s real time
this.getServer().getScheduler().scheduleSyncRepeatingTask(
this, new TimedFlagsTimer(this), 25 * 5, 25 * 5);
// Register the commands that we want to use
final WorldGuardPlugin plugin = this;
commands = new CommandsManager<CommandSender>() {
@Override
@ -110,12 +95,57 @@ public boolean hasPermission(CommandSender player, String perm) {
}
};
// Register command classes
commands.register(ToggleCommands.class);
commands.register(ProtectionCommands.class);
// Set up permissions
perms = new PermissionsResolverManager(
getConfiguration(), getServer(), "WorldGuard", logger);
}
/**
* Called on plugin enable.
*/
public void onEnable() {
// Need to create the plugins/WorldGuard folder
getDataFolder().mkdirs();
// This must be done before configuration is laoded
LegacyWorldGuardMigration.migrateBlacklist(this);
// Load the configuration
configuration.load();
globalRegionManager.preload();
// Migrate regions after the regions were loaded because
// the migration code reuses the loaded region managers
LegacyWorldGuardMigration.migrateRegions(this);
// Load permissions
(new PermissionsResolverServerListener(perms)).register(this);
perms.load();
// Register events
(new WorldGuardPlayerListener(this)).registerEvents();
(new WorldGuardBlockListener(this)).registerEvents();
(new WorldGuardEntityListener(this)).registerEvents();
(new WorldGuardVehicleListener(this)).registerEvents();
// 25 equals about 1s real time
getServer().getScheduler().scheduleSyncRepeatingTask(
this, new TimedFlagsTimer(this), 25 * 5, 25 * 5);
if (configuration.suppressTickSyncWarnings) {
Logger.getLogger("Minecraft").setFilter(
new TickSyncDelayLoggerFilter());
} else {
Filter filter = Logger.getLogger("Minecraft").getFilter();
if (filter != null && filter instanceof TickSyncDelayLoggerFilter) {
Logger.getLogger("Minecraft").setFilter(null);
}
}
logger.info("WorldGuard " + this.getDescription().getVersion() + " enabled.");
}
@ -129,6 +159,34 @@ public void onDisable() {
logger.info("WorldGuard " + getDescription().getVersion() + " disabled.");
}
/**
* Handle a command.
*/
@Override
public boolean onCommand(CommandSender sender, Command cmd, String label,
String[] args) {
try {
commands.execute(cmd.getName(), args, sender, this, sender);
} catch (CommandPermissionsException e) {
sender.sendMessage(ChatColor.RED + "You don't have permission.");
} catch (MissingNestedCommandException e) {
sender.sendMessage(ChatColor.RED + e.getUsage());
} catch (CommandUsageException e) {
sender.sendMessage(ChatColor.RED + e.getMessage());
sender.sendMessage(ChatColor.RED + e.getUsage());
} catch (WrappedCommandException e) {
if (e.getCause() instanceof NumberFormatException) {
sender.sendMessage(ChatColor.RED + "Number expected, string received instead.");
} else {
sender.sendMessage(ChatColor.RED + "An error has occurred. See console.");
e.printStackTrace();
}
} catch (CommandException e) {
sender.sendMessage(ChatColor.RED + e.getMessage());
}
return true;
}
/**
* Get the GlobalRegionManager.
@ -144,7 +202,7 @@ public GlobalRegionManager getGlobalRegionManager() {
*
* @return
*/
public GlobalConfiguration getGlobalConfiguration() {
public ConfigurationManager getGlobalConfiguration() {
return configuration;
}
@ -528,6 +586,48 @@ public WorldEditPlugin getWorldEdit() throws CommandException {
throw new CommandException("WorldEdit detection failed (report error).");
}
}
/**
* Check if a player has permission to build at a location.
*
* @param player
* @param loc
* @return
*/
public boolean canBuild(Player player, Location loc) {
WorldConfiguration worldConfig =
configuration.forWorld(loc.getWorld().getName());
if (worldConfig.useRegions) {
LocalPlayer localPlayer = wrapPlayer(player);
if (!hasPermission(player, "region.bypass")) {
RegionManager mgr = getGlobalRegionManager()
.get(player.getWorld().getName());
if (!mgr.getApplicableRegions(BukkitUtil.toVector(loc))
.canBuild(localPlayer)) {
return false;
}
}
return true;
} else {
return true;
}
}
/**
* Check if a player has permission to build at a location.
*
* @param player
* @param x
* @param y
* @param z
* @return
*/
public boolean canBuild(Player player, int x, int y, int z) {
return canBuild(player, new Location(player.getWorld(), x, y, z));
}
/**
* Wrap a player as a LocalPlayer.
@ -573,7 +673,7 @@ public static void createDefaultConfiguration(File actual,
}
logger.info("WorldGuard: Default configuration file written: "
+ defaultName);
+ actual.getAbsolutePath());
} catch (IOException e) {
e.printStackTrace();
} finally {

View File

@ -69,8 +69,7 @@ public void onVehicleCreate(VehicleCreateEvent event) {
Vector pt = new Vector(vhclLoc.getBlockX(), vhclLoc.getBlockY(), vhclLoc.getBlockZ());
if (vhcl instanceof Minecart || vhcl instanceof Boat) {
GlobalConfiguration cfg = plugin.getGlobalConfiguration();
RegionManager mgr = cfg.getWorldGuardPlugin().getGlobalRegionManager().get(vhcl.getWorld().getName());
RegionManager mgr = plugin.getGlobalRegionManager().get(vhcl.getWorld().getName());
ApplicableRegionSet applicableRegions = mgr.getApplicableRegions(pt);
if (!applicableRegions.allows(DefaultFlag.PLACE_VEHICLE)) {

View File

@ -0,0 +1,33 @@
// $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.commands;
import org.bukkit.command.CommandSender;
import com.sk89q.minecraft.util.commands.*;
import com.sk89q.worldguard.bukkit.WorldGuardPlugin;
public class ProtectionCommands {
@Command(aliases = {"region"},
desc = "Region management commands")
@NestedCommand({RegionCommands.class})
public static void region(CommandContext args, WorldGuardPlugin plugin,
CommandSender sender) throws CommandException {
}
}

View File

@ -24,8 +24,6 @@
import org.bukkit.World;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import com.nijiko.coelho.iConomy.iConomy;
import com.nijiko.coelho.iConomy.system.Account;
import com.sk89q.minecraft.util.commands.*;
import com.sk89q.worldedit.BlockVector;
import com.sk89q.worldedit.bukkit.WorldEditPlugin;
@ -139,7 +137,7 @@ public static void claim(CommandContext args, WorldGuardPlugin plugin,
}
WorldConfiguration wcfg = plugin.getGlobalConfiguration()
.getWorldConfig(player.getWorld().getName());
.forWorld(player.getWorld().getName());
RegionManager mgr = plugin.getGlobalRegionManager().get(
sel.getWorld().getName());
@ -174,7 +172,7 @@ public static void claim(CommandContext args, WorldGuardPlugin plugin,
}
}*/
if (plugin.getGlobalConfiguration().getiConomy() != null && wcfg.useiConomy && wcfg.buyOnClaim) {
/*if (plugin.getGlobalConfiguration().getiConomy() != null && wcfg.useiConomy && wcfg.buyOnClaim) {
if (iConomy.getBank().hasAccount(player.getName())) {
Account account = iConomy.getBank().getAccount(player.getName());
double balance = account.getBalance();
@ -195,7 +193,7 @@ public static void claim(CommandContext args, WorldGuardPlugin plugin,
player.sendMessage(ChatColor.YELLOW + "You have not enough money.");
return;
}
}
}*/
if (region.countBlocks() > wcfg.maxClaimVolume) {
player.sendMessage(ChatColor.RED + "This region is to large to claim.");

View File

@ -44,7 +44,7 @@ public static void stopFire(CommandContext args, WorldGuardPlugin plugin,
}
WorldConfiguration wcfg = plugin.getGlobalConfiguration()
.getWorldConfig(world.getName());
.forWorld(world.getName());
if (!wcfg.fireSpreadDisableToggle) {
plugin.getServer().broadcastMessage(
@ -76,7 +76,7 @@ public static void allowFire(CommandContext args, WorldGuardPlugin plugin,
}
WorldConfiguration wcfg = plugin.getGlobalConfiguration()
.getWorldConfig(world.getName());
.forWorld(world.getName());
if (wcfg.fireSpreadDisableToggle) {
plugin.getServer().broadcastMessage(ChatColor.YELLOW

View File

@ -18,6 +18,7 @@
*/
package com.sk89q.worldguard.protection;
import com.sk89q.worldguard.bukkit.WorldGuardPlugin;
import com.sk89q.worldguard.protection.databases.JSONDatabase;
import com.sk89q.worldguard.protection.managers.FlatRegionManager;
import com.sk89q.worldguard.protection.managers.RegionManager;
@ -26,6 +27,7 @@
import java.io.IOException;
import java.util.HashMap;
import java.util.logging.Logger;
import org.bukkit.World;
/**
* This class keeps track of region information for every world. It loads
@ -39,9 +41,9 @@ public class GlobalRegionManager {
private static final Logger logger = Logger.getLogger("Minecraft.WorldGuard");
/**
* Path to the folder that region data is stored within.
* Reference to the plugin.
*/
protected File dataFolder;
private WorldGuardPlugin plugin;
/**
* Map of managers per-world.
@ -56,8 +58,11 @@ public class GlobalRegionManager {
/**
* Construct the object.
*
* @param plugin
*/
public GlobalRegionManager() {
public GlobalRegionManager(WorldGuardPlugin plugin) {
this.plugin = plugin;
managers = new HashMap<String, RegionManager>();
lastModified = new HashMap<String, Long>();
}
@ -77,8 +82,8 @@ public void unload() {
* @return
*/
protected File getPath(String name) {
return new File(dataFolder,
"name" + File.separator + "regions.json");
return new File(plugin.getDataFolder(),
"worlds" + File.separator + name + File.separator + "regions.json");
}
/**
@ -126,6 +131,16 @@ public void load(String name) {
}
}
/**
* Preloads region managers for all worlds.
*/
public void preload() {
// Load regions
for (World world : plugin.getServer().getWorlds()) {
load(world.getName());
}
}
/**
* Reloads the region information from file when region databases
* have changed.

View File

@ -15,7 +15,7 @@
*
* 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.databases;
@ -23,10 +23,12 @@
import com.google.gson.Gson;
import com.sk89q.worldguard.protection.regions.ProtectedRegion;
import java.io.BufferedInputStream;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileWriter;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.util.Map;
import java.util.logging.Logger;
@ -46,11 +48,11 @@ public class JSONDatabase implements ProtectionDatabase {
/**
* Holds the list of regions.
*/
private Map<String,ProtectedRegion> regions;
private Map<String, ProtectedRegion> regions;
/**
* Construct the database with a path to a file. No file is read or
* written at this time.
* Construct the database with a path to a file. No file is read or written
* at this time.
*
* @param file
*/
@ -61,11 +63,13 @@ public JSONDatabase(File file) {
/**
* Helper function to read a file into a String
*/
private static String readFileAsString(File file) throws java.io.IOException {
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 = new BufferedInputStream(new FileInputStream(
file.getAbsolutePath()));
f.read(buffer);
} finally {
if (f != null) {
@ -76,10 +80,8 @@ private static String readFileAsString(File file) throws java.io.IOException {
}
}
for(int i = 0; i < buffer.length; i++)
{
if(buffer[i] < 0x20 || buffer[i] > 0x126)
{
for (int i = 0; i < buffer.length; i++) {
if (buffer[i] < 0x20 || buffer[i] > 0x126) {
buffer[i] = 0x20;
}
}
@ -93,7 +95,8 @@ private static String readFileAsString(File file) throws java.io.IOException {
public void load() throws IOException {
Gson gson = new Gson();
JSONContainer jContainer = gson.fromJson(readFileAsString(file), JSONContainer.class);
JSONContainer jContainer = gson.fromJson(readFileAsString(file),
JSONContainer.class);
this.regions = jContainer.getRegions();
}
@ -103,11 +106,11 @@ public void load() throws IOException {
public void save() throws IOException {
Gson gson = new Gson();
String jsonData = gson.toJson(new JSONContainer(this.regions), JSONContainer.class);
String jsonData = gson.toJson(new JSONContainer(this.regions),
JSONContainer.class);
writeStringToFile(jsonData, this.file);
}
/**
* Writes a String to a file.
*
@ -115,21 +118,25 @@ public void save() throws IOException {
* @param file
* @throws IOException
*/
public static void writeStringToFile(String string, File file) throws IOException {
FileWriter writer = null;
public static void writeStringToFile(String string, File file)
throws IOException {
FileOutputStream output = null;
try {
writer = new FileWriter(file);
output = new FileOutputStream(file);
OutputStreamWriter streamWriter = new OutputStreamWriter(output, "utf-8");
BufferedWriter writer = new BufferedWriter(streamWriter);
writer.write(string);
} finally {
try {
if (writer != null) {
writer.close();
}
} finally {
if (output != null) {
try {
output.close();
} catch (IOException e) {
}
}
}
}
/**
* Load the list of regions into a region manager.
@ -156,14 +163,14 @@ public void save(RegionManager manager) throws IOException {
*
* @return
*/
public Map<String,ProtectedRegion> getRegions() {
public Map<String, ProtectedRegion> getRegions() {
return regions;
}
/**
* Get a list of protected regions.
*/
public void setRegions(Map<String,ProtectedRegion> regions) {
public void setRegions(Map<String, ProtectedRegion> regions) {
this.regions = regions;
}
}

View File

@ -75,4 +75,9 @@ public String[] getGroups() {
// TODO Auto-generated method stub
return null;
}
@Override
public boolean hasPermission(String perm) {
return true;
}
}