Search in sources :

Example 51 with ItemBuilder

use of com.bencodez.advancedcore.api.item.ItemBuilder in project AdvancedCore by BenCodez.

the class RewardEditLucky method openRemove.

public void openRemove(Player player, RewardEditData reward) {
    EditGUI inv = new EditGUI("Edit Lucky Remove: " + reward.getName());
    inv.addData("Reward", reward);
    for (String key : reward.getData().getConfigurationSection("Lucky").getKeys(false)) {
        inv.addButton(new BInventoryButton(new ItemBuilder(Material.PAPER).setName("&c" + key).addLoreLine("&cClick to remove")) {

            @Override
            public void onClick(ClickEvent clickEvent) {
                RewardEditData reward = (RewardEditData) getInv().getData("Reward");
                reward.setValue("Lucky." + key, null);
                reloadAdvancedCore();
                open(player, reward);
            }
        });
    }
    inv.addButton(getBackButtonCustom(reward, new EditGUIValueInventory("") {

        @Override
        public void openInventory(ClickEvent clickEvent) {
            RewardEditData reward = (RewardEditData) getInv().getData("Reward");
            open(player, reward);
        }
    }));
    inv.openInventory(player);
}
Also used : EditGUI(com.bencodez.advancedcore.api.inventory.editgui.EditGUI) ItemBuilder(com.bencodez.advancedcore.api.item.ItemBuilder) RewardEditData(com.bencodez.advancedcore.api.rewards.RewardEditData) BInventoryButton(com.bencodez.advancedcore.api.inventory.BInventoryButton) ClickEvent(com.bencodez.advancedcore.api.inventory.BInventory.ClickEvent) EditGUIValueInventory(com.bencodez.advancedcore.api.inventory.editgui.valuetypes.EditGUIValueInventory)

Example 52 with ItemBuilder

use of com.bencodez.advancedcore.api.item.ItemBuilder in project AdvancedCore by BenCodez.

the class RewardEditSpecialChance method openRename.

public void openRename(Player player, RewardEditData reward) {
    EditGUI inv = new EditGUI("Edit SpecialChance Rename: " + reward.getName());
    inv.addData("Reward", reward);
    for (String key : reward.getData().getConfigurationSection("SpecialChance").getKeys(false)) {
        inv.addButton(new BInventoryButton(new ItemBuilder(Material.PAPER).setName("&a" + key).addLoreLine("&aClick to rename")) {

            @Override
            public void onClick(ClickEvent clickEvent) {
                new ValueRequestBuilder(new NumberListener() {

                    @Override
                    public void onInput(Player player, Number value) {
                        RewardEditData reward = (RewardEditData) getInv().getData("Reward");
                        reward.setValue("SpecialChance." + value.intValue(), reward.getData().getConfigurationSection("SpecialChance." + key));
                        reward.setValue("SpecialChance." + key, null);
                        reloadAdvancedCore();
                        open(player, reward);
                    }
                }, new Number[] {}).usingMethod(InputMethod.CHAT).request(clickEvent.getPlayer());
            }
        });
    }
    inv.addButton(getBackButtonCustom(reward, new EditGUIValueInventory("") {

        @Override
        public void openInventory(ClickEvent clickEvent) {
            RewardEditData reward = (RewardEditData) getInv().getData("Reward");
            open(player, reward);
        }
    }));
    inv.openInventory(player);
}
Also used : EditGUI(com.bencodez.advancedcore.api.inventory.editgui.EditGUI) ItemBuilder(com.bencodez.advancedcore.api.item.ItemBuilder) NumberListener(com.bencodez.advancedcore.api.valuerequest.listeners.NumberListener) Player(org.bukkit.entity.Player) RewardEditData(com.bencodez.advancedcore.api.rewards.RewardEditData) BInventoryButton(com.bencodez.advancedcore.api.inventory.BInventoryButton) ClickEvent(com.bencodez.advancedcore.api.inventory.BInventory.ClickEvent) EditGUIValueInventory(com.bencodez.advancedcore.api.inventory.editgui.valuetypes.EditGUIValueInventory) ValueRequestBuilder(com.bencodez.advancedcore.api.valuerequest.ValueRequestBuilder)

Example 53 with ItemBuilder

use of com.bencodez.advancedcore.api.item.ItemBuilder in project AdvancedCore by BenCodez.

the class RewardEditSpecialChance method openEditSub.

