Add option to disable sorting players, close #39

This commit is contained in:
William 2023-04-17 20:38:24 +01:00
parent 6e67325731
commit 7e349d3393
No known key found for this signature in database
7 changed files with 37 additions and 33 deletions

View File

@ -43,7 +43,7 @@ jobs:
loaders: | loaders: |
velocity velocity
dependencies: | dependencies: |
protocolize | depends | * protocolize | suggests | *
luckperms | suggests | * luckperms | suggests | *
papiproxybridge | suggests | * papiproxybridge | suggests | *
miniplaceholders | suggests | * miniplaceholders | suggests | *
@ -51,8 +51,6 @@ jobs:
1.16.5 1.16.5
1.17.1 1.17.1
1.18.2 1.18.2
1.19.2
1.19.3
1.19.4 1.19.4
java: 16 java: 16
- name: Upload GitHub Artifact - name: Upload GitHub Artifact

View File

@ -131,13 +131,19 @@ public class Velocitab {
} }
private void prepareScoreboardManager() { private void prepareScoreboardManager() {
this.scoreboardManager = new ScoreboardManager(this); if (settings.isSortPlayers()) {
scoreboardManager.registerPacket(); if (!Hook.isPluginAvailable(this, "protocolize")) {
log("Protocolize is required to sort players by weight, but was not found. Disabling sorting.");
return;
}
this.scoreboardManager = new ScoreboardManager(this);
scoreboardManager.registerPacket();
}
} }
@NotNull @NotNull
public ScoreboardManager getScoreboardManager() { public Optional<ScoreboardManager> getScoreboardManager() {
return scoreboardManager; return Optional.ofNullable(scoreboardManager);
} }
@NotNull @NotNull

View File

@ -81,13 +81,20 @@ public class Settings {
"If no custom display name is provided for a server, its original name will be used.") "If no custom display name is provided for a server, its original name will be used.")
private Map<String, String> serverDisplayNames = Map.of("very-long-server-name", "VLSN"); private Map<String, String> serverDisplayNames = Map.of("very-long-server-name", "VLSN");
@Getter
@YamlKey("enable_papi_hook") @YamlKey("enable_papi_hook")
private boolean enablePapiHook = true; private boolean enablePapiHook = true;
@Getter
@YamlKey("enable_miniplaceholders_hook") @YamlKey("enable_miniplaceholders_hook")
@YamlComment("If you are using MINIMESSAGE formatting, enable this to support MiniPlaceholders in formatting.") @YamlComment("If you are using MINIMESSAGE formatting, enable this to support MiniPlaceholders in formatting.")
private boolean enableMiniPlaceholdersHook = true; private boolean enableMiniPlaceholdersHook = true;
@Getter
@YamlKey("sort_players")
@YamlComment("Whether to sort players in the TAB list. Requires Protocolize to be installed.")
private boolean sortPlayers = true;
@YamlKey("sort_players_by") @YamlKey("sort_players_by")
@YamlComment("Ordered list of elements by which players should be sorted. (ROLE_WEIGHT, ROLE_NAME and SERVER are supported)") @YamlComment("Ordered list of elements by which players should be sorted. (ROLE_WEIGHT, ROLE_NAME and SERVER are supported)")
private List<String> sortPlayersBy = List.of( private List<String> sortPlayersBy = List.of(
@ -95,6 +102,7 @@ public class Settings {
TabPlayer.SortableElement.ROLE_NAME.name() TabPlayer.SortableElement.ROLE_NAME.name()
); );
@Getter
@YamlKey("update_rate") @YamlKey("update_rate")
@YamlComment("How often in milliseconds to periodically update the TAB list, including header and footer, for all users.\n" + @YamlComment("How often in milliseconds to periodically update the TAB list, including header and footer, for all users.\n" +
"If set to 0, TAB will be updated on player join/leave instead. (1s = 1000ms)") "If set to 0, TAB will be updated on player join/leave instead. (1s = 1000ms)")
@ -163,14 +171,6 @@ public class Settings {
.orElse(fallbackGroup); .orElse(fallbackGroup);
} }
public boolean isPapiHookEnabled() {
return enablePapiHook;
}
public boolean isMiniPlaceholdersHookEnabled() {
return enableMiniPlaceholdersHook;
}
@NotNull @NotNull
public List<TabPlayer.SortableElement> getSortingElementList() { public List<TabPlayer.SortableElement> getSortingElementList() {
return sortPlayersBy.stream() return sortPlayersBy.stream()
@ -179,8 +179,4 @@ public class Settings {
.toList(); .toList();
} }
public int getUpdateRate() {
return updateRate;
}
} }

