forked from Upstream/Velocitab
Compare commits
15 Commits
Author | SHA1 | Date | |
---|---|---|---|
|
e398306cd7 | ||
|
9cb20be6e0 | ||
|
a14c8eb2ea | ||
|
d47ee75d5b | ||
|
e17d36deb5 | ||
|
6796f4402f | ||
|
5a46053117 | ||
|
94760f7794 | ||
|
ce88b480a6 | ||
|
a55bd56364 | ||
|
7b8d55ba77 | ||
|
24c29e632f | ||
|
2ba208002a | ||
|
6c558fac3a | ||
|
67931d8d41 |
1
.github/workflows/ci.yml
vendored
1
.github/workflows/ci.yml
vendored
@ -126,4 +126,5 @@ jobs:
|
||||
1.21.1
|
||||
1.21.2
|
||||
1.21.3
|
||||
1.21.4
|
||||
java: 17
|
1
.github/workflows/release.yml
vendored
1
.github/workflows/release.yml
vendored
@ -115,4 +115,5 @@ jobs:
|
||||
1.21.1
|
||||
1.21.2
|
||||
1.21.3
|
||||
1.21.4
|
||||
java: 17
|
10
build.gradle
10
build.gradle
@ -2,7 +2,7 @@ import org.apache.tools.ant.filters.ReplaceTokens
|
||||
|
||||
plugins {
|
||||
id 'xyz.jpenilla.run-velocity' version '2.3.1'
|
||||
id 'com.gradleup.shadow' version '8.3.3'
|
||||
id 'com.gradleup.shadow' version '8.3.5'
|
||||
id 'org.cadixdev.licenser' version '0.6.1'
|
||||
id 'org.ajoberstar.grgit' version '5.3.0'
|
||||
id 'maven-publish'
|
||||
@ -38,8 +38,8 @@ dependencies {
|
||||
compileOnly "com.velocitypowered:velocity-proxy:${velocity_api_version}-SNAPSHOT"
|
||||
compileOnly "net.william278:papiproxybridge:${papi_proxy_bridge_minimum_version}"
|
||||
|
||||
compileOnly 'io.netty:netty-codec-http:4.1.114.Final'
|
||||
compileOnly 'org.projectlombok:lombok:1.18.34'
|
||||
compileOnly 'io.netty:netty-codec-http:4.1.115.Final'
|
||||
compileOnly 'org.projectlombok:lombok:1.18.36'
|
||||
compileOnly 'net.luckperms:api:5.4'
|
||||
compileOnly 'io.github.miniplaceholders:miniplaceholders-api:2.2.3'
|
||||
compileOnly 'it.unimi.dsi:fastutil:8.5.15'
|
||||
@ -53,7 +53,7 @@ dependencies {
|
||||
implementation 'org.apache.commons:commons-jexl3:3.4.0'
|
||||
implementation 'net.jodah:expiringmap:0.5.11'
|
||||
|
||||
annotationProcessor 'org.projectlombok:lombok:1.18.34'
|
||||
annotationProcessor 'org.projectlombok:lombok:1.18.36'
|
||||
}
|
||||
|
||||
processResources {
|
||||
@ -165,7 +165,7 @@ tasks {
|
||||
velocityVersion("${velocity_api_version}-SNAPSHOT")
|
||||
|
||||
downloadPlugins {
|
||||
modrinth ("papiproxybridge", papi)
|
||||
github ("WiIIiam278", "PAPIProxyBridge", "1.7.1", "PAPIProxyBridge-Velocity-1.7.1.jar")
|
||||
modrinth ("miniplaceholders", "2.2.4")
|
||||
}
|
||||
}
|
||||
|
@ -28,10 +28,6 @@ fallback_enabled: true
|
||||
fallback_group: default
|
||||
# Whether to show all players from all groups in the TAB list.
|
||||
show_all_players_from_all_groups: false
|
||||
# Define custom names to be shown in the TAB list for specific server names.
|
||||
# If no custom display name is provided for a server, its original name will be used.
|
||||
server_display_names:
|
||||
very-long-server-name: VLSN
|
||||
# Whether to enable the PAPIProxyBridge hook for PAPI support
|
||||
enable_papi_hook: true
|
||||
# How long in seconds to cache PAPI placeholders for, in milliseconds. (0 to disable)
|
||||
@ -101,6 +97,14 @@ groups:
|
||||
sorting_placeholders:
|
||||
- '%role_weight%'
|
||||
- '%username_lower%'
|
||||
placeholder_replacements:
|
||||
'%current_date_weekday_en-US%':
|
||||
- placeholder: Monday
|
||||
replacement: <red>Monday</red>
|
||||
- placeholder: Tuesday
|
||||
replacement: <gold>Tuesday</gold>
|
||||
- placeholder: Else
|
||||
replacement: <green>Other day</green>
|
||||
collisions: false
|
||||
header_footer_update_rate: 1000
|
||||
placeholder_update_rate: 1000
|
||||
@ -127,3 +131,6 @@ You can use various placeholders that will be replaced with values (for example,
|
||||
|
||||
### Server Links
|
||||
For Minecraft 1.21+ clients, Velocitab supports specifying a list of URLs that will be sent to display in the player pause menu. See [[Server Links]] for more information.
|
||||
|
||||
### Placeholder Replacements
|
||||
Velocitab supports replacing values of placeholders with other values. See [[Placeholders Replacements]] for more information.
|
@ -46,4 +46,35 @@ is equivalent to
|
||||
|
||||
```yaml
|
||||
foo: "bar 1\nbar 2\nbar 3\n"
|
||||
```
|
||||
```
|
||||
|
||||
## List of multi lines strings
|
||||
|
||||
> **Note:** The examples above are generic examples on how yaml works in multi line. If you want to use multi line in headers & footers you need to provide a list of multi line strings like in the example below.
|
||||
|
||||
```yaml
|
||||
headers:
|
||||
- |
|
||||
<rainbow:!2>Running Velocitab by William278 & AlexDev_</rainbow>
|
||||
<gray>Second line of the first element</gray>
|
||||
<yellow>Third line of the first element</yellow>
|
||||
- |
|
||||
<rainbow:!4>Running Velocitab by William278 & AlexDev_</rainbow>
|
||||
<gray>Second line of the second element</gray>
|
||||
<yellow>Third line of the second element</yellow>
|
||||
footers:
|
||||
- <gray>There are currently %players_online%/%max_players_online% players online</gray>
|
||||
- |
|
||||
<gray> Test 1 </gray>
|
||||
<yellow> Test 2 </yellow>
|
||||
```
|
||||
|
||||
In this example the header will switch between the 2 elements, but it will always display all the 3 lines.
|
||||
|
||||
The footer in this example will switch between 2 elements, the first one is just a simple string, the second element will display 2 lines since it's a multi line string
|
||||
|
||||
<figure style="text-align: center;">
|
||||
<img src="https://i.imgur.com/YKu1RWi.gif" />
|
||||
<figcaption>Example of a header and footer with multi line strings</figcaption>
|
||||
</figure>
|
||||
|
||||
|
88
docs/Placeholders-Replacements.md
Normal file
88
docs/Placeholders-Replacements.md
Normal file
@ -0,0 +1,88 @@
|
||||
|
||||
Velocitab supports placeholder replacements, which allow you to replace a placeholder with a different value. This is useful for things like changing the text of a date placeholder to a localized version, changing the text of a biome placeholder to a color or you can use a vanish placeholder to show a player's vanish status if the placeholder returns just a boolean (true/false).
|
||||
|
||||
|
||||
## Configuring
|
||||
|
||||
Placeholder replacements are configured in the `placeholder_replacements` section of the every Tab Group.
|
||||
You can specify a list of replacements for a placeholder, and the replacements will be applied in the order they are listed.
|
||||
|
||||
The replacements are specified as a list of objects with two properties: `placeholder` and `replacement`.
|
||||
`placeholder` is the placeholder to replace, and `replacement` is the replacement text.
|
||||
|
||||
### Example section
|
||||
```yaml
|
||||
placeholder_replacements:
|
||||
'%current_date_weekday_en-US%':
|
||||
- placeholder: Monday
|
||||
replacement: <red>Monday</red>
|
||||
- placeholder: Tuesday
|
||||
replacement: <gold>Tuesday</gold>
|
||||
- placeholder: Else
|
||||
replacement: <green>Other day</green>
|
||||
'%player_world_type%':
|
||||
- placeholder: Overworld
|
||||
replacement: '<aqua>Overworld</aqua>'
|
||||
- placeholder: Nether
|
||||
replacement: '<red>Nether</red>'
|
||||
- placeholder: End
|
||||
replacement: '<yellow>End</yellow>'
|
||||
'%player_biome%':
|
||||
- placeholder: PLAINS
|
||||
replacement: <red>Plains</red>
|
||||
- placeholder: DESERT
|
||||
replacement: <yellow>Desert</yellow>
|
||||
- placeholder: RIVER
|
||||
replacement: <aqua>River</aqua>
|
||||
```
|
||||
|
||||
## Specified cases
|
||||
|
||||
### Vanish status
|
||||
If you want to show a player's vanish status, for example, you can use the `%advancedvanish_is_vanished%` placeholder.
|
||||
This placeholder returns a boolean value, so you can use it to show a player's vanish status.
|
||||
|
||||
For example, if you wanted to show a player's vanish status as a color, you could use the following replacements:
|
||||
```yaml
|
||||
placeholder_replacements:
|
||||
'%advancedvanish_is_vanished%':
|
||||
- placeholder: Yes
|
||||
replacement: <red>Vanished</red>
|
||||
- placeholder: No
|
||||
replacement: <green>Not vanished</green>
|
||||
```
|
||||
|
||||
### Else clause
|
||||
If you don't want to specify every possible value for a placeholder, you can use the `ELSE` placeholder.
|
||||
This placeholder will be replaced with the replacement text of the first replacement that doesn't have a placeholder.
|
||||
|
||||
For example, if you wanted to show the current date as a color, you could use the following replacements:
|
||||
```yaml
|
||||
placeholder_replacements:
|
||||
'%current_date_weekday_en-US%':
|
||||
- placeholder: Monday
|
||||
replacement: <red>Monday</red>
|
||||
- placeholder: Tuesday
|
||||
replacement: <gold>Tuesday</gold>
|
||||
- placeholder: ELSE
|
||||
replacement: <green>Other day</green>
|
||||
```
|
||||
|
||||
### Placeholder not present in a server
|
||||
If you have a group with multiple servers, and you have a placeholder that is not present in one of the servers, you can use the `%<placeholder>%` as a placeholder it will handle the case where the placeholder is not present in the server.
|
||||
|
||||
```yaml
|
||||
placeholder_replacements:
|
||||
'%huskhomes_homes_count%':
|
||||
- placeholder: '%huskhomes_homes_count%'
|
||||
replacement: <red>No homes in this server</red>
|
||||
```
|
||||
|
||||
If you want you can also set the replacement as an empty string, which will be replaced with the empty string.
|
||||
|
||||
```yaml
|
||||
placeholder_replacements:
|
||||
'%huskhomes_homes_count%':
|
||||
- placeholder: '%huskhomes_homes_count%'
|
||||
replacement: ''
|
||||
```
|
@ -40,20 +40,6 @@ Placeholders can be included in the header, footer and player name format of the
|
||||
You can find a list of common primary language subtags [here](https://en.wikipedia.org/wiki/IETF_language_tag#List_of_common_primary_language_subtags).
|
||||
|
||||
|
||||
### Customising server display names
|
||||
You can make use of the `server_display_names` feature in `config.yml` to customise how server display name appear when using the `%server%` placeholder. In the below example, if a user is connected to a server with the name "`very-long-server-`name" and the player name format for the group that server belongs to includes a `%server%` placeholder, the placeholder would be replaced with "`VSLN`" instead of the full server name.
|
||||
|
||||
<details>
|
||||
<summary>Server display names (config.yml)</summary>
|
||||
|
||||
```yaml
|
||||
# Define custom names to be shown in the TAB list for specific server names.
|
||||
# If no custom display name is provided for a server, its original name will be used.
|
||||
server_display_names:
|
||||
very-long-server-name: VLSN
|
||||
```
|
||||
</details>
|
||||
|
||||
## PlaceholderAPI support
|
||||
To use PlaceholderAPI placeholders in Velocitab, install the [PAPIProxyBridge](https://modrinth.com/plugin/papiproxybridge) library plugin on your Velocity proxy and all Minecraft spigot servers on your network, and ensure the PAPI hook option is enabled in your Velocitab [[Config File]]. You can then include PAPI placeholders in your formats as you would any of the default placeholders.
|
||||
|
||||
|
@ -11,6 +11,7 @@
|
||||
* ✍️ [[Placeholders]]
|
||||
* 🔗 [[Relational Placeholders]]
|
||||
* 🔀 [[Conditional Placeholders]]
|
||||
* 📝 [[Placeholders Replacements]]
|
||||
* ✨ [[Animations]]
|
||||
* 🖼️ [[Custom Logos]]
|
||||
* 🔗 [[Server Links]]
|
||||
|
@ -3,10 +3,10 @@ javaVersion=17
|
||||
org.gradle.jvmargs='-Dfile.encoding=UTF-8'
|
||||
org.gradle.daemon=true
|
||||
|
||||
plugin_version=1.7.2
|
||||
plugin_version=1.7.3
|
||||
plugin_archive=velocitab
|
||||
plugin_description=A beautiful and versatile TAB list plugin for Velocity proxies
|
||||
|
||||
velocity_api_version=3.4.0
|
||||
velocity_minimum_build=444
|
||||
velocity_minimum_build=453
|
||||
papi_proxy_bridge_minimum_version=1.7
|
@ -31,6 +31,7 @@ import org.jetbrains.annotations.Nullable;
|
||||
import org.slf4j.event.Level;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
@ -46,6 +47,7 @@ public record Group(
|
||||
Nametag nametag,
|
||||
Set<String> servers,
|
||||
List<String> sortingPlaceholders,
|
||||
Map<String, List<PlaceholderReplacement>> placeholderReplacements,
|
||||
boolean collisions,
|
||||
int headerFooterUpdateRate,
|
||||
int placeholderUpdateRate,
|
||||
|
@ -19,6 +19,8 @@
|
||||
|
||||
package net.william278.velocitab.config;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import com.google.common.collect.Maps;
|
||||
import com.velocitypowered.api.proxy.ServerConnection;
|
||||
import com.velocitypowered.api.proxy.server.RegisteredServer;
|
||||
import it.unimi.dsi.fastutil.Pair;
|
||||
@ -36,8 +38,7 @@ import java.time.LocalDateTime;
|
||||
import java.time.LocalTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.time.format.FormatStyle;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.function.BiFunction;
|
||||
import java.util.regex.Matcher;
|
||||
@ -95,7 +96,7 @@ public enum Placeholder {
|
||||
}),
|
||||
USERNAME((plugin, player) -> player.getCustomName().orElse(player.getPlayer().getUsername())),
|
||||
USERNAME_LOWER((plugin, player) -> player.getCustomName().orElse(player.getPlayer().getUsername()).toLowerCase()),
|
||||
SERVER((plugin, player) -> player.getServerDisplayName(plugin)),
|
||||
SERVER((plugin, player) -> player.getServerName()),
|
||||
PING((plugin, player) -> Long.toString(player.getPlayer().getPing())),
|
||||
PREFIX((plugin, player) -> player.getRole().getPrefix()
|
||||
.orElse(getPlaceholderFallback(plugin, "%luckperms_prefix%"))),
|
||||
@ -105,7 +106,8 @@ public enum Placeholder {
|
||||
.orElse(getPlaceholderFallback(plugin, "%luckperms_primary_group_name%"))),
|
||||
ROLE_DISPLAY_NAME((plugin, player) -> player.getRole().getDisplayName()
|
||||
.orElse(getPlaceholderFallback(plugin, "%luckperms_primary_group_name%"))),
|
||||
ROLE_WEIGHT((plugin, player) -> player.getRoleWeightString()),
|
||||
ROLE_WEIGHT((plugin, player) -> player.getRoleWeightString()
|
||||
.orElse(getPlaceholderFallback(plugin, "%luckperms_meta_weight%"))),
|
||||
SERVER_GROUP((plugin, player) -> player.getGroup().name()),
|
||||
SERVER_GROUP_INDEX((plugin, player) -> Integer.toString(player.getServerGroupPosition(plugin))),
|
||||
DEBUG_TEAM_NAME((plugin, player) -> plugin.getFormatter().escape(player.getLastTeamName().orElse(""))),
|
||||
@ -116,7 +118,7 @@ public enum Placeholder {
|
||||
private final static Pattern VELOCITAB_PATTERN = Pattern.compile("<velocitab_.*?>");
|
||||
private final static Pattern TEST = Pattern.compile("<.*?>");
|
||||
private final static Pattern CONDITION_REPLACER = Pattern.compile("<velocitab_rel_condition:[^:]*:");
|
||||
private final static Pattern PLACEHOLDER_PATTERN = Pattern.compile("%.*?%");
|
||||
private final static Pattern PLACEHOLDER_PATTERN = Pattern.compile("%.*?%", Pattern.DOTALL);
|
||||
private final static String DELIMITER = ":::";
|
||||
private final static Map<String, String> SYMBOL_SUBSTITUTES = Map.of(
|
||||
"<", "*LESS*",
|
||||
@ -126,6 +128,9 @@ public enum Placeholder {
|
||||
"*LESS*", "*LESS2*",
|
||||
"*GREATER*", "*GREATER2*"
|
||||
);
|
||||
private final static String VEL_PLACEHOLDER = "<vel";
|
||||
private final static String VELOCITAB_PLACEHOLDER = "<velocitab_rel";
|
||||
private final static String ELSE_PLACEHOLDER = "ELSE";
|
||||
|
||||
/**
|
||||
* Function to replace placeholders with a real value
|
||||
@ -162,17 +167,13 @@ public enum Placeholder {
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static String replaceInternal(@NotNull String format, @NotNull Velocitab plugin, @Nullable TabPlayer player) {
|
||||
final Pair<Boolean, String> result = processRelationalPlaceholders(format, plugin);
|
||||
format = result.right();
|
||||
format = replacePlaceholders(format, plugin, player);
|
||||
|
||||
return format;
|
||||
public static Pair<String, Map<String, String>> replaceInternal(@NotNull String format, @NotNull Velocitab plugin, @Nullable TabPlayer player) {
|
||||
format = processRelationalPlaceholders(format, plugin);
|
||||
return replacePlaceholders(format, plugin, player);
|
||||
}
|
||||
|
||||
private static Pair<Boolean, String> processRelationalPlaceholders(@NotNull String format, @NotNull Velocitab plugin) {
|
||||
boolean foundRelational = false;
|
||||
if (plugin.getFormatter().equals(Formatter.MINIMESSAGE) && format.contains("<vel")) {
|
||||
private static String processRelationalPlaceholders(@NotNull String format, @NotNull Velocitab plugin) {
|
||||
if (plugin.getFormatter().equals(Formatter.MINIMESSAGE) && format.contains(VEL_PLACEHOLDER)) {
|
||||
final Matcher conditionReplacer = CONDITION_REPLACER.matcher(format);
|
||||
while (conditionReplacer.find()) {
|
||||
|
||||
@ -189,7 +190,7 @@ public enum Placeholder {
|
||||
|
||||
final Matcher testMatcher = TEST.matcher(format);
|
||||
while (testMatcher.find()) {
|
||||
if (testMatcher.group().startsWith("<velocitab_rel")) {
|
||||
if (testMatcher.group().startsWith(VELOCITAB_PLACEHOLDER)) {
|
||||
final Matcher second = TEST.matcher(testMatcher.group().substring(1));
|
||||
while (second.find()) {
|
||||
String s = second.group();
|
||||
@ -209,7 +210,6 @@ public enum Placeholder {
|
||||
|
||||
final Matcher velocitabRelationalMatcher = VELOCITAB_PATTERN.matcher(format);
|
||||
while (velocitabRelationalMatcher.find()) {
|
||||
foundRelational = true;
|
||||
final String relationalPlaceholder = velocitabRelationalMatcher.group().substring(1, velocitabRelationalMatcher.group().length() - 1);
|
||||
String fixedString = relationalPlaceholder;
|
||||
for (Map.Entry<String, String> entry : SYMBOL_SUBSTITUTES_2.entrySet()) {
|
||||
@ -223,25 +223,58 @@ public enum Placeholder {
|
||||
}
|
||||
|
||||
}
|
||||
return Pair.of(foundRelational, format);
|
||||
return format;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private static String replacePlaceholders(@NotNull String format, @NotNull Velocitab plugin, @Nullable TabPlayer player) {
|
||||
private static Pair<String, Map<String, String>> replacePlaceholders(@NotNull String format, @NotNull Velocitab plugin,
|
||||
@Nullable TabPlayer player) {
|
||||
final Map<String, String> replacedPlaceholders = Maps.newHashMap();
|
||||
for (Placeholder placeholder : values()) {
|
||||
Matcher matcher = placeholder.pattern.matcher(format);
|
||||
final Matcher matcher = placeholder.pattern.matcher(format);
|
||||
if (placeholder.parameterised) {
|
||||
format = matcher.replaceAll(matchResult ->
|
||||
Matcher.quoteReplacement(
|
||||
placeholder.replacer.apply(StringUtils.chop(matchResult.group().replace("%" + placeholder.name().toLowerCase(), "")
|
||||
.replaceFirst("_", ""))
|
||||
, plugin, player)
|
||||
));
|
||||
format = matcher.replaceAll(matchResult -> {
|
||||
final String replacement = placeholder.replacer.apply(StringUtils.chop(matchResult.group().replace("%" + placeholder.name().toLowerCase(), "")
|
||||
.replaceFirst("_", "")), plugin, player);
|
||||
replacedPlaceholders.put(matchResult.group(), replacement);
|
||||
return Matcher.quoteReplacement(replacement);
|
||||
});
|
||||
} else {
|
||||
format = matcher.replaceAll(matchResult -> Matcher.quoteReplacement(placeholder.replacer.apply(null, plugin, player)));
|
||||
format = matcher.replaceAll(matchResult -> {
|
||||
final String replacement = placeholder.replacer.apply(null, plugin, player);
|
||||
replacedPlaceholders.put(matchResult.group(), replacement);
|
||||
return Matcher.quoteReplacement(replacement);
|
||||
});
|
||||
}
|
||||
}
|
||||
return format;
|
||||
return Pair.of(format, replacedPlaceholders);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private static String applyPlaceholderReplacements(@NotNull String text, @NotNull TabPlayer player,
|
||||
@NotNull Map<String, String> parsed) {
|
||||
for (final Map.Entry<String, List<PlaceholderReplacement>> entry : player.getGroup().placeholderReplacements().entrySet()) {
|
||||
if (!parsed.containsKey(entry.getKey())) {
|
||||
continue;
|
||||
}
|
||||
|
||||
final String replaced = parsed.get(entry.getKey());
|
||||
final Optional<PlaceholderReplacement> replacement = entry.getValue().stream()
|
||||
.filter(r -> r.placeholder().equalsIgnoreCase(replaced))
|
||||
.findFirst();
|
||||
|
||||
if (replacement.isPresent()) {
|
||||
text = text.replace(entry.getKey(), replacement.get().replacement());
|
||||
} else {
|
||||
final Optional<PlaceholderReplacement> elseReplacement = entry.getValue().stream()
|
||||
.filter(r -> r.placeholder().equalsIgnoreCase(ELSE_PLACEHOLDER))
|
||||
.findFirst();
|
||||
if (elseReplacement.isPresent()) {
|
||||
text = text.replace(entry.getKey(), elseReplacement.get().replacement());
|
||||
}
|
||||
}
|
||||
}
|
||||
return applyPlaceholders(text, parsed);
|
||||
}
|
||||
|
||||
public static CompletableFuture<String> replace(@NotNull String format, @NotNull Velocitab plugin,
|
||||
@ -251,22 +284,48 @@ public enum Placeholder {
|
||||
return CompletableFuture.completedFuture("");
|
||||
}
|
||||
|
||||
final String replaced = replaceInternal(format, plugin, player);
|
||||
|
||||
if (!PLACEHOLDER_PATTERN.matcher(replaced).find()) {
|
||||
return CompletableFuture.completedFuture(replaced);
|
||||
final Pair<String, Map<String, String>> replaced = replaceInternal(format, plugin, player);
|
||||
if (!PLACEHOLDER_PATTERN.matcher(replaced.first()).find()) {
|
||||
return CompletableFuture.completedFuture(applyPlaceholderReplacements(format, player, replaced.second()));
|
||||
}
|
||||
|
||||
final List<String> placeholders = extractPlaceholders(replaced.first());
|
||||
return plugin.getPAPIProxyBridgeHook()
|
||||
.map(hook -> hook.formatPlaceholders(replaced, player.getPlayer())
|
||||
.map(hook -> hook.parsePlaceholders(placeholders, player.getPlayer())
|
||||
.exceptionally(e -> {
|
||||
plugin.log(Level.ERROR, "An error occurred whilst parsing placeholders: " + e.getMessage());
|
||||
return replaced;
|
||||
return Map.of();
|
||||
})
|
||||
)
|
||||
.orElse(CompletableFuture.completedFuture(replaced)).exceptionally(e -> {
|
||||
.orElse(CompletableFuture.completedFuture(Maps.newHashMap()))
|
||||
.exceptionally(e -> {
|
||||
plugin.log(Level.ERROR, "An error occurred whilst parsing placeholders: " + e.getMessage());
|
||||
return replaced;
|
||||
});
|
||||
return Map.of();
|
||||
})
|
||||
.thenApply(m -> applyPlaceholderReplacements(format, player, mergeMaps(m, replaced.second())));
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private static String applyPlaceholders(@NotNull String text, @NotNull Map<String, String> replacements) {
|
||||
for (Map.Entry<String, String> entry : replacements.entrySet()) {
|
||||
text = text.replace(entry.getKey(), entry.getValue());
|
||||
}
|
||||
return text;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private static Map<String, String> mergeMaps(@NotNull Map<String, String> map1, @NotNull Map<String, String> map2) {
|
||||
map1.putAll(map2);
|
||||
return map1;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private static List<String> extractPlaceholders(@NotNull String text) {
|
||||
final List<String> placeholders = Lists.newArrayList();
|
||||
final Matcher matcher = PLACEHOLDER_PATTERN.matcher(text);
|
||||
while (matcher.find()) {
|
||||
placeholders.add(matcher.group());
|
||||
}
|
||||
return placeholders;
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,25 @@
|
||||
/*
|
||||
* This file is part of Velocitab, licensed under the Apache License 2.0.
|
||||
*
|
||||
* Copyright (c) William278 <will27528@gmail.com>
|
||||
* Copyright (c) contributors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package net.william278.velocitab.config;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public record PlaceholderReplacement(@NotNull String placeholder, @NotNull String replacement) {
|
||||
}
|
@ -67,10 +67,6 @@ public class Settings implements ConfigValidator {
|
||||
@Comment("Whether to show all players from all groups in the TAB list.")
|
||||
private boolean showAllPlayersFromAllGroups = false;
|
||||
|
||||
@Comment("Define custom names to be shown in the TAB list for specific server names."
|
||||
+ "\nIf 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");
|
||||
|
||||
@Comment("Whether to enable the PAPIProxyBridge hook for PAPI support")
|
||||
private boolean enablePapiHook = true;
|
||||
|
||||
@ -112,17 +108,6 @@ public class Settings implements ConfigValidator {
|
||||
)
|
||||
);
|
||||
|
||||
/**
|
||||
* Get display name for the server
|
||||
*
|
||||
* @param serverName The server name
|
||||
* @return The display name, or the server name if no display name is defined
|
||||
*/
|
||||
@NotNull
|
||||
public String getServerDisplayName(@NotNull String serverName) {
|
||||
return serverDisplayNames.getOrDefault(serverName, serverName);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public List<ServerUrl> getUrlsForGroup(@NotNull Group group) {
|
||||
return serverLinks.stream()
|
||||
|
@ -54,6 +54,13 @@ public class TabGroups implements ConfigValidator {
|
||||
new Nametag("", ""),
|
||||
Set.of("lobby", "survival", "creative", "minigames", "skyblock", "prison", "hub"),
|
||||
List.of("%role_weight%", "%username_lower%"),
|
||||
new LinkedHashMap<>() {{
|
||||
put("%current_date_weekday_en-US%", List.of(
|
||||
new PlaceholderReplacement("Monday", "<red>Monday</red>"),
|
||||
new PlaceholderReplacement("Tuesday", "<gold>Tuesday</gold>"),
|
||||
new PlaceholderReplacement("Else", "<green>Other day</green>")
|
||||
));
|
||||
}},
|
||||
false,
|
||||
1000,
|
||||
1000,
|
||||
@ -140,6 +147,10 @@ public class TabGroups implements ConfigValidator {
|
||||
if (group.sortingPlaceholders() == null) {
|
||||
missingKeys.put(group, "sortingPlaceholders");
|
||||
}
|
||||
|
||||
if (group.placeholderReplacements() == null) {
|
||||
missingKeys.put(group, "placeholderReplacements");
|
||||
}
|
||||
}
|
||||
|
||||
return missingKeys;
|
||||
@ -160,6 +171,7 @@ public class TabGroups implements ConfigValidator {
|
||||
group.nametag() == null ? DEFAULT_GROUP.nametag() : group.nametag(),
|
||||
group.servers() == null ? DEFAULT_GROUP.servers() : group.servers(),
|
||||
group.sortingPlaceholders() == null ? DEFAULT_GROUP.sortingPlaceholders() : group.sortingPlaceholders(),
|
||||
group.placeholderReplacements() == null ? DEFAULT_GROUP.placeholderReplacements() : group.placeholderReplacements(),
|
||||
group.collisions(),
|
||||
group.headerFooterUpdateRate(),
|
||||
group.placeholderUpdateRate(),
|
||||
|
@ -19,11 +19,15 @@
|
||||
|
||||
package net.william278.velocitab.hook;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import com.google.common.collect.Maps;
|
||||
import com.velocitypowered.api.proxy.Player;
|
||||
import net.william278.papiproxybridge.api.PlaceholderAPI;
|
||||
import net.william278.velocitab.Velocitab;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
public class PAPIProxyBridgeHook extends Hook {
|
||||
@ -41,4 +45,17 @@ public class PAPIProxyBridgeHook extends Hook {
|
||||
return api.formatPlaceholders(input, player.getUniqueId());
|
||||
}
|
||||
|
||||
public CompletableFuture<Map<String, String>> parsePlaceholders(@NotNull List<String> input, @NotNull Player player) {
|
||||
final Map<String, String> map = Maps.newConcurrentMap();
|
||||
final List<CompletableFuture<String>> futures = Lists.newArrayList();
|
||||
|
||||
for (String s : input) {
|
||||
final CompletableFuture<String> future = formatPlaceholders(s, player);
|
||||
futures.add(future);
|
||||
future.thenAccept(r -> map.put(s, r));
|
||||
}
|
||||
|
||||
return CompletableFuture.allOf(futures.toArray(CompletableFuture[]::new)).thenApply(v -> map);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -98,7 +98,7 @@ public class VelocitabMiniExpansion {
|
||||
}
|
||||
|
||||
final String value = fixValue(popAll(queue));
|
||||
String replaced = Placeholder.replaceInternal(value, plugin, targetPlayer);
|
||||
final String replaced = Placeholder.replaceInternal(value, plugin, targetPlayer).first();
|
||||
|
||||
return Tag.selfClosingInserting(MiniMessage.miniMessage().deserialize(replaced, MiniPlaceholders.getAudienceGlobalPlaceholders(audience)));
|
||||
}));
|
||||
|
@ -110,7 +110,7 @@ public class MiniConditionManager {
|
||||
}
|
||||
|
||||
|
||||
condition = Placeholder.replaceInternal(condition, plugin, tabPlayer.get());
|
||||
condition = Placeholder.replaceInternal(condition, plugin, tabPlayer.get()).first();
|
||||
final String falseValue = processFalseValue(parameters.get(2));
|
||||
final String expression = buildExpression(condition);
|
||||
return evaluateAndFormatCondition(expression, target, audience, parameters.get(1), falseValue);
|
||||
|
@ -41,7 +41,8 @@ public class Protocol765Adapter extends Protocol404Adapter {
|
||||
ProtocolVersion.MINECRAFT_1_20_3,
|
||||
ProtocolVersion.MINECRAFT_1_20_5,
|
||||
ProtocolVersion.MINECRAFT_1_21,
|
||||
ProtocolVersion.MINECRAFT_1_21_2
|
||||
ProtocolVersion.MINECRAFT_1_21_2,
|
||||
ProtocolVersion.MINECRAFT_1_21_4
|
||||
));
|
||||
}
|
||||
|
||||
|
@ -152,7 +152,7 @@ public class ScoreboardManager {
|
||||
return;
|
||||
}
|
||||
final Set<RegisteredServer> siblings = tabPlayer.getGroup().registeredServers(plugin);
|
||||
final boolean isNameTagEmpty = tabPlayer.getGroup().nametag().isEmpty();
|
||||
final boolean isNameTagEmpty = tabPlayer.getGroup().nametag().isEmpty() && !plugin.getSettings().isRemoveNametags();
|
||||
|
||||
final Optional<Nametag> cachedTag = Optional.ofNullable(nametags.getOrDefault(teamName, null));
|
||||
cachedTag.ifPresent(nametag -> siblings.forEach(server -> server.getPlayersConnected().stream().filter(p -> p != player)
|
||||
@ -304,7 +304,7 @@ public class ScoreboardManager {
|
||||
|
||||
final UpdateTeamsPacket packet = UpdateTeamsPacket.create(plugin, tabPlayer, teamName, nametag, viewer, teamMembers);
|
||||
trackedTeams.put(viewer.getPlayer().getUniqueId(), teamName);
|
||||
final boolean isNameTagEmpty = tabPlayer.getGroup().nametag().isEmpty();
|
||||
final boolean isNameTagEmpty = tabPlayer.getGroup().nametag().isEmpty() && !plugin.getSettings().isRemoveNametags();
|
||||
sendPacket(viewer.getPlayer(), packet, isNameTagEmpty);
|
||||
}
|
||||
|
||||
@ -314,7 +314,7 @@ public class ScoreboardManager {
|
||||
if (!teams) {
|
||||
return;
|
||||
}
|
||||
final boolean isNameTagEmpty = tabPlayer.getGroup().nametag().isEmpty();
|
||||
final boolean isNameTagEmpty = tabPlayer.getGroup().nametag().isEmpty() && !plugin.getSettings().isRemoveNametags();
|
||||
tabPlayer.getGroup().getTabPlayers(plugin, tabPlayer).forEach(viewer -> {
|
||||
if (viewer == tabPlayer || !viewer.getPlayer().isActive()) {
|
||||
return;
|
||||
@ -373,7 +373,7 @@ public class ScoreboardManager {
|
||||
}
|
||||
|
||||
final Set<Player> players = tabPlayer.getGroup().getPlayers(plugin);
|
||||
final boolean isNameTagEmpty = tabPlayer.getGroup().nametag().isEmpty();
|
||||
final boolean isNameTagEmpty = tabPlayer.getGroup().nametag().isEmpty() && !plugin.getSettings().isRemoveNametags();
|
||||
players.forEach(connected -> {
|
||||
try {
|
||||
final boolean canSee = plugin.getVanishManager().canSee(connected.getUsername(), player.getUsername());
|
||||
@ -459,7 +459,7 @@ public class ScoreboardManager {
|
||||
}
|
||||
|
||||
final UpdateTeamsPacket removeTeam = UpdateTeamsPacket.removeTeam(plugin, team);
|
||||
final boolean isNameTagEmpty = tabPlayer.getGroup().nametag().isEmpty();
|
||||
final boolean isNameTagEmpty = tabPlayer.getGroup().nametag().isEmpty() && !plugin.getSettings().isRemoveNametags();
|
||||
sendPacket(player, removeTeam, isNameTagEmpty);
|
||||
trackedTeams.remove(player.getUniqueId(), team);
|
||||
|
||||
|
@ -30,7 +30,7 @@ import java.util.Optional;
|
||||
@RequiredArgsConstructor
|
||||
public class Role implements Comparable<Role> {
|
||||
|
||||
public static final int DEFAULT_WEIGHT = 0;
|
||||
public static final int DEFAULT_WEIGHT = -1;
|
||||
public static final Role DEFAULT_ROLE = new Role(DEFAULT_WEIGHT, null, null, null, null);
|
||||
@Getter
|
||||
private final int weight;
|
||||
@ -65,8 +65,11 @@ public class Role implements Comparable<Role> {
|
||||
}
|
||||
|
||||
@NotNull
|
||||
protected String getWeightString() {
|
||||
return Integer.toString(weight);
|
||||
protected Optional<String> getWeightString() {
|
||||
if (weight == -1) {
|
||||
return Optional.empty();
|
||||
}
|
||||
return Optional.of(Integer.toString(weight));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -96,7 +96,7 @@ public final class TabPlayer implements Comparable<TabPlayer> {
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public String getRoleWeightString() {
|
||||
public Optional<String> getRoleWeightString() {
|
||||
return getRole().getWeightString();
|
||||
}
|
||||
|
||||
@ -123,18 +123,6 @@ public final class TabPlayer implements Comparable<TabPlayer> {
|
||||
return plugin.getTabGroups().getPosition(group);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the display name of the server the player is currently on.
|
||||
* Affected by server aliases defined in the config.
|
||||
*
|
||||
* @param plugin The plugin instance
|
||||
* @return The display name of the server
|
||||
*/
|
||||
@NotNull
|
||||
public String getServerDisplayName(@NotNull Velocitab plugin) {
|
||||
return plugin.getSettings().getServerDisplayName(getServerName());
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public CompletableFuture<String> getDisplayName(@NotNull Velocitab plugin) {
|
||||
final String format = formatGroup();
|
||||
@ -166,7 +154,7 @@ public final class TabPlayer implements Comparable<TabPlayer> {
|
||||
displayName = displayName.replace(placeholder, value);
|
||||
}
|
||||
|
||||
displayName = Placeholder.replaceInternal(displayName, plugin, this);
|
||||
displayName = Placeholder.replaceInternal(displayName, plugin, this).first();
|
||||
return lastDisplayName = displayName;
|
||||
}
|
||||
|
||||
@ -275,7 +263,7 @@ public final class TabPlayer implements Comparable<TabPlayer> {
|
||||
@Override
|
||||
public int compareTo(@NotNull TabPlayer o) {
|
||||
final int roleDifference = role.compareTo(o.role);
|
||||
if (roleDifference == 0) {
|
||||
if (roleDifference <= 0) {
|
||||
return player.getUsername().compareTo(o.player.getUsername());
|
||||
}
|
||||
return roleDifference;
|
||||
|
@ -32,13 +32,13 @@ public record Nametag(@NotNull String prefix, @NotNull String suffix) {
|
||||
|
||||
@NotNull
|
||||
public Component getPrefixComponent(@NotNull Velocitab plugin, @NotNull TabPlayer tabPlayer, @NotNull TabPlayer target) {
|
||||
final String formatted = Placeholder.replaceInternal(prefix, plugin, tabPlayer);
|
||||
final String formatted = Placeholder.replaceInternal(prefix, plugin, tabPlayer).first();
|
||||
return plugin.getFormatter().format(formatted, tabPlayer, target, plugin);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public Component getSuffixComponent(@NotNull Velocitab plugin, @NotNull TabPlayer tabPlayer, @NotNull TabPlayer target) {
|
||||
final String formatted = Placeholder.replaceInternal(suffix, plugin, tabPlayer);
|
||||
final String formatted = Placeholder.replaceInternal(suffix, plugin, tabPlayer).first();
|
||||
return plugin.getFormatter().format(formatted, tabPlayer, target, plugin);
|
||||
}
|
||||
|
||||
|
@ -26,8 +26,11 @@ import com.velocitypowered.api.proxy.ServerConnection;
|
||||
import com.velocitypowered.api.proxy.player.TabList;
|
||||
import com.velocitypowered.api.proxy.player.TabListEntry;
|
||||
import com.velocitypowered.api.proxy.server.RegisteredServer;
|
||||
import com.velocitypowered.api.util.GameProfile;
|
||||
import com.velocitypowered.proxy.connection.client.ConnectedPlayer;
|
||||
import com.velocitypowered.proxy.protocol.packet.UpsertPlayerInfoPacket;
|
||||
import com.velocitypowered.proxy.tablist.KeyedVelocityTabList;
|
||||
import com.velocitypowered.proxy.tablist.VelocityTabList;
|
||||
import lombok.AccessLevel;
|
||||
import lombok.Getter;
|
||||
import net.kyori.adventure.text.Component;
|
||||
@ -62,15 +65,38 @@ public class PlayerTabList {
|
||||
@Getter(value = AccessLevel.PUBLIC)
|
||||
private final Map<UUID, TabPlayer> players;
|
||||
private final TaskManager taskManager;
|
||||
private final Map<Class<?>, Field> entriesFields;
|
||||
|
||||
public PlayerTabList(@NotNull Velocitab plugin) {
|
||||
this.plugin = plugin;
|
||||
this.vanishTabList = new VanishTabList(plugin, this);
|
||||
this.players = Maps.newConcurrentMap();
|
||||
this.taskManager = new TaskManager(plugin);
|
||||
this.entriesFields = Maps.newHashMap();
|
||||
this.reloadUpdate();
|
||||
this.registerListener();
|
||||
this.ensureDisplayNameTask();
|
||||
this.registerFields();
|
||||
}
|
||||
|
||||
// VelocityTabListLegacy is not supported
|
||||
private void registerFields() {
|
||||
final Class<KeyedVelocityTabList> keyedVelocityTabListClass = KeyedVelocityTabList.class;
|
||||
final Class<VelocityTabList> velocityTabListClass = VelocityTabList.class;
|
||||
try {
|
||||
final Field entriesField = keyedVelocityTabListClass.getDeclaredField("entries");
|
||||
entriesField.setAccessible(true);
|
||||
this.entriesFields.put(keyedVelocityTabListClass, entriesField);
|
||||
} catch (NoSuchFieldException e) {
|
||||
plugin.log(Level.ERROR, "Failed to register KeyedVelocityTabList field", e);
|
||||
}
|
||||
try {
|
||||
final Field entriesField = velocityTabListClass.getDeclaredField("entries");
|
||||
entriesField.setAccessible(true);
|
||||
this.entriesFields.put(velocityTabListClass, entriesField);
|
||||
} catch (NoSuchFieldException e) {
|
||||
plugin.log(Level.ERROR, "Failed to register VelocityTabList field", e);
|
||||
}
|
||||
}
|
||||
|
||||
private void registerListener() {
|
||||
@ -275,8 +301,11 @@ public class PlayerTabList {
|
||||
@SuppressWarnings("unchecked")
|
||||
private void fixDuplicateEntries(@NotNull Player target) {
|
||||
try {
|
||||
final Field entriesField = target.getTabList().getClass().getDeclaredField("entries");
|
||||
entriesField.setAccessible(true);
|
||||
final Optional<Field> optionalField = Optional.ofNullable(this.entriesFields.get(target.getTabList().getClass()));
|
||||
if (optionalField.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
final Field entriesField = optionalField.get();
|
||||
final Map<UUID, TabListEntry> entries = (Map<UUID, TabListEntry>) entriesField.get(target.getTabList());
|
||||
entries.entrySet().stream()
|
||||
.filter(entry -> entry.getValue().getProfile() != null)
|
||||
|
@ -103,7 +103,7 @@ public class TabListListener {
|
||||
plugin.getTabList().clearCachedData(joined);
|
||||
|
||||
if (!plugin.getSettings().isShowAllPlayersFromAllGroups() && previousGroup.isPresent()
|
||||
&& (groupOptional.isPresent() && !previousGroup.get().equals(groupOptional.get())
|
||||
&& (groupOptional.isPresent() && !previousGroup.get().equals(groupOptional.get())
|
||||
|| groupOptional.isEmpty())) {
|
||||
tabList.removeOldEntry(previousGroup.get(), joined.getUniqueId());
|
||||
}
|
||||
@ -127,7 +127,7 @@ public class TabListListener {
|
||||
final Component currentHeader = joined.getPlayerListHeader();
|
||||
final Component currentFooter = joined.getPlayerListFooter();
|
||||
if ((header.equals(currentHeader) && footer.equals(currentFooter)) ||
|
||||
(currentHeader.equals(Component.empty()) && currentFooter.equals(Component.empty()))
|
||||
(currentHeader.equals(Component.empty()) && currentFooter.equals(Component.empty()))
|
||||
) {
|
||||
joined.sendPlayerListHeaderAndFooter(Component.empty(), Component.empty());
|
||||
joined.getCurrentServer().ifPresent(serverConnection -> serverConnection.getServer().getPlayersConnected().forEach(player ->
|
||||
@ -146,20 +146,20 @@ public class TabListListener {
|
||||
|
||||
final Group group = groupOptional.get();
|
||||
plugin.getScoreboardManager().resetCache(joined, group);
|
||||
if (justQuit.contains(joined.getUniqueId())) {
|
||||
plugin.getServer().getScheduler().buildTask(plugin,
|
||||
() -> tabList.joinPlayer(joined, group))
|
||||
.delay(250, TimeUnit.MILLISECONDS)
|
||||
.schedule();
|
||||
return;
|
||||
}
|
||||
|
||||
tabList.joinPlayer(joined, group);
|
||||
final int delay = justQuit.contains(joined.getUniqueId()) ? 100 : 250;
|
||||
plugin.getServer().getScheduler().buildTask(plugin,
|
||||
() -> tabList.joinPlayer(joined, group))
|
||||
.delay(delay, TimeUnit.MILLISECONDS)
|
||||
.schedule();
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
@Subscribe(order = PostOrder.CUSTOM, priority = Short.MIN_VALUE)
|
||||
public void onPlayerQuit(@NotNull DisconnectEvent event) {
|
||||
if (event.getLoginStatus() == DisconnectEvent.LoginStatus.CONFLICTING_LOGIN) {
|
||||
return;
|
||||
}
|
||||
if (event.getLoginStatus() != DisconnectEvent.LoginStatus.SUCCESSFUL_LOGIN) {
|
||||
checkDelayedDisconnect(event);
|
||||
return;
|
||||
@ -180,6 +180,7 @@ public class TabListListener {
|
||||
return;
|
||||
}
|
||||
|
||||
tabList.removeOfflinePlayer(player);
|
||||
tabList.removeTabListUUID(event.getPlayer().getUniqueId());
|
||||
}).delay(750, TimeUnit.MILLISECONDS).schedule();
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user