Search in sources :

Example 16 with ClickEvent

use of com.Ben12345rocks.AdvancedCore.Util.Inventory.BInventory.ClickEvent in project VotingPlugin by Ben12345rocks.

the class VoteShop method voteShop.

public void voteShop(Player player) {
    BInventory inv = new BInventory(Config.getInstance().getVoteShopName());
    for (String identifier : Config.getInstance().getIdentifiers()) {
        ItemBuilder builder = new ItemBuilder(Config.getInstance().getIdentifierSection(identifier));
        inv.addButton(Config.getInstance().getIdentifierSlot(identifier), new BInventoryButton(builder) {

            @Override
            public void onClick(ClickEvent event) {
                Player player = event.getWhoClicked();
                User user = UserManager.getInstance().getVotingPluginUser(player);
                int points = Config.getInstance().getIdentifierCost(identifier);
                String identifier = Config.getInstance().getIdentifierFromSlot(event.getSlot());
                if (identifier != null) {
                    if (user.removePoints(points)) {
                        RewardHandler.getInstance().giveReward(user, Config.getInstance().getData(), Config.getInstance().getIdentifierRewardsPath(identifier));
                        user.sendMessage(Config.getInstance().getFormatShopPurchaseMsg().replace("%Identifier%", identifier).replace("%Points%", "" + points));
                    } else {
                        user.sendMessage(Config.getInstance().getFormatShopFailedMsg().replace("%Identifier%", identifier).replace("%Points%", "" + points));
                    }
                }
            }
        });
    }
    if (Config.getInstance().getVoteShopBackButton()) {
        inv.addButton(new BInventoryButton(PlayerGUIs.getInstance().getBackButton()) {

            @Override
            public void onClick(ClickEvent event) {
                PlayerGUIs.getInstance().openVoteGUI(event.getPlayer(), UserManager.getInstance().getVotingPluginUser(player));
            }
        });
    }
    inv.openInventory(player);
}
Also used : ItemBuilder(com.Ben12345rocks.AdvancedCore.Util.Item.ItemBuilder) Player(org.bukkit.entity.Player) User(com.Ben12345rocks.VotingPlugin.Objects.User) BInventoryButton(com.Ben12345rocks.AdvancedCore.Util.Inventory.BInventoryButton) ClickEvent(com.Ben12345rocks.AdvancedCore.Util.Inventory.BInventory.ClickEvent) BInventory(com.Ben12345rocks.AdvancedCore.Util.Inventory.BInventory)

Aggregations

ClickEvent (com.Ben12345rocks.AdvancedCore.Util.Inventory.BInventory.ClickEvent)16 BInventoryButton (com.Ben12345rocks.AdvancedCore.Util.Inventory.BInventoryButton)16 BInventory (com.Ben12345rocks.AdvancedCore.Util.Inventory.BInventory)15 ItemBuilder (com.Ben12345rocks.AdvancedCore.Util.Item.ItemBuilder)10 VoteSite (com.Ben12345rocks.VotingPlugin.Objects.VoteSite)9 Player (org.bukkit.entity.Player)8 User (com.Ben12345rocks.VotingPlugin.Objects.User)7 ArrayList (java.util.ArrayList)4 ItemStack (org.bukkit.inventory.ItemStack)4 StringListener (com.Ben12345rocks.AdvancedCore.Util.ValueRequest.Listeners.StringListener)3 ValueRequest (com.Ben12345rocks.AdvancedCore.Util.ValueRequest.ValueRequest)3 BooleanListener (com.Ben12345rocks.AdvancedCore.Util.ValueRequest.Listeners.BooleanListener)2 NumberListener (com.Ben12345rocks.AdvancedCore.Util.ValueRequest.Listeners.NumberListener)2 ValueRequestBuilder (com.Ben12345rocks.AdvancedCore.Util.ValueRequest.ValueRequestBuilder)1 TopVoter (com.Ben12345rocks.VotingPlugin.Objects.TopVoter)1 DateTimeFormatter (java.time.format.DateTimeFormatter)1 HashMap (java.util.HashMap)1 Entry (java.util.Map.Entry)1 OfflinePlayer (org.bukkit.OfflinePlayer)1