Velocitab/docs/Sorting.md
AlexDev_ cb8a50c24f
Sorting System with Placeholders (#94)
* Added regex check for placeholders to avoid useless requests.
Added support for custom nametags. Due to minecraft limit only legacy chatcolor are supported.
Team names now are unique, so 1 team can have max 1 player.
Fixed problem with luckperms event bus while reloading the plugin.

* Update src/main/java/net/william278/velocitab/config/Placeholder.java

Co-authored-by: William <will27528@gmail.com>

* Update src/main/java/net/william278/velocitab/hook/LuckPermsHook.java

Co-authored-by: William <will27528@gmail.com>

* Update src/main/java/net/william278/velocitab/config/Formatter.java

Co-authored-by: William <will27528@gmail.com>

* Update src/main/java/net/william278/velocitab/packet/UpdateTeamsPacket.java

Co-authored-by: William <will27528@gmail.com>

* Fixed problem while updating display names. Changed a few method signature as requested in pr. Applied changes of pr.

* Added support for placeholders as sorting system

* Code reformat

* Update logging, task scheduling and player rosters

Modified logging in the ScoreboardManager to represent playerNames as an array for readability. Ensured all tasks scheduled by Velocitab are canceled on proxy shutdown to prevent unwanted behavior. Reworked player roster management in PlayerTabList to correctly update player roles and decrease asynchronicity, enhancing performance and preventing possible race conditions.

* Fixed problems after merging with upstream, fixed problem with player team color on join.

* Fixed problems with pr-merge. Added sorting system with placeholders.

* Update src/main/java/net/william278/velocitab/packet/UpdateTeamsPacket.java

Co-authored-by: William <will27528@gmail.com>

* Update src/main/java/net/william278/velocitab/packet/ScoreboardManager.java

Co-authored-by: William <will27528@gmail.com>

* Update src/main/java/net/william278/velocitab/packet/ScoreboardManager.java

Co-authored-by: William <will27528@gmail.com>

* Update src/main/java/net/william278/velocitab/packet/ScoreboardManager.java

Co-authored-by: William <will27528@gmail.com>

* Update src/main/java/net/william278/velocitab/config/Formatter.java

Co-authored-by: William <will27528@gmail.com>

* Update src/main/java/net/william278/velocitab/player/TabPlayer.java

Co-authored-by: William <will27528@gmail.com>

* Fix username replacement in scoreboard and code typo

This commit resolves two issues. Firstly, changed the variable that we split the nametag on in `ScoreboardManager` from a hardcoded string to the player's specific username. This rectifies an issue where incorrect splitting occurred if the username wasn't exactly "%username%". Secondly, fixed a miswritten method call in `Formatter` from '..legacySection()' to '.legacySection()', correcting a syntax error. Lastly, removed superfluous replacement in `TabPlayer's` getNametag method as it was already handled in `ScoreboardManager`.

* Reformat code

* Changed logic with only one plugin message request.

* Update src/main/java/net/william278/velocitab/sorting/SortingManager.java

Co-authored-by: William <will27528@gmail.com>

* Update src/main/java/net/william278/velocitab/hook/LuckPermsHook.java

Co-authored-by: William <will27528@gmail.com>

* Update src/main/java/net/william278/velocitab/packet/ScoreboardManager.java

Co-authored-by: William <will27528@gmail.com>

* Fixed requested changes

* Changed docs

---------

Co-authored-by: William <will27528@gmail.com>
2023-09-25 15:10:45 +01:00

3.3 KiB

Velocitab can sort players in the TAB list by a number of "sorting elements." Sorting is enabled by default, and can be disabled with the sort_players option in the config.yml file.

Sortable elements

To modify what players are sorted by, modify the sorting_placeholders list in the config.yml file. This option accepts an ordered list; the first element in the list is what players will be sorted by first, with subsequent elements being used to break ties. The default sorting strategy is to sort first by %role_weight% followed by %username%.

Sort Players By… (config.yml)
# Ordered list of elements by which players should be sorted. (Correct values are both internal placeholders and (if enabled) PAPI placeholders)
sort_players_by:
  - %role_weight%
  - %username%

List of elements

The following sorting elements are supported:

Sorting element Description
Internal Placeholders Check docs here
PAPI Placeholders Check docs here

Technical details

In Minecraft, the TAB list is sorted by the client; the server does not handle the actual display order of names in the list. Players are sorted first by the name of their scoreboard team, then by their name. This is why having a proxy TAB plugin sort players is a surprisingly complex feature request!

To get the client to correctly sort the TAB list, Velocitab sends fake scoreboard "Update Teams" packets to everyone in order to trick the client into thinking players on the server are members of a fake scoreboard team. The name of the fake team for sorting is based on a number of "sorting elements," which can be customized.

Velocitab has a few optimizations in place to reduce the number of packets sent; if you update frequently sorting element placeholders, do note this will lead to more packets being sent between clients and the proxy as the teams will need to be updated more regularly. This can lead to an observable increase in network traffic—listing fewer sorting elements in the sort_players_by section will reduce the number of packets sent.

Compatibility issues

There are a few compatibility caveats to bear in mind with sorting players in the TAB list:

  • If you're using scoreboard teams on your server, then this will interfere with Velocitab's fake team packets and cause sorting to break. Most modern Minecraft proxy network servers probably won't use this feature, since there are better and more powerful plugin alternatives for teaming players, but it's still important to bear in mind.
  • Some mods can interfere with scoreboard team packets, particularly if they internally deal with managing packets or scoreboard teams.
  • Sending fake scoreboard team packets might not work correctly on some Minecraft server implementations such as Quilt.

In these cases, you may need to disable sorting through the sort_players option detailed earlier.