From 4bf4f4eb92c55faac70b9d7f6f7dfa693b531695 Mon Sep 17 00:00:00 2001 From: Intelli Date: Tue, 9 Jul 2024 18:51:46 -0600 Subject: [PATCH] Prepped logging for skull skin textures on Paper servers --- .../consumer/process/SkullUpdateProcess.java | 2 +- .../database/logger/SkullBreakLogger.java | 4 +- .../database/logger/SkullPlaceLogger.java | 4 +- .../database/statement/SkullStatement.java | 2 +- .../net/coreprotect/paper/PaperAdapter.java | 10 +++++ .../net/coreprotect/paper/PaperInterface.java | 4 ++ .../net/coreprotect/paper/Paper_v1_20.java | 23 ++++++++++ .../coreprotect/patch/script/__2_23_1.java | 44 +++++++++++++++++++ 8 files changed, 89 insertions(+), 4 deletions(-) create mode 100644 src/main/java/net/coreprotect/patch/script/__2_23_1.java diff --git a/src/main/java/net/coreprotect/consumer/process/SkullUpdateProcess.java b/src/main/java/net/coreprotect/consumer/process/SkullUpdateProcess.java index d9a5277..75073bf 100644 --- a/src/main/java/net/coreprotect/consumer/process/SkullUpdateProcess.java +++ b/src/main/java/net/coreprotect/consumer/process/SkullUpdateProcess.java @@ -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 { diff --git a/src/main/java/net/coreprotect/database/logger/SkullBreakLogger.java b/src/main/java/net/coreprotect/database/logger/SkullBreakLogger.java index 9589a37..51f7668 100644 --- a/src/main/java/net/coreprotect/database/logger/SkullBreakLogger.java +++ b/src/main/java/net/coreprotect/database/logger/SkullBreakLogger.java @@ -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); diff --git a/src/main/java/net/coreprotect/database/logger/SkullPlaceLogger.java b/src/main/java/net/coreprotect/database/logger/SkullPlaceLogger.java index 09b951d..2e53862 100644 --- a/src/main/java/net/coreprotect/database/logger/SkullPlaceLogger.java +++ b/src/main/java/net/coreprotect/database/logger/SkullPlaceLogger.java @@ -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); diff --git a/src/main/java/net/coreprotect/database/statement/SkullStatement.java b/src/main/java/net/coreprotect/database/statement/SkullStatement.java index 7ff453d..bcf45bd 100644 --- a/src/main/java/net/coreprotect/database/statement/SkullStatement.java +++ b/src/main/java/net/coreprotect/database/statement/SkullStatement.java @@ -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); diff --git a/src/main/java/net/coreprotect/paper/PaperAdapter.java b/src/main/java/net/coreprotect/paper/PaperAdapter.java index e510aea..8a8b77d 100644 --- a/src/main/java/net/coreprotect/paper/PaperAdapter.java +++ b/src/main/java/net/coreprotect/paper/PaperAdapter.java @@ -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; + } + } diff --git a/src/main/java/net/coreprotect/paper/PaperInterface.java b/src/main/java/net/coreprotect/paper/PaperInterface.java index f4ad0b5..0549ad8 100644 --- a/src/main/java/net/coreprotect/paper/PaperInterface.java +++ b/src/main/java/net/coreprotect/paper/PaperInterface.java @@ -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); + } diff --git a/src/main/java/net/coreprotect/paper/Paper_v1_20.java b/src/main/java/net/coreprotect/paper/Paper_v1_20.java index 3f077ac..6785c33 100644 --- a/src/main/java/net/coreprotect/paper/Paper_v1_20.java +++ b/src/main/java/net/coreprotect/paper/Paper_v1_20.java @@ -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(); + } + } + } diff --git a/src/main/java/net/coreprotect/patch/script/__2_23_1.java b/src/main/java/net/coreprotect/patch/script/__2_23_1.java new file mode 100644 index 0000000..209570a --- /dev/null +++ b/src/main/java/net/coreprotect/patch/script/__2_23_1.java @@ -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; + } + +}