Prepped logging for skull skin textures on Paper servers

This commit is contained in:
Intelli 2024-07-09 18:51:46 -06:00
parent dbd8723752
commit 4bf4f4eb92
8 changed files with 89 additions and 4 deletions

View File

@ -4,9 +4,9 @@ import java.sql.Statement;
import org.bukkit.block.BlockState;
import net.coreprotect.config.ConfigHandler;
import net.coreprotect.database.statement.SkullStatement;
import net.coreprotect.utility.Util;
import net.coreprotect.config.ConfigHandler;
class SkullUpdateProcess {

View File

@ -28,10 +28,12 @@ public class SkullBreakLogger {
int type = Util.getBlockId(block.getType().name(), true);
Skull skull = (Skull) block;
String skullOwner = "";
String skullSkin = null;
int skullKey = 0;
if (skull.hasOwner()) {
skullOwner = PaperAdapter.ADAPTER.getSkullOwner(skull);
ResultSet resultSet = SkullStatement.insert(preparedStmt2, time, skullOwner);
skullSkin = PaperAdapter.ADAPTER.getSkullSkin(skull);
ResultSet resultSet = SkullStatement.insert(preparedStmt2, time, skullOwner, skullSkin);
if (Database.hasReturningKeys()) {
resultSet.next();
skullKey = resultSet.getInt(1);

View File

@ -31,9 +31,11 @@ public class SkullPlaceLogger {
if (block instanceof Skull) {
Skull skull = (Skull) block;
String skullOwner = "";
String skullSkin = null;
if (skull.hasOwner()) {
skullOwner = PaperAdapter.ADAPTER.getSkullOwner(skull);
ResultSet resultSet = SkullStatement.insert(preparedStmt2, time, skullOwner);
skullSkin = PaperAdapter.ADAPTER.getSkullSkin(skull);
ResultSet resultSet = SkullStatement.insert(preparedStmt2, time, skullOwner, skullSkin);
if (Database.hasReturningKeys()) {
resultSet.next();
skullKey = resultSet.getInt(1);

View File

@ -18,7 +18,7 @@ public class SkullStatement {
throw new IllegalStateException("Database class");
}
public static ResultSet insert(PreparedStatement preparedStmt, int time, String owner) {
public static ResultSet insert(PreparedStatement preparedStmt, int time, String owner, String skin) {
try {
preparedStmt.setInt(1, time);
preparedStmt.setString(2, owner);

View File

@ -86,4 +86,14 @@ public class PaperAdapter implements PaperInterface {
return;
}
@Override
public String getSkullSkin(Skull skull) {
return null;
}
@Override
public void setSkullSkin(Skull skull, String skin) {
return;
}
}

View File

@ -20,6 +20,10 @@ public interface PaperInterface {
public String getSkullOwner(Skull skull);
public String getSkullSkin(Skull skull);
public void setSkullOwner(Skull skull, String owner);
public void setSkullSkin(Skull skull, String skin);
}

View File

@ -1,5 +1,8 @@
package net.coreprotect.paper;
import java.net.URI;
import java.net.URL;
import org.bukkit.Bukkit;
import org.bukkit.block.Sign;
import org.bukkit.block.Skull;
@ -41,4 +44,24 @@ public class Paper_v1_20 extends Paper_v1_17 implements PaperInterface {
skull.setPlayerProfile(Bukkit.createProfile(owner));
}
@Override
public String getSkullSkin(Skull skull) {
URL skin = skull.getPlayerProfile().getTextures().getSkin();
if (skin == null) {
return null;
}
return skin.toString();
}
@Override
public void setSkullSkin(Skull skull, String skin) {
try {
skull.getPlayerProfile().getTextures().setSkin(URI.create(skin).toURL());
}
catch (Exception e) {
e.printStackTrace();
}
}
}

View File

@ -0,0 +1,44 @@
package net.coreprotect.patch.script;
import java.sql.Statement;
import net.coreprotect.config.Config;
import net.coreprotect.config.ConfigHandler;
import net.coreprotect.language.Phrase;
import net.coreprotect.language.Selector;
import net.coreprotect.patch.Patch;
import net.coreprotect.utility.Chat;
public class __2_23_1 {
protected static boolean patch(Statement statement) {
try {
if (Config.getGlobal().MYSQL) {
try {
statement.executeUpdate("ALTER TABLE " + ConfigHandler.prefix + "skull ADD COLUMN skin VARCHAR(255);");
}
catch (Exception e) {
Chat.console(Phrase.build(Phrase.PATCH_SKIP_UPDATE, ConfigHandler.prefix + "skull", Selector.FIRST, Selector.FIRST));
}
}
else {
try {
statement.executeUpdate("ALTER TABLE " + ConfigHandler.prefix + "skull ADD COLUMN skin TEXT;");
}
catch (Exception e) {
Chat.console(Phrase.build(Phrase.PATCH_SKIP_UPDATE, ConfigHandler.prefix + "skull", Selector.FIRST, Selector.FIRST));
}
if (!Patch.continuePatch()) {
return false;
}
}
}
catch (Exception e) {
e.printStackTrace();
}
return true;
}
}