Fix LuckPerms role update not updating actual user in TAB list

This commit is contained in:
William 2023-03-16 21:11:53 +00:00
parent 8a4651fb5f
commit 6007cdddb3
No known key found for this signature in database
2 changed files with 20 additions and 8 deletions

View File

@ -10,6 +10,7 @@ import net.luckperms.api.model.user.User;
import net.william278.velocitab.Velocitab;
import net.william278.velocitab.player.Role;
import net.william278.velocitab.player.TabPlayer;
import net.william278.velocitab.tab.PlayerTabList;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@ -47,14 +48,18 @@ public class LuckPermsHook extends Hook {
}
public void onLuckPermsGroupUpdate(@NotNull UserDataRecalculateEvent event) {
final PlayerTabList tabList = plugin.getTabList();
plugin.getServer().getPlayer(event.getUser().getUniqueId())
.ifPresent(player -> plugin.getServer().getScheduler()
.buildTask(plugin, () -> plugin.getTabList()
.onUpdate(new TabPlayer(
player,
getRoleFromMetadata(event.getData().getMetaData()),
getHighestWeight()
)))
.buildTask(plugin, () -> {
final TabPlayer updatedPlayer = new TabPlayer(
player,
getRoleFromMetadata(event.getData().getMetaData()),
getHighestWeight()
);
tabList.replacePlayer(updatedPlayer);
tabList.updatePlayer(updatedPlayer);
})
.delay(500, TimeUnit.MILLISECONDS)
.schedule());
}

View File

@ -141,7 +141,14 @@ public class PlayerTabList {
.schedule();
}
public void onUpdate(@NotNull TabPlayer tabPlayer) {
// Replace a player in the tab list
public void replacePlayer(@NotNull TabPlayer tabPlayer) {
players.removeIf(player -> player.getPlayer().getUniqueId().equals(tabPlayer.getPlayer().getUniqueId()));
players.add(tabPlayer);
}
// Update a player's name in the tab list
public void updatePlayer(@NotNull TabPlayer tabPlayer) {
players.forEach(player -> tabPlayer.getDisplayName(plugin).thenAccept(displayName -> {
player.getPlayer().getTabList().getEntries().stream()
.filter(e -> e.getProfile().getId().equals(tabPlayer.getPlayer().getUniqueId())).findFirst()
@ -173,7 +180,7 @@ public class PlayerTabList {
return;
}
players.forEach(player -> {
this.onUpdate(player);
this.updatePlayer(player);
player.sendHeaderAndFooter(this);
});
})