Skip to content

Commit

Permalink
Prepped logging for skull skin textures on Paper servers
Browse files Browse the repository at this point in the history
  • Loading branch information
Intelli committed Jul 10, 2024
1 parent dbd8723 commit 4bf4f4e
Show file tree
Hide file tree
Showing 8 changed files with 89 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
10 changes: 10 additions & 0 deletions src/main/java/net/coreprotect/paper/PaperAdapter.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

}
4 changes: 4 additions & 0 deletions src/main/java/net/coreprotect/paper/PaperInterface.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);

}
23 changes: 23 additions & 0 deletions src/main/java/net/coreprotect/paper/Paper_v1_20.java
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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();
}
}

}
44 changes: 44 additions & 0 deletions src/main/java/net/coreprotect/patch/script/__2_23_1.java
Original file line number Diff line number Diff line change
@@ -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;
}

}

0 comments on commit 4bf4f4e

Please sign in to comment.