View File

@ -41,7 +41,7 @@ public abstract class Hook {
return Optional.empty(); return Optional.empty();
}), }),
(plugin -> { (plugin -> {
if (isPluginAvailable(plugin, "papiproxybridge") && plugin.getSettings().isPapiHookEnabled()) { if (isPluginAvailable(plugin, "papiproxybridge") && plugin.getSettings().isEnablePapiHook()) {
try { try {
plugin.log("Successfully hooked into PAPIProxyBridge"); plugin.log("Successfully hooked into PAPIProxyBridge");
return Optional.of(new PapiHook(plugin)); return Optional.of(new PapiHook(plugin));
@ -52,7 +52,7 @@ public abstract class Hook {
return Optional.empty(); return Optional.empty();
}), }),
(plugin -> { (plugin -> {
if (isPluginAvailable(plugin, "miniplaceholders") && plugin.getSettings().isMiniPlaceholdersHookEnabled()) { if (isPluginAvailable(plugin, "miniplaceholders") && plugin.getSettings().isEnableMiniPlaceholdersHook()) {
try { try {
plugin.log("Successfully hooked into MiniPlaceholders"); plugin.log("Successfully hooked into MiniPlaceholders");
return Optional.of(new MiniPlaceholdersHook(plugin)); return Optional.of(new MiniPlaceholdersHook(plugin));
@ -70,7 +70,7 @@ public abstract class Hook {
this.plugin = plugin; this.plugin = plugin;
} }
private static boolean isPluginAvailable(@NotNull Velocitab plugin, @NotNull String id) { public static boolean isPluginAvailable(@NotNull Velocitab plugin, @NotNull String id) {
return plugin.getServer().getPluginManager().getPlugin(id).isPresent(); return plugin.getServer().getPluginManager().getPlugin(id).isPresent();
} }

View File

@ -69,7 +69,7 @@ public class UpdateTeamsPacket extends AbstractPacket {
private List<String> entities; private List<String> entities;
@NotNull @NotNull
public static UpdateTeamsPacket create(@NotNull String teamName, @NotNull String... teamMembers) { protected static UpdateTeamsPacket create(@NotNull String teamName, @NotNull String... teamMembers) {
return new UpdateTeamsPacket() return new UpdateTeamsPacket()
.teamName(teamName.length() > 16 ? teamName.substring(0, 16) : teamName) .teamName(teamName.length() > 16 ? teamName.substring(0, 16) : teamName)
.mode(UpdateMode.CREATE_TEAM) .mode(UpdateMode.CREATE_TEAM)
@ -84,7 +84,7 @@ public class UpdateTeamsPacket extends AbstractPacket {
} }
@NotNull @NotNull
public static UpdateTeamsPacket addToTeam(@NotNull String teamName, @NotNull String... teamMembers) { protected static UpdateTeamsPacket addToTeam(@NotNull String teamName, @NotNull String... teamMembers) {
return new UpdateTeamsPacket() return new UpdateTeamsPacket()
.teamName(teamName.length() > 16 ? teamName.substring(0, 16) : teamName) .teamName(teamName.length() > 16 ? teamName.substring(0, 16) : teamName)
.mode(UpdateMode.ADD_PLAYERS) .mode(UpdateMode.ADD_PLAYERS)
@ -92,7 +92,7 @@ public class UpdateTeamsPacket extends AbstractPacket {
} }
@NotNull @NotNull
public static UpdateTeamsPacket removeFromTeam(@NotNull String teamName, @NotNull String... teamMembers) { protected static UpdateTeamsPacket removeFromTeam(@NotNull String teamName, @NotNull String... teamMembers) {
return new UpdateTeamsPacket() return new UpdateTeamsPacket()
.teamName(teamName.length() > 16 ? teamName.substring(0, 16) : teamName) .teamName(teamName.length() > 16 ? teamName.substring(0, 16) : teamName)
.mode(UpdateMode.REMOVE_PLAYERS) .mode(UpdateMode.REMOVE_PLAYERS)

View File

@ -64,7 +64,7 @@ public class PlayerTabList {
@Subscribe @Subscribe
public void onPlayerJoin(@NotNull ServerPostConnectEvent event) { public void onPlayerJoin(@NotNull ServerPostConnectEvent event) {
final Player joined = event.getPlayer(); final Player joined = event.getPlayer();
plugin.getScoreboardManager().resetCache(joined); plugin.getScoreboardManager().ifPresent(manager -> manager.resetCache(joined));
// Remove the player from the tracking list if they are switching servers // Remove the player from the tracking list if they are switching servers
if (event.getPreviousServer() == null) { if (event.getPreviousServer() == null) {
@ -97,7 +97,7 @@ public class PlayerTabList {
for (TabPlayer player : players) { for (TabPlayer player : players) {
// Skip players on other servers if the setting is enabled // Skip players on other servers if the setting is enabled
if (plugin.getSettings().isOnlyListPlayersInSameGroup() && serversInGroup.isPresent() if (plugin.getSettings().isOnlyListPlayersInSameGroup() && serversInGroup.isPresent()
&& !serversInGroup.get().contains(player.getServerName())) { && !serversInGroup.get().contains(player.getServerName())) {
continue; continue;
} }
@ -112,7 +112,7 @@ public class PlayerTabList {
player.sendHeaderAndFooter(this); player.sendHeaderAndFooter(this);
} }
plugin.getScoreboardManager().setRoles(joined, playerRoles); plugin.getScoreboardManager().ifPresent(manager -> manager.setRoles(joined, playerRoles));
}) })
.delay(500, TimeUnit.MILLISECONDS) .delay(500, TimeUnit.MILLISECONDS)
.schedule(); .schedule();
@ -141,11 +141,12 @@ public class PlayerTabList {
() -> createEntry(newPlayer, player.getPlayer().getTabList()) () -> createEntry(newPlayer, player.getPlayer().getTabList())
.thenAccept(entry -> player.getPlayer().getTabList().addEntry(entry)) .thenAccept(entry -> player.getPlayer().getTabList().addEntry(entry))
); );
plugin.getScoreboardManager().updateRoles( plugin.getScoreboardManager().ifPresent(manager -> manager.updateRoles(
player.getPlayer(), player.getPlayer(),
newPlayer.getTeamName(plugin), newPlayer.getTeamName(plugin),
newPlayer.getPlayer().getUsername() newPlayer.getPlayer().getUsername()
); ));
} }
@Subscribe @Subscribe
@ -187,8 +188,11 @@ public class PlayerTabList {
player.getPlayer().getTabList().getEntries().stream() player.getPlayer().getTabList().getEntries().stream()
.filter(e -> e.getProfile().getId().equals(tabPlayer.getPlayer().getUniqueId())).findFirst() .filter(e -> e.getProfile().getId().equals(tabPlayer.getPlayer().getUniqueId())).findFirst()
.ifPresent(entry -> entry.setDisplayName(displayName)); .ifPresent(entry -> entry.setDisplayName(displayName));
plugin.getScoreboardManager().updateRoles(player.getPlayer(), plugin.getScoreboardManager().ifPresent(manager -> manager.updateRoles(
tabPlayer.getTeamName(plugin), tabPlayer.getPlayer().getUsername()); player.getPlayer(),
tabPlayer.getTeamName(plugin),
tabPlayer.getPlayer().getUsername()
));
})); }));
} }

View File

@ -10,7 +10,7 @@
"dependencies": [ "dependencies": [
{ {
"id": "protocolize", "id": "protocolize",
"optional": false "optional": true
}, },
{ {
"id": "luckperms", "id": "luckperms",