aboutsummaryrefslogtreecommitdiffhomepage
path: root/patches/server/0529-Add-PlayerBedFailEnterEvent.patch
blob: feffef2aecf7eabaef606ef2b20a45fdef870e26 (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
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] Add PlayerBedFailEnterEvent


diff --git a/src/main/java/net/minecraft/world/level/block/BedBlock.java b/src/main/java/net/minecraft/world/level/block/BedBlock.java
index 4eb1a77e2a85a242dd5342a500763d87dbe7655e..18b9a62613c08eb5bf63ae26565b0e91e1f44d39 100644
--- a/src/main/java/net/minecraft/world/level/block/BedBlock.java
+++ b/src/main/java/net/minecraft/world/level/block/BedBlock.java
@@ -118,14 +118,23 @@ public class BedBlock extends HorizontalDirectionalBlock implements EntityBlock
                 BlockPos finalblockposition = pos;
                 // CraftBukkit end
                 player.startSleepInBed(pos).ifLeft((entityhuman_enumbedresult) -> {
+                    // Paper start - PlayerBedFailEnterEvent
+                    if (entityhuman_enumbedresult != null) {
+                        io.papermc.paper.event.player.PlayerBedFailEnterEvent event = new io.papermc.paper.event.player.PlayerBedFailEnterEvent((org.bukkit.entity.Player) player.getBukkitEntity(), io.papermc.paper.event.player.PlayerBedFailEnterEvent.FailReason.values()[entityhuman_enumbedresult.ordinal()], org.bukkit.craftbukkit.block.CraftBlock.at(world, finalblockposition), !world.dimensionType().bedWorks(), io.papermc.paper.adventure.PaperAdventure.asAdventure(entityhuman_enumbedresult.getMessage()));
+                        if (!event.callEvent()) {
+                            return;
+                        }
+                        // Paper end - PlayerBedFailEnterEvent
                     // CraftBukkit start - handling bed explosion from below here
-                    if (!world.dimensionType().bedWorks()) {
+                    if (event.getWillExplode()) { // Paper - PlayerBedFailEnterEvent
                         this.explodeBed(finaliblockdata, world, finalblockposition);
                     } else
                     // CraftBukkit end
                     if (entityhuman_enumbedresult.getMessage() != null) {
-                        player.displayClientMessage(entityhuman_enumbedresult.getMessage(), true);
+                        final net.kyori.adventure.text.Component message = event.getMessage(); // Paper - PlayerBedFailEnterEvent
+                        if (message != null) player.displayClientMessage(io.papermc.paper.adventure.PaperAdventure.asVanilla(message), true); // Paper - PlayerBedFailEnterEvent
                     }
+                    } // Paper - PlayerBedFailEnterEvent
 
                 });
                 return InteractionResult.SUCCESS;