Search in sources :

Example 6 with VotingPluginUser

use of com.bencodez.votingplugin.user.VotingPluginUser in project VotingPlugin by Ben12345rocks.

the class VoteGUI method onChest.

@Override
public void onChest(Player player) {
    if (this.user == null) {
        user = UserManager.getInstance().getVotingPluginUser(player);
    }
    BInventory inv = new BInventory(plugin.getGui().getChestVoteGUIName());
    if (!plugin.getConfigFile().isAlwaysCloseInventory()) {
        inv.dontClose();
    }
    if (player.getUniqueId().toString().equals(user.getUUID())) {
        inv.requirePermission("VotingPlugin.Commands.Vote.GUI");
    } else {
        inv.requirePermission("VotingPlugin.Commands.Vote.GUI.Other");
    }
    inv.addPlaceholder("points", "" + user.getPoints());
    inv.addPlaceholder("player", user.getPlayerName());
    inv.addPlaceholder("top", plugin.getConfigFile().getVoteTopDefault());
    for (String slot : plugin.getGui().getChestVoteGUISlots()) {
        ItemBuilder builder = getItemSlot(slot, player);
        inv.addButton(new UpdatingBInventoryButton(builder, 1000, 1000) {

            @Override
            public void onClick(ClickEvent event) {
                Player player = event.getWhoClicked();
                String cmd = plugin.getGui().getChestVoteGUISlotCommand(slot);
                if (cmd.equalsIgnoreCase("none")) {
                    return;
                } else if (!cmd.equals("")) {
                    event.runSync(new Runnable() {

                        @Override
                        public void run() {
                            player.performCommand(cmd);
                        }
                    });
                } else {
                    if (slot.equalsIgnoreCase("url")) {
                        new VoteURL(plugin, player, user, true).open();
                    } else if (slot.equalsIgnoreCase("next")) {
                        new VoteNext(plugin, player, user).open(GUIMethod.CHEST);
                    } else if (slot.equalsIgnoreCase("last")) {
                        new VoteLast(plugin, player, user).open(GUIMethod.CHEST);
                    } else if (slot.equalsIgnoreCase("total")) {
                        new VoteTotal(plugin, player, user).open(GUIMethod.CHEST);
                    } else if (slot.equalsIgnoreCase("top")) {
                        new VoteTopVoter(plugin, player, user, TopVoter.getDefault(), 1).open(GUIMethod.CHEST);
                    } else if (slot.equalsIgnoreCase("today")) {
                        new VoteToday(plugin, player, user, 1).open(GUIMethod.CHEST);
                    } else if (slot.equalsIgnoreCase("help")) {
                        player.performCommand("vote help");
                    } else if (slot.equalsIgnoreCase("shop")) {
                        new VoteShop(plugin, player, user).open(GUIMethod.CHEST);
                    } else if (slot.equalsIgnoreCase("lastmonth")) {
                        new VoteTopVoterLastMonth(plugin, player, user).open(GUIMethod.CHEST);
                    } else if (slot.equalsIgnoreCase("best")) {
                        new VoteBest(plugin, player, user).open(GUIMethod.CHEST);
                    } else if (slot.equalsIgnoreCase("streak")) {
                        new VoteStreak(plugin, player, user).open(GUIMethod.CHEST);
                    }
                }
                if (RewardHandler.getInstance().hasRewards(plugin.getGui().getData(), plugin.getGui().getChestVoteGUISlotRewardsPath(slot))) {
                    RewardHandler.getInstance().giveReward(UserManager.getInstance().getVotingPluginUser(player), plugin.getGui().getData(), plugin.getGui().getChestVoteGUISlotRewardsPath(slot), new RewardOptions().addPlaceholder("identifier", slot));
                }
            }

            @Override
            public ItemBuilder onUpdate(Player player) {
                ItemBuilder item = getItemSlot(slot, player);
                VotingPluginUser user = UserManager.getInstance().getVotingPluginUser(player);
                item.addPlaceholder("points", "" + user.getPoints());
                item.addPlaceholder("player", user.getPlayerName());
                item.addPlaceholder("top", plugin.getConfigFile().getVoteTopDefault());
                return item;
            }
        });
    }
    inv.openInventory(player);
}
Also used : UpdatingBInventoryButton(com.bencodez.advancedcore.api.inventory.UpdatingBInventoryButton) Player(org.bukkit.entity.Player) ClickEvent(com.bencodez.advancedcore.api.inventory.BInventory.ClickEvent) BInventory(com.bencodez.advancedcore.api.inventory.BInventory) RewardOptions(com.bencodez.advancedcore.api.rewards.RewardOptions) ItemBuilder(com.bencodez.advancedcore.api.item.ItemBuilder) VotingPluginUser(com.bencodez.votingplugin.user.VotingPluginUser)

