use of com.sk89q.worldguard.bukkit.event.entity.SpawnEntityEvent in project WorldGuard by EngineHub.
the class EventAbstractionListener method onHangingPlace.
@EventHandler(ignoreCancelled = true)
public void onHangingPlace(HangingPlaceEvent event) {
Events.fireToCancel(event, new SpawnEntityEvent(event, create(event.getPlayer()), event.getEntity()));
if (event.isCancelled()) {
Block effectBlock = event.getBlock().getRelative(event.getBlockFace());
playDenyEffect(event.getPlayer(), effectBlock.getLocation().add(0.5, 0.5, 0.5));
}
}
use of com.sk89q.worldguard.bukkit.event.entity.SpawnEntityEvent in project WorldGuard by EngineHub.
the class EventAbstractionListener method handleFallingBlock.
private void handleFallingBlock(EntityChangeBlockEvent event, boolean dropItem) {
Entity entity = event.getEntity();
Block block = event.getBlock();
if (entity instanceof FallingBlock) {
try {
if (dropItem) {
FallingBlock fallingBlock = (FallingBlock) entity;
if (!fallingBlock.getDropItem())
return;
final Material material = fallingBlock.getBlockData().getMaterial();
if (!material.isItem())
return;
ItemStack itemStack = new ItemStack(material, 1);
Item item = block.getWorld().dropItem(fallingBlock.getLocation(), itemStack);
item.setVelocity(new Vector());
if (Events.fireAndTestCancel(new SpawnEntityEvent(event, create(block, entity), item))) {
item.remove();
}
}
} finally {
Cause.untrackParentCause(entity);
}
}
}
use of com.sk89q.worldguard.bukkit.event.entity.SpawnEntityEvent in project WorldGuard by EngineHub.
the class EventAbstractionListener method onExpBottle.
@EventHandler(ignoreCancelled = true)
public void onExpBottle(ExpBottleEvent event) {
if (Events.fireAndTestCancel(new SpawnEntityEvent(event, create(event.getEntity()), event.getEntity().getLocation(), EntityType.EXPERIENCE_ORB))) {
event.setExperience(0);
// Give the player back his or her XP bottle
ProjectileSource shooter = event.getEntity().getShooter();
if (shooter instanceof Player) {
Player player = (Player) shooter;
if (player.getGameMode() != GameMode.CREATIVE) {
player.getInventory().addItem(new ItemStack(Material.EXPERIENCE_BOTTLE, 1));
}
}
}
}
use of com.sk89q.worldguard.bukkit.event.entity.SpawnEntityEvent in project WorldGuard by EngineHub.
the class EventAbstractionListener method onLingeringSplash.
@EventHandler(ignoreCancelled = true)
public void onLingeringSplash(LingeringPotionSplashEvent event) {
AreaEffectCloud aec = event.getAreaEffectCloud();
ThrownPotion potion = event.getEntity();
World world = potion.getWorld();
Cause cause = create(event.getEntity());
// Fire item interaction event
Events.fireToCancel(event, new UseItemEvent(event, cause, world, potion.getItem()));
// Fire entity spawn event
if (!event.isCancelled()) {
// radius unfortunately doesn't go through with this, so only a single location is tested
Events.fireToCancel(event, new SpawnEntityEvent(event, cause, aec.getLocation().add(0.5, 0, 0.5), EntityType.AREA_EFFECT_CLOUD));
}
}
use of com.sk89q.worldguard.bukkit.event.entity.SpawnEntityEvent in project WorldGuard by EngineHub.
the class EventAbstractionListener method onEntityChangeBlock.
@EventHandler(ignoreCancelled = true)
public void onEntityChangeBlock(EntityChangeBlockEvent event) {
Block block = event.getBlock();
Entity entity = event.getEntity();
Material toType = event.getTo();
Material fromType = block.getType();
Cause cause = create(entity);
// Fire two events: one as BREAK and one as PLACE
if (toType != Material.AIR && fromType != Material.AIR) {
BreakBlockEvent breakDelagate = new BreakBlockEvent(event, cause, block);
setDelegateEventMaterialOptions(breakDelagate, fromType, toType);
boolean denied;
if (!(denied = Events.fireToCancel(event, breakDelagate))) {
PlaceBlockEvent placeDelegate = new PlaceBlockEvent(event, cause, block.getLocation(), toType);
setDelegateEventMaterialOptions(placeDelegate, fromType, toType);
denied = Events.fireToCancel(event, placeDelegate);
}
if (denied && entity instanceof Player) {
playDenyEffect((Player) entity, block.getLocation());
}
handleFallingBlock(event, denied);
} else if (toType == Material.AIR) {
// Track the source so later we can create a proper chain of causes
if (entity instanceof FallingBlock) {
Cause.trackParentCause(entity, block);
// Switch around the event
Events.fireToCancel(event, new SpawnEntityEvent(event, create(block), entity));
} else {
entityBreakBlockDebounce.debounce(block, event.getEntity(), event, new BreakBlockEvent(event, cause, block));
}
} else {
// toType != Material.AIR && fromType == Material.AIR
boolean denied = Events.fireToCancel(event, new PlaceBlockEvent(event, cause, block.getLocation(), toType));
handleFallingBlock(event, denied);
}
}
Aggregations