SPIGOT-1904: AreaEffectCloud events and additional API

This commit is contained in:
t00thpick1 2016-03-12 12:12:25 -05:00 committed by md_5
parent 02b26eec0e
commit b3f6de0da5
6 changed files with 93 additions and 14 deletions

View File

@ -1,6 +1,17 @@
--- a/net/minecraft/server/EntityAreaEffectCloud.java
+++ b/net/minecraft/server/EntityAreaEffectCloud.java
@@ -91,6 +91,22 @@
@@ -8,6 +8,10 @@
import java.util.List;
import java.util.Map;
import java.util.UUID;
+
+import org.bukkit.craftbukkit.entity.CraftLivingEntity; // CraftBukkit
+import org.bukkit.entity.LivingEntity; // CraftBukkit
+
import java.util.Map.Entry;
public class EntityAreaEffectCloud extends Entity {
@@ -91,6 +95,22 @@
}
@ -23,3 +34,29 @@
public int getColor() {
return ((Integer) this.getDataWatcher().get(EntityAreaEffectCloud.b)).intValue();
}
@@ -237,6 +257,7 @@
if (!list.isEmpty()) {
Iterator iterator2 = list.iterator();
+ List<LivingEntity> entities = new ArrayList<LivingEntity>(); // CraftBukkit
while (iterator2.hasNext()) {
EntityLiving entityliving = (EntityLiving) iterator2.next();
@@ -246,6 +267,17 @@
double d2 = d0 * d0 + d1 * d1;
if (d2 <= (double) (f * f)) {
+ // CraftBukkit start
+ entities.add((LivingEntity) entityliving.getBukkitEntity());
+ }
+ }
+ }
+ org.bukkit.event.entity.AreaEffectCloudApplyEvent event = org.bukkit.craftbukkit.event.CraftEventFactory.callAreaEffectCloudApplyEvent(this, entities);
+ if (true) { // Preserve NMS spacing and bracket count for smallest diff
+ for (LivingEntity entity : event.getAffectedEntities()) {
+ if (entity instanceof CraftLivingEntity) {
+ EntityLiving entityliving = ((CraftLivingEntity) entity).getHandle();
+ // CraftBukkit end
this.g.put(entityliving, Integer.valueOf(this.ticksLived + this.reapplicationDelay));
Iterator iterator3 = arraylist.iterator();

View File

@ -14,7 +14,7 @@
public class EntityPotion extends EntityProjectile {
private static final DataWatcherObject<Optional<ItemStack>> d = DataWatcher.a(EntityItem.class, DataWatcherRegistry.f);
@@ -77,7 +84,7 @@
@@ -77,10 +84,11 @@
this.world.triggerEffect(2002, new BlockPosition(this), PotionRegistry.a(potionregistry));
this.die();
} else {
@ -23,15 +23,24 @@
if (this.n()) {
EntityAreaEffectCloud entityareaeffectcloud = new EntityAreaEffectCloud(this.world, this.locX, this.locY, this.locZ);
@@ -89,6 +96,7 @@
entityareaeffectcloud.a(potionregistry);
iterator = PotionUtil.b(itemstack).iterator();
+ entityareaeffectcloud.projectileSource = this.projectileSource; // CraftBukkit
entityareaeffectcloud.a(this.getShooter());
entityareaeffectcloud.setRadius(3.0F);
entityareaeffectcloud.setRadiusOnUse(-0.5F);
@@ -95,11 +103,21 @@
entityareaeffectcloud.a(new MobEffect(mobeffect.getMobEffect(), mobeffect.getDuration(), mobeffect.getAmplifier()));
}
+ // PAIL: Add events
while (iterator.hasNext()) {
MobEffect mobeffect = (MobEffect) iterator.next();
@@ -100,6 +108,9 @@
- this.world.addEntity(entityareaeffectcloud);
+ // CraftBukkit start
+ org.bukkit.event.entity.LingeringPotionSplashEvent event = org.bukkit.craftbukkit.event.CraftEventFactory.callLingeringPotionSplashEvent(this, entityareaeffectcloud);
+ if (!(event.isCancelled() || entityareaeffectcloud.dead)) {
+ this.world.addEntity(entityareaeffectcloud);
+ } else {
+ entityareaeffectcloud.dead = true;
+ }
+ // CraftBukkit end
} else {
AxisAlignedBB axisalignedbb = this.getBoundingBox().grow(4.0D, 2.0D, 4.0D);
List list1 = this.world.a(EntityLiving.class, axisalignedbb);
@ -41,7 +50,7 @@
if (!list1.isEmpty()) {
Iterator iterator1 = list1.iterator();
@@ -116,21 +127,45 @@
@@ -116,21 +134,45 @@
d1 = 1.0D;
}
@ -101,7 +110,7 @@
}
}
}
@@ -138,19 +173,20 @@
@@ -138,19 +180,20 @@
}
}
}