Example 7 with VotingPluginUser

use of com.bencodez.votingplugin.user.VotingPluginUser in project VotingPlugin by Ben12345rocks.

the class VoteShop method onChest.

@Override
public void onChest(Player player) {
    if (!plugin.getGui().getChestVoteShopEnabled()) {
        player.sendMessage(StringParser.getInstance().colorize(plugin.getGui().getChestVoteShopDisabled()));
        return;
    }
    if (this.user == null) {
        user = plugin.getVotingPluginUserManager().getVotingPluginUser(player);
    }
    BInventory inv = new BInventory(plugin.getGui().getChestVoteShopName());
    inv.addPlaceholder("points", "" + user.getPoints());
    inv.dontClose();
    for (final String identifier : plugin.getGui().getChestShopIdentifiers()) {
        String perm = plugin.getGui().getChestVoteShopPermission(identifier);
        boolean hasPerm = false;
        if (perm.isEmpty()) {
            hasPerm = true;
        } else {
            hasPerm = player.hasPermission(perm);
        }
        int limit = plugin.getGui().getChestShopIdentifierLimit(identifier);
        boolean limitPass = true;
        if (limit > 0) {
            if (user.getVoteShopIdentifierLimit(identifier) >= limit) {
                limitPass = false;
            }
        }
        if (!plugin.getGui().getChestVoteShopNotBuyable(identifier)) {
            if (hasPerm && (limitPass || !plugin.getGui().isChestVoteShopHideLimitedReached())) {
                ItemBuilder builder = new ItemBuilder(plugin.getGui().getChestShopIdentifierSection(identifier));
                inv.addButton(new BInventoryButton(builder) {

                    @Override
                    public void onClick(ClickEvent event) {
                        Player player = event.getWhoClicked();
                        VotingPluginUser user = UserManager.getInstance().getVotingPluginUser(player);
                        user.clearCache();
                        String identifier = (String) getData("identifier");
                        int limit = (int) getData("Limit");
                        int points = plugin.getGui().getChestShopIdentifierCost(identifier);
                        if (identifier != null) {
                            if (plugin.getGui().getChestVoteShopCloseGUI(identifier)) {
                                event.getButton().getInv().closeInv(player, null);
                            }
                            // limit fail-safe, should never be needed, except in rare cases
                            boolean limitPass = true;
                            if (limit > 0) {
                                if (user.getVoteShopIdentifierLimit(identifier) >= limit) {
                                    limitPass = false;
                                }
                            }
                            if (limitPass) {
                                if (!plugin.getGui().isChestVoteShopRequireConfirmation(identifier)) {
                                    HashMap<String, String> placeholders = new HashMap<String, String>();
                                    placeholders.put("identifier", plugin.getGui().getChestShopIdentifierIdentifierName(identifier));
                                    placeholders.put("points", "" + points);
                                    placeholders.put("limit", "" + limit);
                                    if (user.removePoints(points)) {
                                        plugin.getLogger().info("VoteShop: " + user.getPlayerName() + "/" + user.getUUID() + " bought " + identifier + " for " + points);
                                        RewardHandler.getInstance().giveReward(user, plugin.getGui().getData(), plugin.getGui().getChestShopIdentifierRewardsPath(identifier), new RewardOptions().setPlaceholders(placeholders));
                                        user.sendMessage(StringParser.getInstance().replacePlaceHolder(plugin.getGui().getCHESTVoteShopPurchase(identifier), placeholders));
                                        if (limit > 0) {
                                            user.setVoteShopIdentifierLimit(identifier, user.getVoteShopIdentifierLimit(identifier) + 1);
                                        }
                                    } else {
                                        user.sendMessage(StringParser.getInstance().replacePlaceHolder(plugin.getConfigFile().getFormatShopFailedMsg(), placeholders));
                                    }
                                } else {
                                    new VoteShopConfirm(plugin, player, user, identifier).open(GUIMethod.CHEST);
                                }
                            } else {
                                user.sendMessage(plugin.getGui().getChestVoteShopLimitReached());
                            }
                        }
                    }
                }.addData("identifier", identifier).addData("Limit", limit));
            }
        } else {
            if (hasPerm) {
                ItemBuilder builder = new ItemBuilder(plugin.getGui().getChestShopIdentifierSection(identifier));
                inv.addButton(new BInventoryButton(builder) {

                    @Override
                    public void onClick(ClickEvent event) {
                    }
                }.dontClose().addData("identifier", identifier).addData("Limit", limit));
            }
        }
    }
    if (plugin.getGui().getChestVoteShopBackButton()) {
        inv.addButton(plugin.getCommandLoader().getBackButton(user));
    }
    inv.openInventory(player);
}
Also used : Player(org.bukkit.entity.Player) HashMap(java.util.HashMap) BInventoryButton(com.bencodez.advancedcore.api.inventory.BInventoryButton) ClickEvent(com.bencodez.advancedcore.api.inventory.BInventory.ClickEvent) BInventory(com.bencodez.advancedcore.api.inventory.BInventory) RewardOptions(com.bencodez.advancedcore.api.rewards.RewardOptions) ItemBuilder(com.bencodez.advancedcore.api.item.ItemBuilder) VotingPluginUser(com.bencodez.votingplugin.user.VotingPluginUser)

