diff --git a/src/main/java/net/coreprotect/CoreProtectAPI.java b/src/main/java/net/coreprotect/CoreProtectAPI.java index edb53c7..8157a24 100755 --- a/src/main/java/net/coreprotect/CoreProtectAPI.java +++ b/src/main/java/net/coreprotect/CoreProtectAPI.java @@ -168,7 +168,6 @@ public class CoreProtectAPI extends Queue { } public int APIVersion() { - return 8; try { // deny access to BlocksHub to prevent duplicate data from being logged if (!checkedBlocksHub && Bukkit.getPluginManager().getPlugin("BlocksHub") != null) { @@ -187,6 +186,7 @@ public class CoreProtectAPI extends Queue { // proceed with returning API version } + return 8; } public List blockLookup(Block block, int time) { @@ -483,7 +483,8 @@ public class CoreProtectAPI extends Queue { } long timestamp = System.currentTimeMillis() / 1000L; - long timePeriod = timestamp - time; + long startTime = timestamp - time; + long endTime = 0; if (radius < 1) { radius = -1; @@ -525,16 +526,16 @@ public class CoreProtectAPI extends Queue { } if (useLimit) { - result = Lookup.performPartialLookup(statement, null, uuids, restrictUsers, restrictBlocks, excludeBlocks, excludeUsers, actionList, location, argRadius, null, timePeriod, offset, rowCount, restrictWorld, true); + result = Lookup.performPartialLookup(statement, null, uuids, restrictUsers, restrictBlocks, excludeBlocks, excludeUsers, actionList, location, argRadius, null, startTime, endTime, offset, rowCount, restrictWorld, true); } else { - result = Lookup.performLookup(statement, null, uuids, restrictUsers, restrictBlocks, excludeBlocks, excludeUsers, actionList, location, argRadius, timePeriod, restrictWorld, true); + result = Lookup.performLookup(statement, null, uuids, restrictUsers, restrictBlocks, excludeBlocks, excludeUsers, actionList, location, argRadius, startTime, endTime, restrictWorld, true); } } else { if (!Bukkit.isPrimaryThread()) { boolean verbose = false; - result = Rollback.performRollbackRestore(statement, null, uuids, restrictUsers, null, restrictBlocks, excludeBlocks, excludeUsers, actionList, location, argRadius, timePeriod, restrictWorld, false, verbose, action, 0); + result = Rollback.performRollbackRestore(statement, null, uuids, restrictUsers, null, restrictBlocks, excludeBlocks, excludeUsers, actionList, location, argRadius, startTime, endTime, restrictWorld, false, verbose, action, 0); } } diff --git a/src/main/java/net/coreprotect/command/ApplyCommand.java b/src/main/java/net/coreprotect/command/ApplyCommand.java index d44489a..eb886cc 100755 --- a/src/main/java/net/coreprotect/command/ApplyCommand.java +++ b/src/main/java/net/coreprotect/command/ApplyCommand.java @@ -17,9 +17,10 @@ public class ApplyCommand { try { if (ConfigHandler.lastRollback.get(user.getName()) != null) { List list = ConfigHandler.lastRollback.get(user.getName()); - long time = (Long) list.get(0); - args = (String[]) list.get(1); - Location location = (Location) list.get(2); + long startTime = (Long) list.get(0); + long endTime = (Long) list.get(1); + args = (String[]) list.get(2); + Location location = (Location) list.get(3); boolean valid = false; for (int i = 0; i < args.length; i++) { if (args[i].equals("#preview")) { @@ -32,7 +33,7 @@ public class ApplyCommand { } else { ConfigHandler.lastRollback.remove(user.getName()); - RollbackRestoreCommand.runCommand(user, command, permission, args, location, time); + RollbackRestoreCommand.runCommand(user, command, permission, args, location, startTime, endTime); } } else { diff --git a/src/main/java/net/coreprotect/command/CancelCommand.java b/src/main/java/net/coreprotect/command/CancelCommand.java index 6a16f74..4fe80e6 100755 --- a/src/main/java/net/coreprotect/command/CancelCommand.java +++ b/src/main/java/net/coreprotect/command/CancelCommand.java @@ -17,9 +17,10 @@ public class CancelCommand { try { if (ConfigHandler.lastRollback.get(user.getName()) != null) { List list = ConfigHandler.lastRollback.get(user.getName()); - long time = (Long) list.get(0); - args = (String[]) list.get(1); - Location location = (Location) list.get(2); + long startTime = (Long) list.get(0); + long endTime = (Long) list.get(1); + args = (String[]) list.get(2); + Location location = (Location) list.get(3); boolean valid = false; for (int i = 0; i < args.length; i++) { if (args[i].equals("#preview")) { @@ -32,7 +33,7 @@ public class CancelCommand { } else { ConfigHandler.lastRollback.remove(user.getName()); - RollbackRestoreCommand.runCommand(user, command, permission, args, location, time); + RollbackRestoreCommand.runCommand(user, command, permission, args, location, startTime, endTime); } } else { diff --git a/src/main/java/net/coreprotect/command/CommandHandler.java b/src/main/java/net/coreprotect/command/CommandHandler.java index a90c33b..efdf045 100755 --- a/src/main/java/net/coreprotect/command/CommandHandler.java +++ b/src/main/java/net/coreprotect/command/CommandHandler.java @@ -691,11 +691,13 @@ public class CommandHandler implements CommandExecutor { return restricted; } - protected static long parseTime(String[] inputArguments) { + protected static long[] parseTime(String[] inputArguments) { String[] argumentArray = inputArguments.clone(); - long time = 0; + long timeStart = 0; + long timeEnd = 0; int count = 0; int next = 0; + boolean range = false; double w = 0; double d = 0; double h = 0; @@ -720,41 +722,59 @@ public class CommandHandler implements CommandExecutor { argument = argument.replaceAll("d", "d:"); argument = argument.replaceAll("h", "h:"); argument = argument.replaceAll("s", "s:"); + range = argument.contains("-"); + + int argCount = 0; String[] i2 = argument.split(":"); for (String i3 : i2) { - if (i3.endsWith("w")) { + if (range && argCount > 0 && timeStart == 0 && i3.startsWith("-")) { + timeStart = (long) (((w * 7 * 24 * 60 * 60) + (d * 24 * 60 * 60) + (h * 60 * 60) + (m * 60) + s)); + w = 0; + d = 0; + h = 0; + m = 0; + s = 0; + } + + if (i3.endsWith("w") && w == 0) { String i4 = i3.replaceAll("[^0-9.]", ""); if (i4.length() > 0 && i4.replaceAll("[^0-9]", "").length() > 0 && i4.indexOf('.') == i4.lastIndexOf('.')) { w = Double.parseDouble(i4); } } - else if (i3.endsWith("d")) { + else if (i3.endsWith("d") && d == 0) { String i4 = i3.replaceAll("[^0-9.]", ""); if (i4.length() > 0 && i4.replaceAll("[^0-9]", "").length() > 0 && i4.indexOf('.') == i4.lastIndexOf('.')) { d = Double.parseDouble(i4); } } - else if (i3.endsWith("h")) { + else if (i3.endsWith("h") && h == 0) { String i4 = i3.replaceAll("[^0-9.]", ""); if (i4.length() > 0 && i4.replaceAll("[^0-9]", "").length() > 0 && i4.indexOf('.') == i4.lastIndexOf('.')) { h = Double.parseDouble(i4); } } - else if (i3.endsWith("m")) { + else if (i3.endsWith("m") && m == 0) { String i4 = i3.replaceAll("[^0-9.]", ""); if (i4.length() > 0 && i4.replaceAll("[^0-9]", "").length() > 0 && i4.indexOf('.') == i4.lastIndexOf('.')) { m = Double.parseDouble(i4); } } - else if (i3.endsWith("s")) { + else if (i3.endsWith("s") && s == 0) { String i4 = i3.replaceAll("[^0-9.]", ""); if (i4.length() > 0 && i4.replaceAll("[^0-9]", "").length() > 0 && i4.indexOf('.') == i4.lastIndexOf('.')) { s = Double.parseDouble(i4); } } + + argCount++; + } + if (timeStart > 0) { + timeEnd = (long) (((w * 7 * 24 * 60 * 60) + (d * 24 * 60 * 60) + (h * 60 * 60) + (m * 60) + s)); + } + else { + timeStart = (long) (((w * 7 * 24 * 60 * 60) + (d * 24 * 60 * 60) + (h * 60 * 60) + (m * 60) + s)); } - double rs = ((w * 7 * 24 * 60 * 60) + (d * 24 * 60 * 60) + (h * 60 * 60) + (m * 60) + s); - time = (long) rs; next = 0; } else { @@ -764,7 +784,12 @@ public class CommandHandler implements CommandExecutor { count++; } - return time; + if (timeEnd >= timeStart) { + return new long[] { timeEnd, timeStart }; + } + else { + return new long[] { timeStart, timeEnd }; + } } private static String timeString(BigDecimal input) { @@ -776,6 +801,7 @@ public class CommandHandler implements CommandExecutor { String time = ""; int count = 0; int next = 0; + boolean range = false; BigDecimal w = new BigDecimal(0); BigDecimal d = new BigDecimal(0); BigDecimal h = new BigDecimal(0); @@ -800,43 +826,82 @@ public class CommandHandler implements CommandExecutor { argument = argument.replaceAll("d", "d:"); argument = argument.replaceAll("h", "h:"); argument = argument.replaceAll("s", "s:"); + range = argument.contains("-"); + + int argCount = 0; String[] i2 = argument.split(":"); for (String i3 : i2) { - if (i3.endsWith("w")) { + if (range && argCount > 0 && !time.contains("-") && i3.startsWith("-")) { + w = new BigDecimal(0); + d = new BigDecimal(0); + h = new BigDecimal(0); + m = new BigDecimal(0); + s = new BigDecimal(0); + time = time + " -"; + } + + if (i3.endsWith("w") && w.intValue() == 0) { String i4 = i3.replaceAll("[^0-9.]", ""); if (i4.length() > 0 && i4.replaceAll("[^0-9]", "").length() > 0 && i4.indexOf('.') == i4.lastIndexOf('.')) { w = new BigDecimal(i4); - time = time + " " + Phrase.build(Phrase.TIME_WEEKS, timeString(w), (w.doubleValue() == 1 ? Selector.FIRST : Selector.SECOND)); + if (range) { + time = time + " " + timeString(w) + "w"; + } + else { + time = time + " " + Phrase.build(Phrase.TIME_WEEKS, timeString(w), (w.doubleValue() == 1 ? Selector.FIRST : Selector.SECOND)); + } } } - else if (i3.endsWith("d")) { + else if (i3.endsWith("d") && d.intValue() == 0) { String i4 = i3.replaceAll("[^0-9.]", ""); if (i4.length() > 0 && i4.replaceAll("[^0-9]", "").length() > 0 && i4.indexOf('.') == i4.lastIndexOf('.')) { d = new BigDecimal(i4); - time = time + " " + Phrase.build(Phrase.TIME_DAYS, timeString(d), (d.doubleValue() == 1 ? Selector.FIRST : Selector.SECOND)); + if (range) { + time = time + " " + timeString(d) + "d"; + } + else { + time = time + " " + Phrase.build(Phrase.TIME_DAYS, timeString(d), (d.doubleValue() == 1 ? Selector.FIRST : Selector.SECOND)); + } } } - else if (i3.endsWith("h")) { + else if (i3.endsWith("h") && h.intValue() == 0) { String i4 = i3.replaceAll("[^0-9.]", ""); if (i4.length() > 0 && i4.replaceAll("[^0-9]", "").length() > 0 && i4.indexOf('.') == i4.lastIndexOf('.')) { h = new BigDecimal(i4); - time = time + " " + Phrase.build(Phrase.TIME_HOURS, timeString(h), (h.doubleValue() == 1 ? Selector.FIRST : Selector.SECOND)); + if (range) { + time = time + " " + timeString(h) + "h"; + } + else { + time = time + " " + Phrase.build(Phrase.TIME_HOURS, timeString(h), (h.doubleValue() == 1 ? Selector.FIRST : Selector.SECOND)); + } } } - else if (i3.endsWith("m")) { + else if (i3.endsWith("m") && m.intValue() == 0) { String i4 = i3.replaceAll("[^0-9.]", ""); if (i4.length() > 0 && i4.replaceAll("[^0-9]", "").length() > 0 && i4.indexOf('.') == i4.lastIndexOf('.')) { m = new BigDecimal(i4); - time = time + " " + Phrase.build(Phrase.TIME_MINUTES, timeString(m), (m.doubleValue() == 1 ? Selector.FIRST : Selector.SECOND)); + if (range) { + time = time + " " + timeString(m) + "m"; + } + else { + time = time + " " + Phrase.build(Phrase.TIME_MINUTES, timeString(m), (m.doubleValue() == 1 ? Selector.FIRST : Selector.SECOND)); + } } } - else if (i3.endsWith("s")) { + else if (i3.endsWith("s") && s.intValue() == 0) { String i4 = i3.replaceAll("[^0-9.]", ""); if (i4.length() > 0 && i4.replaceAll("[^0-9]", "").length() > 0 && i4.indexOf('.') == i4.lastIndexOf('.')) { s = new BigDecimal(i4); - time = time + " " + Phrase.build(Phrase.TIME_SECONDS, timeString(s), (s.doubleValue() == 1 ? Selector.FIRST : Selector.SECOND)); + if (range) { + time = time + " " + timeString(s) + "s"; + } + else { + time = time + " " + Phrase.build(Phrase.TIME_SECONDS, timeString(s), (s.doubleValue() == 1 ? Selector.FIRST : Selector.SECOND)); + } } } + + argCount++; } next = 0; } @@ -1128,7 +1193,7 @@ public class CommandHandler implements CommandExecutor { } if (corecommand.equals("rollback") || corecommand.equals("restore") || corecommand.equals("rb") || corecommand.equals("rs") || corecommand.equals("ro") || corecommand.equals("re")) { - RollbackRestoreCommand.runCommand(user, command, permission, argumentArray, null, 0); + RollbackRestoreCommand.runCommand(user, command, permission, argumentArray, null, 0, 0); } else if (corecommand.equals("apply")) { ApplyCommand.runCommand(user, command, permission, argumentArray); diff --git a/src/main/java/net/coreprotect/command/LookupCommand.java b/src/main/java/net/coreprotect/command/LookupCommand.java index 1eea2df..dba1e85 100755 --- a/src/main/java/net/coreprotect/command/LookupCommand.java +++ b/src/main/java/net/coreprotect/command/LookupCommand.java @@ -52,7 +52,9 @@ public class LookupCommand { List argExclude = CommandHandler.parseExcluded(player, args, argAction); List argExcludeUsers = CommandHandler.parseExcludedUsers(player, args); String ts = CommandHandler.parseTimeString(args); - long rbseconds = CommandHandler.parseTime(args); + long[] argTime = CommandHandler.parseTime(args); + long startTime = argTime[0]; + long endTime = argTime[1]; int argWid = CommandHandler.parseWorld(args, true, true); int parseRows = CommandHandler.parseRows(args); boolean count = CommandHandler.parseCount(args); @@ -258,7 +260,7 @@ public class LookupCommand { } } - if (rbseconds <= 0 && !pageLookup && type == 4 && (argBlocks.size() > 0 || argUsers.size() > 0)) { + if (startTime <= 0 && !pageLookup && type == 4 && (argBlocks.size() > 0 || argUsers.size() > 0)) { Chat.sendMessage(player, Color.DARK_AQUA + "CoreProtect " + Color.WHITE + "- " + Phrase.build(Phrase.MISSING_LOOKUP_TIME, Selector.FIRST)); return; } @@ -571,7 +573,8 @@ public class LookupCommand { c++; } - long cs = -1; + long timeStart = -1; + long timeEnd = 0; int x = 0; int y = 0; int z = 0; @@ -584,14 +587,14 @@ public class LookupCommand { y = Integer.parseInt(data[1]); z = Integer.parseInt(data[2]); wid = Integer.parseInt(data[3]); - cs = Long.parseLong(data[4]); - // arg_radius = Integer.parseInt(data[5]); - argNoisy = Integer.parseInt(data[5]); - argExcluded = Integer.parseInt(data[6]); - argRestricted = Integer.parseInt(data[7]); - argWid = Integer.parseInt(data[8]); + timeStart = Long.parseLong(data[4]); + timeEnd = Long.parseLong(data[5]); + argNoisy = Integer.parseInt(data[6]); + argExcluded = Integer.parseInt(data[7]); + argRestricted = Integer.parseInt(data[8]); + argWid = Integer.parseInt(data[9]); if (defaultRe) { - re = Integer.parseInt(data[9]); + re = Integer.parseInt(data[10]); } rollbackusers = ConfigHandler.lookupUlist.get(player.getName()); @@ -601,7 +604,8 @@ public class LookupCommand { argAction = ConfigHandler.lookupAlist.get(player.getName()); argRadius = ConfigHandler.lookupRadius.get(player.getName()); ts = ConfigHandler.lookupTime.get(player.getName()); - rbseconds = 1; + startTime = 1; + endTime = 0; } else { if (lo != null) { @@ -658,15 +662,23 @@ public class LookupCommand { final List rollbackusers2 = rollbackusers; long unixtimestamp = (System.currentTimeMillis() / 1000L); - if (cs == -1) { - if (rbseconds <= 0) { - cs = 0; + if (timeStart == -1) { + if (startTime <= 0) { + timeStart = 0; } else { - cs = unixtimestamp - rbseconds; + timeStart = unixtimestamp - startTime; + } + if (endTime <= 0) { + timeEnd = 0; + } + else { + timeEnd = unixtimestamp - endTime; } } - final long stime = cs; + + final long finalTimeStart = timeStart; + final long finalTimeEnd = timeEnd; final Integer[] radius = argRadius; try { @@ -701,7 +713,7 @@ public class LookupCommand { List uuidList = new ArrayList<>(); Location location = finalLocation; boolean exists = false; - String bc = finalX + "." + finalY + "." + finalZ + "." + finalWid + "." + stime + "." + noisy + "." + excluded + "." + restricted + "." + finalArgWid + "." + displayResults; + String bc = finalX + "." + finalY + "." + finalZ + "." + finalWid + "." + finalTimeStart + "." + finalTimeEnd + "." + noisy + "." + excluded + "." + restricted + "." + finalArgWid + "." + displayResults; ConfigHandler.lookupCommand.put(player2.getName(), bc); ConfigHandler.lookupPage.put(player2.getName(), page); ConfigHandler.lookupTime.put(player2.getName(), rtime); @@ -788,7 +800,7 @@ public class LookupCommand { } if (checkRows) { - rows = Lookup.countLookupRows(statement, player2, uuidList, userList, blist, elist, euserlist, finalArgAction, location, radius, rowData, stime, restrict_world, true); + rows = Lookup.countLookupRows(statement, player2, uuidList, userList, blist, elist, euserlist, finalArgAction, location, radius, rowData, finalTimeStart, finalTimeEnd, restrict_world, true); rowData[3] = rows; ConfigHandler.lookupRows.put(player2.getName(), rowData); } @@ -797,7 +809,7 @@ public class LookupCommand { Chat.sendMessage(player2, Color.DARK_AQUA + "CoreProtect " + Color.WHITE + "- " + Phrase.build(Phrase.LOOKUP_ROWS_FOUND, row_format, (rows == 1 ? Selector.FIRST : Selector.SECOND))); } else if (pageStart < rows) { - List lookupList = Lookup.performPartialLookup(statement, player2, uuidList, userList, blist, elist, euserlist, finalArgAction, location, radius, rowData, stime, (int) pageStart, displayResults, restrict_world, true); + List lookupList = Lookup.performPartialLookup(statement, player2, uuidList, userList, blist, elist, euserlist, finalArgAction, location, radius, rowData, finalTimeStart, finalTimeEnd, (int) pageStart, displayResults, restrict_world, true); Chat.sendMessage(player2, Color.WHITE + "----- " + Color.DARK_AQUA + Phrase.build(Phrase.LOOKUP_HEADER, "CoreProtect" + Color.WHITE + " | " + Color.DARK_AQUA) + Color.WHITE + " -----"); if (finalArgAction.contains(6) || finalArgAction.contains(7)) { // Chat/command diff --git a/src/main/java/net/coreprotect/command/PurgeCommand.java b/src/main/java/net/coreprotect/command/PurgeCommand.java index 002f69e..59850c1 100755 --- a/src/main/java/net/coreprotect/command/PurgeCommand.java +++ b/src/main/java/net/coreprotect/command/PurgeCommand.java @@ -31,10 +31,12 @@ public class PurgeCommand extends Consumer { int resultc = args.length; Location location = CommandHandler.parseLocation(player, args); final Integer[] argRadius = CommandHandler.parseRadius(args, player, location); - final long seconds = CommandHandler.parseTime(args); + final long[] argTime = CommandHandler.parseTime(args); final int argWid = CommandHandler.parseWorld(args, false, false); final List argAction = CommandHandler.parseAction(args); final List supportedActions = Arrays.asList(); + long startTime = argTime[1] > 0 ? argTime[0] : 0; + long endTime = argTime[1] > 0 ? argTime[1] : argTime[0]; if (ConfigHandler.converterRunning) { Chat.sendMessage(player, Color.DARK_AQUA + "CoreProtect " + Color.WHITE + "- " + Phrase.build(Phrase.UPGRADE_IN_PROGRESS)); @@ -52,7 +54,7 @@ public class PurgeCommand extends Consumer { Chat.sendMessage(player, Color.DARK_AQUA + "CoreProtect " + Color.WHITE + "- " + Phrase.build(Phrase.MISSING_PARAMETERS, "/co purge t: