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

View File

@ -131,13 +131,19 @@ public class Velocitab {
}
private void prepareScoreboardManager() {
this.scoreboardManager = new ScoreboardManager(this);
scoreboardManager.registerPacket();
if (settings.isSortPlayers()) {
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
public ScoreboardManager getScoreboardManager() {
return scoreboardManager;
public Optional<ScoreboardManager> getScoreboardManager() {
return Optional.ofNullable(scoreboardManager);
}
@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.")
private Map<String, String> serverDisplayNames = Map.of("very-long-server-name", "VLSN");
@Getter
@YamlKey("enable_papi_hook")
private boolean enablePapiHook = true;
@Getter
@YamlKey("enable_miniplaceholders_hook")
@YamlComment("If you are using MINIMESSAGE formatting, enable this to support MiniPlaceholders in formatting.")
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")
@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(
@ -95,6 +102,7 @@ public class Settings {
TabPlayer.SortableElement.ROLE_NAME.name()
);
@Getter
@YamlKey("update_rate")
@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)")
@ -163,14 +171,6 @@ public class Settings {
.orElse(fallbackGroup);
}
public boolean isPapiHookEnabled() {
return enablePapiHook;
}
public boolean isMiniPlaceholdersHookEnabled() {
return enableMiniPlaceholdersHook;
}
@NotNull
public List<TabPlayer.SortableElement> getSortingElementList() {
return sortPlayersBy.stream()
@ -179,8 +179,4 @@ public class Settings {
.toList();
}
public int getUpdateRate() {
return updateRate;
}
}

View File

@ -41,7 +41,7 @@ public abstract class Hook {
return Optional.empty();
}),
(plugin -> {
if (isPluginAvailable(plugin, "papiproxybridge") && plugin.getSettings().isPapiHookEnabled()) {
if (isPluginAvailable(plugin, "papiproxybridge") && plugin.getSettings().isEnablePapiHook()) {
try {
plugin.log("Successfully hooked into PAPIProxyBridge");
return Optional.of(new PapiHook(plugin));
@ -52,7 +52,7 @@ public abstract class Hook {
return Optional.empty();
}),
(plugin -> {
if (isPluginAvailable(plugin, "miniplaceholders") && plugin.getSettings().isMiniPlaceholdersHookEnabled()) {
if (isPluginAvailable(plugin, "miniplaceholders") && plugin.getSettings().isEnableMiniPlaceholdersHook()) {
try {
plugin.log("Successfully hooked into MiniPlaceholders");
return Optional.of(new MiniPlaceholdersHook(plugin));
@ -70,7 +70,7 @@ public abstract class Hook {
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();
}

View File

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

View File

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

View File

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