diff --git a/plugins/exilepearl-paper/src/main/java/com/devotedmc/ExilePearl/command/CmdShowAllPearls.java b/plugins/exilepearl-paper/src/main/java/com/devotedmc/ExilePearl/command/CmdShowAllPearls.java index 0a42c30e1..0eb26358e 100644 --- a/plugins/exilepearl-paper/src/main/java/com/devotedmc/ExilePearl/command/CmdShowAllPearls.java +++ b/plugins/exilepearl-paper/src/main/java/com/devotedmc/ExilePearl/command/CmdShowAllPearls.java @@ -18,6 +18,7 @@ import java.util.function.Supplier; import java.util.stream.Collectors; import net.kyori.adventure.text.Component; import net.kyori.adventure.text.format.NamedTextColor; +import net.kyori.adventure.text.format.TextDecoration; import net.md_5.bungee.api.ChatColor; import org.apache.commons.collections4.ComparatorUtils; import org.apache.commons.collections4.list.LazyList; @@ -43,6 +44,7 @@ public class CmdShowAllPearls extends PearlCommand { private static final DateFormat DATE_FORMAT = new SimpleDateFormat("dd MMM yyyy"); private static final Map COOLDOWNS = new HashMap<>(); private static final long COOLDOWN = 10_000; // 10 seconds + private boolean bannedPearlToggle = true; public CmdShowAllPearls(final ExilePearlApi pearlApi) { super(pearlApi); @@ -65,6 +67,10 @@ public class CmdShowAllPearls extends PearlCommand { } COOLDOWNS.put(sender.getUniqueId(), now); + generateOpenPearlsMenu(sender); + } + + private void generateOpenPearlsMenu(Player sender) { final Location senderLocation = sender.getLocation(); final double pearlExclusionRadius = this.plugin.getPearlConfig().getRulePearlRadius() * 1.2; final boolean isBanStickEnabled = this.plugin.isBanStickEnabled(); @@ -72,6 +78,14 @@ public class CmdShowAllPearls extends PearlCommand { final List> contentSuppliers = this.plugin.getPearls().stream() // Sort pearls from newest to oldest .sorted(ComparatorUtils.reversedComparator(Comparator.comparing(ExilePearl::getPearledOn))) + .filter((pearl) -> { + if (bannedPearlToggle) { + final boolean isPlayerBanned = isBanStickEnabled + && BanHandler.isPlayerBanned(pearl.getPlayerId()); + + return !isPlayerBanned; + } else return true; + }) .>map((pearl) -> () -> { final Location pearlLocation = pearl.getLocation(); final boolean isPlayerBanned = isBanStickEnabled @@ -188,7 +202,38 @@ public class CmdShowAllPearls extends PearlCommand { } LazyList lazyContents = MoreCollectionUtils.lazyList(contentSuppliers); - new MultiPageView(sender, lazyContents, "All Pearls", true).showScreen(); + final var pageView = new MultiPageView(sender, lazyContents, "All Pearls", true); + + pageView.setMenuSlot(contructBannedPearlsToggleClick(), 4); + pageView.showScreen(); } + private IClickable contructBannedPearlsToggleClick() { + final var item = new ItemStack(Material.BARRIER); + ItemUtils.handleItemMeta(item, (final ItemMeta meta) -> { + meta.displayName(Component.text() + .decoration(TextDecoration.ITALIC, false) + .color(NamedTextColor.GOLD) + .content("Toggle banned pearls") + .build()); + MetaUtils.setComponentLore(meta, + Component.text() + .decoration(TextDecoration.ITALIC, false) + .color(NamedTextColor.AQUA) + .content("Currently turned " + (!bannedPearlToggle ? "on" : "off")) + .build()); + return true; + }); + return new Clickable(item) { + @Override + public void clicked(final Player clicker) { + bannedPearlToggle = !bannedPearlToggle; + clicker.sendMessage(Component.text() + .color(NamedTextColor.GREEN) + .content("Banned pearls toggled " + (!bannedPearlToggle ? "on" : "off")) + .build()); + generateOpenPearlsMenu(clicker); + } + }; + } }