forked from Upstream/Velocitab
Add function to exclude servers
This commit is contained in:
parent
a968fc32fc
commit
a50837dcb4
@ -6,6 +6,8 @@ import net.william278.velocitab.BuildConstants;
|
||||
import org.apache.commons.text.StringEscapeUtils;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
@YamlFile(header = """
|
||||
┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
|
||||
┃ Velocitab Config ┃
|
||||
@ -20,6 +22,8 @@ public class Settings {
|
||||
private String footer = "[There are currently %players_online%/%max_players_online% players online](gray)";
|
||||
@YamlKey("format")
|
||||
private String format = "&7[%server%] &f%prefix%%username%";
|
||||
@YamlKey("excluded_servers")
|
||||
private ArrayList<String> excludedServers = new ArrayList<>();
|
||||
|
||||
private Settings() {
|
||||
}
|
||||
@ -39,4 +43,8 @@ public class Settings {
|
||||
return StringEscapeUtils.unescapeJava(format);
|
||||
}
|
||||
|
||||
public boolean isServerExcluded(@NotNull String serverName) {
|
||||
return excludedServers.contains(serverName);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -4,6 +4,9 @@ import com.google.common.collect.ImmutableList;
|
||||
import com.velocitypowered.api.event.Subscribe;
|
||||
import com.velocitypowered.api.event.connection.DisconnectEvent;
|
||||
import com.velocitypowered.api.event.player.ServerPostConnectEvent;
|
||||
import com.velocitypowered.api.proxy.Player;
|
||||
import com.velocitypowered.api.proxy.ServerConnection;
|
||||
import com.velocitypowered.api.proxy.server.ServerInfo;
|
||||
import de.themoep.minedown.adventure.MineDown;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.william278.velocitab.Velocitab;
|
||||
@ -26,13 +29,22 @@ public class PlayerTabList {
|
||||
@SuppressWarnings("UnstableApiUsage")
|
||||
@Subscribe
|
||||
public void onPlayerJoin(@NotNull ServerPostConnectEvent event) {
|
||||
final Player joined = event.getPlayer();
|
||||
// Remove the player from the tracking list if they are switching servers
|
||||
if (event.getPreviousServer() == null) {
|
||||
players.removeIf(player -> player.getPlayer().getUniqueId().equals(event.getPlayer().getUniqueId()));
|
||||
players.removeIf(player -> player.getPlayer().getUniqueId().equals(joined.getUniqueId()));
|
||||
}
|
||||
|
||||
// Don't set their list if they are on an excluded server
|
||||
if (plugin.getSettings().isServerExcluded(joined.getCurrentServer()
|
||||
.map(ServerConnection::getServerInfo)
|
||||
.map(ServerInfo::getName)
|
||||
.orElse("?"))) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Add the player to the tracking list
|
||||
players.add(plugin.getTabPlayer(event.getPlayer()));
|
||||
players.add(plugin.getTabPlayer(joined));
|
||||
|
||||
// Update the tab list of all players
|
||||
plugin.getServer().getScheduler().buildTask(plugin, this::updateList)
|
||||
|
Loading…
Reference in New Issue
Block a user