From cae29f257d407fc2ec87f2fe24c98ca4a9e0efe9 Mon Sep 17 00:00:00 2001 From: Intelli Date: Thu, 15 Aug 2024 20:48:21 -0600 Subject: [PATCH] Fixed NullPointerException when attempting to roll back skulls with texture data --- .../database/statement/SkullStatement.java | 7 +---- .../net/coreprotect/paper/PaperAdapter.java | 7 ++++- .../net/coreprotect/paper/Paper_v1_20.java | 29 +++++++++++++------ 3 files changed, 27 insertions(+), 16 deletions(-) diff --git a/src/main/java/net/coreprotect/database/statement/SkullStatement.java b/src/main/java/net/coreprotect/database/statement/SkullStatement.java index 44beae8a..6dd005aa 100644 --- a/src/main/java/net/coreprotect/database/statement/SkullStatement.java +++ b/src/main/java/net/coreprotect/database/statement/SkullStatement.java @@ -3,9 +3,7 @@ import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.Statement; -import java.util.UUID; -import org.bukkit.Bukkit; import org.bukkit.block.BlockState; import org.bukkit.block.Skull; @@ -48,10 +46,7 @@ public static void getData(Statement statement, BlockState block, String query) while (resultSet.next()) { String owner = resultSet.getString("owner"); - if (owner != null && owner.length() >= 32 && owner.contains("-")) { - skull.setOwningPlayer(Bukkit.getOfflinePlayer(UUID.fromString(owner))); - } - else if (owner != null && owner.length() > 1) { + if (owner != null && owner.length() > 1) { PaperAdapter.ADAPTER.setSkullOwner(skull, owner); } diff --git a/src/main/java/net/coreprotect/paper/PaperAdapter.java b/src/main/java/net/coreprotect/paper/PaperAdapter.java index 8a8b77dd..935a8e7f 100644 --- a/src/main/java/net/coreprotect/paper/PaperAdapter.java +++ b/src/main/java/net/coreprotect/paper/PaperAdapter.java @@ -1,5 +1,8 @@ package net.coreprotect.paper; +import java.util.UUID; + +import org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.Server; import org.bukkit.block.Sign; @@ -83,7 +86,9 @@ public String getSkullOwner(Skull skull) { @Override public void setSkullOwner(Skull skull, String owner) { - return; + if (owner != null && owner.length() >= 32 && owner.contains("-")) { + skull.setOwningPlayer(Bukkit.getOfflinePlayer(UUID.fromString(owner))); + } } @Override 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 6785c33a..048c96a9 100644 --- a/src/main/java/net/coreprotect/paper/Paper_v1_20.java +++ b/src/main/java/net/coreprotect/paper/Paper_v1_20.java @@ -2,11 +2,15 @@ import java.net.URI; import java.net.URL; +import java.util.UUID; import org.bukkit.Bukkit; import org.bukkit.block.Sign; import org.bukkit.block.Skull; import org.bukkit.block.sign.Side; +import org.bukkit.profile.PlayerTextures; + +import com.destroystokyo.paper.profile.PlayerProfile; import net.coreprotect.config.Config; import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer; @@ -27,13 +31,11 @@ public String getLine(Sign sign, int line) { @Override public String getSkullOwner(Skull skull) { String owner = skull.getPlayerProfile().getName(); - if (Config.getGlobal().MYSQL) { - if (owner.length() > 255 && skull.getPlayerProfile().getId() != null) { - return skull.getPlayerProfile().getId().toString(); - } - else if (owner.length() > 255) { - return owner.substring(0, 255); - } + if (skull.getPlayerProfile().getId() != null) { + owner = skull.getPlayerProfile().getId().toString(); + } + else if (Config.getGlobal().MYSQL && owner.length() > 255) { + return owner.substring(0, 255); } return owner; @@ -41,7 +43,12 @@ else if (owner.length() > 255) { @Override public void setSkullOwner(Skull skull, String owner) { - skull.setPlayerProfile(Bukkit.createProfile(owner)); + if (owner != null && owner.length() >= 32 && owner.contains("-")) { + skull.setPlayerProfile(Bukkit.createProfile(UUID.fromString(owner))); + } + else { + skull.setPlayerProfile(Bukkit.createProfile(owner)); + } } @Override @@ -57,7 +64,11 @@ public String getSkullSkin(Skull skull) { @Override public void setSkullSkin(Skull skull, String skin) { try { - skull.getPlayerProfile().getTextures().setSkin(URI.create(skin).toURL()); + PlayerProfile playerProfile = skull.getPlayerProfile(); + PlayerTextures textures = playerProfile.getTextures(); + textures.setSkin(URI.create(skin).toURL()); + playerProfile.setTextures(textures); + skull.setPlayerProfile(playerProfile); } catch (Exception e) { e.printStackTrace();