Search in sources :

Example 1 with AreaEffectCloudApplyEvent

use of org.bukkit.event.entity.AreaEffectCloudApplyEvent in project Arclight by IzzelAliz.

the class AreaEffectCloudEntityMixin method tick.

// @formatter:on
/**
 * @author IzzelAliz
 * @reason
 */
@Overwrite
public void tick() {
    super.tick();
    boolean flag = this.shouldIgnoreRadius();
    float f = this.getRadius();
    if (this.world.isRemote) {
        IParticleData iparticledata = this.getParticleData();
        if (flag) {
            if (this.rand.nextBoolean()) {
                for (int i = 0; i < 2; ++i) {
                    float f1 = this.rand.nextFloat() * ((float) Math.PI * 2F);
                    float f2 = MathHelper.sqrt(this.rand.nextFloat()) * 0.2F;
                    float f3 = MathHelper.cos(f1) * f2;
                    float f4 = MathHelper.sin(f1) * f2;
                    if (iparticledata.getType() == ParticleTypes.ENTITY_EFFECT) {
                        int j = this.rand.nextBoolean() ? 16777215 : this.getColor();
                        int k = j >> 16 & 255;
                        int l = j >> 8 & 255;
                        int i1 = j & 255;
                        this.world.addOptionalParticle(iparticledata, this.posX + (double) f3, this.posY, this.posZ + (double) f4, (double) ((float) k / 255.0F), (double) ((float) l / 255.0F), (double) ((float) i1 / 255.0F));
                    } else {
                        this.world.addOptionalParticle(iparticledata, this.posX + (double) f3, this.posY, this.posZ + (double) f4, 0.0D, 0.0D, 0.0D);
                    }
                }
            }
        } else {
            float f5 = (float) Math.PI * f * f;
            for (int k1 = 0; (float) k1 < f5; ++k1) {
                float f6 = this.rand.nextFloat() * ((float) Math.PI * 2F);
                float f7 = MathHelper.sqrt(this.rand.nextFloat()) * f;
                float f8 = MathHelper.cos(f6) * f7;
                float f9 = MathHelper.sin(f6) * f7;
                if (iparticledata.getType() == ParticleTypes.ENTITY_EFFECT) {
                    int l1 = this.getColor();
                    int i2 = l1 >> 16 & 255;
                    int j2 = l1 >> 8 & 255;
                    int j1 = l1 & 255;
                    this.world.addOptionalParticle(iparticledata, this.posX + (double) f8, this.posY, this.posZ + (double) f9, (double) ((float) i2 / 255.0F), (double) ((float) j2 / 255.0F), (double) ((float) j1 / 255.0F));
                } else {
                    this.world.addOptionalParticle(iparticledata, this.posX + (double) f8, this.posY, this.posZ + (double) f9, (0.5D - this.rand.nextDouble()) * 0.15D, (double) 0.01F, (0.5D - this.rand.nextDouble()) * 0.15D);
                }
            }
        }
    } else {
        if (this.ticksExisted >= this.waitTime + this.duration) {
            this.remove();
            return;
        }
        boolean flag1 = this.ticksExisted < this.waitTime;
        if (flag != flag1) {
            this.setIgnoreRadius(flag1);
        }
        if (flag1) {
            return;
        }
        if (this.radiusPerTick != 0.0F) {
            f += this.radiusPerTick;
            if (f < 0.5F) {
                this.remove();
                return;
            }
            this.setRadius(f);
        }
        if (this.ticksExisted % 5 == 0) {
            Iterator<Map.Entry<Entity, Integer>> iterator = this.reapplicationDelayMap.entrySet().iterator();
            while (iterator.hasNext()) {
                Map.Entry<Entity, Integer> entry = iterator.next();
                if (this.ticksExisted >= entry.getValue()) {
                    iterator.remove();
                }
            }
            List<EffectInstance> effects = Lists.newArrayList();
            for (EffectInstance effectinstance1 : this.potion.getEffects()) {
                effects.add(new EffectInstance(effectinstance1.getPotion(), effectinstance1.getDuration() / 4, effectinstance1.getAmplifier(), effectinstance1.isAmbient(), effectinstance1.doesShowParticles()));
            }
            effects.addAll(this.effects);
            if (effects.isEmpty()) {
                this.reapplicationDelayMap.clear();
            } else {
                List<LivingEntity> list = this.world.getEntitiesWithinAABB(LivingEntity.class, this.getBoundingBox());
                if (!list.isEmpty()) {
                    List<LivingEntity> entities = new java.util.ArrayList<>();
                    for (LivingEntity livingentity : list) {
                        if (!this.reapplicationDelayMap.containsKey(livingentity) && livingentity.canBeHitWithPotion()) {
                            double d0 = livingentity.posX - this.posX;
                            double d1 = livingentity.posZ - this.posZ;
                            double d2 = d0 * d0 + d1 * d1;
                            if (d2 <= (double) (f * f)) {
                                entities.add(livingentity);
                            }
                        }
                    }
                    AreaEffectCloudApplyEvent event = CraftEventFactory.callAreaEffectCloudApplyEvent((AreaEffectCloudEntity) (Object) this, Lists.transform(entities, living -> ((LivingEntityBridge) living).bridge$getBukkitEntity()));
                    if (!event.isCancelled()) {
                        for (org.bukkit.entity.LivingEntity entity : event.getAffectedEntities()) {
                            if (entity instanceof CraftLivingEntity) {
                                LivingEntity livingentity = ((CraftLivingEntity) entity).getHandle();
                                this.reapplicationDelayMap.put(livingentity, this.ticksExisted + this.reapplicationDelay);
                                for (EffectInstance effectinstance : effects) {
                                    if (effectinstance.getPotion().isInstant()) {
                                        effectinstance.getPotion().affectEntity((AreaEffectCloudEntity) (Object) this, this.getOwner(), livingentity, effectinstance.getAmplifier(), 0.5D);
                                    } else {
                                        ((LivingEntityBridge) livingentity).bridge$pushEffectCause(EntityPotionEffectEvent.Cause.AREA_EFFECT_CLOUD);
                                        livingentity.addPotionEffect(new EffectInstance(effectinstance));
                                    }
                                }
                                if (this.radiusOnUse != 0.0F) {
                                    f += this.radiusOnUse;
                                    if (f < 0.5F) {
                                        this.remove();
                                        return;
                                    }
                                    this.setRadius(f);
                                }
                                if (this.durationOnUse != 0) {
                                    this.duration += this.durationOnUse;
                                    if (this.duration <= 0) {
                                        this.remove();
                                        return;
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }
}
Also used : AreaEffectCloudApplyEvent(org.bukkit.event.entity.AreaEffectCloudApplyEvent) LivingEntityBridge(io.izzel.arclight.common.bridge.entity.LivingEntityBridge) Overwrite(org.spongepowered.asm.mixin.Overwrite) Lists(com.google.common.collect.Lists) EffectInstance(net.minecraft.potion.EffectInstance) Mixin(org.spongepowered.asm.mixin.Mixin) Map(java.util.Map) CraftEventFactory(org.bukkit.craftbukkit.v.event.CraftEventFactory) Nullable(javax.annotation.Nullable) AreaEffectCloudEntity(net.minecraft.entity.AreaEffectCloudEntity) PotionUtils(net.minecraft.potion.PotionUtils) Entity(net.minecraft.entity.Entity) Iterator(java.util.Iterator) LivingEntity(net.minecraft.entity.LivingEntity) DataParameter(net.minecraft.network.datasync.DataParameter) EntityPotionEffectEvent(org.bukkit.event.entity.EntityPotionEffectEvent) Final(org.spongepowered.asm.mixin.Final) Registry(net.minecraft.util.registry.Registry) IParticleData(net.minecraft.particles.IParticleData) Implements(org.spongepowered.asm.mixin.Implements) ParticleTypes(net.minecraft.particles.ParticleTypes) List(java.util.List) MathHelper(net.minecraft.util.math.MathHelper) AreaEffectCloudEntityBridge(io.izzel.arclight.common.bridge.entity.AreaEffectCloudEntityBridge) ResourceLocation(net.minecraft.util.ResourceLocation) CraftLivingEntity(org.bukkit.craftbukkit.v.entity.CraftLivingEntity) Shadow(org.spongepowered.asm.mixin.Shadow) Potion(net.minecraft.potion.Potion) Interface(org.spongepowered.asm.mixin.Interface) AreaEffectCloudEntity(net.minecraft.entity.AreaEffectCloudEntity) Entity(net.minecraft.entity.Entity) LivingEntity(net.minecraft.entity.LivingEntity) CraftLivingEntity(org.bukkit.craftbukkit.v.entity.CraftLivingEntity) AreaEffectCloudApplyEvent(org.bukkit.event.entity.AreaEffectCloudApplyEvent) LivingEntity(net.minecraft.entity.LivingEntity) CraftLivingEntity(org.bukkit.craftbukkit.v.entity.CraftLivingEntity) LivingEntityBridge(io.izzel.arclight.common.bridge.entity.LivingEntityBridge) IParticleData(net.minecraft.particles.IParticleData) CraftLivingEntity(org.bukkit.craftbukkit.v.entity.CraftLivingEntity) Map(java.util.Map) EffectInstance(net.minecraft.potion.EffectInstance) Overwrite(org.spongepowered.asm.mixin.Overwrite)

Example 2 with AreaEffectCloudApplyEvent

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

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

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

use of org.bukkit.event.entity.AreaEffectCloudApplyEvent in project Magma-1.16.x by magmafoundation.

the class CraftEventFactory method callAreaEffectCloudApplyEvent.

public static AreaEffectCloudApplyEvent callAreaEffectCloudApplyEvent(AreaEffectCloudEntity cloud, List<LivingEntity> entities) {
    AreaEffectCloudApplyEvent event = new AreaEffectCloudApplyEvent((AreaEffectCloud) cloud.getBukkitEntity(), entities);
    cloud.level.getServerCB().getPluginManager().callEvent(event);
    return event;
}
Also used : AreaEffectCloudApplyEvent(org.bukkit.event.entity.AreaEffectCloudApplyEvent)

Aggregations

AreaEffectCloudApplyEvent (org.bukkit.event.entity.AreaEffectCloudApplyEvent)7 ArrayList (java.util.ArrayList)4 AreaEffectCloud (org.bukkit.entity.AreaEffectCloud)4 LingeringPotion (org.bukkit.entity.LingeringPotion)4 LivingEntity (org.bukkit.entity.LivingEntity)4 LingeringPotionSplashEvent (org.bukkit.event.entity.LingeringPotionSplashEvent)4 Test (org.junit.Test)4 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)4 Lists (com.google.common.collect.Lists)1 AreaEffectCloudEntityBridge (io.izzel.arclight.common.bridge.entity.AreaEffectCloudEntityBridge)1 LivingEntityBridge (io.izzel.arclight.common.bridge.entity.LivingEntityBridge)1 Iterator (java.util.Iterator)1 List (java.util.List)1 Map (java.util.Map)1 Nullable (javax.annotation.Nullable)1 AreaEffectCloudEntity (net.minecraft.entity.AreaEffectCloudEntity)1 Entity (net.minecraft.entity.Entity)1 LivingEntity (net.minecraft.entity.LivingEntity)1 DataParameter (net.minecraft.network.datasync.DataParameter)1 IParticleData (net.minecraft.particles.IParticleData)1