mirror of
https://github.com/mcMMO-Dev/mcMMO.git
synced 2024-11-24 06:06:45 +01:00
Replace Bukkit schedulers in ScoreboardWrapper.java
This commit is contained in:
parent
dc8a9102fe
commit
0603faff33
@ -18,12 +18,10 @@ import com.gmail.nossr50.util.player.NotificationManager;
|
||||
import com.gmail.nossr50.util.player.UserManager;
|
||||
import com.gmail.nossr50.util.scoreboards.ScoreboardManager.SidebarType;
|
||||
import com.gmail.nossr50.util.skills.SkillTools;
|
||||
import com.tcoded.folialib.wrapper.WrappedTask;
|
||||
import org.apache.commons.lang.Validate;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
import org.bukkit.scheduler.BukkitTask;
|
||||
import org.bukkit.scoreboard.DisplaySlot;
|
||||
import org.bukkit.scoreboard.Objective;
|
||||
import org.bukkit.scoreboard.Score;
|
||||
@ -87,38 +85,40 @@ public class ScoreboardWrapper {
|
||||
}
|
||||
}
|
||||
|
||||
public BukkitTask updateTask = null;
|
||||
public WrappedTask updateTask = null;
|
||||
|
||||
private class ScoreboardQuickUpdate extends BukkitRunnable {
|
||||
@Override
|
||||
public void run() {
|
||||
updateSidebar();
|
||||
updateTask = null;
|
||||
private class ScoreboardQuickUpdate {
|
||||
public WrappedTask runTaskLater(long delay) {
|
||||
return mcMMO.p.getFoliaLib().getImpl().runLater(() -> {
|
||||
updateSidebar();
|
||||
updateTask = null;
|
||||
}, delay * Misc.TICK_CONVERSION_FACTOR, TimeUnit.MILLISECONDS);
|
||||
}
|
||||
}
|
||||
|
||||
public BukkitTask revertTask = null;
|
||||
public WrappedTask revertTask = null;
|
||||
|
||||
private class ScoreboardChangeTask extends BukkitRunnable {
|
||||
@Override
|
||||
public void run() {
|
||||
tryRevertBoard();
|
||||
revertTask = null;
|
||||
private class ScoreboardChangeTask {
|
||||
public WrappedTask runTaskLater(long delay) {
|
||||
return mcMMO.p.getFoliaLib().getImpl().runLater(() -> {
|
||||
tryRevertBoard();
|
||||
revertTask = null;
|
||||
}, delay * Misc.TICK_CONVERSION_FACTOR, TimeUnit.MILLISECONDS);
|
||||
}
|
||||
}
|
||||
|
||||
public BukkitTask cooldownTask = null;
|
||||
public WrappedTask cooldownTask = null;
|
||||
|
||||
private class ScoreboardCooldownTask extends BukkitRunnable {
|
||||
@Override
|
||||
public void run() {
|
||||
// Stop updating if it's no longer something displaying cooldowns
|
||||
if (isBoardShown() && (isSkillScoreboard() || isCooldownScoreboard())) {
|
||||
doSidebarUpdateSoon();
|
||||
}
|
||||
else {
|
||||
stopCooldownUpdating();
|
||||
}
|
||||
private class ScoreboardCooldownTask {
|
||||
public WrappedTask runTaskTimer(long delay, long period) {
|
||||
return mcMMO.p.getFoliaLib().getImpl().runTimer(() -> {
|
||||
// Stop updating if it's no longer something displaying cooldowns
|
||||
if (isBoardShown() && (isSkillScoreboard() || isCooldownScoreboard())) {
|
||||
doSidebarUpdateSoon();
|
||||
} else {
|
||||
stopCooldownUpdating();
|
||||
}
|
||||
}, delay, period, TimeUnit.MILLISECONDS);
|
||||
}
|
||||
}
|
||||
|
||||
@ -126,7 +126,7 @@ public class ScoreboardWrapper {
|
||||
public void doSidebarUpdateSoon() {
|
||||
if (updateTask == null) {
|
||||
// To avoid spamming the scheduler, store the instance and run 2 ticks later
|
||||
updateTask = new ScoreboardQuickUpdate().runTaskLater(mcMMO.p, 2L);
|
||||
updateTask = new ScoreboardQuickUpdate().runTaskLater(2L);
|
||||
}
|
||||
}
|
||||
|
||||
@ -134,7 +134,7 @@ public class ScoreboardWrapper {
|
||||
if (cooldownTask == null) {
|
||||
// Repeat every 5 seconds.
|
||||
// Cancels once all cooldowns are done, using stopCooldownUpdating().
|
||||
cooldownTask = new ScoreboardCooldownTask().runTaskTimer(mcMMO.p, 5 * Misc.TICK_CONVERSION_FACTOR, 5 * Misc.TICK_CONVERSION_FACTOR);
|
||||
cooldownTask = new ScoreboardCooldownTask().runTaskTimer(5 * Misc.TICK_CONVERSION_FACTOR, 5 * Misc.TICK_CONVERSION_FACTOR);
|
||||
}
|
||||
}
|
||||
|
||||
@ -217,7 +217,7 @@ public class ScoreboardWrapper {
|
||||
}
|
||||
|
||||
player.setScoreboard(scoreboard);
|
||||
revertTask = new ScoreboardChangeTask().runTaskLater(mcMMO.p, ticks);
|
||||
revertTask = new ScoreboardChangeTask().runTaskLater(ticks);
|
||||
|
||||
// TODO is there any way to do the time that looks acceptable?
|
||||
// player.sendMessage(LocaleLoader.getString("Commands.Scoreboard.Timer", StringUtils.capitalize(sidebarType.toString().toLowerCase(Locale.ENGLISH)), ticks / 20F));
|
||||
|
Loading…
Reference in New Issue
Block a user