mirror of
https://github.com/EngineHub/WorldGuard.git
synced 2024-12-26 02:57:42 +01:00
Abstract events for regions and blacklists further.
This commit is contained in:
parent
9cab51dac8
commit
4a501a49db
@ -42,6 +42,7 @@
|
||||
import org.bukkit.entity.Tameable;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.List;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
@ -312,6 +313,22 @@ public static Target createTarget(Block block) {
|
||||
return new MaterialTarget(block.getTypeId(), block.getData());
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a blacklist target for the given block.
|
||||
*
|
||||
* @param block the block
|
||||
* @param material a fallback material
|
||||
* @return a target
|
||||
*/
|
||||
public static Target createTarget(@Nullable Block block, Material material) {
|
||||
checkNotNull(material);
|
||||
if (block != null) {
|
||||
return new MaterialTarget(block.getTypeId(), block.getData());
|
||||
} else {
|
||||
return new MaterialTarget(material.getId(), (short) 0);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a blacklist target for the given item.
|
||||
*
|
||||
|
@ -23,17 +23,9 @@
|
||||
import com.sk89q.worldedit.blocks.BlockID;
|
||||
import com.sk89q.worldedit.blocks.BlockType;
|
||||
import com.sk89q.worldedit.blocks.ItemType;
|
||||
import com.sk89q.worldguard.LocalPlayer;
|
||||
import com.sk89q.worldguard.blacklist.event.BlockDispenseBlacklistEvent;
|
||||
import com.sk89q.worldguard.internal.Events;
|
||||
import com.sk89q.worldguard.internal.cause.Causes;
|
||||
import com.sk89q.worldguard.internal.event.BlockInteractEvent;
|
||||
import com.sk89q.worldguard.internal.event.Interaction;
|
||||
import com.sk89q.worldguard.internal.event.ItemInteractEvent;
|
||||
import com.sk89q.worldguard.protection.ApplicableRegionSet;
|
||||
import com.sk89q.worldguard.protection.flags.DefaultFlag;
|
||||
import com.sk89q.worldguard.protection.managers.RegionManager;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.block.Block;
|
||||
@ -44,8 +36,6 @@
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.block.BlockBreakEvent;
|
||||
import org.bukkit.event.block.BlockBurnEvent;
|
||||
import org.bukkit.event.block.BlockDamageEvent;
|
||||
import org.bukkit.event.block.BlockDispenseEvent;
|
||||
import org.bukkit.event.block.BlockExpEvent;
|
||||
import org.bukkit.event.block.BlockFadeEvent;
|
||||
import org.bukkit.event.block.BlockFormEvent;
|
||||
@ -60,10 +50,8 @@
|
||||
import org.bukkit.event.block.BlockSpreadEvent;
|
||||
import org.bukkit.event.block.EntityBlockFormEvent;
|
||||
import org.bukkit.event.block.LeavesDecayEvent;
|
||||
import org.bukkit.event.block.SignChangeEvent;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import static com.sk89q.worldguard.bukkit.BukkitUtil.createTarget;
|
||||
import static com.sk89q.worldguard.bukkit.BukkitUtil.toVector;
|
||||
|
||||
/**
|
||||
@ -111,20 +99,6 @@ protected WorldConfiguration getWorldConfig(Player player) {
|
||||
return getWorldConfig(player.getWorld());
|
||||
}
|
||||
|
||||
/*
|
||||
* Called when a block is damaged.
|
||||
*/
|
||||
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
|
||||
public void onBlockDamage(BlockDamageEvent event) {
|
||||
Block target = event.getBlock();
|
||||
|
||||
// Cake are damaged and not broken when they are eaten, so we must
|
||||
// handle them a bit separately
|
||||
if (target.getType() == Material.CAKE_BLOCK) {
|
||||
Events.fireToCancel(event, new BlockInteractEvent(event, Causes.create(event.getPlayer()), Interaction.INTERACT, target));
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Called when a block is broken.
|
||||
*/
|
||||
@ -141,8 +115,6 @@ public void onBlockBreak(BlockBreakEvent event) {
|
||||
player.setItemInHand(held);
|
||||
}
|
||||
}
|
||||
|
||||
Events.fireToCancel(event, new BlockInteractEvent(event, Causes.create(event.getPlayer()), Interaction.BREAK, target));
|
||||
}
|
||||
|
||||
/*
|
||||
@ -301,25 +273,9 @@ public void onBlockIgnite(BlockIgniteEvent event) {
|
||||
|
||||
if (wcfg.useRegions) {
|
||||
Vector pt = toVector(block);
|
||||
Player player = event.getPlayer();
|
||||
RegionManager mgr = plugin.getGlobalRegionManager().get(world);
|
||||
ApplicableRegionSet set = mgr.getApplicableRegions(pt);
|
||||
|
||||
if (player != null && !plugin.getGlobalRegionManager().hasBypass(player, world)) {
|
||||
LocalPlayer localPlayer = plugin.wrapPlayer(player);
|
||||
|
||||
// this is preliminarily handled in the player listener under handleBlockRightClick
|
||||
// why it's handled here too, no one knows
|
||||
if (cause == IgniteCause.FLINT_AND_STEEL || cause == IgniteCause.FIREBALL) {
|
||||
if (!set.allows(DefaultFlag.LIGHTER)
|
||||
&& !set.canBuild(localPlayer)
|
||||
&& !plugin.hasPermission(player, "worldguard.override.lighter")) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (wcfg.highFreqFlags && isFireSpread
|
||||
&& !set.allows(DefaultFlag.FIRE_SPREAD)) {
|
||||
event.setCancelled(true);
|
||||
@ -469,8 +425,6 @@ public void onBlockPlace(BlockPlaceEvent event) {
|
||||
ConfigurationManager cfg = plugin.getGlobalStateManager();
|
||||
WorldConfiguration wcfg = cfg.get(world);
|
||||
|
||||
Events.fireToCancel(event, new BlockInteractEvent(event, Causes.create(event.getPlayer()), Interaction.PLACE, target));
|
||||
|
||||
if (wcfg.simulateSponge && target.getType() == Material.SPONGE) {
|
||||
if (wcfg.redstoneSponges && target.isBlockIndirectlyPowered()) {
|
||||
return;
|
||||
@ -519,75 +473,6 @@ public void onBlockRedstoneChange(BlockRedstoneEvent event) {
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Called when a sign is changed.
|
||||
*/
|
||||
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
|
||||
public void onSignChange(SignChangeEvent event) {
|
||||
Player player = event.getPlayer();
|
||||
WorldConfiguration wcfg = getWorldConfig(player);
|
||||
|
||||
if (wcfg.signChestProtection) {
|
||||
if (event.getLine(0).equalsIgnoreCase("[Lock]")) {
|
||||
if (wcfg.isChestProtectedPlacement(event.getBlock(), player)) {
|
||||
player.sendMessage(ChatColor.DARK_RED + "You do not own the adjacent chest.");
|
||||
event.getBlock().breakNaturally();
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
|
||||
if (event.getBlock().getTypeId() != BlockID.SIGN_POST) {
|
||||
player.sendMessage(ChatColor.RED
|
||||
+ "The [Lock] sign must be a sign post, not a wall sign.");
|
||||
|
||||
event.getBlock().breakNaturally();
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!event.getLine(1).equalsIgnoreCase(player.getName())) {
|
||||
player.sendMessage(ChatColor.RED
|
||||
+ "The first owner line must be your name.");
|
||||
|
||||
event.getBlock().breakNaturally();
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
|
||||
int below = event.getBlock().getRelative(0, -1, 0).getTypeId();
|
||||
|
||||
if (below == BlockID.TNT || below == BlockID.SAND
|
||||
|| below == BlockID.GRAVEL || below == BlockID.SIGN_POST) {
|
||||
player.sendMessage(ChatColor.RED
|
||||
+ "That is not a safe block that you're putting this sign on.");
|
||||
|
||||
event.getBlock().breakNaturally();
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
|
||||
event.setLine(0, "[Lock]");
|
||||
player.sendMessage(ChatColor.YELLOW
|
||||
+ "A chest or double chest above is now protected.");
|
||||
}
|
||||
} else if (!wcfg.disableSignChestProtectionCheck) {
|
||||
if (event.getLine(0).equalsIgnoreCase("[Lock]")) {
|
||||
player.sendMessage(ChatColor.RED
|
||||
+ "WorldGuard's sign chest protection is disabled.");
|
||||
|
||||
event.getBlock().breakNaturally();
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (!plugin.getGlobalRegionManager().canBuild(player, event.getBlock())) {
|
||||
player.sendMessage(ChatColor.DARK_RED + "You don't have permission for this area.");
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
|
||||
public void onLeavesDecay(LeavesDecayEvent event) {
|
||||
ConfigurationManager cfg = plugin.getGlobalStateManager();
|
||||
@ -827,21 +712,6 @@ public void onBlockPistonRetract(BlockPistonRetractEvent event) {
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
|
||||
public void onBlockDispense(BlockDispenseEvent event) {
|
||||
ConfigurationManager cfg = plugin.getGlobalStateManager();
|
||||
WorldConfiguration wcfg = cfg.get(event.getBlock().getWorld());
|
||||
|
||||
if (wcfg.getBlacklist() != null) {
|
||||
if (!wcfg.getBlacklist().check(new BlockDispenseBlacklistEvent(null, toVector(event.getBlock()), createTarget(event.getItem())), false, false)) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
Events.fireToCancel(event, new ItemInteractEvent(event, Causes.create(event.getBlock()), Interaction.INTERACT, event.getBlock().getWorld(), event.getItem()));
|
||||
}
|
||||
|
||||
/*
|
||||
* Called when a block yields exp
|
||||
*/
|
||||
|
@ -22,11 +22,6 @@
|
||||
import com.sk89q.worldedit.Vector;
|
||||
import com.sk89q.worldedit.blocks.BlockID;
|
||||
import com.sk89q.worldguard.LocalPlayer;
|
||||
import com.sk89q.worldguard.blacklist.event.ItemUseBlacklistEvent;
|
||||
import com.sk89q.worldguard.internal.Events;
|
||||
import com.sk89q.worldguard.internal.cause.Causes;
|
||||
import com.sk89q.worldguard.internal.event.Interaction;
|
||||
import com.sk89q.worldguard.internal.event.ItemInteractEvent;
|
||||
import com.sk89q.worldguard.protection.ApplicableRegionSet;
|
||||
import com.sk89q.worldguard.protection.GlobalRegionManager;
|
||||
import com.sk89q.worldguard.protection.events.DisallowedPVPEvent;
|
||||
@ -83,7 +78,6 @@
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
import static com.sk89q.worldguard.bukkit.BukkitUtil.createTarget;
|
||||
import static com.sk89q.worldguard.bukkit.BukkitUtil.toVector;
|
||||
|
||||
/**
|
||||
@ -225,26 +219,6 @@ private void onEntityDamageByEntity(EntityDamageByEntityEvent event) {
|
||||
Entity attacker = event.getDamager();
|
||||
Entity defender = event.getEntity();
|
||||
|
||||
if (attacker instanceof Player) {
|
||||
Player player = (Player) attacker;
|
||||
|
||||
ConfigurationManager cfg = plugin.getGlobalStateManager();
|
||||
WorldConfiguration wcfg = cfg.get(player.getWorld());
|
||||
|
||||
ItemStack held = player.getInventory().getItemInHand();
|
||||
|
||||
if (held != null) {
|
||||
if (wcfg.getBlacklist() != null) {
|
||||
if (!wcfg.getBlacklist().check(
|
||||
new ItemUseBlacklistEvent(plugin.wrapPlayer(player),
|
||||
toVector(player.getLocation()), createTarget(held)), false, false)) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (defender instanceof ItemFrame) {
|
||||
if (checkItemFrameProtection(attacker, (ItemFrame) defender)) {
|
||||
event.setCancelled(true);
|
||||
@ -934,9 +908,6 @@ public void onPotionSplash(PotionSplashEvent event) {
|
||||
World world = entity.getWorld();
|
||||
|
||||
ConfigurationManager cfg = plugin.getGlobalStateManager();
|
||||
WorldConfiguration wcfg = cfg.get(world);
|
||||
|
||||
Events.fireToCancel(event, new ItemInteractEvent(event, Causes.create(potion.getShooter()), Interaction.INTERACT, world, potion.getItem()));
|
||||
|
||||
GlobalRegionManager regionMan = plugin.getGlobalRegionManager();
|
||||
|
||||
@ -1017,16 +988,7 @@ private boolean checkItemFrameProtection(Entity attacker, ItemFrame defender) {
|
||||
if (wcfg.useRegions) {
|
||||
// bukkit throws this event when a player attempts to remove an item from a frame
|
||||
RegionManager mgr = plugin.getGlobalRegionManager().get(world);
|
||||
if (attacker instanceof Player) {
|
||||
Player player = (Player) attacker;
|
||||
LocalPlayer localPlayer = plugin.wrapPlayer(player);
|
||||
if (!plugin.getGlobalRegionManager().hasBypass(player, world)
|
||||
&& !mgr.getApplicableRegions(defender.getLocation())
|
||||
.canBuild(localPlayer)) {
|
||||
player.sendMessage(ChatColor.DARK_RED + "You don't have permission for this area.");
|
||||
return true;
|
||||
}
|
||||
} else {
|
||||
if (!(attacker instanceof Player)) {
|
||||
if (!plugin.getGlobalRegionManager().allows(
|
||||
DefaultFlag.ENTITY_ITEM_FRAME_DESTROY, defender.getLocation())) {
|
||||
return true;
|
||||
|
@ -19,14 +19,8 @@
|
||||
|
||||
package com.sk89q.worldguard.bukkit;
|
||||
|
||||
import com.sk89q.worldedit.blocks.ItemID;
|
||||
import com.sk89q.worldguard.blacklist.event.BlockBreakBlacklistEvent;
|
||||
import com.sk89q.worldguard.blacklist.event.ItemUseBlacklistEvent;
|
||||
import com.sk89q.worldguard.blacklist.target.MaterialTarget;
|
||||
import com.sk89q.worldguard.protection.flags.DefaultFlag;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.entity.Creeper;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.Hanging;
|
||||
@ -41,12 +35,8 @@
|
||||
import org.bukkit.event.hanging.HangingBreakByEntityEvent;
|
||||
import org.bukkit.event.hanging.HangingBreakEvent;
|
||||
import org.bukkit.event.hanging.HangingBreakEvent.RemoveCause;
|
||||
import org.bukkit.event.hanging.HangingPlaceEvent;
|
||||
import org.bukkit.event.player.PlayerInteractEntityEvent;
|
||||
import org.bukkit.projectiles.ProjectileSource;
|
||||
|
||||
import static com.sk89q.worldguard.bukkit.BukkitUtil.toVector;
|
||||
|
||||
/**
|
||||
* Listener for painting related events.
|
||||
*
|
||||
@ -73,7 +63,7 @@ public void registerEvents() {
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
|
||||
public void onHangingingBreak(HangingBreakEvent event) {
|
||||
public void onHangingBreak(HangingBreakEvent event) {
|
||||
Hanging hanging = event.getEntity();
|
||||
World world = hanging.getWorld();
|
||||
ConfigurationManager cfg = plugin.getGlobalStateManager();
|
||||
@ -88,33 +78,7 @@ public void onHangingingBreak(HangingBreakEvent event) {
|
||||
removerEntity = (remover instanceof LivingEntity ? (LivingEntity) remover : null);
|
||||
}
|
||||
|
||||
if (removerEntity instanceof Player) {
|
||||
Player player = (Player) removerEntity;
|
||||
|
||||
if (wcfg.getBlacklist() != null) {
|
||||
if (hanging instanceof Painting
|
||||
&& !wcfg.getBlacklist().check(
|
||||
new BlockBreakBlacklistEvent(plugin.wrapPlayer(player),
|
||||
toVector(player.getLocation()), new MaterialTarget(ItemID.PAINTING, (short) 0)), false, false)) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
} else if (hanging instanceof ItemFrame
|
||||
&& !wcfg.getBlacklist().check(
|
||||
new BlockBreakBlacklistEvent(plugin.wrapPlayer(player),
|
||||
toVector(player.getLocation()), new MaterialTarget(ItemID.ITEM_FRAME, (short) 0)), false, false)) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (wcfg.useRegions) {
|
||||
if (!plugin.getGlobalRegionManager().canBuild(player, hanging.getLocation())) {
|
||||
player.sendMessage(ChatColor.DARK_RED + "You don't have permission for this area.");
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (!(removerEntity instanceof Player)) {
|
||||
if (removerEntity instanceof Creeper) {
|
||||
if (wcfg.blockCreeperBlockDamage || wcfg.blockCreeperExplosions) {
|
||||
event.setCancelled(true);
|
||||
@ -152,65 +116,4 @@ public void onHangingingBreak(HangingBreakEvent event) {
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
|
||||
public void onHangingPlace(HangingPlaceEvent event) {
|
||||
Block placedOn = event.getBlock();
|
||||
Player player = event.getPlayer();
|
||||
World world = placedOn.getWorld();
|
||||
|
||||
ConfigurationManager cfg = plugin.getGlobalStateManager();
|
||||
WorldConfiguration wcfg = cfg.get(world);
|
||||
|
||||
if (wcfg.getBlacklist() != null) {
|
||||
|
||||
if (event.getEntity() instanceof Painting
|
||||
&& !wcfg.getBlacklist().check(
|
||||
new ItemUseBlacklistEvent(plugin.wrapPlayer(player),
|
||||
toVector(player.getLocation()), new MaterialTarget(ItemID.PAINTING, (short) 0)), false, false)) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
} else if (event.getEntity() instanceof ItemFrame
|
||||
&& !wcfg.getBlacklist().check(
|
||||
new ItemUseBlacklistEvent(plugin.wrapPlayer(player),
|
||||
toVector(player.getLocation()), new MaterialTarget(ItemID.ITEM_FRAME, (short) 0)), false, false)) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (wcfg.useRegions) {
|
||||
if (!plugin.getGlobalRegionManager().canBuild(player, placedOn.getRelative(event.getBlockFace()))) {
|
||||
player.sendMessage(ChatColor.DARK_RED + "You don't have permission for this area.");
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
|
||||
public void onEntityInteract(PlayerInteractEntityEvent event) {
|
||||
Player player = event.getPlayer();
|
||||
Entity entity = event.getRightClicked();
|
||||
|
||||
ConfigurationManager cfg = plugin.getGlobalStateManager();
|
||||
WorldConfiguration wcfg = cfg.get(entity.getWorld());
|
||||
|
||||
if (wcfg.useRegions && (entity instanceof ItemFrame || entity instanceof Painting)) {
|
||||
if (!plugin.getGlobalRegionManager().canBuild(player, entity.getLocation())) {
|
||||
player.sendMessage(ChatColor.DARK_RED + "You don't have permission for this area.");
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
|
||||
// if (entity instanceof ItemFrame
|
||||
// && ((!plugin.getGlobalRegionManager().allows(
|
||||
// DefaultFlag.ENTITY_ITEM_FRAME_DESTROY, entity.getLocation())))) {
|
||||
// event.setCancelled(true);
|
||||
// } else if (entity instanceof Painting
|
||||
// && ((!plugin.getGlobalRegionManager().allows(
|
||||
// DefaultFlag.ENTITY_PAINTING_DESTROY, entity.getLocation())))) {
|
||||
// event.setCancelled(true);
|
||||
// }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -21,20 +21,9 @@
|
||||
|
||||
import com.sk89q.worldedit.Vector;
|
||||
import com.sk89q.worldedit.blocks.BlockID;
|
||||
import com.sk89q.worldedit.blocks.BlockType;
|
||||
import com.sk89q.worldedit.blocks.ItemID;
|
||||
import com.sk89q.worldguard.LocalPlayer;
|
||||
import com.sk89q.worldguard.blacklist.event.BlockBreakBlacklistEvent;
|
||||
import com.sk89q.worldguard.blacklist.event.BlockInteractBlacklistEvent;
|
||||
import com.sk89q.worldguard.blacklist.event.BlockPlaceBlacklistEvent;
|
||||
import com.sk89q.worldguard.blacklist.event.ItemAcquireBlacklistEvent;
|
||||
import com.sk89q.worldguard.blacklist.event.ItemDropBlacklistEvent;
|
||||
import com.sk89q.worldguard.blacklist.event.ItemUseBlacklistEvent;
|
||||
import com.sk89q.worldguard.bukkit.FlagStateManager.PlayerFlagState;
|
||||
import com.sk89q.worldguard.internal.Events;
|
||||
import com.sk89q.worldguard.internal.cause.Causes;
|
||||
import com.sk89q.worldguard.internal.event.Interaction;
|
||||
import com.sk89q.worldguard.internal.event.ItemInteractEvent;
|
||||
import com.sk89q.worldguard.protection.ApplicableRegionSet;
|
||||
import com.sk89q.worldguard.protection.flags.DefaultFlag;
|
||||
import com.sk89q.worldguard.protection.managers.RegionManager;
|
||||
@ -45,19 +34,14 @@
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.BlockFace;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.Item;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.Event.Result;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.block.Action;
|
||||
import org.bukkit.event.player.AsyncPlayerChatEvent;
|
||||
import org.bukkit.event.player.PlayerBedEnterEvent;
|
||||
import org.bukkit.event.player.PlayerBucketEmptyEvent;
|
||||
import org.bukkit.event.player.PlayerBucketFillEvent;
|
||||
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
|
||||
import org.bukkit.event.player.PlayerDropItemEvent;
|
||||
import org.bukkit.event.player.PlayerFishEvent;
|
||||
@ -68,7 +52,6 @@
|
||||
import org.bukkit.event.player.PlayerJoinEvent;
|
||||
import org.bukkit.event.player.PlayerLoginEvent;
|
||||
import org.bukkit.event.player.PlayerMoveEvent;
|
||||
import org.bukkit.event.player.PlayerPickupItemEvent;
|
||||
import org.bukkit.event.player.PlayerQuitEvent;
|
||||
import org.bukkit.event.player.PlayerRespawnEvent;
|
||||
import org.bukkit.event.player.PlayerTeleportEvent;
|
||||
@ -474,39 +457,13 @@ public void onPlayerQuit(PlayerQuitEvent event) {
|
||||
plugin.forgetPlayer(player);
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGH)
|
||||
public void onPlayerInteractEntity(PlayerInteractEntityEvent event) {
|
||||
// TODO reduce duplication with right-click-air
|
||||
Player player = event.getPlayer();
|
||||
World world = player.getWorld();
|
||||
ItemStack item = player.getItemInHand();
|
||||
|
||||
ConfigurationManager cfg = plugin.getGlobalStateManager();
|
||||
WorldConfiguration wcfg = cfg.get(world);
|
||||
|
||||
if (wcfg.getBlacklist() != null) {
|
||||
if (!wcfg.getBlacklist().check(
|
||||
new ItemUseBlacklistEvent(plugin.wrapPlayer(player), toVector(player.getLocation()), createTarget(item)), false, false)) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGH)
|
||||
public void onPlayerInteract(PlayerInteractEvent event) {
|
||||
Player player = event.getPlayer();
|
||||
World world = player.getWorld();
|
||||
ItemStack item = event.getItem();
|
||||
|
||||
if (event.getAction() == Action.RIGHT_CLICK_BLOCK) {
|
||||
handleBlockRightClick(event);
|
||||
} else if (event.getAction() == Action.RIGHT_CLICK_AIR) {
|
||||
handleAirRightClick(event);
|
||||
} else if (event.getAction() == Action.LEFT_CLICK_BLOCK) {
|
||||
handleBlockLeftClick(event);
|
||||
} else if (event.getAction() == Action.LEFT_CLICK_AIR) {
|
||||
handleAirLeftClick(event);
|
||||
} else if (event.getAction() == Action.PHYSICAL) {
|
||||
handlePhysicalInteract(event);
|
||||
}
|
||||
@ -523,115 +480,6 @@ public void onPlayerInteract(PlayerInteractEvent event) {
|
||||
player.sendMessage(ChatColor.RED + "Infinite stack removed.");
|
||||
}
|
||||
}
|
||||
|
||||
if (item != null) {
|
||||
Events.fireItemEventToCancel(event, new ItemInteractEvent(event, Causes.create(event.getPlayer()), Interaction.INTERACT, world, item));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when a player left clicks air.
|
||||
*
|
||||
* @param event Thrown event
|
||||
*/
|
||||
private void handleAirLeftClick(PlayerInteractEvent event) {
|
||||
// I don't think we have to do anything here yet.
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when a player left clicks a block.
|
||||
*
|
||||
* @param event Thrown event
|
||||
*/
|
||||
private void handleBlockLeftClick(PlayerInteractEvent event) {
|
||||
if (event.isCancelled()) return;
|
||||
|
||||
Player player = event.getPlayer();
|
||||
Block block = event.getClickedBlock();
|
||||
int type = block.getTypeId();
|
||||
World world = player.getWorld();
|
||||
|
||||
ConfigurationManager cfg = plugin.getGlobalStateManager();
|
||||
WorldConfiguration wcfg = cfg.get(world);
|
||||
|
||||
if (wcfg.useRegions) {
|
||||
Vector pt = toVector(block);
|
||||
RegionManager mgr = plugin.getGlobalRegionManager().get(world);
|
||||
ApplicableRegionSet set = mgr.getApplicableRegions(pt);
|
||||
LocalPlayer localPlayer = plugin.wrapPlayer(player);
|
||||
|
||||
/*if (type == BlockID.STONE_BUTTON
|
||||
|| type == BlockID.LEVER
|
||||
|| type == BlockID.WOODEN_DOOR
|
||||
|| type == BlockID.TRAP_DOOR
|
||||
|| type == BlockID.NOTE_BLOCK) {
|
||||
if (!plugin.getGlobalRegionManager().hasBypass(player, world)
|
||||
&& !set.allows(DefaultFlag.USE, localPlayer)
|
||||
&& !set.canBuild(localPlayer)) {
|
||||
player.sendMessage(ChatColor.DARK_RED + "You don't have permission to use that in this area.");
|
||||
event.setUseInteractedBlock(Result.DENY);
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
}*/
|
||||
|
||||
if (type == BlockID.DRAGON_EGG) {
|
||||
if (!plugin.getGlobalRegionManager().hasBypass(player, world)
|
||||
&& !set.canBuild(localPlayer)) {
|
||||
player.sendMessage(ChatColor.DARK_RED + "You're not allowed to move dragon eggs here!");
|
||||
event.setUseInteractedBlock(Result.DENY);
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (block.getRelative(event.getBlockFace()).getTypeId() == BlockID.FIRE) {
|
||||
if (!plugin.getGlobalRegionManager().hasBypass(player, world)
|
||||
&& !mgr.getApplicableRegions(block.getRelative(event.getBlockFace())
|
||||
.getLocation()).canBuild(localPlayer)) {
|
||||
event.setUseInteractedBlock(Result.DENY);
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if (type == BlockID.TNT && player.getItemInHand().getTypeId() == ItemID.FLINT_AND_TINDER) {
|
||||
if (wcfg.getBlacklist() != null) {
|
||||
if (!wcfg.getBlacklist().check(
|
||||
new BlockBreakBlacklistEvent(plugin.wrapPlayer(player), toVector(event.getClickedBlock()), createTarget(event.getClickedBlock())), false, false)) {
|
||||
event.setUseInteractedBlock(Result.DENY);
|
||||
event.setUseItemInHand(Result.DENY);
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when a player right clicks air.
|
||||
*
|
||||
* @param event Thrown event
|
||||
*/
|
||||
private void handleAirRightClick(PlayerInteractEvent event) {
|
||||
Player player = event.getPlayer();
|
||||
World world = player.getWorld();
|
||||
ItemStack item = player.getItemInHand();
|
||||
|
||||
ConfigurationManager cfg = plugin.getGlobalStateManager();
|
||||
WorldConfiguration wcfg = cfg.get(world);
|
||||
|
||||
if (wcfg.getBlacklist() != null) {
|
||||
if (!wcfg.getBlacklist().check(
|
||||
new ItemUseBlacklistEvent(plugin.wrapPlayer(player), toVector(player.getLocation()), createTarget(item)), false, false)) {
|
||||
event.setCancelled(true);
|
||||
event.setUseItemInHand(Result.DENY);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@ -699,396 +547,8 @@ private void handleBlockRightClick(PlayerInteractEvent event) {
|
||||
}
|
||||
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
|
||||
if (item.getTypeId() == BlockID.TNT) {
|
||||
// workaround for a bug that allowed tnt to trigger instantly if placed
|
||||
// next to redstone, without plugins getting the block place event
|
||||
// (not sure if this actually still happens)
|
||||
if (!plugin.getGlobalRegionManager().hasBypass(player, world)
|
||||
&& !placedInSet.allows(DefaultFlag.TNT, localPlayer)) {
|
||||
event.setUseItemInHand(Result.DENY);
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
|
||||
// hacky workaround for craftbukkit bug
|
||||
// has since been fixed, but leaving for legacy
|
||||
if (item.getTypeId() == BlockID.STEP
|
||||
|| item.getTypeId() == BlockID.WOODEN_STEP) {
|
||||
if (!plugin.getGlobalRegionManager().hasBypass(localPlayer, world)) {
|
||||
boolean cancel = false;
|
||||
if ((block.getTypeId() == item.getTypeId())
|
||||
&& !set.canBuild(localPlayer)) {
|
||||
// if we are on a step already, the new block will end up in the same block as the interact
|
||||
cancel = true;
|
||||
} else if (!placedInSet.canBuild(localPlayer)) {
|
||||
// if we are on another block, the half-slab in hand will be pushed to the adjacent block
|
||||
cancel = true;
|
||||
}
|
||||
if (cancel) {
|
||||
player.sendMessage(ChatColor.DARK_RED + "You don't have permission for this area.");
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (item.getTypeId() == ItemID.BED_ITEM) {
|
||||
// this is mojang-level code, it had better give us the right direction
|
||||
double yaw = (player.getLocation().getYaw() * 4.0F / 360.0F) + 0.5D;
|
||||
int i = (int) yaw;
|
||||
int i1 = (yaw < i ? i - 1 : i) & 3;
|
||||
byte b0 = 0;
|
||||
byte b1 = 0;
|
||||
if (i1 == 0) {
|
||||
b1 = 1;
|
||||
}
|
||||
if (i1 == 1) {
|
||||
b0 = -1;
|
||||
}
|
||||
if (i1 == 2) {
|
||||
b1 = -1;
|
||||
}
|
||||
if (i1 == 3) {
|
||||
b0 = 1;
|
||||
}
|
||||
// end mojang-level code
|
||||
Location headLoc = placedIn.getRelative(b0, 0, b1).getLocation();
|
||||
if (!plugin.getGlobalRegionManager().hasBypass(localPlayer, world)
|
||||
&& !mgr.getApplicableRegions(headLoc).canBuild(localPlayer)) {
|
||||
// note that normal block placement is handled later, this is just a workaround
|
||||
// for the location of the head block of the bed
|
||||
player.sendMessage(ChatColor.DARK_RED + "You don't have permission for this area.");
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (block.getTypeId() == BlockID.PISTON_MOVING_PIECE) {
|
||||
if (!plugin.getGlobalRegionManager().hasBypass(player, world)
|
||||
&& !set.canBuild(localPlayer)) {
|
||||
event.setUseInteractedBlock(Result.DENY);
|
||||
}
|
||||
}
|
||||
|
||||
if (item.getTypeId() == ItemID.WOODEN_DOOR_ITEM || item.getTypeId() == ItemID.IRON_DOOR_ITEM) {
|
||||
if (!plugin.getGlobalRegionManager().hasBypass(localPlayer, world)
|
||||
&& !placedInSet.canBuild(localPlayer)) {
|
||||
// note that normal block placement is handled later, this is just a workaround
|
||||
// for the location of the top block of the door
|
||||
player.sendMessage(ChatColor.DARK_RED + "You don't have permission for this area.");
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (item.getTypeId() == ItemID.FIRE_CHARGE || item.getTypeId() == ItemID.FLINT_AND_TINDER) {
|
||||
if (!plugin.getGlobalRegionManager().hasBypass(localPlayer, world)
|
||||
&& !plugin.canBuild(player, placedIn)
|
||||
&& !placedInSet.allows(DefaultFlag.LIGHTER)) {
|
||||
event.setCancelled(true);
|
||||
event.setUseItemInHand(Result.DENY);
|
||||
player.sendMessage(ChatColor.DARK_RED + "You're not allowed to use that here.");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (item.getTypeId() == ItemID.EYE_OF_ENDER && block.getTypeId() == BlockID.END_PORTAL_FRAME) {
|
||||
if (!plugin.getGlobalRegionManager().hasBypass(player, world)
|
||||
&& !set.canBuild(localPlayer)) {
|
||||
event.setCancelled(true);
|
||||
event.setUseItemInHand(Result.DENY);
|
||||
player.sendMessage(ChatColor.DARK_RED + "You're not allowed to use that here.");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (item.getTypeId() == ItemID.INK_SACK
|
||||
&& item.getData() != null) {
|
||||
if (item.getData().getData() == 15 // bonemeal
|
||||
&& (type == BlockID.GRASS
|
||||
|| type == BlockID.SAPLING
|
||||
|| type == BlockID.CROPS
|
||||
|| type == BlockID.BROWN_MUSHROOM
|
||||
|| type == BlockID.RED_MUSHROOM
|
||||
|| type == BlockID.PUMPKIN_STEM
|
||||
|| type == BlockID.MELON_STEM
|
||||
|| type == BlockID.POTATOES
|
||||
|| type == BlockID.CARROTS
|
||||
|| type == BlockID.COCOA_PLANT
|
||||
|| type == BlockID.LONG_GRASS)) {
|
||||
if (!plugin.getGlobalRegionManager().hasBypass(player, world)
|
||||
&& !set.canBuild(localPlayer)) {
|
||||
event.setCancelled(true);
|
||||
event.setUseItemInHand(Result.DENY);
|
||||
player.sendMessage(ChatColor.DARK_RED + "You're not allowed to use that here.");
|
||||
return;
|
||||
}
|
||||
} else if (item.getData().getData() == 3) { // cocoa beans
|
||||
// craftbukkit doesn't throw a block place for this, so workaround
|
||||
if (!plugin.getGlobalRegionManager().hasBypass(player, world)
|
||||
&& !set.canBuild(localPlayer)) {
|
||||
if (!(event.getBlockFace() == BlockFace.DOWN || event.getBlockFace() == BlockFace.UP)) {
|
||||
event.setCancelled(true);
|
||||
event.setUseItemInHand(Result.DENY);
|
||||
player.sendMessage(ChatColor.DARK_RED + "You're not allowed to plant that here.");
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (type == BlockID.FLOWER_POT) { // no api for this atm
|
||||
if (item.getTypeId() == BlockID.RED_FLOWER
|
||||
|| item.getTypeId() == BlockID.YELLOW_FLOWER
|
||||
|| item.getTypeId() == BlockID.SAPLING
|
||||
|| item.getTypeId() == BlockID.RED_MUSHROOM
|
||||
|| item.getTypeId() == BlockID.BROWN_MUSHROOM
|
||||
|| item.getTypeId() == BlockID.CACTUS
|
||||
|| item.getTypeId() == BlockID.LONG_GRASS
|
||||
|| item.getTypeId() == BlockID.DEAD_BUSH) {
|
||||
if (!plugin.getGlobalRegionManager().hasBypass(player, world)
|
||||
&& !set.canBuild(localPlayer)) {
|
||||
event.setUseItemInHand(Result.DENY);
|
||||
event.setCancelled(true);
|
||||
player.sendMessage(ChatColor.DARK_RED + "You're not allowed to plant that here.");
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (type == BlockID.BED) {
|
||||
if (!plugin.getGlobalRegionManager().hasBypass(player, world)
|
||||
&& !set.allows(DefaultFlag.SLEEP, localPlayer)) {
|
||||
player.sendMessage(ChatColor.DARK_RED + "You're not allowed to use that bed.");
|
||||
event.setUseInteractedBlock(Result.DENY);
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (type == BlockID.CHEST
|
||||
|| type == BlockID.JUKEBOX //stores the (arguably) most valuable item
|
||||
|| type == BlockID.DISPENSER
|
||||
|| type == BlockID.FURNACE
|
||||
|| type == BlockID.BURNING_FURNACE
|
||||
|| type == BlockID.BREWING_STAND
|
||||
|| type == BlockID.TRAPPED_CHEST
|
||||
|| type == BlockID.HOPPER
|
||||
|| type == BlockID.DROPPER) {
|
||||
if (!plugin.getGlobalRegionManager().hasBypass(player, world)
|
||||
&& !set.canBuild(localPlayer)
|
||||
&& !set.allows(DefaultFlag.CHEST_ACCESS, localPlayer)) {
|
||||
player.sendMessage(ChatColor.DARK_RED + "You don't have permission to open that in this area.");
|
||||
event.setUseInteractedBlock(Result.DENY);
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (type == BlockID.DRAGON_EGG) {
|
||||
if (!plugin.getGlobalRegionManager().hasBypass(player, world)
|
||||
&& !set.canBuild(localPlayer)) {
|
||||
player.sendMessage(ChatColor.DARK_RED + "You're not allowed to move dragon eggs here!");
|
||||
event.setUseInteractedBlock(Result.DENY);
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (type == BlockID.LEVER
|
||||
|| type == BlockID.STONE_BUTTON
|
||||
|| type == BlockID.WOODEN_BUTTON
|
||||
|| type == BlockID.NOTE_BLOCK
|
||||
|| type == BlockID.REDSTONE_REPEATER_OFF
|
||||
|| type == BlockID.REDSTONE_REPEATER_ON
|
||||
|| type == BlockID.WOODEN_DOOR
|
||||
|| type == BlockID.TRAP_DOOR
|
||||
|| type == BlockID.FENCE_GATE
|
||||
|| type == BlockID.JUKEBOX //stores the (arguably) most valuable item
|
||||
|| type == BlockID.DISPENSER
|
||||
|| type == BlockID.FURNACE
|
||||
|| type == BlockID.BURNING_FURNACE
|
||||
|| type == BlockID.WORKBENCH
|
||||
|| type == BlockID.BREWING_STAND
|
||||
|| type == BlockID.ENCHANTMENT_TABLE
|
||||
|| type == BlockID.CAULDRON
|
||||
|| type == BlockID.ENDER_CHEST // blah
|
||||
|| type == BlockID.BEACON
|
||||
|| type == BlockID.ANVIL
|
||||
|| type == BlockID.HOPPER
|
||||
|| type == BlockID.DROPPER) {
|
||||
if (!plugin.getGlobalRegionManager().hasBypass(player, world)
|
||||
&& !set.canBuild(localPlayer)
|
||||
&& !set.allows(DefaultFlag.USE, localPlayer)) {
|
||||
player.sendMessage(ChatColor.DARK_RED + "You don't have permission to use that in this area.");
|
||||
event.setUseInteractedBlock(Result.DENY);
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (type == BlockID.REDSTONE_REPEATER_OFF
|
||||
|| type == BlockID.REDSTONE_REPEATER_ON
|
||||
|| type == BlockID.COMPARATOR_OFF
|
||||
|| type == BlockID.COMPARATOR_ON) {
|
||||
if (!plugin.getGlobalRegionManager().hasBypass(player, world)
|
||||
&& !set.canBuild(localPlayer)) {
|
||||
// using build and not use because it can potentially damage a circuit and use is more general-purposed
|
||||
player.sendMessage(ChatColor.DARK_RED + "You don't have permission to use that in this area.");
|
||||
event.setUseInteractedBlock(Result.DENY);
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (type == BlockID.CAKE_BLOCK) {
|
||||
if (!plugin.getGlobalRegionManager().hasBypass(player, world)
|
||||
&& !set.canBuild(localPlayer)
|
||||
&& !set.allows(DefaultFlag.USE, localPlayer)) {
|
||||
player.sendMessage(ChatColor.DARK_RED + "You're not invited to this tea party!");
|
||||
event.setUseInteractedBlock(Result.DENY);
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (BlockType.isRailBlock(type)
|
||||
&& (item.getTypeId() == ItemID.MINECART
|
||||
|| item.getTypeId() == ItemID.POWERED_MINECART
|
||||
|| item.getTypeId() == ItemID.STORAGE_MINECART
|
||||
|| item.getTypeId() == ItemID.TNT_MINECART
|
||||
|| item.getTypeId() == ItemID.HOPPER_MINECART)) {
|
||||
if (!plugin.getGlobalRegionManager().hasBypass(player, world)
|
||||
&& !placedInSet.canBuild(localPlayer)
|
||||
&& !placedInSet.allows(DefaultFlag.PLACE_VEHICLE, localPlayer)) {
|
||||
player.sendMessage(ChatColor.DARK_RED + "You don't have permission to place vehicles here.");
|
||||
event.setUseItemInHand(Result.DENY);
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (item.getTypeId() == ItemID.WOOD_BOAT) {
|
||||
if (!plugin.getGlobalRegionManager().hasBypass(player, world)
|
||||
&& !placedInSet.canBuild(localPlayer)
|
||||
&& !placedInSet.allows(DefaultFlag.PLACE_VEHICLE, localPlayer)) {
|
||||
player.sendMessage(ChatColor.DARK_RED + "You don't have permission to place vehicles here.");
|
||||
event.setUseItemInHand(Result.DENY);
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (wcfg.getBlacklist() != null) {
|
||||
if (player.isSneaking() // sneak + right clicking no longer opens guis as of some recent version
|
||||
|| (type != BlockID.CHEST
|
||||
&& type != BlockID.DISPENSER
|
||||
&& type != BlockID.FURNACE
|
||||
&& type != BlockID.BURNING_FURNACE
|
||||
&& type != BlockID.BREWING_STAND
|
||||
&& type != BlockID.ENCHANTMENT_TABLE
|
||||
&& type != BlockID.ANVIL
|
||||
&& type != BlockID.ENDER_CHEST
|
||||
&& type != BlockID.TRAPPED_CHEST
|
||||
&& type != BlockID.HOPPER
|
||||
&& type != BlockID.DROPPER)) {
|
||||
if (!wcfg.getBlacklist().check(
|
||||
new ItemUseBlacklistEvent(plugin.wrapPlayer(player), toVector(block), createTarget(item)), false, false)) {
|
||||
event.setUseItemInHand(Result.DENY);
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (!wcfg.getBlacklist().check(
|
||||
new BlockInteractBlacklistEvent(plugin.wrapPlayer(player), toVector(block), createTarget(block)), false, false)) {
|
||||
event.setUseInteractedBlock(Result.DENY);
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
|
||||
// Workaround for http://leaky.bukkit.org/issues/1034
|
||||
if (item.getTypeId() == BlockID.TNT) {
|
||||
Block placedOn = block.getRelative(event.getBlockFace());
|
||||
if (!wcfg.getBlacklist().check(
|
||||
new BlockPlaceBlacklistEvent(plugin.wrapPlayer(player), toVector(placedOn), createTarget(item)), false, false)) {
|
||||
event.setUseItemInHand(Result.DENY);
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ((type == BlockID.CHEST
|
||||
|| type == BlockID.DISPENSER
|
||||
|| type == BlockID.FURNACE
|
||||
|| type == BlockID.BURNING_FURNACE
|
||||
|| type == BlockID.ENCHANTMENT_TABLE
|
||||
|| type == BlockID.BREWING_STAND
|
||||
|| type == BlockID.TRAPPED_CHEST
|
||||
|| type == BlockID.HOPPER
|
||||
|| type == BlockID.DROPPER)) {
|
||||
|
||||
if (wcfg.isChestProtected(block, player)) {
|
||||
player.sendMessage(ChatColor.DARK_RED + "The chest is protected.");
|
||||
event.setUseInteractedBlock(Result.DENY);
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
/*if (wcfg.useRegions && wcfg.useiConomy && cfg.getiConomy() != null
|
||||
&& (type == BlockID.SIGN_POST || type == ItemID.SIGN || type == BlockID.WALL_SIGN)) {
|
||||
BlockState block = blockClicked.getState();
|
||||
|
||||
if (((Sign)block).getLine(0).equalsIgnoreCase("[WorldGuard]")
|
||||
&& ((Sign)block).getLine(1).equalsIgnoreCase("For sale")) {
|
||||
String regionId = ((Sign)block).getLine(2);
|
||||
//String regionComment = ((Sign)block).getLine(3);
|
||||
|
||||
if (regionId != null && regionId != "") {
|
||||
RegionManager mgr = cfg.getWorldGuardPlugin().getGlobalRegionManager().get(player.getWorld().getName());
|
||||
ProtectedRegion region = mgr.getRegion(regionId);
|
||||
|
||||
if (region != null) {
|
||||
RegionFlags flags = region.getFlags();
|
||||
|
||||
if (flags.getBooleanFlag(DefaultFlag.BUYABLE).getValue(false)) {
|
||||
if (iConomy.getBank().hasAccount(player.getName())) {
|
||||
Account account = iConomy.getBank().getAccount(player.getName());
|
||||
double balance = account.getBalance();
|
||||
double regionPrice = flags.getDoubleFlag(DefaultFlag.PRICE).getValue();
|
||||
|
||||
if (balance >= regionPrice) {
|
||||
account.subtract(regionPrice);
|
||||
player.sendMessage(ChatColor.YELLOW + "You have bought the region " + regionId + " for " +
|
||||
iConomy.getBank().format(regionPrice));
|
||||
DefaultDomain owners = region.getOwners();
|
||||
owners.addPlayer(player.getName());
|
||||
region.setOwners(owners);
|
||||
flags.getBooleanFlag(DefaultFlag.BUYABLE).setValue(false);
|
||||
account.save();
|
||||
} else {
|
||||
player.sendMessage(ChatColor.YELLOW + "You have not enough money.");
|
||||
}
|
||||
} else {
|
||||
player.sendMessage(ChatColor.YELLOW + "You have not enough money.");
|
||||
}
|
||||
} else {
|
||||
player.sendMessage(ChatColor.RED + "Region: " + regionId + " is not buyable");
|
||||
}
|
||||
} else {
|
||||
player.sendMessage(ChatColor.DARK_RED + "The region " + regionId + " does not exist.");
|
||||
}
|
||||
} else {
|
||||
player.sendMessage(ChatColor.DARK_RED + "No region specified.");
|
||||
}
|
||||
}
|
||||
}*/
|
||||
}
|
||||
|
||||
/**
|
||||
@ -1111,94 +571,8 @@ private void handlePhysicalInteract(PlayerInteractEvent event) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
|
||||
if (wcfg.useRegions) {
|
||||
Vector pt = toVector(block);
|
||||
RegionManager mgr = plugin.getGlobalRegionManager().get(world);
|
||||
ApplicableRegionSet set = mgr.getApplicableRegions(pt);
|
||||
LocalPlayer localPlayer = plugin.wrapPlayer(player);
|
||||
|
||||
if (type == BlockID.STONE_PRESSURE_PLATE || type == BlockID.WOODEN_PRESSURE_PLATE
|
||||
|| type == BlockID.TRIPWIRE || type == BlockID.PRESSURE_PLATE_LIGHT
|
||||
|| type == BlockID.PRESSURE_PLATE_HEAVY) {
|
||||
if (!plugin.getGlobalRegionManager().hasBypass(player, world)
|
||||
&& !set.canBuild(localPlayer)
|
||||
&& !set.allows(DefaultFlag.USE, localPlayer)) {
|
||||
event.setUseInteractedBlock(Result.DENY);
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when a player uses an item.
|
||||
*//*
|
||||
@Override
|
||||
public void onPlayerItem(PlayerItemEvent event) {
|
||||
|
||||
if (event.isCancelled()) {
|
||||
return;
|
||||
}
|
||||
|
||||
Player player = event.getPlayer();
|
||||
Block block = event.getBlockClicked();
|
||||
ItemStack item = event.getItem();
|
||||
int itemId = item.getTypeId();
|
||||
|
||||
GlobalConfiguration cfg = plugin.getGlobalConfiguration();
|
||||
WorldConfiguration wcfg = cfg.getWorldConfig(player.getWorld().getName());
|
||||
|
||||
if (wcfg.useRegions
|
||||
&& (itemId == 322 || itemId == 320 || itemId == 319 || itemId == 297 || itemId == 260
|
||||
|| itemId == 350 || itemId == 349 || itemId == 354) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!wcfg.itemDurability) {
|
||||
// Hoes
|
||||
if (item.getTypeId() >= 290 && item.getTypeId() <= 294) {
|
||||
item.setDurability((byte) -1);
|
||||
player.setItemInHand(item);
|
||||
}
|
||||
}
|
||||
|
||||
if (wcfg.useRegions && !event.isBlock() && block != null) {
|
||||
Vector pt = toVector(block.getRelative(event.getBlockFace()));
|
||||
if (block.getTypeId() == BlockID.WALL_SIGN) {
|
||||
pt = pt.subtract(0, 1, 0);
|
||||
}
|
||||
|
||||
if (!cfg.canBuild(player, pt)) {
|
||||
player.sendMessage(ChatColor.DARK_RED
|
||||
+ "You don't have permission for this area.");
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (wcfg.getBlacklist() != null && item != null && block != null) {
|
||||
if (!wcfg.getBlacklist().check(
|
||||
new ItemUseBlacklistEvent(plugin.wrapPlayer(player),
|
||||
toVector(block.getRelative(event.getBlockFace())),
|
||||
item.getTypeId()), false, false)) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (wcfg.useRegions && item != null && block != null && item.getTypeId() == 259) {
|
||||
Vector pt = toVector(block.getRelative(event.getBlockFace()));
|
||||
RegionManager mgr = plugin.getGlobalRegionManager().get(player.getWorld().getName());
|
||||
|
||||
if (!mgr.getApplicableRegions(pt).isStateFlagAllowed(DefaultFlag.LIGHTER)) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}*/
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
|
||||
public void onPlayerDropItem(PlayerDropItemEvent event) {
|
||||
ConfigurationManager cfg = plugin.getGlobalStateManager();
|
||||
@ -1212,61 +586,6 @@ public void onPlayerDropItem(PlayerDropItemEvent event) {
|
||||
player.sendMessage(ChatColor.RED + "You don't have permission to do that in this area.");
|
||||
}
|
||||
}
|
||||
|
||||
if (wcfg.getBlacklist() != null) {
|
||||
Item ci = event.getItemDrop();
|
||||
|
||||
if (!wcfg.getBlacklist().check(
|
||||
new ItemDropBlacklistEvent(plugin.wrapPlayer(event.getPlayer()),
|
||||
toVector(ci.getLocation()), createTarget(ci.getItemStack())), false, false)) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
|
||||
public void onPlayerPickupItem(PlayerPickupItemEvent event) {
|
||||
ConfigurationManager cfg = plugin.getGlobalStateManager();
|
||||
WorldConfiguration wcfg = cfg.get(event.getPlayer().getWorld());
|
||||
|
||||
if (wcfg.getBlacklist() != null) {
|
||||
Item ci = event.getItem();
|
||||
|
||||
if (!wcfg.getBlacklist().check(
|
||||
new ItemAcquireBlacklistEvent(plugin.wrapPlayer(event.getPlayer()),
|
||||
toVector(ci.getLocation()), createTarget(ci.getItemStack())), false, true)) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
|
||||
public void onPlayerBucketFill(PlayerBucketFillEvent event) {
|
||||
Player player = event.getPlayer();
|
||||
World world = player.getWorld();
|
||||
|
||||
ConfigurationManager cfg = plugin.getGlobalStateManager();
|
||||
WorldConfiguration wcfg = cfg.get(world);
|
||||
|
||||
if (!plugin.getGlobalRegionManager().canBuild(
|
||||
player, event.getBlockClicked().getRelative(event.getBlockFace()))
|
||||
&& !(event.getItemStack().getTypeId() == ItemID.MILK_BUCKET)) {
|
||||
player.sendMessage(ChatColor.DARK_RED + "You don't have permission for this area.");
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
|
||||
if (wcfg.getBlacklist() != null) {
|
||||
if (!wcfg.getBlacklist().check(
|
||||
new ItemUseBlacklistEvent(plugin.wrapPlayer(player),
|
||||
toVector(player.getLocation()), createTarget(event.getBucket())), false, false)) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
|
||||
@ -1279,31 +598,6 @@ public void onPlayerFish(PlayerFishEvent event) {
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
|
||||
public void onPlayerBucketEmpty(PlayerBucketEmptyEvent event) {
|
||||
Player player = event.getPlayer();
|
||||
World world = player.getWorld();
|
||||
|
||||
ConfigurationManager cfg = plugin.getGlobalStateManager();
|
||||
WorldConfiguration wcfg = cfg.get(world);
|
||||
|
||||
if (!plugin.getGlobalRegionManager().canBuild(
|
||||
player, event.getBlockClicked().getRelative(event.getBlockFace()))) {
|
||||
player.sendMessage(ChatColor.DARK_RED + "You don't have permission for this area.");
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
|
||||
if (wcfg.getBlacklist() != null) {
|
||||
if (!wcfg.getBlacklist().check(
|
||||
new ItemUseBlacklistEvent(plugin.wrapPlayer(player),
|
||||
toVector(player.getLocation()), createTarget(event.getBucket())), false, false)) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGHEST)
|
||||
public void onPlayerRespawn(PlayerRespawnEvent event) {
|
||||
Player player = event.getPlayer();
|
||||
|
@ -19,22 +19,12 @@
|
||||
|
||||
package com.sk89q.worldguard.bukkit;
|
||||
|
||||
import static com.sk89q.worldguard.bukkit.BukkitUtil.toVector;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.entity.Vehicle;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.vehicle.VehicleDestroyEvent;
|
||||
import org.bukkit.event.vehicle.VehicleMoveEvent;
|
||||
import com.sk89q.worldedit.Vector;
|
||||
import com.sk89q.worldguard.LocalPlayer;
|
||||
import com.sk89q.worldguard.protection.ApplicableRegionSet;
|
||||
import com.sk89q.worldguard.protection.flags.DefaultFlag;
|
||||
import com.sk89q.worldguard.protection.managers.RegionManager;
|
||||
|
||||
public class WorldGuardVehicleListener implements Listener {
|
||||
|
||||
@ -56,34 +46,6 @@ public void registerEvents() {
|
||||
plugin.getServer().getPluginManager().registerEvents(this, plugin);
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onVehicleDestroy(VehicleDestroyEvent event) {
|
||||
Vehicle vehicle = event.getVehicle();
|
||||
Entity destroyer = event.getAttacker();
|
||||
|
||||
if (!(destroyer instanceof Player)) return; // don't care
|
||||
Player player = (Player) destroyer;
|
||||
World world = vehicle.getWorld();
|
||||
|
||||
ConfigurationManager cfg = plugin.getGlobalStateManager();
|
||||
WorldConfiguration wcfg = cfg.get(world);
|
||||
|
||||
if (wcfg.useRegions) {
|
||||
Vector pt = toVector(vehicle.getLocation());
|
||||
RegionManager mgr = plugin.getGlobalRegionManager().get(world);
|
||||
ApplicableRegionSet set = mgr.getApplicableRegions(pt);
|
||||
LocalPlayer localPlayer = plugin.wrapPlayer(player);
|
||||
|
||||
if (!plugin.getGlobalRegionManager().hasBypass(player, world)
|
||||
&& !set.canBuild(localPlayer)
|
||||
&& !set.allows(DefaultFlag.DESTROY_VEHICLE, localPlayer)) {
|
||||
player.sendMessage(ChatColor.DARK_RED + "You don't have permission to destroy vehicles here.");
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onVehicleMove(VehicleMoveEvent event) {
|
||||
Vehicle vehicle = event.getVehicle();
|
||||
|
@ -0,0 +1,490 @@
|
||||
/*
|
||||
* 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.listener;
|
||||
|
||||
import com.sk89q.worldguard.bukkit.WorldGuardPlugin;
|
||||
import com.sk89q.worldguard.bukkit.util.Blocks;
|
||||
import com.sk89q.worldguard.bukkit.util.Materials;
|
||||
import com.sk89q.worldguard.internal.Events;
|
||||
import com.sk89q.worldguard.internal.cause.Cause;
|
||||
import com.sk89q.worldguard.internal.cause.Causes;
|
||||
import com.sk89q.worldguard.internal.event.block.BreakBlockEvent;
|
||||
import com.sk89q.worldguard.internal.event.block.PlaceBlockEvent;
|
||||
import com.sk89q.worldguard.internal.event.block.UseBlockEvent;
|
||||
import com.sk89q.worldguard.internal.event.entity.DestroyEntityEvent;
|
||||
import com.sk89q.worldguard.internal.event.entity.SpawnEntityEvent;
|
||||
import com.sk89q.worldguard.internal.event.entity.UseEntityEvent;
|
||||
import com.sk89q.worldguard.internal.event.inventory.UseItemEvent;
|
||||
import org.bukkit.DyeColor;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.BlockFace;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.entity.LivingEntity;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.entity.ThrownPotion;
|
||||
import org.bukkit.event.Event.Result;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.block.Action;
|
||||
import org.bukkit.event.block.BlockBreakEvent;
|
||||
import org.bukkit.event.block.BlockBurnEvent;
|
||||
import org.bukkit.event.block.BlockDamageEvent;
|
||||
import org.bukkit.event.block.BlockDispenseEvent;
|
||||
import org.bukkit.event.block.BlockFromToEvent;
|
||||
import org.bukkit.event.block.BlockIgniteEvent;
|
||||
import org.bukkit.event.block.BlockIgniteEvent.IgniteCause;
|
||||
import org.bukkit.event.block.BlockPlaceEvent;
|
||||
import org.bukkit.event.block.SignChangeEvent;
|
||||
import org.bukkit.event.entity.EntityChangeBlockEvent;
|
||||
import org.bukkit.event.entity.EntityCombustByBlockEvent;
|
||||
import org.bukkit.event.entity.EntityCombustByEntityEvent;
|
||||
import org.bukkit.event.entity.EntityCombustEvent;
|
||||
import org.bukkit.event.entity.EntityDamageByBlockEvent;
|
||||
import org.bukkit.event.entity.EntityDamageByEntityEvent;
|
||||
import org.bukkit.event.entity.EntityDamageEvent;
|
||||
import org.bukkit.event.entity.EntityTameEvent;
|
||||
import org.bukkit.event.entity.EntityUnleashEvent;
|
||||
import org.bukkit.event.entity.PotionSplashEvent;
|
||||
import org.bukkit.event.hanging.HangingBreakByEntityEvent;
|
||||
import org.bukkit.event.hanging.HangingBreakEvent;
|
||||
import org.bukkit.event.hanging.HangingPlaceEvent;
|
||||
import org.bukkit.event.player.PlayerBedEnterEvent;
|
||||
import org.bukkit.event.player.PlayerBucketEmptyEvent;
|
||||
import org.bukkit.event.player.PlayerBucketFillEvent;
|
||||
import org.bukkit.event.player.PlayerDropItemEvent;
|
||||
import org.bukkit.event.player.PlayerInteractEntityEvent;
|
||||
import org.bukkit.event.player.PlayerInteractEvent;
|
||||
import org.bukkit.event.player.PlayerPickupItemEvent;
|
||||
import org.bukkit.event.player.PlayerShearEntityEvent;
|
||||
import org.bukkit.event.player.PlayerUnleashEntityEvent;
|
||||
import org.bukkit.event.vehicle.VehicleDamageEvent;
|
||||
import org.bukkit.event.vehicle.VehicleDestroyEvent;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import static com.sk89q.worldguard.bukkit.util.Materials.isBlockModifiedOnClick;
|
||||
import static com.sk89q.worldguard.bukkit.util.Materials.isItemAppliedToBlock;
|
||||
import static com.sk89q.worldguard.internal.cause.Causes.create;
|
||||
|
||||
public class CauseListener implements Listener {
|
||||
|
||||
private final WorldGuardPlugin plugin;
|
||||
|
||||
public CauseListener(WorldGuardPlugin plugin) {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
public void registerEvents() {
|
||||
plugin.getServer().getPluginManager().registerEvents(this, plugin);
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
// Block break / place
|
||||
//-------------------------------------------------------------------------
|
||||
|
||||
@EventHandler
|
||||
public void onBlockBreak(BlockBreakEvent event) {
|
||||
Events.fireToCancel(event, new BreakBlockEvent(event, create(event.getPlayer()), event.getBlock()));
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onBlockPlace(BlockPlaceEvent event) {
|
||||
Events.fireToCancel(event, new UseBlockEvent(event, create(event.getPlayer()), event.getBlock()));
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onBlockBurn(BlockBurnEvent event) {
|
||||
Events.fireToCancel(event, new UseBlockEvent(event, Collections.<Cause<?>>emptyList(), event.getBlock()));
|
||||
}
|
||||
|
||||
// TODO: Handle EntityCreatePortalEvent?
|
||||
|
||||
@EventHandler
|
||||
public void onEntityChangeBlock(EntityChangeBlockEvent event) {
|
||||
// Fire two events: one as BREAK and one as PLACE
|
||||
if (event.getTo() != Material.AIR && event.getBlock().getType() != Material.AIR) {
|
||||
Events.fireToCancel(event, new BreakBlockEvent(event, create(event.getEntity()), event.getBlock()));
|
||||
Events.fireToCancel(event, new PlaceBlockEvent(event, create(event.getEntity()), event.getBlock()));
|
||||
} else {
|
||||
if (event.getTo() == Material.AIR) {
|
||||
Events.fireToCancel(event, new BreakBlockEvent(event, create(event.getEntity()), event.getBlock()));
|
||||
} else {
|
||||
Events.fireToCancel(event, new PlaceBlockEvent(event, create(event.getEntity()), event.getBlock()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: Handle pistons
|
||||
// TODO: Handle EntityExplodeEvent
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
// Block external interaction
|
||||
//-------------------------------------------------------------------------
|
||||
|
||||
@EventHandler
|
||||
public void onBlockDamage(BlockDamageEvent event) {
|
||||
Block target = event.getBlock();
|
||||
|
||||
// Previously, and perhaps still, the only way to catch cake eating
|
||||
// events was through here
|
||||
if (target.getType() == Material.CAKE_BLOCK) {
|
||||
Events.fireToCancel(event, new UseBlockEvent(event, create(event.getPlayer()), target));
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerInteract(PlayerInteractEvent event) {
|
||||
Player player = event.getPlayer();
|
||||
@Nullable ItemStack item = player.getItemInHand();
|
||||
Block block = event.getClickedBlock();
|
||||
List<? extends Cause<?>> causes = create(player);
|
||||
|
||||
switch (event.getAction()) {
|
||||
case PHYSICAL:
|
||||
// TODO: Don't fire events for blocks that can't be interacted with using PHYSICAL
|
||||
if (Events.fireAndTestCancel(new UseBlockEvent(event, causes, block))) {
|
||||
event.setUseInteractedBlock(Result.DENY);
|
||||
event.setCancelled(true);
|
||||
}
|
||||
break;
|
||||
|
||||
case RIGHT_CLICK_BLOCK:
|
||||
if (item != null && item.getType() == Material.TNT) {
|
||||
// Workaround for a bug that allowed tnt to trigger instantly if placed
|
||||
// next to redstone, without plugins getting the block place event
|
||||
// (not sure if this actually still happens)
|
||||
Events.fireToCancel(event, new UseBlockEvent(event, create(event.getPlayer()), block.getLocation(), Material.TNT));
|
||||
}
|
||||
|
||||
// Handle created Minecarts
|
||||
if (item != null && Materials.isMinecart(item.getType())) {
|
||||
// TODO: Give a more specific minecart type
|
||||
Block placedBlock = block.getRelative(event.getBlockFace());
|
||||
Events.fireToCancel(event, new SpawnEntityEvent(event, create(event.getPlayer()), placedBlock.getLocation().add(0.5, 0, 0.5), EntityType.MINECART));
|
||||
}
|
||||
|
||||
// Handle cocoa beans
|
||||
if (item != null && item.getType() == Material.INK_SACK && Materials.isDyeColor(item.getData(), DyeColor.BROWN)) {
|
||||
// CraftBukkit doesn't or didn't throw a block place for this
|
||||
if (!(event.getBlockFace() == BlockFace.DOWN || event.getBlockFace() == BlockFace.UP)) {
|
||||
Block placedBlock = block.getRelative(event.getBlockFace());
|
||||
Events.fireToCancel(event, new PlaceBlockEvent(event, create(event.getPlayer()), placedBlock.getLocation(), Material.COCOA));
|
||||
}
|
||||
}
|
||||
|
||||
// Workaround for http://leaky.bukkit.org/issues/1034
|
||||
if (item != null && item.getType() == Material.TNT) {
|
||||
Block placedBlock = block.getRelative(event.getBlockFace());
|
||||
Events.fireToCancel(event, new PlaceBlockEvent(event, create(event.getPlayer()), placedBlock.getLocation(), Material.TNT));
|
||||
}
|
||||
|
||||
// Handle flint and steel and fire charge as fire place
|
||||
if (item != null && (item.getType() == Material.FIREBALL || item.getType() == Material.FLINT_AND_STEEL)) {
|
||||
Block placedBlock = block.getRelative(event.getBlockFace());
|
||||
if (!Events.fireAndTestCancel(new PlaceBlockEvent(event, create(event.getPlayer()), placedBlock.getLocation(), Material.FIRE))) {
|
||||
event.setUseItemInHand(Result.DENY);
|
||||
}
|
||||
}
|
||||
|
||||
case LEFT_CLICK_BLOCK:
|
||||
// TODO: Don't fire events for blocks that can't be interacted with using clicks
|
||||
|
||||
// As of MC ~1.6, sneaking blocks the use of blocks with right click
|
||||
if (!player.isSneaking() || event.getAction() == Action.LEFT_CLICK_BLOCK) {
|
||||
// Only fire events for blocks that are modified when right clicked
|
||||
if (isBlockModifiedOnClick(block.getType()) || (item != null && isItemAppliedToBlock(item.getType(), block.getType()))) {
|
||||
if (Events.fireAndTestCancel(new UseBlockEvent(event, causes, block))) {
|
||||
event.setUseInteractedBlock(Result.DENY);
|
||||
}
|
||||
|
||||
// Handle connected blocks (i.e. beds, chests)
|
||||
for (Block connected : Blocks.getConnected(block)) {
|
||||
if (Events.fireAndTestCancel(new UseBlockEvent(event, create(event.getPlayer()), connected))) {
|
||||
event.setUseInteractedBlock(Result.DENY);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Special handling of flint and steel on TNT
|
||||
if (block.getType() == Material.TNT && item != null && item.getType() == Material.FLINT_AND_STEEL) {
|
||||
if (Events.fireAndTestCancel(new BreakBlockEvent(event, create(event.getPlayer()), block))) {
|
||||
event.setUseInteractedBlock(Result.DENY);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Special handling of putting out fires
|
||||
if (event.getAction() == Action.LEFT_CLICK_BLOCK && block.getType() == Material.FIRE) {
|
||||
if (Events.fireAndTestCancel(new BreakBlockEvent(event, create(event.getPlayer()), block))) {
|
||||
event.setUseInteractedBlock(Result.DENY);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
case LEFT_CLICK_AIR:
|
||||
case RIGHT_CLICK_AIR:
|
||||
if (item != null && Events.fireAndTestCancel(new UseItemEvent(event, causes, player.getWorld(), item))) {
|
||||
event.setUseItemInHand(Result.DENY);
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onEntityInteract(org.bukkit.event.entity.EntityInteractEvent event) {
|
||||
Events.fireToCancel(event, new UseBlockEvent(event, create(event.getEntity()), event.getBlock()));
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onBlockIgnite(BlockIgniteEvent event) {
|
||||
List<? extends Cause<?>> causes;
|
||||
|
||||
// Find the cause
|
||||
if (event.getPlayer() != null) {
|
||||
causes = create(event.getPlayer());
|
||||
} else if (event.getIgnitingEntity() != null) {
|
||||
causes = create(event.getIgnitingEntity());
|
||||
} else if (event.getIgnitingBlock() != null) {
|
||||
causes = create(event.getIgnitingBlock());
|
||||
} else {
|
||||
causes = Collections.emptyList();
|
||||
}
|
||||
|
||||
Events.fireToCancel(event, new BreakBlockEvent(event, causes, event.getBlock()));
|
||||
|
||||
// This is also handled in the PlayerInteractEvent listener
|
||||
if (event.getCause() == IgniteCause.FLINT_AND_STEEL || event.getCause() == IgniteCause.FIREBALL) {
|
||||
// TODO: Test location of block
|
||||
Events.fireToCancel(event, new PlaceBlockEvent(event, causes, event.getBlock().getLocation(), Material.FIRE));
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onSignChange(SignChangeEvent event) {
|
||||
Events.fireToCancel(event, new UseBlockEvent(event, create(event.getPlayer()), event.getBlock()));
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onBedEnter(PlayerBedEnterEvent event) {
|
||||
Events.fireToCancel(event, new UseBlockEvent(event, create(event.getPlayer()), event.getBed()));
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerBucketEmpty(PlayerBucketEmptyEvent event) {
|
||||
Player player = event.getPlayer();
|
||||
Block blockAffected = event.getBlockClicked().getRelative(event.getBlockFace());
|
||||
|
||||
// Milk buckets can't be emptied as of writing
|
||||
if (event.getBucket() != Material.MILK_BUCKET) {
|
||||
ItemStack item = new ItemStack(event.getBucket(), 1);
|
||||
Events.fireToCancel(event, new PlaceBlockEvent(event, create(player), blockAffected));
|
||||
Events.fireToCancel(event, new UseItemEvent(event, create(player), player.getWorld(), item));
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerBucketFill(PlayerBucketFillEvent event) {
|
||||
Player player = event.getPlayer();
|
||||
Block blockAffected = event.getBlockClicked().getRelative(event.getBlockFace());
|
||||
|
||||
// Milk buckets can't be filled by right clicking the ground as of writing
|
||||
if (event.getBucket() != Material.MILK_BUCKET) {
|
||||
ItemStack item = new ItemStack(event.getBucket(), 1);
|
||||
Events.fireToCancel(event, new BreakBlockEvent(event, create(player), blockAffected));
|
||||
Events.fireToCancel(event, new UseItemEvent(event, create(player), player.getWorld(), item));
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: Handle EntityPortalEnterEvent
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
// Block self-interaction
|
||||
//-------------------------------------------------------------------------
|
||||
|
||||
@EventHandler
|
||||
public void onBlockFromTo(BlockFromToEvent event) {
|
||||
Events.fireToCancel(event, new PlaceBlockEvent(event, create(event.getBlock()), event.getToBlock()));
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
// Entity break / place
|
||||
//-------------------------------------------------------------------------
|
||||
|
||||
@EventHandler
|
||||
public void onHangingPlace(HangingPlaceEvent event) {
|
||||
Events.fireToCancel(event, new SpawnEntityEvent(event, create(event.getPlayer()), event.getEntity()));
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onHangingBreak(HangingBreakEvent event) {
|
||||
if (event instanceof HangingBreakByEntityEvent) {
|
||||
Events.fireToCancel(event, new DestroyEntityEvent(event, create(((HangingBreakByEntityEvent) event).getRemover()), event.getEntity()));
|
||||
} else {
|
||||
Events.fireToCancel(event, new DestroyEntityEvent(event, Collections.<Cause<?>>emptyList(), event.getEntity()));
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onVehicleDestroy(VehicleDestroyEvent event) {
|
||||
Events.fireToCancel(event, new DestroyEntityEvent(event, create(event.getAttacker()), event.getVehicle()));
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
// Entity external interaction
|
||||
//-------------------------------------------------------------------------
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerInteractEntity(PlayerInteractEntityEvent event) {
|
||||
Player player = event.getPlayer();
|
||||
World world = player.getWorld();
|
||||
ItemStack item = player.getItemInHand();
|
||||
Entity entity = event.getRightClicked();
|
||||
|
||||
Events.fireToCancel(event, new UseItemEvent(event, create(player), world, item));
|
||||
Events.fireToCancel(event, new UseEntityEvent(event, create(player), entity));
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onEntityDamage(EntityDamageEvent event) {
|
||||
if (event instanceof EntityDamageByBlockEvent) {
|
||||
Events.fireToCancel(event, new UseEntityEvent(event, create(((EntityDamageByBlockEvent) event).getDamager()), event.getEntity()));
|
||||
|
||||
} else if (event instanceof EntityDamageByEntityEvent) {
|
||||
EntityDamageByEntityEvent entityEvent = (EntityDamageByEntityEvent) event;
|
||||
Entity damager = entityEvent.getDamager();
|
||||
Events.fireToCancel(event, new UseEntityEvent(event, create(damager), event.getEntity()));
|
||||
|
||||
// Item use event with the item in hand
|
||||
// Older blacklist handler code used this, although it suffers from
|
||||
// race problems
|
||||
if (damager instanceof Player) {
|
||||
ItemStack item = ((Player) damager).getItemInHand();
|
||||
|
||||
if (item != null) {
|
||||
Events.fireToCancel(event, new UseItemEvent(event, create(damager), event.getEntity().getWorld(), item));
|
||||
}
|
||||
}
|
||||
|
||||
} else {
|
||||
Events.fireToCancel(event, new UseEntityEvent(event, Collections.<Cause<?>>emptyList(), event.getEntity()));
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onEntityCombust(EntityCombustEvent event) {
|
||||
if (event instanceof EntityCombustByBlockEvent) {
|
||||
Events.fireToCancel(event, new UseEntityEvent(event, create(((EntityCombustByBlockEvent) event).getCombuster()), event.getEntity()));
|
||||
|
||||
} else if (event instanceof EntityCombustByEntityEvent) {
|
||||
Events.fireToCancel(event, new UseEntityEvent(event, create(((EntityCombustByEntityEvent) event).getCombuster()), event.getEntity()));
|
||||
|
||||
} else {
|
||||
Events.fireToCancel(event, new UseEntityEvent(event, Collections.<Cause<?>>emptyList(), event.getEntity()));
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onEntityUnleash(EntityUnleashEvent event) {
|
||||
if (event instanceof PlayerUnleashEntityEvent) {
|
||||
PlayerUnleashEntityEvent playerEvent = (PlayerUnleashEntityEvent) event;
|
||||
Events.fireToCancel(playerEvent, new UseEntityEvent(playerEvent, create(playerEvent.getPlayer()), event.getEntity()));
|
||||
} else {
|
||||
// TODO: Raise anyway?
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onEntityTame(EntityTameEvent event) {
|
||||
Events.fireToCancel(event, new UseEntityEvent(event, create(event.getOwner()), event.getEntity()));
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerShearEntity(PlayerShearEntityEvent event) {
|
||||
Events.fireToCancel(event, new UseEntityEvent(event, create(event.getPlayer()), event.getEntity()));
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerPickupItem(PlayerPickupItemEvent event) {
|
||||
Events.fireToCancel(event, new DestroyEntityEvent(event, create(event.getPlayer()), event.getItem()));
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerDropItem(PlayerDropItemEvent event) {
|
||||
Events.fireToCancel(event, new SpawnEntityEvent(event, create(event.getPlayer()), event.getItemDrop()));
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onVehicleDamage(VehicleDamageEvent event) {
|
||||
Events.fireToCancel(event, new DestroyEntityEvent(event, create(event.getAttacker()), event.getVehicle()));
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onVehicleEnter(VehicleDamageEvent event) {
|
||||
Events.fireToCancel(event, new UseEntityEvent(event, create(event.getAttacker()), event.getVehicle()));
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
// Composite events
|
||||
//-------------------------------------------------------------------------
|
||||
|
||||
@EventHandler
|
||||
public void onPotionSplash(PotionSplashEvent event) {
|
||||
Entity entity = event.getEntity();
|
||||
ThrownPotion potion = event.getPotion();
|
||||
World world = entity.getWorld();
|
||||
List<? extends Cause<?>> causes = Causes.create(potion.getShooter());
|
||||
|
||||
// Fire item interaction event
|
||||
Events.fireToCancel(event, new UseItemEvent(event, causes, world, potion.getItem()));
|
||||
|
||||
// Fire entity interaction event
|
||||
if (!event.isCancelled()) {
|
||||
int blocked = 0;
|
||||
|
||||
for (LivingEntity affected : event.getAffectedEntities()) {
|
||||
if (Events.fireAndTestCancel(new UseEntityEvent(event, causes, affected))) {
|
||||
event.setIntensity(affected, 0);
|
||||
blocked++;
|
||||
}
|
||||
}
|
||||
|
||||
if (blocked == event.getAffectedEntities().size()) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onBlockDispense(BlockDispenseEvent event) {
|
||||
Events.fireToCancel(event, new UseItemEvent(event, create(event.getBlock()), event.getBlock().getWorld(), event.getItem()));
|
||||
}
|
||||
|
||||
// TODO: Inventory events?
|
||||
|
||||
}
|
@ -17,15 +17,34 @@
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.sk89q.worldguard.internal.event;
|
||||
package com.sk89q.worldguard.bukkit.util;
|
||||
|
||||
/**
|
||||
* Represents a possible act upon an object.
|
||||
*/
|
||||
public enum Interaction {
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.material.Bed;
|
||||
import org.bukkit.material.MaterialData;
|
||||
|
||||
PLACE,
|
||||
BREAK,
|
||||
INTERACT
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
public final class Blocks {
|
||||
|
||||
private Blocks() {
|
||||
}
|
||||
|
||||
public static List<Block> getConnected(Block block) {
|
||||
MaterialData data = block.getState().getData();
|
||||
|
||||
if (data instanceof Bed) {
|
||||
Bed bed = (Bed) data;
|
||||
if (bed.isHeadOfBed()) {
|
||||
return Arrays.asList(block.getRelative(bed.getFacing().getOppositeFace()));
|
||||
} else {
|
||||
return Arrays.asList(block.getRelative(bed.getFacing()));
|
||||
}
|
||||
} else {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,54 @@
|
||||
/*
|
||||
* 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 org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.LivingEntity;
|
||||
import org.bukkit.event.entity.EntityDamageEvent.DamageCause;
|
||||
|
||||
public final class DamageCauses {
|
||||
|
||||
private DamageCauses() {
|
||||
}
|
||||
|
||||
public static boolean isFire(DamageCause cause) {
|
||||
return cause == DamageCause.FIRE || cause == DamageCause.FIRE_TICK;
|
||||
}
|
||||
|
||||
public static boolean isExplosion(DamageCause cause) {
|
||||
return cause == DamageCause.BLOCK_EXPLOSION || cause == DamageCause.ENTITY_EXPLOSION;
|
||||
}
|
||||
|
||||
public static void restoreStatistic(Entity entity, DamageCause cause) {
|
||||
if (cause == DamageCause.DROWNING && entity instanceof LivingEntity) {
|
||||
LivingEntity living = (LivingEntity) entity;
|
||||
living.setRemainingAir(living.getMaximumAir());
|
||||
}
|
||||
|
||||
if (isFire(cause)) {
|
||||
entity.setFireTicks(0);
|
||||
}
|
||||
|
||||
if (cause == DamageCause.LAVA) {
|
||||
entity.setFireTicks(0);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
114
src/main/java/com/sk89q/worldguard/bukkit/util/Entities.java
Normal file
114
src/main/java/com/sk89q/worldguard/bukkit/util/Entities.java
Normal file
@ -0,0 +1,114 @@
|
||||
/*
|
||||
* 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 org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.entity.Projectile;
|
||||
import org.bukkit.entity.Tameable;
|
||||
import org.bukkit.projectiles.ProjectileSource;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
public final class Entities {
|
||||
|
||||
private Entities() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Test whether the given entity is tameable and tamed.
|
||||
*
|
||||
* @param entity the entity, or null
|
||||
* @return true if tamed
|
||||
*/
|
||||
public static boolean isTamed(@Nullable Entity entity) {
|
||||
return entity instanceof Tameable && ((Tameable) entity).isTamed();
|
||||
}
|
||||
|
||||
/**
|
||||
* Return if the given entity type is TNT-based.
|
||||
*
|
||||
* @param type the type
|
||||
* @return true if TNT based
|
||||
*/
|
||||
public static boolean isTNTBased(EntityType type) {
|
||||
return type == EntityType.PRIMED_TNT || type == EntityType.MINECART_TNT;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return if the given entity type is a fireball
|
||||
* (not including wither skulls).
|
||||
*
|
||||
* @param type the type
|
||||
* @return true if a fireball
|
||||
*/
|
||||
public static boolean isFireball(EntityType type) {
|
||||
return type == EntityType.FIREBALL || type == EntityType.SMALL_FIREBALL;
|
||||
}
|
||||
|
||||
/**
|
||||
* Test whether the given entity type is a vehicle type.
|
||||
*
|
||||
* @param type the type
|
||||
* @return true if the type is a vehicle type
|
||||
*/
|
||||
public static boolean isVehicle(EntityType type) {
|
||||
return type == EntityType.BOAT
|
||||
|| isMinecart(type);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test whether the given entity type is a Minecart type.
|
||||
*
|
||||
* @param type the type
|
||||
* @return true if the type is a Minecart type
|
||||
*/
|
||||
public static boolean isMinecart(EntityType type) {
|
||||
return type == EntityType.MINECART
|
||||
|| type == EntityType.MINECART_CHEST
|
||||
|| type == EntityType.MINECART_COMMAND
|
||||
|| type == EntityType.MINECART_FURNACE
|
||||
|| type == EntityType.MINECART_HOPPER
|
||||
|| type == EntityType.MINECART_MOB_SPAWNER
|
||||
|| type == EntityType.MINECART_TNT;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the underlying shooter of a projectile if one exists.
|
||||
*
|
||||
* @param entity the entity
|
||||
* @return the shooter
|
||||
*/
|
||||
public static Entity getShooter(Entity entity) {
|
||||
|
||||
while (entity instanceof Projectile) {
|
||||
Projectile projectile = (Projectile) entity;
|
||||
ProjectileSource remover = projectile.getShooter();
|
||||
if (remover instanceof Entity && remover != entity) {
|
||||
entity = (Entity) remover;
|
||||
} else {
|
||||
return entity;
|
||||
}
|
||||
}
|
||||
|
||||
return entity;
|
||||
}
|
||||
|
||||
}
|
563
src/main/java/com/sk89q/worldguard/bukkit/util/Materials.java
Normal file
563
src/main/java/com/sk89q/worldguard/bukkit/util/Materials.java
Normal file
@ -0,0 +1,563 @@
|
||||
/*
|
||||
* 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.google.common.collect.BiMap;
|
||||
import com.google.common.collect.HashBiMap;
|
||||
import org.bukkit.DyeColor;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.material.Dye;
|
||||
import org.bukkit.material.MaterialData;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Material utility class.
|
||||
*/
|
||||
public final class Materials {
|
||||
|
||||
private static final int MODIFED_ON_CLICK = 1;
|
||||
private static final int MODIFIES_BLOCKS = 1;
|
||||
|
||||
private static final BiMap<EntityType, Material> ENTITY_ITEMS = HashBiMap.create();
|
||||
private static final Map<Material, Integer> MATERIAL_FLAGS = new HashMap<Material, Integer>();
|
||||
|
||||
static {
|
||||
ENTITY_ITEMS.put(EntityType.PAINTING, Material.PAINTING);
|
||||
ENTITY_ITEMS.put(EntityType.ARROW, Material.ARROW);
|
||||
ENTITY_ITEMS.put(EntityType.SNOWBALL, Material.SNOW_BALL);
|
||||
ENTITY_ITEMS.put(EntityType.FIREBALL, Material.FIREBALL);
|
||||
ENTITY_ITEMS.put(EntityType.SMALL_FIREBALL, Material.FIREWORK_CHARGE);
|
||||
ENTITY_ITEMS.put(EntityType.ENDER_PEARL, Material.ENDER_PEARL);
|
||||
ENTITY_ITEMS.put(EntityType.THROWN_EXP_BOTTLE, Material.EXP_BOTTLE);
|
||||
ENTITY_ITEMS.put(EntityType.ITEM_FRAME, Material.ITEM_FRAME);
|
||||
ENTITY_ITEMS.put(EntityType.PRIMED_TNT, Material.TNT);
|
||||
ENTITY_ITEMS.put(EntityType.FIREWORK, Material.FIREWORK);
|
||||
ENTITY_ITEMS.put(EntityType.MINECART_COMMAND, Material.COMMAND_MINECART);
|
||||
ENTITY_ITEMS.put(EntityType.BOAT, Material.BOAT);
|
||||
ENTITY_ITEMS.put(EntityType.MINECART, Material.MINECART);
|
||||
ENTITY_ITEMS.put(EntityType.MINECART_CHEST, Material.STORAGE_MINECART);
|
||||
ENTITY_ITEMS.put(EntityType.MINECART_FURNACE, Material.POWERED_MINECART);
|
||||
ENTITY_ITEMS.put(EntityType.MINECART_TNT, Material.EXPLOSIVE_MINECART);
|
||||
ENTITY_ITEMS.put(EntityType.MINECART_HOPPER, Material.HOPPER_MINECART);
|
||||
ENTITY_ITEMS.put(EntityType.SPLASH_POTION, Material.POTION);
|
||||
ENTITY_ITEMS.put(EntityType.EGG, Material.EGG);
|
||||
|
||||
MATERIAL_FLAGS.put(Material.AIR, 0);
|
||||
MATERIAL_FLAGS.put(Material.STONE, 0);
|
||||
MATERIAL_FLAGS.put(Material.GRASS, 0);
|
||||
MATERIAL_FLAGS.put(Material.DIRT, 0);
|
||||
MATERIAL_FLAGS.put(Material.COBBLESTONE, 0);
|
||||
MATERIAL_FLAGS.put(Material.WOOD, 0);
|
||||
MATERIAL_FLAGS.put(Material.SAPLING, 0);
|
||||
MATERIAL_FLAGS.put(Material.BEDROCK, 0);
|
||||
MATERIAL_FLAGS.put(Material.WATER, 0);
|
||||
MATERIAL_FLAGS.put(Material.STATIONARY_WATER, 0);
|
||||
MATERIAL_FLAGS.put(Material.LAVA, 0);
|
||||
MATERIAL_FLAGS.put(Material.STATIONARY_LAVA, 0);
|
||||
MATERIAL_FLAGS.put(Material.SAND, 0);
|
||||
MATERIAL_FLAGS.put(Material.GRAVEL, 0);
|
||||
MATERIAL_FLAGS.put(Material.GOLD_ORE, 0);
|
||||
MATERIAL_FLAGS.put(Material.IRON_ORE, 0);
|
||||
MATERIAL_FLAGS.put(Material.COAL_ORE, 0);
|
||||
MATERIAL_FLAGS.put(Material.LOG, 0);
|
||||
MATERIAL_FLAGS.put(Material.LEAVES, 0);
|
||||
MATERIAL_FLAGS.put(Material.SPONGE, 0);
|
||||
MATERIAL_FLAGS.put(Material.GLASS, 0);
|
||||
MATERIAL_FLAGS.put(Material.LAPIS_ORE, 0);
|
||||
MATERIAL_FLAGS.put(Material.LAPIS_BLOCK, 0);
|
||||
MATERIAL_FLAGS.put(Material.DISPENSER, MODIFED_ON_CLICK);
|
||||
MATERIAL_FLAGS.put(Material.SANDSTONE, 0);
|
||||
MATERIAL_FLAGS.put(Material.NOTE_BLOCK, MODIFED_ON_CLICK);
|
||||
MATERIAL_FLAGS.put(Material.BED_BLOCK, MODIFED_ON_CLICK);
|
||||
MATERIAL_FLAGS.put(Material.POWERED_RAIL, 0);
|
||||
MATERIAL_FLAGS.put(Material.DETECTOR_RAIL, 0);
|
||||
MATERIAL_FLAGS.put(Material.PISTON_STICKY_BASE, 0);
|
||||
MATERIAL_FLAGS.put(Material.WEB, 0);
|
||||
MATERIAL_FLAGS.put(Material.LONG_GRASS, 0);
|
||||
MATERIAL_FLAGS.put(Material.DEAD_BUSH, 0);
|
||||
MATERIAL_FLAGS.put(Material.PISTON_BASE, 0);
|
||||
MATERIAL_FLAGS.put(Material.PISTON_EXTENSION, 0);
|
||||
MATERIAL_FLAGS.put(Material.WOOL, 0);
|
||||
MATERIAL_FLAGS.put(Material.PISTON_MOVING_PIECE, 0);
|
||||
MATERIAL_FLAGS.put(Material.YELLOW_FLOWER, 0);
|
||||
MATERIAL_FLAGS.put(Material.RED_ROSE, 0);
|
||||
MATERIAL_FLAGS.put(Material.BROWN_MUSHROOM, 0);
|
||||
MATERIAL_FLAGS.put(Material.RED_MUSHROOM, 0);
|
||||
MATERIAL_FLAGS.put(Material.GOLD_BLOCK, 0);
|
||||
MATERIAL_FLAGS.put(Material.IRON_BLOCK, 0);
|
||||
MATERIAL_FLAGS.put(Material.DOUBLE_STEP, 0);
|
||||
MATERIAL_FLAGS.put(Material.STEP, 0);
|
||||
MATERIAL_FLAGS.put(Material.BRICK, 0);
|
||||
MATERIAL_FLAGS.put(Material.TNT, MODIFED_ON_CLICK);
|
||||
MATERIAL_FLAGS.put(Material.BOOKSHELF, 0);
|
||||
MATERIAL_FLAGS.put(Material.MOSSY_COBBLESTONE, 0);
|
||||
MATERIAL_FLAGS.put(Material.OBSIDIAN, 0);
|
||||
MATERIAL_FLAGS.put(Material.TORCH, 0);
|
||||
MATERIAL_FLAGS.put(Material.FIRE, 0);
|
||||
MATERIAL_FLAGS.put(Material.MOB_SPAWNER, 0);
|
||||
MATERIAL_FLAGS.put(Material.WOOD_STAIRS, 0);
|
||||
MATERIAL_FLAGS.put(Material.CHEST, MODIFED_ON_CLICK);
|
||||
MATERIAL_FLAGS.put(Material.REDSTONE_WIRE, 0);
|
||||
MATERIAL_FLAGS.put(Material.DIAMOND_ORE, 0);
|
||||
MATERIAL_FLAGS.put(Material.DIAMOND_BLOCK, 0);
|
||||
MATERIAL_FLAGS.put(Material.WORKBENCH, 0);
|
||||
MATERIAL_FLAGS.put(Material.CROPS, 0);
|
||||
MATERIAL_FLAGS.put(Material.SOIL, 0);
|
||||
MATERIAL_FLAGS.put(Material.FURNACE, MODIFED_ON_CLICK);
|
||||
MATERIAL_FLAGS.put(Material.BURNING_FURNACE, MODIFED_ON_CLICK);
|
||||
MATERIAL_FLAGS.put(Material.SIGN_POST, 0);
|
||||
MATERIAL_FLAGS.put(Material.WOODEN_DOOR, 0);
|
||||
MATERIAL_FLAGS.put(Material.LADDER, 0);
|
||||
MATERIAL_FLAGS.put(Material.RAILS, 0);
|
||||
MATERIAL_FLAGS.put(Material.COBBLESTONE_STAIRS, 0);
|
||||
MATERIAL_FLAGS.put(Material.WALL_SIGN, 0);
|
||||
MATERIAL_FLAGS.put(Material.LEVER, MODIFED_ON_CLICK);
|
||||
MATERIAL_FLAGS.put(Material.STONE_PLATE, 0);
|
||||
MATERIAL_FLAGS.put(Material.IRON_DOOR_BLOCK, MODIFED_ON_CLICK);
|
||||
MATERIAL_FLAGS.put(Material.WOOD_PLATE, 0);
|
||||
MATERIAL_FLAGS.put(Material.REDSTONE_ORE, 0);
|
||||
MATERIAL_FLAGS.put(Material.GLOWING_REDSTONE_ORE, 0);
|
||||
MATERIAL_FLAGS.put(Material.REDSTONE_TORCH_OFF, 0);
|
||||
MATERIAL_FLAGS.put(Material.REDSTONE_TORCH_ON, 0);
|
||||
MATERIAL_FLAGS.put(Material.STONE_BUTTON, MODIFED_ON_CLICK);
|
||||
MATERIAL_FLAGS.put(Material.SNOW, 0);
|
||||
MATERIAL_FLAGS.put(Material.ICE, 0);
|
||||
MATERIAL_FLAGS.put(Material.SNOW_BLOCK, 0);
|
||||
MATERIAL_FLAGS.put(Material.CACTUS, 0);
|
||||
MATERIAL_FLAGS.put(Material.CLAY, 0);
|
||||
MATERIAL_FLAGS.put(Material.SUGAR_CANE_BLOCK, 0);
|
||||
MATERIAL_FLAGS.put(Material.JUKEBOX, MODIFED_ON_CLICK);
|
||||
MATERIAL_FLAGS.put(Material.FENCE, 0);
|
||||
MATERIAL_FLAGS.put(Material.PUMPKIN, 0);
|
||||
MATERIAL_FLAGS.put(Material.NETHERRACK, 0);
|
||||
MATERIAL_FLAGS.put(Material.SOUL_SAND, 0);
|
||||
MATERIAL_FLAGS.put(Material.GLOWSTONE, 0);
|
||||
MATERIAL_FLAGS.put(Material.PORTAL, 0);
|
||||
MATERIAL_FLAGS.put(Material.JACK_O_LANTERN, 0);
|
||||
MATERIAL_FLAGS.put(Material.CAKE_BLOCK, MODIFED_ON_CLICK);
|
||||
MATERIAL_FLAGS.put(Material.DIODE_BLOCK_OFF, MODIFED_ON_CLICK);
|
||||
MATERIAL_FLAGS.put(Material.DIODE_BLOCK_ON, MODIFED_ON_CLICK);
|
||||
MATERIAL_FLAGS.put(Material.STAINED_GLASS, 0);
|
||||
MATERIAL_FLAGS.put(Material.TRAP_DOOR, MODIFED_ON_CLICK);
|
||||
MATERIAL_FLAGS.put(Material.MONSTER_EGGS, 0);
|
||||
MATERIAL_FLAGS.put(Material.SMOOTH_BRICK, 0);
|
||||
MATERIAL_FLAGS.put(Material.HUGE_MUSHROOM_1, 0);
|
||||
MATERIAL_FLAGS.put(Material.HUGE_MUSHROOM_2, 0);
|
||||
MATERIAL_FLAGS.put(Material.IRON_FENCE, 0);
|
||||
MATERIAL_FLAGS.put(Material.THIN_GLASS, 0);
|
||||
MATERIAL_FLAGS.put(Material.MELON_BLOCK, 0);
|
||||
MATERIAL_FLAGS.put(Material.PUMPKIN_STEM, 0);
|
||||
MATERIAL_FLAGS.put(Material.MELON_STEM, 0);
|
||||
MATERIAL_FLAGS.put(Material.VINE, 0);
|
||||
MATERIAL_FLAGS.put(Material.FENCE_GATE, MODIFED_ON_CLICK);
|
||||
MATERIAL_FLAGS.put(Material.BRICK_STAIRS, 0);
|
||||
MATERIAL_FLAGS.put(Material.SMOOTH_STAIRS, 0);
|
||||
MATERIAL_FLAGS.put(Material.MYCEL, 0);
|
||||
MATERIAL_FLAGS.put(Material.WATER_LILY, 0);
|
||||
MATERIAL_FLAGS.put(Material.NETHER_BRICK, 0);
|
||||
MATERIAL_FLAGS.put(Material.NETHER_FENCE, 0);
|
||||
MATERIAL_FLAGS.put(Material.NETHER_BRICK_STAIRS, 0);
|
||||
MATERIAL_FLAGS.put(Material.NETHER_WARTS, 0);
|
||||
MATERIAL_FLAGS.put(Material.ENCHANTMENT_TABLE, 0);
|
||||
MATERIAL_FLAGS.put(Material.BREWING_STAND, MODIFED_ON_CLICK);
|
||||
MATERIAL_FLAGS.put(Material.CAULDRON, MODIFED_ON_CLICK);
|
||||
MATERIAL_FLAGS.put(Material.ENDER_PORTAL, 0);
|
||||
MATERIAL_FLAGS.put(Material.ENDER_PORTAL_FRAME, 0);
|
||||
MATERIAL_FLAGS.put(Material.ENDER_STONE, 0);
|
||||
MATERIAL_FLAGS.put(Material.DRAGON_EGG, MODIFED_ON_CLICK);
|
||||
MATERIAL_FLAGS.put(Material.REDSTONE_LAMP_OFF, 0);
|
||||
MATERIAL_FLAGS.put(Material.REDSTONE_LAMP_ON, 0);
|
||||
MATERIAL_FLAGS.put(Material.WOOD_DOUBLE_STEP, 0);
|
||||
MATERIAL_FLAGS.put(Material.WOOD_STEP, 0);
|
||||
MATERIAL_FLAGS.put(Material.COCOA, 0);
|
||||
MATERIAL_FLAGS.put(Material.SANDSTONE_STAIRS, 0);
|
||||
MATERIAL_FLAGS.put(Material.EMERALD_ORE, 0);
|
||||
MATERIAL_FLAGS.put(Material.ENDER_CHEST, 0);
|
||||
MATERIAL_FLAGS.put(Material.TRIPWIRE_HOOK, 0);
|
||||
MATERIAL_FLAGS.put(Material.TRIPWIRE, 0);
|
||||
MATERIAL_FLAGS.put(Material.EMERALD_BLOCK, 0);
|
||||
MATERIAL_FLAGS.put(Material.SPRUCE_WOOD_STAIRS, 0);
|
||||
MATERIAL_FLAGS.put(Material.BIRCH_WOOD_STAIRS, 0);
|
||||
MATERIAL_FLAGS.put(Material.JUNGLE_WOOD_STAIRS, 0);
|
||||
MATERIAL_FLAGS.put(Material.COMMAND, MODIFED_ON_CLICK);
|
||||
MATERIAL_FLAGS.put(Material.BEACON, MODIFED_ON_CLICK);
|
||||
MATERIAL_FLAGS.put(Material.COBBLE_WALL, 0);
|
||||
MATERIAL_FLAGS.put(Material.FLOWER_POT, MODIFED_ON_CLICK);
|
||||
MATERIAL_FLAGS.put(Material.CARROT, 0);
|
||||
MATERIAL_FLAGS.put(Material.POTATO, 0);
|
||||
MATERIAL_FLAGS.put(Material.WOOD_BUTTON, MODIFED_ON_CLICK);
|
||||
MATERIAL_FLAGS.put(Material.SKULL, 0);
|
||||
MATERIAL_FLAGS.put(Material.ANVIL, MODIFED_ON_CLICK);
|
||||
MATERIAL_FLAGS.put(Material.TRAPPED_CHEST, MODIFED_ON_CLICK);
|
||||
MATERIAL_FLAGS.put(Material.GOLD_PLATE, 0);
|
||||
MATERIAL_FLAGS.put(Material.IRON_PLATE, 0);
|
||||
MATERIAL_FLAGS.put(Material.REDSTONE_COMPARATOR_OFF, MODIFED_ON_CLICK);
|
||||
MATERIAL_FLAGS.put(Material.REDSTONE_COMPARATOR_ON, MODIFED_ON_CLICK);
|
||||
MATERIAL_FLAGS.put(Material.DAYLIGHT_DETECTOR, MODIFED_ON_CLICK);
|
||||
MATERIAL_FLAGS.put(Material.REDSTONE_BLOCK, 0);
|
||||
MATERIAL_FLAGS.put(Material.QUARTZ_ORE, 0);
|
||||
MATERIAL_FLAGS.put(Material.HOPPER, MODIFED_ON_CLICK);
|
||||
MATERIAL_FLAGS.put(Material.QUARTZ_BLOCK, 0);
|
||||
MATERIAL_FLAGS.put(Material.QUARTZ_STAIRS, 0);
|
||||
MATERIAL_FLAGS.put(Material.ACTIVATOR_RAIL, 0);
|
||||
MATERIAL_FLAGS.put(Material.DROPPER, MODIFED_ON_CLICK);
|
||||
MATERIAL_FLAGS.put(Material.STAINED_CLAY, 0);
|
||||
MATERIAL_FLAGS.put(Material.STAINED_GLASS_PANE, 0);
|
||||
MATERIAL_FLAGS.put(Material.LEAVES_2, 0);
|
||||
MATERIAL_FLAGS.put(Material.LOG_2, 0);
|
||||
MATERIAL_FLAGS.put(Material.ACACIA_STAIRS, 0);
|
||||
MATERIAL_FLAGS.put(Material.DARK_OAK_STAIRS, 0);
|
||||
MATERIAL_FLAGS.put(Material.HAY_BLOCK, 0);
|
||||
MATERIAL_FLAGS.put(Material.CARPET, 0);
|
||||
MATERIAL_FLAGS.put(Material.HARD_CLAY, 0);
|
||||
MATERIAL_FLAGS.put(Material.COAL_BLOCK, 0);
|
||||
MATERIAL_FLAGS.put(Material.PACKED_ICE, 0);
|
||||
MATERIAL_FLAGS.put(Material.DOUBLE_PLANT, 0);
|
||||
|
||||
MATERIAL_FLAGS.put(Material.IRON_SPADE, 0);
|
||||
MATERIAL_FLAGS.put(Material.IRON_PICKAXE, 0);
|
||||
MATERIAL_FLAGS.put(Material.IRON_AXE, 0);
|
||||
MATERIAL_FLAGS.put(Material.FLINT_AND_STEEL, 0);
|
||||
MATERIAL_FLAGS.put(Material.APPLE, 0);
|
||||
MATERIAL_FLAGS.put(Material.BOW, 0);
|
||||
MATERIAL_FLAGS.put(Material.ARROW, 0);
|
||||
MATERIAL_FLAGS.put(Material.COAL, 0);
|
||||
MATERIAL_FLAGS.put(Material.DIAMOND, 0);
|
||||
MATERIAL_FLAGS.put(Material.IRON_INGOT, 0);
|
||||
MATERIAL_FLAGS.put(Material.GOLD_INGOT, 0);
|
||||
MATERIAL_FLAGS.put(Material.IRON_SWORD, 0);
|
||||
MATERIAL_FLAGS.put(Material.WOOD_SWORD, 0);
|
||||
MATERIAL_FLAGS.put(Material.WOOD_SPADE, 0);
|
||||
MATERIAL_FLAGS.put(Material.WOOD_PICKAXE, 0);
|
||||
MATERIAL_FLAGS.put(Material.WOOD_AXE, 0);
|
||||
MATERIAL_FLAGS.put(Material.STONE_SWORD, 0);
|
||||
MATERIAL_FLAGS.put(Material.STONE_SPADE, 0);
|
||||
MATERIAL_FLAGS.put(Material.STONE_PICKAXE, 0);
|
||||
MATERIAL_FLAGS.put(Material.STONE_AXE, 0);
|
||||
MATERIAL_FLAGS.put(Material.DIAMOND_SWORD, 0);
|
||||
MATERIAL_FLAGS.put(Material.DIAMOND_SPADE, 0);
|
||||
MATERIAL_FLAGS.put(Material.DIAMOND_PICKAXE, 0);
|
||||
MATERIAL_FLAGS.put(Material.DIAMOND_AXE, 0);
|
||||
MATERIAL_FLAGS.put(Material.STICK, 0);
|
||||
MATERIAL_FLAGS.put(Material.BOWL, 0);
|
||||
MATERIAL_FLAGS.put(Material.MUSHROOM_SOUP, 0);
|
||||
MATERIAL_FLAGS.put(Material.GOLD_SWORD, 0);
|
||||
MATERIAL_FLAGS.put(Material.GOLD_SPADE, 0);
|
||||
MATERIAL_FLAGS.put(Material.GOLD_PICKAXE, 0);
|
||||
MATERIAL_FLAGS.put(Material.GOLD_AXE, 0);
|
||||
MATERIAL_FLAGS.put(Material.STRING, 0);
|
||||
MATERIAL_FLAGS.put(Material.FEATHER, 0);
|
||||
MATERIAL_FLAGS.put(Material.SULPHUR, 0);
|
||||
MATERIAL_FLAGS.put(Material.WOOD_HOE, MODIFIES_BLOCKS);
|
||||
MATERIAL_FLAGS.put(Material.STONE_HOE, MODIFIES_BLOCKS);
|
||||
MATERIAL_FLAGS.put(Material.IRON_HOE, MODIFIES_BLOCKS);
|
||||
MATERIAL_FLAGS.put(Material.DIAMOND_HOE, MODIFIES_BLOCKS);
|
||||
MATERIAL_FLAGS.put(Material.GOLD_HOE, MODIFIES_BLOCKS);
|
||||
MATERIAL_FLAGS.put(Material.SEEDS, MODIFIES_BLOCKS);
|
||||
MATERIAL_FLAGS.put(Material.WHEAT, 0);
|
||||
MATERIAL_FLAGS.put(Material.BREAD, 0);
|
||||
MATERIAL_FLAGS.put(Material.LEATHER_HELMET, 0);
|
||||
MATERIAL_FLAGS.put(Material.LEATHER_CHESTPLATE, 0);
|
||||
MATERIAL_FLAGS.put(Material.LEATHER_LEGGINGS, 0);
|
||||
MATERIAL_FLAGS.put(Material.LEATHER_BOOTS, 0);
|
||||
MATERIAL_FLAGS.put(Material.CHAINMAIL_HELMET, 0);
|
||||
MATERIAL_FLAGS.put(Material.CHAINMAIL_CHESTPLATE, 0);
|
||||
MATERIAL_FLAGS.put(Material.CHAINMAIL_LEGGINGS, 0);
|
||||
MATERIAL_FLAGS.put(Material.CHAINMAIL_BOOTS, 0);
|
||||
MATERIAL_FLAGS.put(Material.IRON_HELMET, 0);
|
||||
MATERIAL_FLAGS.put(Material.IRON_CHESTPLATE, 0);
|
||||
MATERIAL_FLAGS.put(Material.IRON_LEGGINGS, 0);
|
||||
MATERIAL_FLAGS.put(Material.IRON_BOOTS, 0);
|
||||
MATERIAL_FLAGS.put(Material.DIAMOND_HELMET, 0);
|
||||
MATERIAL_FLAGS.put(Material.DIAMOND_CHESTPLATE, 0);
|
||||
MATERIAL_FLAGS.put(Material.DIAMOND_LEGGINGS, 0);
|
||||
MATERIAL_FLAGS.put(Material.DIAMOND_BOOTS, 0);
|
||||
MATERIAL_FLAGS.put(Material.GOLD_HELMET, 0);
|
||||
MATERIAL_FLAGS.put(Material.GOLD_CHESTPLATE, 0);
|
||||
MATERIAL_FLAGS.put(Material.GOLD_LEGGINGS, 0);
|
||||
MATERIAL_FLAGS.put(Material.GOLD_BOOTS, 0);
|
||||
MATERIAL_FLAGS.put(Material.FLINT, 0);
|
||||
MATERIAL_FLAGS.put(Material.PORK, 0);
|
||||
MATERIAL_FLAGS.put(Material.GRILLED_PORK, 0);
|
||||
MATERIAL_FLAGS.put(Material.PAINTING, 0);
|
||||
MATERIAL_FLAGS.put(Material.GOLDEN_APPLE, 0);
|
||||
MATERIAL_FLAGS.put(Material.SIGN, 0);
|
||||
MATERIAL_FLAGS.put(Material.WOOD_DOOR, 0);
|
||||
MATERIAL_FLAGS.put(Material.BUCKET, 0);
|
||||
MATERIAL_FLAGS.put(Material.WATER_BUCKET, 0);
|
||||
MATERIAL_FLAGS.put(Material.LAVA_BUCKET, 0);
|
||||
MATERIAL_FLAGS.put(Material.MINECART, 0);
|
||||
MATERIAL_FLAGS.put(Material.SADDLE, 0);
|
||||
MATERIAL_FLAGS.put(Material.IRON_DOOR, 0);
|
||||
MATERIAL_FLAGS.put(Material.REDSTONE, 0);
|
||||
MATERIAL_FLAGS.put(Material.SNOW_BALL, 0);
|
||||
MATERIAL_FLAGS.put(Material.BOAT, 0);
|
||||
MATERIAL_FLAGS.put(Material.LEATHER, 0);
|
||||
MATERIAL_FLAGS.put(Material.MILK_BUCKET, 0);
|
||||
MATERIAL_FLAGS.put(Material.CLAY_BRICK, 0);
|
||||
MATERIAL_FLAGS.put(Material.CLAY_BALL, 0);
|
||||
MATERIAL_FLAGS.put(Material.SUGAR_CANE, 0);
|
||||
MATERIAL_FLAGS.put(Material.PAPER, 0);
|
||||
MATERIAL_FLAGS.put(Material.BOOK, 0);
|
||||
MATERIAL_FLAGS.put(Material.SLIME_BALL, 0);
|
||||
MATERIAL_FLAGS.put(Material.STORAGE_MINECART, 0);
|
||||
MATERIAL_FLAGS.put(Material.POWERED_MINECART, 0);
|
||||
MATERIAL_FLAGS.put(Material.EGG, 0);
|
||||
MATERIAL_FLAGS.put(Material.COMPASS, 0);
|
||||
MATERIAL_FLAGS.put(Material.FISHING_ROD, 0);
|
||||
MATERIAL_FLAGS.put(Material.WATCH, 0);
|
||||
MATERIAL_FLAGS.put(Material.GLOWSTONE_DUST, 0);
|
||||
MATERIAL_FLAGS.put(Material.RAW_FISH, 0);
|
||||
MATERIAL_FLAGS.put(Material.COOKED_FISH, 0);
|
||||
MATERIAL_FLAGS.put(Material.INK_SACK, 0);
|
||||
MATERIAL_FLAGS.put(Material.BONE, 0);
|
||||
MATERIAL_FLAGS.put(Material.SUGAR, 0);
|
||||
MATERIAL_FLAGS.put(Material.CAKE, 0);
|
||||
MATERIAL_FLAGS.put(Material.BED, 0);
|
||||
MATERIAL_FLAGS.put(Material.DIODE, 0);
|
||||
MATERIAL_FLAGS.put(Material.COOKIE, 0);
|
||||
MATERIAL_FLAGS.put(Material.MAP, 0);
|
||||
MATERIAL_FLAGS.put(Material.SHEARS, MODIFIES_BLOCKS);
|
||||
MATERIAL_FLAGS.put(Material.MELON, 0);
|
||||
MATERIAL_FLAGS.put(Material.PUMPKIN_SEEDS, 0);
|
||||
MATERIAL_FLAGS.put(Material.MELON_SEEDS, 0);
|
||||
MATERIAL_FLAGS.put(Material.RAW_BEEF, 0);
|
||||
MATERIAL_FLAGS.put(Material.COOKED_BEEF, 0);
|
||||
MATERIAL_FLAGS.put(Material.RAW_CHICKEN, 0);
|
||||
MATERIAL_FLAGS.put(Material.COOKED_CHICKEN, 0);
|
||||
MATERIAL_FLAGS.put(Material.ROTTEN_FLESH, 0);
|
||||
MATERIAL_FLAGS.put(Material.ENDER_PEARL, 0);
|
||||
MATERIAL_FLAGS.put(Material.BLAZE_ROD, 0);
|
||||
MATERIAL_FLAGS.put(Material.GHAST_TEAR, 0);
|
||||
MATERIAL_FLAGS.put(Material.GOLD_NUGGET, 0);
|
||||
MATERIAL_FLAGS.put(Material.NETHER_STALK, 0);
|
||||
MATERIAL_FLAGS.put(Material.POTION, 0);
|
||||
MATERIAL_FLAGS.put(Material.GLASS_BOTTLE, 0);
|
||||
MATERIAL_FLAGS.put(Material.SPIDER_EYE, 0);
|
||||
MATERIAL_FLAGS.put(Material.FERMENTED_SPIDER_EYE, 0);
|
||||
MATERIAL_FLAGS.put(Material.BLAZE_POWDER, 0);
|
||||
MATERIAL_FLAGS.put(Material.MAGMA_CREAM, 0);
|
||||
MATERIAL_FLAGS.put(Material.BREWING_STAND_ITEM, 0);
|
||||
MATERIAL_FLAGS.put(Material.CAULDRON_ITEM, 0);
|
||||
MATERIAL_FLAGS.put(Material.EYE_OF_ENDER, 0);
|
||||
MATERIAL_FLAGS.put(Material.SPECKLED_MELON, 0);
|
||||
MATERIAL_FLAGS.put(Material.MONSTER_EGG, 0);
|
||||
MATERIAL_FLAGS.put(Material.EXP_BOTTLE, 0);
|
||||
MATERIAL_FLAGS.put(Material.FIREBALL, 0);
|
||||
MATERIAL_FLAGS.put(Material.BOOK_AND_QUILL, 0);
|
||||
MATERIAL_FLAGS.put(Material.WRITTEN_BOOK, 0);
|
||||
MATERIAL_FLAGS.put(Material.EMERALD, 0);
|
||||
MATERIAL_FLAGS.put(Material.ITEM_FRAME, 0);
|
||||
MATERIAL_FLAGS.put(Material.FLOWER_POT_ITEM, 0);
|
||||
MATERIAL_FLAGS.put(Material.CARROT_ITEM, 0);
|
||||
MATERIAL_FLAGS.put(Material.POTATO_ITEM, 0);
|
||||
MATERIAL_FLAGS.put(Material.BAKED_POTATO, 0);
|
||||
MATERIAL_FLAGS.put(Material.POISONOUS_POTATO, 0);
|
||||
MATERIAL_FLAGS.put(Material.EMPTY_MAP, 0);
|
||||
MATERIAL_FLAGS.put(Material.GOLDEN_CARROT, 0);
|
||||
MATERIAL_FLAGS.put(Material.SKULL_ITEM, 0);
|
||||
MATERIAL_FLAGS.put(Material.CARROT_STICK, 0);
|
||||
MATERIAL_FLAGS.put(Material.NETHER_STAR, 0);
|
||||
MATERIAL_FLAGS.put(Material.PUMPKIN_PIE, 0);
|
||||
MATERIAL_FLAGS.put(Material.FIREWORK, 0);
|
||||
MATERIAL_FLAGS.put(Material.FIREWORK_CHARGE, 0);
|
||||
MATERIAL_FLAGS.put(Material.ENCHANTED_BOOK, 0);
|
||||
MATERIAL_FLAGS.put(Material.REDSTONE_COMPARATOR, 0);
|
||||
MATERIAL_FLAGS.put(Material.NETHER_BRICK_ITEM, 0);
|
||||
MATERIAL_FLAGS.put(Material.QUARTZ, 0);
|
||||
MATERIAL_FLAGS.put(Material.EXPLOSIVE_MINECART, 0);
|
||||
MATERIAL_FLAGS.put(Material.HOPPER_MINECART, 0);
|
||||
MATERIAL_FLAGS.put(Material.IRON_BARDING, 0);
|
||||
MATERIAL_FLAGS.put(Material.GOLD_BARDING, 0);
|
||||
MATERIAL_FLAGS.put(Material.DIAMOND_BARDING, 0);
|
||||
MATERIAL_FLAGS.put(Material.LEASH, 0);
|
||||
MATERIAL_FLAGS.put(Material.NAME_TAG, 0);
|
||||
MATERIAL_FLAGS.put(Material.COMMAND_MINECART, 0);
|
||||
MATERIAL_FLAGS.put(Material.GOLD_RECORD, 0);
|
||||
MATERIAL_FLAGS.put(Material.GREEN_RECORD, 0);
|
||||
MATERIAL_FLAGS.put(Material.RECORD_3, 0);
|
||||
MATERIAL_FLAGS.put(Material.RECORD_4, 0);
|
||||
MATERIAL_FLAGS.put(Material.RECORD_5, 0);
|
||||
MATERIAL_FLAGS.put(Material.RECORD_6, 0);
|
||||
MATERIAL_FLAGS.put(Material.RECORD_7, 0);
|
||||
MATERIAL_FLAGS.put(Material.RECORD_8, 0);
|
||||
MATERIAL_FLAGS.put(Material.RECORD_9, 0);
|
||||
MATERIAL_FLAGS.put(Material.RECORD_10, 0);
|
||||
MATERIAL_FLAGS.put(Material.RECORD_11, 0);
|
||||
MATERIAL_FLAGS.put(Material.RECORD_12, 0);
|
||||
}
|
||||
|
||||
private Materials() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the related material for an entity type.
|
||||
*
|
||||
* @param type the entity type
|
||||
* @return the related material or {@code null} if one is not known or exists
|
||||
*/
|
||||
@Nullable
|
||||
public static Material getRelatedMaterial(EntityType type) {
|
||||
return ENTITY_ITEMS.get(type);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test whether the given material is a mushroom.
|
||||
*
|
||||
* @param material the material
|
||||
* @return true if a mushroom block
|
||||
*/
|
||||
public static boolean isMushroom(Material material) {
|
||||
return material == Material.RED_MUSHROOM || material == Material.BROWN_MUSHROOM;
|
||||
}
|
||||
|
||||
/**
|
||||
* Test whether the given material is a leaf block.
|
||||
*
|
||||
* @param material the material
|
||||
* @return true if a leaf block
|
||||
*/
|
||||
public static boolean isLeaf(Material material) {
|
||||
return material == Material.LEAVES || material == Material.LEAVES_2;
|
||||
}
|
||||
|
||||
/**
|
||||
* Test whether the given material is water.
|
||||
*
|
||||
* @param material the material
|
||||
* @return true if a water block
|
||||
*/
|
||||
public static boolean isWater(Material material) {
|
||||
return material == Material.WATER || material == Material.STATIONARY_WATER;
|
||||
}
|
||||
|
||||
/**
|
||||
* Test whether the given material is lava.
|
||||
*
|
||||
* @param material the material
|
||||
* @return true if a lava block
|
||||
*/
|
||||
public static boolean isLava(Material material) {
|
||||
return material == Material.LAVA || material == Material.STATIONARY_LAVA;
|
||||
}
|
||||
|
||||
/**
|
||||
* Test whether the given material is a portal material.
|
||||
*
|
||||
* @param material the material
|
||||
* @return true if a portal block
|
||||
*/
|
||||
public static boolean isPortal(Material material) {
|
||||
return material == Material.PORTAL || material == Material.ENDER_PORTAL;
|
||||
}
|
||||
|
||||
/**
|
||||
* Test whether the given material data is of the given dye color.
|
||||
*
|
||||
* <p>Returns false for non-dyed items.</p>
|
||||
*
|
||||
* @param data the data
|
||||
* @return true if it is the provided dye color
|
||||
*/
|
||||
public static boolean isDyeColor(MaterialData data, DyeColor color) {
|
||||
return data instanceof Dye && ((Dye) data).getColor() == color;
|
||||
}
|
||||
|
||||
/**
|
||||
* Test whether the given material is a rail block.
|
||||
*
|
||||
* @param material the material
|
||||
* @return true if a rail block
|
||||
*/
|
||||
public static boolean isRailBlock(Material material) {
|
||||
return material == Material.RAILS
|
||||
|| material == Material.ACTIVATOR_RAIL
|
||||
|| material == Material.DETECTOR_RAIL
|
||||
|| material == Material.POWERED_RAIL;
|
||||
}
|
||||
|
||||
/**
|
||||
* Test whether the given material is a Minecart.
|
||||
*
|
||||
* @param material the material
|
||||
* @return true if a Minecart item
|
||||
*/
|
||||
public static boolean isMinecart(Material material) {
|
||||
return material == Material.MINECART
|
||||
|| material == Material.COMMAND_MINECART
|
||||
|| material == Material.EXPLOSIVE_MINECART
|
||||
|| material == Material.HOPPER_MINECART
|
||||
|| material == Material.POWERED_MINECART
|
||||
|| material == Material.STORAGE_MINECART;
|
||||
}
|
||||
|
||||
/**
|
||||
* Test whether the given material is an inventory block.
|
||||
*
|
||||
* @param material the material
|
||||
* @return true if an inventory block
|
||||
*/
|
||||
public static boolean isInventoryBlock(Material material) {
|
||||
return material == Material.CHEST
|
||||
|| material == Material.JUKEBOX
|
||||
|| material == Material.DISPENSER
|
||||
|| material == Material.FURNACE
|
||||
|| material == Material.BURNING_FURNACE
|
||||
|| material == Material.BREWING_STAND
|
||||
|| material == Material.TRAPPED_CHEST
|
||||
|| material == Material.HOPPER
|
||||
|| material == Material.DROPPER;
|
||||
}
|
||||
|
||||
/**
|
||||
* Test whether the given material is a block that is modified when it is
|
||||
* left or right clicked.
|
||||
*
|
||||
* <p>This test is conservative, returning true for blocks that it is not
|
||||
* aware of.</p>
|
||||
*
|
||||
* @param material the material
|
||||
* @return true if the block is modified
|
||||
*/
|
||||
public static boolean isBlockModifiedOnClick(Material material) {
|
||||
Integer flags = MATERIAL_FLAGS.get(material);
|
||||
return flags == null || (flags & MODIFED_ON_CLICK) == MODIFED_ON_CLICK;
|
||||
}
|
||||
|
||||
/**
|
||||
* Test whether the given item modifies a given block when right clicked.
|
||||
*
|
||||
* <p>This test is conservative, returning true for blocks that it is not
|
||||
* aware of or does not have the details for.</p>
|
||||
*
|
||||
* @param item the item
|
||||
* @param block the block
|
||||
* @return true if the item is applied to the block
|
||||
*/
|
||||
public static boolean isItemAppliedToBlock(Material item, Material block) {
|
||||
Integer flags = MATERIAL_FLAGS.get(item);
|
||||
return flags == null || (flags & MODIFIES_BLOCKS) == MODIFIES_BLOCKS;
|
||||
}
|
||||
|
||||
}
|
102
src/main/java/com/sk89q/worldguard/bukkit/util/RegionQuery.java
Normal file
102
src/main/java/com/sk89q/worldguard/bukkit/util/RegionQuery.java
Normal file
@ -0,0 +1,102 @@
|
||||
/*
|
||||
* 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.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.block.Block;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import static com.sk89q.worldguard.bukkit.BukkitUtil.toVector;
|
||||
|
||||
public class RegionQuery {
|
||||
|
||||
private final WorldGuardPlugin plugin;
|
||||
private final ConfigurationManager config;
|
||||
private final GlobalRegionManager globalManager;
|
||||
@Nullable
|
||||
private final LocalPlayer localPlayer;
|
||||
|
||||
public RegionQuery(WorldGuardPlugin plugin, @Nullable Player player) {
|
||||
this.plugin = plugin;
|
||||
this.config = plugin.getGlobalStateManager();
|
||||
this.globalManager = plugin.getGlobalRegionManager();
|
||||
this.localPlayer = player != null ? plugin.wrapPlayer(player) : null;
|
||||
}
|
||||
|
||||
public boolean canBuild(Block block) {
|
||||
return canBuild(block.getLocation());
|
||||
}
|
||||
|
||||
public boolean canBuild(Location location) {
|
||||
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.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 (globalManager.hasBypass(localPlayer, world)) {
|
||||
return true;
|
||||
} else {
|
||||
RegionManager manager = globalManager.get(location.getWorld());
|
||||
return manager.getApplicableRegions(BukkitUtil.toVector(location)).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);
|
||||
}
|
||||
|
||||
}
|
@ -34,8 +34,20 @@ private Events() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Fire the {@code eventToFire} if {@code original} has not been cancelled
|
||||
* and cancel the original if the fired event is cancelled.
|
||||
* Fire the {@code eventToFire} and return whether the event was cancelled.
|
||||
*
|
||||
* @param eventToFire the event to fire
|
||||
* @param <T> an event that can be fired and is cancellable
|
||||
* @return true if the event was fired
|
||||
*/
|
||||
public static <T extends Event & Cancellable> boolean fireAndTestCancel( T eventToFire) {
|
||||
Bukkit.getServer().getPluginManager().callEvent(eventToFire);
|
||||
return eventToFire.isCancelled();
|
||||
}
|
||||
|
||||
/**
|
||||
* Fire the {@code eventToFire} and cancel the original if the fired event
|
||||
* is cancelled.
|
||||
*
|
||||
* @param original the original event to potentially cancel
|
||||
* @param eventToFire the event to fire to consider cancelling the original event
|
||||
@ -43,20 +55,18 @@ private Events() {
|
||||
* @return true if the event was fired and it caused the original event to be cancelled
|
||||
*/
|
||||
public static <T extends Event & Cancellable> boolean fireToCancel(Cancellable original, T eventToFire) {
|
||||
if (!original.isCancelled()) {
|
||||
Bukkit.getServer().getPluginManager().callEvent(eventToFire);
|
||||
if (eventToFire.isCancelled()) {
|
||||
original.setCancelled(true);
|
||||
return true;
|
||||
}
|
||||
Bukkit.getServer().getPluginManager().callEvent(eventToFire);
|
||||
if (eventToFire.isCancelled()) {
|
||||
original.setCancelled(true);
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Fire the {@code eventToFire} if {@code original}
|
||||
* and cancel the original if the fired event is cancelled.
|
||||
* Fire the {@code eventToFire} and cancel the original if the fired event
|
||||
* is cancelled.
|
||||
*
|
||||
* @param original the original event to potentially cancel
|
||||
* @param eventToFire the event to fire to consider cancelling the original event
|
||||
|
@ -22,6 +22,7 @@
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.entity.Projectile;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.ArrayList;
|
||||
@ -88,6 +89,9 @@ public static List<? extends Cause<?>> create(Object ... cause) {
|
||||
causes.add(new PlayerCause((Player) o));
|
||||
} else if (o instanceof Block) {
|
||||
causes.add(new BlockCause((Block) o));
|
||||
} else if (o instanceof Projectile) {
|
||||
causes.addAll(create(o));
|
||||
causes.add(new EntityCause((Entity) o));
|
||||
} else if (o instanceof Entity) {
|
||||
causes.add(new EntityCause((Entity) o));
|
||||
} else {
|
||||
|
@ -28,11 +28,10 @@
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
abstract class AbstractInteractEvent extends Event implements Cancellable {
|
||||
public abstract class AbstractInteractEvent extends Event implements Cancellable {
|
||||
|
||||
private final Event originalEvent;
|
||||
private final List<? extends Cause<?>> causes;
|
||||
private final Interaction interaction;
|
||||
private boolean cancelled;
|
||||
|
||||
/**
|
||||
@ -40,15 +39,12 @@ abstract class AbstractInteractEvent extends Event implements Cancellable {
|
||||
*
|
||||
* @param originalEvent the original event
|
||||
* @param causes a list of causes, where the originating causes are at the beginning
|
||||
* @param interaction the action that is being taken
|
||||
*/
|
||||
protected AbstractInteractEvent(Event originalEvent, List<? extends Cause<?>> causes, Interaction interaction) {
|
||||
protected AbstractInteractEvent(Event originalEvent, List<? extends Cause<?>> causes) {
|
||||
checkNotNull(originalEvent);
|
||||
checkNotNull(causes);
|
||||
checkNotNull(interaction);
|
||||
this.originalEvent = originalEvent;
|
||||
this.causes = causes;
|
||||
this.interaction = interaction;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -70,15 +66,6 @@ public List<? extends Cause<?>> getCauses() {
|
||||
return Collections.unmodifiableList(causes);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the action that is being taken.
|
||||
*
|
||||
* @return the action
|
||||
*/
|
||||
public Interaction getInteraction() {
|
||||
return interaction;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isCancelled() {
|
||||
return cancelled;
|
||||
|
@ -0,0 +1,85 @@
|
||||
/*
|
||||
* 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.internal.event.block;
|
||||
|
||||
import com.sk89q.worldguard.internal.cause.Cause;
|
||||
import com.sk89q.worldguard.internal.event.AbstractInteractEvent;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.event.Event;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.List;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
abstract class AbstractBlockEvent extends AbstractInteractEvent {
|
||||
|
||||
private final Location target;
|
||||
@Nullable
|
||||
private final Block block;
|
||||
private final Material effectiveMaterial;
|
||||
|
||||
protected AbstractBlockEvent(Event originalEvent, List<? extends Cause<?>> causes, Block block) {
|
||||
super(originalEvent, causes);
|
||||
checkNotNull(block);
|
||||
this.target = block.getLocation();
|
||||
this.block = block;
|
||||
this.effectiveMaterial = block.getType();
|
||||
}
|
||||
|
||||
protected AbstractBlockEvent(Event originalEvent, List<? extends Cause<?>> causes, Location target, Material effectiveMaterial) {
|
||||
super(originalEvent, causes);
|
||||
this.target = target;
|
||||
this.block = null;
|
||||
this.effectiveMaterial = effectiveMaterial;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the target block being affected.
|
||||
*
|
||||
* @return a block
|
||||
*/
|
||||
public Location getTarget() {
|
||||
return target;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the block.
|
||||
*
|
||||
* @return the block
|
||||
*/
|
||||
@Nullable
|
||||
public Block getBlock() {
|
||||
return block;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the effective material of the block, regardless of what the block
|
||||
* currently is.
|
||||
*
|
||||
* @return the effective material
|
||||
*/
|
||||
public Material getEffectiveMaterial() {
|
||||
return effectiveMaterial;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,52 @@
|
||||
/*
|
||||
* 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.internal.event.block;
|
||||
|
||||
import com.sk89q.worldguard.internal.cause.Cause;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.event.Event;
|
||||
import org.bukkit.event.HandlerList;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class BreakBlockEvent extends AbstractBlockEvent {
|
||||
|
||||
private static final HandlerList handlers = new HandlerList();
|
||||
|
||||
public BreakBlockEvent(Event originalEvent, List<? extends Cause<?>> causes, Block block) {
|
||||
super(originalEvent, causes, block);
|
||||
}
|
||||
|
||||
public BreakBlockEvent(Event originalEvent, List<? extends Cause<?>> causes, Location target, Material effectiveMaterial) {
|
||||
super(originalEvent, causes, target, effectiveMaterial);
|
||||
}
|
||||
|
||||
@Override
|
||||
public HandlerList getHandlers() {
|
||||
return handlers;
|
||||
}
|
||||
|
||||
public static HandlerList getHandlerList() {
|
||||
return handlers;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,52 @@
|
||||
/*
|
||||
* 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.internal.event.block;
|
||||
|
||||
import com.sk89q.worldguard.internal.cause.Cause;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.event.Event;
|
||||
import org.bukkit.event.HandlerList;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class PlaceBlockEvent extends AbstractBlockEvent {
|
||||
|
||||
private static final HandlerList handlers = new HandlerList();
|
||||
|
||||
public PlaceBlockEvent(Event originalEvent, List<? extends Cause<?>> causes, Block block) {
|
||||
super(originalEvent, causes, block);
|
||||
}
|
||||
|
||||
public PlaceBlockEvent(Event originalEvent, List<? extends Cause<?>> causes, Location target, Material effectiveMaterial) {
|
||||
super(originalEvent, causes, target, effectiveMaterial);
|
||||
}
|
||||
|
||||
@Override
|
||||
public HandlerList getHandlers() {
|
||||
return handlers;
|
||||
}
|
||||
|
||||
public static HandlerList getHandlerList() {
|
||||
return handlers;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,55 @@
|
||||
/*
|
||||
* 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.internal.event.block;
|
||||
|
||||
import com.sk89q.worldguard.internal.cause.Cause;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.event.Event;
|
||||
import org.bukkit.event.HandlerList;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Fired when a block is interacted with.
|
||||
*/
|
||||
public class UseBlockEvent extends AbstractBlockEvent {
|
||||
|
||||
private static final HandlerList handlers = new HandlerList();
|
||||
|
||||
public UseBlockEvent(Event originalEvent, List<? extends Cause<?>> causes, Block block) {
|
||||
super(originalEvent, causes, block);
|
||||
}
|
||||
|
||||
public UseBlockEvent(Event originalEvent, List<? extends Cause<?>> causes, Location target, Material effectiveMaterial) {
|
||||
super(originalEvent, causes, target, effectiveMaterial);
|
||||
}
|
||||
|
||||
@Override
|
||||
public HandlerList getHandlers() {
|
||||
return handlers;
|
||||
}
|
||||
|
||||
public static HandlerList getHandlerList() {
|
||||
return handlers;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,87 @@
|
||||
/*
|
||||
* 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.internal.event.entity;
|
||||
|
||||
import com.sk89q.worldguard.internal.cause.Cause;
|
||||
import com.sk89q.worldguard.internal.event.AbstractInteractEvent;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.event.Event;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.List;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
abstract class AbstractEntityEvent extends AbstractInteractEvent {
|
||||
|
||||
private final Location target;
|
||||
@Nullable
|
||||
private final Entity entity;
|
||||
|
||||
/**
|
||||
* Create a new instance
|
||||
*
|
||||
* @param originalEvent the original event
|
||||
* @param causes a list of causes, where the originating causes are at the beginning
|
||||
* @param entity the target
|
||||
*/
|
||||
protected AbstractEntityEvent(Event originalEvent, List<? extends Cause<?>> causes, Entity entity) {
|
||||
super(originalEvent, causes);
|
||||
checkNotNull(entity);
|
||||
this.target = entity.getLocation();
|
||||
this.entity = entity;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new instance
|
||||
*
|
||||
* @param originalEvent the original event
|
||||
* @param causes a list of causes, where the originating causes are at the beginning
|
||||
* @param target the target
|
||||
*/
|
||||
protected AbstractEntityEvent(Event originalEvent, List<? extends Cause<?>> causes, Location target) {
|
||||
super(originalEvent, causes);
|
||||
checkNotNull(target);
|
||||
this.target = target;
|
||||
this.entity = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the target location being affected.
|
||||
*
|
||||
* @return a location
|
||||
*/
|
||||
public Location getTarget() {
|
||||
return target;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get the target entity being affected.
|
||||
*
|
||||
* @return a entity
|
||||
*/
|
||||
@Nullable
|
||||
public Entity getEntity() {
|
||||
return entity;
|
||||
}
|
||||
|
||||
}
|
@ -17,46 +17,37 @@
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.sk89q.worldguard.internal.event;
|
||||
package com.sk89q.worldguard.internal.event.entity;
|
||||
|
||||
import com.sk89q.worldguard.internal.cause.Cause;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.event.Event;
|
||||
import org.bukkit.event.HandlerList;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import java.util.List;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
/**
|
||||
* Fired when a block is interacted with.
|
||||
*/
|
||||
public class BlockInteractEvent extends AbstractInteractEvent {
|
||||
public class DestroyEntityEvent extends AbstractEntityEvent {
|
||||
|
||||
private static final HandlerList handlers = new HandlerList();
|
||||
private final Block target;
|
||||
|
||||
/**
|
||||
* Create a new instance.
|
||||
*
|
||||
* @param originalEvent the original event
|
||||
* @param causes a list of causes, where the originating causes are at the beginning
|
||||
* @param interaction the action that is being taken
|
||||
* @param target the target block being affected
|
||||
* @param target the target entity being affected
|
||||
*/
|
||||
public BlockInteractEvent(Event originalEvent, List<? extends Cause<?>> causes, Interaction interaction, Block target) {
|
||||
super(originalEvent, causes, interaction);
|
||||
checkNotNull(target);
|
||||
this.target = target;
|
||||
public DestroyEntityEvent(Event originalEvent, List<? extends Cause<?>> causes, Entity target) {
|
||||
super(originalEvent, causes, checkNotNull(target));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the target block being affected.
|
||||
*
|
||||
* @return a block
|
||||
*/
|
||||
public Block getTarget() {
|
||||
return target;
|
||||
@Override
|
||||
@Nonnull
|
||||
public Entity getEntity() {
|
||||
return super.getEntity();
|
||||
}
|
||||
|
||||
@Override
|
@ -0,0 +1,67 @@
|
||||
/*
|
||||
* 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.internal.event.entity;
|
||||
|
||||
import com.sk89q.worldguard.internal.cause.Cause;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.event.Event;
|
||||
import org.bukkit.event.HandlerList;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
public class SpawnEntityEvent extends AbstractEntityEvent {
|
||||
|
||||
private static final HandlerList handlers = new HandlerList();
|
||||
private final EntityType effectiveType;
|
||||
|
||||
public SpawnEntityEvent(Event originalEvent, List<? extends Cause<?>> causes, Entity target) {
|
||||
super(originalEvent, causes, checkNotNull(target));
|
||||
this.effectiveType = target.getType();
|
||||
}
|
||||
|
||||
public SpawnEntityEvent(Event originalEvent, List<? extends Cause<?>> causes, Location location, EntityType type) {
|
||||
super(originalEvent, causes, location);
|
||||
checkNotNull(type);
|
||||
this.effectiveType = type;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the effective entity type of the spawned entity.
|
||||
*
|
||||
* @return the effective type
|
||||
*/
|
||||
public EntityType getEffectiveType() {
|
||||
return effectiveType;
|
||||
}
|
||||
|
||||
@Override
|
||||
public HandlerList getHandlers() {
|
||||
return handlers;
|
||||
}
|
||||
|
||||
public static HandlerList getHandlerList() {
|
||||
return handlers;
|
||||
}
|
||||
|
||||
}
|
@ -17,13 +17,14 @@
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.sk89q.worldguard.internal.event;
|
||||
package com.sk89q.worldguard.internal.event.entity;
|
||||
|
||||
import com.sk89q.worldguard.internal.cause.Cause;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.event.Event;
|
||||
import org.bukkit.event.HandlerList;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import java.util.List;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
@ -31,32 +32,25 @@
|
||||
/**
|
||||
* Fired when an entity is interacted with.
|
||||
*/
|
||||
public class EntityInteractEvent extends AbstractInteractEvent {
|
||||
public class UseEntityEvent extends AbstractEntityEvent {
|
||||
|
||||
private static final HandlerList handlers = new HandlerList();
|
||||
private final Entity target;
|
||||
|
||||
/**
|
||||
* Create a new instance.
|
||||
*
|
||||
* @param originalEvent the original event
|
||||
* @param causes a list of causes, where the originating causes are at the beginning
|
||||
* @param interaction the action that is being taken
|
||||
* @param target the target entity being affected
|
||||
*/
|
||||
public EntityInteractEvent(Event originalEvent, List<? extends Cause<?>> causes, Interaction interaction, Entity target) {
|
||||
super(originalEvent, causes, interaction);
|
||||
checkNotNull(target);
|
||||
this.target = target;
|
||||
public UseEntityEvent(Event originalEvent, List<? extends Cause<?>> causes, Entity target) {
|
||||
super(originalEvent, causes, checkNotNull(target));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the target entity.
|
||||
*
|
||||
* @return the target entity
|
||||
*/
|
||||
public Entity getTarget() {
|
||||
return target;
|
||||
@Override
|
||||
@Nonnull
|
||||
public Entity getEntity() {
|
||||
return super.getEntity();
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -67,4 +61,5 @@ public HandlerList getHandlers() {
|
||||
public static HandlerList getHandlerList() {
|
||||
return handlers;
|
||||
}
|
||||
|
||||
}
|
@ -17,9 +17,10 @@
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.sk89q.worldguard.internal.event;
|
||||
package com.sk89q.worldguard.internal.event.inventory;
|
||||
|
||||
import com.sk89q.worldguard.internal.cause.Cause;
|
||||
import com.sk89q.worldguard.internal.event.AbstractInteractEvent;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.event.Event;
|
||||
import org.bukkit.event.HandlerList;
|
||||
@ -32,7 +33,7 @@
|
||||
/**
|
||||
* Fired when an item is interacted with.
|
||||
*/
|
||||
public class ItemInteractEvent extends AbstractInteractEvent {
|
||||
public class UseItemEvent extends AbstractInteractEvent {
|
||||
|
||||
private static final HandlerList handlers = new HandlerList();
|
||||
private final World world;
|
||||
@ -43,12 +44,11 @@ public class ItemInteractEvent extends AbstractInteractEvent {
|
||||
*
|
||||
* @param originalEvent the original event
|
||||
* @param causes a list of causes, where the originating causes are at the beginning
|
||||
* @param interaction the action that is being taken
|
||||
* @param world the world
|
||||
* @param itemStack the item
|
||||
*/
|
||||
public ItemInteractEvent(Event originalEvent, List<? extends Cause<?>> causes, Interaction interaction, World world, ItemStack itemStack) {
|
||||
super(originalEvent, causes, interaction);
|
||||
public UseItemEvent(Event originalEvent, List<? extends Cause<?>> causes, World world, ItemStack itemStack) {
|
||||
super(originalEvent, causes);
|
||||
checkNotNull(world);
|
||||
checkNotNull(itemStack);
|
||||
this.world = world;
|
@ -19,16 +19,37 @@
|
||||
|
||||
package com.sk89q.worldguard.internal.listener;
|
||||
|
||||
import com.sk89q.worldguard.LocalPlayer;
|
||||
import com.sk89q.worldguard.blacklist.event.BlockBreakBlacklistEvent;
|
||||
import com.sk89q.worldguard.blacklist.event.BlockDispenseBlacklistEvent;
|
||||
import com.sk89q.worldguard.blacklist.event.BlockInteractBlacklistEvent;
|
||||
import com.sk89q.worldguard.blacklist.event.BlockPlaceBlacklistEvent;
|
||||
import com.sk89q.worldguard.blacklist.event.ItemAcquireBlacklistEvent;
|
||||
import com.sk89q.worldguard.blacklist.event.ItemDestroyWithBlacklistEvent;
|
||||
import com.sk89q.worldguard.blacklist.event.ItemDropBlacklistEvent;
|
||||
import com.sk89q.worldguard.blacklist.event.ItemUseBlacklistEvent;
|
||||
import com.sk89q.worldguard.bukkit.ConfigurationManager;
|
||||
import com.sk89q.worldguard.bukkit.WorldConfiguration;
|
||||
import com.sk89q.worldguard.bukkit.WorldGuardPlugin;
|
||||
import com.sk89q.worldguard.bukkit.util.Materials;
|
||||
import com.sk89q.worldguard.internal.cause.Causes;
|
||||
import com.sk89q.worldguard.internal.event.BlockInteractEvent;
|
||||
import com.sk89q.worldguard.internal.event.block.BreakBlockEvent;
|
||||
import com.sk89q.worldguard.internal.event.block.PlaceBlockEvent;
|
||||
import com.sk89q.worldguard.internal.event.block.UseBlockEvent;
|
||||
import com.sk89q.worldguard.internal.event.entity.DestroyEntityEvent;
|
||||
import com.sk89q.worldguard.internal.event.entity.SpawnEntityEvent;
|
||||
import com.sk89q.worldguard.internal.event.inventory.UseItemEvent;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.Item;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.block.BlockDispenseEvent;
|
||||
import org.bukkit.event.player.PlayerDropItemEvent;
|
||||
import org.bukkit.event.player.PlayerPickupItemEvent;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import static com.sk89q.worldguard.bukkit.BukkitUtil.createTarget;
|
||||
import static com.sk89q.worldguard.bukkit.BukkitUtil.toVector;
|
||||
@ -48,9 +69,15 @@ public BlacklistListener(WorldGuardPlugin plugin) {
|
||||
}
|
||||
|
||||
@EventHandler(ignoreCancelled = true)
|
||||
public void handleBlockInteract(BlockInteractEvent event) {
|
||||
public void onBreakBlock(BreakBlockEvent event) {
|
||||
Player player = Causes.getInvolvedPlayer(event.getCauses());
|
||||
Block target = event.getTarget();
|
||||
|
||||
if (player == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
LocalPlayer localPlayer = getPlugin().wrapPlayer(player);
|
||||
Block target = event.getBlock();
|
||||
WorldConfiguration wcfg = getWorldConfig(player);
|
||||
|
||||
// Blacklist guard
|
||||
@ -58,31 +85,173 @@ public void handleBlockInteract(BlockInteractEvent event) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (player != null) {
|
||||
switch (event.getInteraction()) {
|
||||
case BREAK:
|
||||
if (!wcfg.getBlacklist().check(
|
||||
new BlockBreakBlacklistEvent(getPlugin().wrapPlayer(player), toVector(target), createTarget(target)), false, false)) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
if (!wcfg.getBlacklist().check(
|
||||
new BlockBreakBlacklistEvent(localPlayer, toVector(event.getTarget()), createTarget(target, event.getEffectiveMaterial())), false, false)) {
|
||||
event.setCancelled(true);
|
||||
} else if (!wcfg.getBlacklist().check(
|
||||
new ItemDestroyWithBlacklistEvent(localPlayer, toVector(event.getTarget()), createTarget(player.getItemInHand())), false, false)) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
|
||||
if (!wcfg.getBlacklist().check(
|
||||
new ItemDestroyWithBlacklistEvent(getPlugin().wrapPlayer(player), toVector(target), createTarget(player.getItemInHand())), false, false)) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
@EventHandler(ignoreCancelled = true)
|
||||
public void onPlaceBlock(PlaceBlockEvent event) {
|
||||
Player player = Causes.getInvolvedPlayer(event.getCauses());
|
||||
|
||||
break;
|
||||
if (player == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
case PLACE:
|
||||
if (!wcfg.getBlacklist().check(
|
||||
new BlockPlaceBlacklistEvent(getPlugin().wrapPlayer(player), toVector(target), createTarget(target)), false, false)) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
LocalPlayer localPlayer = getPlugin().wrapPlayer(player);
|
||||
Block target = event.getBlock();
|
||||
WorldConfiguration wcfg = getWorldConfig(player);
|
||||
|
||||
break;
|
||||
// Blacklist guard
|
||||
if (wcfg.getBlacklist() == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!wcfg.getBlacklist().check(new BlockPlaceBlacklistEvent(
|
||||
localPlayer, toVector(event.getTarget()), createTarget(target, event.getEffectiveMaterial())), false, false)) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(ignoreCancelled = true)
|
||||
public void onUseBlock(UseBlockEvent event) {
|
||||
Player player = Causes.getInvolvedPlayer(event.getCauses());
|
||||
|
||||
if (player == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
LocalPlayer localPlayer = getPlugin().wrapPlayer(player);
|
||||
Block target = event.getBlock();
|
||||
WorldConfiguration wcfg = getWorldConfig(player);
|
||||
|
||||
// Blacklist guard
|
||||
if (wcfg.getBlacklist() == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!wcfg.getBlacklist().check(new BlockInteractBlacklistEvent(
|
||||
localPlayer, toVector(event.getTarget()), createTarget(target, event.getEffectiveMaterial())), false, false)) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(ignoreCancelled = true)
|
||||
public void onSpawnEntity(SpawnEntityEvent event) {
|
||||
Player player = Causes.getInvolvedPlayer(event.getCauses());
|
||||
|
||||
if (player == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
LocalPlayer localPlayer = getPlugin().wrapPlayer(player);
|
||||
WorldConfiguration wcfg = getWorldConfig(player);
|
||||
|
||||
// Blacklist guard
|
||||
if (wcfg.getBlacklist() == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
Material material = Materials.getRelatedMaterial(event.getEffectiveType());
|
||||
if (material != null) {
|
||||
if (!wcfg.getBlacklist().check(new ItemUseBlacklistEvent(localPlayer, toVector(event.getTarget()), createTarget(material)), false, false)) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(ignoreCancelled = true)
|
||||
public void onDestroyEntity(DestroyEntityEvent event) {
|
||||
Player player = Causes.getInvolvedPlayer(event.getCauses());
|
||||
|
||||
if (player == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
LocalPlayer localPlayer = getPlugin().wrapPlayer(player);
|
||||
Entity target = event.getEntity();
|
||||
WorldConfiguration wcfg = getWorldConfig(player);
|
||||
|
||||
// Blacklist guard
|
||||
if (wcfg.getBlacklist() == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
Material material = Materials.getRelatedMaterial(target.getType());
|
||||
if (material != null) {
|
||||
// Not really a block but we only have one on-break blacklist event
|
||||
if (!wcfg.getBlacklist().check(new BlockBreakBlacklistEvent(localPlayer, toVector(event.getTarget()), createTarget(material)), false, false)) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(ignoreCancelled = true)
|
||||
public void onUseItem(UseItemEvent event) {
|
||||
Player player = Causes.getInvolvedPlayer(event.getCauses());
|
||||
|
||||
if (player == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
LocalPlayer localPlayer = getPlugin().wrapPlayer(player);
|
||||
ItemStack target = event.getItemStack();
|
||||
WorldConfiguration wcfg = getWorldConfig(player);
|
||||
|
||||
// Blacklist guard
|
||||
if (wcfg.getBlacklist() == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!wcfg.getBlacklist().check(new ItemUseBlacklistEvent(localPlayer, toVector(player.getLocation()), createTarget(target)), false, false)) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(ignoreCancelled = true)
|
||||
public void onPlayerDropItem(PlayerDropItemEvent event) {
|
||||
ConfigurationManager cfg = getPlugin().getGlobalStateManager();
|
||||
WorldConfiguration wcfg = cfg.get(event.getPlayer().getWorld());
|
||||
|
||||
if (wcfg.getBlacklist() != null) {
|
||||
Item ci = event.getItemDrop();
|
||||
|
||||
if (!wcfg.getBlacklist().check(
|
||||
new ItemDropBlacklistEvent(getPlugin().wrapPlayer(event.getPlayer()),
|
||||
toVector(ci.getLocation()), createTarget(ci.getItemStack())), false, false)) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
|
||||
public void onPlayerPickupItem(PlayerPickupItemEvent event) {
|
||||
ConfigurationManager cfg = getPlugin().getGlobalStateManager();
|
||||
WorldConfiguration wcfg = cfg.get(event.getPlayer().getWorld());
|
||||
|
||||
if (wcfg.getBlacklist() != null) {
|
||||
Item ci = event.getItem();
|
||||
|
||||
if (!wcfg.getBlacklist().check(
|
||||
new ItemAcquireBlacklistEvent(getPlugin().wrapPlayer(event.getPlayer()),
|
||||
toVector(ci.getLocation()), createTarget(ci.getItemStack())), false, true)) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(ignoreCancelled = true)
|
||||
public void onBlockDispense(BlockDispenseEvent event) {
|
||||
ConfigurationManager cfg = getPlugin().getGlobalStateManager();
|
||||
WorldConfiguration wcfg = cfg.get(event.getBlock().getWorld());
|
||||
|
||||
if (wcfg.getBlacklist() != null) {
|
||||
if (!wcfg.getBlacklist().check(new BlockDispenseBlacklistEvent(null, toVector(event.getBlock()), createTarget(event.getItem())), false, false)) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -24,7 +24,7 @@
|
||||
import com.sk89q.worldguard.bukkit.WorldConfiguration;
|
||||
import com.sk89q.worldguard.bukkit.WorldGuardPlugin;
|
||||
import com.sk89q.worldguard.internal.cause.Causes;
|
||||
import com.sk89q.worldguard.internal.event.ItemInteractEvent;
|
||||
import com.sk89q.worldguard.internal.event.inventory.UseItemEvent;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
@ -49,7 +49,7 @@ public BlockedPotionsListener(WorldGuardPlugin plugin) {
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onItemInteract(ItemInteractEvent event) {
|
||||
public void onItemInteract(UseItemEvent event) {
|
||||
// We only care about player caused events
|
||||
if (!Causes.mayInvolvePlayer(event.getCauses())) {
|
||||
return;
|
||||
|
@ -19,15 +19,18 @@
|
||||
|
||||
package com.sk89q.worldguard.internal.listener;
|
||||
|
||||
import com.sk89q.worldedit.blocks.BlockID;
|
||||
import com.sk89q.worldguard.bukkit.WorldConfiguration;
|
||||
import com.sk89q.worldguard.bukkit.WorldGuardPlugin;
|
||||
import com.sk89q.worldguard.internal.cause.Causes;
|
||||
import com.sk89q.worldguard.internal.event.Interaction;
|
||||
import com.sk89q.worldguard.internal.event.BlockInteractEvent;
|
||||
import com.sk89q.worldguard.internal.event.block.BreakBlockEvent;
|
||||
import com.sk89q.worldguard.internal.event.block.PlaceBlockEvent;
|
||||
import com.sk89q.worldguard.internal.event.block.UseBlockEvent;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.block.SignChangeEvent;
|
||||
|
||||
/**
|
||||
* Handle events that need to be processed by the chest protection.
|
||||
@ -44,31 +47,126 @@ public ChestProtectionListener(WorldGuardPlugin plugin) {
|
||||
}
|
||||
|
||||
@EventHandler(ignoreCancelled = true)
|
||||
public void handleBlockInteract(BlockInteractEvent event) {
|
||||
public void onPlaceBlock(PlaceBlockEvent event) {
|
||||
Player player = Causes.getInvolvedPlayer(event.getCauses());
|
||||
Block target = event.getTarget();
|
||||
WorldConfiguration wcfg = getWorldConfig(player);
|
||||
|
||||
// Early guard
|
||||
if (!wcfg.signChestProtection) {
|
||||
return;
|
||||
}
|
||||
Location target = event.getTarget();
|
||||
|
||||
if (player != null) {
|
||||
if (wcfg.isChestProtected(target, player)) {
|
||||
player.sendMessage(ChatColor.DARK_RED + "This chest is protected.");
|
||||
event.setCancelled(true);
|
||||
WorldConfiguration wcfg = getWorldConfig(player);
|
||||
|
||||
// Early guard
|
||||
if (!wcfg.signChestProtection) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (event.getInteraction() == Interaction.PLACE) {
|
||||
if (wcfg.getChestProtection().isChest(target.getTypeId())) {
|
||||
if (wcfg.isAdjacentChestProtected(target, player)) {
|
||||
player.sendMessage(ChatColor.DARK_RED + "This spot is for a chest that you don't have permission for.");
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
if (wcfg.getChestProtection().isChest(event.getEffectiveMaterial().getId()) && wcfg.isChestProtected(target.getBlock(), player)) {
|
||||
player.sendMessage(ChatColor.DARK_RED + "This spot is for a chest that you don't have permission for.");
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(ignoreCancelled = true)
|
||||
public void onBreakBlock(BreakBlockEvent event) {
|
||||
Player player = Causes.getInvolvedPlayer(event.getCauses());
|
||||
Location target = event.getTarget();
|
||||
|
||||
if (player != null) {
|
||||
WorldConfiguration wcfg = getWorldConfig(player);
|
||||
|
||||
// Early guard
|
||||
if (!wcfg.signChestProtection) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (wcfg.isChestProtected(target.getBlock(), player)) {
|
||||
player.sendMessage(ChatColor.DARK_RED + "This chest is protected.");
|
||||
event.setCancelled(true);
|
||||
}
|
||||
} else {
|
||||
// No player? Deny anyway
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(ignoreCancelled = true)
|
||||
public void onUseBlock(UseBlockEvent event) {
|
||||
Player player = Causes.getInvolvedPlayer(event.getCauses());
|
||||
Location target = event.getTarget();
|
||||
|
||||
if (player != null) {
|
||||
WorldConfiguration wcfg = getWorldConfig(player);
|
||||
|
||||
// Early guard
|
||||
if (!wcfg.signChestProtection) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (wcfg.isChestProtected(target.getBlock(), player)) {
|
||||
player.sendMessage(ChatColor.DARK_RED + "This chest is protected.");
|
||||
event.setCancelled(true);
|
||||
}
|
||||
} else {
|
||||
// No player? Deny anyway
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(ignoreCancelled = true)
|
||||
public void onSignChange(SignChangeEvent event) {
|
||||
Player player = event.getPlayer();
|
||||
WorldConfiguration wcfg = getWorldConfig(player);
|
||||
|
||||
if (wcfg.signChestProtection) {
|
||||
if (event.getLine(0).equalsIgnoreCase("[Lock]")) {
|
||||
if (wcfg.isChestProtectedPlacement(event.getBlock(), player)) {
|
||||
player.sendMessage(ChatColor.DARK_RED + "You do not own the adjacent chest.");
|
||||
event.getBlock().breakNaturally();
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
|
||||
if (event.getBlock().getTypeId() != BlockID.SIGN_POST) {
|
||||
player.sendMessage(ChatColor.RED
|
||||
+ "The [Lock] sign must be a sign post, not a wall sign.");
|
||||
|
||||
event.getBlock().breakNaturally();
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!event.getLine(1).equalsIgnoreCase(player.getName())) {
|
||||
player.sendMessage(ChatColor.RED
|
||||
+ "The first owner line must be your name.");
|
||||
|
||||
event.getBlock().breakNaturally();
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
|
||||
int below = event.getBlock().getRelative(0, -1, 0).getTypeId();
|
||||
|
||||
if (below == BlockID.TNT || below == BlockID.SAND
|
||||
|| below == BlockID.GRAVEL || below == BlockID.SIGN_POST) {
|
||||
player.sendMessage(ChatColor.RED
|
||||
+ "That is not a safe block that you're putting this sign on.");
|
||||
|
||||
event.getBlock().breakNaturally();
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
|
||||
event.setLine(0, "[Lock]");
|
||||
player.sendMessage(ChatColor.YELLOW
|
||||
+ "A chest or double chest above is now protected.");
|
||||
}
|
||||
} else if (!wcfg.disableSignChestProtectionCheck) {
|
||||
if (event.getLine(0).equalsIgnoreCase("[Lock]")) {
|
||||
player.sendMessage(ChatColor.RED
|
||||
+ "WorldGuard's sign chest protection is disabled.");
|
||||
|
||||
event.getBlock().breakNaturally();
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -20,12 +20,22 @@
|
||||
package com.sk89q.worldguard.internal.listener;
|
||||
|
||||
import com.sk89q.worldguard.bukkit.WorldGuardPlugin;
|
||||
import com.sk89q.worldguard.bukkit.util.Entities;
|
||||
import com.sk89q.worldguard.bukkit.util.Materials;
|
||||
import com.sk89q.worldguard.bukkit.util.RegionQuery;
|
||||
import com.sk89q.worldguard.internal.cause.Causes;
|
||||
import com.sk89q.worldguard.internal.event.Interaction;
|
||||
import com.sk89q.worldguard.internal.event.BlockInteractEvent;
|
||||
import com.sk89q.worldguard.internal.event.block.BreakBlockEvent;
|
||||
import com.sk89q.worldguard.internal.event.block.PlaceBlockEvent;
|
||||
import com.sk89q.worldguard.internal.event.block.UseBlockEvent;
|
||||
import com.sk89q.worldguard.internal.event.entity.DestroyEntityEvent;
|
||||
import com.sk89q.worldguard.internal.event.entity.SpawnEntityEvent;
|
||||
import com.sk89q.worldguard.internal.event.entity.UseEntityEvent;
|
||||
import com.sk89q.worldguard.protection.flags.DefaultFlag;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
|
||||
@ -48,23 +58,144 @@ private void tellErrorMessage(CommandSender sender, Object subject) {
|
||||
}
|
||||
|
||||
@EventHandler(ignoreCancelled = true)
|
||||
public void handleBlockInteract(BlockInteractEvent event) {
|
||||
public void onPlaceBlock(PlaceBlockEvent event) {
|
||||
Player player = Causes.getInvolvedPlayer(event.getCauses());
|
||||
Block target = event.getTarget();
|
||||
Location target = event.getTarget();
|
||||
Material type = event.getEffectiveMaterial();
|
||||
|
||||
if (player != null) {
|
||||
RegionQuery query = new RegionQuery(getPlugin(), player);
|
||||
boolean canPlace;
|
||||
|
||||
// Flint and steel, fire charge
|
||||
if (type == Material.FIRE) {
|
||||
canPlace = query.allows(DefaultFlag.LIGHTER, target) || (query.canBuild(target) && query.canConstruct(target));
|
||||
|
||||
} else {
|
||||
canPlace = query.canBuild(target) && query.canConstruct(target);
|
||||
}
|
||||
|
||||
if (!canPlace) {
|
||||
tellErrorMessage(player, target);
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(ignoreCancelled = true)
|
||||
public void onBreakBlock(BreakBlockEvent event) {
|
||||
Player player = Causes.getInvolvedPlayer(event.getCauses());
|
||||
Location target = event.getTarget();
|
||||
|
||||
if (player != null) {
|
||||
if (!getPlugin().getGlobalRegionManager().canBuild(player, target)) {
|
||||
tellErrorMessage(player, target);
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
} else if (!getPlugin().getGlobalRegionManager().canConstruct(player, target)) {
|
||||
tellErrorMessage(player, target);
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(ignoreCancelled = true)
|
||||
public void onUseBlock(UseBlockEvent event) {
|
||||
Player player = Causes.getInvolvedPlayer(event.getCauses());
|
||||
Location target = event.getTarget();
|
||||
Material type = event.getEffectiveMaterial();
|
||||
|
||||
if (player != null) {
|
||||
RegionQuery query = new RegionQuery(getPlugin(), player);
|
||||
boolean canUse;
|
||||
|
||||
// Inventory blocks (CHEST_ACCESS)
|
||||
if (Materials.isInventoryBlock(type)) {
|
||||
canUse = query.canBuild( target)
|
||||
|| query.allows(DefaultFlag.CHEST_ACCESS, target)
|
||||
|| query.allows(DefaultFlag.USE, target);
|
||||
|
||||
// Beds (SLEEP)
|
||||
} else if (type == Material.BED) {
|
||||
canUse = query.canBuild(target)
|
||||
|| query.allows(DefaultFlag.SLEEP, target)
|
||||
|| query.allows(DefaultFlag.USE, target);
|
||||
|
||||
// TNT (TNT)
|
||||
} else if (type == Material.TNT) {
|
||||
canUse = query.canBuild(target)
|
||||
|| query.allows(DefaultFlag.TNT, target);
|
||||
|
||||
// Everything else
|
||||
} else {
|
||||
canUse = query.canBuild(target)
|
||||
|| query.allows(DefaultFlag.USE, target);
|
||||
}
|
||||
|
||||
if (event.getInteraction() != Interaction.INTERACT) {
|
||||
if (!getPlugin().getGlobalRegionManager().canConstruct(player, target)) {
|
||||
tellErrorMessage(player, target);
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
if (!canUse) {
|
||||
tellErrorMessage(player, target);
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(ignoreCancelled = true)
|
||||
public void onSpawnEntity(SpawnEntityEvent event) {
|
||||
Player player = Causes.getInvolvedPlayer(event.getCauses());
|
||||
Location target = event.getTarget();
|
||||
EntityType type = event.getEffectiveType();
|
||||
|
||||
if (player != null) {
|
||||
RegionQuery query = new RegionQuery(getPlugin(), player);
|
||||
boolean canSpawn;
|
||||
|
||||
if (Entities.isVehicle(type)) {
|
||||
canSpawn = query.canBuild(target) || query.allows(DefaultFlag.PLACE_VEHICLE, target);
|
||||
} else {
|
||||
canSpawn = query.canBuild(target);
|
||||
}
|
||||
|
||||
if (!canSpawn) {
|
||||
tellErrorMessage(player, target);
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(ignoreCancelled = true)
|
||||
public void onDestroyEntity(DestroyEntityEvent event) {
|
||||
Player player = Causes.getInvolvedPlayer(event.getCauses());
|
||||
Location target = event.getTarget();
|
||||
EntityType type = event.getEntity().getType();
|
||||
|
||||
if (player != null) {
|
||||
RegionQuery query = new RegionQuery(getPlugin(), player);
|
||||
boolean canDestroy;
|
||||
|
||||
if (Entities.isVehicle(type)) {
|
||||
canDestroy = query.canBuild(target) || query.allows(DefaultFlag.DESTROY_VEHICLE, target);
|
||||
} else {
|
||||
canDestroy = query.canBuild(target);
|
||||
}
|
||||
|
||||
if (!canDestroy) {
|
||||
tellErrorMessage(player, target);
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(ignoreCancelled = true)
|
||||
public void onUseEntity(UseEntityEvent event) {
|
||||
Player player = Causes.getInvolvedPlayer(event.getCauses());
|
||||
Location target = event.getTarget();
|
||||
|
||||
if (player != null) {
|
||||
RegionQuery query = new RegionQuery(getPlugin(), player);
|
||||
boolean canUse = query.canBuild(target) || query.allows(DefaultFlag.USE, target);
|
||||
|
||||
if (!canUse) {
|
||||
tellErrorMessage(player, target);
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user