diff --git a/src/main/java/net/coreprotect/consumer/process/SkullUpdateProcess.java b/src/main/java/net/coreprotect/consumer/process/SkullUpdateProcess.java index d9a5277e..75073bf4 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 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 9589a37b..51f7668e 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 static void log(PreparedStatement preparedStmt, PreparedStatement prepare 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 09b951d0..2e538625 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 static void log(PreparedStatement preparedStmt, PreparedStatement prepare 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 7ff453d6..bcf45bd6 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 @@ private 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 e510aea2..8a8b77dd 100644 --- a/src/main/java/net/coreprotect/paper/PaperAdapter.java +++ b/src/main/java/net/coreprotect/paper/PaperAdapter.java @@ -86,4 +86,14 @@ public void setSkullOwner(Skull skull, String owner) { 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 f4ad0b54..0549ad83 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 3f077ac8..6785c33a 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 void setSkullOwner(Skull skull, String owner) { 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 00000000..209570ae --- /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; + } + +}