public void openEditSub(Player player, RewardEditData reward) {
    EditGUI inv = new EditGUI("Edit SpecialChance Edit Sub: " + reward.getName());
    inv.addData("Reward", reward);
    for (String key : reward.getData().getConfigurationSection("SpecialChance").getKeys(false)) {
        inv.addButton(new BInventoryButton(new ItemBuilder(Material.PAPER).setName("&a" + key).addLoreLine("&aClick to edit")) {

            @Override
            public void onClick(ClickEvent clickEvent) {
                RewardEditData reward = (RewardEditData) getInv().getData("Reward");
                openSubReward(clickEvent.getPlayer(), "SpecialChance." + key, reward);
            }
        });
    }
    inv.addButton(getBackButtonCustom(reward, new EditGUIValueInventory("") {

        @Override
        public void openInventory(ClickEvent clickEvent) {
            RewardEditData reward = (RewardEditData) getInv().getData("Reward");
            open(player, reward);
        }
    }));
    inv.openInventory(player);
}
Also used : EditGUI(com.bencodez.advancedcore.api.inventory.editgui.EditGUI) ItemBuilder(com.bencodez.advancedcore.api.item.ItemBuilder) RewardEditData(com.bencodez.advancedcore.api.rewards.RewardEditData) BInventoryButton(com.bencodez.advancedcore.api.inventory.BInventoryButton) ClickEvent(com.bencodez.advancedcore.api.inventory.BInventory.ClickEvent) EditGUIValueInventory(com.bencodez.advancedcore.api.inventory.editgui.valuetypes.EditGUIValueInventory)

Example 54 with ItemBuilder

use of com.bencodez.advancedcore.api.item.ItemBuilder in project AdvancedCore by BenCodez.

the class EditGUIValueList method onClick.

@Override
public void onClick(ClickEvent clickEvent) {
    if (getCurrentValue() == null) {
        setCurrentValue(new ArrayList<String>());
    }
    BInventory inv = new BInventory("Edit list: " + getKey());
    inv.setMeta(clickEvent.getPlayer(), "Value", getCurrentValue());
    inv.addButton(new BInventoryButton(new ItemBuilder(Material.EMERALD_BLOCK).setName("&cAdd value")) {

        @Override
        public void onClick(ClickEvent clickEvent) {
            new ValueRequestBuilder(new Listener<String>() {

                @Override
                public void onInput(Player player, String add) {
                    @SuppressWarnings("unchecked") ArrayList<String> list = (ArrayList<String>) getMeta(player, "Value");
                    if (list == null) {
                        list = new ArrayList<String>();
                    }
                    list.add(add);
                    setValue(player, list);
                    sendMessage(player, "&cAdded " + add + " to " + getKey());
                }
            }, new String[] {}).request(clickEvent.getPlayer());
        }
    });
    inv.addButton(new BInventoryButton(new ItemBuilder(Material.BARRIER).setName("&cRemove value")) {

        @SuppressWarnings("unchecked")
        @Override
        public void onClick(ClickEvent clickEvent) {
            ArrayList<String> list = (ArrayList<String>) getMeta(clickEvent.getPlayer(), "Value");
            if (!list.isEmpty()) {
                new ValueRequestBuilder(new Listener<String>() {

                    @Override
                    public void onInput(Player player, String add) {
                        ArrayList<String> list = (ArrayList<String>) getMeta(player, "Value");
                        list.remove(add);
                        setValue(player, list);
                        sendMessage(player, "&cRemoved " + add + " from " + getKey());
                    }
                }, ArrayUtils.getInstance().convert((ArrayList<String>) getMeta(clickEvent.getPlayer(), "Value"))).usingMethod(InputMethod.INVENTORY).allowCustomOption(false).request(clickEvent.getPlayer());
            } else {
                clickEvent.getPlayer().sendMessage("No values to remove");
            }
        }
    });
    inv.openInventory(clickEvent.getPlayer());
}
Also used : ItemBuilder(com.bencodez.advancedcore.api.item.ItemBuilder) Player(org.bukkit.entity.Player) BInventoryButton(com.bencodez.advancedcore.api.inventory.BInventoryButton) ClickEvent(com.bencodez.advancedcore.api.inventory.BInventory.ClickEvent) ArrayList(java.util.ArrayList) BInventory(com.bencodez.advancedcore.api.inventory.BInventory) ValueRequestBuilder(com.bencodez.advancedcore.api.valuerequest.ValueRequestBuilder)

Example 55 with ItemBuilder

use of com.bencodez.advancedcore.api.item.ItemBuilder in project AdvancedCore by BenCodez.

