mirror of
https://github.com/PlayPro/CoreProtect.git
synced 2024-11-21 01:13:45 +08: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.config.ConfigHandler;
|
||||||
import net.coreprotect.database.Database;
|
import net.coreprotect.database.Database;
|
||||||
import net.coreprotect.database.statement.SkullStatement;
|
import net.coreprotect.database.statement.SkullStatement;
|
||||||
|
import net.coreprotect.paper.PaperAdapter;
|
||||||
import net.coreprotect.utility.Util;
|
import net.coreprotect.utility.Util;
|
||||||
|
|
||||||
public class SkullBreakLogger {
|
public class SkullBreakLogger {
|
||||||
@ -29,7 +30,7 @@ public class SkullBreakLogger {
|
|||||||
String skullOwner = "";
|
String skullOwner = "";
|
||||||
int skullKey = 0;
|
int skullKey = 0;
|
||||||
if (skull.hasOwner()) {
|
if (skull.hasOwner()) {
|
||||||
skullOwner = skull.getOwningPlayer().getUniqueId().toString();
|
skullOwner = PaperAdapter.ADAPTER.getSkullOwner(skull);
|
||||||
ResultSet resultSet = SkullStatement.insert(preparedStmt2, time, skullOwner);
|
ResultSet resultSet = SkullStatement.insert(preparedStmt2, time, skullOwner);
|
||||||
if (Database.hasReturningKeys()) {
|
if (Database.hasReturningKeys()) {
|
||||||
resultSet.next();
|
resultSet.next();
|
||||||
|
@ -11,6 +11,7 @@ import org.bukkit.block.Skull;
|
|||||||
import net.coreprotect.config.ConfigHandler;
|
import net.coreprotect.config.ConfigHandler;
|
||||||
import net.coreprotect.database.Database;
|
import net.coreprotect.database.Database;
|
||||||
import net.coreprotect.database.statement.SkullStatement;
|
import net.coreprotect.database.statement.SkullStatement;
|
||||||
|
import net.coreprotect.paper.PaperAdapter;
|
||||||
|
|
||||||
public class SkullPlaceLogger {
|
public class SkullPlaceLogger {
|
||||||
|
|
||||||
@ -31,7 +32,7 @@ public class SkullPlaceLogger {
|
|||||||
Skull skull = (Skull) block;
|
Skull skull = (Skull) block;
|
||||||
String skullOwner = "";
|
String skullOwner = "";
|
||||||
if (skull.hasOwner()) {
|
if (skull.hasOwner()) {
|
||||||
skullOwner = skull.getOwningPlayer().getUniqueId().toString();
|
skullOwner = PaperAdapter.ADAPTER.getSkullOwner(skull);
|
||||||
ResultSet resultSet = SkullStatement.insert(preparedStmt2, time, skullOwner);
|
ResultSet resultSet = SkullStatement.insert(preparedStmt2, time, skullOwner);
|
||||||
if (Database.hasReturningKeys()) {
|
if (Database.hasReturningKeys()) {
|
||||||
resultSet.next();
|
resultSet.next();
|
||||||
|
@ -10,6 +10,7 @@ import org.bukkit.block.BlockState;
|
|||||||
import org.bukkit.block.Skull;
|
import org.bukkit.block.Skull;
|
||||||
|
|
||||||
import net.coreprotect.database.Database;
|
import net.coreprotect.database.Database;
|
||||||
|
import net.coreprotect.paper.PaperAdapter;
|
||||||
|
|
||||||
public class SkullStatement {
|
public class SkullStatement {
|
||||||
|
|
||||||
@ -46,9 +47,12 @@ public class SkullStatement {
|
|||||||
|
|
||||||
while (resultSet.next()) {
|
while (resultSet.next()) {
|
||||||
String owner = resultSet.getString("owner");
|
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)));
|
skull.setOwningPlayer(Bukkit.getOfflinePlayer(UUID.fromString(owner)));
|
||||||
}
|
}
|
||||||
|
else if (owner != null && owner.length() > 1) {
|
||||||
|
PaperAdapter.ADAPTER.setSkullOwner(skull, owner);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
resultSet.close();
|
resultSet.close();
|
||||||
|
@ -3,6 +3,7 @@ package net.coreprotect.paper;
|
|||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
import org.bukkit.Server;
|
import org.bukkit.Server;
|
||||||
import org.bukkit.block.Sign;
|
import org.bukkit.block.Sign;
|
||||||
|
import org.bukkit.block.Skull;
|
||||||
import org.bukkit.entity.Entity;
|
import org.bukkit.entity.Entity;
|
||||||
import org.bukkit.inventory.Inventory;
|
import org.bukkit.inventory.Inventory;
|
||||||
import org.bukkit.inventory.InventoryHolder;
|
import org.bukkit.inventory.InventoryHolder;
|
||||||
@ -73,4 +74,14 @@ public class PaperAdapter implements PaperInterface {
|
|||||||
entity.teleport(location);
|
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.Location;
|
||||||
import org.bukkit.Server;
|
import org.bukkit.Server;
|
||||||
import org.bukkit.block.Sign;
|
import org.bukkit.block.Sign;
|
||||||
|
import org.bukkit.block.Skull;
|
||||||
import org.bukkit.entity.Entity;
|
import org.bukkit.entity.Entity;
|
||||||
import org.bukkit.inventory.Inventory;
|
import org.bukkit.inventory.Inventory;
|
||||||
import org.bukkit.inventory.InventoryHolder;
|
import org.bukkit.inventory.InventoryHolder;
|
||||||
@ -17,4 +18,8 @@ public interface PaperInterface {
|
|||||||
|
|
||||||
public void teleportAsync(Entity entity, Location location);
|
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;
|
package net.coreprotect.paper;
|
||||||
|
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.block.Sign;
|
import org.bukkit.block.Sign;
|
||||||
|
import org.bukkit.block.Skull;
|
||||||
import org.bukkit.block.sign.Side;
|
import org.bukkit.block.sign.Side;
|
||||||
|
|
||||||
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
|
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