aboutsummaryrefslogtreecommitdiffhomepage
path: root/Spigot-Server-Patches/0038-Add-BeaconEffectEvent.patch
blob: 6b397633d8dd2369f8ff1246d9077d3c86e5020c (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
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Byteflux <byte@byteflux.net>
Date: Wed, 2 Mar 2016 23:30:53 -0600
Subject: [PATCH] Add BeaconEffectEvent


diff --git a/src/main/java/net/minecraft/server/TileEntityBeacon.java b/src/main/java/net/minecraft/server/TileEntityBeacon.java
index b9aa63e6c38f6b023da5e9865ba1f74f931cc7af..2858ea1f3eb44ea2cc6b11454b8e94bca4ab0568 100644
--- a/src/main/java/net/minecraft/server/TileEntityBeacon.java
+++ b/src/main/java/net/minecraft/server/TileEntityBeacon.java
@@ -14,6 +14,11 @@ import org.bukkit.craftbukkit.potion.CraftPotionUtil;
 import org.bukkit.entity.HumanEntity;
 import org.bukkit.potion.PotionEffect;
 // CraftBukkit end
+// Paper start
+import org.bukkit.craftbukkit.event.CraftEventFactory;
+import org.bukkit.entity.Player;
+import com.destroystokyo.paper.event.block.BeaconEffectEvent;
+// Paper end
 
 public class TileEntityBeacon extends TileEntity implements ITileInventory, ITickable {
 
@@ -240,14 +245,31 @@ public class TileEntityBeacon extends TileEntity implements ITileInventory, ITic
     }
 
     private void applyEffect(List list, MobEffectList effects, int i, int b0) {
+        // Paper - BeaconEffectEvent
+        applyEffect(list, effects, i, b0, true);
+    }
+
+    private void applyEffect(List list, MobEffectList effects, int i, int b0, boolean isPrimary) {
+        // Paper - BeaconEffectEvent
         {
             Iterator iterator = list.iterator();
 
             EntityHuman entityhuman;
 
+            // Paper start - BeaconEffectEvent
+            org.bukkit.block.Block block = world.getWorld().getBlockAt(position.getX(), position.getY(), position.getZ());
+            PotionEffect effect = CraftPotionUtil.toBukkit(new MobEffect(effects, i, b0, true, true));
+            // Paper end
+
             while (iterator.hasNext()) {
                 entityhuman = (EntityHuman) iterator.next();
-                entityhuman.addEffect(new MobEffect(effects, i, b0, true, true), org.bukkit.event.entity.EntityPotionEffectEvent.Cause.BEACON);
+
+                // Paper start - BeaconEffectEvent
+                BeaconEffectEvent event = new BeaconEffectEvent(block, effect, (Player) entityhuman.getBukkitEntity(), isPrimary);
+                if (CraftEventFactory.callEvent(event).isCancelled()) continue;
+                PotionEffect eventEffect = event.getEffect();
+                entityhuman.addEffect(new MobEffect(MobEffectList.fromId(eventEffect.getType().getId()), eventEffect.getDuration(), eventEffect.getAmplifier(), true, true), org.bukkit.event.entity.EntityPotionEffectEvent.Cause.BEACON);
+                // Paper end
             }
         }
     }
@@ -270,10 +292,10 @@ public class TileEntityBeacon extends TileEntity implements ITileInventory, ITic
             int i = getLevel();
             List list = getHumansInRange();
 
-            applyEffect(list, this.primaryEffect, i, b0);
+            applyEffect(list, this.primaryEffect, i, b0, true); // Paper - BeaconEffectEvent
 
             if (hasSecondaryEffect()) {
-                applyEffect(list, this.secondaryEffect, i, 0);
+                applyEffect(list, this.secondaryEffect, i, 0, false); // Paper - BeaconEffectEvent
             }
         }