Skip to content

Commit

Permalink
Fixed NullPointerException when rolling back player heads (fixes #473)
Browse files Browse the repository at this point in the history
  • Loading branch information
Intelli committed Jan 5, 2024
1 parent 1c57ba5 commit ba6a55f
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
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 {
Expand All @@ -29,7 +30,7 @@ public static void log(PreparedStatement preparedStmt, PreparedStatement prepare
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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import net.coreprotect.config.ConfigHandler;
import net.coreprotect.database.Database;
import net.coreprotect.database.statement.SkullStatement;
import net.coreprotect.paper.PaperAdapter;

public class SkullPlaceLogger {

Expand All @@ -31,7 +32,7 @@ public static void log(PreparedStatement preparedStmt, PreparedStatement prepare
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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import org.bukkit.block.Skull;

import net.coreprotect.database.Database;
import net.coreprotect.paper.PaperAdapter;

public class SkullStatement {

Expand Down Expand Up @@ -46,9 +47,12 @@ public static void getData(Statement statement, BlockState block, String query)

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();
Expand Down
11 changes: 11 additions & 0 deletions src/main/java/net/coreprotect/paper/PaperAdapter.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
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;
Expand Down Expand Up @@ -73,4 +74,14 @@ public void teleportAsync(Entity entity, Location location) {
entity.teleport(location);
}

@Override
public String getSkullOwner(Skull skull) {
return skull.getOwningPlayer().getUniqueId().toString();
}

@Override
public void setSkullOwner(Skull skull, String owner) {
return;
}

}
5 changes: 5 additions & 0 deletions src/main/java/net/coreprotect/paper/PaperInterface.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
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;
Expand All @@ -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);

}
12 changes: 12 additions & 0 deletions src/main/java/net/coreprotect/paper/Paper_v1_20.java
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -18,4 +20,14 @@ public String getLine(Sign sign, int line) {
}
}

@Override
public String getSkullOwner(Skull skull) {
return skull.getPlayerProfile().getName();
}

@Override
public void setSkullOwner(Skull skull, String owner) {
skull.setPlayerProfile(Bukkit.createProfile(owner));
}

}

0 comments on commit ba6a55f

Please sign in to comment.