Tab list phase configurable
This commit is contained in:
parent
74bc5fd995
commit
2f3b5fcbc2
2 changed files with 32 additions and 26 deletions
|
@ -21,6 +21,8 @@ public class RccServerConfigModel {
|
||||||
public int teleportRequestTimeout = 120;
|
public int teleportRequestTimeout = 120;
|
||||||
|
|
||||||
public boolean enableTabList = true;
|
public boolean enableTabList = true;
|
||||||
|
public int tabListTickDelay = 2;
|
||||||
|
public double tabPhaseFrequency = 40;
|
||||||
public ArrayList<String> tabHeader = new ArrayList<>(List.of(
|
public ArrayList<String> tabHeader = new ArrayList<>(List.of(
|
||||||
"<gradient:#DEDE6C:#CC4C4C:{phase}><st> </st></gradient>"
|
"<gradient:#DEDE6C:#CC4C4C:{phase}><st> </st></gradient>"
|
||||||
));
|
));
|
||||||
|
|
|
@ -13,40 +13,44 @@ public class TabList {
|
||||||
if (!RccServer.CONFIG.enableTabList())
|
if (!RccServer.CONFIG.enableTabList())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
var minimessage = MiniMessage.miniMessage();
|
||||||
|
|
||||||
ServerTickEvents.END_SERVER_TICK.register(server -> {
|
ServerTickEvents.END_SERVER_TICK.register(server -> {
|
||||||
var phase = (Math.sin((server.getTicks() * Math.PI) / 20) + 1) / 2d;
|
if(server.getTicks() % RccServer.CONFIG.tabListTickDelay() == 0) {
|
||||||
var minimessage = MiniMessage.miniMessage();
|
|
||||||
|
|
||||||
server.getPlayerManager().getPlayerList().forEach(player -> {
|
var phase = (Math.sin((server.getTicks() * Math.PI * 2) / RccServer.CONFIG.tabPhaseFrequency()) + 1) / 2d;
|
||||||
var playerContext = PlaceholderContext.of(player);
|
|
||||||
Component headerComponent = Component.empty();
|
server.getPlayerManager().getPlayerList().forEach(player -> {
|
||||||
for (int i = 0; i < RccServer.CONFIG.tabHeader().size(); i++) {
|
var playerContext = PlaceholderContext.of(player);
|
||||||
var line = RccServer.CONFIG.tabHeader().get(i);
|
Component headerComponent = Component.empty();
|
||||||
line = line.replace("{phase}", String.valueOf(phase));
|
for (int i = 0; i < RccServer.CONFIG.tabHeader().size(); i++) {
|
||||||
if (i > 0) {
|
var line = RccServer.CONFIG.tabHeader().get(i);
|
||||||
headerComponent = headerComponent.appendNewline();
|
line = line.replace("{phase}", String.valueOf(phase));
|
||||||
|
if (i > 0) {
|
||||||
|
headerComponent = headerComponent.appendNewline();
|
||||||
|
}
|
||||||
|
|
||||||
|
headerComponent = headerComponent.append(minimessage.deserialize(line));
|
||||||
}
|
}
|
||||||
|
|
||||||
headerComponent = headerComponent.append(minimessage.deserialize(line));
|
Component footerComponent = Component.empty();
|
||||||
}
|
for (int i = 0; i < RccServer.CONFIG.tabFooter().size(); i++) {
|
||||||
|
var line = RccServer.CONFIG.tabFooter().get(i);
|
||||||
|
line = line.replace("{phase}", String.valueOf(phase));
|
||||||
|
if (i > 0) {
|
||||||
|
footerComponent = footerComponent.appendNewline();
|
||||||
|
}
|
||||||
|
|
||||||
Component footerComponent = Component.empty();
|
footerComponent = footerComponent.append(minimessage.deserialize(line));
|
||||||
for (int i = 0; i < RccServer.CONFIG.tabFooter().size(); i++) {
|
|
||||||
var line = RccServer.CONFIG.tabFooter().get(i);
|
|
||||||
line = line.replace("{phase}", String.valueOf(phase));
|
|
||||||
if (i > 0) {
|
|
||||||
footerComponent = footerComponent.appendNewline();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
footerComponent = footerComponent.append(minimessage.deserialize(line));
|
var parsedHeader = Placeholders.parseText(Components.toText(headerComponent), playerContext);
|
||||||
}
|
var parsedFooter = Placeholders.parseText(Components.toText(footerComponent), playerContext);
|
||||||
|
|
||||||
var parsedHeader = Placeholders.parseText(Components.toText(headerComponent), playerContext);
|
var audience = RccServer.getInstance().adventure().player(player.getUuid());
|
||||||
var parsedFooter = Placeholders.parseText(Components.toText(footerComponent), playerContext);
|
audience.sendPlayerListHeaderAndFooter(parsedHeader, parsedFooter);
|
||||||
|
});
|
||||||
var audience = RccServer.getInstance().adventure().player(player.getUuid());
|
}
|
||||||
audience.sendPlayerListHeaderAndFooter(parsedHeader, parsedFooter);
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue