Search in sources :

Example 1 with LingeringPotionSplashEvent

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

the class CraftEventFactory method callLingeringPotionSplashEvent.

public static LingeringPotionSplashEvent callLingeringPotionSplashEvent(ThrownPotion potion, net.minecraft.world.entity.AreaEffectCloud cloud) {
    org.bukkit.entity.ThrownPotion thrownPotion = (org.bukkit.entity.ThrownPotion) potion.getBukkitEntity();
    AreaEffectCloud effectCloud = (AreaEffectCloud) cloud.getBukkitEntity();
    LingeringPotionSplashEvent event = new LingeringPotionSplashEvent(thrownPotion, effectCloud);
    Bukkit.getPluginManager().callEvent(event);
    return event;
}
Also used : ThrownPotion(net.minecraft.world.entity.projectile.ThrownPotion) LingeringPotionSplashEvent(org.bukkit.event.entity.LingeringPotionSplashEvent) AreaEffectCloud(org.bukkit.entity.AreaEffectCloud)

Example 2 with LingeringPotionSplashEvent

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

the class PVPListenerTest method testOnLingeringPotionDamageNoPVPVisitor.

/**
 * Test method for {@link PVPListener#onLingeringPotionDamage(org.bukkit.event.entity.AreaEffectCloudApplyEvent)}.
 */
@Test
public void testOnLingeringPotionDamageNoPVPVisitor() {
    // Disallow PVP
    when(island.isAllowed(any())).thenReturn(false);
    // Throw a potion
    LingeringPotion tp = mock(LingeringPotion.class);
    when(tp.getShooter()).thenReturn(player);
    when(tp.getWorld()).thenReturn(world);
    when(tp.getLocation()).thenReturn(loc);
    AreaEffectCloud cloud = mock(AreaEffectCloud.class);
    when(cloud.getWorld()).thenReturn(world);
    LingeringPotionSplashEvent e = new LingeringPotionSplashEvent(tp, cloud);
    PVPListener listener = new PVPListener();
    listener.onLingeringPotionSplash(e);
    List<LivingEntity> list = new ArrayList<>();
    // This player will still suffer
    list.add(player);
    list.add(creeper);
    list.add(player2);
    list.add(zombie);
    // Protect visitor
    // This player is a visitor and any damage is not allowed
    when(im.userIsOnIsland(any(), any())).thenReturn(false);
    when(iwm.getIvSettings(any())).thenReturn(Collections.singletonList("ENTITY_ATTACK"));
    // See who it affects
    AreaEffectCloudApplyEvent ae = new AreaEffectCloudApplyEvent(cloud, list);
    listener.onLingeringPotionDamage(ae);
    assertEquals(3, ae.getAffectedEntities().size());
    assertFalse(ae.getAffectedEntities().contains(player2));
    verify(notifier).notify(any(), eq(Flags.INVINCIBLE_VISITORS.getHintReference()));
    // Wrong world
    wrongWorld();
    listener.onLingeringPotionSplash(e);
    assertEquals(3, ae.getAffectedEntities().size());
    assertFalse(ae.getAffectedEntities().contains(player2));
    verify(notifier).notify(any(), eq(Flags.INVINCIBLE_VISITORS.getHintReference()));
}
Also used : LivingEntity(org.bukkit.entity.LivingEntity) ArrayList(java.util.ArrayList) LingeringPotion(org.bukkit.entity.LingeringPotion) LingeringPotionSplashEvent(org.bukkit.event.entity.LingeringPotionSplashEvent) AreaEffectCloud(org.bukkit.entity.AreaEffectCloud) AreaEffectCloudApplyEvent(org.bukkit.event.entity.AreaEffectCloudApplyEvent) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 3 with LingeringPotionSplashEvent

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

the class PVPListenerTest method testOnLingeringPotionDamagePVPVisitor.

/**
 * Test method for {@link PVPListener#onLingeringPotionDamage(org.bukkit.event.entity.AreaEffectCloudApplyEvent)}.
 */
