mirror of
https://github.com/mcMMO-Dev/mcMMO.git
synced 2024-11-24 14:16: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.player.UserManager;
|
||||||
import com.gmail.nossr50.util.scoreboards.ScoreboardManager.SidebarType;
|
import com.gmail.nossr50.util.scoreboards.ScoreboardManager.SidebarType;
|
||||||
import com.gmail.nossr50.util.skills.SkillTools;
|
import com.gmail.nossr50.util.skills.SkillTools;
|
||||||
|
import com.tcoded.folialib.wrapper.WrappedTask;
|
||||||
import org.apache.commons.lang.Validate;
|
import org.apache.commons.lang.Validate;
|
||||||
import org.bukkit.Bukkit;
|
|
||||||
import org.bukkit.ChatColor;
|
import org.bukkit.ChatColor;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.scheduler.BukkitRunnable;
|
|
||||||
import org.bukkit.scheduler.BukkitTask;
|
|
||||||
import org.bukkit.scoreboard.DisplaySlot;
|
import org.bukkit.scoreboard.DisplaySlot;
|
||||||
import org.bukkit.scoreboard.Objective;
|
import org.bukkit.scoreboard.Objective;
|
||||||
import org.bukkit.scoreboard.Score;
|
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 {
|
private class ScoreboardQuickUpdate {
|
||||||
@Override
|
public WrappedTask runTaskLater(long delay) {
|
||||||
public void run() {
|
return mcMMO.p.getFoliaLib().getImpl().runLater(() -> {
|
||||||
updateSidebar();
|
updateSidebar();
|
||||||
updateTask = null;
|
updateTask = null;
|
||||||
|
}, delay * Misc.TICK_CONVERSION_FACTOR, TimeUnit.MILLISECONDS);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public BukkitTask revertTask = null;
|
public WrappedTask revertTask = null;
|
||||||
|
|
||||||
private class ScoreboardChangeTask extends BukkitRunnable {
|
private class ScoreboardChangeTask {
|
||||||
@Override
|
public WrappedTask runTaskLater(long delay) {
|
||||||
public void run() {
|
return mcMMO.p.getFoliaLib().getImpl().runLater(() -> {
|
||||||
tryRevertBoard();
|
tryRevertBoard();
|
||||||
revertTask = null;
|
revertTask = null;
|
||||||
|
}, delay * Misc.TICK_CONVERSION_FACTOR, TimeUnit.MILLISECONDS);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public BukkitTask cooldownTask = null;
|
public WrappedTask cooldownTask = null;
|
||||||
|
|
||||||
private class ScoreboardCooldownTask extends BukkitRunnable {
|
private class ScoreboardCooldownTask {
|
||||||
@Override
|
public WrappedTask runTaskTimer(long delay, long period) {
|
||||||
public void run() {
|
return mcMMO.p.getFoliaLib().getImpl().runTimer(() -> {
|
||||||
// Stop updating if it's no longer something displaying cooldowns
|
// Stop updating if it's no longer something displaying cooldowns
|
||||||
if (isBoardShown() && (isSkillScoreboard() || isCooldownScoreboard())) {
|
if (isBoardShown() && (isSkillScoreboard() || isCooldownScoreboard())) {
|
||||||
doSidebarUpdateSoon();
|
doSidebarUpdateSoon();
|
||||||
}
|
} else {
|
||||||
else {
|
stopCooldownUpdating();
|
||||||
stopCooldownUpdating();
|
}
|
||||||
}
|
}, delay, period, TimeUnit.MILLISECONDS);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -126,7 +126,7 @@ public class ScoreboardWrapper {
|
|||||||
public void doSidebarUpdateSoon() {
|
public void doSidebarUpdateSoon() {
|
||||||
if (updateTask == null) {
|
if (updateTask == null) {
|
||||||
// To avoid spamming the scheduler, store the instance and run 2 ticks later
|
// 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) {
|
if (cooldownTask == null) {
|
||||||
// Repeat every 5 seconds.
|
// Repeat every 5 seconds.
|
||||||
// Cancels once all cooldowns are done, using stopCooldownUpdating().
|
// 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);
|
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?
|
// 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));
|
// player.sendMessage(LocaleLoader.getString("Commands.Scoreboard.Timer", StringUtils.capitalize(sidebarType.toString().toLowerCase(Locale.ENGLISH)), ticks / 20F));
|
||||||
|
Loading…
Reference in New Issue
Block a user