Search in sources :

Example 1 with GUI

use of me.gameisntover.kbffa.gui.GUI in project KnockbackFFA by GaMeIsNtOvEr.

the class GuiStuff method onPlayerItemInteract.

@EventHandler
public void onPlayerItemInteract(PlayerInteractEvent e) {
    ItemStack item = e.getItem();
    if (item == null || item.getItemMeta() == null)
        return;
    ItemMeta itemMeta = item.getItemMeta();
    Player player = e.getPlayer();
    if (e.getAction() != Action.RIGHT_CLICK_AIR && e.getAction() != Action.RIGHT_CLICK_BLOCK)
        return;
    Knocker knocker = KnockbackFFA.getInstance().getKnocker(player);
    assert itemMeta != null;
    assert Items.COSMETIC_ITEM.getItem() != null;
    if (Items.COSMETIC_ITEM.getItem().equals(item)) {
        e.setCancelled(true);
        GUI cosmeticMenu = new GUI("Cosmetic Menu", (short) 5);
        List<String> cList = knocker.getConfig().getStringList("owned-cosmetics");
        cList.forEach(cosmetic -> {
            if (KnockbackFFA.getInstance().getCosmeticConfiguration().getConfig.getString(cosmetic + ".name") != null) {
                String displayName = ChatColor.translateAlternateColorCodes('&', KnockbackFFA.getInstance().getCosmeticConfiguration().getConfig.getString(cosmetic + ".name"));
                String icon = KnockbackFFA.getInstance().getCosmeticConfiguration().getConfig.getString(cosmetic + ".icon");
                List<String> lore = KnockbackFFA.getInstance().getCosmeticConfiguration().getConfig.getStringList(cosmetic + ".lore").stream().map(s -> s.replace("&", "§")).collect(Collectors.toList());
                assert icon != null;
                Button cosmeticItem = KnockbackFFA.getInstance().getButtonManager().create(new ItemBuilder(Material.getMaterial(icon), 1, displayName, Collections.singletonList("")).create(), event -> {
                    List<String> ownedCosmetics = knocker.getConfig().getStringList("owned-cosmetics");
                    String selC = ownedCosmetics.get(event.getSlot());
                    assert event.getCurrentItem() != null;
                    assert event.getCurrentItem().getItemMeta() != null;
                    if (KnockbackFFA.getInstance().getCosmeticConfiguration().getConfig.getString(selC + ".type").equals("KILL_PARTICLE"))
                        knocker.getConfig().set("selected-trails", event.getCurrentItem().getItemMeta().hasEnchant(Enchantment.DURABILITY) ? selC : "");
                    else if (KnockbackFFA.getInstance().getCosmeticConfiguration().getConfig.getString(selC + ".type").equals("TRAIL"))
                        knocker.getConfig().set("selected-trails", event.getCurrentItem().getItemMeta().hasEnchant(Enchantment.DURABILITY) ? selC : "");
                    knocker.saveConfig();
                    player.closeInventory();
                });
                ItemMeta meta = cosmeticItem.getItem().getItemMeta();
                if (KnockbackFFA.getInstance().getCosmeticConfiguration().getConfig.getString(cosmetic + ".type").equals("KILL_PARTICLE")) {
                    if (knocker.getConfig().getString("selected-cosmetic") == null)
                        knocker.getConfig().set("selected-cosmetic", cosmetic);
                    cosmeticItem.setSelected(knocker.getConfig().getString("selected-cosmetic").equals(cosmetic));
                } else if (KnockbackFFA.getInstance().getCosmeticConfiguration().getConfig.getString(cosmetic + ".type").equals("TRAIL"))
                    if (knocker.getConfig().getString("selected-trails") == null)
                        knocker.getConfig().set("selected-trails", cosmetic);
                cosmeticItem.setSelected(knocker.getConfig().getString("selected-trails").equals(cosmetic));
                meta.setLore(lore);
                cosmeticItem.getItem().setItemMeta(meta);
                cosmeticMenu.add(cosmeticItem, cList.indexOf(cosmetic));
            } else {
                cList.remove(cosmetic);
                knocker.getConfig().set("owned-cosmetics", cList);
                knocker.saveConfig();
            }
        });
        cosmeticMenu.setOpenEventConsumer(event -> {
            Player player1 = (Player) event.getPlayer();
            player1.playSound(player1.getLocation(), Sounds.GUI_OPEN.toSound(), 1, 1);
        });
        cosmeticMenu.setCloseEventConsumer(inventoryCloseEvent -> {
            Player player1 = (Player) inventoryCloseEvent.getPlayer();
            player1.playSound(player1.getLocation(), Sounds.GUI_CLOSE.toSound(), 1, 1);
        });
        cosmeticMenu.open(player);
    }
    if (Items.SHOP_ITEM.getItem().equals(item)) {
        e.setCancelled(true);
        GUI shopMenu = new GUI("Shop Menu", (short) 5);
        String cIcon = KnockbackFFA.getInstance().getItems().getConfig.getString("ShopMenu.cosmetic.material");
        String cName = ChatColor.translateAlternateColorCodes('&', KnockbackFFA.getInstance().getItems().getConfig.getString("ShopMenu.cosmetic.name"));
        GUI cosmeticShop = new GUI("Cosmetic Shop", (short) 5);
        Button cosmeticItem = KnockbackFFA.getInstance().getButtonManager().create(new ItemBuilder(Material.getMaterial(cIcon), 1, cName, Arrays.asList("")).create(), event -> {
            List<String> cosmetics = KnockbackFFA.getInstance().getCosmeticConfiguration().getConfig.getList("registered-cosmetics").stream().map(s -> s.toString()).collect(Collectors.toList());
            List<String> cList = knocker.getConfig().getStringList("owned-cosmetics");
            for (String cosmetic : cosmetics) {
                Button cosmeticsItem = KnockbackFFA.getInstance().getButtonManager().create(new ItemBuilder(Material.getMaterial(KnockbackFFA.getInstance().getCosmeticConfiguration().getConfig.getString(cosmetic + ".icon")), 1, ChatColor.translateAlternateColorCodes('&', KnockbackFFA.getInstance().getCosmeticConfiguration().getConfig.getString(cosmetic + ".name")), Collections.singletonList("")).create(), event1 -> {
                    float playerBal = knocker.getBalance();
                    if (playerBal >= KnockbackFFA.getInstance().getCosmeticConfiguration().getConfig.getInt(cosmetics.get(event1.getSlot()) + ".price")) {
                        List<String> ownedCosmetics = knocker.getConfig().getStringList("owned-cosmetics");
                        if (!ownedCosmetics.contains(cosmetics.get(event1.getSlot()))) {
                            knocker.removeBalance(KnockbackFFA.getInstance().getItems().getConfig.getInt(cosmetics.get(event1.getSlot()) + ".price"));
                            ownedCosmetics.add(cosmetics.get(event1.getSlot()));
                            knocker.getConfig().set("owned-cosmetics", ownedCosmetics);
                            knocker.saveConfig();
                            player.sendMessage(Message.COSMETIC_PURCHASE_SUCCESS.toString().replace("&", "§").replace("%cosmetic%", cosmetics.get(event1.getSlot())));
                        } else
                            player.sendMessage(Message.COSMETIC_ALREADY_OWNED.toString().replace("&", "§").replace("%cosmetic%", cosmetics.get(event1.getSlot())));
                    } else
                        player.sendMessage(Message.COSMETIC_NO_ENOUGH_MONEY.toString().replace("&", "§"));
                    player.closeInventory();
                });
                ItemMeta cosmeticMeta = cosmeticsItem.getItem().getItemMeta();
                List<String> lore = KnockbackFFA.getInstance().getCosmeticConfiguration().getConfig.getStringList(cosmetic + ".lore").stream().map(s -> s.replace("&", "§")).collect(Collectors.toList());
                lore.add("§7Cost: §a" + KnockbackFFA.getInstance().getCosmeticConfiguration().getConfig.getInt(cosmetic + ".price"));
                cosmeticMeta.setLore(lore);
                cosmeticsItem.setSelected(cList.contains(cosmetic), "§8(§aOwned§8)");
                cosmeticsItem.getItem().setItemMeta(cosmeticMeta);
                cosmeticShop.add(cosmeticsItem, cosmetics.indexOf(cosmetic));
            }
            knocker.openGUI(cosmeticShop);
        });
        ItemMeta cosmeticMeta = cosmeticItem.getItem().getItemMeta();
        cosmeticMeta.setDisplayName(ChatColor.translateAlternateColorCodes('&', KnockbackFFA.getInstance().getItems().getConfig.getString("ShopMenu.cosmetic.name")));
        cosmeticMeta.setLore(KnockbackFFA.getInstance().getItems().getConfig.getStringList("ShopMenu.cosmetic.lore").stream().map(s -> s.replace("&", "§")).collect(Collectors.toList()));
        cosmeticItem.getItem().setItemMeta(cosmeticMeta);
        shopMenu.add(cosmeticItem, KnockbackFFA.getInstance().getItems().getConfig.getInt("ShopMenu.cosmetic.slot"));
        String kIcon = KnockbackFFA.getInstance().getItems().getConfig.getString("ShopMenu.kit.material");
        String kName = ChatColor.translateAlternateColorCodes('&', KnockbackFFA.getInstance().getItems().getConfig.getString("ShopMenu.kit.name"));
        Button kitItem = KnockbackFFA.getInstance().getButtonManager().create(new ItemBuilder(Material.getMaterial(kIcon), 1, kName, Arrays.asList("")).create(), event -> {
            GUI kitShop = new GUI("Kit Shop", (short) 5);
            List<String> cosmetics = Arrays.asList(KnockbackFFA.getInstance().getKitManager().getFolder().list()).stream().map(s -> s.replace(".yml", "")).collect(Collectors.toList());
            List<String> cList = knocker.getConfig().getStringList("owned-kits");
            for (String cosmetic : cosmetics) {
                if (cosmetic == null)
                    return;
                Kit kit = KnockbackFFA.getInstance().getKitManager().load(cosmetic);
                Button kitsItem = KnockbackFFA.getInstance().getButtonManager().create(new ItemBuilder(kit.getIcon(), 1, kit.getKitName(), Collections.singletonList("")).create(), event1 -> {
                    float playerBal = knocker.getBalance();
                    if (playerBal >= kit.getPrice()) {
                        List<String> ownedKits = knocker.getConfig().getStringList("owned-kits");
                        if (!ownedKits.contains(cosmetics.get(event1.getSlot()))) {
                            knocker.removeBalance(kit.getPrice());
                            ownedKits.add(cosmetics.get(event1.getSlot()));
                            knocker.getConfig().set("owned-kits", ownedKits);
                            knocker.saveConfig();
                            player.closeInventory();
                            player.sendMessage(Message.COSMETIC_PURCHASE_SUCCESS.toString().replace("&", "§").replace("%cosmetic%", cosmetics.get(event1.getSlot())));
                        } else
                            player.sendMessage(Message.COSMETIC_ALREADY_OWNED.toString().replace("&", "§").replace("%cosmetic%", cosmetics.get(event1.getSlot())));
                    } else
                        player.sendMessage(Message.COSMETIC_NO_ENOUGH_MONEY.toString().replace("&", "§"));
                    player.closeInventory();
                });
                if (kitsItem.getItem().getType() == Material.AIR)
                    kitsItem.getItem().setType(Material.BARRIER);
                ItemMeta kitsMeta = kitsItem.getItem().getItemMeta();
                List<String> lore = kit.getConfig().getStringList("KitDescription").stream().map(s -> s.replace("&", "§")).collect(Collectors.toList());
                lore.add("§7Cost: §a" + kit.getPrice());
                kitsMeta.setLore(lore);
                if (cList.contains(cosmetic)) {
                    kitsMeta.addEnchant(Enchantment.DURABILITY, 1, true);
                    kitsMeta.setDisplayName(kitsMeta.getDisplayName().replace("&", "§") + " §8(§aOwned§8)");
                } else {
                    kitsMeta.removeEnchant(Enchantment.DURABILITY);
                    kitsMeta.setDisplayName(kitsMeta.getDisplayName().replace("&", "§").replace(" §8(§aOwned§8)", ""));
                }
                kitsItem.getItem().setItemMeta(kitsMeta);
                kitShop.add(kitsItem, cosmetics.indexOf(cosmetic));
            }
            knocker.openGUI(kitShop);
        });
        ItemMeta kitMeta = kitItem.getItem().getItemMeta();
        kitMeta.setDisplayName(ChatColor.translateAlternateColorCodes('&', KnockbackFFA.getInstance().getItems().getConfig.getString("ShopMenu.kit.name")));
        kitMeta.setLore(KnockbackFFA.getInstance().getItems().getConfig.getStringList("ShopMenu.kit.lore").stream().map(s -> s.replace("&", "§")).collect(Collectors.toList()));
        kitItem.getItem().setItemMeta(kitMeta);
        shopMenu.add(kitItem, KnockbackFFA.getInstance().getItems().getConfig.getInt("ShopMenu.kit.slot"));
        knocker.openGUI(shopMenu);
    }
    assert Items.KIT_ITEM.getItem() != null;
    if (Items.KIT_ITEM.getItem().equals(item)) {
        e.setCancelled(true);
        GUI kitsMenu = new GUI("Kits Menu", (short) 5);
        kitsMenu.setOpenEventConsumer(event -> {
            Player player1 = (Player) event.getPlayer();
            player1.playSound(player1.getLocation(), Sounds.GUI_OPEN.toSound(), 1, 1);
        });
        kitsMenu.setCloseEventConsumer(inventoryCloseEvent -> {
            Player player1 = (Player) inventoryCloseEvent.getPlayer();
            player1.playSound(player1.getLocation(), Sounds.GUI_CLOSE.toSound(), 1, 1);
        });
        if (knocker.getConfig().getList("owned-kits") != null && knocker.getConfig().getList("owned-kits").size() > 0) {
            if (knocker.getConfig().getList("owned-kits") == null)
                knocker.getConfig().set("owned-kits", Collections.singletonList("Default"));
            List<String> kitsList = knocker.getConfig().getList("owned-kits").stream().map(Object::toString).collect(Collectors.toList());
            for (String kit : kitsList) {
                if (kit == null)
                    return;
                Kit kitItems = KnockbackFFA.getInstance().getKitManager().load(kit);
                if (kitItems.getIcon() == null)
                    return;
                Button kitItem = KnockbackFFA.getInstance().getButtonManager().create(new ItemBuilder(kitItems.getIcon(), 1, kitItems.getKitName(), Collections.singletonList("")).create(), event -> {
                    String selC = kitsList.get(event.getSlot());
                    assert event.getCurrentItem() != null;
                    assert event.getCurrentItem().getItemMeta() != null;
                    if (!event.getCurrentItem().getItemMeta().hasEnchant(Enchantment.DURABILITY)) {
                        knocker.getConfig().set("selected-kit", selC);
                        player.sendMessage(Message.SUCCESSFULLY_SELECTED_COSMETIC.toString().replace("%cosmetic%", selC));
                    } else {
                        knocker.getConfig().set("selected-kit", "");
                        player.sendMessage(Message.SUCCESSFULLY_DESELECTED_COSMETIC.toString().replace("%cosmetic%", selC));
                    }
                    knocker.saveConfig();
                    player.closeInventory();
                });
                kitItem.setSelected(knocker.getConfig().getString("selected-kit").equalsIgnoreCase(kit));
                ItemMeta kitMeta = kitItem.getItem().getItemMeta();
                if (kitItem.getItem().getType() == Material.AIR)
                    kitItem.getItem().setType(Material.BARRIER);
                assert kitMeta != null;
                kitMeta.setLore(kitItems.getConfig().getStringList("KitDescription").stream().map(s -> s.replace("&", "§")).collect(Collectors.toList()));
                kitItem.getItem().setItemMeta(kitMeta);
                kitsMenu.add(kitItem, kitsList.indexOf(kit));
            }
            knocker.saveConfig();
            kitsMenu.setOpenEventConsumer(event -> {
                Player player1 = (Player) event.getPlayer();
                player1.playSound(player1.getLocation(), Sounds.GUI_OPEN.toSound(), 1, 1);
            });
            kitsMenu.setCloseEventConsumer(inventoryCloseEvent -> {
                Player player1 = (Player) inventoryCloseEvent.getPlayer();
                player1.playSound(player1.getLocation(), Sounds.GUI_CLOSE.toSound(), 1, 1);
            });
        }
        knocker.openGUI(kitsMenu);
    }
}
Also used : ItemFlag(org.bukkit.inventory.ItemFlag) Arrays(java.util.Arrays) Enchantment(org.bukkit.enchantments.Enchantment) ItemMeta(org.bukkit.inventory.meta.ItemMeta) Player(org.bukkit.entity.Player) ItemBuilder(me.gameisntover.kbffa.util.ItemBuilder) Message(me.gameisntover.kbffa.util.Message) Action(org.bukkit.event.block.Action) EventHandler(org.bukkit.event.EventHandler) Kit(me.gameisntover.kbffa.kit.Kit) Items(me.gameisntover.kbffa.util.Items) Sounds(me.gameisntover.kbffa.util.Sounds) PlayerInteractEvent(org.bukkit.event.player.PlayerInteractEvent) Material(org.bukkit.Material) Button(me.gameisntover.kbffa.gui.Button) Listener(org.bukkit.event.Listener) KnockbackFFA(me.gameisntover.kbffa.KnockbackFFA) PlayerDropItemEvent(org.bukkit.event.player.PlayerDropItemEvent) GUI(me.gameisntover.kbffa.gui.GUI) Collectors(java.util.stream.Collectors) ItemStack(org.bukkit.inventory.ItemStack) List(java.util.List) Knocker(me.gameisntover.kbffa.api.Knocker) ChatColor(org.bukkit.ChatColor) Collections(java.util.Collections) Player(org.bukkit.entity.Player) Knocker(me.gameisntover.kbffa.api.Knocker) ItemBuilder(me.gameisntover.kbffa.util.ItemBuilder) Button(me.gameisntover.kbffa.gui.Button) Kit(me.gameisntover.kbffa.kit.Kit) GUI(me.gameisntover.kbffa.gui.GUI) ItemStack(org.bukkit.inventory.ItemStack) ItemMeta(org.bukkit.inventory.meta.ItemMeta) EventHandler(org.bukkit.event.EventHandler)