View File

@ -2,6 +2,7 @@ package org.bukkit.craftbukkit.entity;
import java.util.List;
import net.minecraft.server.EntityAreaEffectCloud;
import net.minecraft.server.EntityLiving;
import net.minecraft.server.MobEffect;
import net.minecraft.server.MobEffectList;
@ -15,6 +16,7 @@ import org.bukkit.entity.AreaEffectCloud;
import org.bukkit.entity.EntityType;
import org.bukkit.potion.PotionEffect;
import org.bukkit.potion.PotionEffectType;
import org.bukkit.projectiles.ProjectileSource;
import org.bukkit.potion.PotionData;
import com.google.common.collect.ImmutableList;
@ -202,4 +204,17 @@ public class CraftAreaEffectCloud extends CraftEntity implements AreaEffectCloud
public PotionData getBasePotionData() {
return CraftPotionUtil.toBukkit(getHandle().getType());
}
public ProjectileSource getSource() {
return getHandle().projectileSource;
}
public void setSource(ProjectileSource shooter) {
if (shooter instanceof CraftLivingEntity) {
getHandle().a((EntityLiving) ((CraftLivingEntity) shooter).getHandle()); // PAIL rename setSource
} else {
getHandle().a((EntityLiving) null);
}
getHandle().projectileSource = shooter;
}
}

View File

@ -6,9 +6,10 @@ import org.bukkit.Material;
import org.bukkit.craftbukkit.CraftServer;
import org.bukkit.craftbukkit.inventory.CraftItemStack;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.LingeringPotion;
import org.bukkit.inventory.ItemStack;
public class CraftLingeringPotion extends CraftThrownPotion {
public class CraftLingeringPotion extends CraftThrownPotion implements LingeringPotion {
public CraftLingeringPotion(CraftServer server, EntityPotion entity) {
super(server, entity);

View File

@ -6,9 +6,10 @@ import org.bukkit.Material;
import org.bukkit.craftbukkit.CraftServer;
import org.bukkit.craftbukkit.inventory.CraftItemStack;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.SplashPotion;
import org.bukkit.inventory.ItemStack;
public class CraftSplashPotion extends CraftThrownPotion {
public class CraftSplashPotion extends CraftThrownPotion implements SplashPotion {
public CraftSplashPotion(CraftServer server, EntityPotion entity) {
super(server, entity);

View File

@ -31,6 +31,7 @@ import org.bukkit.craftbukkit.inventory.CraftItemStack;
import org.bukkit.craftbukkit.inventory.CraftMetaBook;
import org.bukkit.craftbukkit.util.CraftDamageSource;
import org.bukkit.craftbukkit.util.CraftMagicNumbers;
import org.bukkit.entity.AreaEffectCloud;
import org.bukkit.entity.Arrow;
import org.bukkit.entity.Creeper;
import org.bukkit.entity.EntityType;
@ -344,6 +345,15 @@ public class CraftEventFactory {
return event;
}
public static LingeringPotionSplashEvent callLingeringPotionSplashEvent(EntityPotion potion, EntityAreaEffectCloud cloud) {
ThrownPotion thrownPotion = (ThrownPotion) potion.getBukkitEntity();
AreaEffectCloud effectCloud = (AreaEffectCloud) cloud.getBukkitEntity();
LingeringPotionSplashEvent event = new LingeringPotionSplashEvent(thrownPotion, effectCloud);
Bukkit.getPluginManager().callEvent(event);
return event;
}
/**
* BlockFadeEvent
*/
@ -993,4 +1003,10 @@ public class CraftEventFactory {
entity.world.getServer().getPluginManager().callEvent(event);
return event;
}
public static AreaEffectCloudApplyEvent callAreaEffectCloudApplyEvent(EntityAreaEffectCloud cloud, List<LivingEntity> entities) {
AreaEffectCloudApplyEvent event = new AreaEffectCloudApplyEvent((AreaEffectCloud) cloud.getBukkitEntity(), entities);
cloud.world.getServer().getPluginManager().callEvent(event);
return event;
}
}