Skip to content

Commit

Permalink
Added logging and rollback support for double sided signs
Browse files Browse the repository at this point in the history
  • Loading branch information
Intelli committed Jul 12, 2023
1 parent 7e97e12 commit 4e43a42
Show file tree
Hide file tree
Showing 25 changed files with 660 additions and 109 deletions.
36 changes: 33 additions & 3 deletions src/main/java/net/coreprotect/bukkit/BukkitAdapter.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import java.util.List;
import java.util.Map;

import org.bukkit.Color;
import org.bukkit.DyeColor;
import org.bukkit.Material;
import org.bukkit.World;
import org.bukkit.block.Block;
Expand Down Expand Up @@ -131,13 +133,13 @@ public Class<?> getFrameClass(Material material) {
}

@Override
public boolean isGlowing(Sign sign) {
public boolean isGlowing(Sign sign, boolean isFront) {
return false;
}

@Override
public void setGlowing(Sign sign, boolean set) {
return;
public boolean isWaxed(Sign sign) {
return false;
}

@Override
Expand All @@ -150,4 +152,32 @@ public ItemStack adjustIngredient(MerchantRecipe recipe, ItemStack itemStack) {
return null;
}

@Override
public void setGlowing(Sign sign, boolean isFront, boolean isGlowing) {
return;
}

@Override
public void setColor(Sign sign, boolean isFront, int color) {
if (!isFront) {
return;
}

sign.setColor(DyeColor.getByColor(Color.fromRGB(color)));
}

@Override
public void setWaxed(Sign sign, boolean isWaxed) {
return;
}

@Override
public int getColor(Sign sign, boolean isFront) {
if (isFront) {
return sign.getColor().getColor().asRGB();
}

return 0;
}

}
12 changes: 10 additions & 2 deletions src/main/java/net/coreprotect/bukkit/BukkitInterface.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,22 @@ public interface BukkitInterface {

public boolean isItemFrame(Material material);

public boolean isGlowing(Sign sign);
public boolean isGlowing(Sign sign, boolean isFront);

public boolean isInvisible(Material material);

public boolean isWaxed(Sign sign);

public int getMinHeight(World world);

public int getLegacyBlockId(Material material);

public void setGlowing(Sign sign, boolean b);
public void setGlowing(Sign sign, boolean isFront, boolean isGlowing);

public void setColor(Sign sign, boolean isFront, int color);

public void setWaxed(Sign sign, boolean isWaxed);

public int getColor(Sign sign, boolean isFront);

}
14 changes: 11 additions & 3 deletions src/main/java/net/coreprotect/bukkit/Bukkit_v1_17.java
Original file line number Diff line number Diff line change
Expand Up @@ -218,13 +218,21 @@ public Class<?> getFrameClass(Material material) {
}

@Override
public boolean isGlowing(Sign sign) {
public boolean isGlowing(Sign sign, boolean isFront) {
if (!isFront) {
return false;
}

return sign.isGlowingText();
}

@Override
public void setGlowing(Sign sign, boolean set) {
sign.setGlowingText(set);
public void setGlowing(Sign sign, boolean isFront, boolean isGlowing) {
if (!isFront) {
return;
}

sign.setGlowingText(isGlowing);
}

@Override
Expand Down
54 changes: 54 additions & 0 deletions src/main/java/net/coreprotect/bukkit/Bukkit_v1_20.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@
import java.util.Arrays;
import java.util.HashSet;

import org.bukkit.Color;
import org.bukkit.DyeColor;
import org.bukkit.Material;
import org.bukkit.block.Sign;
import org.bukkit.block.sign.Side;

import net.coreprotect.model.BlockGroup;

Expand All @@ -14,4 +18,54 @@ public Bukkit_v1_20() {
BlockGroup.UPDATE_STATE = new HashSet<>(Arrays.asList(Material.TORCH, Material.WALL_TORCH, Material.REDSTONE_WIRE, Material.RAIL, Material.POWERED_RAIL, Material.DETECTOR_RAIL, Material.FURNACE, Material.BLAST_FURNACE, Material.SMOKER, Material.LEVER, Material.REDSTONE_TORCH, Material.REDSTONE_WALL_TORCH, Material.GLOWSTONE, Material.JACK_O_LANTERN, Material.REPEATER, Material.REDSTONE_LAMP, Material.BEACON, Material.COMPARATOR, Material.DAYLIGHT_DETECTOR, Material.REDSTONE_BLOCK, Material.HOPPER, Material.CHEST, Material.TRAPPED_CHEST, Material.ACTIVATOR_RAIL, Material.SOUL_TORCH, Material.SOUL_WALL_TORCH, Material.SHROOMLIGHT, Material.RESPAWN_ANCHOR, Material.CRYING_OBSIDIAN, Material.TARGET, Material.SMALL_AMETHYST_BUD, Material.MEDIUM_AMETHYST_BUD, Material.LARGE_AMETHYST_BUD, Material.AMETHYST_CLUSTER, Material.CAVE_VINES, Material.CAVE_VINES_PLANT, Material.GLOW_LICHEN, Material.LIGHT, Material.LAVA_CAULDRON, Material.CHISELED_BOOKSHELF));
}

@Override
public void setGlowing(Sign sign, boolean isFront, boolean isGlowing) {
if (isFront) {
sign.getSide(Side.FRONT).setGlowingText(isGlowing);
}
else {
sign.getSide(Side.BACK).setGlowingText(isGlowing);
}
}

@Override
public void setColor(Sign sign, boolean isFront, int color) {
if (isFront) {
sign.getSide(Side.FRONT).setColor(DyeColor.getByColor(Color.fromRGB(color)));
}
else {
sign.getSide(Side.BACK).setColor(DyeColor.getByColor(Color.fromRGB(color)));
}
}

@Override
public void setWaxed(Sign sign, boolean isWaxed) {
sign.setWaxed(isWaxed);
}

@Override
public int getColor(Sign sign, boolean isFront) {
if (isFront) {
return sign.getSide(Side.FRONT).getColor().getColor().asRGB();
}
else {
return sign.getSide(Side.BACK).getColor().getColor().asRGB();
}
}

@Override
public boolean isGlowing(Sign sign, boolean isFront) {
if (isFront) {
return sign.getSide(Side.FRONT).isGlowingText();
}
else {
return sign.getSide(Side.BACK).isGlowingText();
}
}

@Override
public boolean isWaxed(Sign sign) {
return sign.isWaxed();
}

}
4 changes: 2 additions & 2 deletions src/main/java/net/coreprotect/consumer/Queue.java
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,7 @@ protected static void queueRollbackUpdate(String user, Location location, List<O
queueStandardData(consumerId, currentConsumer, new String[] { user, null }, location);
}

protected static void queueSignText(String user, Location location, int action, int color, boolean glowing, String line1, String line2, String line3, String line4, int offset) {
protected static void queueSignText(String user, Location location, int action, int color, int colorSecondary, boolean frontGlowing, boolean backGlowing, boolean isWaxed, boolean isFront, String line1, String line2, String line3, String line4, String line5, String line6, String line7, String line8, int offset) {
/*
if (line1.length() == 0 && line2.length() == 0 && line3.length() == 0 && line4.length() == 0) {
return;
Expand All @@ -361,7 +361,7 @@ protected static void queueSignText(String user, Location location, int action,
int currentConsumer = Consumer.currentConsumer;
int consumerId = Consumer.newConsumerId(currentConsumer);
addConsumer(currentConsumer, new Object[] { consumerId, Process.SIGN_TEXT, null, color, null, action, offset, null });
Consumer.consumerSigns.get(currentConsumer).put(consumerId, new Object[] { (glowing == true ? 1 : 0), line1, line2, line3, line4 });
Consumer.consumerSigns.get(currentConsumer).put(consumerId, new Object[] { colorSecondary, Util.getSignData(frontGlowing, backGlowing), isWaxed, isFront, line1, line2, line3, line4, line5, line6, line7, line8 });
queueStandardData(consumerId, currentConsumer, new String[] { user, null }, location);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ static void process(PreparedStatement preparedStmt, int batchCount, int processI
Map<Integer, Object[]> signs = Consumer.consumerSigns.get(processId);
if (signs.get(id) != null) {
Object[] SIGN_DATA = signs.get(id);
SignTextLogger.log(preparedStmt, batchCount, user, location, action, color, (Integer) SIGN_DATA[0], (String) SIGN_DATA[1], (String) SIGN_DATA[2], (String) SIGN_DATA[3], (String) SIGN_DATA[4], forceData);
SignTextLogger.log(preparedStmt, batchCount, user, location, action, color, (Integer) SIGN_DATA[0], (Integer) SIGN_DATA[1], (Boolean) SIGN_DATA[2], (Boolean) SIGN_DATA[3], (String) SIGN_DATA[4], (String) SIGN_DATA[5], (String) SIGN_DATA[6], (String) SIGN_DATA[7], (String) SIGN_DATA[8], (String) SIGN_DATA[9], (String) SIGN_DATA[10], (String) SIGN_DATA[11], forceData);
signs.remove(id);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@ static void process(Statement statement, Object object, String user, int action,
int userid = ConfigHandler.playerIdCache.get(user.toLowerCase(Locale.ROOT));
String query = "";
if (action == 0) {
query = "SELECT color, data, line_1, line_2, line_3, line_4 FROM " + ConfigHandler.prefix + "sign WHERE user='" + userid + "' AND wid='" + wid + "' AND x='" + x + "' AND z='" + z + "' AND y='" + y + "' AND time < '" + time + "' ORDER BY rowid DESC LIMIT 0, 1";
query = "SELECT color, color_secondary, data, waxed, face, line_1, line_2, line_3, line_4, line_5, line_6, line_7, line_8 FROM " + ConfigHandler.prefix + "sign WHERE user='" + userid + "' AND wid='" + wid + "' AND x='" + x + "' AND z='" + z + "' AND y='" + y + "' AND time < '" + time + "' ORDER BY rowid DESC LIMIT 0, 1";
}
else {
query = "SELECT color, data, line_1, line_2, line_3, line_4 FROM " + ConfigHandler.prefix + "sign WHERE user='" + userid + "' AND wid='" + wid + "' AND x='" + x + "' AND z='" + z + "' AND y='" + y + "' AND time >= '" + time + "' ORDER BY rowid ASC LIMIT 0, 1";
query = "SELECT color, color_secondary, data, waxed, face, line_1, line_2, line_3, line_4, line_5, line_6, line_7, line_8 FROM " + ConfigHandler.prefix + "sign WHERE user='" + userid + "' AND wid='" + wid + "' AND x='" + x + "' AND z='" + z + "' AND y='" + y + "' AND time >= '" + time + "' ORDER BY rowid ASC LIMIT 0, 1";
}
SignStatement.getData(statement, block, query);
Util.updateBlock(block);
Expand Down
10 changes: 5 additions & 5 deletions src/main/java/net/coreprotect/database/Database.java
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ else if (table == 2) {
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 (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
Expand Down Expand Up @@ -348,7 +348,7 @@ public static void createDatabaseTables(String prefix, boolean purge) {
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");
Expand All @@ -362,7 +362,7 @@ public static void createDatabaseTables(String prefix, boolean purge) {
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");
Expand Down Expand Up @@ -426,7 +426,7 @@ else if (type.equalsIgnoreCase("index")) {
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);");
Expand All @@ -450,7 +450,7 @@ else if (type.equalsIgnoreCase("index")) {
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);");
Expand Down
Loading

0 comments on commit 4e43a42

Please sign in to comment.