use of com.sk89q.worldguard.bukkit.event.entity.UseEntityEvent in project WorldGuard by EngineHub.
the class EventAbstractionListener method onEntityUnleash.
@EventHandler(ignoreCancelled = true)
public void onEntityUnleash(EntityUnleashEvent event) {
if (event instanceof PlayerUnleashEntityEvent) {
PlayerUnleashEntityEvent playerEvent = (PlayerUnleashEntityEvent) event;
Events.fireToCancel(playerEvent, new UseEntityEvent(playerEvent, create(playerEvent.getPlayer()), event.getEntity()));
}
}
use of com.sk89q.worldguard.bukkit.event.entity.UseEntityEvent in project WorldGuard by EngineHub.
the class EventAbstractionListener method onPotionSplash.
@EventHandler(ignoreCancelled = true)
public void onPotionSplash(PotionSplashEvent event) {
Entity entity = event.getEntity();
ThrownPotion potion = event.getPotion();
World world = entity.getWorld();
Cause cause = create(potion);
// Fire item interaction event
Events.fireToCancel(event, new UseItemEvent(event, cause, world, potion.getItem()));
// Fire entity interaction event
if (!event.isCancelled()) {
int blocked = 0;
int affectedSize = event.getAffectedEntities().size();
boolean hasDamageEffect = Materials.hasDamageEffect(potion.getEffects());
for (LivingEntity affected : event.getAffectedEntities()) {
DelegateEvent delegate = hasDamageEffect ? new DamageEntityEvent(event, cause, affected) : new UseEntityEvent(event, cause, affected);
// Consider the potion splash flag
delegate.getRelevantFlags().add(Flags.POTION_SPLASH);
if (Events.fireAndTestCancel(delegate)) {
event.setIntensity(affected, 0);
blocked++;
}
}
if (affectedSize > 0 && blocked == affectedSize) {
// server does weird things with this if the event is modified, so use cached number
event.setCancelled(true);
}
}
}
use of com.sk89q.worldguard.bukkit.event.entity.UseEntityEvent in project WorldGuard by EngineHub.
the class EventAbstractionListener method handleInventoryHolderUse.
private static <T extends Event & Cancellable> void handleInventoryHolderUse(T originalEvent, Cause cause, InventoryHolder holder) {
if (originalEvent.isCancelled()) {
return;
}
if (holder instanceof Entity) {
Entity entity = (Entity) holder;
Material mat = Materials.getRelatedMaterial((entity).getType());
UseEntityEvent useEntityEvent = new UseEntityEvent(originalEvent, cause, entity);
if (mat != null && hasInteractBypass((entity).getWorld(), mat)) {
useEntityEvent.setAllowed(true);
}
Events.fireToCancel(originalEvent, useEntityEvent);
} else {
if (holder instanceof BlockState) {
final BlockState block = (BlockState) holder;
final UseBlockEvent useBlockEvent = new UseBlockEvent(originalEvent, cause, block.getBlock());
if (hasInteractBypass(block.getWorld(), block.getType())) {
useBlockEvent.setAllowed(true);
}
Events.fireToCancel(originalEvent, useBlockEvent);
} else if (holder instanceof DoubleChest) {
InventoryHolder left = ((DoubleChest) holder).getLeftSide();
InventoryHolder right = ((DoubleChest) holder).getRightSide();
if (left instanceof Chest) {
Events.fireToCancel(originalEvent, new UseBlockEvent(originalEvent, cause, ((Chest) left).getBlock()));
}
if (right instanceof Chest) {
Events.fireToCancel(originalEvent, new UseBlockEvent(originalEvent, cause, ((Chest) right).getBlock()));
}
}
}
}
use of com.sk89q.worldguard.bukkit.event.entity.UseEntityEvent in project WorldGuard by EngineHub.
the class EventAbstractionListener method onPlayerInteractEntity.
// -------------------------------------------------------------------------
// Entity external interaction
// -------------------------------------------------------------------------
@EventHandler(ignoreCancelled = true)
public void onPlayerInteractEntity(PlayerInteractEntityEvent event) {
Player player = event.getPlayer();
World world = player.getWorld();
ItemStack item = event.getHand() == EquipmentSlot.OFF_HAND ? player.getInventory().getItemInOffHand() : player.getInventory().getItemInMainHand();
Entity entity = event.getRightClicked();
if (Events.fireToCancel(event, new UseItemEvent(event, create(player), world, item))) {
return;
}
final UseEntityEvent useEntityEvent = new UseEntityEvent(event, create(player), entity);
Material matchingItem = Materials.getRelatedMaterial(entity.getType());
if (matchingItem != null && hasInteractBypass(world, matchingItem)) {
useEntityEvent.setAllowed(true);
}
if (!Events.fireToCancel(event, useEntityEvent)) {
// so this is a hack but CreeperIgniteEvent doesn't actually tell us who, so we need to do it here
if (item.getType() == Material.FLINT_AND_STEEL && entity.getType() == EntityType.CREEPER) {
Cause.trackParentCause(entity, player);
}
}
}
Aggregations