use of org.bukkit.event.hanging.HangingBreakByEntityEvent in project Denizen-For-Bukkit by DenizenScript.
the class HangingBreaksScriptEvent method onHangingBreaks.
@EventHandler
public void onHangingBreaks(HangingBreakEvent event) {
hanging = new dEntity(event.getEntity());
cause = new Element(event.getCause().name());
location = new dLocation(hanging.getLocation());
if (event instanceof HangingBreakByEntityEvent) {
entity = new dEntity(((HangingBreakByEntityEvent) event).getRemover());
}
cuboids = new dList();
for (dCuboid cuboid : dCuboid.getNotableCuboidsContaining(location)) {
cuboids.add(cuboid.identifySimple());
}
cancelled = event.isCancelled();
this.event = event;
fire();
event.setCancelled(cancelled);
}
use of org.bukkit.event.hanging.HangingBreakByEntityEvent in project Towny by ElgarL.
the class TownyEntityListener method onHangingBreak.
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
public void onHangingBreak(HangingBreakEvent event) {
if (plugin.isError()) {
event.setCancelled(true);
return;
}
TownyWorld townyWorld = null;
String worldName = null;
Entity hanging = event.getEntity();
try {
worldName = hanging.getWorld().getName();
townyWorld = TownyUniverse.getDataSource().getWorld(worldName);
if (!townyWorld.isUsingTowny())
return;
} catch (NotRegisteredException e1) {
// event.setCancelled(true);
return;
}
if (event instanceof HangingBreakByEntityEvent) {
HangingBreakByEntityEvent evt = (HangingBreakByEntityEvent) event;
Object remover = evt.getRemover();
/*
* Check if this has a shooter.
*/
if (remover instanceof Projectile) {
remover = ((Projectile) remover).getShooter();
}
if (remover instanceof Player) {
Player player = (Player) remover;
// Get destroy permissions (updates if none exist)
boolean bDestroy = PlayerCacheUtil.getCachePermission(player, hanging.getLocation(), 321, (byte) 0, TownyPermission.ActionType.DESTROY);
// Allow the removal if we are permitted
if (bDestroy)
return;
/*
* Fetch the players cache
*/
PlayerCache cache = plugin.getCache(player);
event.setCancelled(true);
if (cache.hasBlockErrMsg())
TownyMessaging.sendErrorMsg(player, cache.getBlockErrMsg());
} else {
// Explosions are blocked in this plot
if (!locationCanExplode(townyWorld, hanging.getLocation()))
event.setCancelled(true);
}
} else {
switch(event.getCause()) {
case EXPLOSION:
if (!locationCanExplode(townyWorld, event.getEntity().getLocation()))
event.setCancelled(true);
break;
default:
}
}
}
use of org.bukkit.event.hanging.HangingBreakByEntityEvent in project Denizen-For-Bukkit by DenizenScript.
the class HangingBreaksScriptEvent method onHangingBreaks.
@EventHandler
public void onHangingBreaks(HangingBreakEvent event) {
hanging = new EntityTag(event.getEntity());
cause = new ElementTag(event.getCause().name());
if (event instanceof HangingBreakByEntityEvent) {
entity = new EntityTag(((HangingBreakByEntityEvent) event).getRemover());
} else {
entity = null;
}
this.event = event;
fire(event);
}
use of org.bukkit.event.hanging.HangingBreakByEntityEvent in project Glowstone by GlowstoneMC.
the class GlowItemFrame method entityInteract.
// //////////////////////////////////////////////////////////////////////////
// Overrides
@Override
public boolean entityInteract(GlowPlayer player, InteractEntityMessage message) {
if (message.getAction() == Action.INTERACT.ordinal() && message.getHandSlot() == EquipmentSlot.HAND) {
if (InventoryUtil.isEmpty(getItem())) {
ItemStack isInHand = player.getItemInHand();
if (isInHand != null) {
setItem(isInHand);
if (player.getGameMode() != GameMode.CREATIVE) {
int amount = player.getItemInHand().getAmount();
isInHand.setAmount(amount - 1);
if (isInHand.getAmount() <= 0) {
isInHand = null;
}
player.setItemInHand(isInHand);
}
}
} else {
int rot = (getRotation().ordinal() + 1) % 8;
setRotation(Rotation.values()[rot]);
}
}
if (message.getAction() == Action.ATTACK.ordinal()) {
if (isEmpty()) {
if (EventFactory.getInstance().callEvent(new HangingBreakByEntityEvent(this, player)).isCancelled()) {
return false;
}
if (player.getGameMode() != GameMode.CREATIVE) {
world.dropItemNaturally(location, new ItemStack(Material.ITEM_FRAME));
}
remove();
} else {
if (EventFactory.getInstance().callEvent(new EntityDamageByEntityEvent(player, this, DamageCause.ENTITY_ATTACK, 0)).isCancelled()) {
return false;
}
if (player.getGameMode() != GameMode.CREATIVE) {
world.dropItemNaturally(location, getItem().clone());
}
setItem(InventoryUtil.createEmptyStack());
}
}
return true;
}
Aggregations