Example 8 with VotingPluginUser

use of com.bencodez.votingplugin.user.VotingPluginUser in project VotingPlugin by Ben12345rocks.

the class AdminVotePlaceholdersPlayer method onBook.

@Override
public void onBook(Player player) {
    BookWrapper book = new BookWrapper("Placeholders");
    for (PlaceHolder<VotingPluginUser> placeholder : plugin.getPlaceholders().getPlaceholders()) {
        String identifier = placeholder.getIdentifier();
        if (identifier.endsWith("_")) {
            identifier += "1";
        }
        String value = placeholder.placeholderRequest(user, identifier);
        String msg = identifier + " = " + value;
        Layout layout = new Layout(new ArrayList<String>(Arrays.asList("[Json]")));
        layout.replaceTextComponent("[Json]", BookUtil.TextBuilder.of(msg).color(ChatColor.AQUA).onHover(BookUtil.HoverAction.showText(value)).build());
        book.addLayout(layout);
    }
    for (NonPlayerPlaceHolder<VotingPluginUser> placeholder : plugin.getPlaceholders().getNonPlayerPlaceholders()) {
        String identifier = placeholder.getIdentifier();
        if (identifier.endsWith("_")) {
            identifier += "1";
        }
        String value = placeholder.placeholderRequest(identifier);
        String msg = identifier + " = " + value;
        Layout layout = new Layout(new ArrayList<String>(Arrays.asList("[Json]")));
        layout.replaceTextComponent("[Json]", BookUtil.TextBuilder.of(msg).color(ChatColor.AQUA).onHover(BookUtil.HoverAction.showText(value)).build());
        book.addLayout(layout);
    }
    book.open(player);
}
Also used : BookWrapper(com.bencodez.advancedcore.api.bookgui.BookWrapper) Layout(com.bencodez.advancedcore.api.bookgui.Layout) VotingPluginUser(com.bencodez.votingplugin.user.VotingPluginUser)

Example 9 with VotingPluginUser

