Skip to content

Commit b9f3257

Browse files
committed
Code improvements - better parsing
1 parent c735103 commit b9f3257

File tree

1 file changed

+17
-40
lines changed

1 file changed

+17
-40
lines changed

src/main/java/world/bentobox/bentobox/api/commands/admin/purge/AdminPurgeRegionsCommand.java

Lines changed: 17 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@
3636

3737
public class AdminPurgeRegionsCommand extends CompositeCommand implements Listener {
3838

39-
private int count;
4039
private volatile boolean inPurge;
4140
private boolean toBeConfirmed;
4241
private User user;
@@ -86,11 +85,18 @@ public boolean execute(User user, String label, List<String> args) {
8685
// Clear tbc
8786
toBeConfirmed = false;
8887

89-
days = Integer.parseInt(args.get(0));
90-
if (days < 1) {
88+
try {
89+
days = Integer.parseInt(args.get(0));
90+
if (days <= 0) {
91+
user.sendMessage("commands.admin.purge.days-one-or-more");
92+
return false;
93+
}
94+
95+
} catch (NumberFormatException e) {
9196
user.sendMessage("commands.admin.purge.days-one-or-more");
9297
return false;
9398
}
99+
94100
user.sendMessage("commands.admin.purge.scanning");
95101
// Save all worlds to update any region files
96102
Bukkit.getWorlds().forEach(World::save);
@@ -100,6 +106,7 @@ public boolean execute(User user, String label, List<String> args) {
100106
return true;
101107
}
102108

109+
103110
private boolean deleteEverything() {
104111
if (deleteableRegions.isEmpty()) {
105112
user.sendMessage("commands.admin.purge.none-found"); // Should never happen
@@ -146,7 +153,7 @@ private boolean deleteEverything() {
146153
* @return {@code true} if deletion was performed; {@code false} if cancelled
147154
* due to any file being newer than the cutoff
148155
*/
149-
public boolean deleteRegionFiles() {
156+
private boolean deleteRegionFiles() {
150157
if (days <= 0) {
151158
getPlugin().logError("Days is somehow zero or negative!");
152159
return false;
@@ -292,22 +299,22 @@ private void displayIsland(Island island) {
292299
+ " who last logged in " + formatLocalTimestamp(getPlugin().getPlayers().getLastLoginTimestamp(island.getOwner()))
293300
+ " will be deleted");
294301
}
295-
302+
296303
/**
297304
* Formats a millisecond timestamp into a human-readable string
298305
* using the system's local time zone.
299306
*
300307
* @param millis the timestamp in milliseconds
301308
* @return formatted string in the form "yyyy-MM-dd HH:mm"
302309
*/
303-
public String formatLocalTimestamp(Long millis) {
310+
private String formatLocalTimestamp(Long millis) {
304311
if (millis == null) {
305312
return "(unknown or never recorded)";
306313
}
307314
Instant instant = Instant.ofEpochMilli(millis);
308315

309316
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm")
310-
.withZone(ZoneId.systemDefault()); // Uses the machine's local time zone
317+
.withZone(ZoneId.systemDefault()); // Uses the machine's local time zone
311318

312319
return formatter.format(instant);
313320
}
@@ -350,7 +357,7 @@ private boolean canDeleteIsland(Island island) {
350357
* @return a list of {@code Pair<regionX, regionZ>} for each region meeting
351358
* the age criteria
352359
*/
353-
public List<Pair<Integer, Integer>> findOldRegions(int days) {
360+
private List<Pair<Integer, Integer>> findOldRegions(int days) {
354361
List<Pair<Integer, Integer>> regions = new ArrayList<>();
355362

356363
// Base folders
@@ -429,7 +436,7 @@ public List<Pair<Integer, Integer>> findOldRegions(int days) {
429436
* @param grid a 2D TreeMap mapping centreX → (centreZ → IslandData)
430437
* @return a map from region coords to the set of overlapping island IDs
431438
*/
432-
public Map<Pair<Integer, Integer>, Set<String>> mapIslandsToRegions(
439+
private Map<Pair<Integer, Integer>, Set<String>> mapIslandsToRegions(
433440
List<Pair<Integer, Integer>> oldRegions,
434441
TreeMap<Integer, TreeMap<Integer, IslandData>> grid
435442
) {
@@ -475,36 +482,6 @@ public Map<Pair<Integer, Integer>, Set<String>> mapIslandsToRegions(
475482
return regionToIslands;
476483
}
477484

478-
/**
479-
* @return the inPurge
480-
*/
481-
boolean isInPurge() {
482-
return inPurge;
483-
}
484-
485-
/**
486-
* Stop the purge
487-
*/
488-
void stop() {
489-
inPurge = false;
490-
}
491-
492-
/**
493-
* @param user the user to set
494-
*/
495-
void setUser(User user) {
496-
this.user = user;
497-
}
498-
499-
/**
500-
* Returns the amount of purged islands.
501-
* @return the amount of islands that have been purged.
502-
* @since 1.13.0
503-
*/
504-
int getPurgedIslandsCount() {
505-
return this.count;
506-
}
507-
508485
/**
509486
* Reads a Minecraft region file (.mca) and returns the most recent
510487
* per-chunk timestamp found in its header, in milliseconds since epoch.
@@ -513,7 +490,7 @@ int getPurgedIslandsCount() {
513490
* @return the most recent timestamp (in millis) among all chunk entries,
514491
* or 0 if the file is invalid or empty
515492
*/
516-
public long getRegionTimestamp(File regionFile) {
493+
private long getRegionTimestamp(File regionFile) {
517494
if (!regionFile.exists() || regionFile.length() < 8192) {
518495
return 0L;
519496
}

0 commit comments

Comments
 (0)