Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -60,4 +60,13 @@
</plugins>
</build>


<dependencies>
<dependency>
<groupId>org.spigotmc</groupId>
<artifactId>spigot-api</artifactId>
<version>1.8.8-R0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
</dependencies>
</project>
15 changes: 15 additions & 0 deletions src/main/java/me/tigerhix/lib/scoreboard/type/Scoreboard.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);

}
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ public class SimpleScoreboard implements Scoreboard {
private Table<String, Integer, FakePlayer> playerCache = HashBasedTable.create();
private Table<Team, String, String> teamCache = HashBasedTable.create();
private BukkitRunnable updateTask;
private boolean async = false;

public SimpleScoreboard(Player holder) {
this.holder = holder;
Expand All @@ -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);
}

Expand Down Expand Up @@ -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()) {
Expand Down