Skip to content

Commit

Permalink
Fixed MysqlDataTruncation error when logging custom skull data
Browse files Browse the repository at this point in the history
  • Loading branch information
Intelli committed May 11, 2024
1 parent 377a6f5 commit d18a023
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/main/java/net/coreprotect/database/Database.java
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,7 @@ public static void createDatabaseTables(String prefix, boolean purge) {
statement.executeUpdate("CREATE TABLE IF NOT EXISTS " + prefix + "session(rowid int NOT NULL AUTO_INCREMENT,PRIMARY KEY(rowid),time int, user int, wid int, x int, y int (3), z int, action tinyint" + index + ") ENGINE=InnoDB DEFAULT CHARACTER SET utf8mb4");
index = ", INDEX(wid,x,z,time), INDEX(user,time), INDEX(time)";
statement.executeUpdate("CREATE TABLE IF NOT EXISTS " + prefix + "sign(rowid int NOT NULL AUTO_INCREMENT,PRIMARY KEY(rowid),time int, user int, wid int, x int, y int, z int, action tinyint, color int, color_secondary int, data tinyint, waxed tinyint, face tinyint, line_1 varchar(100), line_2 varchar(100), line_3 varchar(100), line_4 varchar(100), line_5 varchar(100), line_6 varchar(100), line_7 varchar(100), line_8 varchar(100)" + index + ") ENGINE=InnoDB DEFAULT CHARACTER SET utf8mb4");
statement.executeUpdate("CREATE TABLE IF NOT EXISTS " + prefix + "skull(rowid int NOT NULL AUTO_INCREMENT,PRIMARY KEY(rowid), time int, owner varchar(64)) ENGINE=InnoDB DEFAULT CHARACTER SET utf8mb4");
statement.executeUpdate("CREATE TABLE IF NOT EXISTS " + prefix + "skull(rowid int NOT NULL AUTO_INCREMENT,PRIMARY KEY(rowid), time int, owner varchar(255)) ENGINE=InnoDB DEFAULT CHARACTER SET utf8mb4");
index = ", INDEX(user), INDEX(uuid)";
statement.executeUpdate("CREATE TABLE IF NOT EXISTS " + prefix + "user(rowid int NOT NULL AUTO_INCREMENT,PRIMARY KEY(rowid),time int,user varchar(100),uuid varchar(64)" + index + ") ENGINE=InnoDB DEFAULT CHARACTER SET utf8mb4");
index = ", INDEX(uuid,user)";
Expand Down
10 changes: 9 additions & 1 deletion src/main/java/net/coreprotect/paper/Paper_v1_20.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,15 @@ public String getLine(Sign sign, int line) {

@Override
public String getSkullOwner(Skull skull) {
return skull.getPlayerProfile().getName();
String owner = skull.getPlayerProfile().getName();
if (owner.length() > 255 && skull.getPlayerProfile().getId() != null) {
return skull.getPlayerProfile().getId().toString();
}
else if (owner.length() > 255) {
return owner.substring(0, 255);
}

return owner;
}

@Override
Expand Down
31 changes: 31 additions & 0 deletions src/main/java/net/coreprotect/patch/script/__2_23_0.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
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.utility.Chat;

public class __2_23_0 {

protected static boolean patch(Statement statement) {
try {
if (Config.getGlobal().MYSQL) {
try {
statement.executeUpdate("ALTER TABLE " + ConfigHandler.prefix + "skull MODIFY owner VARCHAR(255);");
}
catch (Exception e) {
Chat.console(Phrase.build(Phrase.PATCH_SKIP_UPDATE, ConfigHandler.prefix + "skull", Selector.FIRST, Selector.FIRST));
}
}
}
catch (Exception e) {
e.printStackTrace();
}

return true;
}

}

0 comments on commit d18a023

Please sign in to comment.