mirror of
https://github.com/PlayPro/CoreProtect.git
synced 2024-12-30 18:08:24 +01:00
Fixed NullPointerException when rolling back player heads (fixes #473)
This commit is contained in:
parent
1c57ba52aa
commit
ba6a55fff6
@ -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();
|
||||
|
@ -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();
|
||||
|
@ -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();
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -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);
|
||||
|
||||
}
|
||||
|
@ -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));
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user