aboutsummaryrefslogtreecommitdiffhomepage
path: root/patches/server/0049-Add-BeaconEffectEvent.patch
blob: ce80109f252b7dd0b1f4c27e86bbaa43b85de7bc (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
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/world/level/block/entity/BeaconBlockEntity.java b/src/main/java/net/minecraft/world/level/block/entity/BeaconBlockEntity.java
index 94fcd67edd81120d56478ffd30f3c1d7dee955e6..8332296663b845df1d09d403b49a4769b2d54afc 100644
--- a/src/main/java/net/minecraft/world/level/block/entity/BeaconBlockEntity.java
+++ b/src/main/java/net/minecraft/world/level/block/entity/BeaconBlockEntity.java
@@ -1,5 +1,6 @@
 package net.minecraft.world.level.block.entity;
 
+import com.destroystokyo.paper.event.block.BeaconEffectEvent;
 import com.google.common.collect.ImmutableList;
 import com.google.common.collect.Lists;
 import java.util.Collection;
@@ -46,6 +47,7 @@ import net.minecraft.world.level.block.state.BlockState;
 import net.minecraft.world.level.levelgen.Heightmap;
 import net.minecraft.world.phys.AABB;
 // CraftBukkit start
+import org.bukkit.craftbukkit.event.CraftEventFactory;
 import org.bukkit.craftbukkit.potion.CraftPotionUtil;
 import org.bukkit.potion.PotionEffect;
 // CraftBukkit end
@@ -295,15 +297,23 @@ public class BeaconBlockEntity extends BlockEntity implements MenuProvider, Name
         }
     }
 
-    private static void applyEffect(List list, @Nullable Holder<MobEffect> holder, int j, int b0) {
-        {
+    private static void applyEffect(List list, @Nullable Holder<MobEffect> holder, int j, int b0, boolean isPrimary, BlockPos worldPosition) { // Paper - BeaconEffectEvent
+        if (!list.isEmpty()) { // Paper - BeaconEffectEvent
             Iterator iterator = list.iterator();
 
             Player entityhuman;
+            // Paper start - BeaconEffectEvent
+            org.bukkit.block.Block block = org.bukkit.craftbukkit.block.CraftBlock.at(((Player) list.get(0)).level(), worldPosition);
+            PotionEffect effect = CraftPotionUtil.toBukkit(new MobEffectInstance(holder, j, b0, true, true));
+            // Paper end - BeaconEffectEvent
 
             while (iterator.hasNext()) {
-                entityhuman = (Player) iterator.next();
-                entityhuman.addEffect(new MobEffectInstance(holder, j, b0, true, true), org.bukkit.event.entity.EntityPotionEffectEvent.Cause.BEACON);
+                // Paper start - BeaconEffectEvent
+                entityhuman = (ServerPlayer) iterator.next();
+                BeaconEffectEvent event = new BeaconEffectEvent(block, effect, (org.bukkit.entity.Player) entityhuman.getBukkitEntity(), isPrimary);
+                if (CraftEventFactory.callEvent(event).isCancelled()) continue;
+                entityhuman.addEffect(new MobEffectInstance(CraftPotionUtil.fromBukkit(event.getEffect())), org.bukkit.event.entity.EntityPotionEffectEvent.Cause.BEACON);
+                // Paper end - BeaconEffectEvent
             }
         }
     }
@@ -326,10 +336,10 @@ public class BeaconBlockEntity extends BlockEntity implements MenuProvider, Name
             int j = BeaconBlockEntity.getLevel(beaconLevel);
             List list = BeaconBlockEntity.getHumansInRange(world, pos, beaconLevel);
 
-            BeaconBlockEntity.applyEffect(list, primaryEffect, j, b0);
+            BeaconBlockEntity.applyEffect(list, primaryEffect, j, b0, true, pos); // Paper - BeaconEffectEvent
 
             if (BeaconBlockEntity.hasSecondaryEffect(beaconLevel, primaryEffect, secondaryEffect)) {
-                BeaconBlockEntity.applyEffect(list, secondaryEffect, j, 0);
+                BeaconBlockEntity.applyEffect(list, secondaryEffect, j, 0, false, pos); // Paper - BeaconEffectEvent
             }
         }