Paper/patches/server-remapped/0717-Added-PlayerBedFailEnterEvent.patch
Mariell Hoversholm a207d14a0e
Rename all patches to correct numbering scheme
Signed-off-by: Mariell Hoversholm <proximyst@proximyst.com>
2021-06-11 15:46:44 +02:00

58 lines
3.5 KiB
Diff

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/Player.java b/src/main/java/net/minecraft/world/entity/player/Player.java
index c0d2ca1daca0c0c6f21334bc4d9d039440efc453..007d9476943f5a9c75554927df941bda0f7dd6d5 100644
--- a/src/main/java/net/minecraft/world/entity/player/Player.java
+++ b/src/main/java/net/minecraft/world/entity/player/Player.java
@@ -2230,6 +2230,7 @@ public abstract class Player extends LivingEntity {
this.message = ichatbasecomponent;
}
+ public @Nullable Component getChatComponent() { return this.getMessage(); }; // Paper - OBFHELPER
@Nullable
public Component getMessage() {
return this.message;
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 9dcbc0f741f5980305ae031daac70c7933bc6862..9dcf145b6d1a93785150d268828bca4bb31984c8 100644
--- a/src/main/java/net/minecraft/world/level/block/BedBlock.java
+++ b/src/main/java/net/minecraft/world/level/block/BedBlock.java
@@ -43,6 +43,8 @@ import net.minecraft.world.phys.shapes.CollisionContext;
import net.minecraft.world.phys.shapes.Shapes;
import net.minecraft.world.phys.shapes.VoxelShape;
import org.apache.commons.lang3.ArrayUtils;
+import io.papermc.paper.event.player.PlayerBedFailEnterEvent; // Paper
+import io.papermc.paper.adventure.PaperAdventure; // Paper
public class BedBlock extends HorizontalDirectionalBlock implements EntityBlock {
@@ -101,14 +103,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) {
+ PlayerBedFailEnterEvent event = new PlayerBedFailEnterEvent((org.bukkit.entity.Player) player.getBukkitEntity(), PlayerBedFailEnterEvent.FailReason.VALUES[entityhuman_enumbedresult.ordinal()], org.bukkit.craftbukkit.block.CraftBlock.at(world, finalblockposition), entityhuman_enumbedresult == Player.BedSleepingProblem.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 == Player.BedSleepingProblem.NOT_POSSIBLE_HERE) {
+ if (event.getWillExplode()) { // Paper
this.explodeBed(finaliblockdata, world, finalblockposition);
} else
// CraftBukkit end
if (entityhuman_enumbedresult != null) {
- player.displayClientMessage(entityhuman_enumbedresult.getMessage(), true);
+ final net.kyori.adventure.text.Component message = event.getMessage(); // Paper
+ if(message != null) player.displayClientMessage(PaperAdventure.asVanilla(message), true); // Paper
}
+ } // Paper
});
return InteractionResult.SUCCESS;