Example 2 with GUI

use of me.gameisntover.kbffa.gui.GUI in project KnockbackFFA by GaMeIsNtOvEr.

the class EditArenaCommand method perform.

@Override
public void perform(Knocker knocker, String[] args) {
    Player p = knocker.getPlayer();
    if (args.length != 1) {
        p.sendMessage(ChatColor.RED + "Command Arguements missing or is invalid /editarena arenaname");
        return;
    }
    List<String> arenaList = Arrays.asList(KnockbackFFA.getInstance().getArenaManager().getFolder().list());
    if (!arenaList.contains(args[0] + ".yml")) {
        p.sendMessage(ChatColor.RED + "That arena name does not exist!");
        return;
    }
    p.sendMessage(ChatColor.GREEN + "You are now editing " + args[0]);
    Arena arena = KnockbackFFA.getInstance().getArenaManager().load(args[0]);
    GUI arenaGUI = new GUI("Arena Editor", (short) 5);
    List<String> blockbreaklore = new ArrayList<>();
    blockbreaklore.add(ChatColor.GRAY + "Toggle whether or not players can break blocks");
    blockbreaklore.add(ChatColor.GREEN + "Currently Block Breaking is " + arena.getConfig().getBoolean("block-break"));
    Button blockBreak = KnockbackFFA.getInstance().getButtonManager().create(new ItemBuilder(Material.DIAMOND_PICKAXE, 1, ChatColor.GRAY + "Block Break", blockbreaklore).create(ItemFlag.HIDE_ATTRIBUTES), e -> {
        arena.getConfig().set("block-break", !arena.getConfig().getBoolean("block-break"));
        arena.save();
        ItemMeta im = e.getCurrentItem().getItemMeta();
        blockbreaklore.clear();
        blockbreaklore.add(ChatColor.GRAY + "Toggle whether or not players can break blocks");
        blockbreaklore.add(ChatColor.GREEN + "Currently Block Breaking is " + arena.getConfig().getBoolean("block-break"));
        im.setLore(blockbreaklore);
        e.getCurrentItem().setItemMeta(im);
    });
    List<String> itemDropLore = new ArrayList<>();
    itemDropLore.add(ChatColor.GRAY + "Toggle whether or not players can drop items");
    itemDropLore.add(ChatColor.GREEN + "Currently Item Dropping is " + arena.getConfig().getBoolean("item-drop"));
    Button itemDrop = KnockbackFFA.getInstance().getButtonManager().create(new ItemBuilder(Material.DIAMOND, 1, ChatColor.GRAY + "Item Drop", itemDropLore).create(), e -> {
        arena.getConfig().set("item-drop", !arena.getConfig().getBoolean("item-drop"));
        arena.save();
        ItemMeta im = e.getCurrentItem().getItemMeta();
        itemDropLore.clear();
        itemDropLore.add(ChatColor.GRAY + "Toggle whether or not players can drop items");
        itemDropLore.add(ChatColor.GREEN + "Currently Item Dropping is " + arena.getConfig().getBoolean("item-drop"));
        im.setLore(itemDropLore);
        e.getCurrentItem().setItemMeta(im);
    });
    Button setSpawn = KnockbackFFA.getInstance().getButtonManager().create(new ItemBuilder(Material.NETHER_STAR, 1, ChatColor.GRAY + "Set Spawn", Arrays.asList("sets the spawn point of players")).create(), e -> {
        Player player = (Player) e.getWhoClicked();
        arena.getConfig().set("arena.spawn", player.getLocation());
        arena.save();
        player.sendMessage(ChatColor.GREEN + "Arena Spawn Location Set!");
    });
    List<String> autoResetLore = new ArrayList<>();
    autoResetLore.add(ChatColor.GRAY + "Toggle whether or not the arena will reset blocks placed or broke automatically");
    autoResetLore.add(ChatColor.GREEN + "Currently Auto Reset is " + arena.getConfig().getBoolean("auto-reset"));
    Button autoReset = KnockbackFFA.getInstance().getButtonManager().create(new ItemBuilder(Material.DISPENSER, 1, ChatColor.GRAY + "Auto Reset", autoResetLore).create(), e -> {
        arena.getConfig().set("auto-reset", !arena.getConfig().getBoolean("auto-reset"));
        arena.save();
        p.sendMessage("Auto Reset is now set to" + arena.getConfig().getBoolean("auto-reset"));
        if (arena.getConfig().getString("blocks") != null)
            return;
        Location loc1 = arena.getConfig().getLocation("arena.pos1");
        Location loc2 = arena.getConfig().getLocation("arena.pos2");
        List<String> blocks = new ArrayList<>();
        Cuboid region = new Cuboid(loc1, loc2);
        for (Block block : region.getBlocks()) {
            blocks.add(block.getType().name());
        }
        arena.getConfig().set("blocks", blocks);
        arena.save();
        autoResetLore.clear();
        autoResetLore.add(ChatColor.GRAY + "Toggle whether or not the arena will reset blocks placed or broke automatically");
        autoResetLore.add(ChatColor.GREEN + "Currently Auto Reset is " + arena.getConfig().getBoolean("auto-reset"));
        ItemStack item = e.getCurrentItem();
        ItemMeta meta = e.getCurrentItem().getItemMeta();
        meta.setLore(autoResetLore);
        item.setItemMeta(meta);
    });
    Button setpos = KnockbackFFA.getInstance().getButtonManager().create(new ItemBuilder(Material.REDSTONE_BLOCK, 1, ChatColor.GRAY + "Set Position", Arrays.asList(ChatColor.GRAY + "set the new arena positions from here!")).create(), e -> {
        if (WandListener.pos1m.get(e.getWhoClicked()) != null && WandListener.pos2m.get(e.getWhoClicked()) != null) {
            Location loc1 = WandListener.pos1m.get(e.getWhoClicked());
            Location loc2 = WandListener.pos2m.get(e.getWhoClicked());
            BoundingBox box = new BoundingBox(loc1.getX(), loc1.getY(), loc1.getZ(), loc2.getX(), loc2.getY(), loc2.getZ());
            e.getWhoClicked().getWorld().getWorldBorder().setCenter(box.getCenterX(), box.getCenterZ());
            e.getWhoClicked().getWorld().getWorldBorder().setSize(box.getMaxX() - box.getMinX());
            arena.getConfig().set("arena.pos1", loc1);
            arena.getConfig().set("arena.pos2", loc2);
            String world = e.getWhoClicked().getWorld().getName();
            arena.getConfig().set("arena.spawn.world", world);
            List<String> blocks = new ArrayList<>();
            Cuboid region = new Cuboid(loc1, loc2);
            for (Block block : region.getBlocks()) {
                blocks.add(block.getType().name());
            }
            arena.getConfig().set("blocks", blocks);
            arena.save();
            e.getWhoClicked().sendMessage(ChatColor.GREEN + "Arena Positions Set!");
        }
    });
    List<String> worldBorderlore = new ArrayList<>();
    worldBorderlore.add(ChatColor.GRAY + "Toggle whether or not the world border is enabled.");
    worldBorderlore.add(ChatColor.GREEN + "Currently the world border is " + arena.getConfig().getBoolean("world-border"));
    Button worldBorder = KnockbackFFA.getInstance().getButtonManager().create(new ItemBuilder(Material.BARRIER, 1, ChatColor.GRAY + "World Border", worldBorderlore).create(), e -> {
        arena.getConfig().set("world-border", !arena.getConfig().getBoolean("world-border"));
        arena.save();
        Location spawnLoc = arena.getConfig().getLocation("arena.spawn");
        boolean worldBorderBool = arena.getConfig().getBoolean("world-border");
        if (worldBorderBool) {
            Location loc1 = arena.getConfig().getLocation("arena.pos1");
            Location loc2 = arena.getConfig().getLocation("arena.pos2");
            BoundingBox box = new BoundingBox(loc1.getX(), loc1.getY(), loc1.getZ(), loc2.getX(), loc2.getY(), loc2.getZ());
            spawnLoc.getWorld().getWorldBorder().setCenter(box.getCenterX(), box.getCenterZ());
            spawnLoc.getWorld().getWorldBorder().setSize(box.getMaxX() - box.getMinX());
        } else {
            WorldBorder worldBorderr = spawnLoc.getWorld().getWorldBorder();
            worldBorderr.reset();
        }
        worldBorderlore.clear();
        ItemMeta im = e.getCurrentItem().getItemMeta();
        worldBorderlore.add(ChatColor.GRAY + "Toggle whether or not the world border is enabled.");
        worldBorderlore.add(ChatColor.GREEN + "Currently the world border is " + arena.getConfig().getBoolean("world-border"));
        im.setLore(worldBorderlore);
        e.getCurrentItem().setItemMeta(im);
    });
    arenaGUI.add(blockBreak, 10);
    arenaGUI.add(itemDrop, 11);
    arenaGUI.add(setSpawn, 12);
    arenaGUI.add(setpos, 13);
    arenaGUI.add(worldBorder, 14);
    arenaGUI.add(autoReset, 15);
    knocker.openGUI(arenaGUI);
}
Also used : Player(org.bukkit.entity.Player) ArrayList(java.util.ArrayList) Cuboid(me.gameisntover.kbffa.arena.regions.Cuboid) Arena(me.gameisntover.kbffa.arena.Arena) ItemBuilder(me.gameisntover.kbffa.util.ItemBuilder) Button(me.gameisntover.kbffa.gui.Button) BoundingBox(org.bukkit.util.BoundingBox) WorldBorder(org.bukkit.WorldBorder) Block(org.bukkit.block.Block) GUI(me.gameisntover.kbffa.gui.GUI) ItemStack(org.bukkit.inventory.ItemStack) ItemMeta(org.bukkit.inventory.meta.ItemMeta) Location(org.bukkit.Location)

Aggregations

Button (me.gameisntover.kbffa.gui.Button)2 GUI (me.gameisntover.kbffa.gui.GUI)2 ItemBuilder (me.gameisntover.kbffa.util.ItemBuilder)2 Player (org.bukkit.entity.Player)2 ItemStack (org.bukkit.inventory.ItemStack)2 ItemMeta (org.bukkit.inventory.meta.ItemMeta)2 ArrayList (java.util.ArrayList)1 Arrays (java.util.Arrays)1 Collections (java.util.Collections)1 List (java.util.List)1 Collectors (java.util.stream.Collectors)1 KnockbackFFA (me.gameisntover.kbffa.KnockbackFFA)1 Knocker (me.gameisntover.kbffa.api.Knocker)1 Arena (me.gameisntover.kbffa.arena.Arena)1 Cuboid (me.gameisntover.kbffa.arena.regions.Cuboid)1 Kit (me.gameisntover.kbffa.kit.Kit)1 Items (me.gameisntover.kbffa.util.Items)1 Message (me.gameisntover.kbffa.util.Message)1 Sounds (me.gameisntover.kbffa.util.Sounds)1 ChatColor (org.bukkit.ChatColor)1