Search in sources :

Example 1 with MultiPagedGUI

use of biz.princeps.lib.gui.MultiPagedGUI in project LandLord by SpatiumPrinceps.

the class AbstractManage method create.

@Override
protected void create() {
    List<String> regenerateDesc = lm.getStringList("Commands.Manage.Regenerate.description");
    List<String> greetDesc = lm.getStringList("Commands.Manage.SetGreet.description");
    List<String> farewellDesc = lm.getStringList("Commands.Manage.SetFarewell.description");
    int position = 0;
    if (regions.size() < 1)
        return;
    OwnedLand land = regions.get(0);
    for (LLFlag iFlag : land.getFlags()) {
        // For every IFlag of the land we wanna display an icon in the gui IF the flag is enabled for change
        String flagName = iFlag.getWGFlag().getName();
        String title = lm.getRawString("Commands.Manage.Allow" + flagName.substring(0, 1).toUpperCase() + flagName.substring(1) + ".title");
        List<String> description = lm.getStringList("Commands.Manage.Allow" + flagName.substring(0, 1).toUpperCase() + flagName.substring(1) + ".description");
        if (plugin.getConfig().getBoolean("Manage." + flagName + ".enable")) {
            int finalPosition = position;
            this.setIcon(position, new Icon(createItem(iFlag.getMaterial(), 1, title, formatList(description, iFlag.getStatus()))).addClickAction((p, icon) -> {
                for (OwnedLand region : regions) {
                    for (LLFlag llFlag : region.getFlags()) {
                        if (llFlag.getWGFlag().equals(iFlag.getWGFlag())) {
                            llFlag.toggle();
                        }
                    }
                }
                updateLore(finalPosition, formatList(description, iFlag.getStatus()));
            }));
            position++;
        }
    }
    // Reminder: Regenerate is not implemented in Manageall, cos it might cos some trouble. Calculating costs might be a bit tedious
    if (plugin.getConfig().getBoolean("Manage.regenerate.enable") && regions.size() == 1) {
        double cost = plugin.getConfig().getDouble("ResetCost");
        this.setIcon(position, new Icon(createItem(Material.BARRIER, 1, lm.getRawString("Commands.Manage.Regenerate.title"), formatList(regenerateDesc, (Options.isVaultEnabled() ? plugin.getVaultHandler().format(cost) : "-1")))).addClickAction((p, ic) -> {
            if (land.isOwner(player.getUniqueId())) {
                ConfirmationGUI confi = new ConfirmationGUI(p, lm.getRawString("Commands.Manage.Regenerate.confirmation").replace("%cost%", (Options.isVaultEnabled() ? plugin.getVaultHandler().format(cost) : "-1")), (p1, ic1) -> {
                    boolean flag = false;
                    if (Options.isVaultEnabled())
                        if (plugin.getVaultHandler().hasBalance(player.getUniqueId(), cost)) {
                            plugin.getVaultHandler().take(player.getUniqueId(), cost);
                            flag = true;
                        } else
                            player.sendMessage(lm.getString("Commands.Manage.Regenerate.notEnoughMoney").replace("%cost%", plugin.getVaultHandler().format(cost)).replace("%name%", land.getName()));
                    else
                        flag = true;
                    if (flag) {
                        if (land.isOwner(player.getUniqueId())) {
                            player.getWorld().regenerateChunk(land.getChunk().getX(), land.getChunk().getZ());
                            player.sendMessage(lm.getString("Commands.Manage.Regenerate.success").replace("%land%", land.getName()));
                            display();
                        }
                    }
                }, (p2, ic2) -> {
                    player.sendMessage(lm.getString("Commands.Manage.Regenerate.abort").replace("%land%", land.getName()));
                    display();
                }, this);
                confi.setConfirm(lm.getRawString("Confirmation.accept"));
                confi.setDecline(lm.getRawString("Confirmation.decline"));
                confi.display();
            }
        }));
        position++;
    }
    // Set greet icon
    if (plugin.getConfig().getBoolean("Manage.setgreet.enable")) {
        String currentGreet = land.getWGLand().getFlag(DefaultFlag.GREET_MESSAGE);
        this.setIcon(position, new Icon(createItem(Material.valueOf(plugin.getConfig().getString("Manage.setgreet.item")), 1, lm.getRawString("Commands.Manage.SetGreet.title"), formatList(greetDesc, currentGreet))).addClickAction(((p, ic) -> {
            p.closeInventory();
            ComponentBuilder builder = new ComponentBuilder(lm.getString("Commands.Manage.SetGreet.clickMsg"));
            if (regions.size() > 1)
                builder.event(new ClickEvent(ClickEvent.Action.SUGGEST_COMMAND, "/land manage setgreetall "));
            else
                builder.event(new ClickEvent(ClickEvent.Action.SUGGEST_COMMAND, "/land manage setgreet "));
            p.spigot().sendMessage(builder.create());
        })));
        position++;
    }
    // TODO add functionality for manageall
    if (plugin.getConfig().getBoolean("Manage.mob-spawning.enable")) {
        String title = lm.getRawString("Commands.Manage.AllowMob-spawning.title");
        this.setIcon(position, new Icon(createItem(Material.valueOf(plugin.getConfig().getString("Manage.mob-spawning.item")), 1, title, lm.getStringList("Commands.Manage.AllowMob-spawning.description"))).addClickAction((p, icon) -> {
            // Open a new gui with spawneggs where you can manage the spawns by clicking on them
            List<Icon> icons = new ArrayList<>();
            EntityType[] types = EntityType.values();
            List<String> lore = lm.getStringList("Commands.Manage.AllowMob-spawning.toggleItem.description");
            MultiPagedGUI gui = new MultiPagedGUI(p, 4, title, icons, this) {
            };
            for (EntityType t : types) {
                if (t.isAlive() && t.isSpawnable()) {
                    if (!toggleMobs.contains(t.name()))
                        continue;
                    ItemStack spawnEgg = new ItemStack(Material.MONSTER_EGG);
                    SpawnEggMeta meta = (SpawnEggMeta) spawnEgg.getItemMeta();
                    meta.setSpawnedType(t);
                    meta.setDisplayName(lm.getRawString("Commands.Manage.AllowMob-spawning.toggleItem.title").replace("%mob%", t.name()));
                    Set<EntityType> flag = land.getWGLand().getFlag(DefaultFlag.DENY_SPAWN);
                    String state;
                    if (flag != null)
                        state = (flag.contains(t) ? "DENY" : "ALLOW");
                    else
                        state = "ALLOW";
                    List<String> formattedLore = new ArrayList<>();
                    for (String s : lore) {
                        formattedLore.add(s.replace("%mob%", t.name()).replace("%value%", state));
                    }
                    meta.setLore(formattedLore);
                    spawnEgg.setItemMeta(meta);
                    Icon ic = new Icon(spawnEgg).addClickAction((clickingPlayer, ic3) -> {
                        for (OwnedLand region : regions) {
                            Set<EntityType> localFlag = region.getWGLand().getFlag(DefaultFlag.DENY_SPAWN);
                            // Toggle spawning of specific mob
                            if (localFlag != null) {
                                if (localFlag.contains(t))
                                    localFlag.remove(t);
                                else
                                    localFlag.add(t);
                            } else {
                                Set<EntityType> set = new HashSet<>();
                                set.add(t);
                                region.getWGLand().setFlag(DefaultFlag.DENY_SPAWN, set);
                            }
                        }
                        // update icon text
                        String iconState;
                        if (flag != null)
                            iconState = (flag.contains(t) ? "DENY" : "ALLOW");
                        else
                            iconState = "ALLOW";
                        List<String> newLore = new ArrayList<>();
                        for (String s : lore) {
                            newLore.add(s.replace("%mob%", t.name()).replace("%value%", iconState));
                        }
                        // System.out.println(newLore + " :" + finalIconPos);
                        ic3.setLore(newLore);
                        gui.refresh();
                    });
                    icons.add(ic);
                }
            }
            gui.display();
        }));
        position++;
    }
    // set farewell icon
    if (plugin.getConfig().getBoolean("Manage.setfarewell.enable")) {
        String currentFarewell = land.getWGLand().getFlag(DefaultFlag.FAREWELL_MESSAGE);
        this.setIcon(position, new Icon(createItem(Material.valueOf(plugin.getConfig().getString("Manage.setfarewell.item")), 1, lm.getRawString("Commands.Manage.SetFarewell.title"), formatList(farewellDesc, currentFarewell))).addClickAction(((p, icon) -> {
            p.closeInventory();
            ComponentBuilder builder = new ComponentBuilder(lm.getString("Commands.Manage.SetFarewell.clickMsg"));
            if (regions.size() > 1)
                builder.event(new ClickEvent(ClickEvent.Action.SUGGEST_COMMAND, "/land manage setfarewellall "));
            else
                builder.event(new ClickEvent(ClickEvent.Action.SUGGEST_COMMAND, "/land manage setfarewell "));
            p.spigot().sendMessage(builder.create());
        })));
        position++;
    }
    // set friends icon
    if (plugin.getConfig().getBoolean("Manage.friends.enable")) {
        ItemStack skull = createSkull(player.getName(), lm.getRawString("Commands.Manage.ManageFriends.title"), lm.getStringList("Commands.Manage.ManageFriends.description"));
        Set<UUID> friends = land.getWGLand().getMembers().getUniqueIds();
        MultiPagedGUI friendsGui = new MultiPagedGUI(player, (int) Math.ceil((double) friends.size() / 9.0), lm.getRawString("Commands.Manage.ManageFriends.title"), new ArrayList<>(), this) {
        };
        friends.forEach(id -> friendsGui.addIcon(new Icon(createSkull(Bukkit.getOfflinePlayer(id).getName(), Bukkit.getOfflinePlayer(id).getName(), formatFriendsSegment(id))).addClickAction((player, icon) -> {
            ConfirmationGUI confirmationGUI = new ConfirmationGUI(player, lm.getRawString("Commands.Manage.ManageFriends.unfriend").replace("%player%", Bukkit.getOfflinePlayer(id).getName()), (p, ic1) -> {
                friendsGui.removeIcon(friendsGui.filter(Bukkit.getOfflinePlayer(id).getName()).get(0));
                if (regions.size() > 1)
                    Bukkit.dispatchCommand(player, "land unfriendall " + Bukkit.getOfflinePlayer(id).getName());
                else
                    Bukkit.dispatchCommand(player, "land unfriend " + Bukkit.getOfflinePlayer(id).getName());
                player.closeInventory();
                friendsGui.display();
            }, (p, ic2) -> {
                player.closeInventory();
                friendsGui.display();
            }, friendsGui);
            confirmationGUI.setConfirm(lm.getRawString("Confirmation.accept"));
            confirmationGUI.setDecline(lm.getRawString("Confirmation.decline"));
            confirmationGUI.display();
        })));
        this.setIcon(position, new Icon(skull).setName(lm.getRawString("Commands.Manage.ManageFriends.title")).addClickAction((p, ic) -> friendsGui.display()));
        position++;
    }
    if (plugin.getConfig().getBoolean("Manage.unclaim.enable")) {
        this.setIcon(position, new Icon(createItem(Material.valueOf(plugin.getConfig().getString("Manage.unclaim.item")), 1, lm.getRawString("Commands.Manage.Unclaim.title"), lm.getStringList("Commands.Manage.Unclaim.description"))).addClickAction(((player1, icon) -> {
            ConfirmationGUI gui = new ConfirmationGUI(player1, lm.getRawString("Commands.Manage.Unclaim.confirmationTitle").replace("%land%", land.getName()), (p, ic2) -> {
                if (regions.size() > 1)
                    Bukkit.dispatchCommand(p, "ll unclaimall");
                else
                    Bukkit.dispatchCommand(p, "ll unclaim " + land.getName());
                p.closeInventory();
            }, (p, ic) -> {
                p.closeInventory();
                display();
            }, this);
            gui.setConfirm(lm.getRawString("Confirmation.accept"));
            gui.setDecline(lm.getRawString("Confirmation.decline"));
            gui.display();
        })));
        position++;
    }
}
Also used : MultiPagedGUI(biz.princeps.lib.gui.MultiPagedGUI) java.util(java.util) ItemMeta(org.bukkit.inventory.meta.ItemMeta) ClickEvent(net.md_5.bungee.api.chat.ClickEvent) LLFlag(biz.princeps.landlord.flags.LLFlag) ConfigurationSection(org.bukkit.configuration.ConfigurationSection) Landlord(biz.princeps.landlord.Landlord) OwnedLand(biz.princeps.landlord.util.OwnedLand) CompletableFuture(java.util.concurrent.CompletableFuture) Player(org.bukkit.entity.Player) SkullMeta(org.bukkit.inventory.meta.SkullMeta) DefaultFlag(com.sk89q.worldguard.protection.flags.DefaultFlag) ComponentBuilder(net.md_5.bungee.api.chat.ComponentBuilder) Conditions(biz.princeps.lib.storage.requests.Conditions) SpawnEggMeta(org.bukkit.inventory.meta.SpawnEggMeta) Material(org.bukkit.Material) Bukkit(org.bukkit.Bukkit) ConfirmationGUI(biz.princeps.lib.gui.ConfirmationGUI) LPlayer(biz.princeps.landlord.persistent.LPlayer) Options(biz.princeps.landlord.api.Options) EntityType(org.bukkit.entity.EntityType) OfflinePlayer(org.bukkit.OfflinePlayer) ItemStack(org.bukkit.inventory.ItemStack) ExecutionException(java.util.concurrent.ExecutionException) AbstractGUI(biz.princeps.lib.gui.simple.AbstractGUI) LangManager(biz.princeps.landlord.manager.LangManager) Icon(biz.princeps.lib.gui.simple.Icon) SpawnEggMeta(org.bukkit.inventory.meta.SpawnEggMeta) OwnedLand(biz.princeps.landlord.util.OwnedLand) ClickEvent(net.md_5.bungee.api.chat.ClickEvent) LLFlag(biz.princeps.landlord.flags.LLFlag) EntityType(org.bukkit.entity.EntityType) MultiPagedGUI(biz.princeps.lib.gui.MultiPagedGUI) ConfirmationGUI(biz.princeps.lib.gui.ConfirmationGUI) Icon(biz.princeps.lib.gui.simple.Icon) ItemStack(org.bukkit.inventory.ItemStack) ComponentBuilder(net.md_5.bungee.api.chat.ComponentBuilder)

