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));
}
}
}
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()));
}
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()));
}
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());
}
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);
}
}
}
Aggregations