use of com.bencodez.votingplugin.user.VotingPluginUser in project VotingPlugin by Ben12345rocks.

the class AdminVotePlaceholdersPlayer method onChat.

@Override
public void onChat(CommandSender sender) {
    ArrayList<String> msg = new ArrayList<String>();
    msg.add("&cPlaceholders:");
    VotingPluginUser placeholderUser = user;
    if (plugin.getConfigFile().isUsePrimaryAccountForPlaceholders() && user.hasPrimaryAccount()) {
        placeholderUser = UserManager.getInstance().getVotingPluginUser(user.getPrimaryAccount());
    }
    for (PlaceHolder<VotingPluginUser> placeholder : plugin.getPlaceholders().getPlaceholders()) {
        String identifier = placeholder.getIdentifier();
        if (identifier.endsWith("_")) {
            identifier += "1";
        }
        msg.add("VotingPlugin_" + identifier + " = " + placeholder.placeholderRequest(placeholderUser, identifier));
    }
    for (NonPlayerPlaceHolder<VotingPluginUser> placeholder : plugin.getPlaceholders().getNonPlayerPlaceholders()) {
        String identifier = placeholder.getIdentifier();
        if (identifier.endsWith("_")) {
            identifier += "1";
        }
        msg.add("VotingPlugin_" + identifier + " = " + placeholder.placeholderRequest(identifier));
    }
    sendMessage(msg);
}
Also used : ArrayList(java.util.ArrayList) VotingPluginUser(com.bencodez.votingplugin.user.VotingPluginUser)

Example 10 with VotingPluginUser

use of com.bencodez.votingplugin.user.VotingPluginUser in project VotingPlugin by Ben12345rocks.

the class VotingPluginMain method basicBungeeUpdate.

public void basicBungeeUpdate() {
    for (Player player : Bukkit.getOnlinePlayers()) {
        VotingPluginUser user = UserManager.getInstance().getVotingPluginUser(player);
        user.clearCache();
        user.offVote();
        user.checkOfflineRewards();
    }
}
Also used : TopVoterPlayer(com.bencodez.votingplugin.topvoter.TopVoterPlayer) Player(org.bukkit.entity.Player) OfflinePlayer(org.bukkit.OfflinePlayer) VotingPluginUser(com.bencodez.votingplugin.user.VotingPluginUser)

Aggregations

VotingPluginUser (com.bencodez.votingplugin.user.VotingPluginUser)27 Player (org.bukkit.entity.Player)11 VoteSite (com.bencodez.votingplugin.objects.VoteSite)9 ArrayList (java.util.ArrayList)9 HashMap (java.util.HashMap)7 LinkedHashMap (java.util.LinkedHashMap)6 BInventory (com.bencodez.advancedcore.api.inventory.BInventory)5 ClickEvent (com.bencodez.advancedcore.api.inventory.BInventory.ClickEvent)5 ItemBuilder (com.bencodez.advancedcore.api.item.ItemBuilder)5 RewardOptions (com.bencodez.advancedcore.api.rewards.RewardOptions)5 TopVoter (com.bencodez.votingplugin.topvoter.TopVoter)5 TopVoterPlayer (com.bencodez.votingplugin.topvoter.TopVoterPlayer)5 EventHandler (org.bukkit.event.EventHandler)5 BInventoryButton (com.bencodez.advancedcore.api.inventory.BInventoryButton)4 AdminVotePlaceholdersPlayer (com.bencodez.votingplugin.commands.gui.admin.AdminVotePlaceholdersPlayer)3 AdminVoteVotePlayer (com.bencodez.votingplugin.commands.gui.admin.AdminVoteVotePlayer)3 VoteURLVoteSite (com.bencodez.votingplugin.commands.gui.player.VoteURLVoteSite)3 BookWrapper (com.bencodez.advancedcore.api.bookgui.BookWrapper)2 Layout (com.bencodez.advancedcore.api.bookgui.Layout)2 CommandHandler (com.bencodez.advancedcore.api.command.CommandHandler)2