Skip to content

Commit c1d99e5

Browse files
committed
Improved fill progress saving & restoring
+ Added fill progress save to autosave, to avoid lost progress on hard-crashes + Prevented fill progress from being deleted except when properly finished or terminated. + In case fill progress is saved, but world is not loaded yet when config is loaded, running /wb reload should now resume filling if the world is loaded then. + Updated restoreprogress default values to match the current defaults.
1 parent 0d45093 commit c1d99e5

4 files changed

Lines changed: 31 additions & 19 deletions

File tree

src/main/java/com/wimbli/WorldBorder/Config.java

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -489,10 +489,10 @@ public static void StopBorderTimer(boolean logIt)
489489
logConfig("Border-checking timed task stopped.");
490490
}
491491

492-
public static void StopFillTask()
492+
public static void StopFillTask(boolean SaveFill)
493493
{
494494
if (fillTask != null && fillTask.valid())
495-
fillTask.cancel();
495+
fillTask.cancel(SaveFill);
496496
}
497497

498498
public static void StoreFillTask()
@@ -682,16 +682,15 @@ else if (cfgVersion < 8 && !(msg.substring(0, 1).equals("&")))
682682
if (storedFillTask != null)
683683
{
684684
String worldName = storedFillTask.getString("world");
685-
int fillDistance = storedFillTask.getInt("fillDistance", 176);
686-
int chunksPerRun = storedFillTask.getInt("chunksPerRun", 5);
687-
int tickFrequency = storedFillTask.getInt("tickFrequency", 20);
685+
int fillDistance = storedFillTask.getInt("fillDistance", 208);
686+
int chunksPerRun = storedFillTask.getInt("chunksPerRun", 1);
687+
int tickFrequency = storedFillTask.getInt("tickFrequency", 1);
688688
int fillX = storedFillTask.getInt("x", 0);
689689
int fillZ = storedFillTask.getInt("z", 0);
690690
int fillLength = storedFillTask.getInt("length", 0);
691691
int fillTotal = storedFillTask.getInt("total", 0);
692692
boolean forceLoad = storedFillTask.getBoolean("forceLoad", false);
693693
RestoreFillTask(worldName, fillDistance, chunksPerRun, tickFrequency, fillX, fillZ, fillLength, fillTotal, forceLoad);
694-
save(false);
695694
}
696695

697696
if (logIt)

src/main/java/com/wimbli/WorldBorder/WorldBorder.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ public void onDisable()
4848
DynMapFeatures.removeAllBorders();
4949
Config.StopBorderTimer();
5050
Config.StoreFillTask();
51-
Config.StopFillTask();
51+
Config.StopFillTask(true);
5252
}
5353

5454
// for other plugins to hook into

src/main/java/com/wimbli/WorldBorder/WorldFillTask.java

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -120,23 +120,24 @@ public WorldFillTask(Server theServer, Player player, String worldName, int fill
120120
sendMessage("You must specify a world!");
121121
else
122122
sendMessage("World \"" + worldName + "\" not found!");
123-
this.stop();
123+
//In case world is not loaded yet, do not delete saved progress
124+
this.stop(true);
124125
return;
125126
}
126127

127128
this.border = (Config.Border(worldName) == null) ? null : Config.Border(worldName).copy();
128129
if (this.border == null)
129130
{
130131
sendMessage("No border found for world \"" + worldName + "\"!");
131-
this.stop();
132+
this.stop(false);
132133
return;
133134
}
134135

135136
// load up a new WorldFileData for the world in question, used to scan region files for which chunks are already fully generated and such
136137
worldData = WorldFileData.create(world, notifyPlayer);
137138
if (worldData == null)
138139
{
139-
this.stop();
140+
this.stop(false);
140141
return;
141142
}
142143

@@ -169,7 +170,7 @@ public WorldFillTask(Server theServer, Player player, String worldName, int fill
169170

170171
public void setTaskID(int ID)
171172
{
172-
if (ID == -1) this.stop();
173+
if (ID == -1) this.stop(false);
173174
this.taskID = ID;
174175
}
175176

@@ -356,7 +357,9 @@ public boolean moveToNext()
356357
lastLegX = x;
357358
lastLegZ = z;
358359
lastLegTotal = reportTotal + reportNum;
359-
} else {
360+
}
361+
else
362+
{
360363
refX = lastLegX;
361364
refZ = lastLegZ;
362365
refTotal = lastLegTotal;
@@ -422,18 +425,22 @@ public void finish()
422425
world.save();
423426
Bukkit.getServer().getPluginManager().callEvent(new WorldBorderFillFinishedEvent(world, reportTotal));
424427
sendMessage("task successfully completed for world \"" + refWorld() + "\"!");
425-
this.stop();
428+
this.stop(false);
426429
}
427430

428431
// for cancelling prematurely
429-
public void cancel()
432+
public void cancel(boolean SaveFill)
430433
{
431-
this.stop();
434+
this.stop(SaveFill);
432435
}
433436

434437
// we're done, whether finished or cancelled
435-
private void stop()
438+
private void stop(boolean SaveFill)
436439
{
440+
//If being called by onDisable(), don't delete fill progress
441+
if (!SaveFill)
442+
Config.UnStoreFillTask();
443+
437444
if (server == null)
438445
return;
439446

@@ -482,8 +489,7 @@ public void pause(boolean pause)
482489
Config.StoreFillTask();
483490
reportProgress();
484491
}
485-
else
486-
Config.UnStoreFillTask();
492+
487493
}
488494
public boolean isPaused()
489495
{
@@ -524,6 +530,8 @@ private void reportProgress()
524530
lastAutosave = lastReport;
525531
sendMessage("Saving the world to disk, just to be on the safe side.");
526532
world.save();
533+
//In case of hard-crashes
534+
Config.StoreFillTask();
527535
}
528536
}
529537

@@ -559,6 +567,11 @@ public void continueProgress(int x, int z, int length, int totalDone)
559567
this.length = length;
560568
this.reportTotal = totalDone;
561569
this.continueNotice = true;
570+
//Prevents saving zeroes on first StoreFillTask after restoring
571+
this.refX = x;
572+
this.refZ = z;
573+
this.refLength = length;
574+
this.refTotal = totalDone;
562575
}
563576
public int refX()
564577
{

src/main/java/com/wimbli/WorldBorder/cmd/CmdFill.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public void execute(CommandSender sender, Player player, List<String> params, St
4141
return;
4242
sender.sendMessage(C_HEAD + "Cancelling the world map generation task.");
4343
fillDefaults();
44-
Config.StopFillTask();
44+
Config.StopFillTask(false);
4545
return;
4646
}
4747
else if (check.equals("pause"))

0 commit comments

Comments
 (0)