Search in sources :

Example 6 with LingeringPotion

use of org.bukkit.entity.LingeringPotion in project BentoBox by BentoBoxWorld.

the class PVPListenerTest method testOnLingeringPotionDamageNoPVP.

/**
 * Test method for {@link PVPListener#onLingeringPotionDamage(org.bukkit.event.entity.AreaEffectCloudApplyEvent)}.
 */
@Test
public void testOnLingeringPotionDamageNoPVP() {
    // 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);
    // 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.PVP_OVERWORLD.getHintReference()));
    // Wrong world
    wrongWorld();
    listener.onLingeringPotionSplash(e);
    // No change to results
    assertEquals(3, ae.getAffectedEntities().size());
    assertFalse(ae.getAffectedEntities().contains(player2));
    verify(notifier).notify(any(), eq(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 7 with LingeringPotion

use of org.bukkit.entity.LingeringPotion in project BentoBox by BentoBoxWorld.

the class PVPListenerTest method testOnLingeringPotionSplashNonHuman.

/**
 * Test method for {@link PVPListener#onLingeringPotionSplash(org.bukkit.event.entity.LingeringPotionSplashEvent)}.
 */
@Test
public void testOnLingeringPotionSplashNonHuman() {
    LingeringPotion tp = mock(LingeringPotion.class);
    when(tp.getShooter()).thenReturn(creeper);
    when(tp.getWorld()).thenReturn(world);
    when(tp.getLocation()).thenReturn(loc);
    AreaEffectCloud cloud = mock(AreaEffectCloud.class);
    LingeringPotionSplashEvent e = new LingeringPotionSplashEvent(tp, cloud);
    new PVPListener().onLingeringPotionSplash(e);
    // Verify
    verify(cloud, never()).getEntityId();
    verify(tp).getShooter();
    PowerMockito.verifyStatic(Bukkit.class, never());
    Bukkit.getScheduler();
}
Also used : LingeringPotion(org.bukkit.entity.LingeringPotion) LingeringPotionSplashEvent(org.bukkit.event.entity.LingeringPotionSplashEvent) AreaEffectCloud(org.bukkit.entity.AreaEffectCloud) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 8 with LingeringPotion

use of org.bukkit.entity.LingeringPotion in project AureliumSkills by Archy-X.

the class AlchemyAbilities method lingering.

// Handles the Lingering ability
@EventHandler
@SuppressWarnings("deprecation")
public void lingering(LingeringPotionSplashEvent event) {
    if (blockDisabled(Ability.LINGERING))
        return;
    if (event.isCancelled())
        return;
    Player player = null;
    if (VersionUtils.isAtLeastVersion(14)) {
        if (event.getEntity().getShooter() instanceof Player) {
            player = (Player) event.getEntity().getShooter();
        }
    } else {
        try {
            Object lingeringPotionObject = event.getClass().getDeclaredMethod("getEntity").invoke(event);
            if (lingeringPotionObject instanceof LingeringPotion) {
                LingeringPotion lingeringPotion = (LingeringPotion) lingeringPotionObject;
                if (lingeringPotion.getShooter() instanceof Player) {
                    player = (Player) lingeringPotion.getShooter();
                }
            }
        } catch (IllegalAccessException | InvocationTargetException | NoSuchMethodException ignored) {
        }
    }
    if (player != null) {
        if (blockAbility(player))
            return;
        PlayerData playerData = plugin.getPlayerManager().getPlayerData(player);
        if (playerData == null)
            return;
        if (playerData.getAbilityLevel(Ability.LINGERING) > 0) {
            AreaEffectCloud cloud = event.getAreaEffectCloud();
            if (cloud.hasCustomEffects() && OptionL.getBoolean(Option.ALCHEMY_IGNORE_CUSTOM_POTIONS))
                return;
            // Get values
            double naturalDecay = 1 - (getValue(Ability.LINGERING, playerData) / 100);
            double entityDecay = 1 - (getValue2(Ability.LINGERING, playerData) / 100);
            // 1% limit
            if (naturalDecay <= 0.01)
                naturalDecay = 0.01;
            if (entityDecay <= 0.01)
                entityDecay = 0.01;
            // Apply values
            cloud.setRadiusPerTick(cloud.getRadiusPerTick() * (float) naturalDecay);
            cloud.setRadiusOnUse(cloud.getRadiusOnUse() * (float) entityDecay);
        }
    }
}
Also used : Player(org.bukkit.entity.Player) OfflinePlayer(org.bukkit.OfflinePlayer) LingeringPotion(org.bukkit.entity.LingeringPotion) AreaEffectCloud(org.bukkit.entity.AreaEffectCloud) PlayerData(com.archyx.aureliumskills.data.PlayerData) InvocationTargetException(java.lang.reflect.InvocationTargetException) EventHandler(org.bukkit.event.EventHandler)

Aggregations

LingeringPotion (org.bukkit.entity.LingeringPotion)8 AreaEffectCloud (org.bukkit.entity.AreaEffectCloud)7 LingeringPotionSplashEvent (org.bukkit.event.entity.LingeringPotionSplashEvent)6 Test (org.junit.Test)6 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)6 ArrayList (java.util.ArrayList)4 LivingEntity (org.bukkit.entity.LivingEntity)4 AreaEffectCloudApplyEvent (org.bukkit.event.entity.AreaEffectCloudApplyEvent)4 Player (org.bukkit.entity.Player)2 EventHandler (org.bukkit.event.EventHandler)2 PlayerData (com.archyx.aureliumskills.data.PlayerData)1 Skill (com.archyx.aureliumskills.skills.Skill)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 OfflinePlayer (org.bukkit.OfflinePlayer)1 Projectile (org.bukkit.entity.Projectile)1 ThrownPotion (org.bukkit.entity.ThrownPotion)1 ProjectileHitEvent (org.bukkit.event.entity.ProjectileHitEvent)1 PotionMeta (org.bukkit.inventory.meta.PotionMeta)1 PotionData (org.bukkit.potion.PotionData)1