mirror of
https://github.com/EngineHub/WorldGuard.git
synced 2024-12-18 15:17:36 +01:00
Fixed a bunch of small bugs
This commit is contained in:
parent
2eb6c76da8
commit
e9402c55e6
@ -33,6 +33,7 @@
|
||||
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;
|
||||
import org.bukkit.event.block.BlockFromToEvent;
|
||||
@ -139,7 +140,7 @@ public void onBlockBreak(BlockBreakEvent event) {
|
||||
if (held.getTypeId() > 0
|
||||
&& !(ItemType.usesDamageValue(held.getTypeId())
|
||||
|| BlockType.usesData(held.getTypeId()))) {
|
||||
held.setDurability((short) -1);
|
||||
held.setDurability(Material.getMaterial(held.getTypeId()).getMaxDurability());
|
||||
player.setItemInHand(held);
|
||||
}
|
||||
}
|
||||
@ -872,4 +873,17 @@ public void onBlockDispense(BlockDispenseEvent event) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Called when a block yields exp
|
||||
*/
|
||||
@EventHandler(priority = EventPriority.HIGH)
|
||||
public void onBlockExp(BlockExpEvent event) {
|
||||
ConfigurationManager cfg = plugin.getGlobalStateManager();
|
||||
WorldConfiguration wcfg = cfg.get(event.getBlock().getWorld());
|
||||
if (wcfg.disableExpDrops) {
|
||||
event.setExpToDrop(0);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -88,9 +88,6 @@
|
||||
public class WorldGuardEntityListener implements Listener {
|
||||
|
||||
private WorldGuardPlugin plugin;
|
||||
private EntityType fireballType;
|
||||
private EntityType witherType;
|
||||
private EntityType witherSkullType;
|
||||
|
||||
/**
|
||||
* Construct the object;
|
||||
@ -99,10 +96,6 @@ public class WorldGuardEntityListener implements Listener {
|
||||
*/
|
||||
public WorldGuardEntityListener(WorldGuardPlugin plugin) {
|
||||
this.plugin = plugin;
|
||||
|
||||
fireballType = BukkitUtil.tryEnum(EntityType.class, "LARGE_FIREBALL", "FIREBALL");
|
||||
witherType = BukkitUtil.tryEnum(EntityType.class, "WITHER");
|
||||
witherSkullType = BukkitUtil.tryEnum(EntityType.class, "WITHER_SKULL");
|
||||
}
|
||||
|
||||
/**
|
||||
@ -563,20 +556,71 @@ public void onEntityExplode(EntityExplodeEvent event) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Not all explosions come from an entity
|
||||
if (ent != null) {
|
||||
if (ent instanceof Wither) {
|
||||
if (wcfg.blockWitherBlockDamage) {
|
||||
event.blockList().clear();
|
||||
return;
|
||||
}
|
||||
|
||||
if (wcfg.blockWitherExplosions) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
if (ent instanceof Creeper) {
|
||||
if (wcfg.blockCreeperBlockDamage) {
|
||||
event.blockList().clear();
|
||||
return;
|
||||
}
|
||||
|
||||
if (wcfg.blockCreeperExplosions) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
|
||||
if (wcfg.useRegions) {
|
||||
if (wcfg.useRegions) {
|
||||
RegionManager mgr = plugin.getGlobalRegionManager().get(world);
|
||||
|
||||
for (Block block : event.blockList()) {
|
||||
if (!mgr.getApplicableRegions(toVector(block)).allows(DefaultFlag.CREEPER_EXPLOSION)) {
|
||||
event.blockList().clear();
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} else if (ent instanceof EnderDragon) {
|
||||
if (wcfg.blockEnderDragonBlockDamage) {
|
||||
event.blockList().clear();
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
|
||||
if (wcfg.useRegions) {
|
||||
RegionManager mgr = plugin.getGlobalRegionManager().get(world);
|
||||
|
||||
for (Block block : event.blockList()) {
|
||||
if (!mgr.getApplicableRegions(toVector(block)).allows(DefaultFlag.ENDERDRAGON_BLOCK_DAMAGE)) {
|
||||
event.blockList().clear();
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
} else if (ent instanceof TNTPrimed) {
|
||||
if (wcfg.blockTNTBlockDamage) {
|
||||
event.blockList().clear();
|
||||
return;
|
||||
}
|
||||
|
||||
if (wcfg.blockTNTExplosions) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
|
||||
if (wcfg.useRegions) {
|
||||
RegionManager mgr = plugin.getGlobalRegionManager().get(world);
|
||||
|
||||
for (Block block : event.blockList()) {
|
||||
if (!mgr.getApplicableRegions(toVector(block)).allows(DefaultFlag.TNT)) {
|
||||
event.blockList().clear();
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
} else if (ent instanceof Fireball) {
|
||||
if (ent instanceof WitherSkull) {
|
||||
if (wcfg.blockWitherSkullBlockDamage) {
|
||||
event.blockList().clear();
|
||||
@ -587,73 +631,7 @@ public void onEntityExplode(EntityExplodeEvent event) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (ent instanceof Creeper) {
|
||||
if (wcfg.blockCreeperBlockDamage) {
|
||||
event.blockList().clear();
|
||||
return;
|
||||
}
|
||||
|
||||
if (wcfg.blockCreeperExplosions) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
|
||||
if (wcfg.useRegions) {
|
||||
if (wcfg.useRegions) {
|
||||
RegionManager mgr = plugin.getGlobalRegionManager().get(world);
|
||||
|
||||
for (Block block : event.blockList()) {
|
||||
if (!mgr.getApplicableRegions(toVector(block)).allows(DefaultFlag.CREEPER_EXPLOSION)) {
|
||||
event.blockList().clear();
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} else if (ent instanceof EnderDragon) {
|
||||
if (wcfg.blockEnderDragonBlockDamage) {
|
||||
event.blockList().clear();
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
|
||||
if (wcfg.useRegions) {
|
||||
RegionManager mgr = plugin.getGlobalRegionManager().get(world);
|
||||
|
||||
for (Block block : event.blockList()) {
|
||||
if (!mgr.getApplicableRegions(toVector(block)).allows(DefaultFlag.ENDERDRAGON_BLOCK_DAMAGE)) {
|
||||
event.blockList().clear();
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
} else if (ent instanceof TNTPrimed) {
|
||||
if (wcfg.blockTNTBlockDamage) {
|
||||
event.blockList().clear();
|
||||
return;
|
||||
}
|
||||
|
||||
if (wcfg.blockTNTExplosions) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
|
||||
if (wcfg.useRegions) {
|
||||
RegionManager mgr = plugin.getGlobalRegionManager().get(world);
|
||||
|
||||
for (Block block : event.blockList()) {
|
||||
if (!mgr.getApplicableRegions(toVector(block)).allows(DefaultFlag.TNT)) {
|
||||
event.blockList().clear();
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
} else if (ent instanceof Fireball && !(ent instanceof WitherSkull)) {
|
||||
} else {
|
||||
if (wcfg.blockFireballBlockDamage) {
|
||||
event.blockList().clear();
|
||||
return;
|
||||
@ -663,21 +641,31 @@ public void onEntityExplode(EntityExplodeEvent event) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
// allow wither skull blocking since there is no dedicated flag atm
|
||||
if (wcfg.useRegions) {
|
||||
RegionManager mgr = plugin.getGlobalRegionManager().get(world);
|
||||
|
||||
if (wcfg.useRegions) {
|
||||
RegionManager mgr = plugin.getGlobalRegionManager().get(world);
|
||||
|
||||
for (Block block : event.blockList()) {
|
||||
if (!mgr.getApplicableRegions(toVector(block)).allows(DefaultFlag.GHAST_FIREBALL)) {
|
||||
event.blockList().clear();
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
for (Block block : event.blockList()) {
|
||||
if (!mgr.getApplicableRegions(toVector(block)).allows(DefaultFlag.GHAST_FIREBALL)) {
|
||||
event.blockList().clear();
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
} else if (ent instanceof Wither) {
|
||||
if (wcfg.blockWitherBlockDamage) {
|
||||
event.blockList().clear();
|
||||
return;
|
||||
}
|
||||
|
||||
if (wcfg.blockWitherExplosions) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
// null entity, caused by another plugin or so
|
||||
// unhandled entity
|
||||
if (wcfg.blockOtherExplosions) {
|
||||
event.blockList().clear();
|
||||
event.setCancelled(true);
|
||||
@ -694,6 +682,7 @@ public void onEntityExplode(EntityExplodeEvent event) {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (wcfg.signChestProtection) {
|
||||
for (Block block : event.blockList()) {
|
||||
if (wcfg.isChestProtected(block)) {
|
||||
@ -720,31 +709,27 @@ public void onExplosionPrime(ExplosionPrimeEvent event) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (event.getEntityType() == witherType) {
|
||||
if (event.getEntityType() == EntityType.WITHER) {
|
||||
if (wcfg.blockWitherExplosions) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
else if (event.getEntityType() == witherSkullType) {
|
||||
} else if (event.getEntityType() == EntityType.WITHER_SKULL) {
|
||||
if (wcfg.blockWitherSkullExplosions) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
else if (event.getEntityType() == fireballType) {
|
||||
} else if (event.getEntityType() == EntityType.FIREBALL) {
|
||||
if (wcfg.blockFireballExplosions) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
else if (event.getEntityType() == EntityType.CREEPER) {
|
||||
} else if (event.getEntityType() == EntityType.CREEPER) {
|
||||
if (wcfg.blockCreeperExplosions) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
else if (event.getEntityType() == EntityType.PRIMED_TNT) {
|
||||
} else if (event.getEntityType() == EntityType.PRIMED_TNT) {
|
||||
if (wcfg.blockTNTExplosions) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
@ -810,7 +795,7 @@ public void onCreatePortal(EntityCreatePortalEvent event) {
|
||||
|
||||
switch (event.getEntityType()) {
|
||||
case ENDER_DRAGON:
|
||||
if (wcfg.blockEnderDragonBlockDamage) event.setCancelled(true);
|
||||
if (wcfg.blockEnderDragonPortalCreation) event.setCancelled(true);
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -856,7 +841,7 @@ public void onEntityRegainHealth(EntityRegainHealthEvent event) {
|
||||
* @param event Relevant event details
|
||||
*/
|
||||
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
|
||||
public void onEndermanPickup(EntityChangeBlockEvent event) {
|
||||
public void onEntityChangeBlock(EntityChangeBlockEvent event) {
|
||||
Entity ent = event.getEntity();
|
||||
Block block = event.getBlock();
|
||||
Location location = block.getLocation();
|
||||
@ -875,8 +860,7 @@ public void onEndermanPickup(EntityChangeBlockEvent event) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
} else if (ent.getType() == witherType) {
|
||||
|
||||
} else if (ent.getType() == EntityType.WITHER) {
|
||||
if (wcfg.blockWitherBlockDamage || wcfg.blockWitherExplosions) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
|
@ -570,7 +570,8 @@ private void handleBlockLeftClick(PlayerInteractEvent event) {
|
||||
|
||||
if (block.getRelative(event.getBlockFace()).getTypeId() == BlockID.FIRE) {
|
||||
if (!plugin.getGlobalRegionManager().hasBypass(player, world)
|
||||
&& !set.canBuild(localPlayer)) {
|
||||
&& !mgr.getApplicableRegions(block.getRelative(event.getBlockFace())
|
||||
.getLocation()).canBuild(localPlayer)) {
|
||||
event.setUseInteractedBlock(Result.DENY);
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
@ -664,7 +665,9 @@ private void handleBlockRightClick(PlayerInteractEvent event) {
|
||||
if (wcfg.useRegions) {
|
||||
Vector pt = toVector(block);
|
||||
RegionManager mgr = plugin.getGlobalRegionManager().get(world);
|
||||
Block placedIn = block.getRelative(event.getBlockFace());
|
||||
ApplicableRegionSet set = mgr.getApplicableRegions(pt);
|
||||
ApplicableRegionSet placedInSet = mgr.getApplicableRegions(placedIn.getLocation());
|
||||
LocalPlayer localPlayer = plugin.wrapPlayer(player);
|
||||
|
||||
if (item.getTypeId() == wcfg.regionWand && plugin.hasPermission(player, "worldguard.region.wand")) {
|
||||
@ -689,26 +692,28 @@ private void handleBlockRightClick(PlayerInteractEvent event) {
|
||||
return;
|
||||
}
|
||||
|
||||
Block placedOn = block.getRelative(event.getBlockFace());
|
||||
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)
|
||||
&& !plugin.getGlobalRegionManager().allows(
|
||||
DefaultFlag.TNT, placedOn.getLocation(), localPlayer)) {
|
||||
&& !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())
|
||||
&& !plugin.getGlobalRegionManager().canBuild(player, block.getLocation())) {
|
||||
&& !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 (!plugin.getGlobalRegionManager().canBuild(player, placedOn.getLocation())) {
|
||||
} 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;
|
||||
}
|
||||
@ -740,9 +745,9 @@ private void handleBlockRightClick(PlayerInteractEvent event) {
|
||||
b0 = 1;
|
||||
}
|
||||
// end mojang-level code
|
||||
Block headLoc = placedOn.getRelative(b0, 0, b1);
|
||||
Location headLoc = placedIn.getRelative(b0, 0, b1).getLocation();
|
||||
if (!plugin.getGlobalRegionManager().hasBypass(localPlayer, world)
|
||||
&& !(plugin.canBuild(player, block) && plugin.canBuild(player, headLoc))) {
|
||||
&& !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.");
|
||||
@ -751,6 +756,44 @@ private void handleBlockRightClick(PlayerInteractEvent event) {
|
||||
}
|
||||
}
|
||||
|
||||
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)
|
||||
&& !placedInSet.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.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
|
||||
@ -886,8 +929,8 @@ private void handleBlockRightClick(PlayerInteractEvent event) {
|
||||
|| item.getTypeId() == ItemID.POWERED_MINECART
|
||||
|| item.getTypeId() == ItemID.STORAGE_MINECART)) {
|
||||
if (!plugin.getGlobalRegionManager().hasBypass(player, world)
|
||||
&& !set.canBuild(localPlayer)
|
||||
&& !set.allows(DefaultFlag.PLACE_VEHICLE, localPlayer)) {
|
||||
&& !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);
|
||||
@ -897,8 +940,8 @@ private void handleBlockRightClick(PlayerInteractEvent event) {
|
||||
|
||||
if (item.getTypeId() == ItemID.WOOD_BOAT) {
|
||||
if (!plugin.getGlobalRegionManager().hasBypass(player, world)
|
||||
&& !set.canBuild(localPlayer)
|
||||
&& !set.allows(DefaultFlag.PLACE_VEHICLE, localPlayer)) {
|
||||
&& !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);
|
||||
|
Loading…
Reference in New Issue
Block a user