Search in sources :

Example 1 with PotionSplashEvent

use of org.bukkit.event.entity.PotionSplashEvent in project AncapFramework by ancap-dev.

the class ProtectListener method on.

@EventHandler(priority = EventPriority.LOW)
public void on(PotionSplashEvent e) {
    ThrownPotion potion = e.getPotion();
    Collection<LivingEntity> entities = e.getAffectedEntities();
    if (entities.size() == 0) {
        return;
    }
    ProjectileSource source = potion.getShooter();
    if (!(source instanceof Player)) {
        return;
    }
    Player player = (Player) source;
    for (Entity entity : entities) {
        Location interacted = entity.getLocation();
        this.throwEvent(e, player, interacted);
        if (entity instanceof Player) {
            Player damaged = (Player) entity;
            Event event = new AncapPVPEvent(e, player, damaged);
            this.throwEvent(event);
        }
    }
}
Also used : PotionSplashEvent(org.bukkit.event.entity.PotionSplashEvent) AncapWorldInteractEvent(ru.ancap.framework.plugin.api.events.wrapper.AncapWorldInteractEvent) AncapWorldSelfDestructEvent(ru.ancap.framework.plugin.api.events.wrapper.AncapWorldSelfDestructEvent) Event(org.bukkit.event.Event) BlockBreakEvent(org.bukkit.event.block.BlockBreakEvent) BlockClickEvent(ru.ancap.framework.plugin.api.events.additions.BlockClickEvent) AncapPVPEvent(ru.ancap.framework.plugin.api.events.wrapper.AncapPVPEvent) ProjectileLaunchEvent(org.bukkit.event.entity.ProjectileLaunchEvent) BlockPlaceEvent(org.bukkit.event.block.BlockPlaceEvent) EntityDamageByEntityEvent(org.bukkit.event.entity.EntityDamageByEntityEvent) ProjectileHitEvent(org.bukkit.event.entity.ProjectileHitEvent) AncapPVPEvent(ru.ancap.framework.plugin.api.events.wrapper.AncapPVPEvent) ProjectileSource(org.bukkit.projectiles.ProjectileSource) Location(org.bukkit.Location) EventHandler(org.bukkit.event.EventHandler)

Example 2 with PotionSplashEvent

use of org.bukkit.event.entity.PotionSplashEvent in project Mohist by MohistMC.

the class CraftEventFactory method callPotionSplashEvent.

/**
 * PotionSplashEvent
 */
public static PotionSplashEvent callPotionSplashEvent(ThrownPotion potion, Map<org.bukkit.entity.LivingEntity, Double> affectedEntities) {
    org.bukkit.entity.ThrownPotion thrownPotion = (org.bukkit.entity.ThrownPotion) potion.getBukkitEntity();
    PotionSplashEvent event = new PotionSplashEvent(thrownPotion, affectedEntities);
    Bukkit.getPluginManager().callEvent(event);
    return event;
}
Also used : ThrownPotion(net.minecraft.world.entity.projectile.ThrownPotion) LingeringPotionSplashEvent(org.bukkit.event.entity.LingeringPotionSplashEvent) PotionSplashEvent(org.bukkit.event.entity.PotionSplashEvent)

Example 3 with PotionSplashEvent

use of org.bukkit.event.entity.PotionSplashEvent in project BentoBox by BentoBoxWorld.

the class PVPListenerTest method testOnSplashPotionSplashWitch.

/**
 * Test method for {@link PVPListener#onSplashPotionSplash(org.bukkit.event.entity.PotionSplashEvent)}.
 */
@Test
public void testOnSplashPotionSplashWitch() {
    ThrownPotion tp = mock(ThrownPotion.class);
    ProjectileSource witch = mock(Witch.class);
    when(tp.getShooter()).thenReturn(witch);
    PotionSplashEvent e = new PotionSplashEvent(tp, new HashMap<>());
    new PVPListener().onSplashPotionSplash(e);
    assertFalse(e.isCancelled());
}
Also used : ThrownPotion(org.bukkit.entity.ThrownPotion) ProjectileSource(org.bukkit.projectiles.ProjectileSource) BlockProjectileSource(org.bukkit.projectiles.BlockProjectileSource) LingeringPotionSplashEvent(org.bukkit.event.entity.LingeringPotionSplashEvent) PotionSplashEvent(org.bukkit.event.entity.PotionSplashEvent) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 4 with PotionSplashEvent

use of org.bukkit.event.entity.PotionSplashEvent in project BentoBox by BentoBoxWorld.

the class PVPListenerTest method testOnSplashPotionSplashAllowPVP.

