forked from Upstream/Velocitab
Add support for header and footer animations (#25)
This commit is contained in:
parent
3001abfa17
commit
10c8102e59
@ -21,10 +21,12 @@ import java.util.Map;
|
|||||||
public class Settings {
|
public class Settings {
|
||||||
|
|
||||||
@YamlKey("headers")
|
@YamlKey("headers")
|
||||||
private Map<String, String> headers = Map.of("default", "&rainbow&Running Velocitab by William278");
|
@YamlComment("Header(s) to display above the TAB list for each server group.\nList multiple headers and set update_rate to the number of ticks between frames for basic animations")
|
||||||
|
private Map<String, List<String>> headers = Map.of("default", List.of("&rainbow&Running Velocitab by William278"));
|
||||||
|
|
||||||
@YamlKey("footers")
|
@YamlKey("footers")
|
||||||
private Map<String, String> footers = Map.of("default", "[There are currently %players_online%/%max_players_online% players online](gray)");
|
@YamlComment("Footer(s) to display below the TAB list for each server group, same as headers.")
|
||||||
|
private Map<String, List<String>> footers = Map.of("default", List.of("[There are currently %players_online%/%max_players_online% players online](gray)"));
|
||||||
|
|
||||||
@YamlKey("formats")
|
@YamlKey("formats")
|
||||||
private Map<String, String> formats = Map.of("default", "&7[%server%] &f%prefix%%username%");
|
private Map<String, String> formats = Map.of("default", "&7[%server%] &f%prefix%%username%");
|
||||||
@ -78,15 +80,23 @@ public class Settings {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public String getHeader(@NotNull String serverGroup) {
|
public String getHeader(@NotNull String serverGroup, @NotNull int index) {
|
||||||
return StringEscapeUtils.unescapeJava(
|
return StringEscapeUtils.unescapeJava(
|
||||||
headers.getOrDefault(serverGroup, ""));
|
headers.getOrDefault(serverGroup, List.of("")).get(index));
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public String getFooter(@NotNull String serverGroup) {
|
public String getFooter(@NotNull String serverGroup, @NotNull int index) {
|
||||||
return StringEscapeUtils.unescapeJava(
|
return StringEscapeUtils.unescapeJava(
|
||||||
footers.getOrDefault(serverGroup, ""));
|
footers.getOrDefault(serverGroup, List.of("")).get(index));
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getHeaderListSize(@NotNull String serverGroup) {
|
||||||
|
return headers.getOrDefault(serverGroup, List.of("")).size();
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getFooterListSize(@NotNull String serverGroup) {
|
||||||
|
return footers.getOrDefault(serverGroup, List.of("")).size();
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
|
@ -26,6 +26,8 @@ public class PlayerTabList {
|
|||||||
private final Velocitab plugin;
|
private final Velocitab plugin;
|
||||||
private final ConcurrentLinkedQueue<TabPlayer> players;
|
private final ConcurrentLinkedQueue<TabPlayer> players;
|
||||||
private final ConcurrentLinkedQueue<String> fallbackServers;
|
private final ConcurrentLinkedQueue<String> fallbackServers;
|
||||||
|
private int headerIndex = 0;
|
||||||
|
private int footerIndex = 0;
|
||||||
|
|
||||||
public PlayerTabList(@NotNull Velocitab plugin) {
|
public PlayerTabList(@NotNull Velocitab plugin) {
|
||||||
this.plugin = plugin;
|
this.plugin = plugin;
|
||||||
@ -159,16 +161,26 @@ public class PlayerTabList {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public CompletableFuture<Component> getHeader(@NotNull TabPlayer player) {
|
public CompletableFuture<Component> getHeader(@NotNull TabPlayer player) {
|
||||||
return Placeholder.replace(plugin.getSettings().getHeader(
|
if (headerIndex >= plugin.getSettings().getHeaderListSize(plugin.getSettings().getServerGroup(player.getServerName()))){
|
||||||
plugin.getSettings().getServerGroup(player.getServerName())), plugin, player)
|
headerIndex = 0;
|
||||||
|
}
|
||||||
|
CompletableFuture<Component> headerComponent = Placeholder.replace(plugin.getSettings().getHeader(
|
||||||
|
plugin.getSettings().getServerGroup(player.getServerName()), headerIndex), plugin, player)
|
||||||
.thenApply(header -> plugin.getFormatter().format(header, player, plugin));
|
.thenApply(header -> plugin.getFormatter().format(header, player, plugin));
|
||||||
|
headerIndex++;
|
||||||
|
return headerComponent;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public CompletableFuture<Component> getFooter(@NotNull TabPlayer player) {
|
public CompletableFuture<Component> getFooter(@NotNull TabPlayer player) {
|
||||||
return Placeholder.replace(plugin.getSettings().getFooter(
|
if (footerIndex >= plugin.getSettings().getFooterListSize(plugin.getSettings().getServerGroup(player.getServerName()))){
|
||||||
plugin.getSettings().getServerGroup(player.getServerName())), plugin, player)
|
footerIndex = 0;
|
||||||
|
}
|
||||||
|
CompletableFuture<Component> footerComponent = Placeholder.replace(plugin.getSettings().getFooter(
|
||||||
|
plugin.getSettings().getServerGroup(player.getServerName()), footerIndex), plugin, player)
|
||||||
.thenApply(footer -> plugin.getFormatter().format(footer, player, plugin));
|
.thenApply(footer -> plugin.getFormatter().format(footer, player, plugin));
|
||||||
|
footerIndex++;
|
||||||
|
return footerComponent;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user