Refactor region API with new RegionContainer object.

This commit is contained in:
sk89q 2014-08-14 01:24:38 -07:00
parent ad1c10a3e9
commit 99660920d7
28 changed files with 1431 additions and 1116 deletions

View File

@ -21,7 +21,8 @@
import com.sk89q.worldguard.blacklist.Blacklist;
public class BukkitBlacklist extends Blacklist {
class BukkitBlacklist extends Blacklist {
private WorldGuardPlugin plugin;
public BukkitBlacklist(Boolean useAsWhitelist, WorldGuardPlugin plugin) {
@ -33,4 +34,5 @@ public BukkitBlacklist(Boolean useAsWhitelist, WorldGuardPlugin plugin) {
public void broadcastNotification(String msg) {
plugin.broadcastNotification(msg);
}
}

View File

@ -17,10 +17,9 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.sk89q.worldguard.protection;
package com.sk89q.worldguard.bukkit;
import com.google.common.base.Supplier;
import com.sk89q.worldguard.bukkit.ConfigurationManager;
import com.sk89q.worldguard.protection.managers.RegionManager;
import com.sk89q.worldguard.protection.managers.index.ChunkHashTable;
import com.sk89q.worldguard.protection.managers.index.ConcurrentRegionIndex;
@ -54,16 +53,29 @@ class ManagerContainer {
private static final Logger log = Logger.getLogger(ManagerContainer.class.getCanonicalName());
private static final int SAVE_INTERVAL = 1000 * 30;
private final ConfigurationManager config;
private final ConcurrentMap<Normal, RegionManager> mapping = new ConcurrentHashMap<Normal, RegionManager>();
private final Object lock = new Object();
private final EnumMap<DriverType, RegionStoreDriver> drivers = new EnumMap<DriverType, RegionStoreDriver>(DriverType.class);
private final RegionStoreDriver defaultDriver;
private RegionStoreDriver defaultDriver;
private final Supplier<? extends ConcurrentRegionIndex> indexFactory = new ChunkHashTable.Factory(new PriorityRTreeIndex.Factory());
private final Timer timer = new Timer();
/**
* Create a new instance.
*
* @param config the configuration
*/
ManagerContainer(ConfigurationManager config) {
checkNotNull(config);
this.config = config;
timer.schedule(new BackgroundSaver(), SAVE_INTERVAL, SAVE_INTERVAL);
}
/**
* Create drivers from the configuration.
*/
public void initialize() {
for (DriverType type : DriverType.values()) {
drivers.put(type, type.create(config));
}
@ -73,10 +85,15 @@ class ManagerContainer {
} else {
defaultDriver = drivers.get(DriverType.YAML);
}
timer.schedule(new BackgroundSaver(), SAVE_INTERVAL, SAVE_INTERVAL);
}
/**
* Load the {@code RegionManager} for the world with the given name,
* creating a new instance for the world if one does not exist yet.
*
* @param name the name of the world
* @return a region manager, or {@code null} if loading failed
*/
@Nullable
public RegionManager load(String name) {
checkNotNull(name);
@ -100,6 +117,13 @@ public RegionManager load(String name) {
}
}
/**
* Create a new region manager and load the data.
*
* @param name the name of the world
* @return a region manager
* @throws IOException thrown if loading fals
*/
private RegionManager createAndLoad(String name) throws IOException {
RegionStore store = defaultDriver.get(name);
RegionManager manager = new RegionManager(store, indexFactory);
@ -107,6 +131,14 @@ private RegionManager createAndLoad(String name) throws IOException {
return manager;
}
/**
* Unload the region manager associated with the given world name.
*
* <p>If no region manager has been loaded for the given name, then
* nothing will happen.</p>
*
* @param name the name of the world
*/
public void unload(String name) {
checkNotNull(name);
@ -120,11 +152,16 @@ public void unload(String name) {
} catch (IOException e) {
log.log(Level.WARNING, "Failed to save the region data for '" + name + "'", e);
}
}
mapping.remove(normal);
}
}
}
/**
* Unload all region managers and save their contents before returning.
* This message may block for an extended period of time.
*/
public void unloadAll() {
synchronized (lock) {
for (Map.Entry<Normal, RegionManager> entry : mapping.entrySet()) {
@ -141,16 +178,30 @@ public void unloadAll() {
}
}
/**
* Get the region manager for the given world name.
*
* @param name the name of the world
* @return a region manager, or {@code null} if one was never loaded
*/
@Nullable
public RegionManager get(String name) {
checkNotNull(name);
return mapping.get(Normal.normal(name));
}
/**
* Get an immutable list of loaded region managers.
*
* @return an immutable list
*/
public List<RegionManager> getLoaded() {
return Collections.unmodifiableList(new ArrayList<RegionManager>(mapping.values()));
}
/**
* A task to save managers in the background.
*/
private class BackgroundSaver extends TimerTask {
@Override
public void run() {

View File

@ -0,0 +1,242 @@
/*
* WorldGuard, a suite of tools for Minecraft
* Copyright (C) sk89q <http://www.sk89q.com>
* Copyright (C) WorldGuard team and contributors
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU Lesser 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 Lesser General Public License
* for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.sk89q.worldguard.bukkit;
import com.sk89q.worldedit.Vector2D;
import com.sk89q.worldguard.LocalPlayer;
import com.sk89q.worldguard.protection.managers.RegionManager;
import org.bukkit.Bukkit;
import org.bukkit.Chunk;
import org.bukkit.World;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.world.ChunkLoadEvent;
import org.bukkit.event.world.ChunkUnloadEvent;
import org.bukkit.event.world.WorldLoadEvent;
import org.bukkit.event.world.WorldUnloadEvent;
import javax.annotation.Nullable;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import static com.google.common.base.Preconditions.checkNotNull;
/**
* A region container creates {@link RegionManager}s for loaded worlds, which
* allows access to the region data of a world. Generally, only data is
* loaded for worlds that are loaded in the server.
*
* <p>This class is thread safe and its contents can be accessed from
* multiple concurrent threads.</p>
*
* <p>An instance of this class can be retrieved using
* {@link WorldGuardPlugin#getRegionContainer()}.</p>
*/
public class RegionContainer {
private final Object lock = new Object();
private final WorldGuardPlugin plugin;
private final ManagerContainer container;
/**
* Create a new instance.
*
* @param plugin the plugin
*/
RegionContainer(WorldGuardPlugin plugin) {
this.plugin = plugin;
ConfigurationManager config = plugin.getGlobalStateManager();
container = new ManagerContainer(config);
}
/**
* Initialize the region container.
*/
void initialize() {
container.initialize();
loadWorlds();
Bukkit.getPluginManager().registerEvents(new Listener() {
@EventHandler
public void onWorldLoad(WorldLoadEvent event) {
load(event.getWorld());
}
@EventHandler
public void onWorldUnload(WorldUnloadEvent event) {
unload(event.getWorld());
}
@EventHandler
public void onChunkLoad(ChunkLoadEvent event) {
RegionManager manager = get(event.getWorld());
if (manager != null) {
Chunk chunk = event.getChunk();
manager.loadChunk(new Vector2D(chunk.getX(), chunk.getZ()));
}
}
@EventHandler
public void onChunkUnload(ChunkUnloadEvent event) {
RegionManager manager = get(event.getWorld());
if (manager != null) {
Chunk chunk = event.getChunk();
manager.unloadChunk(new Vector2D(chunk.getX(), chunk.getZ()));
}
}
}, plugin);
}
/**
* Save data and unload.
*/
void unload() {
synchronized (lock) {
container.unloadAll();
}
}
/**
* Try loading the region managers for all currently loaded worlds.
*/
private void loadWorlds() {
synchronized (lock) {
for (World world : Bukkit.getServer().getWorlds()) {
load(world);
}
}
}
/**
* Reload the region container.
*
* <p>This method may block until the data for all loaded worlds has been
* unloaded and new data has been loaded.</p>
*/
public void reload() {
synchronized (lock) {
unload();
loadWorlds();
}
}
/**
* Load the region data for a world if it has not been loaded already.
*
* @param world the world
* @return a region manager, either returned from the cache or newly loaded
*/
@Nullable
private RegionManager load(World world) {
checkNotNull(world);
RegionManager manager;
synchronized (lock) {
manager = container.load(world.getName());
if (manager != null) {
// Bias the region data for loaded chunks
List<Vector2D> positions = new ArrayList<Vector2D>();
for (Chunk chunk : world.getLoadedChunks()) {
positions.add(new Vector2D(chunk.getX(), chunk.getZ()));
}
manager.loadChunks(positions);
}
}
return manager;
}
/**
* Unload the region data for a world.
*
* @param world a world
*/
void unload(World world) {
checkNotNull(world);
synchronized (lock) {
container.unload(world.getName());
}
}
/**
* Get the region manager for a world if one exists.
*
* <p>This method may return {@code null} if region data for the given
* world has not been loaded, has failed to load, or support for regions
* has been disabled. If you merely want to query flags or a list of
* regions in a position, using {@link #createQuery(Player)} is much
* simpler and it will handle the case of a {@code null}
* {@code RegionManager}. That said, if you wish to make changes to
* regions, then you will have to get a region manager.</p>
*
* @param world the world
* @return a region manager, or {@code null} if one is not available
*/
@Nullable
public RegionManager get(World world) {
return container.get(world.getName());
}
/**
* Get an immutable list of loaded {@link RegionManager}s.
*
* @return a list of managers
*/
public List<RegionManager> getLoaded() {
return Collections.unmodifiableList(container.getLoaded());
}
/**
* Create a new region query with no player.
*
* @return a new query
*/
public RegionQuery createAnonymousQuery() {
return new RegionQuery(plugin, (Player) null);
}
/**
* Create a new region query.
*
* @param player a player, or {@code null}
* @return a new query
*/
public RegionQuery createQuery(@Nullable Player player) {
return new RegionQuery(plugin, player);
}
/**
* Create a new region query.
*
* @param player a player, or {@code null}
* @return a new query
*/
public RegionQuery createQuery(@Nullable LocalPlayer player) {
return new RegionQuery(plugin, player);
}
}

View File

@ -0,0 +1,196 @@
/*
* WorldGuard, a suite of tools for Minecraft
* Copyright (C) sk89q <http://www.sk89q.com>
* Copyright (C) WorldGuard team and contributors
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU Lesser 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 Lesser General Public License
* for more details.
*
* You should have received a copy of the GNU Lesser 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.protection.ApplicableRegionSet;
import com.sk89q.worldguard.protection.GlobalRegionManager;
import com.sk89q.worldguard.protection.flags.DefaultFlag;
import com.sk89q.worldguard.protection.flags.StateFlag;
import com.sk89q.worldguard.protection.managers.RegionManager;
import org.bukkit.Location;
import org.bukkit.World;
import org.bukkit.entity.Player;
import javax.annotation.Nullable;
import static com.google.common.base.Preconditions.checkNotNull;
/**
* This object allows easy spatial queries involving region data.
*
* <p>Results may be cached for brief amounts of time.</p>
*/
public class RegionQuery {
private final ConfigurationManager config;
private final GlobalRegionManager globalManager;
@Nullable
private final LocalPlayer localPlayer;
/**
* Create a new instance.
*
* @param plugin the plugin
* @param player an optional player
*/
RegionQuery(WorldGuardPlugin plugin, @Nullable Player player) {
this(plugin, player != null ? plugin.wrapPlayer(player) : null);
}
/**
* Create a new instance.
*
* @param plugin the plugin
* @param player an optional player
*/
RegionQuery(WorldGuardPlugin plugin, @Nullable LocalPlayer player) {
checkNotNull(plugin);
this.config = plugin.getGlobalStateManager();
//noinspection deprecation
this.globalManager = plugin.getGlobalRegionManager();
this.localPlayer = player;
}
/**
* Test whether the player (which must not be {@code null} can build at
* the given location, using only the membership information and the state
* of the {@link DefaultFlag#BUILD} flag to determine status.
*
* <p>This method is used to check blocks and entities for which there
* are no other related flags for (i.e. beds have the
* {@link DefaultFlag#SLEEP} flag).</p>
*
* <p>If region data is not available (it failed to load or region support
* is disabled), then either {@code true} or {@code false} may be returned
* depending on the configuration.</p>
*
* @param location the location
* @return true if building is permitted
* @throws NullPointerException if there is no player for this query
*/
public boolean testPermission(Location location) {
checkNotNull(location);
checkNotNull(localPlayer, "testPermission() requires a player for the query");
World world = location.getWorld();
WorldConfiguration worldConfig = config.get(world);
if (!worldConfig.useRegions) {
return true;
}
if (globalManager.hasBypass(localPlayer, world)) {
return true;
} else {
RegionManager manager = globalManager.get(location.getWorld());
return manager == null || manager.getApplicableRegions(BukkitUtil.toVector(location)).canBuild(localPlayer);
}
}
/**
* Test whether the player (which must not be {@code null} can build at
* the given location, using the membership information, state
* of the {@link DefaultFlag#BUILD} flag, and the state of any passed
* flags.
*
* <p>This method is used to check blocks and entities for which there
* are other related flags for (i.e. beds have the
* {@link DefaultFlag#SLEEP} flag). The criteria under which this method
* returns true is subject to change (i.e. all flags must be true or
* one cannot be DENY, etc.).</p>
*
* <p>If region data is not available (it failed to load or region support
* is disabled), then either {@code true} or {@code false} may be returned
* depending on the configuration.</p>
*
* @param location the location to test
* @param flags an array of flags
* @return true if the flag tests true
*/
public boolean testPermission(Location location, StateFlag... flags) {
checkNotNull(location);
checkNotNull(flags);
checkNotNull(localPlayer, "testPermission() requires a player for the query");
World world = location.getWorld();
WorldConfiguration worldConfig = config.get(world);
if (!worldConfig.useRegions) {
return true;
}
RegionManager manager = globalManager.get(location.getWorld());
if (manager != null) {
ApplicableRegionSet result = manager.getApplicableRegions(BukkitUtil.toVector(location));
if (result.canBuild(localPlayer)) {
return true;
}
for (StateFlag flag : flags) {
if (result.allows(flag, localPlayer)) {
return true;
}
}
return false;
} else{
return true; // null manager -> return true for now
}
}
/**
* Test whether a {@link StateFlag} is evaluates to {@code ALLOW}.
*
* <p>This method is to check whether certain functionality
* is enabled (i.e. water flow). The player, if provided, may be used
* in evaluation of the flag.</p>
*
* <p>If region data is not available (it failed to load or region support
* is disabled), then either {@code true} or {@code false} may be returned
* depending on the configuration.</p>
*
* @param location the location
* @param flag the flag
* @return true if the flag evaluates to {@code ALLOW}
*/
public boolean testEnabled(Location location, StateFlag flag) {
checkNotNull(location);
checkNotNull(flag);
World world = location.getWorld();
WorldConfiguration worldConfig = config.get(world);
if (!worldConfig.useRegions) {
return true;
}
if (globalManager.hasBypass(localPlayer, world)) {
return true;
} else {
RegionManager manager = globalManager.get(location.getWorld());
return manager == null || manager.getApplicableRegions(BukkitUtil.toVector(location)).allows(flag, localPlayer);
}
}
}

View File

@ -53,6 +53,7 @@
import com.sk89q.worldguard.bukkit.listener.ChestProtectionListener;
import com.sk89q.worldguard.bukkit.listener.DebuggingListener;
import com.sk89q.worldguard.bukkit.listener.EventAbstractionListener;
import com.sk89q.worldguard.bukkit.listener.FlagStateManager;
import com.sk89q.worldguard.bukkit.listener.RegionProtectionListener;
import com.sk89q.worldguard.bukkit.listener.WorldGuardBlockListener;
import com.sk89q.worldguard.bukkit.listener.WorldGuardCommandBookListener;
@ -69,7 +70,6 @@
import com.sk89q.worldguard.protection.util.migrator.MigrationException;
import com.sk89q.worldguard.protection.util.migrator.UUIDMigrator;
import com.sk89q.worldguard.util.FatalConfigurationLoadingException;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Location;
import org.bukkit.World;
@ -109,8 +109,9 @@ public class WorldGuardPlugin extends JavaPlugin {
private static WorldGuardPlugin inst;
private final CommandsManager<CommandSender> commands;
private GlobalRegionManager globalRegionManager;
private ConfigurationManager configuration;
private final ConfigurationManager configuration = new ConfigurationManager(this);
private final RegionContainer regionContainer = new RegionContainer(this);
private final GlobalRegionManager globalRegionManager = new GlobalRegionManager(this, regionContainer);
private FlagStateManager flagStateManager;
private final Supervisor supervisor = new SimpleSupervisor();
private ListeningExecutorService executorService;
@ -145,7 +146,8 @@ public static WorldGuardPlugin inst() {
@Override
@SuppressWarnings("deprecation")
public void onEnable() {
configuration = new ConfigurationManager(this);
getDataFolder().mkdirs(); // Need to create the plugins/WorldGuard folder
executorService = MoreExecutors.listeningDecorator(EvenMoreExecutors.newBoundedCachedThreadPool(0, 1, 20));
// Set the proper command injector
@ -165,9 +167,6 @@ public void run() {
}
}, 0L);
// Need to create the plugins/WorldGuard folder
getDataFolder().mkdirs();
File cacheDir = new File(getDataFolder(), "cache");
cacheDir.mkdirs();
try {
@ -190,8 +189,7 @@ public void run() {
configuration.load();
getLogger().info("Loading region data...");
globalRegionManager = new GlobalRegionManager(this);
globalRegionManager.loadAll(Bukkit.getServer().getWorlds());
regionContainer.initialize();
migrateRegionUniqueIds(); // Migrate to UUIDs
} catch (FatalConfigurationLoadingException e) {
@ -282,7 +280,7 @@ public void onDisable() {
getLogger().log(Level.WARNING, "Some tasks failed while waiting for remaining tasks to finish", e);
}
globalRegionManager.unloadAll();
regionContainer.unload();
configuration.unload();
this.getServer().getScheduler().cancelTasks(this);
}
@ -362,12 +360,23 @@ public String convertThrowable(@Nullable Throwable throwable) {
/**
* Get the GlobalRegionManager.
*
* @return The plugin's global region manager
* @return the plugin's global region manager
* @deprecated use {@link #getRegionContainer()}
*/
@Deprecated
public GlobalRegionManager getGlobalRegionManager() {
return globalRegionManager;
}
/**
* Get the object that manages region data.
*
* @return the region container
*/
public RegionContainer getRegionContainer() {
return regionContainer;
}
/**
* Get the WorldGuard Configuration.
*

View File

@ -34,7 +34,7 @@
import com.sk89q.worldedit.bukkit.selections.Polygonal2DSelection;
import com.sk89q.worldedit.bukkit.selections.Selection;
import com.sk89q.worldguard.LocalPlayer;
import com.sk89q.worldguard.bukkit.LoggerToChatHandler;
import com.sk89q.worldguard.bukkit.util.LoggerToChatHandler;
import com.sk89q.worldguard.bukkit.permission.RegionPermissionModel;
import com.sk89q.worldguard.bukkit.WorldConfiguration;
import com.sk89q.worldguard.bukkit.WorldGuardPlugin;

View File

@ -25,8 +25,8 @@
import com.sk89q.minecraft.util.commands.CommandPermissions;
import com.sk89q.odeum.task.Task;
import com.sk89q.odeum.task.TaskStateComparator;
import com.sk89q.worldguard.bukkit.LoggerToChatHandler;
import com.sk89q.worldguard.bukkit.ReportWriter;
import com.sk89q.worldguard.bukkit.util.LoggerToChatHandler;
import com.sk89q.worldguard.bukkit.util.ReportWriter;
import com.sk89q.worldguard.bukkit.WorldGuardPlugin;
import com.sk89q.worldguard.util.PastebinPoster;
import com.sk89q.worldguard.util.PastebinPoster.PasteCallback;
@ -78,9 +78,8 @@ public void reload(CommandContext args, CommandSender sender) throws CommandExce
try {
plugin.getGlobalStateManager().unload();
plugin.getGlobalRegionManager().unloadAll();
plugin.getRegionContainer().reload();
plugin.getGlobalStateManager().load();
plugin.getGlobalRegionManager().loadAll(Bukkit.getServer().getWorlds());
// WGBukkit.cleanCache();
sender.sendMessage("WorldGuard configuration reloaded.");
} catch (Throwable t) {

View File

@ -23,10 +23,13 @@
import org.bukkit.event.Cancellable;
import org.bukkit.event.Event;
import javax.annotation.Nullable;
import static com.google.common.base.Preconditions.checkNotNull;
public abstract class AbstractInteractEvent extends Event implements Cancellable {
public abstract class AbstractDelegateEvent extends Event implements Cancellable {
@Nullable
private final Event originalEvent;
private final Cause cause;
private boolean cancelled;
@ -37,8 +40,7 @@ public abstract class AbstractInteractEvent extends Event implements Cancellable
* @param originalEvent the original event
* @param cause the cause
*/
protected AbstractInteractEvent(Event originalEvent, Cause cause) {
checkNotNull(originalEvent);
protected AbstractDelegateEvent(@Nullable Event originalEvent, Cause cause) {
checkNotNull(cause);
this.originalEvent = originalEvent;
this.cause = cause;
@ -47,8 +49,9 @@ protected AbstractInteractEvent(Event originalEvent, Cause cause) {
/**
* Get the original event.
*
* @return the original event
* @return the original event, which may be {@code null} if unavailable
*/
@Nullable
public Event getOriginalEvent() {
return originalEvent;
}

View File

@ -20,7 +20,7 @@
package com.sk89q.worldguard.bukkit.event.block;
import com.sk89q.worldguard.bukkit.cause.Cause;
import com.sk89q.worldguard.bukkit.event.AbstractInteractEvent;
import com.sk89q.worldguard.bukkit.event.AbstractDelegateEvent;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.block.Block;
@ -30,14 +30,14 @@
import static com.google.common.base.Preconditions.checkNotNull;
abstract class AbstractBlockEvent extends AbstractInteractEvent {
abstract class AbstractBlockEvent extends AbstractDelegateEvent {
private final Location target;
@Nullable
private final Block block;
private final Material effectiveMaterial;
protected AbstractBlockEvent(Event originalEvent, Cause cause, Block block) {
protected AbstractBlockEvent(@Nullable Event originalEvent, Cause cause, Block block) {
super(originalEvent, cause);
checkNotNull(block);
this.target = block.getLocation();
@ -45,7 +45,7 @@ protected AbstractBlockEvent(Event originalEvent, Cause cause, Block block) {
this.effectiveMaterial = block.getType();
}
protected AbstractBlockEvent(Event originalEvent, Cause cause, Location target, Material effectiveMaterial) {
protected AbstractBlockEvent(@Nullable Event originalEvent, Cause cause, Location target, Material effectiveMaterial) {
super(originalEvent, cause);
this.target = target;
this.block = null;

View File

@ -26,15 +26,17 @@
import org.bukkit.event.Event;
import org.bukkit.event.HandlerList;
import javax.annotation.Nullable;
public class BreakBlockEvent extends AbstractBlockEvent {
private static final HandlerList handlers = new HandlerList();
public BreakBlockEvent(Event originalEvent, Cause cause, Block block) {
public BreakBlockEvent(@Nullable Event originalEvent, Cause cause, Block block) {
super(originalEvent, cause, block);
}
public BreakBlockEvent(Event originalEvent, Cause cause, Location target, Material effectiveMaterial) {
public BreakBlockEvent(@Nullable Event originalEvent, Cause cause, Location target, Material effectiveMaterial) {
super(originalEvent, cause, target, effectiveMaterial);
}

View File

@ -26,15 +26,17 @@
import org.bukkit.event.Event;
import org.bukkit.event.HandlerList;
import javax.annotation.Nullable;
public class PlaceBlockEvent extends AbstractBlockEvent {
private static final HandlerList handlers = new HandlerList();
public PlaceBlockEvent(Event originalEvent, Cause cause, Block block) {
public PlaceBlockEvent(@Nullable Event originalEvent, Cause cause, Block block) {
super(originalEvent, cause, block);
}
public PlaceBlockEvent(Event originalEvent, Cause cause, Location target, Material effectiveMaterial) {
public PlaceBlockEvent(@Nullable Event originalEvent, Cause cause, Location target, Material effectiveMaterial) {
super(originalEvent, cause, target, effectiveMaterial);
}

View File

@ -26,6 +26,8 @@
import org.bukkit.event.Event;
import org.bukkit.event.HandlerList;
import javax.annotation.Nullable;
/**
* Fired when a block is interacted with.
*/
@ -33,11 +35,11 @@ public class UseBlockEvent extends AbstractBlockEvent {
private static final HandlerList handlers = new HandlerList();
public UseBlockEvent(Event originalEvent, Cause cause, Block block) {
public UseBlockEvent(@Nullable Event originalEvent, Cause cause, Block block) {
super(originalEvent, cause, block);
}
public UseBlockEvent(Event originalEvent, Cause cause, Location target, Material effectiveMaterial) {
public UseBlockEvent(@Nullable Event originalEvent, Cause cause, Location target, Material effectiveMaterial) {
super(originalEvent, cause, target, effectiveMaterial);
}

View File

@ -20,7 +20,7 @@
package com.sk89q.worldguard.bukkit.event.entity;
import com.sk89q.worldguard.bukkit.cause.Cause;
import com.sk89q.worldguard.bukkit.event.AbstractInteractEvent;
import com.sk89q.worldguard.bukkit.event.AbstractDelegateEvent;
import org.bukkit.Location;
import org.bukkit.entity.Entity;
import org.bukkit.event.Event;
@ -29,20 +29,20 @@
import static com.google.common.base.Preconditions.checkNotNull;
abstract class AbstractEntityEvent extends AbstractInteractEvent {
abstract class AbstractEntityEvent extends AbstractDelegateEvent {
private final Location target;
@Nullable
private final Entity entity;
protected AbstractEntityEvent(Event originalEvent, Cause cause, Entity entity) {
protected AbstractEntityEvent(@Nullable Event originalEvent, Cause cause, Entity entity) {
super(originalEvent, cause);
checkNotNull(entity);
this.target = entity.getLocation();
this.entity = entity;
}
protected AbstractEntityEvent(Event originalEvent, Cause cause, Location target) {
protected AbstractEntityEvent(@Nullable Event originalEvent, Cause cause, Location target) {
super(originalEvent, cause);
checkNotNull(target);
this.target = target;

View File

@ -25,6 +25,7 @@
import org.bukkit.event.HandlerList;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import static com.google.common.base.Preconditions.checkNotNull;
@ -32,7 +33,7 @@ public class DestroyEntityEvent extends AbstractEntityEvent {
private static final HandlerList handlers = new HandlerList();
public DestroyEntityEvent(Event originalEvent, Cause cause, Entity target) {
public DestroyEntityEvent(@Nullable Event originalEvent, Cause cause, Entity target) {
super(originalEvent, cause, checkNotNull(target));
}

View File

@ -26,6 +26,8 @@
import org.bukkit.event.Event;
import org.bukkit.event.HandlerList;
import javax.annotation.Nullable;
import static com.google.common.base.Preconditions.checkNotNull;
public class SpawnEntityEvent extends AbstractEntityEvent {
@ -33,12 +35,12 @@ public class SpawnEntityEvent extends AbstractEntityEvent {
private static final HandlerList handlers = new HandlerList();
private final EntityType effectiveType;
public SpawnEntityEvent(Event originalEvent, Cause cause, Entity target) {
public SpawnEntityEvent(@Nullable Event originalEvent, Cause cause, Entity target) {
super(originalEvent, cause, checkNotNull(target));
this.effectiveType = target.getType();
}
public SpawnEntityEvent(Event originalEvent, Cause cause, Location location, EntityType type) {
public SpawnEntityEvent(@Nullable Event originalEvent, Cause cause, Location location, EntityType type) {
super(originalEvent, cause, location);
checkNotNull(type);
this.effectiveType = type;

View File

@ -25,6 +25,7 @@
import org.bukkit.event.HandlerList;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import static com.google.common.base.Preconditions.checkNotNull;
@ -35,7 +36,7 @@ public class UseEntityEvent extends AbstractEntityEvent {
private static final HandlerList handlers = new HandlerList();
public UseEntityEvent(Event originalEvent, Cause cause, Entity target) {
public UseEntityEvent(@Nullable Event originalEvent, Cause cause, Entity target) {
super(originalEvent, cause, checkNotNull(target));
}

View File

@ -20,24 +20,26 @@
package com.sk89q.worldguard.bukkit.event.inventory;
import com.sk89q.worldguard.bukkit.cause.Cause;
import com.sk89q.worldguard.bukkit.event.AbstractInteractEvent;
import com.sk89q.worldguard.bukkit.event.AbstractDelegateEvent;
import org.bukkit.World;
import org.bukkit.event.Event;
import org.bukkit.event.HandlerList;
import org.bukkit.inventory.ItemStack;
import javax.annotation.Nullable;
import static com.google.common.base.Preconditions.checkNotNull;
/**
* Fired when an item is interacted with.
*/
public class UseItemEvent extends AbstractInteractEvent {
public class UseItemEvent extends AbstractDelegateEvent {
private static final HandlerList handlers = new HandlerList();
private final World world;
private final ItemStack itemStack;
public UseItemEvent(Event originalEvent, Cause cause, World world, ItemStack itemStack) {
public UseItemEvent(@Nullable Event originalEvent, Cause cause, World world, ItemStack itemStack) {
super(originalEvent, cause);
checkNotNull(world);
checkNotNull(itemStack);

View File

@ -17,9 +17,13 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.sk89q.worldguard.bukkit;
package com.sk89q.worldguard.bukkit.listener;
import com.sk89q.worldedit.Vector;
import com.sk89q.worldguard.bukkit.ConfigurationManager;
import com.sk89q.worldguard.bukkit.util.RegionQueryUtil;
import com.sk89q.worldguard.bukkit.WorldConfiguration;
import com.sk89q.worldguard.bukkit.WorldGuardPlugin;
import com.sk89q.worldguard.protection.ApplicableRegionSet;
import com.sk89q.worldguard.protection.flags.DefaultFlag;
import com.sk89q.worldguard.protection.managers.RegionManager;

View File

@ -19,7 +19,7 @@
package com.sk89q.worldguard.bukkit.listener;
import com.sk89q.worldedit.Vector2D;
import com.sk89q.worldguard.bukkit.RegionQuery;
import com.sk89q.worldguard.bukkit.WorldGuardPlugin;
import com.sk89q.worldguard.bukkit.event.block.BreakBlockEvent;
import com.sk89q.worldguard.bukkit.event.block.PlaceBlockEvent;
@ -29,21 +29,14 @@
import com.sk89q.worldguard.bukkit.event.entity.UseEntityEvent;
import com.sk89q.worldguard.bukkit.util.Entities;
import com.sk89q.worldguard.bukkit.util.Materials;
import com.sk89q.worldguard.bukkit.util.ProtectedRegionQuery;
import com.sk89q.worldguard.protection.flags.DefaultFlag;
import com.sk89q.worldguard.protection.managers.RegionManager;
import org.bukkit.ChatColor;
import org.bukkit.Chunk;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.world.ChunkLoadEvent;
import org.bukkit.event.world.ChunkUnloadEvent;
import org.bukkit.event.world.WorldLoadEvent;
import org.bukkit.event.world.WorldUnloadEvent;
/**
* Handle events that need to be processed by region protection.
@ -63,34 +56,6 @@ private void tellErrorMessage(CommandSender sender, Object subject) {
sender.sendMessage(ChatColor.DARK_RED + "You don't have permission for this area.");
}
@EventHandler
public void onWorldLoad(WorldLoadEvent event) {
getPlugin().getGlobalRegionManager().load(event.getWorld());
}
@EventHandler
public void onWorldUnload(WorldUnloadEvent event) {
getPlugin().getGlobalRegionManager().unload(event.getWorld());
}
@EventHandler
public void onChunkLoad(ChunkLoadEvent event) {
RegionManager manager = getPlugin().getGlobalRegionManager().get(event.getWorld());
if (manager != null) {
Chunk chunk = event.getChunk();
manager.loadChunk(new Vector2D(chunk.getX(), chunk.getZ()));
}
}
@EventHandler
public void onChunkUnload(ChunkUnloadEvent event) {
RegionManager manager = getPlugin().getGlobalRegionManager().get(event.getWorld());
if (manager != null) {
Chunk chunk = event.getChunk();
manager.unloadChunk(new Vector2D(chunk.getX(), chunk.getZ()));
}
}
@EventHandler(ignoreCancelled = true)
public void onPlaceBlock(PlaceBlockEvent event) {
Player player = event.getCause().getPlayerRootCause();
@ -98,15 +63,15 @@ public void onPlaceBlock(PlaceBlockEvent event) {
Material type = event.getEffectiveMaterial();
if (player != null) {
ProtectedRegionQuery query = new ProtectedRegionQuery(getPlugin(), player);
RegionQuery query = getPlugin().getRegionContainer().createQuery(player);
boolean canPlace;
// Flint and steel, fire charge
if (type == Material.FIRE) {
canPlace = query.allows(DefaultFlag.LIGHTER, target) || (query.canBuild(target) && query.canConstruct(target));
canPlace = query.testPermission(target, DefaultFlag.LIGHTER);
} else {
canPlace = query.canBuild(target) && query.canConstruct(target);
canPlace = query.testPermission(target);
}
if (!canPlace) {
@ -139,30 +104,24 @@ public void onUseBlock(UseBlockEvent event) {
Material type = event.getEffectiveMaterial();
if (player != null) {
ProtectedRegionQuery query = new ProtectedRegionQuery(getPlugin(), player);
RegionQuery query = getPlugin().getRegionContainer().createQuery(player);
boolean canUse;
// Inventory blocks (CHEST_ACCESS)
if (Materials.isInventoryBlock(type)) {
canUse = query.canBuild( target)
|| query.allows(DefaultFlag.CHEST_ACCESS, target)
|| query.allows(DefaultFlag.USE, target);
canUse = query.testPermission(target, DefaultFlag.USE, DefaultFlag.CHEST_ACCESS);
// Beds (SLEEP)
} else if (type == Material.BED) {
canUse = query.canBuild(target)
|| query.allows(DefaultFlag.SLEEP, target)
|| query.allows(DefaultFlag.USE, target);
canUse = query.testPermission(target, DefaultFlag.USE, DefaultFlag.SLEEP);
// TNT (TNT)
} else if (type == Material.TNT) {
canUse = query.canBuild(target)
|| query.allows(DefaultFlag.TNT, target);
canUse = query.testPermission(target, DefaultFlag.TNT);
// Everything else
} else {
canUse = query.canBuild(target)
|| query.allows(DefaultFlag.USE, target);
canUse = query.testPermission(target, DefaultFlag.USE);
}
if (!canUse) {
@ -179,13 +138,13 @@ public void onSpawnEntity(SpawnEntityEvent event) {
EntityType type = event.getEffectiveType();
if (player != null) {
ProtectedRegionQuery query = new ProtectedRegionQuery(getPlugin(), player);
RegionQuery query = getPlugin().getRegionContainer().createQuery(player);
boolean canSpawn;
if (Entities.isVehicle(type)) {
canSpawn = query.canBuild(target) || query.allows(DefaultFlag.PLACE_VEHICLE, target);
canSpawn = query.testPermission(target, DefaultFlag.PLACE_VEHICLE);
} else {
canSpawn = query.canBuild(target);
canSpawn = query.testPermission(target);
}
if (!canSpawn) {
@ -202,13 +161,13 @@ public void onDestroyEntity(DestroyEntityEvent event) {
EntityType type = event.getEntity().getType();
if (player != null) {
ProtectedRegionQuery query = new ProtectedRegionQuery(getPlugin(), player);
RegionQuery query = getPlugin().getRegionContainer().createQuery(player);
boolean canDestroy;
if (Entities.isVehicle(type)) {
canDestroy = query.canBuild(target) || query.allows(DefaultFlag.DESTROY_VEHICLE, target);
canDestroy = query.testPermission(target, DefaultFlag.DESTROY_VEHICLE);
} else {
canDestroy = query.canBuild(target);
canDestroy = query.testPermission(target);
}
if (!canDestroy) {
@ -224,8 +183,8 @@ public void onUseEntity(UseEntityEvent event) {
Location target = event.getTarget();
if (player != null) {
ProtectedRegionQuery query = new ProtectedRegionQuery(getPlugin(), player);
boolean canUse = query.canBuild(target) || query.allows(DefaultFlag.USE, target);
RegionQuery query = getPlugin().getRegionContainer().createQuery(player);
boolean canUse = query.testPermission(target, DefaultFlag.USE);
if (!canUse) {
tellErrorMessage(player, target);

View File

@ -17,8 +17,11 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.sk89q.worldguard.bukkit;
package com.sk89q.worldguard.bukkit.listener;
import com.sk89q.worldguard.bukkit.ConfigurationManager;
import com.sk89q.worldguard.bukkit.WorldConfiguration;
import com.sk89q.worldguard.bukkit.WorldGuardPlugin;
import org.bukkit.World;
import static com.sk89q.worldguard.bukkit.BukkitUtil.isBlockWater;

View File

@ -24,7 +24,6 @@
import com.sk89q.worldedit.blocks.BlockType;
import com.sk89q.worldedit.blocks.ItemType;
import com.sk89q.worldguard.bukkit.ConfigurationManager;
import com.sk89q.worldguard.bukkit.SpongeUtil;
import com.sk89q.worldguard.bukkit.WorldConfiguration;
import com.sk89q.worldguard.bukkit.WorldGuardPlugin;
import com.sk89q.worldguard.protection.ApplicableRegionSet;

View File

@ -24,7 +24,7 @@
import com.sk89q.worldguard.LocalPlayer;
import com.sk89q.worldguard.bukkit.BukkitUtil;
import com.sk89q.worldguard.bukkit.ConfigurationManager;
import com.sk89q.worldguard.bukkit.RegionQueryUtil;
import com.sk89q.worldguard.bukkit.util.RegionQueryUtil;
import com.sk89q.worldguard.bukkit.WorldConfiguration;
import com.sk89q.worldguard.bukkit.WorldGuardPlugin;
import com.sk89q.worldguard.protection.ApplicableRegionSet;

View File

@ -22,10 +22,9 @@
import com.sk89q.worldedit.Vector;
import com.sk89q.worldedit.blocks.BlockID;
import com.sk89q.worldguard.LocalPlayer;
import com.sk89q.worldguard.blacklist.event.ItemUseBlacklistEvent;
import com.sk89q.worldguard.bukkit.BukkitUtil;
import com.sk89q.worldguard.bukkit.ConfigurationManager;
import com.sk89q.worldguard.bukkit.FlagStateManager.PlayerFlagState;
import com.sk89q.worldguard.bukkit.listener.FlagStateManager.PlayerFlagState;
import com.sk89q.worldguard.bukkit.WorldConfiguration;
import com.sk89q.worldguard.bukkit.WorldGuardPlugin;
import com.sk89q.worldguard.protection.ApplicableRegionSet;
@ -50,7 +49,6 @@
import org.bukkit.event.player.PlayerDropItemEvent;
import org.bukkit.event.player.PlayerFishEvent;
import org.bukkit.event.player.PlayerGameModeChangeEvent;
import org.bukkit.event.player.PlayerInteractEntityEvent;
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.event.player.PlayerItemHeldEvent;
import org.bukkit.event.player.PlayerJoinEvent;

View File

@ -17,14 +17,14 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.sk89q.worldguard.bukkit;
import java.util.logging.Handler;
import java.util.logging.LogRecord;
package com.sk89q.worldguard.bukkit.util;
import org.bukkit.ChatColor;
import org.bukkit.command.CommandSender;
import java.util.logging.Handler;
import java.util.logging.LogRecord;
/**
* Sends all logger messages to a player.
*

View File

@ -1,101 +0,0 @@
/*
* WorldGuard, a suite of tools for Minecraft
* Copyright (C) sk89q <http://www.sk89q.com>
* Copyright (C) WorldGuard team and contributors
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU Lesser 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 Lesser General Public License
* for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.sk89q.worldguard.bukkit.util;
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.WorldGuardPlugin;
import com.sk89q.worldguard.protection.ApplicableRegionSet;
import com.sk89q.worldguard.protection.GlobalRegionManager;
import com.sk89q.worldguard.protection.flags.StateFlag;
import com.sk89q.worldguard.protection.managers.RegionManager;
import org.bukkit.Location;
import org.bukkit.World;
import org.bukkit.entity.Player;
import javax.annotation.Nullable;
import static com.sk89q.worldguard.bukkit.BukkitUtil.toVector;
public class ProtectedRegionQuery {
private final ConfigurationManager config;
private final GlobalRegionManager globalManager;
@Nullable
private final LocalPlayer localPlayer;
public ProtectedRegionQuery(WorldGuardPlugin plugin, @Nullable Player player) {
this(plugin, player != null ? plugin.wrapPlayer(player) : null);
}
public ProtectedRegionQuery(WorldGuardPlugin plugin, @Nullable LocalPlayer player) {
this.config = plugin.getGlobalStateManager();
this.globalManager = plugin.getGlobalRegionManager();
this.localPlayer = player;
}
public boolean canBuild(Location location) {
World world = location.getWorld();
WorldConfiguration worldConfig = config.get(world);
if (!worldConfig.useRegions) {
return true;
}
if (localPlayer != null && globalManager.hasBypass(localPlayer, world)) {
return true;
} else {
RegionManager manager = globalManager.get(location.getWorld());
return manager.getApplicableRegions(BukkitUtil.toVector(location)).canBuild(localPlayer);
}
}
public boolean canConstruct(Location location) {
World world = location.getWorld();
WorldConfiguration worldConfig = config.get(world);
if (!worldConfig.useRegions) {
return true;
}
if (localPlayer != null && globalManager.hasBypass(localPlayer, world)) {
return true;
} else {
RegionManager manager = globalManager.get(location.getWorld());
ApplicableRegionSet result = manager.getApplicableRegions(BukkitUtil.toVector(location));
return result.canBuild(localPlayer) && result.canConstruct(localPlayer);
}
}
public boolean allows(StateFlag flag, Location location) {
World world = location.getWorld();
WorldConfiguration worldConfig = config.get(world);
if (!worldConfig.useRegions) {
return true;
}
RegionManager manager = globalManager.get(location.getWorld());
return manager.getApplicableRegions(toVector(location)).allows(flag, localPlayer);
}
}

View File

@ -17,8 +17,10 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.sk89q.worldguard.bukkit;
package com.sk89q.worldguard.bukkit.util;
import com.sk89q.worldguard.bukkit.WorldGuardPlugin;
import com.sk89q.worldguard.bukkit.listener.FlagStateManager;
import org.bukkit.Location;
import org.bukkit.World;
import org.bukkit.entity.Player;

View File

@ -17,7 +17,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.sk89q.worldguard.bukkit;
package com.sk89q.worldguard.bukkit.util;
import java.io.BufferedWriter;
import java.io.File;
@ -30,6 +30,9 @@
import java.util.List;
import java.util.Map;
import com.sk89q.worldguard.bukkit.ConfigurationManager;
import com.sk89q.worldguard.bukkit.WorldConfiguration;
import com.sk89q.worldguard.bukkit.WorldGuardPlugin;
import org.bukkit.Server;
import org.bukkit.World;
import org.bukkit.entity.Entity;

View File

@ -19,111 +19,45 @@
package com.sk89q.worldguard.protection;
import com.sk89q.worldedit.Vector2D;
import com.sk89q.worldguard.LocalPlayer;
import com.sk89q.worldguard.bukkit.ConfigurationManager;
import com.sk89q.worldguard.bukkit.RegionContainer;
import com.sk89q.worldguard.bukkit.RegionQuery;
import com.sk89q.worldguard.bukkit.WorldGuardPlugin;
import com.sk89q.worldguard.bukkit.util.ProtectedRegionQuery;
import com.sk89q.worldguard.protection.flags.StateFlag;
import com.sk89q.worldguard.protection.managers.RegionManager;
import org.bukkit.Chunk;
import org.bukkit.Location;
import org.bukkit.World;
import org.bukkit.block.Block;
import org.bukkit.entity.Player;
import javax.annotation.Nullable;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import static com.google.common.base.Preconditions.checkNotNull;
/**
* A global region manager loads, saves and caches region data for zero or
* more worlds at a time.
* This is the legacy class for accessing region data.
*
* <p>This class is thread safe and its contents can be accessed from
* multiple concurrent threads.</p>
* @deprecated use {@link WorldGuardPlugin#getRegionContainer()}
*/
@Deprecated
public class GlobalRegionManager {
private final WorldGuardPlugin plugin;
private final ManagerContainer container;
private final RegionContainer container;
/**
* Create a new instance.
*
* @param plugin the plugin
* @param container the container
*/
public GlobalRegionManager(WorldGuardPlugin plugin) {
public GlobalRegionManager(WorldGuardPlugin plugin, RegionContainer container) {
checkNotNull(plugin);
checkNotNull(container);
this.plugin = plugin;
ConfigurationManager config = plugin.getGlobalStateManager();
container = new ManagerContainer(config);
}
/**
* Load the region data for a world if it has not been loaded already.
*
* <p>This method is called by WorldGuard and should not be called
* by other plugins.</p>
*
* @param world the world
* @return a region manager, either returned from the cache or newly loaded
*/
@Nullable
public RegionManager load(World world) {
checkNotNull(world);
RegionManager manager = container.load(world.getName());
if (manager != null) {
// Bias the region data for loaded chunks
List<Vector2D> positions = new ArrayList<Vector2D>();
for (Chunk chunk : world.getLoadedChunks()) {
positions.add(new Vector2D(chunk.getX(), chunk.getZ()));
}
manager.loadChunks(positions);
}
return manager;
}
/**
* Load the region data for a list of worlds.
*
* <p>This method is called by WorldGuard and should not be called
* by other plugins.</p>
*
* @param worlds a list of worlds
*/
public void loadAll(Collection<? extends World> worlds) {
checkNotNull(worlds);
for (World world : worlds) {
load(world);
}
}
/**
* Unload the region data for a world.
*
* @param world a world
*/
public void unload(World world) {
checkNotNull(world);
container.unload(world.getName());
}
/**
* Unload all region data for all worlds that region data has
* been loaded for.
*/
public void unloadAll() {
container.unloadAll();
this.container = container;
}
/**
@ -138,7 +72,7 @@ public void unloadAll() {
*/
@Nullable
public RegionManager get(World world) {
return container.get(world.getName());
return container.get(world);
}
/**
@ -155,8 +89,8 @@ public List<RegionManager> getLoaded() {
*
* @return a new query
*/
public ProtectedRegionQuery createAnonymousQuery() {
return new ProtectedRegionQuery(plugin, (Player) null);
private RegionQuery createAnonymousQuery() {
return container.createAnonymousQuery();
}
/**
@ -165,8 +99,8 @@ public ProtectedRegionQuery createAnonymousQuery() {
* @param player a player, or {@code null}
* @return a new query
*/
public ProtectedRegionQuery createQuery(@Nullable Player player) {
return new ProtectedRegionQuery(plugin, player);
private RegionQuery createQuery(@Nullable Player player) {
return container.createQuery(player);
}
/**
@ -175,8 +109,8 @@ public ProtectedRegionQuery createQuery(@Nullable Player player) {
* @param player a player, or {@code null}
* @return a new query
*/
private ProtectedRegionQuery createQuery(@Nullable LocalPlayer player) {
return new ProtectedRegionQuery(plugin, player);
private RegionQuery createQuery(@Nullable LocalPlayer player) {
return container.createQuery(player);
}
/**
@ -243,7 +177,7 @@ public boolean canBuild(Player player, Block block) {
*/
@Deprecated
public boolean canBuild(Player player, Location location) {
return createQuery(player).canBuild(location);
return createQuery(player).testPermission(location);
}
/**
@ -252,12 +186,12 @@ public boolean canBuild(Player player, Location location) {
* @param player the player
* @param block the block
* @return true if permitted
* @deprecated use {@link #createQuery(Player)}
* @deprecated the construct flag is being removed
*/
@Deprecated
@SuppressWarnings("deprecation")
public boolean canConstruct(Player player, Block block) {
return canConstruct(player, block.getLocation());
return canBuild(player, block.getLocation());
}
/**
@ -266,11 +200,11 @@ public boolean canConstruct(Player player, Block block) {
* @param player the player
* @param location the location
* @return true if permitted
* @deprecated use {@link #createQuery(Player)}
* @deprecated the construct flag is being removed
*/
@Deprecated
public boolean canConstruct(Player player, Location location) {
return createQuery(player).canConstruct(location);
return canBuild(player, location);
}
/**
@ -299,7 +233,7 @@ public boolean allows(StateFlag flag, Location location) {
*/
@Deprecated
public boolean allows(StateFlag flag, Location location, @Nullable LocalPlayer player) {
return createQuery(player).allows(flag, location);
return createQuery(player).testEnabled(location, flag);
}
}