Search in sources :

Example 6 with BInventoryButton

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

the class RewardEditGUI method openRewardsGUI.

/**
 * Open rewards GUI.
 *
 * @param player the player
 */
public void openRewardsGUI(Player player) {
    if (!player.hasPermission(AdvancedCorePlugin.getInstance().getOptions().getPermPrefix() + ".RewardEdit")) {
        player.sendMessage("You do not have enough permission to do this");
        return;
    }
    BInventory inv = new BInventory("Rewards");
    for (Reward reward : RewardHandler.getInstance().getRewards()) {
        if (!reward.getConfig().isDirectlyDefinedReward()) {
            ArrayList<String> lore = new ArrayList<String>();
            if (reward.getConfig().isDirectlyDefinedReward()) {
                lore.add("&cReward is not directly defined, can not edit in GUI");
            }
            inv.addButton(new BInventoryButton(reward.getRewardName(), ArrayUtils.getInstance().convert(lore), new ItemStack(Material.STONE)) {

                @Override
                public void onClick(ClickEvent event) {
                    Player player = event.getWhoClicked();
                    Reward reward = (Reward) getData("Reward");
                    if (!reward.getConfig().isDirectlyDefinedReward()) {
                        openRewardGUI(player, new RewardEditData(reward), reward.getRewardName());
                    } else {
                        player.sendMessage("Can't edit this reward, directly defined reward");
                    }
                }
            }.addData("Reward", reward));
        }
    }
    inv.openInventory(player);
}
Also used : 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) ArrayList(java.util.ArrayList) BInventory(com.bencodez.advancedcore.api.inventory.BInventory) DirectlyDefinedReward(com.bencodez.advancedcore.api.rewards.DirectlyDefinedReward) Reward(com.bencodez.advancedcore.api.rewards.Reward) ItemStack(org.bukkit.inventory.ItemStack)

Example 7 with BInventoryButton

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

the class UserGUI method openUserGUI.

/**
 * Open user GUI.
 *
 * @param player     the player
 * @param playerName the player name
 */
public void openUserGUI(Player player, final String playerName) {
    if (!player.hasPermission("AdvancedCore.UserEdit")) {
        player.sendMessage("Not enough permissions");
        return;
    }
    BInventory inv = new BInventory("UserGUI: " + playerName);
    inv.addData("player", playerName);
    inv.addButton(new BInventoryButton("Give Reward File", new String[] {}, new ItemStack(Material.STONE)) {

        @Override
        public void onClick(ClickEvent clickEvent) {
            ArrayList<String> rewards = new ArrayList<String>();
            for (Reward reward : RewardHandler.getInstance().getRewards()) {
                rewards.add(reward.getRewardName());
            }
            new ValueRequest().requestString(clickEvent.getPlayer(), "", ArrayUtils.getInstance().convert(rewards), true, new StringListener() {

                @Override
                public void onInput(Player player, String value) {
                    AdvancedCoreUser user = plugin.getUserManager().getUser(UserGUI.getInstance().getCurrentPlayer(player));
                    RewardHandler.getInstance().giveReward(user, value, new RewardOptions());
                    player.sendMessage("Given " + user.getPlayerName() + " reward file " + value);
                }
            });
        }
    });
    inv.addButton(new BInventoryButton(new ItemBuilder("WRITABLE_BOOK").setName("Edit Data")) {

        @Override
        public void onClick(ClickEvent clickEvent) {
            Player player = clickEvent.getPlayer();
            EditGUI inv = new EditGUI("Edit Data, click to change");
            final AdvancedCoreUser user = plugin.getUserManager().getUser(playerName);
            for (final String key : user.getData().getKeys()) {
                String value = user.getData().getValue(key);
                inv.addButton(new EditGUIButton(new ItemBuilder(Material.STONE).setName(key + " = " + value), new EditGUIValueString(key, value) {

                    @Override
                    public void setValue(Player player, String value) {
                        if (value.equals("\"\"")) {
                            value = "";
                        }
                        user.getData().setString(key, value);
                        openUserGUI(player, playerName);
                    }
                }));
            }
            inv.openInventory(player);
        }
    });
    inv.addButton(new BInventoryButton(new ItemBuilder(Material.PAPER).setName("&cView player data")) {

        @Override
        public void onClick(ClickEvent clickEvent) {
            AdvancedCoreUser user = plugin.getUserManager().getUser(playerName);
            for (String key : user.getData().getKeys()) {
                String str = user.getData().getValue(key);
                user.sendMessage("&c&l" + key + " &c" + str);
            }
        }
    });
    for (BInventoryButton button : extraButtons.values()) {
        inv.addButton(button);
    }
    inv.openInventory(player);
}
Also used : EditGUI(com.bencodez.advancedcore.api.inventory.editgui.EditGUI) Player(org.bukkit.entity.Player) BInventoryButton(com.bencodez.advancedcore.api.inventory.BInventoryButton) ClickEvent(com.bencodez.advancedcore.api.inventory.BInventory.ClickEvent) ArrayList(java.util.ArrayList) EditGUIValueString(com.bencodez.advancedcore.api.inventory.editgui.valuetypes.EditGUIValueString) BInventory(com.bencodez.advancedcore.api.inventory.BInventory) EditGUIValueString(com.bencodez.advancedcore.api.inventory.editgui.valuetypes.EditGUIValueString) ValueRequest(com.bencodez.advancedcore.api.valuerequest.ValueRequest) AdvancedCoreUser(com.bencodez.advancedcore.api.user.AdvancedCoreUser) RewardOptions(com.bencodez.advancedcore.api.rewards.RewardOptions) ItemBuilder(com.bencodez.advancedcore.api.item.ItemBuilder) EditGUIButton(com.bencodez.advancedcore.api.inventory.editgui.EditGUIButton) Reward(com.bencodez.advancedcore.api.rewards.Reward) StringListener(com.bencodez.advancedcore.api.valuerequest.listeners.StringListener) ItemStack(org.bukkit.inventory.ItemStack)

