Added logging and rollback support for double sided signs

This commit is contained in:
Intelli 2023-07-12 15:17:14 -06:00
parent 7e97e12969
commit 4e43a42662
25 changed files with 658 additions and 107 deletions

View file

@ -215,7 +215,7 @@ public class Database extends Queue {
public static PreparedStatement prepareStatement(Connection connection, int type, boolean keys) {
PreparedStatement preparedStatement = null;
try {
String signInsert = "INSERT INTO " + ConfigHandler.prefix + "sign (time, user, wid, x, y, z, action, color, data, line_1, line_2, line_3, line_4) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
String signInsert = "INSERT INTO " + ConfigHandler.prefix + "sign (time, user, wid, x, y, z, action, color, color_secondary, data, waxed, face, line_1, line_2, line_3, line_4, line_5, line_6, line_7, line_8) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
String blockInsert = "INSERT INTO " + ConfigHandler.prefix + "block (time, user, wid, x, y, z, type, data, meta, blockdata, action, rolled_back) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
String skullInsert = "INSERT INTO " + ConfigHandler.prefix + "skull (time, owner) VALUES (?, ?)";
String containerInsert = "INSERT INTO " + ConfigHandler.prefix + "container (time, user, wid, x, y, z, type, data, amount, metadata, action, rolled_back) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
@ -348,7 +348,7 @@ public class Database extends Queue {
index = ", INDEX(time), INDEX(user,time), INDEX(wid,x,z,time)";
statement.executeUpdate("CREATE TABLE IF NOT EXISTS " + prefix + "command(rowid int NOT NULL AUTO_INCREMENT,PRIMARY KEY(rowid),time int, user int, wid int, x int, y int (3), z int, message varchar(16000)" + index + ") ENGINE=InnoDB DEFAULT CHARACTER SET utf8mb4");
index = ", INDEX(wid,x,z,time), INDEX(user,time), INDEX(type,time)";
statement.executeUpdate("CREATE TABLE IF NOT EXISTS " + prefix + "container(rowid int NOT NULL AUTO_INCREMENT,PRIMARY KEY(rowid), time int, user int, wid int, x int, y int, z int, type int, data int, amount int, metadata blob, action tinyint, rolled_back tinyint" + index + ") ENGINE=InnoDB DEFAULT CHARACTER SET utf8mb4");
statement.executeUpdate("CREATE TABLE IF NOT EXISTS " + prefix + "container(rowid int NOT NULL AUTO_INCREMENT,PRIMARY KEY(rowid), time int, user int, wid int, x int, y int, z int, type int, data int, amount int, slot tinyint, metadata blob, action tinyint, rolled_back tinyint" + index + ") ENGINE=InnoDB DEFAULT CHARACTER SET utf8mb4");
index = ", INDEX(wid,x,z,time), INDEX(user,time), INDEX(type,time)";
statement.executeUpdate("CREATE TABLE IF NOT EXISTS " + prefix + "item(rowid int NOT NULL AUTO_INCREMENT,PRIMARY KEY(rowid), time int, user int, wid int, x int, y int, z int, type int, data blob, amount int, action tinyint, rolled_back tinyint" + index + ") ENGINE=InnoDB DEFAULT CHARACTER SET utf8mb4");
statement.executeUpdate("CREATE TABLE IF NOT EXISTS " + prefix + "database_lock(rowid int NOT NULL AUTO_INCREMENT,PRIMARY KEY(rowid),status tinyint,time int) ENGINE=InnoDB DEFAULT CHARACTER SET utf8mb4");
@ -362,7 +362,7 @@ public class Database extends Queue {
index = ", INDEX(wid,x,z,time), INDEX(action,time), INDEX(user,time), INDEX(time)";
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, data tinyint, line_1 varchar(100), line_2 varchar(100), line_3 varchar(100), line_4 varchar(100)" + index + ") ENGINE=InnoDB DEFAULT CHARACTER SET utf8mb4");
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");
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");
@ -426,7 +426,7 @@ public class Database extends Queue {
statement.executeUpdate("CREATE TABLE IF NOT EXISTS " + prefix + "command (time INTEGER, user INTEGER, wid INTEGER, x INTEGER, y INTEGER, z INTEGER, message TEXT);");
}
if (!tableData.contains(prefix + "container")) {
statement.executeUpdate("CREATE TABLE IF NOT EXISTS " + prefix + "container (time INTEGER, user INTEGER, wid INTEGER, x INTEGER, y INTEGER, z INTEGER, type INTEGER, data INTEGER, amount INTEGER, metadata BLOB, action INTEGER, rolled_back INTEGER);");
statement.executeUpdate("CREATE TABLE IF NOT EXISTS " + prefix + "container (time INTEGER, user INTEGER, wid INTEGER, x INTEGER, y INTEGER, z INTEGER, type INTEGER, data INTEGER, amount INTEGER, slot INTEGER, metadata BLOB, action INTEGER, rolled_back INTEGER);");
}
if (!tableData.contains(prefix + "item")) {
statement.executeUpdate("CREATE TABLE IF NOT EXISTS " + prefix + "item (time INTEGER, user INTEGER, wid INTEGER, x INTEGER, y INTEGER, z INTEGER, type INTEGER, data BLOB, amount INTEGER, action INTEGER, rolled_back INTEGER);");
@ -450,7 +450,7 @@ public class Database extends Queue {
statement.executeUpdate("CREATE TABLE IF NOT EXISTS " + prefix + "session (time INTEGER, user INTEGER, wid INTEGER, x INTEGER, y INTEGER, z INTEGER, action INTEGER);");
}
if (!tableData.contains(prefix + "sign")) {
statement.executeUpdate("CREATE TABLE IF NOT EXISTS " + prefix + "sign (time INTEGER, user INTEGER, wid INTEGER, x INTEGER, y INTEGER, z INTEGER, action INTEGER, color INTEGER, data INTEGER, line_1 TEXT, line_2 TEXT, line_3 TEXT, line_4 TEXT);");
statement.executeUpdate("CREATE TABLE IF NOT EXISTS " + prefix + "sign (time INTEGER, user INTEGER, wid INTEGER, x INTEGER, y INTEGER, z INTEGER, action INTEGER, color INTEGER, color_secondary INTEGER, data INTEGER, waxed INTEGER, face INTEGER, line_1 TEXT, line_2 TEXT, line_3 TEXT, line_4 TEXT, line_5 TEXT, line_6 TEXT, line_7 TEXT, line_8 TEXT);");
}
if (!tableData.contains(prefix + "skull")) {
statement.executeUpdate("CREATE TABLE IF NOT EXISTS " + prefix + "skull (id INTEGER PRIMARY KEY ASC, time INTEGER, owner TEXT);");

View file

@ -191,36 +191,65 @@ public class Lookup extends Queue {
int resultX = results.getInt("x");
int resultY = results.getInt("y");
int resultZ = results.getInt("z");
boolean isFront = results.getInt("face") == 0;
String line1 = results.getString("line_1");
String line2 = results.getString("line_2");
String line3 = results.getString("line_3");
String line4 = results.getString("line_4");
String line5 = results.getString("line_5");
String line6 = results.getString("line_6");
String line7 = results.getString("line_7");
String line8 = results.getString("line_8");
StringBuilder message = new StringBuilder();
if (line1 != null && line1.length() > 0) {
if (isFront && line1 != null && line1.length() > 0) {
message.append(line1);
if (!line1.endsWith(" ")) {
message.append(" ");
}
}
if (line2 != null && line2.length() > 0) {
if (isFront && line2 != null && line2.length() > 0) {
message.append(line2);
if (!line2.endsWith(" ")) {
message.append(" ");
}
}
if (line3 != null && line3.length() > 0) {
if (isFront && line3 != null && line3.length() > 0) {
message.append(line3);
if (!line3.endsWith(" ")) {
message.append(" ");
}
}
if (line4 != null && line4.length() > 0) {
if (isFront && line4 != null && line4.length() > 0) {
message.append(line4);
if (!line4.endsWith(" ")) {
message.append(" ");
}
}
if (!isFront && line5 != null && line5.length() > 0) {
message.append(line5);
if (!line5.endsWith(" ")) {
message.append(" ");
}
}
if (!isFront && line6 != null && line6.length() > 0) {
message.append(line6);
if (!line6.endsWith(" ")) {
message.append(" ");
}
}
if (!isFront && line7 != null && line7.length() > 0) {
message.append(line7);
if (!line7.endsWith(" ")) {
message.append(" ");
}
}
if (!isFront && line8 != null && line8.length() > 0) {
message.append(line8);
if (!line8.endsWith(" ")) {
message.append(" ");
}
}
Object[] dataArray = new Object[] { resultId, resultTime, resultUserId, resultWorldId, resultX, resultY, resultZ, message.toString() };
list.add(dataArray);
@ -596,7 +625,7 @@ public class Lookup extends Queue {
}
if (actionList.contains(10)) {
queryBlock = queryBlock + " action = '1' AND (LENGTH(line_1) > 0 OR LENGTH(line_2) > 0 OR LENGTH(line_3) > 0 OR LENGTH(line_4) > 0) AND";
queryBlock = queryBlock + " action = '1' AND (LENGTH(line_1) > 0 OR LENGTH(line_2) > 0 OR LENGTH(line_3) > 0 OR LENGTH(line_4) > 0 OR LENGTH(line_5) > 0 OR LENGTH(line_6) > 0 OR LENGTH(line_7) > 0 OR LENGTH(line_8) > 0) AND";
}
if (queryBlock.length() > 0) {
@ -649,7 +678,7 @@ public class Lookup extends Queue {
}
else if (actionList.contains(10)) {
queryTable = "sign";
rows = "rowid as id,time,user,wid,x,y,z,line_1,line_2,line_3,line_4";
rows = "rowid as id,time,user,wid,x,y,z,face,line_1,line_2,line_3,line_4,line_5,line_6,line_7,line_8";
}
else if (actionList.contains(11)) {
queryTable = "item";

View file

@ -18,7 +18,7 @@ public class SignTextLogger {
throw new IllegalStateException("Database class");
}
public static void log(PreparedStatement preparedStmt, int batchCount, String user, Location location, int action, int color, int data, String line1, String line2, String line3, String line4, int timeOffset) {
public static void log(PreparedStatement preparedStmt, int batchCount, String user, Location location, int action, int color, int colorSecondary, int data, boolean isWaxed, boolean isFront, String line1, String line2, String line3, String line4, String line5, String line6, String line7, String line8, int timeOffset) {
try {
if (ConfigHandler.blacklist.get(user.toLowerCase(Locale.ROOT)) != null) {
return;
@ -33,7 +33,21 @@ public class SignTextLogger {
int x = location.getBlockX();
int y = location.getBlockY();
int z = location.getBlockZ();
SignStatement.insert(preparedStmt, batchCount, time, userId, wid, x, y, z, action, color, data, line1, line2, line3, line4);
if (line1.isEmpty() && line2.isEmpty() && line3.isEmpty() && line4.isEmpty()) {
line1 = null;
line2 = null;
line3 = null;
line4 = null;
}
if (line5.isEmpty() && line6.isEmpty() && line7.isEmpty() && line8.isEmpty()) {
line5 = null;
line6 = null;
line7 = null;
line8 = null;
}
SignStatement.insert(preparedStmt, batchCount, time, userId, wid, x, y, z, action, color, colorSecondary, data, isWaxed ? 1 : 0, isFront ? 0 : 1, line1, line2, line3, line4, line5, line6, line7, line8);
}
catch (Exception e) {
e.printStackTrace();

View file

@ -55,7 +55,7 @@ public class SignMessageLookup {
int rowMax = page * limit;
int pageStart = rowMax - limit;
String query = "SELECT COUNT(*) as count from " + ConfigHandler.prefix + "sign " + Util.getWidIndex("sign") + "WHERE wid = '" + worldId + "' AND x = '" + x + "' AND z = '" + z + "' AND y = '" + y + "' AND action = '1' AND (LENGTH(line_1) > 0 OR LENGTH(line_2) > 0 OR LENGTH(line_3) > 0 OR LENGTH(line_4) > 0) LIMIT 0, 1";
String query = "SELECT COUNT(*) as count from " + ConfigHandler.prefix + "sign " + Util.getWidIndex("sign") + "WHERE wid = '" + worldId + "' AND x = '" + x + "' AND z = '" + z + "' AND y = '" + y + "' AND action = '1' AND (LENGTH(line_1) > 0 OR LENGTH(line_2) > 0 OR LENGTH(line_3) > 0 OR LENGTH(line_4) > 0 OR LENGTH(line_5) > 0 OR LENGTH(line_6) > 0 OR LENGTH(line_7) > 0 OR LENGTH(line_8) > 0) LIMIT 0, 1";
ResultSet results = statement.executeQuery(query);
while (results.next()) {
@ -65,7 +65,7 @@ public class SignMessageLookup {
int totalPages = (int) Math.ceil(count / (limit + 0.0));
query = "SELECT time,user,line_1,line_2,line_3,line_4 FROM " + ConfigHandler.prefix + "sign " + Util.getWidIndex("sign") + "WHERE wid = '" + worldId + "' AND x = '" + x + "' AND z = '" + z + "' AND y = '" + y + "' AND action = '1' AND (LENGTH(line_1) > 0 OR LENGTH(line_2) > 0 OR LENGTH(line_3) > 0 OR LENGTH(line_4) > 0) ORDER BY rowid DESC LIMIT " + pageStart + ", " + limit + "";
query = "SELECT time,user,face,line_1,line_2,line_3,line_4,line_5,line_6,line_7,line_8 FROM " + ConfigHandler.prefix + "sign " + Util.getWidIndex("sign") + "WHERE wid = '" + worldId + "' AND x = '" + x + "' AND z = '" + z + "' AND y = '" + y + "' AND action = '1' AND (LENGTH(line_1) > 0 OR LENGTH(line_2) > 0 OR LENGTH(line_3) > 0 OR LENGTH(line_4) > 0 OR LENGTH(line_5) > 0 OR LENGTH(line_6) > 0 OR LENGTH(line_7) > 0 OR LENGTH(line_8) > 0) ORDER BY rowid DESC LIMIT " + pageStart + ", " + limit + "";
results = statement.executeQuery(query);
while (results.next()) {
@ -75,32 +75,61 @@ public class SignMessageLookup {
String line2 = results.getString("line_2");
String line3 = results.getString("line_3");
String line4 = results.getString("line_4");
String line5 = results.getString("line_5");
String line6 = results.getString("line_6");
String line7 = results.getString("line_7");
String line8 = results.getString("line_8");
boolean isFront = results.getInt("face") == 0;
StringBuilder message = new StringBuilder();
if (line1 != null && line1.length() > 0) {
if (isFront && line1 != null && line1.length() > 0) {
message.append(line1);
if (!line1.endsWith(" ")) {
message.append(" ");
}
}
if (line2 != null && line2.length() > 0) {
if (isFront && line2 != null && line2.length() > 0) {
message.append(line2);
if (!line2.endsWith(" ")) {
message.append(" ");
}
}
if (line3 != null && line3.length() > 0) {
if (isFront && line3 != null && line3.length() > 0) {
message.append(line3);
if (!line3.endsWith(" ")) {
message.append(" ");
}
}
if (line4 != null && line4.length() > 0) {
if (isFront && line4 != null && line4.length() > 0) {
message.append(line4);
if (!line4.endsWith(" ")) {
message.append(" ");
}
}
if (!isFront && line5 != null && line5.length() > 0) {
message.append(line5);
if (!line5.endsWith(" ")) {
message.append(" ");
}
}
if (!isFront && line6 != null && line6.length() > 0) {
message.append(line6);
if (!line6.endsWith(" ")) {
message.append(" ");
}
}
if (!isFront && line7 != null && line7.length() > 0) {
message.append(line7);
if (!line7.endsWith(" ")) {
message.append(" ");
}
}
if (!isFront && line8 != null && line8.length() > 0) {
message.append(line8);
if (!line8.endsWith(" ")) {
message.append(" ");
}
}
String parsedMessage = message.toString();
if (parsedMessage.contains("§x")) {

View file

@ -4,12 +4,12 @@ import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.Statement;
import org.bukkit.Color;
import org.bukkit.DyeColor;
import org.bukkit.block.BlockState;
import org.bukkit.block.Sign;
import net.coreprotect.bukkit.BukkitAdapter;
import net.coreprotect.spigot.SpigotAdapter;
import net.coreprotect.utility.Util;
public class SignStatement {
@ -17,7 +17,7 @@ public class SignStatement {
throw new IllegalStateException("Database class");
}
public static void insert(PreparedStatement preparedStmt, int batchCount, int time, int id, int wid, int x, int y, int z, int action, int color, int data, String line1, String line2, String line3, String line4) {
public static void insert(PreparedStatement preparedStmt, int batchCount, int time, int id, int wid, int x, int y, int z, int action, int color, int colorSecondary, int data, int waxed, int face, String line1, String line2, String line3, String line4, String line5, String line6, String line7, String line8) {
try {
preparedStmt.setInt(1, time);
preparedStmt.setInt(2, id);
@ -27,11 +27,18 @@ public class SignStatement {
preparedStmt.setInt(6, z);
preparedStmt.setInt(7, action);
preparedStmt.setInt(8, color);
preparedStmt.setInt(9, data);
preparedStmt.setString(10, line1);
preparedStmt.setString(11, line2);
preparedStmt.setString(12, line3);
preparedStmt.setString(13, line4);
preparedStmt.setInt(9, colorSecondary);
preparedStmt.setInt(10, data);
preparedStmt.setInt(11, waxed);
preparedStmt.setInt(12, face);
preparedStmt.setString(13, line1);
preparedStmt.setString(14, line2);
preparedStmt.setString(15, line3);
preparedStmt.setString(16, line4);
preparedStmt.setString(17, line5);
preparedStmt.setString(18, line6);
preparedStmt.setString(19, line7);
preparedStmt.setString(20, line8);
preparedStmt.addBatch();
if (batchCount > 0 && batchCount % 1000 == 0) {
@ -54,24 +61,39 @@ public class SignStatement {
while (resultSet.next()) {
int color = resultSet.getInt("color");
int colorSecondary = resultSet.getInt("color_secondary");
int data = resultSet.getInt("data");
boolean isWaxed = resultSet.getInt("waxed") == 1;
// boolean isFront = resultSet.getInt("face") == 0;
String line1 = resultSet.getString("line_1");
String line2 = resultSet.getString("line_2");
String line3 = resultSet.getString("line_3");
String line4 = resultSet.getString("line_4");
String line5 = resultSet.getString("line_5");
String line6 = resultSet.getString("line_6");
String line7 = resultSet.getString("line_7");
String line8 = resultSet.getString("line_8");
if (color > 0) {
sign.setColor(DyeColor.getByColor(Color.fromRGB(color)));
BukkitAdapter.ADAPTER.setColor(sign, true, color);
}
if (colorSecondary > 0) {
BukkitAdapter.ADAPTER.setColor(sign, false, colorSecondary);
}
if (data > 0) {
BukkitAdapter.ADAPTER.setGlowing(sign, (data == 1 ? true : false));
}
sign.setLine(0, line1);
sign.setLine(1, line2);
sign.setLine(2, line3);
sign.setLine(3, line4);
boolean frontGlowing = Util.isSideGlowing(true, data);
boolean backGlowing = Util.isSideGlowing(false, data);
BukkitAdapter.ADAPTER.setGlowing(sign, true, frontGlowing);
BukkitAdapter.ADAPTER.setGlowing(sign, false, backGlowing);
SpigotAdapter.ADAPTER.setLine(sign, 0, line1);
SpigotAdapter.ADAPTER.setLine(sign, 1, line2);
SpigotAdapter.ADAPTER.setLine(sign, 2, line3);
SpigotAdapter.ADAPTER.setLine(sign, 3, line4);
SpigotAdapter.ADAPTER.setLine(sign, 4, line5);
SpigotAdapter.ADAPTER.setLine(sign, 5, line6);
SpigotAdapter.ADAPTER.setLine(sign, 6, line7);
SpigotAdapter.ADAPTER.setLine(sign, 7, line8);
BukkitAdapter.ADAPTER.setWaxed(sign, isWaxed);
}
resultSet.close();