summaryrefslogtreecommitdiffstats
path: root/nms-patches/EntityPotion.patch
blob: 5d169e65449cf606ef59646da804557c5489adbe (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
--- /home/matt/mc-dev-private//net/minecraft/server/EntityPotion.java	2015-02-26 22:40:22.663608139 +0000
+++ src/main/java/net/minecraft/server/EntityPotion.java	2015-02-26 22:40:22.663608139 +0000
@@ -3,9 +3,16 @@
 import java.util.Iterator;
 import java.util.List;
 
+// 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 ItemStack item;
+    public ItemStack item; // CraftBukkit - public
 
     public EntityPotion(World world) {
         super(world);
@@ -57,13 +64,16 @@
         if (!this.world.isClientSide) {
             List list = Items.POTION.h(this.item);
 
-            if (list != null && !list.isEmpty()) {
+            if (true || list != null && !list.isEmpty()) { // CraftBukkit - Call event even if no effects to apply
                 AxisAlignedBB axisalignedbb = this.getBoundingBox().grow(4.0D, 2.0D, 4.0D);
                 List list1 = this.world.a(EntityLiving.class, axisalignedbb);
 
-                if (!list1.isEmpty()) {
+                if (true || !list1.isEmpty()) { // CraftBukkit - Run code even if there are no entities around
                     Iterator iterator = list1.iterator();
 
+                    // CraftBukkit
+                    HashMap<LivingEntity, Double> affected = new HashMap<LivingEntity, Double>();
+
                     while (iterator.hasNext()) {
                         EntityLiving entityliving = (EntityLiving) iterator.next();
                         double d0 = this.h(entityliving);
@@ -75,12 +85,35 @@
                                 d1 = 1.0D;
                             }
 
+                            // CraftBukkit start
+                            affected.put((LivingEntity) entityliving.getBukkitEntity(), d1);
+                        }
+                    }
+
+                    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 iterator1 = list.iterator();
 
                             while (iterator1.hasNext()) {
                                 MobEffect mobeffect = (MobEffect) iterator1.next();
                                 int i = mobeffect.getEffectId();
 
+                                // CraftBukkit start - Abide by PVP settings - for players only!
+                                if (!this.world.pvpMode && this.getShooter() instanceof EntityPlayer && entityliving instanceof EntityPlayer && entityliving != this.getShooter()) {
+                                    // 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.byId[i].isInstant()) {
                                     MobEffectList.byId[i].applyInstantEffect(this, this.getShooter(), entityliving, mobeffect.getAmplifier(), d1);
                                 } else {