use of org.bukkit.event.entity.LingeringPotionSplashEvent in project Mohist by MohistMC.
the class CraftEventFactory method callLingeringPotionSplashEvent.
public static LingeringPotionSplashEvent callLingeringPotionSplashEvent(ThrownPotion potion, net.minecraft.world.entity.AreaEffectCloud cloud) {
org.bukkit.entity.ThrownPotion thrownPotion = (org.bukkit.entity.ThrownPotion) potion.getBukkitEntity();
AreaEffectCloud effectCloud = (AreaEffectCloud) cloud.getBukkitEntity();
LingeringPotionSplashEvent event = new LingeringPotionSplashEvent(thrownPotion, effectCloud);
Bukkit.getPluginManager().callEvent(event);
return event;
}
use of org.bukkit.event.entity.LingeringPotionSplashEvent 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.event.entity.LingeringPotionSplashEvent 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.event.entity.LingeringPotionSplashEvent 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.event.entity.LingeringPotionSplashEvent in project Nexus by ProjectEdenGG.
the class InvisibleItemFramesListener method onSplashPotion.
@EventHandler
public void onSplashPotion(LingeringPotionSplashEvent event) {
List<PotionEffectType> potionEffectTypes = new ArrayList<>();
event.getEntity().getEffects().forEach(e -> potionEffectTypes.add(e.getType()));
if (!potionEffectTypes.contains(PotionEffectType.INVISIBILITY))
return;
List<Entity> entities = Arrays.stream(event.getEntity().getNearbyEntities(2, 2, 2).toArray(Entity[]::new)).filter(e -> e.getType() == EntityType.ITEM_FRAME).collect(Collectors.toList());
// Cancel if in a region
if (!new WorldGuardUtils(event.getEntity().getWorld()).getRegionsAt(event.getEntity().getLocation()).isEmpty())
return;
// Get the iFrame plugin's instance to make them work
Plugin iFramePlugin = Bukkit.getPluginManager().getPlugin("SurvivalInvisiframes");
if (iFramePlugin == null || !iFramePlugin.isEnabled())
return;
NamespacedKey key = new NamespacedKey(iFramePlugin, "invisible");
for (Entity entity : entities) {
ItemFrame itemFrame = (ItemFrame) entity;
itemFrame.getPersistentDataContainer().set(key, PersistentDataType.BYTE, (byte) 1);
if (isNullOrAir(itemFrame.getItem())) {
itemFrame.setVisible(true);
itemFrame.setGlowing(true);
} else
itemFrame.setVisible(false);
}
}
Aggregations