Example 8 with BInventoryButton

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

the class StringRequester 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<String, ItemStack> options, String promptText, boolean allowCustomOption, StringListener listener) {
    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<String, ItemStack> entry : options.entrySet()) {
            inv.addButton(inv.getNextSlot(), new BInventoryButton(entry.getKey(), new String[] {}, entry.getValue()) {

                @Override
                public void onClick(ClickEvent clickEvent) {
                    listener.onInput(clickEvent.getPlayer(), clickEvent.getClickedItem().getItemMeta().getDisplayName());
                }
            });
        }
        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().requestString(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, "ValueRequestString", listener);
            for (String option : options.keySet()) {
                TextComponent comp = new TextComponent(option);
                comp.setClickEvent(new net.md_5.bungee.api.chat.ClickEvent(Action.RUN_COMMAND, "/" + AdvancedCorePlugin.getInstance().getName() + "valuerequestinput String " + 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 String " + 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) {
                    Bukkit.getScheduler().runTaskAsynchronously(AdvancedCorePlugin.getInstance(), new Runnable() {

                        @Override
                        public void run() {
                            listener.onInput((Player) conversable, input);
                        }
                    });
                }
            });
        }
    } else if (method.equals(InputMethod.BOOK)) {
        new BookManager(player, currentValue, new BookSign() {

            @Override
            public void onBookSign(Player player, String input) {
                listener.onInput(player, input);
            }
        });
    } else if (method.equals(InputMethod.SIGN)) {
        AdvancedCorePlugin.getInstance().getSignMenu().open(player.getUniqueId(), new String[] { "", "", "", "" }, new InputReceiver() {

            @Override
            public void receive(Player player, String[] text) {
                String str = "";
                for (String t : text) {
                    str += t;
                }
                listener.onInput(player, str);
            }
        });
    } else {
        player.sendMessage("Invalid method/disabled method, change your request method");
    }
}
Also used : TextComponent(net.md_5.bungee.api.chat.TextComponent) InputReceiver(com.bencodez.advancedcore.api.valuerequest.sign.SignMenu.InputReceiver) 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 9 with BInventoryButton

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

the class ChoiceGUI method openClaimChoices.

public void openClaimChoices(Player player, Reward reward) {
    if (!reward.getConfig().getEnableChoices()) {
        player.sendMessage("Choice rewards not enabled");
        return;
    }
    AdvancedCoreUser user = plugin.getUserManager().getUser(player);
    BInventory inv = new BInventory("Pick reward");
    inv.dontClose();
    for (String choice : reward.getConfig().getChoices()) {
        ItemBuilder builder = new ItemBuilder(reward.getConfig().getChoicesItem(choice)).setNameIfNotExist("&a" + choice);
        inv.addButton(new BInventoryButton(builder) {

            @Override
            public void onClick(ClickEvent clickEvent) {
                Reward reward = (Reward) getInv().getData("Reward");
                AdvancedCoreUser user = (AdvancedCoreUser) getInv().getData("User");
                String choice = (String) getData("Choice");
                user.removeUnClaimedChoiceReward(reward.getName());
                RewardHandler.getInstance().giveChoicesReward(reward, user, choice);
                if (user.getUnClaimedChoices().size() > 0) {
                    openClaimChoices(clickEvent.getPlayer());
                } else {
                    Bukkit.getScheduler().runTask(plugin, new Runnable() {

                        @Override
                        public void run() {
                            clickEvent.getPlayer().closeInventory();
                        }
                    });
                }
            }
        }.addData("Choice", choice));
    }
    inv.addData("User", user);
    inv.addData("Reward", reward);
    inv.openInventory(player);
}
Also used : AdvancedCoreUser(com.bencodez.advancedcore.api.user.AdvancedCoreUser) ItemBuilder(com.bencodez.advancedcore.api.item.ItemBuilder) BInventoryButton(com.bencodez.advancedcore.api.inventory.BInventoryButton) ClickEvent(com.bencodez.advancedcore.api.inventory.BInventory.ClickEvent) BInventory(com.bencodez.advancedcore.api.inventory.BInventory) Reward(com.bencodez.advancedcore.api.rewards.Reward)

