diff --git a/src/main/java/net/coreprotect/database/logger/SkullBreakLogger.java b/src/main/java/net/coreprotect/database/logger/SkullBreakLogger.java index 577f4b0..9589a37 100644 --- a/src/main/java/net/coreprotect/database/logger/SkullBreakLogger.java +++ b/src/main/java/net/coreprotect/database/logger/SkullBreakLogger.java @@ -10,6 +10,7 @@ import org.bukkit.block.Skull; import net.coreprotect.config.ConfigHandler; import net.coreprotect.database.Database; import net.coreprotect.database.statement.SkullStatement; +import net.coreprotect.paper.PaperAdapter; import net.coreprotect.utility.Util; public class SkullBreakLogger { @@ -29,7 +30,7 @@ public class SkullBreakLogger { String skullOwner = ""; int skullKey = 0; if (skull.hasOwner()) { - skullOwner = skull.getOwningPlayer().getUniqueId().toString(); + skullOwner = PaperAdapter.ADAPTER.getSkullOwner(skull); ResultSet resultSet = SkullStatement.insert(preparedStmt2, time, skullOwner); if (Database.hasReturningKeys()) { resultSet.next(); diff --git a/src/main/java/net/coreprotect/database/logger/SkullPlaceLogger.java b/src/main/java/net/coreprotect/database/logger/SkullPlaceLogger.java index e8bdfa5..09b951d 100644 --- a/src/main/java/net/coreprotect/database/logger/SkullPlaceLogger.java +++ b/src/main/java/net/coreprotect/database/logger/SkullPlaceLogger.java @@ -11,6 +11,7 @@ import org.bukkit.block.Skull; import net.coreprotect.config.ConfigHandler; import net.coreprotect.database.Database; import net.coreprotect.database.statement.SkullStatement; +import net.coreprotect.paper.PaperAdapter; public class SkullPlaceLogger { @@ -31,7 +32,7 @@ public class SkullPlaceLogger { Skull skull = (Skull) block; String skullOwner = ""; if (skull.hasOwner()) { - skullOwner = skull.getOwningPlayer().getUniqueId().toString(); + skullOwner = PaperAdapter.ADAPTER.getSkullOwner(skull); ResultSet resultSet = SkullStatement.insert(preparedStmt2, time, skullOwner); if (Database.hasReturningKeys()) { resultSet.next(); diff --git a/src/main/java/net/coreprotect/database/statement/SkullStatement.java b/src/main/java/net/coreprotect/database/statement/SkullStatement.java index 1a1bd8b..7ff453d 100644 --- a/src/main/java/net/coreprotect/database/statement/SkullStatement.java +++ b/src/main/java/net/coreprotect/database/statement/SkullStatement.java @@ -10,6 +10,7 @@ import org.bukkit.block.BlockState; import org.bukkit.block.Skull; import net.coreprotect.database.Database; +import net.coreprotect.paper.PaperAdapter; public class SkullStatement { @@ -46,9 +47,12 @@ public class SkullStatement { while (resultSet.next()) { String owner = resultSet.getString("owner"); - if (owner != null && owner.length() >= 32) { + if (owner != null && owner.length() >= 32 && owner.contains("-")) { skull.setOwningPlayer(Bukkit.getOfflinePlayer(UUID.fromString(owner))); } + else if (owner != null && owner.length() > 1) { + PaperAdapter.ADAPTER.setSkullOwner(skull, owner); + } } resultSet.close(); diff --git a/src/main/java/net/coreprotect/paper/PaperAdapter.java b/src/main/java/net/coreprotect/paper/PaperAdapter.java index 58c66ed..e0933d5 100644 --- a/src/main/java/net/coreprotect/paper/PaperAdapter.java +++ b/src/main/java/net/coreprotect/paper/PaperAdapter.java @@ -3,6 +3,7 @@ package net.coreprotect.paper; import org.bukkit.Location; import org.bukkit.Server; import org.bukkit.block.Sign; +import org.bukkit.block.Skull; import org.bukkit.entity.Entity; import org.bukkit.inventory.Inventory; import org.bukkit.inventory.InventoryHolder; @@ -73,4 +74,14 @@ public class PaperAdapter implements PaperInterface { entity.teleport(location); } + @Override + public String getSkullOwner(Skull skull) { + return skull.getOwningPlayer().getUniqueId().toString(); + } + + @Override + public void setSkullOwner(Skull skull, String owner) { + return; + } + } diff --git a/src/main/java/net/coreprotect/paper/PaperInterface.java b/src/main/java/net/coreprotect/paper/PaperInterface.java index 73bdd6a..f4ad0b5 100644 --- a/src/main/java/net/coreprotect/paper/PaperInterface.java +++ b/src/main/java/net/coreprotect/paper/PaperInterface.java @@ -3,6 +3,7 @@ package net.coreprotect.paper; import org.bukkit.Location; import org.bukkit.Server; import org.bukkit.block.Sign; +import org.bukkit.block.Skull; import org.bukkit.entity.Entity; import org.bukkit.inventory.Inventory; import org.bukkit.inventory.InventoryHolder; @@ -17,4 +18,8 @@ public interface PaperInterface { public void teleportAsync(Entity entity, Location location); + public String getSkullOwner(Skull skull); + + public void setSkullOwner(Skull skull, String owner); + } diff --git a/src/main/java/net/coreprotect/paper/Paper_v1_20.java b/src/main/java/net/coreprotect/paper/Paper_v1_20.java index c7e22dc..db2c829 100644 --- a/src/main/java/net/coreprotect/paper/Paper_v1_20.java +++ b/src/main/java/net/coreprotect/paper/Paper_v1_20.java @@ -1,6 +1,8 @@ package net.coreprotect.paper; +import org.bukkit.Bukkit; import org.bukkit.block.Sign; +import org.bukkit.block.Skull; import org.bukkit.block.sign.Side; import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer; @@ -18,4 +20,14 @@ public class Paper_v1_20 extends Paper_v1_17 implements PaperInterface { } } + @Override + public String getSkullOwner(Skull skull) { + return skull.getPlayerProfile().getName(); + } + + @Override + public void setSkullOwner(Skull skull, String owner) { + skull.setPlayerProfile(Bukkit.createProfile(owner)); + } + }