Search in sources :

Example 36 with BInventoryButton

use of com.bencodez.advancedcore.api.inventory.BInventoryButton in project AdvancedCore by BenCodez.

the class RewardEditGUI method openRewardGUIRewards.

public void openRewardGUIRewards(Player player, RewardEditData rewardEditData, String rewardName, boolean unsetValuesShown) {
    EditGUI inv = new EditGUI("Rewards: " + rewardName);
    inv.requirePermission(AdvancedCorePlugin.getInstance().getOptions().getPermPrefix() + ".RewardEdit");
    inv.addData("Reward", rewardEditData);
    for (RewardInject injectReward : plugin.getRewardHandler().getInjectedRewards()) {
        if (injectReward.isEditable()) {
            for (BInventoryButton b : injectReward.getEditButtons()) {
                if (b instanceof EditGUIButton) {
                    EditGUIButton eb = (EditGUIButton) b;
                    if (unsetValuesShown || eb.getEditor().containsKey(rewardEditData)) {
                        if (eb.getEditor().isCanGetValue()) {
                            eb.getEditor().setCurrentValue(rewardEditData.getValue(eb.getEditor().getKey()));
                        }
                        inv.addButton(eb);
                    }
                } else {
                    inv.addButton(b);
                }
            }
        }
    }
    inv.sort();
    if (!unsetValuesShown) {
        inv.addButton(new BInventoryButton(new ItemBuilder(Material.CHEST).setName("&cUnset Values")) {

            @Override
            public void onClick(ClickEvent clickEvent) {
                openRewardGUIRewards(player, rewardEditData, rewardName, true);
            }
        });
    } else {
        inv.addButton(new BInventoryButton(new ItemBuilder(Material.BOOK).setName("&cValues not setable in GUI yet:").setLore("&aRandom, Item, Items(WIP), RandomItem", "&bThese will eventually be aded to edit gui", "&3Also looking for feedback on GUI")) {

            @Override
            public void onClick(ClickEvent clickEvent) {
            }
        });
    }
    inv.addButton(new BInventoryButton(new ItemBuilder(Material.BARRIER).setName("&cGo back")) {

        @Override
        public void onClick(ClickEvent clickEvent) {
            openRewardGUI(clickEvent.getPlayer(), rewardEditData, rewardName);
        }
    });
    inv.openInventory(player);
}
Also used : EditGUI(com.bencodez.advancedcore.api.inventory.editgui.EditGUI) ItemBuilder(com.bencodez.advancedcore.api.item.ItemBuilder) EditGUIButton(com.bencodez.advancedcore.api.inventory.editgui.EditGUIButton) BInventoryButton(com.bencodez.advancedcore.api.inventory.BInventoryButton) ClickEvent(com.bencodez.advancedcore.api.inventory.BInventory.ClickEvent) RewardInject(com.bencodez.advancedcore.api.rewards.injected.RewardInject)

Example 37 with BInventoryButton

use of com.bencodez.advancedcore.api.inventory.BInventoryButton in project AdvancedCore by BenCodez.

the class NumberRequester method request.

/**
 * Request.
 *
 * @param player            the player
 * @param method            the method
 * @param currentValue      the current value
 * @param promptText        the prompt text
 * @param options           the options
 * @param allowCustomOption the allow custom option
 * @param listener          the listener
 */
