Merged the handlers for EndermanPickup/PlaceEvent into a EntityChangeBlockEvent handler.

This commit is contained in:
TomyLobo 2012-02-14 02:26:28 +01:00
parent 29529e4a06
commit 1d9908e1f6

View File

@ -24,12 +24,14 @@
import com.sk89q.worldedit.blocks.BlockID;
import org.bukkit.ChatColor;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.World;
import org.bukkit.block.Block;
import org.bukkit.entity.Creature;
import org.bukkit.entity.CreatureType;
import org.bukkit.entity.Creeper;
import org.bukkit.entity.EnderDragon;
import org.bukkit.entity.Enderman;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Fireball;
import org.bukkit.entity.LivingEntity;
@ -45,8 +47,7 @@
import org.bukkit.event.Listener;
import org.bukkit.event.entity.CreatureSpawnEvent;
import org.bukkit.event.entity.CreeperPowerEvent;
import org.bukkit.event.entity.EndermanPickupEvent;
import org.bukkit.event.entity.EndermanPlaceEvent;
import org.bukkit.event.entity.EntityChangeBlockEvent;
import org.bukkit.event.entity.EntityCombustEvent;
import org.bukkit.event.entity.EntityDamageByBlockEvent;
import org.bukkit.event.entity.EntityDamageByEntityEvent;
@ -814,17 +815,21 @@ public void onEntityRegainHealth(EntityRegainHealthEvent event) {
}
/**
* Called when an enderman picks a block up.
* Called when an enderman picks up or puts down a block and some other cases.
*/
@EventHandler(priority = EventPriority.HIGH)
public void onEndermanPickup(EndermanPickupEvent event) {
public void onEndermanPickup(EntityChangeBlockEvent event) {
if (event.isCancelled()) {
return;
}
Entity ent = event.getEntity();
Block block = event.getBlock();
Location location = block.getLocation();
if (ent instanceof Enderman) {
if (event.getTo() == Material.AIR) {
// pickup
ConfigurationManager cfg = plugin.getGlobalStateManager();
WorldConfiguration wcfg = cfg.get(ent.getWorld());
@ -834,25 +839,13 @@ public void onEndermanPickup(EndermanPickupEvent event) {
}
if (wcfg.useRegions) {
if (!plugin.getGlobalRegionManager().allows(DefaultFlag.ENDER_BUILD, block.getLocation())) {
if (!plugin.getGlobalRegionManager().allows(DefaultFlag.ENDER_BUILD, location)) {
event.setCancelled(true);
return;
}
}
}
/**
* Called when an enderman places a block.
*/
@EventHandler(priority = EventPriority.HIGH)
public void onEndermanPlace(EndermanPlaceEvent event) {
if (event.isCancelled()) {
return;
}
Entity ent = event.getEntity();
Location loc = event.getLocation();
} else {
// place
ConfigurationManager cfg = plugin.getGlobalStateManager();
WorldConfiguration wcfg = cfg.get(ent.getWorld());
@ -862,12 +855,14 @@ public void onEndermanPlace(EndermanPlaceEvent event) {
}
if (wcfg.useRegions) {
if (!plugin.getGlobalRegionManager().allows(DefaultFlag.ENDER_BUILD, loc)) {
if (!plugin.getGlobalRegionManager().allows(DefaultFlag.ENDER_BUILD, location)) {
event.setCancelled(true);
return;
}
}
}
}
}
@EventHandler(priority = EventPriority.HIGH)
public void onFoodLevelChange(FoodLevelChangeEvent event) {