aboutsummaryrefslogtreecommitdiffhomepage
path: root/Spigot-Server-Patches/0715-Added-PlayerBedFailEnterEvent.patch
blob: 16189aeee4cfec4ad991f69aef36fe27b43943c2 (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
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Jake Potrebic <jake.m.potrebic@gmail.com>
Date: Thu, 24 Dec 2020 12:27:41 -0800
Subject: [PATCH] Added PlayerBedFailEnterEvent


diff --git a/src/main/java/net/minecraft/world/entity/player/EntityHuman.java b/src/main/java/net/minecraft/world/entity/player/EntityHuman.java
index 3a13e7a050db7f5c93d810afe56325495cec7aa4..c39c50e53549e9cb9d3520bc7e8b7e89cfa20163 100644
--- a/src/main/java/net/minecraft/world/entity/player/EntityHuman.java
+++ b/src/main/java/net/minecraft/world/entity/player/EntityHuman.java
@@ -2233,6 +2233,7 @@ public abstract class EntityHuman extends EntityLiving {
             this.g = ichatbasecomponent;
         }
 
+        public @Nullable IChatBaseComponent getChatComponent() { return this.a(); }; // Paper - OBFHELPER
         @Nullable
         public IChatBaseComponent a() {
             return this.g;
diff --git a/src/main/java/net/minecraft/world/level/block/BlockBed.java b/src/main/java/net/minecraft/world/level/block/BlockBed.java
index eca84595342756e3550883551e487aaf79574fde..00a01a157deec004bcf2f8587723a0ecd0bfef85 100644
--- a/src/main/java/net/minecraft/world/level/block/BlockBed.java
+++ b/src/main/java/net/minecraft/world/level/block/BlockBed.java
@@ -43,6 +43,8 @@ import net.minecraft.world.phys.shapes.VoxelShape;
 import net.minecraft.world.phys.shapes.VoxelShapeCollision;
 import net.minecraft.world.phys.shapes.VoxelShapes;
 import org.apache.commons.lang3.ArrayUtils;
+import io.papermc.paper.event.player.PlayerBedFailEnterEvent; // Paper
+import io.papermc.paper.adventure.PaperAdventure; // Paper
 
 public class BlockBed extends BlockFacingHorizontal implements ITileEntity {
 
@@ -101,14 +103,23 @@ public class BlockBed extends BlockFacingHorizontal implements ITileEntity {
                 BlockPosition finalblockposition = blockposition;
                 // CraftBukkit end
                 entityhuman.sleep(blockposition).ifLeft((entityhuman_enumbedresult) -> {
+                    // Paper start - PlayerBedFailEnterEvent
+                    if (entityhuman_enumbedresult != null) {
+                        PlayerBedFailEnterEvent event = new PlayerBedFailEnterEvent((org.bukkit.entity.Player) entityhuman.getBukkitEntity(), PlayerBedFailEnterEvent.FailReason.VALUES[entityhuman_enumbedresult.ordinal()], org.bukkit.craftbukkit.block.CraftBlock.at(world, finalblockposition), entityhuman_enumbedresult == EntityHuman.EnumBedResult.NOT_POSSIBLE_HERE, PaperAdventure.asAdventure(entityhuman_enumbedresult.getChatComponent()));
+                        if (!event.callEvent()) {
+                            return;
+                        }
+                        // Paper end
                     // CraftBukkit start - handling bed explosion from below here
-                    if (entityhuman_enumbedresult == EntityHuman.EnumBedResult.NOT_POSSIBLE_HERE) {
+                    if (event.getWillExplode()) { // Paper
                         this.explodeBed(finaliblockdata, world, finalblockposition);
                     } else
                     // CraftBukkit end
                     if (entityhuman_enumbedresult != null) {
-                        entityhuman.a(entityhuman_enumbedresult.a(), true);
+                        final net.kyori.adventure.text.Component message = event.getMessage(); // Paper
+                        if(message != null) entityhuman.a(PaperAdventure.asVanilla(message), true); // Paper
                     }
+                    } // Paper
 
                 });
                 return EnumInteractionResult.SUCCESS;