Example 10 with BInventoryButton

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

the class ChoiceGUI method openPreferenceReward.

public void openPreferenceReward(Player player, String rewardName) {
    Reward reward = RewardHandler.getInstance().getReward(rewardName);
    if (!reward.getConfig().getEnableChoices()) {
        player.sendMessage("Choice rewards not enabled");
        return;
    }
    AdvancedCoreUser user = plugin.getUserManager().getUser(player);
    BInventory inv = new BInventory("Select Preference");
    for (String choice : reward.getConfig().getChoices()) {
        ItemBuilder builder = new ItemBuilder(reward.getConfig().getChoicesItem(choice));
        if (user.getChoicePreference(rewardName).equalsIgnoreCase(choice)) {
            builder.addLoreLine("&cCurrent preference");
            builder.addLoreLine("&c&lClick to remove");
        } else {
            builder.addLoreLine("&aClick to set as preference");
        }
        builder.setName("&a" + choice);
        inv.addButton(new BInventoryButton(builder) {

            @Override
            public void onClick(ClickEvent clickEvent) {
                AdvancedCoreUser user = (AdvancedCoreUser) getInv().getData("User");
                String rewardName = (String) getInv().getData("Reward");
                String choice = (String) getData("Choice");
                if (user.getChoicePreference(rewardName).equals(choice)) {
                    choice = "none";
                }
                user.setChoicePreference(rewardName, choice);
                user.sendMessage(plugin.getOptions().getFormatChoiceRewardsPreferenceSet(), "choice", choice);
            }
        }.addData("Choice", choice));
    }
    inv.addData("User", user);
    inv.addData("Reward", rewardName);
    inv.openInventory(player);
}
Also used : AdvancedCoreUser(com.bencodez.advancedcore.api.user.AdvancedCoreUser) ItemBuilder(com.bencodez.advancedcore.api.item.ItemBuilder) BInventoryButton(com.bencodez.advancedcore.api.inventory.BInventoryButton) ClickEvent(com.bencodez.advancedcore.api.inventory.BInventory.ClickEvent) Reward(com.bencodez.advancedcore.api.rewards.Reward) BInventory(com.bencodez.advancedcore.api.inventory.BInventory)

Aggregations

BInventoryButton (com.bencodez.advancedcore.api.inventory.BInventoryButton)63 ClickEvent (com.bencodez.advancedcore.api.inventory.BInventory.ClickEvent)62 ItemBuilder (com.bencodez.advancedcore.api.item.ItemBuilder)54 BInventory (com.bencodez.advancedcore.api.inventory.BInventory)31 Player (org.bukkit.entity.Player)31 EditGUI (com.bencodez.advancedcore.api.inventory.editgui.EditGUI)30 RewardEditData (com.bencodez.advancedcore.api.rewards.RewardEditData)26 EditGUIValueInventory (com.bencodez.advancedcore.api.inventory.editgui.valuetypes.EditGUIValueInventory)23 ArrayList (java.util.ArrayList)15 EditGUIValueString (com.bencodez.advancedcore.api.inventory.editgui.valuetypes.EditGUIValueString)10 ValueRequestBuilder (com.bencodez.advancedcore.api.valuerequest.ValueRequestBuilder)10 ItemStack (org.bukkit.inventory.ItemStack)10 ValueRequest (com.bencodez.advancedcore.api.valuerequest.ValueRequest)9 StringListener (com.bencodez.advancedcore.api.valuerequest.listeners.StringListener)9 EditGUIButton (com.bencodez.advancedcore.api.inventory.editgui.EditGUIButton)8 UpdatingBInventoryButton (com.bencodez.advancedcore.api.inventory.UpdatingBInventoryButton)7 AdvancedCoreUser (com.bencodez.advancedcore.api.user.AdvancedCoreUser)7 VoteSite (com.bencodez.votingplugin.objects.VoteSite)7 Reward (com.bencodez.advancedcore.api.rewards.Reward)6 NumberListener (com.bencodez.advancedcore.api.valuerequest.listeners.NumberListener)5