use of org.bukkit.event.entity.PotionSplashEvent in project AncapFramework by ancap-dev.
the class ProtectListener method on.
@EventHandler(priority = EventPriority.LOW)
public void on(PotionSplashEvent e) {
ThrownPotion potion = e.getPotion();
Collection<LivingEntity> entities = e.getAffectedEntities();
if (entities.size() == 0) {
return;
}
ProjectileSource source = potion.getShooter();
if (!(source instanceof Player)) {
return;
}
Player player = (Player) source;
for (Entity entity : entities) {
Location interacted = entity.getLocation();
this.throwEvent(e, player, interacted);
if (entity instanceof Player) {
Player damaged = (Player) entity;
Event event = new AncapPVPEvent(e, player, damaged);
this.throwEvent(event);
}
}
}
use of org.bukkit.event.entity.PotionSplashEvent in project Mohist by MohistMC.
the class CraftEventFactory method callPotionSplashEvent.
/**
* PotionSplashEvent
*/
public static PotionSplashEvent callPotionSplashEvent(ThrownPotion potion, Map<org.bukkit.entity.LivingEntity, Double> affectedEntities) {
org.bukkit.entity.ThrownPotion thrownPotion = (org.bukkit.entity.ThrownPotion) potion.getBukkitEntity();
PotionSplashEvent event = new PotionSplashEvent(thrownPotion, affectedEntities);
Bukkit.getPluginManager().callEvent(event);
return event;
}
use of org.bukkit.event.entity.PotionSplashEvent in project BentoBox by BentoBoxWorld.
the class PVPListenerTest method testOnSplashPotionSplashWitch.
/**
* Test method for {@link PVPListener#onSplashPotionSplash(org.bukkit.event.entity.PotionSplashEvent)}.
*/
@Test
public void testOnSplashPotionSplashWitch() {
ThrownPotion tp = mock(ThrownPotion.class);
ProjectileSource witch = mock(Witch.class);
when(tp.getShooter()).thenReturn(witch);
PotionSplashEvent e = new PotionSplashEvent(tp, new HashMap<>());
new PVPListener().onSplashPotionSplash(e);
assertFalse(e.isCancelled());
}
use of org.bukkit.event.entity.PotionSplashEvent in project BentoBox by BentoBoxWorld.
the class PVPListenerTest method testOnSplashPotionSplashAllowPVP.
/**
* Test method for {@link PVPListener#onSplashPotionSplash(org.bukkit.event.entity.PotionSplashEvent)}.
*/
@Test
public void testOnSplashPotionSplashAllowPVP() {
// Disallow PVP
when(island.isAllowed(any())).thenReturn(true);
ThrownPotion tp = mock(ThrownPotion.class);
when(tp.getShooter()).thenReturn(player);
when(tp.getWorld()).thenReturn(world);
when(tp.getLocation()).thenReturn(loc);
// Create a damage map
Map<LivingEntity, Double> map = new HashMap<>();
map.put(player2, 100D);
map.put(zombie, 100D);
map.put(creeper, 10D);
PotionSplashEvent e = new PotionSplashEvent(tp, map);
new PVPListener().onSplashPotionSplash(e);
assertTrue(e.getAffectedEntities().contains(player2));
assertTrue(e.getAffectedEntities().contains(zombie));
assertTrue(e.getAffectedEntities().contains(creeper));
verify(player, never()).sendMessage(Flags.PVP_OVERWORLD.getHintReference());
}
use of org.bukkit.event.entity.PotionSplashEvent in project BentoBox by BentoBoxWorld.
the class PVPListenerTest method testOnSplashPotionSplash.
/**
* Test method for {@link PVPListener#onSplashPotionSplash(org.bukkit.event.entity.PotionSplashEvent)}.
*/
@Test
public void testOnSplashPotionSplash() {
// Disallow PVP
when(island.isAllowed(any())).thenReturn(false);
ThrownPotion tp = mock(ThrownPotion.class);
when(tp.getShooter()).thenReturn(player);
when(tp.getWorld()).thenReturn(world);
when(tp.getLocation()).thenReturn(loc);
// Create a damage map
Map<LivingEntity, Double> map = new HashMap<>();
map.put(player2, 100D);
map.put(zombie, 100D);
map.put(creeper, 10D);
PotionSplashEvent e = new PotionSplashEvent(tp, map);
new PVPListener().onSplashPotionSplash(e);
assertFalse(e.getAffectedEntities().contains(player2));
assertTrue(e.getAffectedEntities().contains(zombie));
assertTrue(e.getAffectedEntities().contains(creeper));
verify(notifier).notify(any(), eq(Flags.PVP_OVERWORLD.getHintReference()));
// Wrong world
wrongWorld();
e = new PotionSplashEvent(tp, map);
new PVPListener().onSplashPotionSplash(e);
assertFalse(e.isCancelled());
}
Aggregations