From e216f2ef2d9bd45aee305b6b76271e7ea40223f8 Mon Sep 17 00:00:00 2001 From: CraftBukkit/Spigot Date: Mon, 15 Jan 2024 20:30:41 +1100 Subject: [PATCH] #1329: Add method to get an offline player's location By: Nothixal --- .../craftbukkit/CraftOfflinePlayer.java | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/CraftOfflinePlayer.java b/paper-server/src/main/java/org/bukkit/craftbukkit/CraftOfflinePlayer.java index 63d1588c93..67fd0dfc40 100644 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/CraftOfflinePlayer.java +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/CraftOfflinePlayer.java @@ -12,6 +12,7 @@ import java.util.UUID; import net.minecraft.core.GlobalPos; import net.minecraft.nbt.DynamicOpsNBT; import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.nbt.NBTTagList; import net.minecraft.server.players.WhiteListEntry; import net.minecraft.stats.ServerStatisticManager; import net.minecraft.world.level.storage.WorldNBTStorage; @@ -269,6 +270,31 @@ public class CraftOfflinePlayer implements OfflinePlayer, ConfigurationSerializa return null; } + @Override + public Location getLocation() { + NBTTagCompound data = getData(); + if (data == null) { + return null; + } + + if (data.contains("Pos") && data.contains("Rotation")) { + NBTTagList position = (NBTTagList) data.get("Pos"); + NBTTagList rotation = (NBTTagList) data.get("Rotation"); + + UUID uuid = new UUID(data.getLong("WorldUUIDMost"), data.getLong("WorldUUIDLeast")); + + return new Location(server.getWorld(uuid), + position.getDouble(0), + position.getDouble(1), + position.getDouble(2), + rotation.getFloat(0), + rotation.getFloat(1) + ); + } + + return null; + } + @Override public Location getBedSpawnLocation() { NBTTagCompound data = getData();