the class BInventory method openInventory.

/**
 * Open inventory.
 *
 * @param player the player
 * @param page   the page
 */
public void openInventory(Player player, int page) {
    BInventory inventory = this;
    inv = Bukkit.createInventory(new GUISession(this, page), maxInvSize, StringParser.getInstance().replaceJavascript(player, StringParser.getInstance().replacePlaceHolder(inventory.getInventoryName(), getPlaceholders())));
    this.page = page;
    int startSlot = (page - 1) * (maxInvSize - 9);
    for (Entry<Integer, BInventoryButton> pair : inventory.getButtons().entrySet()) {
        int slot = pair.getKey();
        if (slot >= startSlot) {
            slot -= startSlot;
            if (slot < (maxInvSize - 9)) {
                ItemStack item = pair.getValue().getItem(player, getPlaceholders());
                inv.setItem(slot, item);
                BInventoryButton b = pair.getValue();
                b.setInv(this);
                b.setSlot(pair.getKey());
                b.load(player);
            }
        }
    }
    for (BInventoryButton b : pageButtons) {
        inv.setItem((maxInvSize - 9) + b.getSlot(), b.getItem(player, getPlaceholders()));
    }
    if (prevItem == null) {
        if (AdvancedCorePlugin.getInstance().getOptions().getPrevItem() != null) {
            prevItem = new ItemBuilder(AdvancedCorePlugin.getInstance().getOptions().getPrevItem()).addPlaceholder(getPlaceholders()).toItemStack(player);
        } else {
            prevItem = new ItemBuilder(Material.BLACK_STAINED_GLASS_PANE, 1).setName("&aPrevious Page").addPlaceholder(getPlaceholders()).toItemStack(player);
        }
    }
    if (nextItem == null) {
        if (AdvancedCorePlugin.getInstance().getOptions().getNextItem() != null) {
            nextItem = new ItemBuilder(AdvancedCorePlugin.getInstance().getOptions().getNextItem()).addPlaceholder(getPlaceholders()).toItemStack(player);
        } else {
            nextItem = new ItemBuilder(Material.BLACK_STAINED_GLASS_PANE, 1).setName("&aNext Page").addPlaceholder(getPlaceholders()).toItemStack(player);
        }
    }
    inv.setItem(maxInvSize - 9, prevItem);
    inv.setItem(maxInvSize - 1, nextItem);
    openInv(player, inv);
}
Also used : ItemBuilder(com.bencodez.advancedcore.api.item.ItemBuilder) ItemStack(org.bukkit.inventory.ItemStack)

Aggregations

ItemBuilder (com.bencodez.advancedcore.api.item.ItemBuilder)71 ClickEvent (com.bencodez.advancedcore.api.inventory.BInventory.ClickEvent)64 BInventoryButton (com.bencodez.advancedcore.api.inventory.BInventoryButton)57 EditGUI (com.bencodez.advancedcore.api.inventory.editgui.EditGUI)32 Player (org.bukkit.entity.Player)32 EditGUIValueInventory (com.bencodez.advancedcore.api.inventory.editgui.valuetypes.EditGUIValueInventory)30 BInventory (com.bencodez.advancedcore.api.inventory.BInventory)28 RewardEditData (com.bencodez.advancedcore.api.rewards.RewardEditData)28 EditGUIButton (com.bencodez.advancedcore.api.inventory.editgui.EditGUIButton)13 ArrayList (java.util.ArrayList)13 UpdatingBInventoryButton (com.bencodez.advancedcore.api.inventory.UpdatingBInventoryButton)11 EditGUIValueString (com.bencodez.advancedcore.api.inventory.editgui.valuetypes.EditGUIValueString)11 ValueRequestBuilder (com.bencodez.advancedcore.api.valuerequest.ValueRequestBuilder)11 StringListener (com.bencodez.advancedcore.api.valuerequest.listeners.StringListener)9 EditGUIValueList (com.bencodez.advancedcore.api.inventory.editgui.valuetypes.EditGUIValueList)7 VoteSite (com.bencodez.votingplugin.objects.VoteSite)7 EditGUIValueNumber (com.bencodez.advancedcore.api.inventory.editgui.valuetypes.EditGUIValueNumber)6 Reward (com.bencodez.advancedcore.api.rewards.Reward)6 AdvancedCoreUser (com.bencodez.advancedcore.api.user.AdvancedCoreUser)6 ValueRequest (com.bencodez.advancedcore.api.valuerequest.ValueRequest)6