Added filtering support for a:sign

This commit is contained in:
Intelli committed 2026-07-12 13:04:14 -06:00
1 parent 39f66412d6
commit e4c0ea88df
6 files changed
+73 -17

No files matched your search

@@ -100,7 +100,7 @@ public class HelpCommand {
Chat.sendMessage(player, Color.GREY + Color.ITALIC + Phrase.build(Phrase.HELP_ACTION_2));
}
else if (helpcommand.equals("f") || helpcommand.equals("filter") || helpcommand.equals("ffilter")) {
Chat.sendMessage(player, Color.DARK_AQUA + "/co lookup a:<chat|command> f:<filter> " + Color.WHITE + "- " + Phrase.build(Phrase.HELP_FILTER_1));
Chat.sendMessage(player, Color.DARK_AQUA + "/co lookup a:<chat|command|sign> f:<filter> " + Color.WHITE + "- " + Phrase.build(Phrase.HELP_FILTER_1));
Chat.sendMessage(player, Color.GREY + Color.ITALIC + Phrase.build(Phrase.HELP_FILTER_2));
}
else if (helpcommand.equals("i") || helpcommand.equals("include") || helpcommand.equals("iinclude") || helpcommand.equals("b") || helpcommand.equals("block") || helpcommand.equals("blocks") || helpcommand.equals("bblock") || helpcommand.equals("bblocks")) {
@@ -189,7 +189,9 @@ public class LookupCommand {
Chat.sendMessage(player, Color.DARK_AQUA + "CoreProtect " + Color.WHITE + "- " + Phrase.build(Phrase.MESSAGE_FILTER_TOO_SHORT, Integer.toString(MessageFilterParser.MINIMUM_FILTER_CODE_POINTS)));
return;
}
if (argAction.isEmpty() || argAction.stream().anyMatch(action -> action != LookupActions.CHAT && action != LookupActions.COMMAND)) {
boolean messageLookup = !argAction.isEmpty() && argAction.stream().allMatch(action -> action == LookupActions.CHAT || action == LookupActions.COMMAND);
boolean signLookup = !argAction.isEmpty() && argAction.stream().allMatch(action -> action == LookupActions.SIGN);
if (!messageLookup && !signLookup) {
Chat.sendMessage(player, Color.DARK_AQUA + "CoreProtect " + Color.WHITE + "- " + Phrase.build(Phrase.INCOMPATIBLE_ACTION, "f:<filter>"));
return;
}
@@ -498,7 +498,7 @@ public class Database extends Queue {
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");
// Sign
index = ", INDEX(wid,x,z,time), INDEX(user,time), INDEX(time)";
index = ", INDEX(wid,x,z,time), INDEX(user,time), INDEX(time), INDEX line_1_prefix_index(line_1(16)), INDEX line_2_prefix_index(line_2(16)), INDEX line_3_prefix_index(line_3(16)), INDEX line_4_prefix_index(line_4(16)), INDEX line_5_prefix_index(line_5(16)), INDEX line_6_prefix_index(line_6(16)), INDEX line_7_prefix_index(line_7(16)), INDEX line_8_prefix_index(line_8(16))";
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");
// Skull
@@ -640,8 +640,9 @@ public class Database extends Queue {
String tablePrefix = forcePrefix ? prefix : ConfigHandler.prefix;
boolean createChatMessagePrefixIndex = !tableData.contains(tablePrefix + "chat");
boolean createCommandMessagePrefixIndex = !tableData.contains(tablePrefix + "command");
boolean createSignMessagePrefixIndexes = !tableData.contains(tablePrefix + "sign");
createSQLiteTableStructures(prefix, statement, tableData);
createSQLiteIndexes(tablePrefix, statement, indexData, attachDatabase, purge, createChatMessagePrefixIndex, createCommandMessagePrefixIndex);
createSQLiteIndexes(tablePrefix, statement, indexData, attachDatabase, purge, createChatMessagePrefixIndex, createCommandMessagePrefixIndex, createSignMessagePrefixIndexes);
if (!purge && forceConnection == null) {
initializeTables(prefix, statement);
@@ -731,7 +732,7 @@ public class Database extends Queue {
}
}
private static void createSQLiteIndexes(String prefix, Statement statement, List<String> indexData, String attachDatabase, boolean purge, boolean createChatMessagePrefixIndex, boolean createCommandMessagePrefixIndex) {
private static void createSQLiteIndexes(String prefix, Statement statement, List<String> indexData, String attachDatabase, boolean purge, boolean createChatMessagePrefixIndex, boolean createCommandMessagePrefixIndex, boolean createSignMessagePrefixIndexes) {
try {
createSQLiteIndex(statement, indexData, attachDatabase, "art_map_id_index", prefix + "art_map(id)");
createSQLiteIndex(statement, indexData, attachDatabase, "block_index", prefix + "block(wid,x,z,time)");
@@ -777,6 +778,11 @@ public class Database extends Queue {
if (createCommandMessagePrefixIndex) {
createSQLiteIndex(statement, indexData, attachDatabase, "command_message_prefix_index", prefix + "command(substr(message,1,16) COLLATE NOCASE)");
}
if (createSignMessagePrefixIndexes) {
for (int line = 1; line <= 8; line++) {
createSQLiteIndex(statement, indexData, attachDatabase, "sign_line_" + line + "_prefix_index", prefix + "sign(substr(line_" + line + ",1,16) COLLATE NOCASE)");
}
}
}
catch (Exception e) {
Chat.console(Phrase.build(Phrase.DATABASE_INDEX_ERROR));
@@ -781,6 +781,9 @@ public class LookupRaw extends Queue {
else if (chatLookup || commandLookup) {
baseQuery = appendMessageFilters(baseQuery, messageFilters, queryTable, messageFilterBindings);
}
else if (actionList.contains(LookupActions.SIGN)) {
baseQuery = appendSignMessageFilters(baseQuery, messageFilters, messageFilterBindings);
}
boolean itemLookup = inventoryQuery;
if ((lookup && actionList.size() == 0) || (itemLookup && !actionList.contains(LookupActions.BLOCK_BREAK))) {
@@ -965,6 +968,37 @@ public class LookupRaw extends Queue {
return query.append("))").toString();
}
private static String appendSignMessageFilters(String baseQuery, List<String> messageFilters, List<String> bindings) {
if (messageFilters == null || messageFilters.isEmpty()) {
return baseQuery;
}
String alias = "signFilterRows";
StringBuilder query = new StringBuilder(baseQuery).append(" AND rowid IN (");
boolean union = false;
for (String filter : messageFilters) {
String prefix = escapeLike(firstCodePoints(filter, 16)) + "%";
String message = escapeLike(filter) + "%";
for (int line = 1; line <= 8; line++) {
if (union) {
query.append(" UNION ALL ");
}
String column = "line_" + line;
String prefixExpression = Config.getGlobal().MYSQL ? alias + "." + column : "substr(" + alias + "." + column + ",1,16)";
query.append("SELECT ").append(alias).append(".rowid FROM ")
.append(ConfigHandler.prefix).append("sign ").append(alias)
.append(" WHERE ").append(alias).append(line <= 4 ? ".face = 0" : ".face <> 0")
.append(" AND (").append(prefixExpression).append(" LIKE ? ESCAPE '~' AND ")
.append(alias).append(".").append(column).append(" LIKE ? ESCAPE '~')");
bindings.add(prefix);
bindings.add(message);
union = true;
}
}
return query.append(")").toString();
}
private static String firstCodePoints(String value, int maximum) {
if (value == null) {
return "";
@@ -77,8 +77,8 @@ public class Language {
phrases.put(Phrase.HELP_COMMAND, "Display more info for that command.");
phrases.put(Phrase.HELP_EXCLUDE_1, "Exclude blocks/users.");
phrases.put(Phrase.HELP_EXCLUDE_2, "Examples: [e:stone], [e:Notch], [e:stone,Notch]");
phrases.put(Phrase.HELP_FILTER_1, "Filter chat/command messages.");
phrases.put(Phrase.HELP_FILTER_2, "Example: [a:command f:/co]");
phrases.put(Phrase.HELP_FILTER_1, "Filter chat, command, or sign text.");
phrases.put(Phrase.HELP_FILTER_2, "Examples: [a:command f:/co], [a:sign f:Shop]");
phrases.put(Phrase.HELP_HEADER, "{0} Help");
phrases.put(Phrase.HELP_INCLUDE_1, "Include specific blocks/entities.");
phrases.put(Phrase.HELP_INCLUDE_2, "Examples: [i:stone], [i:zombie], [i:stone,wood,bedrock]");
@@ -16,9 +16,16 @@ public class __2_25_0 {
protected static boolean patch(Statement statement) {
if (Config.getGlobal().MYSQL) {
return createMySQLMessagePrefixIndex(statement, ConfigHandler.prefix + "chat")
&& createMySQLMessagePrefixIndex(statement, ConfigHandler.prefix + "command")
&& widenMySQLEntityData(statement, ConfigHandler.prefix + "entity");
if (!createMySQLPrefixIndex(statement, ConfigHandler.prefix + "chat", "message_prefix_index", "message(16)")
|| !createMySQLPrefixIndex(statement, ConfigHandler.prefix + "command", "message_prefix_index", "message(16)")) {
return false;
}
for (int line = 1; line <= 8; line++) {
if (!createMySQLPrefixIndex(statement, ConfigHandler.prefix + "sign", "line_" + line + "_prefix_index", "line_" + line + "(16)")) {
return false;
}
}
return widenMySQLEntityData(statement, ConfigHandler.prefix + "entity");
}
Connection connection = null;
@@ -27,12 +34,19 @@ public class __2_25_0 {
connection = statement.getConnection();
autoCommit = connection.getAutoCommit();
connection.setAutoCommit(false);
statement.executeUpdate("CREATE INDEX IF NOT EXISTS chat_message_prefix_index ON " + ConfigHandler.prefix + "chat(substr(message,1,16) COLLATE NOCASE)");
if (!Patch.continuePatch()) {
connection.rollback();
return false;
String[] indexQueries = new String[10];
indexQueries[0] = "CREATE INDEX IF NOT EXISTS chat_message_prefix_index ON " + ConfigHandler.prefix + "chat(substr(message,1,16) COLLATE NOCASE)";
indexQueries[1] = "CREATE INDEX IF NOT EXISTS command_message_prefix_index ON " + ConfigHandler.prefix + "command(substr(message,1,16) COLLATE NOCASE)";
for (int line = 1; line <= 8; line++) {
indexQueries[line + 1] = "CREATE INDEX IF NOT EXISTS sign_line_" + line + "_prefix_index ON " + ConfigHandler.prefix + "sign(substr(line_" + line + ",1,16) COLLATE NOCASE)";
}
for (String query : indexQueries) {
statement.executeUpdate(query);
if (!Patch.continuePatch()) {
connection.rollback();
return false;
}
}
statement.executeUpdate("CREATE INDEX IF NOT EXISTS command_message_prefix_index ON " + ConfigHandler.prefix + "command(substr(message,1,16) COLLATE NOCASE)");
connection.commit();
return true;
}
@@ -46,9 +60,9 @@ public class __2_25_0 {
}
}
private static boolean createMySQLMessagePrefixIndex(Statement statement, String table) {
private static boolean createMySQLPrefixIndex(Statement statement, String table, String index, String column) {
try {
statement.executeUpdate("CREATE INDEX message_prefix_index ON " + table + "(message(16))");
statement.executeUpdate("CREATE INDEX " + index + " ON " + table + "(" + column + ")");
return true;
}
catch (SQLException e) {