From d7ee5257dd58e64cbea8db89233d928a4bba6e7d Mon Sep 17 00:00:00 2001 From: Intelli Date: Thu, 16 Dec 2021 18:08:56 -0700 Subject: [PATCH] Changed additional timestamp values to long types --- .../java/net/coreprotect/command/ApplyCommand.java | 3 +-- .../java/net/coreprotect/command/CancelCommand.java | 3 +-- .../java/net/coreprotect/command/CommandHandler.java | 7 ++++--- .../java/net/coreprotect/command/InspectCommand.java | 1 - .../java/net/coreprotect/command/LookupCommand.java | 10 +++++----- .../java/net/coreprotect/command/PurgeCommand.java | 11 +++++++---- .../coreprotect/command/RollbackRestoreCommand.java | 10 +++++----- .../java/net/coreprotect/command/UndoCommand.java | 3 +-- .../java/net/coreprotect/config/ConfigHandler.java | 12 +++++++----- .../net/coreprotect/consumer/process/Process.java | 1 - .../net/coreprotect/database/ContainerRollback.java | 2 +- src/main/java/net/coreprotect/database/Lookup.java | 2 +- .../net/coreprotect/database/lookup/BlockLookup.java | 7 +++---- .../database/lookup/ChestTransactionLookup.java | 5 ++--- .../database/lookup/InteractionLookup.java | 3 +-- .../database/lookup/SignMessageLookup.java | 4 ++-- src/main/java/net/coreprotect/utility/Util.java | 6 +++--- 17 files changed, 44 insertions(+), 46 deletions(-) diff --git a/src/main/java/net/coreprotect/command/ApplyCommand.java b/src/main/java/net/coreprotect/command/ApplyCommand.java index f40a294..d44489a 100755 --- a/src/main/java/net/coreprotect/command/ApplyCommand.java +++ b/src/main/java/net/coreprotect/command/ApplyCommand.java @@ -11,14 +11,13 @@ import net.coreprotect.language.Phrase; import net.coreprotect.language.Selector; import net.coreprotect.utility.Chat; import net.coreprotect.utility.Color; -import net.coreprotect.utility.Util; public class ApplyCommand { protected static void runCommand(CommandSender user, Command command, boolean permission, String[] args) { try { if (ConfigHandler.lastRollback.get(user.getName()) != null) { List list = ConfigHandler.lastRollback.get(user.getName()); - int time = (Integer) list.get(0); + long time = (Long) list.get(0); args = (String[]) list.get(1); Location location = (Location) list.get(2); boolean valid = false; diff --git a/src/main/java/net/coreprotect/command/CancelCommand.java b/src/main/java/net/coreprotect/command/CancelCommand.java index 6e3c20b..6a16f74 100755 --- a/src/main/java/net/coreprotect/command/CancelCommand.java +++ b/src/main/java/net/coreprotect/command/CancelCommand.java @@ -11,14 +11,13 @@ import net.coreprotect.language.Phrase; import net.coreprotect.language.Selector; import net.coreprotect.utility.Chat; import net.coreprotect.utility.Color; -import net.coreprotect.utility.Util; public class CancelCommand { protected static void runCommand(CommandSender user, Command command, boolean permission, String[] args) { try { if (ConfigHandler.lastRollback.get(user.getName()) != null) { List list = ConfigHandler.lastRollback.get(user.getName()); - int time = (Integer) list.get(0); + long time = (Long) list.get(0); args = (String[]) list.get(1); Location location = (Location) list.get(2); boolean valid = false; diff --git a/src/main/java/net/coreprotect/command/CommandHandler.java b/src/main/java/net/coreprotect/command/CommandHandler.java index e4d025a..6c54a18 100755 --- a/src/main/java/net/coreprotect/command/CommandHandler.java +++ b/src/main/java/net/coreprotect/command/CommandHandler.java @@ -691,9 +691,9 @@ public class CommandHandler implements CommandExecutor { return restricted; } - protected static int parseTime(String[] inputArguments) { + protected static long parseTime(String[] inputArguments) { String[] argumentArray = inputArguments.clone(); - int time = 0; + long time = 0; int count = 0; int next = 0; double w = 0; @@ -754,7 +754,7 @@ public class CommandHandler implements CommandExecutor { } } double rs = ((w * 7 * 24 * 60 * 60) + (d * 24 * 60 * 60) + (h * 60 * 60) + (m * 60) + s); - time = (int) rs; + time = (long) rs; next = 0; } else { @@ -763,6 +763,7 @@ public class CommandHandler implements CommandExecutor { } count++; } + return time; } diff --git a/src/main/java/net/coreprotect/command/InspectCommand.java b/src/main/java/net/coreprotect/command/InspectCommand.java index 057c53c..0ffe6fa 100755 --- a/src/main/java/net/coreprotect/command/InspectCommand.java +++ b/src/main/java/net/coreprotect/command/InspectCommand.java @@ -7,7 +7,6 @@ import net.coreprotect.language.Phrase; import net.coreprotect.language.Selector; import net.coreprotect.utility.Chat; import net.coreprotect.utility.Color; -import net.coreprotect.utility.Util; public class InspectCommand { protected static void runCommand(CommandSender player, boolean permission, String[] args) { diff --git a/src/main/java/net/coreprotect/command/LookupCommand.java b/src/main/java/net/coreprotect/command/LookupCommand.java index 6e54f64..1575d8b 100755 --- a/src/main/java/net/coreprotect/command/LookupCommand.java +++ b/src/main/java/net/coreprotect/command/LookupCommand.java @@ -51,7 +51,7 @@ public class LookupCommand { List argExclude = CommandHandler.parseExcluded(player, args, argAction); List argExcludeUsers = CommandHandler.parseExcludedUsers(player, args); String ts = CommandHandler.parseTimeString(args); - int rbseconds = CommandHandler.parseTime(args); + long rbseconds = CommandHandler.parseTime(args); int argWid = CommandHandler.parseWorld(args, true, true); int parseRows = CommandHandler.parseRows(args); boolean count = CommandHandler.parseCount(args); @@ -554,7 +554,7 @@ public class LookupCommand { c++; } - int cs = -1; + long cs = -1; int x = 0; int y = 0; int z = 0; @@ -567,7 +567,7 @@ public class LookupCommand { y = Integer.parseInt(data[1]); z = Integer.parseInt(data[2]); wid = Integer.parseInt(data[3]); - cs = Integer.parseInt(data[4]); + cs = Long.parseLong(data[4]); // arg_radius = Integer.parseInt(data[5]); argNoisy = Integer.parseInt(data[5]); argExcluded = Integer.parseInt(data[6]); @@ -640,7 +640,7 @@ public class LookupCommand { } final List rollbackusers2 = rollbackusers; - int unixtimestamp = (int) (System.currentTimeMillis() / 1000L); + long unixtimestamp = (System.currentTimeMillis() / 1000L); if (cs == -1) { if (rbseconds <= 0) { cs = 0; @@ -649,7 +649,7 @@ public class LookupCommand { cs = unixtimestamp - rbseconds; } } - final int stime = cs; + final long stime = cs; final Integer[] radius = argRadius; try { diff --git a/src/main/java/net/coreprotect/command/PurgeCommand.java b/src/main/java/net/coreprotect/command/PurgeCommand.java index fb8244b..db37bd4 100755 --- a/src/main/java/net/coreprotect/command/PurgeCommand.java +++ b/src/main/java/net/coreprotect/command/PurgeCommand.java @@ -1,7 +1,10 @@ package net.coreprotect.command; import java.io.File; -import java.sql.*; +import java.sql.Connection; +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.sql.ResultSetMetaData; import java.text.NumberFormat; import java.util.Arrays; import java.util.List; @@ -28,7 +31,7 @@ public class PurgeCommand extends Consumer { int resultc = args.length; Location location = CommandHandler.parseLocation(player, args); final Integer[] argRadius = CommandHandler.parseRadius(args, player, location); - final int seconds = CommandHandler.parseTime(args); + final long seconds = CommandHandler.parseTime(args); final int argWid = CommandHandler.parseWorld(args, false, false); final List argAction = CommandHandler.parseAction(args); final List supportedActions = Arrays.asList(); @@ -92,8 +95,8 @@ public class PurgeCommand extends Consumer { @Override public void run() { try (Connection connection = Database.getConnection(false, 500)) { - int timestamp = (int) (System.currentTimeMillis() / 1000L); - int ptime = timestamp - seconds; + long timestamp = (System.currentTimeMillis() / 1000L); + long ptime = timestamp - seconds; long removed = 0; for (int i = 0; i <= 5; i++) { diff --git a/src/main/java/net/coreprotect/command/RollbackRestoreCommand.java b/src/main/java/net/coreprotect/command/RollbackRestoreCommand.java index 341fa40..4227078 100755 --- a/src/main/java/net/coreprotect/command/RollbackRestoreCommand.java +++ b/src/main/java/net/coreprotect/command/RollbackRestoreCommand.java @@ -31,7 +31,7 @@ import net.coreprotect.utility.Color; import net.coreprotect.utility.Util; public class RollbackRestoreCommand { - protected static void runCommand(CommandSender player, Command command, boolean permission, String[] args, Location argLocation, int forceSeconds) { + protected static void runCommand(CommandSender player, Command command, boolean permission, String[] args, Location argLocation, long forceSeconds) { Location lo = (argLocation != null ? argLocation : CommandHandler.parseLocation(player, args)); List argUuids = new ArrayList<>(); List argUsers = CommandHandler.parseUsers(args); @@ -42,7 +42,7 @@ public class RollbackRestoreCommand { List argExclude = CommandHandler.parseExcluded(player, args, argAction); List argExcludeUsers = CommandHandler.parseExcludedUsers(player, args); String ts = CommandHandler.parseTimeString(args); - int rbSeconds = CommandHandler.parseTime(args); + long rbSeconds = CommandHandler.parseTime(args); int argWid = CommandHandler.parseWorld(args, true, true); boolean count = CommandHandler.parseCount(args); boolean worldedit = CommandHandler.parseWorldEdit(args); @@ -284,12 +284,12 @@ public class RollbackRestoreCommand { final List rollbackusers2 = rollbackusers; if (rbSeconds > 0) { - int unixtimestamp = (int) (System.currentTimeMillis() / 1000L); - int seconds = unixtimestamp - rbSeconds; + long unixtimestamp = (System.currentTimeMillis() / 1000L); + long seconds = unixtimestamp - rbSeconds; if (forceSeconds > 0) { seconds = forceSeconds; } - final int stime = seconds; + final long stime = seconds; final Integer[] radius = argRadius; try { final CommandSender player2 = player; diff --git a/src/main/java/net/coreprotect/command/UndoCommand.java b/src/main/java/net/coreprotect/command/UndoCommand.java index 15edb9f..089d33b 100755 --- a/src/main/java/net/coreprotect/command/UndoCommand.java +++ b/src/main/java/net/coreprotect/command/UndoCommand.java @@ -11,14 +11,13 @@ import net.coreprotect.language.Phrase; import net.coreprotect.language.Selector; import net.coreprotect.utility.Chat; import net.coreprotect.utility.Color; -import net.coreprotect.utility.Util; public class UndoCommand { protected static void runCommand(CommandSender user, Command command, boolean permission, String[] args) { try { if (ConfigHandler.lastRollback.get(user.getName()) != null) { List list = ConfigHandler.lastRollback.get(user.getName()); - int time = (Integer) list.get(0); + long time = (Long) list.get(0); args = (String[]) list.get(1); Location location = (Location) list.get(2); for (String arg : args) { diff --git a/src/main/java/net/coreprotect/config/ConfigHandler.java b/src/main/java/net/coreprotect/config/ConfigHandler.java index f87ee8d..4640065 100644 --- a/src/main/java/net/coreprotect/config/ConfigHandler.java +++ b/src/main/java/net/coreprotect/config/ConfigHandler.java @@ -14,8 +14,6 @@ import java.util.Map; import java.util.UUID; import java.util.concurrent.ConcurrentHashMap; -import com.zaxxer.hikari.HikariConfig; -import com.zaxxer.hikari.HikariDataSource; import org.bukkit.Bukkit; import org.bukkit.World; import org.bukkit.entity.Player; @@ -23,8 +21,10 @@ import org.bukkit.inventory.ItemStack; import org.bukkit.plugin.Plugin; import org.bukkit.plugin.PluginManager; +import com.zaxxer.hikari.HikariConfig; +import com.zaxxer.hikari.HikariDataSource; + import net.coreprotect.bukkit.BukkitAdapter; -import net.coreprotect.consumer.Consumer; import net.coreprotect.consumer.Queue; import net.coreprotect.database.Database; import net.coreprotect.database.statement.UserStatement; @@ -207,7 +207,8 @@ public class ConfigHandler extends Queue { catch (Exception e) { e.printStackTrace(); } - } else { + } + else { HikariConfig config = new HikariConfig(); config.setJdbcUrl("jdbc:mysql://" + ConfigHandler.host + ":" + ConfigHandler.port + "/" + ConfigHandler.database); config.setUsername(ConfigHandler.username); @@ -395,7 +396,8 @@ public class ConfigHandler extends Queue { ConfigHandler.loadConfig(); // Load (or create) the configuration file. ConfigHandler.loadDatabase(); // Initialize MySQL and create tables if necessary. - } catch (Exception e) { + } + catch (Exception e) { e.printStackTrace(); } diff --git a/src/main/java/net/coreprotect/consumer/process/Process.java b/src/main/java/net/coreprotect/consumer/process/Process.java index f39c29e..4085ab6 100755 --- a/src/main/java/net/coreprotect/consumer/process/Process.java +++ b/src/main/java/net/coreprotect/consumer/process/Process.java @@ -2,7 +2,6 @@ package net.coreprotect.consumer.process; import java.sql.Connection; import java.sql.PreparedStatement; -import java.sql.SQLException; import java.sql.Statement; import java.util.ArrayList; import java.util.Locale; diff --git a/src/main/java/net/coreprotect/database/ContainerRollback.java b/src/main/java/net/coreprotect/database/ContainerRollback.java index 67c73f1..1619bc9 100644 --- a/src/main/java/net/coreprotect/database/ContainerRollback.java +++ b/src/main/java/net/coreprotect/database/ContainerRollback.java @@ -24,7 +24,7 @@ import net.coreprotect.utility.Util; public class ContainerRollback extends Queue { - public static void performContainerRollbackRestore(Statement statement, CommandSender user, List checkUuids, List checkUsers, String timeString, List restrictList, List excludeList, List excludeUserList, List actionList, final Location location, Integer[] radius, int checkTime, boolean restrictWorld, boolean lookup, boolean verbose, final int rollbackType) { + public static void performContainerRollbackRestore(Statement statement, CommandSender user, List checkUuids, List checkUsers, String timeString, List restrictList, List excludeList, List excludeUserList, List actionList, final Location location, Integer[] radius, long checkTime, boolean restrictWorld, boolean lookup, boolean verbose, final int rollbackType) { try { long startTime = System.currentTimeMillis(); diff --git a/src/main/java/net/coreprotect/database/Lookup.java b/src/main/java/net/coreprotect/database/Lookup.java index 5c1b204..f02e478 100755 --- a/src/main/java/net/coreprotect/database/Lookup.java +++ b/src/main/java/net/coreprotect/database/Lookup.java @@ -75,7 +75,7 @@ public class Lookup extends Queue { return newList; } - public static int countLookupRows(Statement statement, CommandSender user, List checkUuids, List checkUsers, List restrictList, List excludeList, List excludeUserList, List actionList, Location location, Integer[] radius, int checkTime, boolean restrictWorld, boolean lookup) { + public static int countLookupRows(Statement statement, CommandSender user, List checkUuids, List checkUsers, List restrictList, List excludeList, List excludeUserList, List actionList, Location location, Integer[] radius, long checkTime, boolean restrictWorld, boolean lookup) { int rows = 0; try { diff --git a/src/main/java/net/coreprotect/database/lookup/BlockLookup.java b/src/main/java/net/coreprotect/database/lookup/BlockLookup.java index 8abb4d3..3912dac 100644 --- a/src/main/java/net/coreprotect/database/lookup/BlockLookup.java +++ b/src/main/java/net/coreprotect/database/lookup/BlockLookup.java @@ -12,7 +12,6 @@ import net.coreprotect.config.ConfigHandler; import net.coreprotect.database.statement.UserStatement; import net.coreprotect.language.Phrase; import net.coreprotect.language.Selector; -import net.coreprotect.utility.Chat; import net.coreprotect.utility.Color; import net.coreprotect.utility.Util; @@ -45,9 +44,9 @@ public class BlockLookup { int x = block.getX(); int y = block.getY(); int z = block.getZ(); - int time = (int) (System.currentTimeMillis() / 1000L); + long time = (System.currentTimeMillis() / 1000L); int worldId = Util.getWorldId(block.getWorld().getName()); - int checkTime = 0; + long checkTime = 0; int count = 0; int rowMax = page * limit; int page_start = rowMax - limit; @@ -75,7 +74,7 @@ public class BlockLookup { int resultAction = results.getInt("action"); int resultType = results.getInt("type"); int resultData = results.getInt("data"); - int resultTime = results.getInt("time"); + long resultTime = results.getLong("time"); int resultRolledBack = results.getInt("rolled_back"); if (ConfigHandler.playerIdCacheReversed.get(resultUserId) == null) { diff --git a/src/main/java/net/coreprotect/database/lookup/ChestTransactionLookup.java b/src/main/java/net/coreprotect/database/lookup/ChestTransactionLookup.java index e2b036e..db4e66c 100644 --- a/src/main/java/net/coreprotect/database/lookup/ChestTransactionLookup.java +++ b/src/main/java/net/coreprotect/database/lookup/ChestTransactionLookup.java @@ -12,7 +12,6 @@ import net.coreprotect.config.ConfigHandler; import net.coreprotect.database.statement.UserStatement; import net.coreprotect.language.Phrase; import net.coreprotect.language.Selector; -import net.coreprotect.utility.Chat; import net.coreprotect.utility.Color; import net.coreprotect.utility.Util; @@ -48,7 +47,7 @@ public class ChestTransactionLookup { int x2 = (int) Math.ceil(l.getX()); int y2 = (int) Math.ceil(l.getY()); int z2 = (int) Math.ceil(l.getZ()); - int time = (int) (System.currentTimeMillis() / 1000L); + long time = (System.currentTimeMillis() / 1000L); int worldId = Util.getWorldId(l.getWorld().getName()); int count = 0; int rowMax = page * limit; @@ -79,7 +78,7 @@ public class ChestTransactionLookup { int resultAction = results.getInt("action"); int resultType = results.getInt("type"); int resultData = results.getInt("data"); - int resultTime = results.getInt("time"); + long resultTime = results.getLong("time"); int resultAmount = results.getInt("amount"); int resultRolledBack = results.getInt("rolled_back"); diff --git a/src/main/java/net/coreprotect/database/lookup/InteractionLookup.java b/src/main/java/net/coreprotect/database/lookup/InteractionLookup.java index 00fa719..69a3938 100644 --- a/src/main/java/net/coreprotect/database/lookup/InteractionLookup.java +++ b/src/main/java/net/coreprotect/database/lookup/InteractionLookup.java @@ -12,7 +12,6 @@ import net.coreprotect.config.ConfigHandler; import net.coreprotect.database.statement.UserStatement; import net.coreprotect.language.Phrase; import net.coreprotect.language.Selector; -import net.coreprotect.utility.Chat; import net.coreprotect.utility.Color; import net.coreprotect.utility.Util; @@ -73,7 +72,7 @@ public class InteractionLookup { int resultAction = results.getInt("action"); int resultType = results.getInt("type"); int resultData = results.getInt("data"); - int resultTime = results.getInt("time"); + long resultTime = results.getLong("time"); int resultRolledBack = results.getInt("rolled_back"); if (ConfigHandler.playerIdCacheReversed.get(resultUserId) == null) { diff --git a/src/main/java/net/coreprotect/database/lookup/SignMessageLookup.java b/src/main/java/net/coreprotect/database/lookup/SignMessageLookup.java index 6ff75d5..3e1b603 100644 --- a/src/main/java/net/coreprotect/database/lookup/SignMessageLookup.java +++ b/src/main/java/net/coreprotect/database/lookup/SignMessageLookup.java @@ -44,7 +44,7 @@ public class SignMessageLookup { int x = l.getBlockX(); int y = l.getBlockY(); int z = l.getBlockZ(); - int time = (int) (System.currentTimeMillis() / 1000L); + long time = (System.currentTimeMillis() / 1000L); int worldId = Util.getWorldId(l.getWorld().getName()); int count = 0; int rowMax = page * limit; @@ -64,7 +64,7 @@ public class SignMessageLookup { results = statement.executeQuery(query); while (results.next()) { - int resultTime = results.getInt("time"); + long resultTime = results.getLong("time"); int resultUserId = results.getInt("user"); String line1 = results.getString("line_1"); String line2 = results.getString("line_2"); diff --git a/src/main/java/net/coreprotect/utility/Util.java b/src/main/java/net/coreprotect/utility/Util.java index 4c9b39b..993fe2d 100755 --- a/src/main/java/net/coreprotect/utility/Util.java +++ b/src/main/java/net/coreprotect/utility/Util.java @@ -196,9 +196,9 @@ public class Util extends Queue { return message.append(Color.WHITE + backArrow + Phrase.build(Phrase.LOOKUP_PAGE, page + "/" + totalPages) + nextArrow).toString(); } - public static String getTimeSince(int logTime, int currentTime, boolean component) { + public static String getTimeSince(long resultTime, long currentTime, boolean component) { StringBuilder message = new StringBuilder(); - double timeSince = currentTime - (logTime + 0.00); + double timeSince = currentTime - (resultTime + 0.00); // minutes timeSince = timeSince / 60; @@ -221,7 +221,7 @@ public class Util extends Queue { } if (component) { - Date logDate = new Date(logTime * 1000L); + Date logDate = new Date(resultTime * 1000L); String formattedTimestamp = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss z").format(logDate); return Chat.COMPONENT_TAG_OPEN + Chat.COMPONENT_POPUP + "|" + Color.GREY + formattedTimestamp + "|" + Color.GREY + message.toString() + Chat.COMPONENT_TAG_CLOSE;