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