2021-06-11 14:02:28 +02:00
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: JRoy <joshroy126@gmail.com>
Date: Sun, 10 May 2020 23:06:30 -0400
Subject: [PATCH] Potential bed API
Adds a new method to fetch the location of a player's bed without generating any sync loads.
getPotentialBedLocation - Gets the last known location of a player's bed. This does not preform any check if the bed is still valid and does not load any chunks.
diff --git a/src/main/java/org/bukkit/craftbukkit/entity/CraftHumanEntity.java b/src/main/java/org/bukkit/craftbukkit/entity/CraftHumanEntity.java
2023-09-22 06:05:18 +02:00
index 872adf91703baa24d67f417e7a45309f92984da9..80694a1d660a10909408c9b3169dda7847bf295e 100644
2021-06-11 14:02:28 +02:00
--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftHumanEntity.java
+++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftHumanEntity.java
@@ -12,6 +12,7 @@ import net.minecraft.nbt.CompoundTag;
import net.minecraft.network.chat.Component;
import net.minecraft.network.protocol.game.ClientboundOpenScreenPacket;
import net.minecraft.network.protocol.game.ServerboundContainerClosePacket;
+import net.minecraft.server.level.ServerLevel;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.world.MenuProvider;
import net.minecraft.world.entity.Entity;
2023-05-12 13:10:08 +02:00
@@ -130,6 +131,22 @@ public class CraftHumanEntity extends CraftLivingEntity implements HumanEntity {
2021-06-14 07:32:56 +02:00
return this.getHandle().sleepCounter;
2021-06-11 14:02:28 +02:00
}
+ // Paper start - Potential bed api
+ @Override
+ public Location getPotentialBedLocation() {
+ ServerPlayer handle = (ServerPlayer) getHandle();
+ BlockPos bed = handle.getRespawnPosition();
+ if (bed == null) {
+ return null;
+ }
+
+ ServerLevel worldServer = handle.server.getLevel(handle.getRespawnDimension());
+ if (worldServer == null) {
+ return null;
+ }
+ return new Location(worldServer.getWorld(), bed.getX(), bed.getY(), bed.getZ());
+ }
+ // Paper end
@Override
public boolean sleep(Location location, boolean force) {
Preconditions.checkArgument(location != null, "Location cannot be null");