Example 2 with MultiPagedGUI

use of biz.princeps.lib.gui.MultiPagedGUI in project LandLord by SpatiumPrinceps.

the class ListLands method onListLands.

public void onListLands(Player sender, LPlayer target, int page) {
    List<ProtectedRegion> lands = new ArrayList<>(plugin.getWgHandler().getRegions(target.getUuid()));
    if (lands.size() > 0) {
        String mode = plugin.getConfig().getString("CommandSettings.ListLands.mode");
        if (mode.equals("gui")) {
            MultiPagedGUI landGui = new MultiPagedGUI(sender, 5, plugin.getLangManager().getRawString("Commands.ListLands.header").replace("%player%", target.getName()));
            lands.forEach(land -> landGui.addIcon(new Icon(new ItemStack(Material.GRASS)).setName(land.getId())));
            landGui.setIcon(52, new Icon(new ItemStack(Material.BEACON)).setName(lm.getRawString("Commands.ListLands.manageAll")).addClickAction((p, ic2) -> {
                ManageGUIAll manageGUIAll = new ManageGUIAll(sender, landGui, plugin.getWgHandler().getRegionsAsOL(target.getUuid()));
                manageGUIAll.display();
            }));
            landGui.display();
        } else {
            // Chat based system
            List<String> formatted = new ArrayList<>();
            String segment = lm.getRawString("Commands.ListLands.chat.segment");
            lands.forEach(land -> {
                OwnedLand ol = plugin.getLand(land);
                formatted.add(segment.replace("%landname%", ol.getName()).replace("%members%", ol.printMembers()));
            });
            String prev = lm.getRawString("Commands.ListLands.chat.previous");
            String next = lm.getRawString("Commands.ListLands.chat.next");
            MultiPagedMessage message = new MultiPagedMessage("/land list", plugin.getLangManager().getRawString("Commands.ListLands.header").replace("%player%", target.getName()), plugin.getConfig().getInt("CommandSettings.ListLands.landsPerPage"), formatted, prev, next, page);
            sender.spigot().sendMessage(message.create());
        }
    } else {
        sender.sendMessage(plugin.getLangManager().getString("Commands.ListLands.noLands"));
    }
}
Also used : MultiPagedGUI(biz.princeps.lib.gui.MultiPagedGUI) LandlordCommand(biz.princeps.landlord.commands.LandlordCommand) ManageGUIAll(biz.princeps.landlord.guis.ManageGUIAll) ProtectedRegion(com.sk89q.worldguard.protection.regions.ProtectedRegion) LPlayer(biz.princeps.landlord.persistent.LPlayer) OwnedLand(biz.princeps.landlord.util.OwnedLand) Player(org.bukkit.entity.Player) OfflinePlayer(org.bukkit.OfflinePlayer) ItemStack(org.bukkit.inventory.ItemStack) ArrayList(java.util.ArrayList) List(java.util.List) MultiPagedMessage(biz.princeps.lib.chat.MultiPagedMessage) Icon(biz.princeps.lib.gui.simple.Icon) Material(org.bukkit.Material) ManageGUIAll(biz.princeps.landlord.guis.ManageGUIAll) MultiPagedGUI(biz.princeps.lib.gui.MultiPagedGUI) OwnedLand(biz.princeps.landlord.util.OwnedLand) ProtectedRegion(com.sk89q.worldguard.protection.regions.ProtectedRegion) ArrayList(java.util.ArrayList) Icon(biz.princeps.lib.gui.simple.Icon) MultiPagedMessage(biz.princeps.lib.chat.MultiPagedMessage) ItemStack(org.bukkit.inventory.ItemStack)

