From 895bec706126e59f63af2745838528c6f2d5776b Mon Sep 17 00:00:00 2001 From: Maxim Van de Wynckel Date: Fri, 15 Jan 2016 12:38:17 +0100 Subject: [PATCH] public percentage methods for fill and trim task Provides public methods to get the percentage for the fill and trim task. These can be used by 3rd party plugins to get the calculated percentage or get the values of the processed/total amount of chunks. Possible usages I have in mind: - Boss bar showing a progress of the fill task - Action bar showing the status - ... --- .../com/wimbli/WorldBorder/WorldFillTask.java | 29 ++++++++++++++++++- .../com/wimbli/WorldBorder/WorldTrimTask.java | 29 ++++++++++++++++++- 2 files changed, 56 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/wimbli/WorldBorder/WorldFillTask.java b/src/main/java/com/wimbli/WorldBorder/WorldFillTask.java index 6bb3993..6e48066 100644 --- a/src/main/java/com/wimbli/WorldBorder/WorldFillTask.java +++ b/src/main/java/com/wimbli/WorldBorder/WorldFillTask.java @@ -385,7 +385,7 @@ public class WorldFillTask implements Runnable private void reportProgress() { lastReport = Config.Now(); - double perc = ((double)(reportTotal + reportNum) / (double)reportTarget) * 100; + double perc = getPercentageCompleted(); if (perc > 100) perc = 100; sendMessage(reportNum + " more chunks processed (" + (reportTotal + reportNum) + " total, ~" + Config.coord.format(perc) + "%" + ")"); reportTotal += reportNum; @@ -469,4 +469,31 @@ public class WorldFillTask implements Runnable { return forceLoad; } + + /** + * Get the percentage completed for the fill task. + * + * @return Percentage + */ + public double getPercentageCompleted() { + return ((double) (reportTotal + reportNum) / (double) reportTarget) * 100; + } + + /** + * Amount of chunks completed for the fill task. + * + * @return Number of chunks processed. + */ + public int getChunksCompleted() { + return reportTotal; + } + + /** + * Total amount of chunks that need to be generated for the fill task. + * + * @return Number of chunks that need to be processed. + */ + public int getChunksTotal() { + return reportTarget; + } } diff --git a/src/main/java/com/wimbli/WorldBorder/WorldTrimTask.java b/src/main/java/com/wimbli/WorldBorder/WorldTrimTask.java index 91d69cf..6be491e 100644 --- a/src/main/java/com/wimbli/WorldBorder/WorldTrimTask.java +++ b/src/main/java/com/wimbli/WorldBorder/WorldTrimTask.java @@ -391,7 +391,7 @@ public class WorldTrimTask implements Runnable private void reportProgress() { lastReport = Config.Now(); - double perc = ((double)(reportTotal) / (double)reportTarget) * 100; + double perc = getPercentageCompleted(); sendMessage(reportTrimmedRegions + " entire region(s) and " + reportTrimmedChunks + " individual chunk(s) trimmed so far (" + Config.coord.format(perc) + "% done" + ")"); } @@ -402,4 +402,31 @@ public class WorldTrimTask implements Runnable if (notifyPlayer != null) notifyPlayer.sendMessage("[Trim] " + text); } + + /** + * Get the percentage completed for the trim task. + * + * @return Percentage + */ + public double getPercentageCompleted() { + return ((double) (reportTotal) / (double) reportTarget) * 100; + } + + /** + * Amount of chunks completed for the trim task. + * + * @return Number of chunks processed. + */ + public int getChunksCompleted() { + return reportTotal; + } + + /** + * Total amount of chunks that need to be trimmed for the trim task. + * + * @return Number of chunks that need to be processed. + */ + public int getChunksTotal() { + return reportTarget; + } }