diff --git a/src/main/java/net/william278/velocitab/hook/LuckPermsHook.java b/src/main/java/net/william278/velocitab/hook/LuckPermsHook.java index 4b2d554f..a418c447 100644 --- a/src/main/java/net/william278/velocitab/hook/LuckPermsHook.java +++ b/src/main/java/net/william278/velocitab/hook/LuckPermsHook.java @@ -45,6 +45,7 @@ public class LuckPermsHook extends Hook { private final LuckPerms api; private final EventSubscription event; private final Map lastUpdate; + private boolean enabled; public LuckPermsHook(@NotNull Velocitab plugin) throws IllegalStateException { super(plugin); @@ -53,10 +54,12 @@ public LuckPermsHook(@NotNull Velocitab plugin) throws IllegalStateException { this.event = api.getEventBus().subscribe( plugin, UserDataRecalculateEvent.class, this::onLuckPermsGroupUpdate ); + this.enabled = true; } public void closeEvent() { event.close(); + this.enabled = false; } @NotNull @@ -92,6 +95,10 @@ public void onLuckPermsGroupUpdate(@NotNull UserDataRecalculateEvent event) { } lastUpdate.put(event.getUser().getUniqueId(), System.currentTimeMillis()); + if (!enabled) { + return; + } + final PlayerTabList tabList = plugin.getTabList(); plugin.getServer().getPlayer(event.getUser().getUniqueId()) .ifPresent(player -> plugin.getServer().getScheduler() @@ -103,7 +110,12 @@ public void onLuckPermsGroupUpdate(@NotNull UserDataRecalculateEvent event) { final TabPlayer tabPlayer = tabPlayerOptional.get(); final Role oldRole = tabPlayer.getRole(); - tabPlayer.setRole(getRoleFromMetadata(event.getData().getMetaData())); + final Role newRole = getRoleFromMetadata(event.getUser().getCachedData().getMetaData()); + if (oldRole.equals(newRole)) { + return; + } + + tabPlayer.setRole(newRole); tabList.updatePlayerDisplayName(tabPlayer); tabList.getVanishTabList().recalculateVanishForPlayer(tabPlayer); checkRoleUpdate(tabPlayer, oldRole); diff --git a/src/main/java/net/william278/velocitab/packet/PlayerChannelHandler.java b/src/main/java/net/william278/velocitab/packet/PlayerChannelHandler.java index a542377a..28f7af66 100644 --- a/src/main/java/net/william278/velocitab/packet/PlayerChannelHandler.java +++ b/src/main/java/net/william278/velocitab/packet/PlayerChannelHandler.java @@ -26,9 +26,11 @@ import io.netty.channel.ChannelPromise; import lombok.RequiredArgsConstructor; import net.william278.velocitab.Velocitab; +import net.william278.velocitab.player.TabPlayer; import org.jetbrains.annotations.NotNull; import java.util.List; +import java.util.Optional; @RequiredArgsConstructor @@ -44,6 +46,11 @@ public void write(ChannelHandlerContext ctx, Object msg, ChannelPromise promise) return; } + final Optional tabPlayer = plugin.getTabList().getTabPlayer(player); + if (tabPlayer.isEmpty()) { + super.write(ctx, msg, promise); + return; + } if (plugin.getSettings().isRemoveSpectatorEffect() && minecraftPacket.containsAction(UpsertPlayerInfoPacket.Action.UPDATE_GAME_MODE)) { forceGameMode(minecraftPacket.getEntries()); diff --git a/src/main/java/net/william278/velocitab/packet/ScoreboardManager.java b/src/main/java/net/william278/velocitab/packet/ScoreboardManager.java index 0d1ac4a8..c62ce2e8 100644 --- a/src/main/java/net/william278/velocitab/packet/ScoreboardManager.java +++ b/src/main/java/net/william278/velocitab/packet/ScoreboardManager.java @@ -82,8 +82,9 @@ public void close() { public void resetCache(@NotNull Player player) { final String team = createdTeams.remove(player.getUniqueId()); if (team != null) { - final TabPlayer tabPlayer = plugin.getTabList().getTabPlayer(player).orElseThrow(); - dispatchGroupPacket(UpdateTeamsPacket.removeTeam(plugin, team), tabPlayer); + plugin.getTabList().getTabPlayer(player).ifPresent(tabPlayer -> + dispatchGroupPacket(UpdateTeamsPacket.removeTeam(plugin, team), tabPlayer) + ); } } diff --git a/src/main/java/net/william278/velocitab/player/Role.java b/src/main/java/net/william278/velocitab/player/Role.java index 9cb8ddde..d62c539e 100644 --- a/src/main/java/net/william278/velocitab/player/Role.java +++ b/src/main/java/net/william278/velocitab/player/Role.java @@ -20,12 +20,16 @@ package net.william278.velocitab.player; import lombok.Getter; +import lombok.RequiredArgsConstructor; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; +import java.util.Objects; import java.util.Optional; +@RequiredArgsConstructor public class Role implements Comparable { + public static final int DEFAULT_WEIGHT = 0; public static final Role DEFAULT_ROLE = new Role(DEFAULT_WEIGHT, null, null, null, null); @Getter @@ -39,14 +43,6 @@ public class Role implements Comparable { @Nullable private final String suffix; - public Role(int weight, @Nullable String name, @Nullable String displayName, @Nullable String prefix, @Nullable String suffix) { - this.weight = weight; - this.name = name; - this.displayName = displayName; - this.prefix = prefix; - this.suffix = suffix; - } - @Override public int compareTo(@NotNull Role o) { return Double.compare(weight, o.weight); @@ -73,4 +69,15 @@ protected String getWeightString() { return Integer.toString(weight); } + @Override + public boolean equals(Object obj) { + if (this == obj) return true; + if (obj == null || getClass() != obj.getClass()) return false; + final Role role = (Role) obj; + return weight == role.weight && + Objects.equals(name, role.name) && + Objects.equals(displayName, role.displayName) && + Objects.equals(prefix, role.prefix) && + Objects.equals(suffix, role.suffix); + } } diff --git a/src/main/java/net/william278/velocitab/tab/PlayerTabList.java b/src/main/java/net/william278/velocitab/tab/PlayerTabList.java index c353f26e..054928c3 100644 --- a/src/main/java/net/william278/velocitab/tab/PlayerTabList.java +++ b/src/main/java/net/william278/velocitab/tab/PlayerTabList.java @@ -19,6 +19,7 @@ package net.william278.velocitab.tab; +import com.google.common.collect.Lists; import com.google.common.collect.Maps; import com.velocitypowered.api.proxy.Player; import com.velocitypowered.api.proxy.ServerConnection; @@ -128,7 +129,7 @@ public void close() { return; } - final List serversInGroup = new ArrayList<>(tabPlayer.getGroup().registeredServers(plugin)); + final List serversInGroup = Lists.newArrayList(tabPlayer.getGroup().registeredServers(plugin)); if (serversInGroup.isEmpty()) { return; } diff --git a/src/main/java/net/william278/velocitab/tab/TabListListener.java b/src/main/java/net/william278/velocitab/tab/TabListListener.java index 5b195769..b5ec226b 100644 --- a/src/main/java/net/william278/velocitab/tab/TabListListener.java +++ b/src/main/java/net/william278/velocitab/tab/TabListListener.java @@ -77,11 +77,16 @@ public void onPlayerJoin(@NotNull ServerPostConnectEvent event) { // If the server is not in a group, use fallback. // If fallback is disabled, permit the player to switch excluded servers without a header or footer override - if (isDefault && !plugin.getSettings().isFallbackEnabled() && event.getPreviousServer() != null) { + if (isDefault && !plugin.getSettings().isFallbackEnabled()) { final Optional tabPlayer = tabList.getTabPlayer(joined); if (tabPlayer.isEmpty()) { return; } + + if (event.getPreviousServer() == null) { + return; + } + final Component header = tabPlayer.get().getLastHeader(); final Component footer = tabPlayer.get().getLastFooter(); final Component displayName = tabPlayer.get().getLastDisplayName();