From 85ee50d5f1070625d2a78d9eac609eee2bd814b5 Mon Sep 17 00:00:00 2001 From: CraftBukkit/Spigot Date: Fri, 10 Jun 2022 09:56:52 +1000 Subject: [PATCH] SPIGOT-7047: Add Player#getLastDeathLocation By: Doc --- .../bukkit/craftbukkit/CraftOfflinePlayer.java | 11 +++++++++++ .../craftbukkit/entity/CraftHumanEntity.java | 15 +++++++++++++++ 2 files 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 a02ae32f54..3e462e63ff 100644 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/CraftOfflinePlayer.java +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/CraftOfflinePlayer.java @@ -6,6 +6,8 @@ import java.util.LinkedHashMap; import java.util.List; import java.util.Map; import java.util.UUID; +import net.minecraft.core.GlobalPos; +import net.minecraft.nbt.DynamicOpsNBT; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.server.players.WhiteListEntry; import net.minecraft.stats.ServerStatisticManager; @@ -19,6 +21,7 @@ import org.bukkit.Server; import org.bukkit.Statistic; import org.bukkit.configuration.serialization.ConfigurationSerializable; import org.bukkit.configuration.serialization.SerializableAs; +import org.bukkit.craftbukkit.entity.memory.CraftMemoryMapper; import org.bukkit.craftbukkit.profile.CraftPlayerProfile; import org.bukkit.entity.EntityType; import org.bukkit.entity.Player; @@ -247,6 +250,14 @@ public class CraftOfflinePlayer implements OfflinePlayer, ConfigurationSerializa return getData() != null; } + @Override + public Location getLastDeathLocation() { + if (getData().contains("LastDeathLocation", 10)) { + return GlobalPos.CODEC.parse(DynamicOpsNBT.INSTANCE, getData().get("LastDeathLocation")).result().map(CraftMemoryMapper::fromNms).orElse(null); + } + return null; + } + @Override public Location getBedSpawnLocation() { NBTTagCompound data = getData(); diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftHumanEntity.java b/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftHumanEntity.java index 1e973add11..ac19f50306 100644 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftHumanEntity.java +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftHumanEntity.java @@ -36,6 +36,7 @@ import org.bukkit.Material; import org.bukkit.NamespacedKey; import org.bukkit.block.Block; import org.bukkit.craftbukkit.CraftServer; +import org.bukkit.craftbukkit.entity.memory.CraftMemoryMapper; import org.bukkit.craftbukkit.event.CraftEventFactory; import org.bukkit.craftbukkit.inventory.CraftContainer; import org.bukkit.craftbukkit.inventory.CraftInventory; @@ -646,4 +647,18 @@ public class CraftHumanEntity extends CraftLivingEntity implements HumanEntity { public void setStarvationRate(int i) { getHandle().getFoodData().starvationRate = i; } + + @Override + public Location getLastDeathLocation() { + return getHandle().getLastDeathLocation().map(CraftMemoryMapper::fromNms).orElse(null); + } + + @Override + public void setLastDeathLocation(Location location) { + if (location == null) { + getHandle().setLastDeathLocation(Optional.empty()); + } else { + getHandle().setLastDeathLocation(Optional.of(CraftMemoryMapper.toNms(location))); + } + } }