/**
 * Test method for {@link PVPListener#onSplashPotionSplash(org.bukkit.event.entity.PotionSplashEvent)}.
 */
@Test
public void testOnSplashPotionSplashAllowPVP() {
    // Disallow PVP
    when(island.isAllowed(any())).thenReturn(true);
    ThrownPotion tp = mock(ThrownPotion.class);
    when(tp.getShooter()).thenReturn(player);
    when(tp.getWorld()).thenReturn(world);
    when(tp.getLocation()).thenReturn(loc);
    // Create a damage map
    Map<LivingEntity, Double> map = new HashMap<>();
    map.put(player2, 100D);
    map.put(zombie, 100D);
    map.put(creeper, 10D);
    PotionSplashEvent e = new PotionSplashEvent(tp, map);
    new PVPListener().onSplashPotionSplash(e);
    assertTrue(e.getAffectedEntities().contains(player2));
    assertTrue(e.getAffectedEntities().contains(zombie));
    assertTrue(e.getAffectedEntities().contains(creeper));
    verify(player, never()).sendMessage(Flags.PVP_OVERWORLD.getHintReference());
}
Also used : LivingEntity(org.bukkit.entity.LivingEntity) HashMap(java.util.HashMap) ThrownPotion(org.bukkit.entity.ThrownPotion) LingeringPotionSplashEvent(org.bukkit.event.entity.LingeringPotionSplashEvent) PotionSplashEvent(org.bukkit.event.entity.PotionSplashEvent) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 5 with PotionSplashEvent

use of org.bukkit.event.entity.PotionSplashEvent in project BentoBox by BentoBoxWorld.

the class PVPListenerTest method testOnSplashPotionSplash.

/**
 * Test method for {@link PVPListener#onSplashPotionSplash(org.bukkit.event.entity.PotionSplashEvent)}.
 */
@Test
public void testOnSplashPotionSplash() {
    // Disallow PVP
    when(island.isAllowed(any())).thenReturn(false);
    ThrownPotion tp = mock(ThrownPotion.class);
    when(tp.getShooter()).thenReturn(player);
    when(tp.getWorld()).thenReturn(world);
    when(tp.getLocation()).thenReturn(loc);
    // Create a damage map
    Map<LivingEntity, Double> map = new HashMap<>();
    map.put(player2, 100D);
    map.put(zombie, 100D);
    map.put(creeper, 10D);
    PotionSplashEvent e = new PotionSplashEvent(tp, map);
    new PVPListener().onSplashPotionSplash(e);
    assertFalse(e.getAffectedEntities().contains(player2));
    assertTrue(e.getAffectedEntities().contains(zombie));
    assertTrue(e.getAffectedEntities().contains(creeper));
    verify(notifier).notify(any(), eq(Flags.PVP_OVERWORLD.getHintReference()));
    // Wrong world
    wrongWorld();
    e = new PotionSplashEvent(tp, map);
    new PVPListener().onSplashPotionSplash(e);
    assertFalse(e.isCancelled());
}
Also used : LivingEntity(org.bukkit.entity.LivingEntity) HashMap(java.util.HashMap) ThrownPotion(org.bukkit.entity.ThrownPotion) LingeringPotionSplashEvent(org.bukkit.event.entity.LingeringPotionSplashEvent) PotionSplashEvent(org.bukkit.event.entity.PotionSplashEvent) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Aggregations

PotionSplashEvent (org.bukkit.event.entity.PotionSplashEvent)12 LingeringPotionSplashEvent (org.bukkit.event.entity.LingeringPotionSplashEvent)9 ThrownPotion (org.bukkit.entity.ThrownPotion)8 HashMap (java.util.HashMap)7 LivingEntity (org.bukkit.entity.LivingEntity)6 Test (org.junit.Test)6 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)6 Location (org.bukkit.Location)2 ProjectileSource (org.bukkit.projectiles.ProjectileSource)2 LivingEntityBridge (io.izzel.arclight.common.bridge.entity.LivingEntityBridge)1 WorldBridge (io.izzel.arclight.common.bridge.world.WorldBridge)1 LivingEntity (net.minecraft.entity.LivingEntity)1 ServerPlayerEntity (net.minecraft.entity.player.ServerPlayerEntity)1 Effect (net.minecraft.potion.Effect)1 EffectInstance (net.minecraft.potion.EffectInstance)1 AxisAlignedBB (net.minecraft.util.math.AxisAlignedBB)1 ThrownPotion (net.minecraft.world.entity.projectile.ThrownPotion)1 CraftLivingEntity (org.bukkit.craftbukkit.v.entity.CraftLivingEntity)1 Event (org.bukkit.event.Event)1 EventHandler (org.bukkit.event.EventHandler)1