Skip to content

Commit

Permalink
Only show staff if event host add menu (#68)
Browse files Browse the repository at this point in the history
Signed-off-by: Christopher White <[email protected]>
  • Loading branch information
cswhite2000 authored Jun 30, 2024
1 parent a20c415 commit 1670d3f
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 29 deletions.
23 changes: 13 additions & 10 deletions src/main/java/dev/pgm/community/menu/PlayerSelectionProvider.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import java.util.Comparator;
import java.util.List;
import java.util.function.Consumer;
import java.util.function.Predicate;
import java.util.stream.Collectors;
import org.bukkit.Bukkit;
import org.bukkit.Material;
Expand Down Expand Up @@ -40,7 +41,7 @@ public void open(Player viewer) {
@Override
public void init(Player player, InventoryContents contents) {
Pagination page = contents.pagination();
page.setItems(getAllPlayers(player));
page.setItems(getFilteredPlayers(player));
page.setItemsPerPage(45);

page.addToIterator(contents.newIterator(SlotIterator.Type.HORIZONTAL, 0, 0));
Expand Down Expand Up @@ -84,16 +85,18 @@ public ItemStack getNamedItem(String text, Material material, int amount) {
return stack;
}

private Comparator<Player> COMPARE =
Comparator.comparing(
Player::getName,
(p1, p2) -> {
return p1.compareToIgnoreCase(p2);
});
private final Comparator<Player> COMPARE =
Comparator.comparing(Player::getName, String::compareToIgnoreCase);

private ClickableItem[] getAllPlayers(Player viewer) {
List<Player> online =
Bukkit.getOnlinePlayers().stream().sorted(COMPARE).collect(Collectors.toList());
public Predicate<Player> relevantPlayerFilter() {
return (player) -> true;
}

private ClickableItem[] getFilteredPlayers(Player viewer) {
List<Player> online = Bukkit.getOnlinePlayers().stream()
.filter(relevantPlayerFilter())
.sorted(COMPARE)
.collect(Collectors.toList());
ClickableItem[] items = new ClickableItem[online.size()];
for (int i = 0; i < online.size(); i++) {
Player player = online.get(i);
Expand Down
36 changes: 17 additions & 19 deletions src/main/java/dev/pgm/community/party/menu/hosts/HostAddMenu.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import fr.minuskube.inv.content.InventoryContents;
import java.util.List;
import java.util.function.Consumer;
import java.util.function.Predicate;
import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.entity.Player;
Expand All @@ -24,26 +25,26 @@ public class HostAddMenu extends PlayerSelectionProvider {

public HostAddMenu(MapPartyHosts hosts) {
this.hosts = hosts;
this.inventory =
SmartInventory.builder()
.size(6, 9)
.manager(Community.get().getInventory())
.provider(this)
.title(colorize("&a&lAdd New Host&7:"))
.build();
this.inventory = SmartInventory.builder()
.size(6, 9)
.manager(Community.get().getInventory())
.provider(this)
.title(colorize("&a&lAdd New Host&7:"))
.build();
}

@Override
public void init(Player player, InventoryContents contents) {
super.init(player, contents);
contents.set(
5,
4,
ClickableItem.of(
getNamedItem("&7Return to &aEvent Hosts", Material.CAKE, 1),
c -> {
Bukkit.dispatchCommand(player, "event hosts");
}));
5, 4, ClickableItem.of(getNamedItem("&7Return to &aEvent Hosts", Material.CAKE, 1), c -> {
Bukkit.dispatchCommand(player, "event hosts");
}));
}

@Override
public Predicate<Player> relevantPlayerFilter() {
return player -> player.hasPermission(CommunityPermissions.STAFF);
}

@Override
Expand All @@ -65,10 +66,7 @@ public Consumer<InventoryClickEvent> getClickEvent(Player target) {
@Override
public List<String> getPlayerLore(Player viewer, Player player) {
boolean isHost = hosts.isHost(player.getUniqueId());
return Lists.newArrayList(
colorize(
isHost
? "&cAlready a host"
: "&aClick to make " + player.getDisplayName() + " &aa host"));
return Lists.newArrayList(colorize(
isHost ? "&cAlready a host" : "&aClick to make " + player.getDisplayName() + " &aa host"));
}
}

0 comments on commit 1670d3f

Please sign in to comment.