public void request(Player player, InputMethod method, String currentValue, LinkedHashMap<Number, ItemStack> options, String promptText, boolean allowCustomOption, NumberListener listener) {
    if (method.equals(InputMethod.SIGN)) {
        method = InputMethod.INVENTORY;
    }
    if ((options == null || options.size() == 0) && method.equals(InputMethod.INVENTORY) && allowCustomOption) {
        method = InputMethod.CHAT;
    }
    if (AdvancedCorePlugin.getInstance().getOptions().getDisabledRequestMethods().contains(method.toString())) {
        player.sendMessage("Disabled method: " + method.toString());
    }
    if (method.equals(InputMethod.INVENTORY)) {
        if (options == null) {
            player.sendMessage("There are no choices to choice from to use this method");
            return;
        }
        BInventory inv = new BInventory("Click one of the following:");
        for (Entry<Number, ItemStack> entry : options.entrySet()) {
            inv.addButton(inv.getNextSlot(), new BInventoryButton(entry.getKey().toString(), new String[] {}, entry.getValue()) {

                @Override
                public void onClick(ClickEvent clickEvent) {
                    String num = clickEvent.getClickedItem().getItemMeta().getDisplayName();
                    try {
                        Number number = Double.valueOf(num);
                        listener.onInput(clickEvent.getPlayer(), number);
                    } catch (NumberFormatException ex) {
                        ex.printStackTrace();
                    }
                }
            });
        }
        if (allowCustomOption) {
            inv.addButton(inv.getNextSlot(), new BInventoryButton("&cClick to enter custom value", new String[] {}, new ItemStack(Material.ANVIL)) {

                @Override
                public void onClick(ClickEvent clickEvent) {
                    new ValueRequest().requestNumber(clickEvent.getPlayer(), listener);
                }
            });
        }
        inv.openInventory(player);
    } else if (method.equals(InputMethod.CHAT)) {
        if (options != null && options.size() != 0) {
            AdvancedCoreUser user = AdvancedCorePlugin.getInstance().getUserManager().getUser(player);
            user.sendMessage("&cClick one of the following options below:");
            PlayerUtils.getInstance().setPlayerMeta(player, "ValueRequestNumber", listener);
            for (Number num : options.keySet()) {
                String option = num.toString();
                TextComponent comp = new TextComponent(option);
                comp.setClickEvent(new net.md_5.bungee.api.chat.ClickEvent(Action.RUN_COMMAND, "/" + AdvancedCorePlugin.getInstance().getName() + "valuerequestinput Number " + option));
                user.sendJson(comp);
            }
            if (allowCustomOption) {
                String option = "CustomValue";
                TextComponent comp = new TextComponent(option);
                comp.setClickEvent(new net.md_5.bungee.api.chat.ClickEvent(Action.RUN_COMMAND, "/" + AdvancedCorePlugin.getInstance().getName() + "valuerequestinput Number " + option));
                user.sendJson(comp);
            }
        } else {
            ConversationFactory convoFactory = new ConversationFactory(AdvancedCorePlugin.getInstance()).withModality(true).withEscapeSequence("cancel").withTimeout(60);
            PromptManager prompt = new PromptManager(promptText + " Current value: " + currentValue, convoFactory);
            prompt.stringPrompt(player, new PromptReturnString() {

                @Override
                public void onInput(ConversationContext context, Conversable conversable, String input) {
                    String num = input;
                    try {
                        Number number = Double.valueOf(num);
                        Bukkit.getScheduler().runTaskAsynchronously(AdvancedCorePlugin.getInstance(), new Runnable() {

                            @Override
                            public void run() {
                                listener.onInput((Player) conversable, number);
                            }
                        });
                    } catch (NumberFormatException ex) {
                        ex.printStackTrace();
                    }
                }
            });
        }
    } else if (method.equals(InputMethod.BOOK)) {
        new BookManager(player, currentValue.toString(), new BookSign() {

            @Override
            public void onBookSign(Player player, String input) {
                String num = input;
                try {
                    Number number = Double.valueOf(num);
                    listener.onInput(player, number);
                } catch (NumberFormatException ex) {
                    ex.printStackTrace();
                }
            }
        });
    } else {
        player.sendMessage("Invalid method/disabled method, change your request method");
    }
}
Also used : TextComponent(net.md_5.bungee.api.chat.TextComponent) Player(org.bukkit.entity.Player) ConversationFactory(org.bukkit.conversations.ConversationFactory) BInventoryButton(com.bencodez.advancedcore.api.inventory.BInventoryButton) ClickEvent(com.bencodez.advancedcore.api.inventory.BInventory.ClickEvent) Conversable(org.bukkit.conversations.Conversable) BInventory(com.bencodez.advancedcore.api.inventory.BInventory) PromptReturnString(com.bencodez.advancedcore.api.valuerequest.prompt.PromptReturnString) ValueRequest(com.bencodez.advancedcore.api.valuerequest.ValueRequest) PromptReturnString(com.bencodez.advancedcore.api.valuerequest.prompt.PromptReturnString) AdvancedCoreUser(com.bencodez.advancedcore.api.user.AdvancedCoreUser) BookSign(com.bencodez.advancedcore.api.valuerequest.book.BookSign) ItemStack(org.bukkit.inventory.ItemStack) ConversationContext(org.bukkit.conversations.ConversationContext) BookManager(com.bencodez.advancedcore.api.valuerequest.book.BookManager) PromptManager(com.bencodez.advancedcore.api.valuerequest.prompt.PromptManager)

