Fixed NullPointerException when attempting to roll back skulls with texture data

This commit is contained in:
Intelli 2024-08-15 20:48:21 -06:00
parent c6f8be9043
commit cae29f257d
3 changed files with 27 additions and 16 deletions

View File

@ -3,9 +3,7 @@ package net.coreprotect.database.statement;
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 class SkullStatement {
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);
}

View File

@ -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 class PaperAdapter implements PaperInterface {
@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

View File

@ -2,11 +2,15 @@ package net.coreprotect.paper;
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 class Paper_v1_20 extends Paper_v1_17 implements PaperInterface {
@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 @@ public class Paper_v1_20 extends Paper_v1_17 implements PaperInterface {
@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 class Paper_v1_20 extends Paper_v1_17 implements PaperInterface {
@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();