Fixed ClassCastException when logging chat and command messages

This commit is contained in:
Intelli 2021-11-04 13:59:48 -06:00
parent a61df070e6
commit 69184302c9
3 changed files with 20 additions and 10 deletions

View File

@ -10,13 +10,18 @@ import net.coreprotect.database.logger.ChatLogger;
class PlayerChatProcess { class PlayerChatProcess {
static void process(PreparedStatement preparedStmt, int batchCount, int processId, int id, Object[] object, String user) { static void process(PreparedStatement preparedStmt, int batchCount, int processId, int id, Object object, String user) {
if (object[1] instanceof Location) { if (!(object instanceof Object[])) {
return;
}
Object[] data = (Object[]) object;
if (data[1] instanceof Location) {
Map<Integer, String> strings = Consumer.consumerStrings.get(processId); Map<Integer, String> strings = Consumer.consumerStrings.get(processId);
if (strings.get(id) != null) { if (strings.get(id) != null) {
String message = strings.get(id); String message = strings.get(id);
Long timestamp = (Long) object[0]; Long timestamp = (Long) data[0];
Location location = (Location) object[1]; Location location = (Location) data[1];
ChatLogger.log(preparedStmt, batchCount, timestamp, location, user, message); ChatLogger.log(preparedStmt, batchCount, timestamp, location, user, message);
strings.remove(id); strings.remove(id);
} }

View File

@ -10,13 +10,18 @@ import net.coreprotect.database.logger.CommandLogger;
class PlayerCommandProcess { class PlayerCommandProcess {
static void process(PreparedStatement preparedStmt, int batchCount, int processId, int id, Object[] object, String user) { static void process(PreparedStatement preparedStmt, int batchCount, int processId, int id, Object object, String user) {
if (object[1] instanceof Location) { if (!(object instanceof Object[])) {
return;
}
Object[] data = (Object[]) object;
if (data[1] instanceof Location) {
Map<Integer, String> strings = Consumer.consumerStrings.get(processId); Map<Integer, String> strings = Consumer.consumerStrings.get(processId);
if (strings.get(id) != null) { if (strings.get(id) != null) {
String message = strings.get(id); String message = strings.get(id);
Long timestamp = (Long) object[0]; Long timestamp = (Long) data[0];
Location location = (Location) object[1]; Location location = (Location) data[1];
CommandLogger.log(preparedStmt, batchCount, timestamp, location, user, message); CommandLogger.log(preparedStmt, batchCount, timestamp, location, user, message);
strings.remove(id); strings.remove(id);
} }

View File

@ -195,10 +195,10 @@ public class Process {
SkullUpdateProcess.process(statement, object, forceData); SkullUpdateProcess.process(statement, object, forceData);
break; break;
case Process.PLAYER_CHAT: case Process.PLAYER_CHAT:
PlayerChatProcess.process(preparedStmtChat, i, processId, id, (Object[]) object, user); PlayerChatProcess.process(preparedStmtChat, i, processId, id, object, user);
break; break;
case Process.PLAYER_COMMAND: case Process.PLAYER_COMMAND:
PlayerCommandProcess.process(preparedStmtCommand, i, processId, id, (Object[]) object, user); PlayerCommandProcess.process(preparedStmtCommand, i, processId, id, object, user);
break; break;
case Process.PLAYER_LOGIN: case Process.PLAYER_LOGIN:
PlayerLoginProcess.process(connection, preparedStmtSession, i, processId, id, object, blockData, replaceData, forceData, user); PlayerLoginProcess.process(connection, preparedStmtSession, i, processId, id, object, blockData, replaceData, forceData, user);