Search in sources :

Example 1 with LingeringPotion

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

the class HealingLeveler method onLingeringPotionSplash.

@EventHandler
@SuppressWarnings("deprecation")
public void onLingeringPotionSplash(LingeringPotionSplashEvent event) {
    if (!OptionL.isEnabled(Skills.HEALING))
        return;
    // Check cancelled
    if (OptionL.getBoolean(Option.HEALING_CHECK_CANCELLED)) {
        if (event.isCancelled()) {
            return;
        }
    }
    ProjectileHitEvent projEvent = event;
    if (!(projEvent.getEntity().getShooter() instanceof Player))
        return;
    Player player = (Player) projEvent.getEntity().getShooter();
    if (player == null) {
        return;
    }
    PotionMeta meta;
    Projectile projectile = projEvent.getEntity();
    if (VersionUtils.isAtLeastVersion(14)) {
        if (!(projectile instanceof ThrownPotion)) {
            return;
        }
        ThrownPotion thrownPotion = (ThrownPotion) projectile;
        if (thrownPotion.getEffects().size() == 0)
            return;
        if (!(thrownPotion.getItem().getItemMeta() instanceof PotionMeta))
            return;
        meta = (PotionMeta) thrownPotion.getItem().getItemMeta();
    } else {
        // 1.12-1.13 compatibility
        if (!(projectile instanceof LingeringPotion)) {
            return;
        }
        LingeringPotion lingeringPotion = (LingeringPotion) projectile;
        if (lingeringPotion.getEffects().size() == 0)
            return;
        if (!(lingeringPotion.getItem().getItemMeta() instanceof PotionMeta))
            return;
        meta = (PotionMeta) lingeringPotion.getItem().getItemMeta();
    }
    PotionData data = meta.getBasePotionData();
    if (OptionL.getBoolean(Option.HEALING_EXCLUDE_NEGATIVE_POTIONS) && PotionUtil.isNegativePotion(data.getType())) {
        return;
    }
    Skill skill = Skills.HEALING;
    if (blockXpGain(player))
        return;
    if (!data.getType().equals(PotionType.MUNDANE) && !data.getType().equals(PotionType.THICK) && !data.getType().equals(PotionType.WATER) && !data.getType().equals(PotionType.AWKWARD)) {
        if (data.isExtended()) {
            plugin.getLeveler().addXp(player, skill, getXp(player, HealingSource.LINGERING_EXTENDED));
        } else if (data.isUpgraded()) {
            plugin.getLeveler().addXp(player, skill, getXp(player, HealingSource.LINGERING_UPGRADED));
        } else {
            plugin.getLeveler().addXp(player, skill, getXp(player, HealingSource.LINGERING_REGULAR));
        }
    }
}
Also used : ProjectileHitEvent(org.bukkit.event.entity.ProjectileHitEvent) Player(org.bukkit.entity.Player) Skill(com.archyx.aureliumskills.skills.Skill) PotionData(org.bukkit.potion.PotionData) ThrownPotion(org.bukkit.entity.ThrownPotion) LingeringPotion(org.bukkit.entity.LingeringPotion) PotionMeta(org.bukkit.inventory.meta.PotionMeta) Projectile(org.bukkit.entity.Projectile) EventHandler(org.bukkit.event.EventHandler)

Example 2 with LingeringPotion

use of org.bukkit.entity.LingeringPotion 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 LingeringPotion

use of org.bukkit.entity.LingeringPotion 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 LingeringPotion

use of org.bukkit.entity.LingeringPotion 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 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