From d564186e6f287d291de0cf1983e803d243a91418 Mon Sep 17 00:00:00 2001 From: LoRy24 <51451299+LoRy24@users.noreply.github.com> Date: Tue, 15 Nov 2022 16:17:50 +0100 Subject: [PATCH 1/2] Add spigot dependency --- pom.xml | 9 +++++++++ 1 file changed, 9 insertions(+) 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 + + From e5ba9e1736848fd48ac812a1d5674976cc2c68f4 Mon Sep 17 00:00:00 2001 From: LoRy24 <51451299+LoRy24@users.noreply.github.com> Date: Tue, 15 Nov 2022 16:18:44 +0100 Subject: [PATCH 2/2] Implement async update feature --- .../lib/scoreboard/type/Scoreboard.java | 15 ++++++++++ .../lib/scoreboard/type/SimpleScoreboard.java | 29 +++++++++++++++++++ 2 files changed, 44 insertions(+) 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()) {