summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorkaenganxt <kaenganxt@mc-anura.de>2018-07-20 16:04:37 +1000
committermd_5 <git@md-5.net>2018-07-20 16:06:34 +1000
commit814c742554e40554a30cee1915b42457081000c6 (patch)
treeab1cc74348447c556db92576fd282ab465c70f3d /src
parentfa6e97a8f8c57e0a5bbd046fe9af3d795a2c11b5 (diff)
downloadcraftbukkit-814c742554e40554a30cee1915b42457081000c6.tar
craftbukkit-814c742554e40554a30cee1915b42457081000c6.tar.gz
craftbukkit-814c742554e40554a30cee1915b42457081000c6.tar.lz
craftbukkit-814c742554e40554a30cee1915b42457081000c6.tar.xz
craftbukkit-814c742554e40554a30cee1915b42457081000c6.zip
SPIGOT-840, SPIGOT-2522: [Draft] Add EntityPotionEffectChangeEvent
Discussion ongoing in PR #449
Diffstat (limited to 'src')
-rw-r--r--src/main/java/org/bukkit/craftbukkit/entity/CraftLivingEntity.java5
-rw-r--r--src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java35
2 files changed, 38 insertions, 2 deletions
diff --git a/src/main/java/org/bukkit/craftbukkit/entity/CraftLivingEntity.java b/src/main/java/org/bukkit/craftbukkit/entity/CraftLivingEntity.java
index 382b8028..13100e5d 100644
--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftLivingEntity.java
+++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftLivingEntity.java
@@ -68,6 +68,7 @@ import org.bukkit.entity.ThrownPotion;
import org.bukkit.entity.TippedArrow;
import org.bukkit.entity.Trident;
import org.bukkit.entity.WitherSkull;
+import org.bukkit.event.entity.EntityPotionEffectEvent;
import org.bukkit.event.player.PlayerTeleportEvent;
import org.bukkit.inventory.EntityEquipment;
import org.bukkit.inventory.ItemStack;
@@ -262,7 +263,7 @@ public class CraftLivingEntity extends CraftEntity implements LivingEntity {
}
removePotionEffect(effect.getType());
}
- getHandle().addEffect(new MobEffect(MobEffectList.fromId(effect.getType().getId()), effect.getDuration(), effect.getAmplifier(), effect.isAmbient(), effect.hasParticles()));
+ getHandle().addEffect(new MobEffect(MobEffectList.fromId(effect.getType().getId()), effect.getDuration(), effect.getAmplifier(), effect.isAmbient(), effect.hasParticles()), EntityPotionEffectEvent.Cause.PLUGIN);
return true;
}
@@ -285,7 +286,7 @@ public class CraftLivingEntity extends CraftEntity implements LivingEntity {
}
public void removePotionEffect(PotionEffectType type) {
- getHandle().removeEffect(MobEffectList.fromId(type.getId()));
+ getHandle().removeEffect(MobEffectList.fromId(type.getId()), EntityPotionEffectEvent.Cause.PLUGIN);
}
public Collection<PotionEffect> getActivePotionEffects() {
diff --git a/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java b/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java
index 5793bdf4..72b5dfd7 100644
--- a/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java
+++ b/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java
@@ -31,6 +31,7 @@ import org.bukkit.craftbukkit.entity.CraftPlayer;
import org.bukkit.craftbukkit.inventory.CraftInventoryCrafting;
import org.bukkit.craftbukkit.inventory.CraftItemStack;
import org.bukkit.craftbukkit.inventory.CraftMetaBook;
+import org.bukkit.craftbukkit.potion.CraftPotionUtil;
import org.bukkit.craftbukkit.util.CraftDamageSource;
import org.bukkit.craftbukkit.util.CraftMagicNumbers;
import org.bukkit.entity.AreaEffectCloud;
@@ -67,6 +68,7 @@ import org.bukkit.inventory.meta.BookMeta;
import org.bukkit.entity.AbstractHorse;
import org.bukkit.entity.Vehicle;
import org.bukkit.event.vehicle.VehicleCreateEvent;
+import org.bukkit.potion.PotionEffect;
public class CraftEventFactory {
public static final DamageSource MELTING = CraftDamageSource.copyOf(DamageSource.BURN);
@@ -1054,6 +1056,39 @@ public class CraftEventFactory {
return handleBlockFormEvent(world, pos, block, 3);
}
+ public static EntityPotionEffectEvent callEntityPotionEffectChangeEvent(EntityLiving entity, @Nullable MobEffect oldEffect, @Nullable MobEffect newEffect, EntityPotionEffectEvent.Cause cause) {
+ return callEntityPotionEffectChangeEvent(entity, oldEffect, newEffect, cause, true);
+ }
+
+ public static EntityPotionEffectEvent callEntityPotionEffectChangeEvent(EntityLiving entity, @Nullable MobEffect oldEffect, @Nullable MobEffect newEffect, EntityPotionEffectEvent.Cause cause, EntityPotionEffectEvent.Action action) {
+ return callEntityPotionEffectChangeEvent(entity, oldEffect, newEffect, cause, action, true);
+ }
+
+ public static EntityPotionEffectEvent callEntityPotionEffectChangeEvent(EntityLiving entity, @Nullable MobEffect oldEffect, @Nullable MobEffect newEffect, EntityPotionEffectEvent.Cause cause, boolean willOverride) {
+ EntityPotionEffectEvent.Action action = EntityPotionEffectEvent.Action.CHANGED;
+ if (oldEffect == null) {
+ action = EntityPotionEffectEvent.Action.ADDED;
+ } else if (newEffect == null) {
+ action = EntityPotionEffectEvent.Action.REMOVED;
+ }
+
+ return callEntityPotionEffectChangeEvent(entity, oldEffect, newEffect, cause, action, willOverride);
+ }
+
+ public static EntityPotionEffectEvent callEntityPotionEffectChangeEvent(EntityLiving entity, @Nullable MobEffect oldEffect, @Nullable MobEffect newEffect, EntityPotionEffectEvent.Cause cause, EntityPotionEffectEvent.Action action, boolean willOverride) {
+ PotionEffect bukkitOldEffect = (oldEffect == null) ? null : CraftPotionUtil.toBukkit(oldEffect);
+ PotionEffect bukkitNewEffect = (newEffect == null) ? null : CraftPotionUtil.toBukkit(newEffect);
+
+ if (bukkitOldEffect == null && bukkitNewEffect == null) {
+ throw new IllegalStateException("Old and new potion effect are both null");
+ }
+
+ EntityPotionEffectEvent event = new EntityPotionEffectEvent((LivingEntity) entity.getBukkitEntity(), bukkitOldEffect, bukkitNewEffect, cause, action, willOverride);
+ Bukkit.getPluginManager().callEvent(event);
+
+ return event;
+ }
+
public static boolean handleBlockFormEvent(World world, BlockPosition pos, IBlockData block, @Nullable Entity entity) {
return handleBlockFormEvent(world, pos, block, 3, entity);
}