diff --git a/src/main/java/net/william278/velocitab/config/Settings.java b/src/main/java/net/william278/velocitab/config/Settings.java index 5db6659..eb259c0 100644 --- a/src/main/java/net/william278/velocitab/config/Settings.java +++ b/src/main/java/net/william278/velocitab/config/Settings.java @@ -24,6 +24,8 @@ public class Settings { private String format = "&7[%server%] &f%prefix%%username%"; @YamlKey("excluded_servers") private ArrayList excludedServers = new ArrayList<>(); + @YamlKey(("update_rate")) + private int updateRate = 0; private Settings() { } @@ -47,4 +49,7 @@ public class Settings { return excludedServers.contains(serverName); } + public int getUpdateRate() { + return updateRate; + } } diff --git a/src/main/java/net/william278/velocitab/luckperms/LuckPermsHook.java b/src/main/java/net/william278/velocitab/luckperms/LuckPermsHook.java index ebbfbba..bb32936 100644 --- a/src/main/java/net/william278/velocitab/luckperms/LuckPermsHook.java +++ b/src/main/java/net/william278/velocitab/luckperms/LuckPermsHook.java @@ -48,7 +48,7 @@ public class LuckPermsHook { public void onLuckPermsGroupUpdate(@NotNull UserDataRecalculateEvent event) { plugin.getServer().getPlayer(event.getUser().getUniqueId()) - .ifPresent(player -> plugin.getTabList().onPlayerRoleUpdate(new TabPlayer( + .ifPresent(player -> plugin.getTabList().onUpdate(new TabPlayer( player, getRoleFromMetadata(event.getData().getMetaData()), getHighestWeight() diff --git a/src/main/java/net/william278/velocitab/tab/PlayerTabList.java b/src/main/java/net/william278/velocitab/tab/PlayerTabList.java index 49f6d43..b820188 100644 --- a/src/main/java/net/william278/velocitab/tab/PlayerTabList.java +++ b/src/main/java/net/william278/velocitab/tab/PlayerTabList.java @@ -27,6 +27,11 @@ public class PlayerTabList { public PlayerTabList(@NotNull Velocitab plugin) { this.plugin = plugin; this.players = new ConcurrentLinkedQueue<>(); + + // If the update time is set to 0 do not schedule the updater + if (plugin.getSettings().getUpdateRate() > 0) { + updateTimer(plugin.getSettings().getUpdateRate()); + } } @SuppressWarnings("UnstableApiUsage") @@ -122,7 +127,7 @@ public class PlayerTabList { .schedule(); } - public void onPlayerRoleUpdate(@NotNull TabPlayer tabPlayer) { + public void onUpdate(@NotNull TabPlayer tabPlayer) { plugin.getServer().getScheduler() .buildTask(plugin, () -> players.forEach(player -> { player.getPlayer().getTabList().getEntries().stream() @@ -145,4 +150,14 @@ public class PlayerTabList { return new MineDown(Placeholder.format(plugin.getSettings().getFooter(), plugin, player)).toComponent(); } + private void updateTimer(int updateRate) { + plugin.getServer().getScheduler() + .buildTask(plugin, () -> { + if (!players.isEmpty()){ + players.forEach(this::onUpdate); + } + }) + .repeat(updateRate, TimeUnit.MILLISECONDS) + .schedule(); + } }