mirror of
https://github.com/EngineHub/WorldGuard.git
synced 2024-11-24 03:25:24 +01:00
Refactor region API with new RegionContainer object.
This commit is contained in:
parent
ad1c10a3e9
commit
99660920d7
@ -21,7 +21,8 @@
|
|||||||
|
|
||||||
import com.sk89q.worldguard.blacklist.Blacklist;
|
import com.sk89q.worldguard.blacklist.Blacklist;
|
||||||
|
|
||||||
public class BukkitBlacklist extends Blacklist {
|
class BukkitBlacklist extends Blacklist {
|
||||||
|
|
||||||
private WorldGuardPlugin plugin;
|
private WorldGuardPlugin plugin;
|
||||||
|
|
||||||
public BukkitBlacklist(Boolean useAsWhitelist, WorldGuardPlugin plugin) {
|
public BukkitBlacklist(Boolean useAsWhitelist, WorldGuardPlugin plugin) {
|
||||||
@ -33,4 +34,5 @@ public BukkitBlacklist(Boolean useAsWhitelist, WorldGuardPlugin plugin) {
|
|||||||
public void broadcastNotification(String msg) {
|
public void broadcastNotification(String msg) {
|
||||||
plugin.broadcastNotification(msg);
|
plugin.broadcastNotification(msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -17,10 +17,9 @@
|
|||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package com.sk89q.worldguard.protection;
|
package com.sk89q.worldguard.bukkit;
|
||||||
|
|
||||||
import com.google.common.base.Supplier;
|
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.RegionManager;
|
||||||
import com.sk89q.worldguard.protection.managers.index.ChunkHashTable;
|
import com.sk89q.worldguard.protection.managers.index.ChunkHashTable;
|
||||||
import com.sk89q.worldguard.protection.managers.index.ConcurrentRegionIndex;
|
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 Logger log = Logger.getLogger(ManagerContainer.class.getCanonicalName());
|
||||||
private static final int SAVE_INTERVAL = 1000 * 30;
|
private static final int SAVE_INTERVAL = 1000 * 30;
|
||||||
|
|
||||||
|
private final ConfigurationManager config;
|
||||||
private final ConcurrentMap<Normal, RegionManager> mapping = new ConcurrentHashMap<Normal, RegionManager>();
|
private final ConcurrentMap<Normal, RegionManager> mapping = new ConcurrentHashMap<Normal, RegionManager>();
|
||||||
private final Object lock = new Object();
|
private final Object lock = new Object();
|
||||||
private final EnumMap<DriverType, RegionStoreDriver> drivers = new EnumMap<DriverType, RegionStoreDriver>(DriverType.class);
|
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 Supplier<? extends ConcurrentRegionIndex> indexFactory = new ChunkHashTable.Factory(new PriorityRTreeIndex.Factory());
|
||||||
private final Timer timer = new Timer();
|
private final Timer timer = new Timer();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a new instance.
|
||||||
|
*
|
||||||
|
* @param config the configuration
|
||||||
|
*/
|
||||||
ManagerContainer(ConfigurationManager config) {
|
ManagerContainer(ConfigurationManager config) {
|
||||||
checkNotNull(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()) {
|
for (DriverType type : DriverType.values()) {
|
||||||
drivers.put(type, type.create(config));
|
drivers.put(type, type.create(config));
|
||||||
}
|
}
|
||||||
@ -73,10 +85,15 @@ class ManagerContainer {
|
|||||||
} else {
|
} else {
|
||||||
defaultDriver = drivers.get(DriverType.YAML);
|
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
|
@Nullable
|
||||||
public RegionManager load(String name) {
|
public RegionManager load(String name) {
|
||||||
checkNotNull(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 {
|
private RegionManager createAndLoad(String name) throws IOException {
|
||||||
RegionStore store = defaultDriver.get(name);
|
RegionStore store = defaultDriver.get(name);
|
||||||
RegionManager manager = new RegionManager(store, indexFactory);
|
RegionManager manager = new RegionManager(store, indexFactory);
|
||||||
@ -107,6 +131,14 @@ private RegionManager createAndLoad(String name) throws IOException {
|
|||||||
return manager;
|
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) {
|
public void unload(String name) {
|
||||||
checkNotNull(name);
|
checkNotNull(name);
|
||||||
|
|
||||||
@ -120,11 +152,16 @@ public void unload(String name) {
|
|||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
log.log(Level.WARNING, "Failed to save the region data for '" + name + "'", e);
|
log.log(Level.WARNING, "Failed to save the region data for '" + name + "'", e);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
mapping.remove(normal);
|
||||||
}
|
}
|
||||||
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() {
|
public void unloadAll() {
|
||||||
synchronized (lock) {
|
synchronized (lock) {
|
||||||
for (Map.Entry<Normal, RegionManager> entry : mapping.entrySet()) {
|
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
|
@Nullable
|
||||||
public RegionManager get(String name) {
|
public RegionManager get(String name) {
|
||||||
checkNotNull(name);
|
checkNotNull(name);
|
||||||
return mapping.get(Normal.normal(name));
|
return mapping.get(Normal.normal(name));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get an immutable list of loaded region managers.
|
||||||
|
*
|
||||||
|
* @return an immutable list
|
||||||
|
*/
|
||||||
public List<RegionManager> getLoaded() {
|
public List<RegionManager> getLoaded() {
|
||||||
return Collections.unmodifiableList(new ArrayList<RegionManager>(mapping.values()));
|
return Collections.unmodifiableList(new ArrayList<RegionManager>(mapping.values()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A task to save managers in the background.
|
||||||
|
*/
|
||||||
private class BackgroundSaver extends TimerTask {
|
private class BackgroundSaver extends TimerTask {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
242
src/main/java/com/sk89q/worldguard/bukkit/RegionContainer.java
Normal file
242
src/main/java/com/sk89q/worldguard/bukkit/RegionContainer.java
Normal 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);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
196
src/main/java/com/sk89q/worldguard/bukkit/RegionQuery.java
Normal file
196
src/main/java/com/sk89q/worldguard/bukkit/RegionQuery.java
Normal 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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -53,6 +53,7 @@
|
|||||||
import com.sk89q.worldguard.bukkit.listener.ChestProtectionListener;
|
import com.sk89q.worldguard.bukkit.listener.ChestProtectionListener;
|
||||||
import com.sk89q.worldguard.bukkit.listener.DebuggingListener;
|
import com.sk89q.worldguard.bukkit.listener.DebuggingListener;
|
||||||
import com.sk89q.worldguard.bukkit.listener.EventAbstractionListener;
|
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.RegionProtectionListener;
|
||||||
import com.sk89q.worldguard.bukkit.listener.WorldGuardBlockListener;
|
import com.sk89q.worldguard.bukkit.listener.WorldGuardBlockListener;
|
||||||
import com.sk89q.worldguard.bukkit.listener.WorldGuardCommandBookListener;
|
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.MigrationException;
|
||||||
import com.sk89q.worldguard.protection.util.migrator.UUIDMigrator;
|
import com.sk89q.worldguard.protection.util.migrator.UUIDMigrator;
|
||||||
import com.sk89q.worldguard.util.FatalConfigurationLoadingException;
|
import com.sk89q.worldguard.util.FatalConfigurationLoadingException;
|
||||||
import org.bukkit.Bukkit;
|
|
||||||
import org.bukkit.ChatColor;
|
import org.bukkit.ChatColor;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
import org.bukkit.World;
|
import org.bukkit.World;
|
||||||
@ -109,8 +109,9 @@ public class WorldGuardPlugin extends JavaPlugin {
|
|||||||
|
|
||||||
private static WorldGuardPlugin inst;
|
private static WorldGuardPlugin inst;
|
||||||
private final CommandsManager<CommandSender> commands;
|
private final CommandsManager<CommandSender> commands;
|
||||||
private GlobalRegionManager globalRegionManager;
|
private final ConfigurationManager configuration = new ConfigurationManager(this);
|
||||||
private ConfigurationManager configuration;
|
private final RegionContainer regionContainer = new RegionContainer(this);
|
||||||
|
private final GlobalRegionManager globalRegionManager = new GlobalRegionManager(this, regionContainer);
|
||||||
private FlagStateManager flagStateManager;
|
private FlagStateManager flagStateManager;
|
||||||
private final Supervisor supervisor = new SimpleSupervisor();
|
private final Supervisor supervisor = new SimpleSupervisor();
|
||||||
private ListeningExecutorService executorService;
|
private ListeningExecutorService executorService;
|
||||||
@ -145,7 +146,8 @@ public static WorldGuardPlugin inst() {
|
|||||||
@Override
|
@Override
|
||||||
@SuppressWarnings("deprecation")
|
@SuppressWarnings("deprecation")
|
||||||
public void onEnable() {
|
public void onEnable() {
|
||||||
configuration = new ConfigurationManager(this);
|
getDataFolder().mkdirs(); // Need to create the plugins/WorldGuard folder
|
||||||
|
|
||||||
executorService = MoreExecutors.listeningDecorator(EvenMoreExecutors.newBoundedCachedThreadPool(0, 1, 20));
|
executorService = MoreExecutors.listeningDecorator(EvenMoreExecutors.newBoundedCachedThreadPool(0, 1, 20));
|
||||||
|
|
||||||
// Set the proper command injector
|
// Set the proper command injector
|
||||||
@ -165,9 +167,6 @@ public void run() {
|
|||||||
}
|
}
|
||||||
}, 0L);
|
}, 0L);
|
||||||
|
|
||||||
// Need to create the plugins/WorldGuard folder
|
|
||||||
getDataFolder().mkdirs();
|
|
||||||
|
|
||||||
File cacheDir = new File(getDataFolder(), "cache");
|
File cacheDir = new File(getDataFolder(), "cache");
|
||||||
cacheDir.mkdirs();
|
cacheDir.mkdirs();
|
||||||
try {
|
try {
|
||||||
@ -190,8 +189,7 @@ public void run() {
|
|||||||
configuration.load();
|
configuration.load();
|
||||||
|
|
||||||
getLogger().info("Loading region data...");
|
getLogger().info("Loading region data...");
|
||||||
globalRegionManager = new GlobalRegionManager(this);
|
regionContainer.initialize();
|
||||||
globalRegionManager.loadAll(Bukkit.getServer().getWorlds());
|
|
||||||
|
|
||||||
migrateRegionUniqueIds(); // Migrate to UUIDs
|
migrateRegionUniqueIds(); // Migrate to UUIDs
|
||||||
} catch (FatalConfigurationLoadingException e) {
|
} 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);
|
getLogger().log(Level.WARNING, "Some tasks failed while waiting for remaining tasks to finish", e);
|
||||||
}
|
}
|
||||||
|
|
||||||
globalRegionManager.unloadAll();
|
regionContainer.unload();
|
||||||
configuration.unload();
|
configuration.unload();
|
||||||
this.getServer().getScheduler().cancelTasks(this);
|
this.getServer().getScheduler().cancelTasks(this);
|
||||||
}
|
}
|
||||||
@ -362,12 +360,23 @@ public String convertThrowable(@Nullable Throwable throwable) {
|
|||||||
/**
|
/**
|
||||||
* Get the GlobalRegionManager.
|
* 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() {
|
public GlobalRegionManager getGlobalRegionManager() {
|
||||||
return globalRegionManager;
|
return globalRegionManager;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the object that manages region data.
|
||||||
|
*
|
||||||
|
* @return the region container
|
||||||
|
*/
|
||||||
|
public RegionContainer getRegionContainer() {
|
||||||
|
return regionContainer;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the WorldGuard Configuration.
|
* Get the WorldGuard Configuration.
|
||||||
*
|
*
|
||||||
|
@ -34,7 +34,7 @@
|
|||||||
import com.sk89q.worldedit.bukkit.selections.Polygonal2DSelection;
|
import com.sk89q.worldedit.bukkit.selections.Polygonal2DSelection;
|
||||||
import com.sk89q.worldedit.bukkit.selections.Selection;
|
import com.sk89q.worldedit.bukkit.selections.Selection;
|
||||||
import com.sk89q.worldguard.LocalPlayer;
|
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.permission.RegionPermissionModel;
|
||||||
import com.sk89q.worldguard.bukkit.WorldConfiguration;
|
import com.sk89q.worldguard.bukkit.WorldConfiguration;
|
||||||
import com.sk89q.worldguard.bukkit.WorldGuardPlugin;
|
import com.sk89q.worldguard.bukkit.WorldGuardPlugin;
|
||||||
|
@ -25,8 +25,8 @@
|
|||||||
import com.sk89q.minecraft.util.commands.CommandPermissions;
|
import com.sk89q.minecraft.util.commands.CommandPermissions;
|
||||||
import com.sk89q.odeum.task.Task;
|
import com.sk89q.odeum.task.Task;
|
||||||
import com.sk89q.odeum.task.TaskStateComparator;
|
import com.sk89q.odeum.task.TaskStateComparator;
|
||||||
import com.sk89q.worldguard.bukkit.LoggerToChatHandler;
|
import com.sk89q.worldguard.bukkit.util.LoggerToChatHandler;
|
||||||
import com.sk89q.worldguard.bukkit.ReportWriter;
|
import com.sk89q.worldguard.bukkit.util.ReportWriter;
|
||||||
import com.sk89q.worldguard.bukkit.WorldGuardPlugin;
|
import com.sk89q.worldguard.bukkit.WorldGuardPlugin;
|
||||||
import com.sk89q.worldguard.util.PastebinPoster;
|
import com.sk89q.worldguard.util.PastebinPoster;
|
||||||
import com.sk89q.worldguard.util.PastebinPoster.PasteCallback;
|
import com.sk89q.worldguard.util.PastebinPoster.PasteCallback;
|
||||||
@ -78,9 +78,8 @@ public void reload(CommandContext args, CommandSender sender) throws CommandExce
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
plugin.getGlobalStateManager().unload();
|
plugin.getGlobalStateManager().unload();
|
||||||
plugin.getGlobalRegionManager().unloadAll();
|
plugin.getRegionContainer().reload();
|
||||||
plugin.getGlobalStateManager().load();
|
plugin.getGlobalStateManager().load();
|
||||||
plugin.getGlobalRegionManager().loadAll(Bukkit.getServer().getWorlds());
|
|
||||||
// WGBukkit.cleanCache();
|
// WGBukkit.cleanCache();
|
||||||
sender.sendMessage("WorldGuard configuration reloaded.");
|
sender.sendMessage("WorldGuard configuration reloaded.");
|
||||||
} catch (Throwable t) {
|
} catch (Throwable t) {
|
||||||
|
@ -23,10 +23,13 @@
|
|||||||
import org.bukkit.event.Cancellable;
|
import org.bukkit.event.Cancellable;
|
||||||
import org.bukkit.event.Event;
|
import org.bukkit.event.Event;
|
||||||
|
|
||||||
|
import javax.annotation.Nullable;
|
||||||
|
|
||||||
import static com.google.common.base.Preconditions.checkNotNull;
|
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 Event originalEvent;
|
||||||
private final Cause cause;
|
private final Cause cause;
|
||||||
private boolean cancelled;
|
private boolean cancelled;
|
||||||
@ -37,8 +40,7 @@ public abstract class AbstractInteractEvent extends Event implements Cancellable
|
|||||||
* @param originalEvent the original event
|
* @param originalEvent the original event
|
||||||
* @param cause the cause
|
* @param cause the cause
|
||||||
*/
|
*/
|
||||||
protected AbstractInteractEvent(Event originalEvent, Cause cause) {
|
protected AbstractDelegateEvent(@Nullable Event originalEvent, Cause cause) {
|
||||||
checkNotNull(originalEvent);
|
|
||||||
checkNotNull(cause);
|
checkNotNull(cause);
|
||||||
this.originalEvent = originalEvent;
|
this.originalEvent = originalEvent;
|
||||||
this.cause = cause;
|
this.cause = cause;
|
||||||
@ -47,8 +49,9 @@ protected AbstractInteractEvent(Event originalEvent, Cause cause) {
|
|||||||
/**
|
/**
|
||||||
* Get the original event.
|
* Get the original event.
|
||||||
*
|
*
|
||||||
* @return the original event
|
* @return the original event, which may be {@code null} if unavailable
|
||||||
*/
|
*/
|
||||||
|
@Nullable
|
||||||
public Event getOriginalEvent() {
|
public Event getOriginalEvent() {
|
||||||
return originalEvent;
|
return originalEvent;
|
||||||
}
|
}
|
@ -20,7 +20,7 @@
|
|||||||
package com.sk89q.worldguard.bukkit.event.block;
|
package com.sk89q.worldguard.bukkit.event.block;
|
||||||
|
|
||||||
import com.sk89q.worldguard.bukkit.cause.Cause;
|
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.Location;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.block.Block;
|
import org.bukkit.block.Block;
|
||||||
@ -30,14 +30,14 @@
|
|||||||
|
|
||||||
import static com.google.common.base.Preconditions.checkNotNull;
|
import static com.google.common.base.Preconditions.checkNotNull;
|
||||||
|
|
||||||
abstract class AbstractBlockEvent extends AbstractInteractEvent {
|
abstract class AbstractBlockEvent extends AbstractDelegateEvent {
|
||||||
|
|
||||||
private final Location target;
|
private final Location target;
|
||||||
@Nullable
|
@Nullable
|
||||||
private final Block block;
|
private final Block block;
|
||||||
private final Material effectiveMaterial;
|
private final Material effectiveMaterial;
|
||||||
|
|
||||||
protected AbstractBlockEvent(Event originalEvent, Cause cause, Block block) {
|
protected AbstractBlockEvent(@Nullable Event originalEvent, Cause cause, Block block) {
|
||||||
super(originalEvent, cause);
|
super(originalEvent, cause);
|
||||||
checkNotNull(block);
|
checkNotNull(block);
|
||||||
this.target = block.getLocation();
|
this.target = block.getLocation();
|
||||||
@ -45,7 +45,7 @@ protected AbstractBlockEvent(Event originalEvent, Cause cause, Block block) {
|
|||||||
this.effectiveMaterial = block.getType();
|
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);
|
super(originalEvent, cause);
|
||||||
this.target = target;
|
this.target = target;
|
||||||
this.block = null;
|
this.block = null;
|
||||||
|
@ -26,15 +26,17 @@
|
|||||||
import org.bukkit.event.Event;
|
import org.bukkit.event.Event;
|
||||||
import org.bukkit.event.HandlerList;
|
import org.bukkit.event.HandlerList;
|
||||||
|
|
||||||
|
import javax.annotation.Nullable;
|
||||||
|
|
||||||
public class BreakBlockEvent extends AbstractBlockEvent {
|
public class BreakBlockEvent extends AbstractBlockEvent {
|
||||||
|
|
||||||
private static final HandlerList handlers = new HandlerList();
|
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);
|
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);
|
super(originalEvent, cause, target, effectiveMaterial);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -26,15 +26,17 @@
|
|||||||
import org.bukkit.event.Event;
|
import org.bukkit.event.Event;
|
||||||
import org.bukkit.event.HandlerList;
|
import org.bukkit.event.HandlerList;
|
||||||
|
|
||||||
|
import javax.annotation.Nullable;
|
||||||
|
|
||||||
public class PlaceBlockEvent extends AbstractBlockEvent {
|
public class PlaceBlockEvent extends AbstractBlockEvent {
|
||||||
|
|
||||||
private static final HandlerList handlers = new HandlerList();
|
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);
|
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);
|
super(originalEvent, cause, target, effectiveMaterial);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -26,6 +26,8 @@
|
|||||||
import org.bukkit.event.Event;
|
import org.bukkit.event.Event;
|
||||||
import org.bukkit.event.HandlerList;
|
import org.bukkit.event.HandlerList;
|
||||||
|
|
||||||
|
import javax.annotation.Nullable;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Fired when a block is interacted with.
|
* Fired when a block is interacted with.
|
||||||
*/
|
*/
|
||||||
@ -33,11 +35,11 @@ public class UseBlockEvent extends AbstractBlockEvent {
|
|||||||
|
|
||||||
private static final HandlerList handlers = new HandlerList();
|
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);
|
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);
|
super(originalEvent, cause, target, effectiveMaterial);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -20,7 +20,7 @@
|
|||||||
package com.sk89q.worldguard.bukkit.event.entity;
|
package com.sk89q.worldguard.bukkit.event.entity;
|
||||||
|
|
||||||
import com.sk89q.worldguard.bukkit.cause.Cause;
|
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.Location;
|
||||||
import org.bukkit.entity.Entity;
|
import org.bukkit.entity.Entity;
|
||||||
import org.bukkit.event.Event;
|
import org.bukkit.event.Event;
|
||||||
@ -29,20 +29,20 @@
|
|||||||
|
|
||||||
import static com.google.common.base.Preconditions.checkNotNull;
|
import static com.google.common.base.Preconditions.checkNotNull;
|
||||||
|
|
||||||
abstract class AbstractEntityEvent extends AbstractInteractEvent {
|
abstract class AbstractEntityEvent extends AbstractDelegateEvent {
|
||||||
|
|
||||||
private final Location target;
|
private final Location target;
|
||||||
@Nullable
|
@Nullable
|
||||||
private final Entity entity;
|
private final Entity entity;
|
||||||
|
|
||||||
protected AbstractEntityEvent(Event originalEvent, Cause cause, Entity entity) {
|
protected AbstractEntityEvent(@Nullable Event originalEvent, Cause cause, Entity entity) {
|
||||||
super(originalEvent, cause);
|
super(originalEvent, cause);
|
||||||
checkNotNull(entity);
|
checkNotNull(entity);
|
||||||
this.target = entity.getLocation();
|
this.target = entity.getLocation();
|
||||||
this.entity = entity;
|
this.entity = entity;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected AbstractEntityEvent(Event originalEvent, Cause cause, Location target) {
|
protected AbstractEntityEvent(@Nullable Event originalEvent, Cause cause, Location target) {
|
||||||
super(originalEvent, cause);
|
super(originalEvent, cause);
|
||||||
checkNotNull(target);
|
checkNotNull(target);
|
||||||
this.target = target;
|
this.target = target;
|
||||||
|
@ -25,6 +25,7 @@
|
|||||||
import org.bukkit.event.HandlerList;
|
import org.bukkit.event.HandlerList;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
import javax.annotation.Nonnull;
|
||||||
|
import javax.annotation.Nullable;
|
||||||
|
|
||||||
import static com.google.common.base.Preconditions.checkNotNull;
|
import static com.google.common.base.Preconditions.checkNotNull;
|
||||||
|
|
||||||
@ -32,7 +33,7 @@ public class DestroyEntityEvent extends AbstractEntityEvent {
|
|||||||
|
|
||||||
private static final HandlerList handlers = new HandlerList();
|
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));
|
super(originalEvent, cause, checkNotNull(target));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -26,6 +26,8 @@
|
|||||||
import org.bukkit.event.Event;
|
import org.bukkit.event.Event;
|
||||||
import org.bukkit.event.HandlerList;
|
import org.bukkit.event.HandlerList;
|
||||||
|
|
||||||
|
import javax.annotation.Nullable;
|
||||||
|
|
||||||
import static com.google.common.base.Preconditions.checkNotNull;
|
import static com.google.common.base.Preconditions.checkNotNull;
|
||||||
|
|
||||||
public class SpawnEntityEvent extends AbstractEntityEvent {
|
public class SpawnEntityEvent extends AbstractEntityEvent {
|
||||||
@ -33,12 +35,12 @@ public class SpawnEntityEvent extends AbstractEntityEvent {
|
|||||||
private static final HandlerList handlers = new HandlerList();
|
private static final HandlerList handlers = new HandlerList();
|
||||||
private final EntityType effectiveType;
|
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));
|
super(originalEvent, cause, checkNotNull(target));
|
||||||
this.effectiveType = target.getType();
|
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);
|
super(originalEvent, cause, location);
|
||||||
checkNotNull(type);
|
checkNotNull(type);
|
||||||
this.effectiveType = type;
|
this.effectiveType = type;
|
||||||
|
@ -25,6 +25,7 @@
|
|||||||
import org.bukkit.event.HandlerList;
|
import org.bukkit.event.HandlerList;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
import javax.annotation.Nonnull;
|
||||||
|
import javax.annotation.Nullable;
|
||||||
|
|
||||||
import static com.google.common.base.Preconditions.checkNotNull;
|
import static com.google.common.base.Preconditions.checkNotNull;
|
||||||
|
|
||||||
@ -35,7 +36,7 @@ public class UseEntityEvent extends AbstractEntityEvent {
|
|||||||
|
|
||||||
private static final HandlerList handlers = new HandlerList();
|
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));
|
super(originalEvent, cause, checkNotNull(target));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -20,24 +20,26 @@
|
|||||||
package com.sk89q.worldguard.bukkit.event.inventory;
|
package com.sk89q.worldguard.bukkit.event.inventory;
|
||||||
|
|
||||||
import com.sk89q.worldguard.bukkit.cause.Cause;
|
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.World;
|
||||||
import org.bukkit.event.Event;
|
import org.bukkit.event.Event;
|
||||||
import org.bukkit.event.HandlerList;
|
import org.bukkit.event.HandlerList;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
|
||||||
|
import javax.annotation.Nullable;
|
||||||
|
|
||||||
import static com.google.common.base.Preconditions.checkNotNull;
|
import static com.google.common.base.Preconditions.checkNotNull;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Fired when an item is interacted with.
|
* 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 static final HandlerList handlers = new HandlerList();
|
||||||
private final World world;
|
private final World world;
|
||||||
private final ItemStack itemStack;
|
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);
|
super(originalEvent, cause);
|
||||||
checkNotNull(world);
|
checkNotNull(world);
|
||||||
checkNotNull(itemStack);
|
checkNotNull(itemStack);
|
||||||
|
@ -1,252 +1,256 @@
|
|||||||
/*
|
/*
|
||||||
* WorldGuard, a suite of tools for Minecraft
|
* WorldGuard, a suite of tools for Minecraft
|
||||||
* Copyright (C) sk89q <http://www.sk89q.com>
|
* Copyright (C) sk89q <http://www.sk89q.com>
|
||||||
* Copyright (C) WorldGuard team and contributors
|
* Copyright (C) WorldGuard team and contributors
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify it
|
* 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
|
* under the terms of the GNU Lesser General Public License as published by the
|
||||||
* Free Software Foundation, either version 3 of the License, or
|
* Free Software Foundation, either version 3 of the License, or
|
||||||
* (at your option) any later version.
|
* (at your option) any later version.
|
||||||
*
|
*
|
||||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
|
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
|
||||||
* for more details.
|
* for more details.
|
||||||
*
|
*
|
||||||
* You should have received a copy of the GNU Lesser General Public License
|
* 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/>.
|
* 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.worldedit.Vector;
|
||||||
import com.sk89q.worldguard.protection.ApplicableRegionSet;
|
import com.sk89q.worldguard.bukkit.ConfigurationManager;
|
||||||
import com.sk89q.worldguard.protection.flags.DefaultFlag;
|
import com.sk89q.worldguard.bukkit.util.RegionQueryUtil;
|
||||||
import com.sk89q.worldguard.protection.managers.RegionManager;
|
import com.sk89q.worldguard.bukkit.WorldConfiguration;
|
||||||
import org.bukkit.GameMode;
|
import com.sk89q.worldguard.bukkit.WorldGuardPlugin;
|
||||||
import org.bukkit.World;
|
import com.sk89q.worldguard.protection.ApplicableRegionSet;
|
||||||
import org.bukkit.entity.Player;
|
import com.sk89q.worldguard.protection.flags.DefaultFlag;
|
||||||
|
import com.sk89q.worldguard.protection.managers.RegionManager;
|
||||||
import java.util.HashMap;
|
import org.bukkit.GameMode;
|
||||||
import java.util.Map;
|
import org.bukkit.World;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
import static com.sk89q.worldguard.bukkit.BukkitUtil.toVector;
|
|
||||||
|
import java.util.HashMap;
|
||||||
/**
|
import java.util.Map;
|
||||||
* This processes per-player state information and is also meant to be used
|
|
||||||
* as a scheduled task.
|
import static com.sk89q.worldguard.bukkit.BukkitUtil.toVector;
|
||||||
*
|
|
||||||
* @author sk89q
|
/**
|
||||||
*/
|
* This processes per-player state information and is also meant to be used
|
||||||
public class FlagStateManager implements Runnable {
|
* as a scheduled task.
|
||||||
|
*
|
||||||
public static final int RUN_DELAY = 20;
|
* @author sk89q
|
||||||
|
*/
|
||||||
private WorldGuardPlugin plugin;
|
public class FlagStateManager implements Runnable {
|
||||||
private Map<String, PlayerFlagState> states;
|
|
||||||
|
public static final int RUN_DELAY = 20;
|
||||||
/**
|
|
||||||
* Construct the object.
|
private WorldGuardPlugin plugin;
|
||||||
*
|
private Map<String, PlayerFlagState> states;
|
||||||
* @param plugin The plugin instance
|
|
||||||
*/
|
/**
|
||||||
public FlagStateManager(WorldGuardPlugin plugin) {
|
* Construct the object.
|
||||||
this.plugin = plugin;
|
*
|
||||||
|
* @param plugin The plugin instance
|
||||||
states = new HashMap<String, PlayerFlagState>();
|
*/
|
||||||
}
|
public FlagStateManager(WorldGuardPlugin plugin) {
|
||||||
|
this.plugin = plugin;
|
||||||
/**
|
|
||||||
* Run the task.
|
states = new HashMap<String, PlayerFlagState>();
|
||||||
*/
|
}
|
||||||
@Override
|
|
||||||
public void run() {
|
/**
|
||||||
Player[] players = plugin.getServer().getOnlinePlayers();
|
* Run the task.
|
||||||
ConfigurationManager config = plugin.getGlobalStateManager();
|
*/
|
||||||
|
@Override
|
||||||
for (Player player : players) {
|
public void run() {
|
||||||
WorldConfiguration worldConfig = config.get(player.getWorld());
|
Player[] players = plugin.getServer().getOnlinePlayers();
|
||||||
|
ConfigurationManager config = plugin.getGlobalStateManager();
|
||||||
if (!worldConfig.useRegions) {
|
|
||||||
continue;
|
for (Player player : players) {
|
||||||
}
|
WorldConfiguration worldConfig = config.get(player.getWorld());
|
||||||
|
|
||||||
PlayerFlagState state;
|
if (!worldConfig.useRegions) {
|
||||||
|
continue;
|
||||||
synchronized (this) {
|
}
|
||||||
state = states.get(player.getName());
|
|
||||||
|
PlayerFlagState state;
|
||||||
if (state == null) {
|
|
||||||
state = new PlayerFlagState();
|
synchronized (this) {
|
||||||
states.put(player.getName(), state);
|
state = states.get(player.getName());
|
||||||
}
|
|
||||||
}
|
if (state == null) {
|
||||||
|
state = new PlayerFlagState();
|
||||||
Vector playerLocation = toVector(player.getLocation());
|
states.put(player.getName(), state);
|
||||||
RegionManager regionManager = plugin.getGlobalRegionManager().get(player.getWorld());
|
}
|
||||||
ApplicableRegionSet applicable = regionManager.getApplicableRegions(playerLocation);
|
}
|
||||||
|
|
||||||
if (!RegionQueryUtil.isInvincible(plugin, player, applicable)
|
Vector playerLocation = toVector(player.getLocation());
|
||||||
&& !plugin.getGlobalStateManager().hasGodMode(player)
|
RegionManager regionManager = plugin.getGlobalRegionManager().get(player.getWorld());
|
||||||
&& !(player.getGameMode() == GameMode.CREATIVE)) {
|
ApplicableRegionSet applicable = regionManager.getApplicableRegions(playerLocation);
|
||||||
processHeal(applicable, player, state);
|
|
||||||
processFeed(applicable, player, state);
|
if (!RegionQueryUtil.isInvincible(plugin, player, applicable)
|
||||||
}
|
&& !plugin.getGlobalStateManager().hasGodMode(player)
|
||||||
}
|
&& !(player.getGameMode() == GameMode.CREATIVE)) {
|
||||||
}
|
processHeal(applicable, player, state);
|
||||||
|
processFeed(applicable, player, state);
|
||||||
/**
|
}
|
||||||
* Process healing for a player.
|
}
|
||||||
*
|
}
|
||||||
* @param applicable The set of applicable regions
|
|
||||||
* @param player The player to process healing flags on
|
/**
|
||||||
* @param state The player's state
|
* Process healing for a player.
|
||||||
*/
|
*
|
||||||
private void processHeal(ApplicableRegionSet applicable, Player player,
|
* @param applicable The set of applicable regions
|
||||||
PlayerFlagState state) {
|
* @param player The player to process healing flags on
|
||||||
|
* @param state The player's state
|
||||||
if (player.getHealth() <= 0) {
|
*/
|
||||||
return;
|
private void processHeal(ApplicableRegionSet applicable, Player player,
|
||||||
}
|
PlayerFlagState state) {
|
||||||
|
|
||||||
long now = System.currentTimeMillis();
|
if (player.getHealth() <= 0) {
|
||||||
|
return;
|
||||||
Integer healAmount = applicable.getFlag(DefaultFlag.HEAL_AMOUNT);
|
}
|
||||||
Integer healDelay = applicable.getFlag(DefaultFlag.HEAL_DELAY);
|
|
||||||
Double minHealth = applicable.getFlag(DefaultFlag.MIN_HEAL);
|
long now = System.currentTimeMillis();
|
||||||
Double maxHealth = applicable.getFlag(DefaultFlag.MAX_HEAL);
|
|
||||||
|
Integer healAmount = applicable.getFlag(DefaultFlag.HEAL_AMOUNT);
|
||||||
if (healAmount == null || healDelay == null || healAmount == 0 || healDelay < 0) {
|
Integer healDelay = applicable.getFlag(DefaultFlag.HEAL_DELAY);
|
||||||
return;
|
Double minHealth = applicable.getFlag(DefaultFlag.MIN_HEAL);
|
||||||
}
|
Double maxHealth = applicable.getFlag(DefaultFlag.MAX_HEAL);
|
||||||
if (minHealth == null) {
|
|
||||||
minHealth = 0.0;
|
if (healAmount == null || healDelay == null || healAmount == 0 || healDelay < 0) {
|
||||||
}
|
return;
|
||||||
if (maxHealth == null) {
|
}
|
||||||
maxHealth = player.getMaxHealth();
|
if (minHealth == null) {
|
||||||
}
|
minHealth = 0.0;
|
||||||
|
}
|
||||||
// Apply a cap to prevent possible exceptions
|
if (maxHealth == null) {
|
||||||
minHealth = Math.min(player.getMaxHealth(), minHealth);
|
maxHealth = player.getMaxHealth();
|
||||||
maxHealth = Math.min(player.getMaxHealth(), maxHealth);
|
}
|
||||||
|
|
||||||
if (player.getHealth() >= maxHealth && healAmount > 0) {
|
// Apply a cap to prevent possible exceptions
|
||||||
return;
|
minHealth = Math.min(player.getMaxHealth(), minHealth);
|
||||||
}
|
maxHealth = Math.min(player.getMaxHealth(), maxHealth);
|
||||||
|
|
||||||
if (healDelay <= 0) {
|
if (player.getHealth() >= maxHealth && healAmount > 0) {
|
||||||
player.setHealth(healAmount > 0 ? maxHealth : minHealth); // this will insta-kill if the flag is unset
|
return;
|
||||||
state.lastHeal = now;
|
}
|
||||||
} else if (now - state.lastHeal > healDelay * 1000) {
|
|
||||||
// clamp health between minimum and maximum
|
if (healDelay <= 0) {
|
||||||
player.setHealth(Math.min(maxHealth, Math.max(minHealth, player.getHealth() + healAmount)));
|
player.setHealth(healAmount > 0 ? maxHealth : minHealth); // this will insta-kill if the flag is unset
|
||||||
state.lastHeal = now;
|
state.lastHeal = now;
|
||||||
}
|
} else if (now - state.lastHeal > healDelay * 1000) {
|
||||||
}
|
// clamp health between minimum and maximum
|
||||||
|
player.setHealth(Math.min(maxHealth, Math.max(minHealth, player.getHealth() + healAmount)));
|
||||||
/**
|
state.lastHeal = now;
|
||||||
* Process restoring hunger for a player.
|
}
|
||||||
*
|
}
|
||||||
* @param applicable The set of applicable regions
|
|
||||||
* @param player The player to process hunger flags on
|
/**
|
||||||
* @param state The player's state
|
* Process restoring hunger for a player.
|
||||||
*/
|
*
|
||||||
private void processFeed(ApplicableRegionSet applicable, Player player,
|
* @param applicable The set of applicable regions
|
||||||
PlayerFlagState state) {
|
* @param player The player to process hunger flags on
|
||||||
|
* @param state The player's state
|
||||||
long now = System.currentTimeMillis();
|
*/
|
||||||
|
private void processFeed(ApplicableRegionSet applicable, Player player,
|
||||||
Integer feedAmount = applicable.getFlag(DefaultFlag.FEED_AMOUNT);
|
PlayerFlagState state) {
|
||||||
Integer feedDelay = applicable.getFlag(DefaultFlag.FEED_DELAY);
|
|
||||||
Integer minHunger = applicable.getFlag(DefaultFlag.MIN_FOOD);
|
long now = System.currentTimeMillis();
|
||||||
Integer maxHunger = applicable.getFlag(DefaultFlag.MAX_FOOD);
|
|
||||||
|
Integer feedAmount = applicable.getFlag(DefaultFlag.FEED_AMOUNT);
|
||||||
if (feedAmount == null || feedDelay == null || feedAmount == 0 || feedDelay < 0) {
|
Integer feedDelay = applicable.getFlag(DefaultFlag.FEED_DELAY);
|
||||||
return;
|
Integer minHunger = applicable.getFlag(DefaultFlag.MIN_FOOD);
|
||||||
}
|
Integer maxHunger = applicable.getFlag(DefaultFlag.MAX_FOOD);
|
||||||
if (minHunger == null) {
|
|
||||||
minHunger = 0;
|
if (feedAmount == null || feedDelay == null || feedAmount == 0 || feedDelay < 0) {
|
||||||
}
|
return;
|
||||||
if (maxHunger == null) {
|
}
|
||||||
maxHunger = 20;
|
if (minHunger == null) {
|
||||||
}
|
minHunger = 0;
|
||||||
|
}
|
||||||
// Apply a cap to prevent possible exceptions
|
if (maxHunger == null) {
|
||||||
minHunger = Math.min(20, minHunger);
|
maxHunger = 20;
|
||||||
maxHunger = Math.min(20, maxHunger);
|
}
|
||||||
|
|
||||||
if (player.getFoodLevel() >= maxHunger && feedAmount > 0) {
|
// Apply a cap to prevent possible exceptions
|
||||||
return;
|
minHunger = Math.min(20, minHunger);
|
||||||
}
|
maxHunger = Math.min(20, maxHunger);
|
||||||
|
|
||||||
if (feedDelay <= 0) {
|
if (player.getFoodLevel() >= maxHunger && feedAmount > 0) {
|
||||||
player.setFoodLevel(feedAmount > 0 ? maxHunger : minHunger);
|
return;
|
||||||
player.setSaturation(player.getFoodLevel());
|
}
|
||||||
state.lastFeed = now;
|
|
||||||
} else if (now - state.lastFeed > feedDelay * 1000) {
|
if (feedDelay <= 0) {
|
||||||
// clamp health between minimum and maximum
|
player.setFoodLevel(feedAmount > 0 ? maxHunger : minHunger);
|
||||||
player.setFoodLevel(Math.min(maxHunger, Math.max(minHunger, player.getFoodLevel() + feedAmount)));
|
player.setSaturation(player.getFoodLevel());
|
||||||
player.setSaturation(player.getFoodLevel());
|
state.lastFeed = now;
|
||||||
state.lastFeed = now;
|
} else if (now - state.lastFeed > feedDelay * 1000) {
|
||||||
}
|
// clamp health between minimum and maximum
|
||||||
}
|
player.setFoodLevel(Math.min(maxHunger, Math.max(minHunger, player.getFoodLevel() + feedAmount)));
|
||||||
|
player.setSaturation(player.getFoodLevel());
|
||||||
/**
|
state.lastFeed = now;
|
||||||
* Forget a player.
|
}
|
||||||
*
|
}
|
||||||
* @param player The player to forget
|
|
||||||
*/
|
/**
|
||||||
public synchronized void forget(Player player) {
|
* Forget a player.
|
||||||
states.remove(player.getName());
|
*
|
||||||
}
|
* @param player The player to forget
|
||||||
|
*/
|
||||||
/**
|
public synchronized void forget(Player player) {
|
||||||
* Forget all managed players. Use with caution.
|
states.remove(player.getName());
|
||||||
*/
|
}
|
||||||
public synchronized void forgetAll() {
|
|
||||||
states.clear();
|
/**
|
||||||
}
|
* Forget all managed players. Use with caution.
|
||||||
|
*/
|
||||||
/**
|
public synchronized void forgetAll() {
|
||||||
* Get a player's flag state. A new state will be created if there is no existing
|
states.clear();
|
||||||
* state for the player.
|
}
|
||||||
*
|
|
||||||
* @param player The player to get a state for
|
/**
|
||||||
* @return The {@code player}'s state
|
* Get a player's flag state. A new state will be created if there is no existing
|
||||||
*/
|
* state for the player.
|
||||||
public synchronized PlayerFlagState getState(Player player) {
|
*
|
||||||
PlayerFlagState state = states.get(player.getName());
|
* @param player The player to get a state for
|
||||||
|
* @return The {@code player}'s state
|
||||||
if (state == null) {
|
*/
|
||||||
state = new PlayerFlagState();
|
public synchronized PlayerFlagState getState(Player player) {
|
||||||
states.put(player.getName(), state);
|
PlayerFlagState state = states.get(player.getName());
|
||||||
}
|
|
||||||
|
if (state == null) {
|
||||||
return state;
|
state = new PlayerFlagState();
|
||||||
}
|
states.put(player.getName(), state);
|
||||||
|
}
|
||||||
/**
|
|
||||||
* Keeps state per player.
|
return state;
|
||||||
*/
|
}
|
||||||
public static class PlayerFlagState {
|
|
||||||
public long lastHeal;
|
/**
|
||||||
public long lastFeed;
|
* Keeps state per player.
|
||||||
public String lastGreeting;
|
*/
|
||||||
public String lastFarewell;
|
public static class PlayerFlagState {
|
||||||
public Boolean lastExitAllowed = null;
|
public long lastHeal;
|
||||||
public Boolean notifiedForLeave = false;
|
public long lastFeed;
|
||||||
public Boolean notifiedForEnter = false;
|
public String lastGreeting;
|
||||||
public GameMode lastGameMode;
|
public String lastFarewell;
|
||||||
public World lastWorld;
|
public Boolean lastExitAllowed = null;
|
||||||
public int lastBlockX;
|
public Boolean notifiedForLeave = false;
|
||||||
public int lastBlockY;
|
public Boolean notifiedForEnter = false;
|
||||||
public int lastBlockZ;
|
public GameMode lastGameMode;
|
||||||
|
public World lastWorld;
|
||||||
/* Used to cache invincibility status */
|
public int lastBlockX;
|
||||||
public World lastInvincibleWorld;
|
public int lastBlockY;
|
||||||
public int lastInvincibleX;
|
public int lastBlockZ;
|
||||||
public int lastInvincibleY;
|
|
||||||
public int lastInvincibleZ;
|
/* Used to cache invincibility status */
|
||||||
public boolean wasInvincible;
|
public World lastInvincibleWorld;
|
||||||
}
|
public int lastInvincibleX;
|
||||||
}
|
public int lastInvincibleY;
|
||||||
|
public int lastInvincibleZ;
|
||||||
|
public boolean wasInvincible;
|
||||||
|
}
|
||||||
|
}
|
@ -19,7 +19,7 @@
|
|||||||
|
|
||||||
package com.sk89q.worldguard.bukkit.listener;
|
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.WorldGuardPlugin;
|
||||||
import com.sk89q.worldguard.bukkit.event.block.BreakBlockEvent;
|
import com.sk89q.worldguard.bukkit.event.block.BreakBlockEvent;
|
||||||
import com.sk89q.worldguard.bukkit.event.block.PlaceBlockEvent;
|
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.event.entity.UseEntityEvent;
|
||||||
import com.sk89q.worldguard.bukkit.util.Entities;
|
import com.sk89q.worldguard.bukkit.util.Entities;
|
||||||
import com.sk89q.worldguard.bukkit.util.Materials;
|
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.flags.DefaultFlag;
|
||||||
import com.sk89q.worldguard.protection.managers.RegionManager;
|
|
||||||
import org.bukkit.ChatColor;
|
import org.bukkit.ChatColor;
|
||||||
import org.bukkit.Chunk;
|
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
import org.bukkit.entity.EntityType;
|
import org.bukkit.entity.EntityType;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.event.EventHandler;
|
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.
|
* 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.");
|
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)
|
@EventHandler(ignoreCancelled = true)
|
||||||
public void onPlaceBlock(PlaceBlockEvent event) {
|
public void onPlaceBlock(PlaceBlockEvent event) {
|
||||||
Player player = event.getCause().getPlayerRootCause();
|
Player player = event.getCause().getPlayerRootCause();
|
||||||
@ -98,15 +63,15 @@ public void onPlaceBlock(PlaceBlockEvent event) {
|
|||||||
Material type = event.getEffectiveMaterial();
|
Material type = event.getEffectiveMaterial();
|
||||||
|
|
||||||
if (player != null) {
|
if (player != null) {
|
||||||
ProtectedRegionQuery query = new ProtectedRegionQuery(getPlugin(), player);
|
RegionQuery query = getPlugin().getRegionContainer().createQuery(player);
|
||||||
boolean canPlace;
|
boolean canPlace;
|
||||||
|
|
||||||
// Flint and steel, fire charge
|
// Flint and steel, fire charge
|
||||||
if (type == Material.FIRE) {
|
if (type == Material.FIRE) {
|
||||||
canPlace = query.allows(DefaultFlag.LIGHTER, target) || (query.canBuild(target) && query.canConstruct(target));
|
canPlace = query.testPermission(target, DefaultFlag.LIGHTER);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
canPlace = query.canBuild(target) && query.canConstruct(target);
|
canPlace = query.testPermission(target);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!canPlace) {
|
if (!canPlace) {
|
||||||
@ -139,30 +104,24 @@ public void onUseBlock(UseBlockEvent event) {
|
|||||||
Material type = event.getEffectiveMaterial();
|
Material type = event.getEffectiveMaterial();
|
||||||
|
|
||||||
if (player != null) {
|
if (player != null) {
|
||||||
ProtectedRegionQuery query = new ProtectedRegionQuery(getPlugin(), player);
|
RegionQuery query = getPlugin().getRegionContainer().createQuery(player);
|
||||||
boolean canUse;
|
boolean canUse;
|
||||||
|
|
||||||
// Inventory blocks (CHEST_ACCESS)
|
// Inventory blocks (CHEST_ACCESS)
|
||||||
if (Materials.isInventoryBlock(type)) {
|
if (Materials.isInventoryBlock(type)) {
|
||||||
canUse = query.canBuild( target)
|
canUse = query.testPermission(target, DefaultFlag.USE, DefaultFlag.CHEST_ACCESS);
|
||||||
|| query.allows(DefaultFlag.CHEST_ACCESS, target)
|
|
||||||
|| query.allows(DefaultFlag.USE, target);
|
|
||||||
|
|
||||||
// Beds (SLEEP)
|
// Beds (SLEEP)
|
||||||
} else if (type == Material.BED) {
|
} else if (type == Material.BED) {
|
||||||
canUse = query.canBuild(target)
|
canUse = query.testPermission(target, DefaultFlag.USE, DefaultFlag.SLEEP);
|
||||||
|| query.allows(DefaultFlag.SLEEP, target)
|
|
||||||
|| query.allows(DefaultFlag.USE, target);
|
|
||||||
|
|
||||||
// TNT (TNT)
|
// TNT (TNT)
|
||||||
} else if (type == Material.TNT) {
|
} else if (type == Material.TNT) {
|
||||||
canUse = query.canBuild(target)
|
canUse = query.testPermission(target, DefaultFlag.TNT);
|
||||||
|| query.allows(DefaultFlag.TNT, target);
|
|
||||||
|
|
||||||
// Everything else
|
// Everything else
|
||||||
} else {
|
} else {
|
||||||
canUse = query.canBuild(target)
|
canUse = query.testPermission(target, DefaultFlag.USE);
|
||||||
|| query.allows(DefaultFlag.USE, target);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!canUse) {
|
if (!canUse) {
|
||||||
@ -179,13 +138,13 @@ public void onSpawnEntity(SpawnEntityEvent event) {
|
|||||||
EntityType type = event.getEffectiveType();
|
EntityType type = event.getEffectiveType();
|
||||||
|
|
||||||
if (player != null) {
|
if (player != null) {
|
||||||
ProtectedRegionQuery query = new ProtectedRegionQuery(getPlugin(), player);
|
RegionQuery query = getPlugin().getRegionContainer().createQuery(player);
|
||||||
boolean canSpawn;
|
boolean canSpawn;
|
||||||
|
|
||||||
if (Entities.isVehicle(type)) {
|
if (Entities.isVehicle(type)) {
|
||||||
canSpawn = query.canBuild(target) || query.allows(DefaultFlag.PLACE_VEHICLE, target);
|
canSpawn = query.testPermission(target, DefaultFlag.PLACE_VEHICLE);
|
||||||
} else {
|
} else {
|
||||||
canSpawn = query.canBuild(target);
|
canSpawn = query.testPermission(target);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!canSpawn) {
|
if (!canSpawn) {
|
||||||
@ -202,13 +161,13 @@ public void onDestroyEntity(DestroyEntityEvent event) {
|
|||||||
EntityType type = event.getEntity().getType();
|
EntityType type = event.getEntity().getType();
|
||||||
|
|
||||||
if (player != null) {
|
if (player != null) {
|
||||||
ProtectedRegionQuery query = new ProtectedRegionQuery(getPlugin(), player);
|
RegionQuery query = getPlugin().getRegionContainer().createQuery(player);
|
||||||
boolean canDestroy;
|
boolean canDestroy;
|
||||||
|
|
||||||
if (Entities.isVehicle(type)) {
|
if (Entities.isVehicle(type)) {
|
||||||
canDestroy = query.canBuild(target) || query.allows(DefaultFlag.DESTROY_VEHICLE, target);
|
canDestroy = query.testPermission(target, DefaultFlag.DESTROY_VEHICLE);
|
||||||
} else {
|
} else {
|
||||||
canDestroy = query.canBuild(target);
|
canDestroy = query.testPermission(target);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!canDestroy) {
|
if (!canDestroy) {
|
||||||
@ -224,8 +183,8 @@ public void onUseEntity(UseEntityEvent event) {
|
|||||||
Location target = event.getTarget();
|
Location target = event.getTarget();
|
||||||
|
|
||||||
if (player != null) {
|
if (player != null) {
|
||||||
ProtectedRegionQuery query = new ProtectedRegionQuery(getPlugin(), player);
|
RegionQuery query = getPlugin().getRegionContainer().createQuery(player);
|
||||||
boolean canUse = query.canBuild(target) || query.allows(DefaultFlag.USE, target);
|
boolean canUse = query.testPermission(target, DefaultFlag.USE);
|
||||||
|
|
||||||
if (!canUse) {
|
if (!canUse) {
|
||||||
tellErrorMessage(player, target);
|
tellErrorMessage(player, target);
|
||||||
|
@ -1,129 +1,132 @@
|
|||||||
/*
|
/*
|
||||||
* WorldGuard, a suite of tools for Minecraft
|
* WorldGuard, a suite of tools for Minecraft
|
||||||
* Copyright (C) sk89q <http://www.sk89q.com>
|
* Copyright (C) sk89q <http://www.sk89q.com>
|
||||||
* Copyright (C) WorldGuard team and contributors
|
* Copyright (C) WorldGuard team and contributors
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify it
|
* 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
|
* under the terms of the GNU Lesser General Public License as published by the
|
||||||
* Free Software Foundation, either version 3 of the License, or
|
* Free Software Foundation, either version 3 of the License, or
|
||||||
* (at your option) any later version.
|
* (at your option) any later version.
|
||||||
*
|
*
|
||||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
|
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
|
||||||
* for more details.
|
* for more details.
|
||||||
*
|
*
|
||||||
* You should have received a copy of the GNU Lesser General Public License
|
* 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/>.
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package com.sk89q.worldguard.bukkit;
|
package com.sk89q.worldguard.bukkit.listener;
|
||||||
|
|
||||||
import org.bukkit.World;
|
import com.sk89q.worldguard.bukkit.ConfigurationManager;
|
||||||
|
import com.sk89q.worldguard.bukkit.WorldConfiguration;
|
||||||
import static com.sk89q.worldguard.bukkit.BukkitUtil.isBlockWater;
|
import com.sk89q.worldguard.bukkit.WorldGuardPlugin;
|
||||||
import static com.sk89q.worldguard.bukkit.BukkitUtil.setBlockToWater;
|
import org.bukkit.World;
|
||||||
|
|
||||||
public final class SpongeUtil {
|
import static com.sk89q.worldguard.bukkit.BukkitUtil.isBlockWater;
|
||||||
|
import static com.sk89q.worldguard.bukkit.BukkitUtil.setBlockToWater;
|
||||||
private SpongeUtil() {
|
|
||||||
}
|
public final class SpongeUtil {
|
||||||
|
|
||||||
/**
|
private SpongeUtil() {
|
||||||
* Remove water around a sponge.
|
}
|
||||||
*
|
|
||||||
* @param plugin The plugin instace
|
/**
|
||||||
* @param world The world the sponge isin
|
* Remove water around a sponge.
|
||||||
* @param ox The x coordinate of the 'sponge' block
|
*
|
||||||
* @param oy The y coordinate of the 'sponge' block
|
* @param plugin The plugin instace
|
||||||
* @param oz The z coordinate of the 'sponge' block
|
* @param world The world the sponge isin
|
||||||
*/
|
* @param ox The x coordinate of the 'sponge' block
|
||||||
public static void clearSpongeWater(WorldGuardPlugin plugin, World world, int ox, int oy, int oz) {
|
* @param oy The y coordinate of the 'sponge' block
|
||||||
ConfigurationManager cfg = plugin.getGlobalStateManager();
|
* @param oz The z coordinate of the 'sponge' block
|
||||||
WorldConfiguration wcfg = cfg.get(world);
|
*/
|
||||||
|
public static void clearSpongeWater(WorldGuardPlugin plugin, World world, int ox, int oy, int oz) {
|
||||||
for (int cx = -wcfg.spongeRadius; cx <= wcfg.spongeRadius; cx++) {
|
ConfigurationManager cfg = plugin.getGlobalStateManager();
|
||||||
for (int cy = -wcfg.spongeRadius; cy <= wcfg.spongeRadius; cy++) {
|
WorldConfiguration wcfg = cfg.get(world);
|
||||||
for (int cz = -wcfg.spongeRadius; cz <= wcfg.spongeRadius; cz++) {
|
|
||||||
if (isBlockWater(world, ox + cx, oy + cy, oz + cz)) {
|
for (int cx = -wcfg.spongeRadius; cx <= wcfg.spongeRadius; cx++) {
|
||||||
world.getBlockAt(ox + cx, oy + cy, oz + cz).setTypeId(0);
|
for (int cy = -wcfg.spongeRadius; cy <= wcfg.spongeRadius; cy++) {
|
||||||
}
|
for (int cz = -wcfg.spongeRadius; cz <= wcfg.spongeRadius; cz++) {
|
||||||
}
|
if (isBlockWater(world, ox + cx, oy + cy, oz + cz)) {
|
||||||
}
|
world.getBlockAt(ox + cx, oy + cy, oz + cz).setTypeId(0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
/**
|
}
|
||||||
* Add water around a sponge.
|
}
|
||||||
*
|
|
||||||
* @param plugin The plugin instance
|
/**
|
||||||
* @param world The world the sponge is located in
|
* Add water around a sponge.
|
||||||
* @param ox The x coordinate of the 'sponge' block
|
*
|
||||||
* @param oy The y coordinate of the 'sponge' block
|
* @param plugin The plugin instance
|
||||||
* @param oz The z coordinate of the 'sponge' block
|
* @param world The world the sponge is located in
|
||||||
*/
|
* @param ox The x coordinate of the 'sponge' block
|
||||||
public static void addSpongeWater(WorldGuardPlugin plugin, World world, int ox, int oy, int oz) {
|
* @param oy The y coordinate of the 'sponge' block
|
||||||
ConfigurationManager cfg = plugin.getGlobalStateManager();
|
* @param oz The z coordinate of the 'sponge' block
|
||||||
WorldConfiguration wcfg = cfg.get(world);
|
*/
|
||||||
|
public static void addSpongeWater(WorldGuardPlugin plugin, World world, int ox, int oy, int oz) {
|
||||||
// The negative x edge
|
ConfigurationManager cfg = plugin.getGlobalStateManager();
|
||||||
int cx = ox - wcfg.spongeRadius - 1;
|
WorldConfiguration wcfg = cfg.get(world);
|
||||||
for (int cy = oy - wcfg.spongeRadius - 1; cy <= oy + wcfg.spongeRadius + 1; cy++) {
|
|
||||||
for (int cz = oz - wcfg.spongeRadius - 1; cz <= oz + wcfg.spongeRadius + 1; cz++) {
|
// The negative x edge
|
||||||
if (isBlockWater(world, cx, cy, cz)) {
|
int cx = ox - wcfg.spongeRadius - 1;
|
||||||
setBlockToWater(world, cx + 1, cy, cz);
|
for (int cy = oy - wcfg.spongeRadius - 1; cy <= oy + wcfg.spongeRadius + 1; cy++) {
|
||||||
}
|
for (int cz = oz - wcfg.spongeRadius - 1; cz <= oz + wcfg.spongeRadius + 1; cz++) {
|
||||||
}
|
if (isBlockWater(world, cx, cy, cz)) {
|
||||||
}
|
setBlockToWater(world, cx + 1, cy, cz);
|
||||||
|
}
|
||||||
// The positive x edge
|
}
|
||||||
cx = ox + wcfg.spongeRadius + 1;
|
}
|
||||||
for (int cy = oy - wcfg.spongeRadius - 1; cy <= oy + wcfg.spongeRadius + 1; cy++) {
|
|
||||||
for (int cz = oz - wcfg.spongeRadius - 1; cz <= oz + wcfg.spongeRadius + 1; cz++) {
|
// The positive x edge
|
||||||
if (isBlockWater(world, cx, cy, cz)) {
|
cx = ox + wcfg.spongeRadius + 1;
|
||||||
setBlockToWater(world, cx - 1, cy, cz);
|
for (int cy = oy - wcfg.spongeRadius - 1; cy <= oy + wcfg.spongeRadius + 1; cy++) {
|
||||||
}
|
for (int cz = oz - wcfg.spongeRadius - 1; cz <= oz + wcfg.spongeRadius + 1; cz++) {
|
||||||
}
|
if (isBlockWater(world, cx, cy, cz)) {
|
||||||
}
|
setBlockToWater(world, cx - 1, cy, cz);
|
||||||
|
}
|
||||||
// The negative y edge
|
}
|
||||||
int cy = oy - wcfg.spongeRadius - 1;
|
}
|
||||||
for (cx = ox - wcfg.spongeRadius - 1; cx <= ox + wcfg.spongeRadius + 1; cx++) {
|
|
||||||
for (int cz = oz - wcfg.spongeRadius - 1; cz <= oz + wcfg.spongeRadius + 1; cz++) {
|
// The negative y edge
|
||||||
if (isBlockWater(world, cx, cy, cz)) {
|
int cy = oy - wcfg.spongeRadius - 1;
|
||||||
setBlockToWater(world, cx, cy + 1, cz);
|
for (cx = ox - wcfg.spongeRadius - 1; cx <= ox + wcfg.spongeRadius + 1; cx++) {
|
||||||
}
|
for (int cz = oz - wcfg.spongeRadius - 1; cz <= oz + wcfg.spongeRadius + 1; cz++) {
|
||||||
}
|
if (isBlockWater(world, cx, cy, cz)) {
|
||||||
}
|
setBlockToWater(world, cx, cy + 1, cz);
|
||||||
|
}
|
||||||
// The positive y edge
|
}
|
||||||
cy = oy + wcfg.spongeRadius + 1;
|
}
|
||||||
for (cx = ox - wcfg.spongeRadius - 1; cx <= ox + wcfg.spongeRadius + 1; cx++) {
|
|
||||||
for (int cz = oz - wcfg.spongeRadius - 1; cz <= oz + wcfg.spongeRadius + 1; cz++) {
|
// The positive y edge
|
||||||
if (isBlockWater(world, cx, cy, cz)) {
|
cy = oy + wcfg.spongeRadius + 1;
|
||||||
setBlockToWater(world, cx, cy - 1, cz);
|
for (cx = ox - wcfg.spongeRadius - 1; cx <= ox + wcfg.spongeRadius + 1; cx++) {
|
||||||
}
|
for (int cz = oz - wcfg.spongeRadius - 1; cz <= oz + wcfg.spongeRadius + 1; cz++) {
|
||||||
}
|
if (isBlockWater(world, cx, cy, cz)) {
|
||||||
}
|
setBlockToWater(world, cx, cy - 1, cz);
|
||||||
|
}
|
||||||
// The negative z edge
|
}
|
||||||
int cz = oz - wcfg.spongeRadius - 1;
|
}
|
||||||
for (cx = ox - wcfg.spongeRadius - 1; cx <= ox + wcfg.spongeRadius + 1; cx++) {
|
|
||||||
for (cy = oy - wcfg.spongeRadius - 1; cy <= oy + wcfg.spongeRadius + 1; cy++) {
|
// The negative z edge
|
||||||
if (isBlockWater(world, cx, cy, cz)) {
|
int cz = oz - wcfg.spongeRadius - 1;
|
||||||
setBlockToWater(world, cx, cy, cz + 1);
|
for (cx = ox - wcfg.spongeRadius - 1; cx <= ox + wcfg.spongeRadius + 1; cx++) {
|
||||||
}
|
for (cy = oy - wcfg.spongeRadius - 1; cy <= oy + wcfg.spongeRadius + 1; cy++) {
|
||||||
}
|
if (isBlockWater(world, cx, cy, cz)) {
|
||||||
}
|
setBlockToWater(world, cx, cy, cz + 1);
|
||||||
|
}
|
||||||
// The positive z edge
|
}
|
||||||
cz = oz + wcfg.spongeRadius + 1;
|
}
|
||||||
for (cx = ox - wcfg.spongeRadius - 1; cx <= ox + wcfg.spongeRadius + 1; cx++) {
|
|
||||||
for (cy = oy - wcfg.spongeRadius - 1; cy <= oy + wcfg.spongeRadius + 1; cy++) {
|
// The positive z edge
|
||||||
if (isBlockWater(world, cx, cy, cz)) {
|
cz = oz + wcfg.spongeRadius + 1;
|
||||||
setBlockToWater(world, cx, cy, cz - 1);
|
for (cx = ox - wcfg.spongeRadius - 1; cx <= ox + wcfg.spongeRadius + 1; cx++) {
|
||||||
}
|
for (cy = oy - wcfg.spongeRadius - 1; cy <= oy + wcfg.spongeRadius + 1; cy++) {
|
||||||
}
|
if (isBlockWater(world, cx, cy, cz)) {
|
||||||
}
|
setBlockToWater(world, cx, cy, cz - 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -24,7 +24,6 @@
|
|||||||
import com.sk89q.worldedit.blocks.BlockType;
|
import com.sk89q.worldedit.blocks.BlockType;
|
||||||
import com.sk89q.worldedit.blocks.ItemType;
|
import com.sk89q.worldedit.blocks.ItemType;
|
||||||
import com.sk89q.worldguard.bukkit.ConfigurationManager;
|
import com.sk89q.worldguard.bukkit.ConfigurationManager;
|
||||||
import com.sk89q.worldguard.bukkit.SpongeUtil;
|
|
||||||
import com.sk89q.worldguard.bukkit.WorldConfiguration;
|
import com.sk89q.worldguard.bukkit.WorldConfiguration;
|
||||||
import com.sk89q.worldguard.bukkit.WorldGuardPlugin;
|
import com.sk89q.worldguard.bukkit.WorldGuardPlugin;
|
||||||
import com.sk89q.worldguard.protection.ApplicableRegionSet;
|
import com.sk89q.worldguard.protection.ApplicableRegionSet;
|
||||||
|
@ -24,7 +24,7 @@
|
|||||||
import com.sk89q.worldguard.LocalPlayer;
|
import com.sk89q.worldguard.LocalPlayer;
|
||||||
import com.sk89q.worldguard.bukkit.BukkitUtil;
|
import com.sk89q.worldguard.bukkit.BukkitUtil;
|
||||||
import com.sk89q.worldguard.bukkit.ConfigurationManager;
|
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.WorldConfiguration;
|
||||||
import com.sk89q.worldguard.bukkit.WorldGuardPlugin;
|
import com.sk89q.worldguard.bukkit.WorldGuardPlugin;
|
||||||
import com.sk89q.worldguard.protection.ApplicableRegionSet;
|
import com.sk89q.worldguard.protection.ApplicableRegionSet;
|
||||||
|
@ -22,10 +22,9 @@
|
|||||||
import com.sk89q.worldedit.Vector;
|
import com.sk89q.worldedit.Vector;
|
||||||
import com.sk89q.worldedit.blocks.BlockID;
|
import com.sk89q.worldedit.blocks.BlockID;
|
||||||
import com.sk89q.worldguard.LocalPlayer;
|
import com.sk89q.worldguard.LocalPlayer;
|
||||||
import com.sk89q.worldguard.blacklist.event.ItemUseBlacklistEvent;
|
|
||||||
import com.sk89q.worldguard.bukkit.BukkitUtil;
|
import com.sk89q.worldguard.bukkit.BukkitUtil;
|
||||||
import com.sk89q.worldguard.bukkit.ConfigurationManager;
|
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.WorldConfiguration;
|
||||||
import com.sk89q.worldguard.bukkit.WorldGuardPlugin;
|
import com.sk89q.worldguard.bukkit.WorldGuardPlugin;
|
||||||
import com.sk89q.worldguard.protection.ApplicableRegionSet;
|
import com.sk89q.worldguard.protection.ApplicableRegionSet;
|
||||||
@ -50,7 +49,6 @@
|
|||||||
import org.bukkit.event.player.PlayerDropItemEvent;
|
import org.bukkit.event.player.PlayerDropItemEvent;
|
||||||
import org.bukkit.event.player.PlayerFishEvent;
|
import org.bukkit.event.player.PlayerFishEvent;
|
||||||
import org.bukkit.event.player.PlayerGameModeChangeEvent;
|
import org.bukkit.event.player.PlayerGameModeChangeEvent;
|
||||||
import org.bukkit.event.player.PlayerInteractEntityEvent;
|
|
||||||
import org.bukkit.event.player.PlayerInteractEvent;
|
import org.bukkit.event.player.PlayerInteractEvent;
|
||||||
import org.bukkit.event.player.PlayerItemHeldEvent;
|
import org.bukkit.event.player.PlayerItemHeldEvent;
|
||||||
import org.bukkit.event.player.PlayerJoinEvent;
|
import org.bukkit.event.player.PlayerJoinEvent;
|
||||||
|
@ -17,14 +17,14 @@
|
|||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package com.sk89q.worldguard.bukkit;
|
package com.sk89q.worldguard.bukkit.util;
|
||||||
|
|
||||||
import java.util.logging.Handler;
|
|
||||||
import java.util.logging.LogRecord;
|
|
||||||
|
|
||||||
import org.bukkit.ChatColor;
|
import org.bukkit.ChatColor;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
|
|
||||||
|
import java.util.logging.Handler;
|
||||||
|
import java.util.logging.LogRecord;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sends all logger messages to a player.
|
* Sends all logger messages to a player.
|
||||||
*
|
*
|
@ -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);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -1,86 +1,88 @@
|
|||||||
/*
|
/*
|
||||||
* WorldGuard, a suite of tools for Minecraft
|
* WorldGuard, a suite of tools for Minecraft
|
||||||
* Copyright (C) sk89q <http://www.sk89q.com>
|
* Copyright (C) sk89q <http://www.sk89q.com>
|
||||||
* Copyright (C) WorldGuard team and contributors
|
* Copyright (C) WorldGuard team and contributors
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify it
|
* 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
|
* under the terms of the GNU Lesser General Public License as published by the
|
||||||
* Free Software Foundation, either version 3 of the License, or
|
* Free Software Foundation, either version 3 of the License, or
|
||||||
* (at your option) any later version.
|
* (at your option) any later version.
|
||||||
*
|
*
|
||||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
|
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
|
||||||
* for more details.
|
* for more details.
|
||||||
*
|
*
|
||||||
* You should have received a copy of the GNU Lesser General Public License
|
* 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/>.
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package com.sk89q.worldguard.bukkit;
|
package com.sk89q.worldguard.bukkit.util;
|
||||||
|
|
||||||
import org.bukkit.Location;
|
import com.sk89q.worldguard.bukkit.WorldGuardPlugin;
|
||||||
import org.bukkit.World;
|
import com.sk89q.worldguard.bukkit.listener.FlagStateManager;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.Location;
|
||||||
|
import org.bukkit.World;
|
||||||
import com.sk89q.worldedit.Vector;
|
import org.bukkit.entity.Player;
|
||||||
import com.sk89q.worldguard.protection.ApplicableRegionSet;
|
|
||||||
import com.sk89q.worldguard.protection.flags.DefaultFlag;
|
import com.sk89q.worldedit.Vector;
|
||||||
import com.sk89q.worldguard.protection.flags.StateFlag;
|
import com.sk89q.worldguard.protection.ApplicableRegionSet;
|
||||||
import com.sk89q.worldguard.protection.managers.RegionManager;
|
import com.sk89q.worldguard.protection.flags.DefaultFlag;
|
||||||
|
import com.sk89q.worldguard.protection.flags.StateFlag;
|
||||||
public final class RegionQueryUtil {
|
import com.sk89q.worldguard.protection.managers.RegionManager;
|
||||||
|
|
||||||
private RegionQueryUtil() {
|
public final class RegionQueryUtil {
|
||||||
}
|
|
||||||
|
private RegionQueryUtil() {
|
||||||
public static boolean isInvincible(WorldGuardPlugin plugin, Player player) {
|
}
|
||||||
return isInvincible(plugin, player, null);
|
|
||||||
}
|
public static boolean isInvincible(WorldGuardPlugin plugin, Player player) {
|
||||||
|
return isInvincible(plugin, player, null);
|
||||||
public static boolean isInvincible(WorldGuardPlugin plugin, Player player,
|
}
|
||||||
ApplicableRegionSet set) {
|
|
||||||
Location loc = player.getLocation();
|
public static boolean isInvincible(WorldGuardPlugin plugin, Player player,
|
||||||
World world = player.getWorld();
|
ApplicableRegionSet set) {
|
||||||
|
Location loc = player.getLocation();
|
||||||
FlagStateManager.PlayerFlagState state = plugin.getFlagStateManager().getState(player);
|
World world = player.getWorld();
|
||||||
|
|
||||||
if (state.lastInvincibleWorld == null ||
|
FlagStateManager.PlayerFlagState state = plugin.getFlagStateManager().getState(player);
|
||||||
!state.lastInvincibleWorld.equals(world) ||
|
|
||||||
state.lastInvincibleX != loc.getBlockX() ||
|
if (state.lastInvincibleWorld == null ||
|
||||||
state.lastInvincibleY != loc.getBlockY() ||
|
!state.lastInvincibleWorld.equals(world) ||
|
||||||
state.lastInvincibleZ != loc.getBlockZ()) {
|
state.lastInvincibleX != loc.getBlockX() ||
|
||||||
state.lastInvincibleX = loc.getBlockX();
|
state.lastInvincibleY != loc.getBlockY() ||
|
||||||
state.lastInvincibleY = loc.getBlockY();
|
state.lastInvincibleZ != loc.getBlockZ()) {
|
||||||
state.lastInvincibleZ = loc.getBlockZ();
|
state.lastInvincibleX = loc.getBlockX();
|
||||||
state.lastInvincibleWorld = world;
|
state.lastInvincibleY = loc.getBlockY();
|
||||||
|
state.lastInvincibleZ = loc.getBlockZ();
|
||||||
if (set == null) {
|
state.lastInvincibleWorld = world;
|
||||||
Vector vec = new Vector(state.lastInvincibleX,
|
|
||||||
state.lastInvincibleY, state.lastInvincibleZ);
|
if (set == null) {
|
||||||
RegionManager mgr = plugin.getGlobalRegionManager().get(world);
|
Vector vec = new Vector(state.lastInvincibleX,
|
||||||
set = mgr.getApplicableRegions(vec);
|
state.lastInvincibleY, state.lastInvincibleZ);
|
||||||
}
|
RegionManager mgr = plugin.getGlobalRegionManager().get(world);
|
||||||
|
set = mgr.getApplicableRegions(vec);
|
||||||
state.wasInvincible = set.allows(DefaultFlag.INVINCIBILITY, plugin.wrapPlayer(player));
|
}
|
||||||
}
|
|
||||||
|
state.wasInvincible = set.allows(DefaultFlag.INVINCIBILITY, plugin.wrapPlayer(player));
|
||||||
return state.wasInvincible;
|
}
|
||||||
}
|
|
||||||
|
return state.wasInvincible;
|
||||||
public static Boolean isAllowedInvinciblity(WorldGuardPlugin plugin, Player player) {
|
}
|
||||||
World world = player.getWorld();
|
|
||||||
FlagStateManager.PlayerFlagState state = plugin.getFlagStateManager().getState(player);
|
public static Boolean isAllowedInvinciblity(WorldGuardPlugin plugin, Player player) {
|
||||||
Vector vec = new Vector(state.lastInvincibleX, state.lastInvincibleY, state.lastInvincibleZ);
|
World world = player.getWorld();
|
||||||
|
FlagStateManager.PlayerFlagState state = plugin.getFlagStateManager().getState(player);
|
||||||
StateFlag.State regionState = plugin.getGlobalRegionManager().get(world).
|
Vector vec = new Vector(state.lastInvincibleX, state.lastInvincibleY, state.lastInvincibleZ);
|
||||||
getApplicableRegions(vec).getFlag(DefaultFlag.INVINCIBILITY, plugin.wrapPlayer(player));
|
|
||||||
if (regionState == StateFlag.State.ALLOW) {
|
StateFlag.State regionState = plugin.getGlobalRegionManager().get(world).
|
||||||
return Boolean.TRUE;
|
getApplicableRegions(vec).getFlag(DefaultFlag.INVINCIBILITY, plugin.wrapPlayer(player));
|
||||||
} else if (regionState == StateFlag.State.DENY) {
|
if (regionState == StateFlag.State.ALLOW) {
|
||||||
return Boolean.FALSE;
|
return Boolean.TRUE;
|
||||||
} else {
|
} else if (regionState == StateFlag.State.DENY) {
|
||||||
return null;
|
return Boolean.FALSE;
|
||||||
}
|
} else {
|
||||||
}
|
return null;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -1,343 +1,346 @@
|
|||||||
/*
|
/*
|
||||||
* WorldGuard, a suite of tools for Minecraft
|
* WorldGuard, a suite of tools for Minecraft
|
||||||
* Copyright (C) sk89q <http://www.sk89q.com>
|
* Copyright (C) sk89q <http://www.sk89q.com>
|
||||||
* Copyright (C) WorldGuard team and contributors
|
* Copyright (C) WorldGuard team and contributors
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify it
|
* 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
|
* under the terms of the GNU Lesser General Public License as published by the
|
||||||
* Free Software Foundation, either version 3 of the License, or
|
* Free Software Foundation, either version 3 of the License, or
|
||||||
* (at your option) any later version.
|
* (at your option) any later version.
|
||||||
*
|
*
|
||||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
|
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
|
||||||
* for more details.
|
* for more details.
|
||||||
*
|
*
|
||||||
* You should have received a copy of the GNU Lesser General Public License
|
* 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/>.
|
* 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.BufferedWriter;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileWriter;
|
import java.io.FileWriter;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.lang.reflect.Field;
|
import java.lang.reflect.Field;
|
||||||
import java.text.SimpleDateFormat;
|
import java.text.SimpleDateFormat;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import org.bukkit.Server;
|
import com.sk89q.worldguard.bukkit.ConfigurationManager;
|
||||||
import org.bukkit.World;
|
import com.sk89q.worldguard.bukkit.WorldConfiguration;
|
||||||
import org.bukkit.entity.Entity;
|
import com.sk89q.worldguard.bukkit.WorldGuardPlugin;
|
||||||
import org.bukkit.plugin.Plugin;
|
import org.bukkit.Server;
|
||||||
|
import org.bukkit.World;
|
||||||
import com.sk89q.worldguard.protection.GlobalRegionManager;
|
import org.bukkit.entity.Entity;
|
||||||
import com.sk89q.worldguard.protection.flags.DefaultFlag;
|
import org.bukkit.plugin.Plugin;
|
||||||
import com.sk89q.worldguard.protection.flags.Flag;
|
|
||||||
import com.sk89q.worldguard.protection.flags.StateFlag;
|
import com.sk89q.worldguard.protection.GlobalRegionManager;
|
||||||
import com.sk89q.worldguard.protection.managers.RegionManager;
|
import com.sk89q.worldguard.protection.flags.DefaultFlag;
|
||||||
import com.sk89q.worldguard.protection.regions.ProtectedRegion;
|
import com.sk89q.worldguard.protection.flags.Flag;
|
||||||
import com.sk89q.worldguard.util.LogListBlock;
|
import com.sk89q.worldguard.protection.flags.StateFlag;
|
||||||
|
import com.sk89q.worldguard.protection.managers.RegionManager;
|
||||||
public class ReportWriter {
|
import com.sk89q.worldguard.protection.regions.ProtectedRegion;
|
||||||
|
import com.sk89q.worldguard.util.LogListBlock;
|
||||||
private static final SimpleDateFormat dateFmt =
|
|
||||||
new SimpleDateFormat("yyyy-MM-dd kk:mm Z");
|
public class ReportWriter {
|
||||||
|
|
||||||
private Date date = new Date();
|
private static final SimpleDateFormat dateFmt =
|
||||||
private StringBuilder output = new StringBuilder();
|
new SimpleDateFormat("yyyy-MM-dd kk:mm Z");
|
||||||
|
|
||||||
public ReportWriter(WorldGuardPlugin plugin) {
|
private Date date = new Date();
|
||||||
appendReportHeader(plugin);
|
private StringBuilder output = new StringBuilder();
|
||||||
appendServerInformation(plugin.getServer());
|
|
||||||
appendPluginInformation(plugin.getServer().getPluginManager().getPlugins());
|
public ReportWriter(WorldGuardPlugin plugin) {
|
||||||
appendWorldInformation(plugin.getServer().getWorlds());
|
appendReportHeader(plugin);
|
||||||
appendGlobalConfiguration(plugin.getGlobalStateManager());
|
appendServerInformation(plugin.getServer());
|
||||||
appendWorldConfigurations(plugin, plugin.getServer().getWorlds(),
|
appendPluginInformation(plugin.getServer().getPluginManager().getPlugins());
|
||||||
plugin.getGlobalRegionManager(), plugin.getGlobalStateManager());
|
appendWorldInformation(plugin.getServer().getWorlds());
|
||||||
appendln("-------------");
|
appendGlobalConfiguration(plugin.getGlobalStateManager());
|
||||||
appendln("END OF REPORT");
|
appendWorldConfigurations(plugin, plugin.getServer().getWorlds(),
|
||||||
appendln();
|
plugin.getGlobalRegionManager(), plugin.getGlobalStateManager());
|
||||||
}
|
appendln("-------------");
|
||||||
|
appendln("END OF REPORT");
|
||||||
protected static String repeat(String str, int n) {
|
appendln();
|
||||||
if(str == null) {
|
}
|
||||||
return null;
|
|
||||||
}
|
protected static String repeat(String str, int n) {
|
||||||
|
if(str == null) {
|
||||||
StringBuilder sb = new StringBuilder();
|
return null;
|
||||||
for (int i = 0; i < n; i++) {
|
}
|
||||||
sb.append(str);
|
|
||||||
}
|
StringBuilder sb = new StringBuilder();
|
||||||
|
for (int i = 0; i < n; i++) {
|
||||||
return sb.toString();
|
sb.append(str);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void appendln(String text) {
|
return sb.toString();
|
||||||
output.append(text);
|
}
|
||||||
output.append("\r\n");
|
|
||||||
}
|
protected void appendln(String text) {
|
||||||
|
output.append(text);
|
||||||
protected void appendln(String text, Object ... args) {
|
output.append("\r\n");
|
||||||
output.append(String.format(text, args));
|
}
|
||||||
output.append("\r\n");
|
|
||||||
}
|
protected void appendln(String text, Object ... args) {
|
||||||
|
output.append(String.format(text, args));
|
||||||
protected void append(LogListBlock log) {
|
output.append("\r\n");
|
||||||
output.append(log.toString());
|
}
|
||||||
}
|
|
||||||
|
protected void append(LogListBlock log) {
|
||||||
protected void appendln() {
|
output.append(log.toString());
|
||||||
output.append("\r\n");
|
}
|
||||||
}
|
|
||||||
|
protected void appendln() {
|
||||||
protected void appendHeader(String text) {
|
output.append("\r\n");
|
||||||
String rule = repeat("-", text.length());
|
}
|
||||||
output.append(rule);
|
|
||||||
output.append("\r\n");
|
protected void appendHeader(String text) {
|
||||||
appendln(text);
|
String rule = repeat("-", text.length());
|
||||||
output.append(rule);
|
output.append(rule);
|
||||||
output.append("\r\n");
|
output.append("\r\n");
|
||||||
appendln();
|
appendln(text);
|
||||||
}
|
output.append(rule);
|
||||||
|
output.append("\r\n");
|
||||||
private void appendReportHeader(WorldGuardPlugin plugin) {
|
appendln();
|
||||||
appendln("WorldGuard Configuration Report");
|
}
|
||||||
appendln("Generated " + dateFmt.format(date));
|
|
||||||
appendln();
|
private void appendReportHeader(WorldGuardPlugin plugin) {
|
||||||
appendln("Version: " + plugin.getDescription().getVersion());
|
appendln("WorldGuard Configuration Report");
|
||||||
appendln();
|
appendln("Generated " + dateFmt.format(date));
|
||||||
}
|
appendln();
|
||||||
|
appendln("Version: " + plugin.getDescription().getVersion());
|
||||||
private void appendGlobalConfiguration(ConfigurationManager config) {
|
appendln();
|
||||||
appendHeader("Global Configuration");
|
}
|
||||||
|
|
||||||
LogListBlock log = new LogListBlock();
|
private void appendGlobalConfiguration(ConfigurationManager config) {
|
||||||
LogListBlock configLog = log.putChild("Configuration");
|
appendHeader("Global Configuration");
|
||||||
|
|
||||||
Class<? extends ConfigurationManager> cls = config.getClass();
|
LogListBlock log = new LogListBlock();
|
||||||
for (Field field : cls.getFields()) {
|
LogListBlock configLog = log.putChild("Configuration");
|
||||||
try {
|
|
||||||
String name = field.getName();
|
Class<? extends ConfigurationManager> cls = config.getClass();
|
||||||
// store these elsewhere maybe?
|
for (Field field : cls.getFields()) {
|
||||||
if (name.equals("CONFIG_HEADER")
|
try {
|
||||||
|| name.equals("hostKeys")
|
String name = field.getName();
|
||||||
|| name.equals("sqlPassword")) {
|
// store these elsewhere maybe?
|
||||||
continue;
|
if (name.equals("CONFIG_HEADER")
|
||||||
}
|
|| name.equals("hostKeys")
|
||||||
Object val = field.get(config);
|
|| name.equals("sqlPassword")) {
|
||||||
configLog.put(name, val);
|
continue;
|
||||||
} catch (IllegalArgumentException e) {
|
}
|
||||||
e.printStackTrace();
|
Object val = field.get(config);
|
||||||
} catch (IllegalAccessException ignore) {
|
configLog.put(name, val);
|
||||||
}
|
} catch (IllegalArgumentException e) {
|
||||||
}
|
e.printStackTrace();
|
||||||
|
} catch (IllegalAccessException ignore) {
|
||||||
append(log);
|
}
|
||||||
appendln();
|
}
|
||||||
}
|
|
||||||
|
append(log);
|
||||||
private void appendServerInformation(Server server) {
|
appendln();
|
||||||
appendHeader("Server Information");
|
}
|
||||||
|
|
||||||
LogListBlock log = new LogListBlock();
|
private void appendServerInformation(Server server) {
|
||||||
|
appendHeader("Server Information");
|
||||||
Runtime runtime = Runtime.getRuntime();
|
|
||||||
|
LogListBlock log = new LogListBlock();
|
||||||
log.put("Java", "%s %s (%s)",
|
|
||||||
System.getProperty("java.vendor"),
|
Runtime runtime = Runtime.getRuntime();
|
||||||
System.getProperty("java.version"),
|
|
||||||
System.getProperty("java.vendor.url"));
|
log.put("Java", "%s %s (%s)",
|
||||||
log.put("Operating system", "%s %s (%s)",
|
System.getProperty("java.vendor"),
|
||||||
System.getProperty("os.name"),
|
System.getProperty("java.version"),
|
||||||
System.getProperty("os.version"),
|
System.getProperty("java.vendor.url"));
|
||||||
System.getProperty("os.arch"));
|
log.put("Operating system", "%s %s (%s)",
|
||||||
log.put("Available processors", runtime.availableProcessors());
|
System.getProperty("os.name"),
|
||||||
log.put("Free memory", runtime.freeMemory() / 1024 / 1024 + " MB");
|
System.getProperty("os.version"),
|
||||||
log.put("Max memory", runtime.maxMemory() / 1024 / 1024 + " MB");
|
System.getProperty("os.arch"));
|
||||||
log.put("Total memory", runtime.totalMemory() / 1024 / 1024 + " MB");
|
log.put("Available processors", runtime.availableProcessors());
|
||||||
log.put("Server ID", server.getServerId());
|
log.put("Free memory", runtime.freeMemory() / 1024 / 1024 + " MB");
|
||||||
log.put("Server name", server.getServerName());
|
log.put("Max memory", runtime.maxMemory() / 1024 / 1024 + " MB");
|
||||||
log.put("Implementation", server.getVersion());
|
log.put("Total memory", runtime.totalMemory() / 1024 / 1024 + " MB");
|
||||||
//log.put("Address", server.getIp(), server.getPort());
|
log.put("Server ID", server.getServerId());
|
||||||
log.put("Player count", "%d/%d",
|
log.put("Server name", server.getServerName());
|
||||||
server.getOnlinePlayers().length, server.getMaxPlayers());
|
log.put("Implementation", server.getVersion());
|
||||||
|
//log.put("Address", server.getIp(), server.getPort());
|
||||||
append(log);
|
log.put("Player count", "%d/%d",
|
||||||
appendln();
|
server.getOnlinePlayers().length, server.getMaxPlayers());
|
||||||
}
|
|
||||||
|
append(log);
|
||||||
private void appendPluginInformation(Plugin[] plugins) {
|
appendln();
|
||||||
appendHeader("Plugins (" + plugins.length + ")");
|
}
|
||||||
|
|
||||||
LogListBlock log = new LogListBlock();
|
private void appendPluginInformation(Plugin[] plugins) {
|
||||||
|
appendHeader("Plugins (" + plugins.length + ")");
|
||||||
for (Plugin plugin : plugins) {
|
|
||||||
log.put(plugin.getDescription().getName(), plugin.getDescription().getVersion());
|
LogListBlock log = new LogListBlock();
|
||||||
}
|
|
||||||
|
for (Plugin plugin : plugins) {
|
||||||
append(log);
|
log.put(plugin.getDescription().getName(), plugin.getDescription().getVersion());
|
||||||
appendln();
|
}
|
||||||
|
|
||||||
/*appendHeader("Plugin Information");
|
append(log);
|
||||||
|
appendln();
|
||||||
log = new LogListBlock();
|
|
||||||
|
/*appendHeader("Plugin Information");
|
||||||
for (Plugin plugin : plugins) {
|
|
||||||
log.putChild(plugin.getDescription().getName())
|
log = new LogListBlock();
|
||||||
.put("Data folder", plugin.getDataFolder())
|
|
||||||
.put("Website", plugin.getDescription().getWebsite())
|
for (Plugin plugin : plugins) {
|
||||||
.put("Entry point", plugin.getDescription().getMain());
|
log.putChild(plugin.getDescription().getName())
|
||||||
}
|
.put("Data folder", plugin.getDataFolder())
|
||||||
|
.put("Website", plugin.getDescription().getWebsite())
|
||||||
append(log);
|
.put("Entry point", plugin.getDescription().getMain());
|
||||||
appendln();*/
|
}
|
||||||
}
|
|
||||||
|
append(log);
|
||||||
private void appendWorldInformation(List<World> worlds) {
|
appendln();*/
|
||||||
appendHeader("Worlds");
|
}
|
||||||
|
|
||||||
LogListBlock log = new LogListBlock();
|
private void appendWorldInformation(List<World> worlds) {
|
||||||
|
appendHeader("Worlds");
|
||||||
int i = 0;
|
|
||||||
for (World world : worlds) {
|
LogListBlock log = new LogListBlock();
|
||||||
int loadedChunkCount = world.getLoadedChunks().length;
|
|
||||||
|
int i = 0;
|
||||||
LogListBlock worldLog = log.putChild(world.getName() + " (" + i + ")");
|
for (World world : worlds) {
|
||||||
LogListBlock infoLog = worldLog.putChild("Information");
|
int loadedChunkCount = world.getLoadedChunks().length;
|
||||||
LogListBlock entitiesLog = worldLog.putChild("Entities");
|
|
||||||
|
LogListBlock worldLog = log.putChild(world.getName() + " (" + i + ")");
|
||||||
infoLog.put("Seed", world.getSeed());
|
LogListBlock infoLog = worldLog.putChild("Information");
|
||||||
infoLog.put("Environment", world.getEnvironment().toString());
|
LogListBlock entitiesLog = worldLog.putChild("Entities");
|
||||||
infoLog.put("Player count", world.getPlayers().size());
|
|
||||||
infoLog.put("Entity count", world.getEntities().size());
|
infoLog.put("Seed", world.getSeed());
|
||||||
infoLog.put("Loaded chunk count", loadedChunkCount);
|
infoLog.put("Environment", world.getEnvironment().toString());
|
||||||
infoLog.put("Spawn location", world.getSpawnLocation());
|
infoLog.put("Player count", world.getPlayers().size());
|
||||||
infoLog.put("Raw time", world.getFullTime());
|
infoLog.put("Entity count", world.getEntities().size());
|
||||||
|
infoLog.put("Loaded chunk count", loadedChunkCount);
|
||||||
Map<Class<? extends Entity>, Integer> entityCounts =
|
infoLog.put("Spawn location", world.getSpawnLocation());
|
||||||
new HashMap<Class<? extends Entity>, Integer>();
|
infoLog.put("Raw time", world.getFullTime());
|
||||||
|
|
||||||
// Collect entities
|
Map<Class<? extends Entity>, Integer> entityCounts =
|
||||||
for (Entity entity : world.getEntities()) {
|
new HashMap<Class<? extends Entity>, Integer>();
|
||||||
Class<? extends Entity> cls = entity.getClass();
|
|
||||||
|
// Collect entities
|
||||||
if (entityCounts.containsKey(cls)) {
|
for (Entity entity : world.getEntities()) {
|
||||||
entityCounts.put(cls, entityCounts.get(cls) + 1);
|
Class<? extends Entity> cls = entity.getClass();
|
||||||
} else {
|
|
||||||
entityCounts.put(cls, 1);
|
if (entityCounts.containsKey(cls)) {
|
||||||
}
|
entityCounts.put(cls, entityCounts.get(cls) + 1);
|
||||||
}
|
} else {
|
||||||
|
entityCounts.put(cls, 1);
|
||||||
// Print entities
|
}
|
||||||
for (Map.Entry<Class<? extends Entity>, Integer> entry
|
}
|
||||||
: entityCounts.entrySet()) {
|
|
||||||
entitiesLog.put(entry.getKey().getSimpleName(),
|
// Print entities
|
||||||
"%d [%f/chunk]",
|
for (Map.Entry<Class<? extends Entity>, Integer> entry
|
||||||
entry.getValue(),
|
: entityCounts.entrySet()) {
|
||||||
(float) (entry.getValue() / (double) loadedChunkCount));
|
entitiesLog.put(entry.getKey().getSimpleName(),
|
||||||
}
|
"%d [%f/chunk]",
|
||||||
|
entry.getValue(),
|
||||||
i++;
|
(float) (entry.getValue() / (double) loadedChunkCount));
|
||||||
}
|
}
|
||||||
|
|
||||||
append(log);
|
i++;
|
||||||
appendln();
|
}
|
||||||
}
|
|
||||||
|
append(log);
|
||||||
private void appendWorldConfigurations(WorldGuardPlugin plugin, List<World> worlds,
|
appendln();
|
||||||
GlobalRegionManager regionMgr, ConfigurationManager mgr) {
|
}
|
||||||
appendHeader("World Configurations");
|
|
||||||
|
private void appendWorldConfigurations(WorldGuardPlugin plugin, List<World> worlds,
|
||||||
LogListBlock log = new LogListBlock();
|
GlobalRegionManager regionMgr, ConfigurationManager mgr) {
|
||||||
|
appendHeader("World Configurations");
|
||||||
int i = 0;
|
|
||||||
for (World world : worlds) {
|
LogListBlock log = new LogListBlock();
|
||||||
LogListBlock worldLog = log.putChild(world.getName() + " (" + i + ")");
|
|
||||||
LogListBlock infoLog = worldLog.putChild("Information");
|
int i = 0;
|
||||||
LogListBlock configLog = worldLog.putChild("Configuration");
|
for (World world : worlds) {
|
||||||
LogListBlock blacklistLog = worldLog.putChild("Blacklist");
|
LogListBlock worldLog = log.putChild(world.getName() + " (" + i + ")");
|
||||||
LogListBlock regionsLog = worldLog.putChild("Region manager");
|
LogListBlock infoLog = worldLog.putChild("Information");
|
||||||
|
LogListBlock configLog = worldLog.putChild("Configuration");
|
||||||
infoLog.put("Configuration file", (new File(plugin.getDataFolder(), "worlds/"
|
LogListBlock blacklistLog = worldLog.putChild("Blacklist");
|
||||||
+ world.getName() + "/config.yml")).getAbsoluteFile());
|
LogListBlock regionsLog = worldLog.putChild("Region manager");
|
||||||
|
|
||||||
infoLog.put("Blacklist file", (new File(plugin.getDataFolder(), "worlds/"
|
infoLog.put("Configuration file", (new File(plugin.getDataFolder(), "worlds/"
|
||||||
+ world.getName() + "/blacklist.txt")).getAbsoluteFile());
|
+ world.getName() + "/config.yml")).getAbsoluteFile());
|
||||||
infoLog.put("Regions file", (new File(plugin.getDataFolder(), "worlds/"
|
|
||||||
+ world.getName() + "/regions.yml")).getAbsoluteFile());
|
infoLog.put("Blacklist file", (new File(plugin.getDataFolder(), "worlds/"
|
||||||
|
+ world.getName() + "/blacklist.txt")).getAbsoluteFile());
|
||||||
WorldConfiguration config = mgr.get(world);
|
infoLog.put("Regions file", (new File(plugin.getDataFolder(), "worlds/"
|
||||||
|
+ world.getName() + "/regions.yml")).getAbsoluteFile());
|
||||||
Class<? extends WorldConfiguration> cls = config.getClass();
|
|
||||||
for (Field field : cls.getFields()) {
|
WorldConfiguration config = mgr.get(world);
|
||||||
try {
|
|
||||||
Object val = field.get(config);
|
Class<? extends WorldConfiguration> cls = config.getClass();
|
||||||
configLog.put(field.getName(), String.valueOf(val));
|
for (Field field : cls.getFields()) {
|
||||||
} catch (IllegalArgumentException e) {
|
try {
|
||||||
e.printStackTrace();
|
Object val = field.get(config);
|
||||||
} catch (IllegalAccessException ignore) {
|
configLog.put(field.getName(), String.valueOf(val));
|
||||||
}
|
} catch (IllegalArgumentException e) {
|
||||||
}
|
e.printStackTrace();
|
||||||
|
} catch (IllegalAccessException ignore) {
|
||||||
if (config.getBlacklist() == null) {
|
}
|
||||||
blacklistLog.put("State", "DISABLED");
|
}
|
||||||
} else {
|
|
||||||
blacklistLog.put("State", "Enabled");
|
if (config.getBlacklist() == null) {
|
||||||
blacklistLog.put("Number of items",
|
blacklistLog.put("State", "DISABLED");
|
||||||
config.getBlacklist().getItemCount());
|
} else {
|
||||||
blacklistLog.put("Is whitelist",
|
blacklistLog.put("State", "Enabled");
|
||||||
config.getBlacklist().isWhitelist());
|
blacklistLog.put("Number of items",
|
||||||
}
|
config.getBlacklist().getItemCount());
|
||||||
|
blacklistLog.put("Is whitelist",
|
||||||
RegionManager worldRegions = regionMgr.get(world);
|
config.getBlacklist().isWhitelist());
|
||||||
|
}
|
||||||
regionsLog.put("Type", worldRegions.getClass().getCanonicalName());
|
|
||||||
regionsLog.put("Number of regions", worldRegions.getRegions().size());
|
RegionManager worldRegions = regionMgr.get(world);
|
||||||
LogListBlock globalRegionLog = regionsLog.putChild("Global region");
|
|
||||||
|
regionsLog.put("Type", worldRegions.getClass().getCanonicalName());
|
||||||
ProtectedRegion globalRegion = worldRegions.matchRegion("__global__");
|
regionsLog.put("Number of regions", worldRegions.getRegions().size());
|
||||||
if (globalRegion == null) {
|
LogListBlock globalRegionLog = regionsLog.putChild("Global region");
|
||||||
globalRegionLog.put("Status", "UNDEFINED");
|
|
||||||
} else {
|
ProtectedRegion globalRegion = worldRegions.matchRegion("__global__");
|
||||||
for (Flag<?> flag : DefaultFlag.getFlags()) {
|
if (globalRegion == null) {
|
||||||
if (flag instanceof StateFlag) {
|
globalRegionLog.put("Status", "UNDEFINED");
|
||||||
globalRegionLog.put(flag.getName(),
|
} else {
|
||||||
globalRegion.getFlag(flag));
|
for (Flag<?> flag : DefaultFlag.getFlags()) {
|
||||||
}
|
if (flag instanceof StateFlag) {
|
||||||
}
|
globalRegionLog.put(flag.getName(),
|
||||||
}
|
globalRegion.getFlag(flag));
|
||||||
}
|
}
|
||||||
|
}
|
||||||
append(log);
|
}
|
||||||
appendln();
|
}
|
||||||
}
|
|
||||||
|
append(log);
|
||||||
public void write(File file) throws IOException {
|
appendln();
|
||||||
FileWriter writer = null;
|
}
|
||||||
BufferedWriter out;
|
|
||||||
|
public void write(File file) throws IOException {
|
||||||
try {
|
FileWriter writer = null;
|
||||||
writer = new FileWriter(file);
|
BufferedWriter out;
|
||||||
out = new BufferedWriter(writer);
|
|
||||||
out.write(output.toString());
|
try {
|
||||||
out.close();
|
writer = new FileWriter(file);
|
||||||
} finally {
|
out = new BufferedWriter(writer);
|
||||||
if (writer != null) {
|
out.write(output.toString());
|
||||||
try {
|
out.close();
|
||||||
writer.close();
|
} finally {
|
||||||
} catch (IOException ignore) {
|
if (writer != null) {
|
||||||
}
|
try {
|
||||||
}
|
writer.close();
|
||||||
}
|
} catch (IOException ignore) {
|
||||||
}
|
}
|
||||||
|
}
|
||||||
@Override
|
}
|
||||||
public String toString() {
|
}
|
||||||
return output.toString();
|
|
||||||
}
|
@Override
|
||||||
}
|
public String toString() {
|
||||||
|
return output.toString();
|
||||||
|
}
|
||||||
|
}
|
@ -19,111 +19,45 @@
|
|||||||
|
|
||||||
package com.sk89q.worldguard.protection;
|
package com.sk89q.worldguard.protection;
|
||||||
|
|
||||||
import com.sk89q.worldedit.Vector2D;
|
|
||||||
import com.sk89q.worldguard.LocalPlayer;
|
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.WorldGuardPlugin;
|
||||||
import com.sk89q.worldguard.bukkit.util.ProtectedRegionQuery;
|
|
||||||
import com.sk89q.worldguard.protection.flags.StateFlag;
|
import com.sk89q.worldguard.protection.flags.StateFlag;
|
||||||
import com.sk89q.worldguard.protection.managers.RegionManager;
|
import com.sk89q.worldguard.protection.managers.RegionManager;
|
||||||
import org.bukkit.Chunk;
|
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
import org.bukkit.World;
|
import org.bukkit.World;
|
||||||
import org.bukkit.block.Block;
|
import org.bukkit.block.Block;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Collection;
|
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import static com.google.common.base.Preconditions.checkNotNull;
|
import static com.google.common.base.Preconditions.checkNotNull;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A global region manager loads, saves and caches region data for zero or
|
* This is the legacy class for accessing region data.
|
||||||
* more worlds at a time.
|
|
||||||
*
|
*
|
||||||
* <p>This class is thread safe and its contents can be accessed from
|
* @deprecated use {@link WorldGuardPlugin#getRegionContainer()}
|
||||||
* multiple concurrent threads.</p>
|
|
||||||
*/
|
*/
|
||||||
|
@Deprecated
|
||||||
public class GlobalRegionManager {
|
public class GlobalRegionManager {
|
||||||
|
|
||||||
private final WorldGuardPlugin plugin;
|
private final WorldGuardPlugin plugin;
|
||||||
private final ManagerContainer container;
|
private final RegionContainer container;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a new instance.
|
* Create a new instance.
|
||||||
*
|
*
|
||||||
* @param plugin the plugin
|
* @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;
|
this.plugin = plugin;
|
||||||
|
this.container = container;
|
||||||
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();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -138,7 +72,7 @@ public void unloadAll() {
|
|||||||
*/
|
*/
|
||||||
@Nullable
|
@Nullable
|
||||||
public RegionManager get(World world) {
|
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
|
* @return a new query
|
||||||
*/
|
*/
|
||||||
public ProtectedRegionQuery createAnonymousQuery() {
|
private RegionQuery createAnonymousQuery() {
|
||||||
return new ProtectedRegionQuery(plugin, (Player) null);
|
return container.createAnonymousQuery();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -165,8 +99,8 @@ public ProtectedRegionQuery createAnonymousQuery() {
|
|||||||
* @param player a player, or {@code null}
|
* @param player a player, or {@code null}
|
||||||
* @return a new query
|
* @return a new query
|
||||||
*/
|
*/
|
||||||
public ProtectedRegionQuery createQuery(@Nullable Player player) {
|
private RegionQuery createQuery(@Nullable Player player) {
|
||||||
return new ProtectedRegionQuery(plugin, player);
|
return container.createQuery(player);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -175,8 +109,8 @@ public ProtectedRegionQuery createQuery(@Nullable Player player) {
|
|||||||
* @param player a player, or {@code null}
|
* @param player a player, or {@code null}
|
||||||
* @return a new query
|
* @return a new query
|
||||||
*/
|
*/
|
||||||
private ProtectedRegionQuery createQuery(@Nullable LocalPlayer player) {
|
private RegionQuery createQuery(@Nullable LocalPlayer player) {
|
||||||
return new ProtectedRegionQuery(plugin, player);
|
return container.createQuery(player);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -243,7 +177,7 @@ public boolean canBuild(Player player, Block block) {
|
|||||||
*/
|
*/
|
||||||
@Deprecated
|
@Deprecated
|
||||||
public boolean canBuild(Player player, Location location) {
|
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 player the player
|
||||||
* @param block the block
|
* @param block the block
|
||||||
* @return true if permitted
|
* @return true if permitted
|
||||||
* @deprecated use {@link #createQuery(Player)}
|
* @deprecated the construct flag is being removed
|
||||||
*/
|
*/
|
||||||
@Deprecated
|
@Deprecated
|
||||||
@SuppressWarnings("deprecation")
|
@SuppressWarnings("deprecation")
|
||||||
public boolean canConstruct(Player player, Block block) {
|
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 player the player
|
||||||
* @param location the location
|
* @param location the location
|
||||||
* @return true if permitted
|
* @return true if permitted
|
||||||
* @deprecated use {@link #createQuery(Player)}
|
* @deprecated the construct flag is being removed
|
||||||
*/
|
*/
|
||||||
@Deprecated
|
@Deprecated
|
||||||
public boolean canConstruct(Player player, Location location) {
|
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
|
@Deprecated
|
||||||
public boolean allows(StateFlag flag, Location location, @Nullable LocalPlayer player) {
|
public boolean allows(StateFlag flag, Location location, @Nullable LocalPlayer player) {
|
||||||
return createQuery(player).allows(flag, location);
|
return createQuery(player).testEnabled(location, flag);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user