Example 38 with BInventoryButton

use of com.bencodez.advancedcore.api.inventory.BInventoryButton in project AdvancedCore by BenCodez.

the class BooleanRequester method request.

/**
 * Request.
 *
 * @param player       the player
 * @param method       the method
 * @param currentValue the current value
 * @param promptText   the prompt text
 * @param listener     the listener
 */
public void request(Player player, InputMethod method, String currentValue, String promptText, BooleanListener listener) {
    if (AdvancedCorePlugin.getInstance().getOptions().getDisabledRequestMethods().contains(method.toString())) {
        player.sendMessage("Disabled method: " + method.toString());
    }
    if (method.equals(InputMethod.SIGN)) {
        method = InputMethod.INVENTORY;
    }
    if (method.equals(InputMethod.INVENTORY)) {
        BInventory inv = new BInventory("Click one of the following:");
        inv.addButton(inv.getNextSlot(), new BInventoryButton("True", new String[] {}, new ItemStack(Material.REDSTONE_BLOCK)) {

            @Override
            public void onClick(ClickEvent clickEvent) {
                listener.onInput(clickEvent.getPlayer(), Boolean.valueOf(clickEvent.getClickedItem().getItemMeta().getDisplayName()));
            }
        });
        inv.addButton(inv.getNextSlot(), new BInventoryButton("False", new String[] {}, new ItemStack(Material.IRON_BLOCK)) {

            @Override
            public void onClick(ClickEvent clickEvent) {
                listener.onInput(clickEvent.getPlayer(), Boolean.valueOf(clickEvent.getClickedItem().getItemMeta().getDisplayName()));
            }
        });
        inv.openInventory(player);
    } else if (method.equals(InputMethod.CHAT)) {
        AdvancedCoreUser user = AdvancedCorePlugin.getInstance().getUserManager().getUser(player);
        user.sendMessage("&cClick one of the following options below:");
        String option = "True";
        TextComponent comp = new TextComponent(option);
        PlayerUtils.getInstance().setPlayerMeta(player, "ValueRequestBoolean", listener);
        comp.setClickEvent(new net.md_5.bungee.api.chat.ClickEvent(Action.RUN_COMMAND, "/" + AdvancedCorePlugin.getInstance().getName() + "valuerequestinput Boolean " + option));
        user.sendJson(comp);
        option = "False";
        comp = new TextComponent(option);
        comp.setClickEvent(new net.md_5.bungee.api.chat.ClickEvent(Action.RUN_COMMAND, "/" + AdvancedCorePlugin.getInstance().getName() + "valuerequestinput Boolean " + option));
        user.sendJson(comp);
    } else if (method.equals(InputMethod.BOOK)) {
        new BookManager(player, currentValue, new BookSign() {

            @Override
            public void onBookSign(Player player, String input) {
                listener.onInput(player, Boolean.valueOf(input));
            }
        });
    } else {
        player.sendMessage("Invalid method/disabled method, change your request method");
    }
}
Also used : TextComponent(net.md_5.bungee.api.chat.TextComponent) Player(org.bukkit.entity.Player) BInventoryButton(com.bencodez.advancedcore.api.inventory.BInventoryButton) ClickEvent(com.bencodez.advancedcore.api.inventory.BInventory.ClickEvent) BInventory(com.bencodez.advancedcore.api.inventory.BInventory) AdvancedCoreUser(com.bencodez.advancedcore.api.user.AdvancedCoreUser) BookSign(com.bencodez.advancedcore.api.valuerequest.book.BookSign) ItemStack(org.bukkit.inventory.ItemStack) BookManager(com.bencodez.advancedcore.api.valuerequest.book.BookManager)