@Test
public void testOnLingeringPotionDamagePVPVisitor() {
    // Allow PVP
    when(island.isAllowed(any())).thenReturn(true);
    // Throw a potion
    LingeringPotion tp = mock(LingeringPotion.class);
    when(tp.getShooter()).thenReturn(player);
    when(tp.getWorld()).thenReturn(world);
    when(tp.getLocation()).thenReturn(loc);
    AreaEffectCloud cloud = mock(AreaEffectCloud.class);
    when(cloud.getWorld()).thenReturn(world);
    LingeringPotionSplashEvent e = new LingeringPotionSplashEvent(tp, cloud);
    PVPListener listener = new PVPListener();
    listener.onLingeringPotionSplash(e);
    List<LivingEntity> list = new ArrayList<>();
    // This player will still suffer
    list.add(player);
    list.add(creeper);
    list.add(player2);
    list.add(zombie);
    // Protect visitor
    // This player is a visitor and any damage is not allowed
    when(im.userIsOnIsland(any(), any())).thenReturn(false);
    when(iwm.getIvSettings(any())).thenReturn(Collections.singletonList("ENTITY_ATTACK"));
    // See who it affects
    AreaEffectCloudApplyEvent ae = new AreaEffectCloudApplyEvent(cloud, list);
    listener.onLingeringPotionDamage(ae);
    assertEquals(3, ae.getAffectedEntities().size());
    assertFalse(ae.getAffectedEntities().contains(player2));
    verify(notifier).notify(any(), eq(Flags.INVINCIBLE_VISITORS.getHintReference()));
    // Wrong world
    wrongWorld();
    listener.onLingeringPotionSplash(e);
    assertEquals(3, ae.getAffectedEntities().size());
    assertFalse(ae.getAffectedEntities().contains(player2));
    verify(notifier).notify(any(), eq(Flags.INVINCIBLE_VISITORS.getHintReference()));
}
Also used : LivingEntity(org.bukkit.entity.LivingEntity) ArrayList(java.util.ArrayList) LingeringPotion(org.bukkit.entity.LingeringPotion) LingeringPotionSplashEvent(org.bukkit.event.entity.LingeringPotionSplashEvent) AreaEffectCloud(org.bukkit.entity.AreaEffectCloud) AreaEffectCloudApplyEvent(org.bukkit.event.entity.AreaEffectCloudApplyEvent) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 4 with LingeringPotionSplashEvent

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

the class PVPListenerTest method testOnLingeringPotionDamagePVP.

/**
 * Test method for {@link PVPListener#onLingeringPotionDamage(org.bukkit.event.entity.AreaEffectCloudApplyEvent)}.
 */
@Test
public void testOnLingeringPotionDamagePVP() {
    // Allow PVP
    when(island.isAllowed(any())).thenReturn(true);
    // Throw a potion
    LingeringPotion tp = mock(LingeringPotion.class);
    when(tp.getShooter()).thenReturn(player);
    when(tp.getWorld()).thenReturn(world);
    when(tp.getLocation()).thenReturn(loc);
    AreaEffectCloud cloud = mock(AreaEffectCloud.class);
    when(cloud.getWorld()).thenReturn(world);
    LingeringPotionSplashEvent e = new LingeringPotionSplashEvent(tp, cloud);
    PVPListener listener = new PVPListener();
    listener.onLingeringPotionSplash(e);
    List<LivingEntity> list = new ArrayList<>();
    // This player will still suffer
    list.add(player);
    list.add(creeper);
    list.add(player2);
    list.add(zombie);
    // See who it affects
    AreaEffectCloudApplyEvent ae = new AreaEffectCloudApplyEvent(cloud, list);
    listener.onLingeringPotionDamage(ae);
    assertEquals(4, ae.getAffectedEntities().size());
    verify(player, never()).sendMessage(Flags.PVP_OVERWORLD.getHintReference());
    // Wrong world
    wrongWorld();
    listener.onLingeringPotionSplash(e);
    assertEquals(4, ae.getAffectedEntities().size());
    verify(player, never()).sendMessage(Flags.PVP_OVERWORLD.getHintReference());
}
Also used : LivingEntity(org.bukkit.entity.LivingEntity) ArrayList(java.util.ArrayList) LingeringPotion(org.bukkit.entity.LingeringPotion) LingeringPotionSplashEvent(org.bukkit.event.entity.LingeringPotionSplashEvent) AreaEffectCloud(org.bukkit.entity.AreaEffectCloud) AreaEffectCloudApplyEvent(org.bukkit.event.entity.AreaEffectCloudApplyEvent) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 5 with LingeringPotionSplashEvent

use of org.bukkit.event.entity.LingeringPotionSplashEvent in project Nexus by ProjectEdenGG.

the class InvisibleItemFramesListener method onSplashPotion.

