summaryrefslogtreecommitdiffstats
path: root/nms-patches/EntityPotion.patch
blob: ef720315961e4e7319c1d3fb3c1dff1f906abe97 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
--- a/net/minecraft/server/EntityPotion.java
+++ b/net/minecraft/server/EntityPotion.java
@@ -7,6 +7,13 @@
 import org.apache.logging.log4j.LogManager;
 import org.apache.logging.log4j.Logger;
 
+// CraftBukkit start
+import java.util.HashMap;
+
+import org.bukkit.craftbukkit.entity.CraftLivingEntity;
+import org.bukkit.entity.LivingEntity;
+// CraftBukkit end
+
 public class EntityPotion extends EntityProjectile {
 
     private static final DataWatcherObject<Optional<ItemStack>> d = DataWatcher.a(EntityPotion.class, DataWatcherRegistry.f);
@@ -78,10 +85,11 @@
                 this.world.triggerEffect(2002, new BlockPosition(this), PotionRegistry.a(potionregistry));
                 this.die();
             } else {
-                if (!list.isEmpty()) {
+                if (true || !list.isEmpty()) { // CraftBukkit - Call event even if no effects to apply
                     if (this.isLingering()) {
                         EntityAreaEffectCloud entityareaeffectcloud = new EntityAreaEffectCloud(this.world, this.locX, this.locY, this.locZ);
 
+                        entityareaeffectcloud.projectileSource = this.projectileSource; // CraftBukkit
                         entityareaeffectcloud.setSource(this.getShooter());
                         entityareaeffectcloud.setRadius(3.0F);
                         entityareaeffectcloud.setRadiusOnUse(-0.5F);
@@ -96,11 +104,21 @@
                             entityareaeffectcloud.a(new MobEffect(mobeffect.getMobEffect(), mobeffect.getDuration(), mobeffect.getAmplifier()));
                         }
 
-                        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);
 
+                        // CraftBukkit
+                        HashMap<LivingEntity, Double> affected = new HashMap<LivingEntity, Double>();
+
                         if (!list1.isEmpty()) {
                             Iterator iterator1 = list1.iterator();
 
@@ -117,21 +135,45 @@
                                             d1 = 1.0D;
                                         }
 
-                                        Iterator iterator2 = list.iterator();
+                                        // CraftBukkit start
+                                        affected.put((LivingEntity) entityliving.getBukkitEntity(), d1);
+                                    }
+                                }
+                            }
+                        }
 
-                                        while (iterator2.hasNext()) {
-                                            MobEffect mobeffect1 = (MobEffect) iterator2.next();
-                                            MobEffectList mobeffectlist = mobeffect1.getMobEffect();
-
-                                            if (mobeffectlist.isInstant()) {
-                                                mobeffectlist.applyInstantEffect(this, this.getShooter(), entityliving, mobeffect1.getAmplifier(), d1);
-                                            } else {
-                                                int i = (int) (d1 * (double) mobeffect1.getDuration() + 0.5D);
-
-                                                if (i > 20) {
-                                                    entityliving.addEffect(new MobEffect(mobeffectlist, i, mobeffect1.getAmplifier()));
-                                                }
-                                            }
+                        org.bukkit.event.entity.PotionSplashEvent event = org.bukkit.craftbukkit.event.CraftEventFactory.callPotionSplashEvent(this, affected);
+                        if (!event.isCancelled() && list != null && !list.isEmpty()) { // do not process effects if there are no effects to process
+                            for (LivingEntity victim : event.getAffectedEntities()) {
+                                if (!(victim instanceof CraftLivingEntity)) {
+                                    continue;
+                                }
+
+                                EntityLiving entityliving = ((CraftLivingEntity) victim).getHandle();
+                                double d1 = event.getIntensity(victim);
+                                // CraftBukkit end
+
+                                Iterator iterator2 = list.iterator();
+
+                                while (iterator2.hasNext()) {
+                                    MobEffect mobeffect1 = (MobEffect) iterator2.next();
+                                    MobEffectList mobeffectlist = mobeffect1.getMobEffect();
+                                    // CraftBukkit start - Abide by PVP settings - for players only!
+                                    if (!this.world.pvpMode && this.getShooter() instanceof EntityPlayer && entityliving instanceof EntityPlayer && entityliving != this.getShooter()) {
+                                        int i = MobEffectList.getId(mobeffectlist);
+                                        // Block SLOWER_MOVEMENT, SLOWER_DIG, HARM, BLINDNESS, HUNGER, WEAKNESS and POISON potions
+                                        if (i == 2 || i == 4 || i == 7 || i == 15 || i == 17 || i == 18 || i == 19) {
+                                            continue;
+                                        }
+                                    }
+                                    // CraftBukkit end
+                                    if (mobeffectlist.isInstant()) {
+                                        mobeffectlist.applyInstantEffect(this, this.getShooter(), entityliving, mobeffect1.getAmplifier(), d1);
+                                    } else {
+                                        int i = (int) (d1 * (double) mobeffect1.getDuration() + 0.5D);
+
+                                        if (i > 20) {
+                                            entityliving.addEffect(new MobEffect(mobeffectlist, i, mobeffect1.getAmplifier()));
                                         }
                                     }
                                 }
@@ -139,10 +181,10 @@
                         }
                     }
                 }
-
-                this.world.triggerEffect(2002, new BlockPosition(this), PotionRegistry.a(potionregistry));
-                this.die();
             }
+
+            this.world.triggerEffect(2002, new BlockPosition(this), PotionRegistry.a(potionregistry));
+            this.die();
         }
     }
 
@@ -152,6 +194,7 @@
 
     private void a(BlockPosition blockposition) {
         if (this.world.getType(blockposition).getBlock() == Blocks.FIRE) {
+            if (org.bukkit.craftbukkit.event.CraftEventFactory.callEntityChangeBlockEvent(this, blockposition, Blocks.AIR, 0).isCancelled()) return; // CraftBukkit
             this.world.setTypeAndData(blockposition, Blocks.AIR.getBlockData(), 2);
         }