Skip to content

Commit

Permalink
Update SelectorGui.java
Browse files Browse the repository at this point in the history
  • Loading branch information
Teddy563 authored Aug 7, 2024
1 parent 23075a2 commit ca84871
Showing 1 changed file with 46 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,13 @@ public static void openGui(Player player) {
menu.setAutomaticPaginationEnabled(true);
menu.setBlockDefaultInteractions(true);

// Add gray stained glass pane outline
for (int i = 0; i < 45; i++) {
if (i < 9 || i > 35 || i % 9 == 0 || i % 9 == 8) {
menu.setButton(i, new SGButton(new ItemBuilder(XMaterial.GRAY_STAINED_GLASS_PANE.parseItem()).name(" ").build()));
}
}

List<ServerRecord> filteredServers = new ArrayList<>(records);

filteredServers.sort(Comparator.comparing(s -> s.online() ? 0 : 1));
Expand All @@ -64,37 +71,53 @@ public static void openGui(Player player) {

final boolean showOffline = instance.getConfig().getBoolean("gui.selector.menu.show-offline");

serversPage.stream()
.filter(server -> showOffline || server.online())
.forEach(server -> {
boolean online = server.online();
XMaterial material = online ? onlinexMaterial : offlinexMaterial;
List<String> onlineLore = Formatter.format(server,
instance.getConfig().getStringList("gui.selector.menu.online.lore"));
int slot = 10; // Start at the first slot of the second row
for (ServerRecord server : serversPage) {
if (!showOffline && !server.online()) {
continue;
}

if (slot % 9 == 8) {
slot += 2; // Skip the outline columns
}

if (slot >= 35) {
break; // Stop if we've filled all available slots
}

boolean online = server.online();
XMaterial material = online ? onlinexMaterial : offlinexMaterial;
List<String> onlineLore = Formatter.format(server,
instance.getConfig().getStringList("gui.selector.menu.online.lore"));

List<String> offlineLore = Formatter.format(server,
instance.getConfig().getStringList("gui.selector.menu.offline.lore"));
List<String> offlineLore = Formatter.format(server,
instance.getConfig().getStringList("gui.selector.menu.offline.lore"));

String onlineName = Formatter.format(server,
instance.getConfig().getString("gui.selector.menu.online.name"));
String onlineName = Formatter.format(server,
instance.getConfig().getString("gui.selector.menu.online.name"));

String offlineName = Formatter.format(server,
instance.getConfig().getString("gui.selector.menu.offline.name"));
String offlineName = Formatter.format(server,
instance.getConfig().getString("gui.selector.menu.offline.name"));

ItemBuilder itemBuilder = new ItemBuilder(material.parseMaterial())
.name(online ? onlineName : offlineName);
ItemBuilder itemBuilder = new ItemBuilder(material.parseMaterial())
.name(online ? onlineName : offlineName);

ItemStack item = itemBuilder
.lore(online ? onlineLore : offlineLore)
.skullOwner(server.name() == null ? "" : server.name())
.build();
ItemStack item = itemBuilder
.lore(online ? onlineLore : offlineLore)
.skullOwner(server.name() == null ? "" : server.name())
.build();

menu.addButton(new SGButton(item).withListener(
listener -> BungeeUtil.connectPlayer(player, server.name())));
});
menu.setButton(slot, new SGButton(item).withListener(
listener -> BungeeUtil.connectPlayer(player, server.name())));

slot++;
}

// Add page buttons at the bottom
menu.setButton(36, menu.previousPageButton());
menu.setButton(44, menu.nextPageButton());

XSound.BLOCK_NOTE_BLOCK_BASS.play(player);
player.openInventory(menu.getInventory());
}

}

0 comments on commit ca84871

Please sign in to comment.