@EventHandler
public void onSplashPotion(LingeringPotionSplashEvent event) {
    List<PotionEffectType> potionEffectTypes = new ArrayList<>();
    event.getEntity().getEffects().forEach(e -> potionEffectTypes.add(e.getType()));
    if (!potionEffectTypes.contains(PotionEffectType.INVISIBILITY))
        return;
    List<Entity> entities = Arrays.stream(event.getEntity().getNearbyEntities(2, 2, 2).toArray(Entity[]::new)).filter(e -> e.getType() == EntityType.ITEM_FRAME).collect(Collectors.toList());
    // Cancel if in a region
    if (!new WorldGuardUtils(event.getEntity().getWorld()).getRegionsAt(event.getEntity().getLocation()).isEmpty())
        return;
    // Get the iFrame plugin's instance to make them work
    Plugin iFramePlugin = Bukkit.getPluginManager().getPlugin("SurvivalInvisiframes");
    if (iFramePlugin == null || !iFramePlugin.isEnabled())
        return;
    NamespacedKey key = new NamespacedKey(iFramePlugin, "invisible");
    for (Entity entity : entities) {
        ItemFrame itemFrame = (ItemFrame) entity;
        itemFrame.getPersistentDataContainer().set(key, PersistentDataType.BYTE, (byte) 1);
        if (isNullOrAir(itemFrame.getItem())) {
            itemFrame.setVisible(true);
            itemFrame.setGlowing(true);
        } else
            itemFrame.setVisible(false);
    }
}
Also used : Plugin(org.bukkit.plugin.Plugin) Nullables(gg.projecteden.nexus.utils.Nullables) Arrays(java.util.Arrays) Player(org.bukkit.entity.Player) ColorType(gg.projecteden.nexus.utils.ColorType) Scoreboard(org.bukkit.scoreboard.Scoreboard) ArrayList(java.util.ArrayList) EventHandler(org.bukkit.event.EventHandler) MaterialTag(gg.projecteden.nexus.utils.MaterialTag) ItemFrame(org.bukkit.entity.ItemFrame) WorldGuardUtils(gg.projecteden.nexus.utils.WorldGuardUtils) Bukkit(org.bukkit.Bukkit) Listener(org.bukkit.event.Listener) Team(org.bukkit.scoreboard.Team) NamespacedKey(org.bukkit.NamespacedKey) Entity(org.bukkit.entity.Entity) Rank(gg.projecteden.nexus.models.nerd.Rank) EntityType(org.bukkit.entity.EntityType) PlayerInteractEntityEvent(org.bukkit.event.player.PlayerInteractEntityEvent) Collectors(java.util.stream.Collectors) ItemStack(org.bukkit.inventory.ItemStack) List(java.util.List) LingeringPotionSplashEvent(org.bukkit.event.entity.LingeringPotionSplashEvent) Nullables.isNullOrAir(gg.projecteden.nexus.utils.Nullables.isNullOrAir) DyeColor(org.bukkit.DyeColor) PotionEffectType(org.bukkit.potion.PotionEffectType) PersistentDataType(org.bukkit.persistence.PersistentDataType) Entity(org.bukkit.entity.Entity) PotionEffectType(org.bukkit.potion.PotionEffectType) NamespacedKey(org.bukkit.NamespacedKey) ArrayList(java.util.ArrayList) ItemFrame(org.bukkit.entity.ItemFrame) WorldGuardUtils(gg.projecteden.nexus.utils.WorldGuardUtils) Plugin(org.bukkit.plugin.Plugin) EventHandler(org.bukkit.event.EventHandler)

Aggregations

LingeringPotionSplashEvent (org.bukkit.event.entity.LingeringPotionSplashEvent)10 AreaEffectCloud (org.bukkit.entity.AreaEffectCloud)8 LingeringPotion (org.bukkit.entity.LingeringPotion)6 Test (org.junit.Test)6 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)6 ArrayList (java.util.ArrayList)5 LivingEntity (org.bukkit.entity.LivingEntity)4 AreaEffectCloudApplyEvent (org.bukkit.event.entity.AreaEffectCloudApplyEvent)4 Rank (gg.projecteden.nexus.models.nerd.Rank)1 ColorType (gg.projecteden.nexus.utils.ColorType)1 MaterialTag (gg.projecteden.nexus.utils.MaterialTag)1 Nullables (gg.projecteden.nexus.utils.Nullables)1 Nullables.isNullOrAir (gg.projecteden.nexus.utils.Nullables.isNullOrAir)1 WorldGuardUtils (gg.projecteden.nexus.utils.WorldGuardUtils)1 Arrays (java.util.Arrays)1 List (java.util.List)1 Collectors (java.util.stream.Collectors)1 ThrownPotion (net.minecraft.world.entity.projectile.ThrownPotion)1 Bukkit (org.bukkit.Bukkit)1 DyeColor (org.bukkit.DyeColor)1