diff --git a/pom.xml b/pom.xml
index bc4125d..2801bb8 100644
--- a/pom.xml
+++ b/pom.xml
@@ -44,7 +44,7 @@
org.spigotmc
spigot-api
- 1.18-R0.1-SNAPSHOT
+ 1.18.1-R0.1-SNAPSHOT
provided
diff --git a/src/main/java/de/diddiz/LogBlock/blockstate/BlockStateCodecSkull.java b/src/main/java/de/diddiz/LogBlock/blockstate/BlockStateCodecSkull.java
index 1939944..d4ad35c 100644
--- a/src/main/java/de/diddiz/LogBlock/blockstate/BlockStateCodecSkull.java
+++ b/src/main/java/de/diddiz/LogBlock/blockstate/BlockStateCodecSkull.java
@@ -8,8 +8,20 @@ import org.bukkit.OfflinePlayer;
import org.bukkit.block.BlockState;
import org.bukkit.block.Skull;
import org.bukkit.configuration.file.YamlConfiguration;
+import org.bukkit.profile.PlayerProfile;
public class BlockStateCodecSkull implements BlockStateCodec {
+ private static final boolean HAS_PROFILE_API;
+ static {
+ boolean hasProfileApi = false;
+ try {
+ Skull.class.getMethod("getOwnerProfile");
+ hasProfileApi = true;
+ } catch (NoSuchMethodException ignored) {
+ }
+ HAS_PROFILE_API = hasProfileApi;
+ }
+
@Override
public Material[] getApplicableMaterials() {
return new Material[] { Material.PLAYER_WALL_HEAD, Material.PLAYER_HEAD };
@@ -20,9 +32,14 @@ public class BlockStateCodecSkull implements BlockStateCodec {
if (state instanceof Skull) {
Skull skull = (Skull) state;
OfflinePlayer owner = skull.hasOwner() ? skull.getOwningPlayer() : null;
- if (owner != null) {
+ PlayerProfile profile = HAS_PROFILE_API ? skull.getOwnerProfile() : null;
+ if (owner != null || profile != null) {
YamlConfiguration conf = new YamlConfiguration();
- conf.set("owner", owner.getUniqueId().toString());
+ if (profile != null) {
+ conf.set("profile", profile);
+ } else if (owner != null) {
+ conf.set("owner", owner.getUniqueId().toString());
+ }
return conf;
}
}
@@ -33,18 +50,30 @@ public class BlockStateCodecSkull implements BlockStateCodec {
public void deserialize(BlockState state, YamlConfiguration conf) {
if (state instanceof Skull) {
Skull skull = (Skull) state;
- UUID ownerId = conf == null ? null : UUID.fromString(conf.getString("owner"));
- if (ownerId == null) {
- skull.setOwningPlayer(null);
+ PlayerProfile profile = conf == null || !HAS_PROFILE_API ? null : (PlayerProfile) conf.get("profile");
+ if (profile != null) {
+ skull.setOwnerProfile(profile);
} else {
- skull.setOwningPlayer(Bukkit.getOfflinePlayer(ownerId));
+ UUID ownerId = conf == null ? null : UUID.fromString(conf.getString("owner"));
+ if (ownerId == null) {
+ skull.setOwningPlayer(null);
+ } else {
+ skull.setOwningPlayer(Bukkit.getOfflinePlayer(ownerId));
+ }
}
}
}
@Override
public String toString(YamlConfiguration conf, YamlConfiguration oldState) {
- UUID ownerId = conf == null ? null : UUID.fromString(conf.getString("owner"));
+ if (HAS_PROFILE_API && conf != null) {
+ PlayerProfile profile = (PlayerProfile) conf.get("profile");
+ if (profile != null) {
+ return "[" + (profile.getName() != null ? profile.getName() : (profile.getUniqueId() != null ? profile.getUniqueId().toString() : "~unknown~")) + "]";
+ }
+ }
+ String ownerIdString = conf == null ? null : conf.getString("owner");
+ UUID ownerId = ownerIdString == null ? null : UUID.fromString(ownerIdString);
if (ownerId != null) {
OfflinePlayer owner = Bukkit.getOfflinePlayer(ownerId);
return "[" + (owner.getName() != null ? owner.getName() : owner.getUniqueId().toString()) + "]";