Changed all timestamp values utilized by the API to long types

This commit is contained in:
Intelli 2021-07-26 18:00:21 -06:00
parent 3c82dc337a
commit 40b52fa321
13 changed files with 53 additions and 51 deletions

View File

@ -157,13 +157,13 @@ public class CoreProtectAPI extends Queue {
boolean match = false; boolean match = false;
if (Config.getGlobal().API_ENABLED) { if (Config.getGlobal().API_ENABLED) {
int unixTimestamp = (int) (System.currentTimeMillis() / 1000L); long timestamp = System.currentTimeMillis() / 1000L;
int offsetTime = unixTimestamp - offset; long offsetTime = timestamp - offset;
List<String[]> check = blockLookup(block, time); List<String[]> check = blockLookup(block, time);
for (String[] value : check) { for (String[] value : check) {
ParseResult result = parseResult(value); ParseResult result = parseResult(value);
if (user.equalsIgnoreCase(result.getPlayer()) && result.getActionId() == 1 && result.getTime() <= offsetTime) { if (user.equalsIgnoreCase(result.getPlayer()) && result.getActionId() == 1 && result.getTimestamp() <= offsetTime) {
match = true; match = true;
break; break;
} }
@ -178,13 +178,13 @@ public class CoreProtectAPI extends Queue {
boolean match = false; boolean match = false;
if (Config.getGlobal().API_ENABLED) { if (Config.getGlobal().API_ENABLED) {
int unixTimestamp = (int) (System.currentTimeMillis() / 1000L); long timestamp = System.currentTimeMillis() / 1000L;
int offsetTime = unixTimestamp - offset; long offsetTime = timestamp - offset;
List<String[]> check = blockLookup(block, time); List<String[]> check = blockLookup(block, time);
for (String[] value : check) { for (String[] value : check) {
ParseResult result = parseResult(value); ParseResult result = parseResult(value);
if (user.equalsIgnoreCase(result.getPlayer()) && result.getActionId() == 0 && result.getTime() <= offsetTime) { if (user.equalsIgnoreCase(result.getPlayer()) && result.getActionId() == 0 && result.getTimestamp() <= offsetTime) {
match = true; match = true;
break; break;
} }
@ -202,9 +202,9 @@ public class CoreProtectAPI extends Queue {
if (Config.getGlobal().API_ENABLED && player != null && Config.getConfig(player.getWorld()).PLAYER_MESSAGES) { if (Config.getGlobal().API_ENABLED && player != null && Config.getConfig(player.getWorld()).PLAYER_MESSAGES) {
if (message != null) { if (message != null) {
if (message.length() > 0 && !message.startsWith("/")) { if (message.length() > 0 && !message.startsWith("/")) {
int time = (int) (System.currentTimeMillis() / 1000L); long timestamp = System.currentTimeMillis() / 1000L;
Queue.queuePlayerChat(player, message, time); Queue.queuePlayerChat(player, message, timestamp);
return true; return true;
} }
} }
@ -217,9 +217,9 @@ public class CoreProtectAPI extends Queue {
if (Config.getGlobal().API_ENABLED && player != null && Config.getConfig(player.getWorld()).PLAYER_COMMANDS) { if (Config.getGlobal().API_ENABLED && player != null && Config.getConfig(player.getWorld()).PLAYER_COMMANDS) {
if (command != null) { if (command != null) {
if (command.length() > 0 && command.startsWith("/")) { if (command.length() > 0 && command.startsWith("/")) {
int time = (int) (System.currentTimeMillis() / 1000L); long timestamp = System.currentTimeMillis() / 1000L;
Queue.queuePlayerCommand(player, command, time); Queue.queuePlayerCommand(player, command, timestamp);
return true; return true;
} }
} }
@ -430,8 +430,8 @@ public class CoreProtectAPI extends Queue {
restrictUsers.add("#global"); restrictUsers.add("#global");
} }
int unixTimestamp = (int) (System.currentTimeMillis() / 1000L); long timestamp = System.currentTimeMillis() / 1000L;
int timePeriod = unixTimestamp - time; long timePeriod = timestamp - time;
if (radius < 1) { if (radius < 1) {
radius = -1; radius = -1;

View File

@ -306,20 +306,20 @@ public class Queue {
queueStandardData(consumerId, currentConsumer, new String[] { user, null }, block); queueStandardData(consumerId, currentConsumer, new String[] { user, null }, block);
} }
protected static void queuePlayerChat(Player player, String message, int time) { protected static void queuePlayerChat(Player player, String message, long timestamp) {
int currentConsumer = Consumer.currentConsumer; int currentConsumer = Consumer.currentConsumer;
int consumerId = Consumer.newConsumerId(currentConsumer); int consumerId = Consumer.newConsumerId(currentConsumer);
addConsumer(currentConsumer, new Object[] { consumerId, Process.PLAYER_CHAT, null, 0, null, 0, time, null }); addConsumer(currentConsumer, new Object[] { consumerId, Process.PLAYER_CHAT, null, 0, null, 0, 0, null });
Consumer.consumerStrings.get(currentConsumer).put(consumerId, message); Consumer.consumerStrings.get(currentConsumer).put(consumerId, message);
queueStandardData(consumerId, currentConsumer, new String[] { player.getName(), null }, player.getLocation().clone()); queueStandardData(consumerId, currentConsumer, new String[] { player.getName(), null }, new Object[] { timestamp, player.getLocation().clone() });
} }
protected static void queuePlayerCommand(Player player, String message, int time) { protected static void queuePlayerCommand(Player player, String message, long timestamp) {
int currentConsumer = Consumer.currentConsumer; int currentConsumer = Consumer.currentConsumer;
int consumerId = Consumer.newConsumerId(currentConsumer); int consumerId = Consumer.newConsumerId(currentConsumer);
addConsumer(currentConsumer, new Object[] { consumerId, Process.PLAYER_COMMAND, null, 0, null, 0, time, null }); addConsumer(currentConsumer, new Object[] { consumerId, Process.PLAYER_COMMAND, null, 0, null, 0, 0, null });
Consumer.consumerStrings.get(currentConsumer).put(consumerId, message); Consumer.consumerStrings.get(currentConsumer).put(consumerId, message);
queueStandardData(consumerId, currentConsumer, new String[] { player.getName(), null }, player.getLocation().clone()); queueStandardData(consumerId, currentConsumer, new String[] { player.getName(), null }, new Object[] { timestamp, player.getLocation().clone() });
} }
protected static void queuePlayerInteraction(String user, BlockState block) { protected static void queuePlayerInteraction(String user, BlockState block) {

View File

@ -10,13 +10,14 @@ import net.coreprotect.database.logger.ChatLogger;
class PlayerChatProcess { class PlayerChatProcess {
static void process(PreparedStatement preparedStmt, int batchCount, int processId, int id, Object object, int time, String user) { static void process(PreparedStatement preparedStmt, int batchCount, int processId, int id, Object[] object, String user) {
if (object instanceof Location) { if (object.length == 2 && object[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);
Location location = (Location) object; Long timestamp = (Long) object[0];
ChatLogger.log(preparedStmt, batchCount, time, location, user, message); Location location = (Location) object[1];
ChatLogger.log(preparedStmt, batchCount, timestamp, location, user, message);
strings.remove(id); strings.remove(id);
} }
} }

View File

@ -10,13 +10,14 @@ import net.coreprotect.database.logger.CommandLogger;
class PlayerCommandProcess { class PlayerCommandProcess {
static void process(PreparedStatement preparedStmt, int batchCount, int processId, int id, Object object, int time, String user) { static void process(PreparedStatement preparedStmt, int batchCount, int processId, int id, Object[] object, String user) {
if (object instanceof Location) { if (object.length == 2 && object[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);
Location location = (Location) object; Long timestamp = (Long) object[0];
CommandLogger.log(preparedStmt, batchCount, time, location, user, message); Location location = (Location) object[1];
CommandLogger.log(preparedStmt, batchCount, timestamp, location, user, message);
strings.remove(id); strings.remove(id);
} }
} }

View File

@ -141,13 +141,13 @@ public class Process {
for (int i = 0; i < consumerDataSize; i++) { for (int i = 0; i < consumerDataSize; i++) {
Object[] data = consumerData.get(i); Object[] data = consumerData.get(i);
if (data != null) { if (data != null) {
int id = (Integer) data[0]; int id = (int) data[0];
int action = (Integer) data[1]; int action = (int) data[1];
Material blockType = (Material) data[2]; Material blockType = (Material) data[2];
int blockData = (Integer) data[3]; int blockData = (int) data[3];
Material replace_type = (Material) data[4]; Material replaceType = (Material) data[4];
int replaceData = (Integer) data[5]; int replaceData = (int) data[5];
int forceData = (Integer) data[6]; int forceData = (int) data[6];
if (users.get(id) != null && consumerObject.get(id) != null) { if (users.get(id) != null && consumerObject.get(id) != null) {
String user = users.get(id)[0]; String user = users.get(id)[0];
@ -156,10 +156,10 @@ public class Process {
try { try {
switch (action) { switch (action) {
case Process.BLOCK_BREAK: case Process.BLOCK_BREAK:
BlockBreakProcess.process(preparedStmtBlocks, preparedStmtSkulls, i, processId, id, blockType, blockData, replace_type, forceData, user, object, (String) data[7]); BlockBreakProcess.process(preparedStmtBlocks, preparedStmtSkulls, i, processId, id, blockType, blockData, replaceType, forceData, user, object, (String) data[7]);
break; break;
case Process.BLOCK_PLACE: case Process.BLOCK_PLACE:
BlockPlaceProcess.process(preparedStmtBlocks, preparedStmtSkulls, i, blockType, blockData, replace_type, replaceData, forceData, user, object, (String) data[7], (String) data[8]); BlockPlaceProcess.process(preparedStmtBlocks, preparedStmtSkulls, i, blockType, blockData, replaceType, replaceData, forceData, user, object, (String) data[7], (String) data[8]);
break; break;
case Process.SIGN_TEXT: case Process.SIGN_TEXT:
SignTextProcess.process(preparedStmtSigns, i, processId, id, forceData, user, object, replaceData, blockData); SignTextProcess.process(preparedStmtSigns, i, processId, id, forceData, user, object, replaceData, blockData);
@ -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, forceData, user); PlayerChatProcess.process(preparedStmtChat, i, processId, id, (Object[]) object, user);
break; break;
case Process.PLAYER_COMMAND: case Process.PLAYER_COMMAND:
PlayerCommandProcess.process(preparedStmtCommand, i, processId, id, object, forceData, user); PlayerCommandProcess.process(preparedStmtCommand, i, processId, id, (Object[]) 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);

View File

@ -99,7 +99,7 @@ public class Lookup extends Queue {
return rows; return rows;
} }
public static List<String[]> performLookup(Statement statement, CommandSender user, List<String> checkUuids, List<String> checkUsers, List<Object> restrictList, List<Object> excludeList, List<String> excludeUserList, List<Integer> actionList, Location location, Integer[] radius, int checkTime, boolean restrictWorld, boolean lookup) { public static List<String[]> performLookup(Statement statement, CommandSender user, List<String> checkUuids, List<String> checkUsers, List<Object> restrictList, List<Object> excludeList, List<String> excludeUserList, List<Integer> actionList, Location location, Integer[] radius, long checkTime, boolean restrictWorld, boolean lookup) {
List<String[]> newList = new ArrayList<>(); List<String[]> newList = new ArrayList<>();
try { try {
@ -113,7 +113,7 @@ public class Lookup extends Queue {
return newList; return newList;
} }
static List<Object[]> performLookupRaw(Statement statement, CommandSender user, List<String> checkUuids, List<String> checkUsers, List<Object> restrictList, List<Object> excludeList, List<String> excludeUserList, List<Integer> actionList, Location location, Integer[] radius, int checkTime, int limitOffset, int limitCount, boolean restrictWorld, boolean lookup) { static List<Object[]> performLookupRaw(Statement statement, CommandSender user, List<String> checkUuids, List<String> checkUsers, List<Object> restrictList, List<Object> excludeList, List<String> excludeUserList, List<Integer> actionList, Location location, Integer[] radius, long checkTime, int limitOffset, int limitCount, boolean restrictWorld, boolean lookup) {
List<Object[]> list = new ArrayList<>(); List<Object[]> list = new ArrayList<>();
List<Integer> invalidRollbackActions = new ArrayList<>(); List<Integer> invalidRollbackActions = new ArrayList<>();
invalidRollbackActions.add(2); invalidRollbackActions.add(2);
@ -256,7 +256,7 @@ public class Lookup extends Queue {
return list; return list;
} }
public static List<String[]> performPartialLookup(Statement statement, CommandSender user, List<String> checkUuids, List<String> checkUsers, List<Object> restrictList, List<Object> excludeList, List<String> excludeUserList, List<Integer> actionList, Location location, Integer[] radius, int checkTime, int limitOffset, int limitCount, boolean restrictWorld, boolean lookup) { public static List<String[]> performPartialLookup(Statement statement, CommandSender user, List<String> checkUuids, List<String> checkUsers, List<Object> restrictList, List<Object> excludeList, List<String> excludeUserList, List<Integer> actionList, Location location, Integer[] radius, long checkTime, int limitOffset, int limitCount, boolean restrictWorld, boolean lookup) {
List<String[]> newList = new ArrayList<>(); List<String[]> newList = new ArrayList<>();
try { try {
@ -270,7 +270,7 @@ public class Lookup extends Queue {
return newList; return newList;
} }
private static ResultSet rawLookupResultSet(Statement statement, CommandSender user, List<String> checkUuids, List<String> checkUsers, List<Object> restrictList, List<Object> excludeList, List<String> excludeUserList, List<Integer> actionList, Location location, Integer[] radius, int checkTime, int limitOffset, int limitCount, boolean restrictWorld, boolean lookup, boolean count) { private static ResultSet rawLookupResultSet(Statement statement, CommandSender user, List<String> checkUuids, List<String> checkUsers, List<Object> restrictList, List<Object> excludeList, List<String> excludeUserList, List<Integer> actionList, Location location, Integer[] radius, long checkTime, int limitOffset, int limitCount, boolean restrictWorld, boolean lookup, boolean count) {
ResultSet results = null; ResultSet results = null;
try { try {

View File

@ -87,7 +87,7 @@ import net.coreprotect.utility.Util;
public class Rollback extends Queue { public class Rollback extends Queue {
public static List<String[]> performRollbackRestore(Statement statement, CommandSender user, List<String> checkUuids, List<String> checkUsers, String timeString, List<Object> restrictList, List<Object> excludeList, List<String> excludeUserList, List<Integer> actionList, Location location, Integer[] radius, int checkTime, boolean restrictWorld, boolean lookup, boolean verbose, final int rollbackType, final int preview) { public static List<String[]> performRollbackRestore(Statement statement, CommandSender user, List<String> checkUuids, List<String> checkUsers, String timeString, List<Object> restrictList, List<Object> excludeList, List<String> excludeUserList, List<Integer> actionList, Location location, Integer[] radius, long checkTime, boolean restrictWorld, boolean lookup, boolean verbose, final int rollbackType, final int preview) {
List<String[]> list = new ArrayList<>(); List<String[]> list = new ArrayList<>();
try { try {

View File

@ -15,7 +15,7 @@ public class ChatLogger {
throw new IllegalStateException("Database class"); throw new IllegalStateException("Database class");
} }
public static void log(PreparedStatement preparedStmt, int batchCount, int time, Location location, String user, String message) { public static void log(PreparedStatement preparedStmt, int batchCount, long time, Location location, String user, String message) {
try { try {
if (ConfigHandler.blacklist.get(user.toLowerCase(Locale.ROOT)) != null) { if (ConfigHandler.blacklist.get(user.toLowerCase(Locale.ROOT)) != null) {
return; return;

View File

@ -15,7 +15,7 @@ public class CommandLogger {
throw new IllegalStateException("Database class"); throw new IllegalStateException("Database class");
} }
public static void log(PreparedStatement preparedStmt, int batchCount, int time, Location location, String user, String message) { public static void log(PreparedStatement preparedStmt, int batchCount, long time, Location location, String user, String message) {
try { try {
if (ConfigHandler.blacklist.get(user.toLowerCase(Locale.ROOT)) != null) { if (ConfigHandler.blacklist.get(user.toLowerCase(Locale.ROOT)) != null) {
return; return;

View File

@ -8,9 +8,9 @@ public class ChatStatement {
throw new IllegalStateException("Database class"); throw new IllegalStateException("Database class");
} }
public static void insert(PreparedStatement preparedStmt, int batchCount, int time, int user, int wid, int x, int y, int z, String message) { public static void insert(PreparedStatement preparedStmt, int batchCount, long time, int user, int wid, int x, int y, int z, String message) {
try { try {
preparedStmt.setInt(1, time); preparedStmt.setLong(1, time);
preparedStmt.setInt(2, user); preparedStmt.setInt(2, user);
preparedStmt.setInt(3, wid); preparedStmt.setInt(3, wid);
preparedStmt.setInt(4, x); preparedStmt.setInt(4, x);

View File

@ -8,9 +8,9 @@ public class CommandStatement {
throw new IllegalStateException("Database class"); throw new IllegalStateException("Database class");
} }
public static void insert(PreparedStatement preparedStmt, int batchCount, int time, int user, int wid, int x, int y, int z, String message) { public static void insert(PreparedStatement preparedStmt, int batchCount, long time, int user, int wid, int x, int y, int z, String message) {
try { try {
preparedStmt.setInt(1, time); preparedStmt.setLong(1, time);
preparedStmt.setInt(2, user); preparedStmt.setInt(2, user);
preparedStmt.setInt(3, wid); preparedStmt.setInt(3, wid);
preparedStmt.setInt(4, x); preparedStmt.setInt(4, x);

View File

@ -20,8 +20,8 @@ public final class PlayerChatListener extends Queue implements Listener {
Player player = event.getPlayer(); Player player = event.getPlayer();
if (!message.startsWith("/") && Config.getConfig(player.getWorld()).PLAYER_MESSAGES) { if (!message.startsWith("/") && Config.getConfig(player.getWorld()).PLAYER_MESSAGES) {
int time = (int) (System.currentTimeMillis() / 1000L); long timestamp = System.currentTimeMillis() / 1000L;
Queue.queuePlayerChat(player, message, time); Queue.queuePlayerChat(player, message, timestamp);
} }
} }
} }

View File

@ -15,8 +15,8 @@ public final class PlayerCommandListener extends Queue implements Listener {
public void onPlayerCommandPreprocess(PlayerCommandPreprocessEvent event) { public void onPlayerCommandPreprocess(PlayerCommandPreprocessEvent event) {
Player player = event.getPlayer(); Player player = event.getPlayer();
if (Config.getConfig(player.getWorld()).PLAYER_COMMANDS) { if (Config.getConfig(player.getWorld()).PLAYER_COMMANDS) {
int time = (int) (System.currentTimeMillis() / 1000L); long timestamp = System.currentTimeMillis() / 1000L;
Queue.queuePlayerCommand(player, event.getMessage(), time); Queue.queuePlayerCommand(player, event.getMessage(), timestamp);
} }
} }
} }