mirror of
https://github.com/EngineHub/WorldGuard.git
synced 2024-11-17 08:05:20 +01:00
Added support for the region query cache on Bukkit's side and added it to BukkitContext.
This commit is contained in:
parent
f4e52f5cd7
commit
579143a5dd
@ -26,13 +26,16 @@
|
||||
import com.sk89q.rulelists.Context;
|
||||
|
||||
/**
|
||||
* An implementation of a {@link Context} for Bukkit.
|
||||
* An implementation of a {@link Context} for Bukkit. This object is thread-safe, but
|
||||
* the underlying objects returned by this class may not be.
|
||||
*
|
||||
* @see Context
|
||||
*/
|
||||
public class BukkitContext extends Context {
|
||||
|
||||
private final RegionQueryCache regionCache;
|
||||
private final Event event;
|
||||
private RegionQuery regionQuery;
|
||||
private String message;
|
||||
private Entity sourceEntity;
|
||||
private Entity targetEntity;
|
||||
@ -44,9 +47,11 @@ public class BukkitContext extends Context {
|
||||
/**
|
||||
* Construct a context linked to the given event.
|
||||
*
|
||||
* @param plugin the WorldGuard plugin
|
||||
* @param event the event
|
||||
*/
|
||||
public BukkitContext(Event event) {
|
||||
BukkitContext(WorldGuardPlugin plugin, Event event) {
|
||||
this.regionCache = plugin.getRegionCache();
|
||||
this.event = event;
|
||||
}
|
||||
|
||||
@ -197,4 +202,16 @@ public Event getEvent() {
|
||||
return event;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the region query object.
|
||||
*
|
||||
* @return region query object
|
||||
*/
|
||||
public synchronized RegionQuery getRegionQuery() {
|
||||
if (regionQuery == null) {
|
||||
regionQuery = regionCache.against(event);
|
||||
}
|
||||
return regionQuery;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -22,28 +22,28 @@
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.event.Event;
|
||||
|
||||
import com.sk89q.worldedit.Vector;
|
||||
import com.sk89q.worldguard.protection.ApplicableRegionSet;
|
||||
import com.sk89q.worldguard.protection.GlobalRegionManager;
|
||||
import com.sk89q.worldguard.protection.RegionQueryCache;
|
||||
import com.sk89q.worldguard.protection.RegionQueryCacheEntry;
|
||||
|
||||
/**
|
||||
* An implementation of {@link RegionQueryCache} for Bukkit. This implementation is
|
||||
* thread-safe.
|
||||
* A class that will cache all region queries. Instances of this class are created
|
||||
* via an instance of {@link RegionQueryCache} and represent a point in time.
|
||||
*/
|
||||
public class BukkitRegionQueryCache extends RegionQueryCache {
|
||||
public final class RegionQuery {
|
||||
|
||||
private final WorldGuardPlugin plugin;
|
||||
private final RegionQueryCacheEntry entry;
|
||||
|
||||
/**
|
||||
* Construct the cache with the given plugin instance.
|
||||
* Construct the instance with the underlying cache entry.
|
||||
*
|
||||
* @param plugin plugin instance
|
||||
* @param entry
|
||||
*/
|
||||
public BukkitRegionQueryCache(WorldGuardPlugin plugin) {
|
||||
RegionQuery(WorldGuardPlugin plugin, RegionQueryCacheEntry entry) {
|
||||
this.plugin = plugin;
|
||||
this.entry = entry;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -51,11 +51,10 @@ public BukkitRegionQueryCache(WorldGuardPlugin plugin) {
|
||||
* temporarily cached for the given event, or null if region protection has
|
||||
* been disabled for the the world of the given location.
|
||||
*
|
||||
* @param event the event to cache against
|
||||
* @param location the location to check
|
||||
* @return the set, or null if region protection is disabled for the given location
|
||||
*/
|
||||
public ApplicableRegionSet lookup(Event event, Location location) {
|
||||
public ApplicableRegionSet lookup(Location location) {
|
||||
World world = location.getWorld();
|
||||
Vector vector = BukkitUtil.toVector(location);
|
||||
|
||||
@ -67,7 +66,7 @@ public ApplicableRegionSet lookup(Event event, Location location) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return get(event).lookup(regionManager.get(world), vector);
|
||||
return entry.lookup(regionManager.get(world), vector);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -75,12 +74,11 @@ public ApplicableRegionSet lookup(Event event, Location location) {
|
||||
* temporarily cached for the given event, or null if region protection has
|
||||
* been disabled for the the world of the given block.
|
||||
*
|
||||
* @param event the event to cache against
|
||||
* @param block the block to check
|
||||
* @return the set, or null if region protection is disabled for the given block
|
||||
*/
|
||||
public ApplicableRegionSet lookup(Event event, Block block) {
|
||||
return lookup(event, block.getLocation());
|
||||
public ApplicableRegionSet lookup(Block block) {
|
||||
return lookup(block.getLocation());
|
||||
}
|
||||
|
||||
/**
|
||||
@ -88,12 +86,11 @@ public ApplicableRegionSet lookup(Event event, Block block) {
|
||||
* temporarily cached for the given event, or null if region protection has
|
||||
* been disabled for the the world of the given entity.
|
||||
*
|
||||
* @param event the event to cache against
|
||||
* @param entity the entity to check
|
||||
* @return the set, or null if region protection is disabled for the given entity
|
||||
*/
|
||||
public ApplicableRegionSet lookup(Event event, Entity entity) {
|
||||
return lookup(event, entity.getLocation());
|
||||
public ApplicableRegionSet lookup(Entity entity) {
|
||||
return lookup(entity.getLocation());
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,53 @@
|
||||
// $Id$
|
||||
/*
|
||||
* This file is a part of WorldGuard.
|
||||
* Copyright (c) sk89q <http://www.sk89q.com>
|
||||
* Copyright (c) the 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
|
||||
* (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
|
||||
* GNU 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 org.bukkit.event.Event;
|
||||
|
||||
import com.sk89q.worldguard.protection.AbstractRegionQueryCache;
|
||||
|
||||
/**
|
||||
* An implementation of {@link AbstractRegionQueryCache} for Bukkit. This implementation
|
||||
* is thread-safe.
|
||||
*/
|
||||
public final class RegionQueryCache extends AbstractRegionQueryCache {
|
||||
|
||||
private final WorldGuardPlugin plugin;
|
||||
|
||||
/**
|
||||
* Construct the cache with the given plugin instance.
|
||||
*
|
||||
* @param plugin plugin instance
|
||||
*/
|
||||
public RegionQueryCache(WorldGuardPlugin plugin) {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a {@link RegionQuery} object that can cache region queries. The object
|
||||
* returned by this method does not need to be cached. It is merely a proxy class.
|
||||
*
|
||||
* @param event the event to cache against
|
||||
* @return an object to perform lookups against
|
||||
*/
|
||||
public RegionQuery against(Event event) {
|
||||
return new RegionQuery(plugin, get(event));
|
||||
}
|
||||
|
||||
}
|
@ -83,7 +83,7 @@ public void onBlockDamage(BlockDamageEvent event) {
|
||||
if (blockDamaged.getTypeId() == BlockID.CAKE_BLOCK) {
|
||||
// RuleLists
|
||||
RuleSet rules = wcfg.getRuleList().get(KnownAttachment.BLOCK_INTERACT);
|
||||
BukkitContext context = new BukkitContext(event);
|
||||
BukkitContext context = new BukkitContext(plugin, event);
|
||||
context.setSourceEntity(player);
|
||||
context.setTargetBlock(event.getBlock().getState());
|
||||
if (rules.process(context)) {
|
||||
@ -103,7 +103,7 @@ public void onBlockBreak(BlockBreakEvent event) {
|
||||
|
||||
// RuleLists
|
||||
RuleSet rules = wcfg.getRuleList().get(KnownAttachment.BLOCK_BREAK);
|
||||
BukkitContext context = new BukkitContext(event);
|
||||
BukkitContext context = new BukkitContext(plugin, event);
|
||||
context.setSourceEntity(player);
|
||||
context.setTargetBlock(event.getBlock().getState());
|
||||
if (rules.process(context)) {
|
||||
@ -143,7 +143,7 @@ public void onBlockFromTo(BlockFromToEvent event) {
|
||||
|
||||
// RuleLists
|
||||
RuleSet rules = wcfg.getRuleList().get(KnownAttachment.BLOCK_SPREAD);
|
||||
BukkitContext context = new BukkitContext(event);
|
||||
BukkitContext context = new BukkitContext(plugin, event);
|
||||
context.setSourceBlock(event.getBlock().getState());
|
||||
context.setTargetBlock(event.getToBlock().getState());
|
||||
if (rules.process(context)) {
|
||||
@ -177,7 +177,7 @@ public void onBlockIgnite(BlockIgniteEvent event) {
|
||||
case FLINT_AND_STEEL:
|
||||
// Consider flint and steel as an item use
|
||||
rules = wcfg.getRuleList().get(KnownAttachment.ITEM_USE);
|
||||
context = new BukkitContext(event);
|
||||
context = new BukkitContext(plugin, event);
|
||||
context.setSourceEntity(event.getPlayer());
|
||||
context.setTargetBlock(event.getBlock().getState());
|
||||
context.setItem(event.getPlayer().getItemInHand()); // Should be flint and steel
|
||||
@ -196,7 +196,7 @@ public void onBlockIgnite(BlockIgniteEvent event) {
|
||||
case SPREAD:
|
||||
// Consider everything else as a block spread
|
||||
rules = wcfg.getRuleList().get(KnownAttachment.BLOCK_SPREAD);
|
||||
context = new BukkitContext(event);
|
||||
context = new BukkitContext(plugin, event);
|
||||
context.setTargetBlock(event.getBlock().getState());
|
||||
|
||||
// Make a virtual source state
|
||||
@ -218,7 +218,7 @@ public void onBlockIgnite(BlockIgniteEvent event) {
|
||||
case LIGHTNING:
|
||||
// Consider everything else as a block spread
|
||||
rules = wcfg.getRuleList().get(KnownAttachment.BLOCK_PLACE);
|
||||
context = new BukkitContext(event);
|
||||
context = new BukkitContext(plugin, event);
|
||||
context.setTargetBlock(event.getBlock().getState());
|
||||
|
||||
// Make a virtual new state
|
||||
@ -250,7 +250,7 @@ public void onBlockBurn(BlockBurnEvent event) {
|
||||
|
||||
// RuleLists
|
||||
RuleSet rules = wcfg.getRuleList().get(KnownAttachment.BLOCK_BREAK);
|
||||
BukkitContext context = new BukkitContext(event);
|
||||
BukkitContext context = new BukkitContext(plugin, event);
|
||||
BlockState virtualFireState = event.getBlock().getState();
|
||||
virtualFireState.setType(Material.FIRE);
|
||||
context.setSourceBlock(virtualFireState);
|
||||
@ -270,7 +270,7 @@ public void onBlockPhysics(BlockPhysicsEvent event) {
|
||||
|
||||
// RuleLists
|
||||
RuleSet rules = wcfg.getRuleList().get(KnownAttachment.BLOCK_PHYSICS);
|
||||
BukkitContext context = new BukkitContext(event);
|
||||
BukkitContext context = new BukkitContext(plugin, event);
|
||||
context.setTargetBlock(event.getBlock().getState());
|
||||
if (rules.process(context)) {
|
||||
event.setCancelled(true);
|
||||
@ -306,7 +306,7 @@ public void onBlockPlace(BlockPlaceEvent event) {
|
||||
|
||||
// RuleLists
|
||||
RuleSet rules = wcfg.getRuleList().get(KnownAttachment.BLOCK_PLACE);
|
||||
BukkitContext context = new BukkitContext(event);
|
||||
BukkitContext context = new BukkitContext(plugin, event);
|
||||
context.setTargetBlock(event.getBlock().getState());
|
||||
context.setPlacedBlock(event.getBlockReplacedState());
|
||||
if (rules.process(context)) {
|
||||
@ -379,7 +379,7 @@ public void onSignChange(SignChangeEvent event) {
|
||||
|
||||
// RuleLists
|
||||
RuleSet rules = wcfg.getRuleList().get(KnownAttachment.BLOCK_INTERACT);
|
||||
BukkitContext context = new BukkitContext(event);
|
||||
BukkitContext context = new BukkitContext(plugin, event);
|
||||
context.setTargetBlock(event.getBlock().getState());
|
||||
if (rules.process(context)) {
|
||||
event.setCancelled(true);
|
||||
@ -394,7 +394,7 @@ public void onLeavesDecay(LeavesDecayEvent event) {
|
||||
|
||||
// RuleLists
|
||||
RuleSet rules = wcfg.getRuleList().get(KnownAttachment.BLOCK_FADE);
|
||||
BukkitContext context = new BukkitContext(event);
|
||||
BukkitContext context = new BukkitContext(plugin, event);
|
||||
context.setTargetBlock(event.getBlock().getState());
|
||||
if (rules.process(context)) {
|
||||
event.setCancelled(true);
|
||||
@ -409,7 +409,7 @@ public void onBlockForm(BlockFormEvent event) {
|
||||
|
||||
// RuleLists
|
||||
RuleSet rules = wcfg.getRuleList().get(KnownAttachment.BLOCK_FORM);
|
||||
BukkitContext context = new BukkitContext(event);
|
||||
BukkitContext context = new BukkitContext(plugin, event);
|
||||
context.setTargetBlock(event.getBlock().getState());
|
||||
context.setPlacedBlock(event.getNewState());
|
||||
if (rules.process(context)) {
|
||||
@ -425,7 +425,7 @@ public void onBlockSpread(BlockSpreadEvent event) {
|
||||
|
||||
// RuleLists
|
||||
RuleSet rules = wcfg.getRuleList().get(KnownAttachment.BLOCK_SPREAD);
|
||||
BukkitContext context = new BukkitContext(event);
|
||||
BukkitContext context = new BukkitContext(plugin, event);
|
||||
context.setSourceBlock(event.getSource().getState());
|
||||
context.setTargetBlock(event.getBlock().getState());
|
||||
context.setPlacedBlock(event.getNewState());
|
||||
@ -442,7 +442,7 @@ public void onBlockFade(BlockFadeEvent event) {
|
||||
|
||||
// RuleLists
|
||||
RuleSet rules = wcfg.getRuleList().get(KnownAttachment.BLOCK_FADE);
|
||||
BukkitContext context = new BukkitContext(event);
|
||||
BukkitContext context = new BukkitContext(plugin, event);
|
||||
context.setTargetBlock(event.getBlock().getState());
|
||||
context.setPlacedBlock(event.getNewState());
|
||||
if (rules.process(context)) {
|
||||
@ -458,7 +458,7 @@ public void onBlockDispense(BlockDispenseEvent event) {
|
||||
|
||||
// RuleLists
|
||||
RuleSet rules = wcfg.getRuleList().get(KnownAttachment.ITEM_DROP);
|
||||
BukkitContext context = new BukkitContext(event);
|
||||
BukkitContext context = new BukkitContext(plugin, event);
|
||||
context.setSourceBlock(event.getBlock().getState());
|
||||
context.setItem(event.getItem());
|
||||
if (rules.process(context)) {
|
||||
|
@ -79,7 +79,7 @@ public void onEntityInteract(EntityInteractEvent event) {
|
||||
|
||||
// RuleLists
|
||||
RuleSet rules = wcfg.getRuleList().get(KnownAttachment.BLOCK_INTERACT);
|
||||
BukkitContext context = new BukkitContext(event);
|
||||
BukkitContext context = new BukkitContext(plugin, event);
|
||||
context.setSourceEntity(event.getEntity());
|
||||
context.setTargetBlock(event.getBlock().getState());
|
||||
if (rules.process(context)) {
|
||||
@ -97,7 +97,7 @@ public void onEntityDeath(EntityDeathEvent event) {
|
||||
|
||||
// RuleLists
|
||||
RuleSet rules = wcfg.getRuleList().get(KnownAttachment.ENTITY_DEATH);
|
||||
BukkitContext context = new BukkitContext(event);
|
||||
BukkitContext context = new BukkitContext(plugin, event);
|
||||
context.setTargetEntity(event.getEntity());
|
||||
|
||||
// Set a message if it's a death from a player
|
||||
@ -122,7 +122,7 @@ public void onEntityDamage(EntityDamageEvent event) {
|
||||
if (event instanceof EntityDamageByEntityEvent) {
|
||||
// RuleLists
|
||||
RuleSet rules = wcfg.getRuleList().get(KnownAttachment.ENTITY_DAMAGE);
|
||||
BukkitContext context = new BukkitContext(event);
|
||||
BukkitContext context = new BukkitContext(plugin, event);
|
||||
context.setSourceEntity(((EntityDamageByEntityEvent) event).getDamager());
|
||||
context.setTargetEntity(event.getEntity());
|
||||
if (rules.process(context)) {
|
||||
@ -134,7 +134,7 @@ public void onEntityDamage(EntityDamageEvent event) {
|
||||
} else if (event instanceof EntityDamageByBlockEvent) {
|
||||
// RuleLists
|
||||
RuleSet rules = wcfg.getRuleList().get(KnownAttachment.ENTITY_DAMAGE);
|
||||
BukkitContext context = new BukkitContext(event);
|
||||
BukkitContext context = new BukkitContext(plugin, event);
|
||||
Block damager = ((EntityDamageByBlockEvent) event).getDamager();
|
||||
if (damager != null) { // Should NOT be null!
|
||||
context.setSourceBlock(damager.getState());
|
||||
@ -149,7 +149,7 @@ public void onEntityDamage(EntityDamageEvent event) {
|
||||
} else {
|
||||
// RuleLists
|
||||
RuleSet rules = wcfg.getRuleList().get(KnownAttachment.ENTITY_DAMAGE);
|
||||
BukkitContext context = new BukkitContext(event);
|
||||
BukkitContext context = new BukkitContext(plugin, event);
|
||||
context.setTargetEntity(event.getEntity());
|
||||
if (rules.process(context)) {
|
||||
event.setCancelled(true);
|
||||
@ -167,7 +167,7 @@ public void onEntityCombust(EntityCombustEvent event) {
|
||||
|
||||
// RuleLists
|
||||
RuleSet rules = wcfg.getRuleList().get(KnownAttachment.ENTITY_IGNITE);
|
||||
BukkitContext context = new BukkitContext(event);
|
||||
BukkitContext context = new BukkitContext(plugin, event);
|
||||
context.setTargetEntity(entity);
|
||||
if (rules.process(context)) {
|
||||
event.setCancelled(true);
|
||||
@ -184,7 +184,7 @@ public void onEntityExplode(EntityExplodeEvent event) {
|
||||
|
||||
// RuleLists
|
||||
RuleSet rules = wcfg.getRuleList().get(KnownAttachment.ENTITY_EXPLODE);
|
||||
BukkitContext context = new BukkitContext(event);
|
||||
BukkitContext context = new BukkitContext(plugin, event);
|
||||
context.setTargetEntity(event.getEntity());
|
||||
if (rules.process(context)) {
|
||||
event.setCancelled(true);
|
||||
@ -199,7 +199,7 @@ public void onEntityExplode(EntityExplodeEvent event) {
|
||||
Block block = iter.next();
|
||||
|
||||
rules = wcfg.getRuleList().get(KnownAttachment.BLOCK_BREAK);
|
||||
context = new BukkitContext(event);
|
||||
context = new BukkitContext(plugin, event);
|
||||
context.setSourceEntity(event.getEntity());
|
||||
context.setTargetBlock(block.getState());
|
||||
rules.process(context);
|
||||
@ -216,7 +216,7 @@ public void onExplosionPrime(ExplosionPrimeEvent event) {
|
||||
|
||||
// RuleLists
|
||||
RuleSet rules = wcfg.getRuleList().get(KnownAttachment.ENTITY_EXPLODE);
|
||||
BukkitContext context = new BukkitContext(event);
|
||||
BukkitContext context = new BukkitContext(plugin, event);
|
||||
context.setTargetEntity(event.getEntity());
|
||||
if (rules.process(context)) {
|
||||
event.setCancelled(true);
|
||||
@ -231,7 +231,7 @@ public void onCreatureSpawn(CreatureSpawnEvent event) {
|
||||
|
||||
// RuleLists
|
||||
RuleSet rules = wcfg.getRuleList().get(KnownAttachment.ENTITY_SPAWN);
|
||||
BukkitContext context = new BukkitContext(event);
|
||||
BukkitContext context = new BukkitContext(plugin, event);
|
||||
context.setTargetEntity(event.getEntity());
|
||||
if (rules.process(context)) {
|
||||
event.setCancelled(true);
|
||||
@ -246,7 +246,7 @@ public void onPigZap(PigZapEvent event) {
|
||||
|
||||
// RuleLists
|
||||
RuleSet rules = wcfg.getRuleList().get(KnownAttachment.ENTITY_STRIKE);
|
||||
BukkitContext context = new BukkitContext(event);
|
||||
BukkitContext context = new BukkitContext(plugin, event);
|
||||
context.setTargetEntity(event.getEntity());
|
||||
if (rules.process(context)) {
|
||||
event.setCancelled(true);
|
||||
@ -261,7 +261,7 @@ public void onCreeperPower(CreeperPowerEvent event) {
|
||||
|
||||
// RuleLists
|
||||
RuleSet rules = wcfg.getRuleList().get(KnownAttachment.ENTITY_STRIKE);
|
||||
BukkitContext context = new BukkitContext(event);
|
||||
BukkitContext context = new BukkitContext(plugin, event);
|
||||
context.setTargetEntity(event.getEntity());
|
||||
if (rules.process(context)) {
|
||||
event.setCancelled(true);
|
||||
@ -279,7 +279,7 @@ public void onEntityChangeBlock(EntityChangeBlockEvent event) {
|
||||
// RuleLists
|
||||
RuleSet rules = wcfg.getRuleList().get(event.getTo() == Material.AIR ?
|
||||
KnownAttachment.BLOCK_BREAK : KnownAttachment.BLOCK_PLACE);
|
||||
BukkitContext context = new BukkitContext(event);
|
||||
BukkitContext context = new BukkitContext(plugin, event);
|
||||
context.setSourceEntity(entity);
|
||||
BlockState newState = event.getBlock().getState(); // This event is lame
|
||||
newState.setType(event.getTo()); // Need to construct our own BlockState
|
||||
|
@ -64,7 +64,7 @@ public void onHangingingBreak(HangingBreakEvent event) {
|
||||
|
||||
// RuleLists
|
||||
RuleSet rules = wcfg.getRuleList().get(KnownAttachment.ENTITY_DAMAGE);
|
||||
BukkitContext context = new BukkitContext(event);
|
||||
BukkitContext context = new BukkitContext(plugin, event);
|
||||
if (event instanceof HangingBreakByEntityEvent) {
|
||||
context.setSourceEntity(((HangingBreakByEntityEvent) event).getRemover());
|
||||
}
|
||||
@ -85,7 +85,7 @@ public void onHangingPlace(HangingPlaceEvent event) {
|
||||
|
||||
// RuleLists
|
||||
RuleSet rules = wcfg.getRuleList().get(KnownAttachment.ENTITY_SPAWN);
|
||||
BukkitContext context = new BukkitContext(event);
|
||||
BukkitContext context = new BukkitContext(plugin, event);
|
||||
context.setSourceEntity(event.getPlayer());
|
||||
context.setTargetEntity(event.getEntity());
|
||||
if (rules.process(context)) {
|
||||
|
@ -66,7 +66,7 @@ public void onPaintingBreak(PaintingBreakEvent event) {
|
||||
|
||||
// RuleLists
|
||||
RuleSet rules = wcfg.getRuleList().get(KnownAttachment.ENTITY_DAMAGE);
|
||||
BukkitContext context = new BukkitContext(event);
|
||||
BukkitContext context = new BukkitContext(plugin, event);
|
||||
if (event instanceof PaintingBreakByEntityEvent) {
|
||||
context.setSourceEntity(((PaintingBreakByEntityEvent) event).getRemover());
|
||||
}
|
||||
@ -87,7 +87,7 @@ public void onPaintingPlace(PaintingPlaceEvent event) {
|
||||
|
||||
// RuleLists
|
||||
RuleSet rules = wcfg.getRuleList().get(KnownAttachment.ENTITY_SPAWN);
|
||||
BukkitContext context = new BukkitContext(event);
|
||||
BukkitContext context = new BukkitContext(plugin, event);
|
||||
context.setSourceEntity(event.getPlayer());
|
||||
context.setTargetEntity(event.getPainting());
|
||||
if (rules.process(context)) {
|
||||
|
@ -97,7 +97,7 @@ public void onPlayerJoin(PlayerJoinEvent event) {
|
||||
|
||||
// RuleLists
|
||||
RuleSet rules = wcfg.getRuleList().get(KnownAttachment.PLAYER_JOIN);
|
||||
BukkitContext context = new BukkitContext(event);
|
||||
BukkitContext context = new BukkitContext(plugin, event);
|
||||
context.setTargetEntity(player);
|
||||
rules.process(context);
|
||||
}
|
||||
@ -109,7 +109,7 @@ public void onPlayerChat(AsyncPlayerChatEvent event) {
|
||||
|
||||
// RuleLists
|
||||
RuleSet rules = wcfg.getRuleList().get(KnownAttachment.CHAT);
|
||||
BukkitContext context = new BukkitContext(event);
|
||||
BukkitContext context = new BukkitContext(plugin, event);
|
||||
context.setSourceEntity(event.getPlayer());
|
||||
context.setMessage(event.getMessage());
|
||||
|
||||
@ -160,7 +160,7 @@ public void onPlayerQuit(PlayerQuitEvent event) {
|
||||
|
||||
// RuleLists
|
||||
RuleSet rules = wcfg.getRuleList().get(KnownAttachment.PLAYER_QUIT);
|
||||
BukkitContext context = new BukkitContext(event);
|
||||
BukkitContext context = new BukkitContext(plugin, event);
|
||||
context.setSourceEntity(player);
|
||||
rules.process(context);
|
||||
|
||||
@ -186,7 +186,7 @@ public void onPlayerInteract(PlayerInteractEvent event) {
|
||||
Block block = event.getClickedBlock();
|
||||
if (block != null) {
|
||||
rules = wcfg.getRuleList().get(KnownAttachment.BLOCK_INTERACT);
|
||||
context = new BukkitContext(event);
|
||||
context = new BukkitContext(plugin, event);
|
||||
context.setSourceEntity(player);
|
||||
context.setTargetBlock(event.getClickedBlock().getState());
|
||||
if (rules.process(context)) {
|
||||
@ -198,7 +198,7 @@ public void onPlayerInteract(PlayerInteractEvent event) {
|
||||
ItemStack heldItem = event.getPlayer().getItemInHand();
|
||||
if (heldItem != null) {
|
||||
rules = wcfg.getRuleList().get(KnownAttachment.ITEM_USE);
|
||||
context = new BukkitContext(event);
|
||||
context = new BukkitContext(plugin, event);
|
||||
context.setSourceEntity(event.getPlayer());
|
||||
context.setItem(heldItem);
|
||||
if (rules.process(context)) {
|
||||
@ -215,7 +215,7 @@ public void onPlayerDropItem(PlayerDropItemEvent event) {
|
||||
|
||||
// RuleLists
|
||||
RuleSet rules = wcfg.getRuleList().get(KnownAttachment.ITEM_DROP);
|
||||
BukkitContext context = new BukkitContext(event);
|
||||
BukkitContext context = new BukkitContext(plugin, event);
|
||||
context.setSourceEntity(player);
|
||||
context.setItem(event.getItemDrop().getItemStack());
|
||||
if (rules.process(context)) {
|
||||
@ -231,7 +231,7 @@ public void onPlayerPickupItem(PlayerPickupItemEvent event) {
|
||||
|
||||
// RuleLists
|
||||
RuleSet rules = wcfg.getRuleList().get(KnownAttachment.ITEM_PICKUP);
|
||||
BukkitContext context = new BukkitContext(event);
|
||||
BukkitContext context = new BukkitContext(plugin, event);
|
||||
context.setSourceEntity(event.getPlayer());
|
||||
context.setItem(event.getItem().getItemStack());
|
||||
if (rules.process(context)) {
|
||||
@ -251,7 +251,7 @@ public void onPlayerDeath(PlayerDeathEvent event) {
|
||||
|
||||
// RuleLists
|
||||
RuleSet rules = wcfg.getRuleList().get(KnownAttachment.ENTITY_DEATH);
|
||||
BukkitContext context = new BukkitContext(event);
|
||||
BukkitContext context = new BukkitContext(plugin, event);
|
||||
context.setTargetEntity(player);
|
||||
rules.process(context);
|
||||
}
|
||||
@ -266,7 +266,7 @@ public void onPlayerBucketFill(PlayerBucketFillEvent event) {
|
||||
|
||||
// RuleLists
|
||||
RuleSet rules = wcfg.getRuleList().get(KnownAttachment.ITEM_USE);
|
||||
BukkitContext context = new BukkitContext(event);
|
||||
BukkitContext context = new BukkitContext(plugin, event);
|
||||
context.setSourceEntity(event.getPlayer());
|
||||
context.setItem(event.getItemStack());
|
||||
if (rules.process(context)) {
|
||||
@ -285,7 +285,7 @@ public void onPlayerBucketEmpty(PlayerBucketEmptyEvent event) {
|
||||
|
||||
// RuleLists
|
||||
RuleSet rules = wcfg.getRuleList().get(KnownAttachment.ITEM_USE);
|
||||
BukkitContext context = new BukkitContext(event);
|
||||
BukkitContext context = new BukkitContext(plugin, event);
|
||||
context.setSourceEntity(event.getPlayer());
|
||||
context.setItem(event.getItemStack());
|
||||
if (rules.process(context)) {
|
||||
@ -305,7 +305,7 @@ public void onPlayerRespawn(PlayerRespawnEvent event) {
|
||||
|
||||
// RuleLists
|
||||
RuleSet rules = wcfg.getRuleList().get(KnownAttachment.PLAYER_RESPAWN);
|
||||
BukkitContext context = new BukkitContext(event);
|
||||
BukkitContext context = new BukkitContext(plugin, event);
|
||||
context.setSourceEntity(event.getPlayer());
|
||||
rules.process(context);
|
||||
}
|
||||
@ -319,7 +319,7 @@ public void onPlayerBedEnter(PlayerBedEnterEvent event) {
|
||||
|
||||
// RuleLists
|
||||
RuleSet rules = wcfg.getRuleList().get(KnownAttachment.BLOCK_INTERACT);
|
||||
BukkitContext context = new BukkitContext(event);
|
||||
BukkitContext context = new BukkitContext(plugin, event);
|
||||
context.setSourceEntity(player);
|
||||
context.setTargetBlock(event.getBed().getState());
|
||||
if (rules.process(context)) {
|
||||
|
@ -109,6 +109,7 @@ public class WorldGuardPlugin extends JavaPlugin {
|
||||
private final ConfigurationManager configuration;
|
||||
private FlagStateManager flagStateManager;
|
||||
private RuleListsManager ruleListsManager;
|
||||
private RegionQueryCache regionCache;
|
||||
private final LagStopMode lagStopper;
|
||||
|
||||
private WorldGuardWorldListener worldListener;
|
||||
@ -141,6 +142,9 @@ public void onEnable() {
|
||||
ruleListsManager = new RuleListsManager();
|
||||
registerRuleList();
|
||||
|
||||
// Setup the cache
|
||||
regionCache = new RegionQueryCache(this);
|
||||
|
||||
// Set the proper command injector
|
||||
commands.setInjector(new SimpleInjector(this));
|
||||
|
||||
@ -300,6 +304,15 @@ public RuleListsManager getRulesListManager() {
|
||||
return ruleListsManager;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the region query cache.
|
||||
*
|
||||
* @return region query cache
|
||||
*/
|
||||
public RegionQueryCache getRegionCache() {
|
||||
return regionCache;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the built-in rules.
|
||||
*
|
||||
|
@ -46,7 +46,7 @@ public void onVehicleDestroy(VehicleDestroyEvent event) {
|
||||
|
||||
// RuleLists
|
||||
RuleSet rules = wcfg.getRuleList().get(KnownAttachment.ENTITY_DAMAGE);
|
||||
BukkitContext context = new BukkitContext(event);
|
||||
BukkitContext context = new BukkitContext(plugin, event);
|
||||
context.setSourceEntity(destroyer);
|
||||
context.setTargetEntity(vehicle);
|
||||
if (rules.process(context)) {
|
||||
|
@ -59,7 +59,7 @@ public void onWeatherChange(WeatherChangeEvent event) {
|
||||
|
||||
// RuleLists
|
||||
RuleSet rules = wcfg.getRuleList().get(KnownAttachment.WEATHER_TRANSITION);
|
||||
BukkitContext context = new BukkitContext(event);
|
||||
BukkitContext context = new BukkitContext(plugin, event);
|
||||
if (rules.process(context)) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
@ -73,7 +73,7 @@ public void onThunderChange(ThunderChangeEvent event) {
|
||||
|
||||
// RuleLists
|
||||
RuleSet rules = wcfg.getRuleList().get(KnownAttachment.WEATHER_TRANSITION);
|
||||
BukkitContext context = new BukkitContext(event);
|
||||
BukkitContext context = new BukkitContext(plugin, event);
|
||||
if (rules.process(context)) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
@ -89,7 +89,7 @@ public void onLightningStrike(LightningStrikeEvent event) {
|
||||
|
||||
// RuleLists
|
||||
RuleSet rules = wcfg.getRuleList().get(KnownAttachment.WEATHER_PHENOMENON);
|
||||
BukkitContext context = new BukkitContext(event);
|
||||
BukkitContext context = new BukkitContext(plugin, event);
|
||||
context.setTargetBlock(loc.getBlock().getState());
|
||||
if (rules.process(context)) {
|
||||
event.setCancelled(true);
|
||||
|
@ -46,7 +46,7 @@ public void onWorldLoad(WorldLoadEvent event) {
|
||||
|
||||
// RuleLists
|
||||
RuleSet rules = wcfg.getRuleList().get(KnownAttachment.WORLD_LOAD);
|
||||
BukkitContext context = new BukkitContext(event);
|
||||
BukkitContext context = new BukkitContext(plugin, event);
|
||||
rules.process(context);
|
||||
}
|
||||
|
||||
@ -57,7 +57,7 @@ public void onWorldLoad(WorldUnloadEvent event) {
|
||||
|
||||
// RuleLists
|
||||
RuleSet rules = wcfg.getRuleList().get(KnownAttachment.WORLD_UNLOAD);
|
||||
BukkitContext context = new BukkitContext(event);
|
||||
BukkitContext context = new BukkitContext(plugin, event);
|
||||
if (rules.process(context)) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
@ -73,7 +73,7 @@ public void onWorldSave(WorldSaveEvent event) {
|
||||
|
||||
// RuleLists
|
||||
RuleSet rules = wcfg.getRuleList().get(KnownAttachment.WORLD_SAVE);
|
||||
BukkitContext context = new BukkitContext(event);
|
||||
BukkitContext context = new BukkitContext(plugin, event);
|
||||
rules.process(context);
|
||||
}
|
||||
}
|
||||
|
@ -35,12 +35,12 @@
|
||||
* This class is abstract because implementing class should provide methods to check
|
||||
* against a standard key object. This cache itself is thread-safe.
|
||||
*/
|
||||
public abstract class RegionQueryCache {
|
||||
public abstract class AbstractRegionQueryCache {
|
||||
|
||||
private final WeakHashMap<Object, RegionQueryCacheEntry> cache =
|
||||
new WeakHashMap<Object, RegionQueryCacheEntry>();
|
||||
|
||||
public RegionQueryCache() {
|
||||
public AbstractRegionQueryCache() {
|
||||
}
|
||||
|
||||
/**
|
@ -30,9 +30,9 @@
|
||||
* An object to cache a list of {@link ApplicableRegionSet}s. This class is
|
||||
* thread-safe.
|
||||
*
|
||||
* @see RegionQueryCache
|
||||
* @see AbstractRegionQueryCache
|
||||
*/
|
||||
public class RegionQueryCacheEntry {
|
||||
public final class RegionQueryCacheEntry {
|
||||
|
||||
private final Map<BlockVector, ApplicableRegionSet> cachedPoints =
|
||||
new HashMap<BlockVector, ApplicableRegionSet>();
|
||||
|
Loading…
Reference in New Issue
Block a user