Example 39 with BInventoryButton

use of com.bencodez.advancedcore.api.inventory.BInventoryButton in project AdvancedCore by BenCodez.

the class RewardEditAdvancedPriority method openRemove.

public void openRemove(Player player, RewardEditData reward) {
    EditGUI inv = new EditGUI("Edit AdvancedPriority Remove: " + reward.getName());
    inv.addData("Reward", reward);
    for (String key : reward.getData().getConfigurationSection("AdvancedPriority").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("AdvancedPriority." + 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 40 with BInventoryButton

use of com.bencodez.advancedcore.api.inventory.BInventoryButton in project AdvancedCore by BenCodez.

the class RewardEditAdvancedPriority method openRename.

public void openRename(Player player, RewardEditData reward) {
    EditGUI inv = new EditGUI("Edit AdvancedPriority Rename: " + reward.getName());
    inv.addData("Reward", reward);
    for (String key : reward.getData().getConfigurationSection("AdvancedPriority").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 StringListener() {

                    @Override
                    public void onInput(Player player, String value) {
                        RewardEditData reward = (RewardEditData) getInv().getData("Reward");
                        reward.setValue("AdvancedPriority." + value, reward.getData().getConfigurationSection("AdvancedPriority." + key));
                        reward.setValue("AdvancedPriority." + key, null);
                        reloadAdvancedCore();
                        open(player, reward);
                    }
                }, new String[] {}).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) 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) StringListener(com.bencodez.advancedcore.api.valuerequest.listeners.StringListener) ValueRequestBuilder(com.bencodez.advancedcore.api.valuerequest.ValueRequestBuilder)

Aggregations

BInventoryButton (com.bencodez.advancedcore.api.inventory.BInventoryButton)66 ClickEvent (com.bencodez.advancedcore.api.inventory.BInventory.ClickEvent)65 ItemBuilder (com.bencodez.advancedcore.api.item.ItemBuilder)57 EditGUI (com.bencodez.advancedcore.api.inventory.editgui.EditGUI)33 Player (org.bukkit.entity.Player)32 BInventory (com.bencodez.advancedcore.api.inventory.BInventory)31 RewardEditData (com.bencodez.advancedcore.api.rewards.RewardEditData)29 EditGUIValueInventory (com.bencodez.advancedcore.api.inventory.editgui.valuetypes.EditGUIValueInventory)26 ArrayList (java.util.ArrayList)15 ValueRequestBuilder (com.bencodez.advancedcore.api.valuerequest.ValueRequestBuilder)11 EditGUIValueString (com.bencodez.advancedcore.api.inventory.editgui.valuetypes.EditGUIValueString)10 StringListener (com.bencodez.advancedcore.api.valuerequest.listeners.StringListener)10 ItemStack (org.bukkit.inventory.ItemStack)10 ValueRequest (com.bencodez.advancedcore.api.valuerequest.ValueRequest)9 EditGUIButton (com.bencodez.advancedcore.api.inventory.editgui.EditGUIButton)8 UpdatingBInventoryButton (com.bencodez.advancedcore.api.inventory.UpdatingBInventoryButton)7 Reward (com.bencodez.advancedcore.api.rewards.Reward)7 AdvancedCoreUser (com.bencodez.advancedcore.api.user.AdvancedCoreUser)7 VoteSite (com.bencodez.votingplugin.objects.VoteSite)7 NumberListener (com.bencodez.advancedcore.api.valuerequest.listeners.NumberListener)5