Skip to content

Commit

Permalink
Fixed NullPointerException when attempting to roll back skulls with t…
Browse files Browse the repository at this point in the history
…exture data
  • Loading branch information
Intelli committed Aug 16, 2024
1 parent c6f8be9 commit cae29f2
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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);
}

Expand Down
7 changes: 6 additions & 1 deletion src/main/java/net/coreprotect/paper/PaperAdapter.java
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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
Expand Down
29 changes: 20 additions & 9 deletions src/main/java/net/coreprotect/paper/Paper_v1_20.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -27,21 +31,24 @@ 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;
}

@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
Expand All @@ -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();
Expand Down

0 comments on commit cae29f2

Please sign in to comment.