mirror of
https://github.com/CivMC/Civ.git
synced 2026-07-18 00:20:44 +00:00
add toggle option for banned players in showall
This commit is contained in:
@@ -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<UUID, Long> 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<Supplier<IClickable>> 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;
|
||||
})
|
||||
.<Supplier<IClickable>>map((pearl) -> () -> {
|
||||
final Location pearlLocation = pearl.getLocation();
|
||||
final boolean isPlayerBanned = isBanStickEnabled
|
||||
@@ -188,7 +202,38 @@ public class CmdShowAllPearls extends PearlCommand {
|
||||
}
|
||||
|
||||
LazyList<IClickable> 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);
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user