diff --git a/pom.xml b/pom.xml index 295a251..8f9bcbb 100644 --- a/pom.xml +++ b/pom.xml @@ -60,4 +60,13 @@ + + + + org.spigotmc + spigot-api + 1.8.8-R0.1-SNAPSHOT + provided + + diff --git a/src/main/java/me/tigerhix/lib/scoreboard/type/Scoreboard.java b/src/main/java/me/tigerhix/lib/scoreboard/type/Scoreboard.java index afdc7e8..39a979f 100644 --- a/src/main/java/me/tigerhix/lib/scoreboard/type/Scoreboard.java +++ b/src/main/java/me/tigerhix/lib/scoreboard/type/Scoreboard.java @@ -62,4 +62,19 @@ public interface Scoreboard { */ Player getHolder(); + /** + * Check if the scoreboard update task is async + * + * @return If the task should be async + */ + boolean isAsync(); + + /** + * Update the async option + * + * @param value If the async option is enabled + * @return The updated value + */ + Scoreboard setAsync(boolean value); + } diff --git a/src/main/java/me/tigerhix/lib/scoreboard/type/SimpleScoreboard.java b/src/main/java/me/tigerhix/lib/scoreboard/type/SimpleScoreboard.java index b864c1b..f5c8e14 100755 --- a/src/main/java/me/tigerhix/lib/scoreboard/type/SimpleScoreboard.java +++ b/src/main/java/me/tigerhix/lib/scoreboard/type/SimpleScoreboard.java @@ -37,6 +37,7 @@ public class SimpleScoreboard implements Scoreboard { private Table playerCache = HashBasedTable.create(); private Table teamCache = HashBasedTable.create(); private BukkitRunnable updateTask; + private boolean async = false; public SimpleScoreboard(Player holder) { this.holder = holder; @@ -60,6 +61,12 @@ public void run() { update(); } }; + // Check if the task should be run asynchronously + if (this.async) { + updateTask.runTaskTimerAsynchronously(ScoreboardLib.getPluginInstance(), 0, updateInterval); + return; + } + // Otherwise, run it normally updateTask.runTaskTimer(ScoreboardLib.getPluginInstance(), 0, updateInterval); } @@ -114,6 +121,28 @@ public Player getHolder() { return holder; } + /** + * Check if the scoreboard update task is async + * + * @return If the task should be async + */ + @Override + public boolean isAsync() { + return this.async; + } + + /** + * Update the async option + * + * @param value If the async option is enabled + * @return The updated value + */ + @Override + public Scoreboard setAsync(boolean value) { + this.async = value; + return this; + } + @SuppressWarnings("deprecation") private void update() { if (!holder.isOnline()) {