Aggregations

LPlayer (biz.princeps.landlord.persistent.LPlayer)2 OwnedLand (biz.princeps.landlord.util.OwnedLand)2 MultiPagedGUI (biz.princeps.lib.gui.MultiPagedGUI)2 Icon (biz.princeps.lib.gui.simple.Icon)2 Material (org.bukkit.Material)2 OfflinePlayer (org.bukkit.OfflinePlayer)2 Player (org.bukkit.entity.Player)2 ItemStack (org.bukkit.inventory.ItemStack)2 Landlord (biz.princeps.landlord.Landlord)1 Options (biz.princeps.landlord.api.Options)1 LandlordCommand (biz.princeps.landlord.commands.LandlordCommand)1 LLFlag (biz.princeps.landlord.flags.LLFlag)1 ManageGUIAll (biz.princeps.landlord.guis.ManageGUIAll)1 LangManager (biz.princeps.landlord.manager.LangManager)1 MultiPagedMessage (biz.princeps.lib.chat.MultiPagedMessage)1 ConfirmationGUI (biz.princeps.lib.gui.ConfirmationGUI)1 AbstractGUI (biz.princeps.lib.gui.simple.AbstractGUI)1 Conditions (biz.princeps.lib.storage.requests.Conditions)1 DefaultFlag (com.sk89q.worldguard.protection.flags.DefaultFlag)1 ProtectedRegion (com.sk89q.worldguard.protection.regions.ProtectedRegion)1