Search in sources :

Example 1 with RewardBuilder

use of com.bencodez.advancedcore.api.rewards.RewardBuilder in project VotingPlugin by Ben12345rocks.

the class VoteURL method onChest.

@Override
public void onChest(Player player) {
    // normal GUI
    BInventory inv = new BInventory(plugin.getGui().getChestVoteURLName());
    if (plugin.getGui().getChestVoteURLViewAllUrlsButtonEnabled()) {
        ItemBuilder builderAll = getItemAll();
        inv.addButton(new UpdatingBInventoryButton(builderAll, 5000, 5000) {

            @Override
            public void onClick(ClickEvent event) {
                VotingPluginUser user = UserManager.getInstance().getVotingPluginUser(event.getPlayer());
                json = true;
                user.sendMessage(getChat(player));
            }

            @Override
            public ItemBuilder onUpdate(Player player) {
                return getItemAll();
            }
        });
    }
    int startSlot = plugin.getGui().getChestVoteURLAllUrlsButtonStartSlot();
    for (final VoteSite voteSite : plugin.getVoteSites()) {
        if (!voteSite.isHidden()) {
            ItemBuilder builder = getItemVoteSite(voteSite);
            if (startSlot >= 0) {
                builder.setSlot(startSlot);
                startSlot++;
            }
            inv.addButton(new UpdatingBInventoryButton(builder, 5000, 5000) {

                @Override
                public void onClick(ClickEvent event) {
                    Player player = event.getPlayer();
                    if (player != null) {
                        VotingPluginUser user = UserManager.getInstance().getVotingPluginUser(player);
                        user.sendMessage(StringParser.getInstance().replacePlaceHolder(StringParser.getInstance().replacePlaceHolder(StringParser.getInstance().replacePlaceHolder(plugin.getGui().getChestVoteURLURLText(), "voteurl", voteSite.getVoteURL()), "sitename", voteSite.getDisplayName()), "player", player.getName()));
                    }
                }

                @Override
                public ItemBuilder onUpdate(Player player) {
                    return getItemVoteSite(voteSite);
                }
            });
        }
    }
    for (final String str : plugin.getGui().getChestVoteURLExtraItems()) {
        inv.addButton(new BInventoryButton(new ItemBuilder(plugin.getGui().getChestVoteURLExtraItemsItem(str))) {

            @Override
            public void onClick(ClickEvent clickEvent) {
                new RewardBuilder(plugin.getGui().getData(), "CHEST.VoteURL.ExtraItems." + str + ".Rewards").setGiveOffline(false).send(clickEvent.getPlayer());
            }
        });
    }
    if (plugin.getGui().getChestVoteURLBackButton()) {
        inv.addButton(plugin.getCommandLoader().getBackButton(user));
    }
    inv.openInventory(player);
}
Also used : VoteSite(com.bencodez.votingplugin.objects.VoteSite) RewardBuilder(com.bencodez.advancedcore.api.rewards.RewardBuilder) UpdatingBInventoryButton(com.bencodez.advancedcore.api.inventory.UpdatingBInventoryButton) ItemBuilder(com.bencodez.advancedcore.api.item.ItemBuilder) Player(org.bukkit.entity.Player) ClickEvent(com.bencodez.advancedcore.api.inventory.BInventory.ClickEvent) UpdatingBInventoryButton(com.bencodez.advancedcore.api.inventory.UpdatingBInventoryButton) BInventoryButton(com.bencodez.advancedcore.api.inventory.BInventoryButton) BInventory(com.bencodez.advancedcore.api.inventory.BInventory) VotingPluginUser(com.bencodez.votingplugin.user.VotingPluginUser)

Example 2 with RewardBuilder

use of com.bencodez.advancedcore.api.rewards.RewardBuilder in project VotingPlugin by Ben12345rocks.

the class BungeeHandler method load.

public void load() {
    plugin.debug("Loading bungee handler");
    method = BungeeMethod.getByName(plugin.getBungeeSettings().getBungeeMethod());
    plugin.getLogger().info("Using BungeeMethod: " + method.toString());
    if (method.equals(BungeeMethod.MYSQL)) {
        plugin.registerBungeeChannels("vp:vp");
    } else if (method.equals(BungeeMethod.PLUGINMESSAGING)) {
        plugin.registerBungeeChannels("vp:vp");
        bungeeVotePartyCurrent = plugin.getServerData().getBungeeVotePartyCurrent();
        bungeeVotePartyRequired = plugin.getServerData().getBungeeVotePartyRequired();
        plugin.getPluginMessaging().setDebug(plugin.getBungeeSettings().isBungeeDebug());
        plugin.getPluginMessaging().add(new PluginMessageHandler("Vote") {

            @Override
            public void onRecieve(String subChannel, ArrayList<String> args) {
                if (args.size() > 8) {
                    int bungeeVersion = Integer.parseInt(args.get(8));
                    if (bungeeVersion != BungeeVersion.getPluginMessageVersion()) {
                        plugin.getLogger().warning("Incompatible version with bungee, please update all servers");
                        return;
                    }
                    String player = args.get(0);
                    String uuid = args.get(1);
                    String service = args.get(2);
                    long time = Long.parseLong(args.get(3));
                    plugin.debug("pluginmessaging vote received from " + player + "/" + uuid + " on " + service);
                    VotingPluginUser user = UserManager.getInstance().getVotingPluginUser(UUID.fromString(uuid), player);
                    boolean wasOnline = Boolean.valueOf(args.get(4));
                    BungeeMessageData text = new BungeeMessageData(args.get(6));
                    bungeeVotePartyCurrent = text.getVotePartyCurrent();
                    bungeeVotePartyRequired = text.getVotePartyRequired();
                    plugin.getPlaceholders().onBungeeVotePartyUpdate();
                    boolean setTotals = Boolean.valueOf(args.get(7));
                    user.clearCache();
                    boolean broadcast = true;
                    boolean bungeeBroadcast = false;
                    if (args.size() > 9) {
                        bungeeBroadcast = Boolean.valueOf(args.get(9));
                    }
                    if (!bungeeBroadcast) {
                        if (!plugin.getBungeeSettings().isBungeeBroadcast() && !plugin.getBungeeSettings().isDisableBroadcast()) {
                            if (wasOnline || plugin.getBungeeSettings().isBungeeBroadcastAlways()) {
                                VoteSite site = plugin.getVoteSite(service, true);
                                if (site != null) {
                                    site.broadcastVote(user, false);
                                    broadcast = false;
                                } else {
                                    plugin.getLogger().warning("No votesite for " + service);
                                }
                            }
                        }
                    } else {
                        broadcast = false;
                    }
                    user.bungeeVotePluginMessaging(service, time, text, !setTotals, wasOnline, broadcast);
                    if (plugin.getBungeeSettings().isPerServerPoints()) {
                        user.addPoints(plugin.getConfigFile().getPointsOnVote());
                    }
                    if (Boolean.valueOf(args.get(5))) {
                        plugin.getServerData().addServiceSite(service);
                    }
                } else {
                    plugin.getLogger().warning("Incompatible version with bungee, please update all servers");
                }
            }
        });
        plugin.getPluginMessaging().add(new PluginMessageHandler("VoteOnline") {

            @Override
            public void onRecieve(String subChannel, ArrayList<String> args) {
                if (args.size() > 8) {
                    int bungeeVersion = Integer.parseInt(args.get(8));
                    if (bungeeVersion != BungeeVersion.getPluginMessageVersion()) {
                        plugin.getLogger().warning("Incompatible version with bungee, please update all servers");
                        return;
                    }
                    String player = args.get(0);
                    String uuid = args.get(1);
                    String service = args.get(2);
                    long time = Long.parseLong(args.get(3));
                    BungeeMessageData text = new BungeeMessageData(args.get(6));
                    bungeeVotePartyCurrent = text.getVotePartyCurrent();
                    bungeeVotePartyRequired = text.getVotePartyRequired();
                    plugin.getPlaceholders().onBungeeVotePartyUpdate();
                    plugin.debug("pluginmessaging voteonline received from " + player + "/" + uuid + " on " + service);
                    VotingPluginUser user = UserManager.getInstance().getVotingPluginUser(UUID.fromString(uuid), player);
                    user.clearCache();
                    if (plugin.getBungeeSettings().isPerServerPoints()) {
                        user.addPoints(plugin.getConfigFile().getPointsOnVote());
                    }
                    boolean setTotals = Boolean.valueOf(args.get(7));
                    boolean wasOnline = Boolean.valueOf(args.get(4));
                    boolean broadcast = true;
                    boolean bungeeBroadcast = false;
                    if (args.size() > 9) {
                        bungeeBroadcast = Boolean.valueOf(args.get(9));
                    }
                    if (!bungeeBroadcast) {
                        if (!plugin.getBungeeSettings().isBungeeBroadcast() && !plugin.getBungeeSettings().isDisableBroadcast()) {
                            if (Boolean.valueOf(args.get(4)) || plugin.getBungeeSettings().isBungeeBroadcastAlways()) {
                                VoteSite site = plugin.getVoteSite(service, true);
                                if (site != null) {
                                    site.broadcastVote(user, false);
                                    broadcast = false;
                                } else {
                                    plugin.getLogger().warning("No votesite for " + service);
                                }
                            }
                        }
                    } else {
                        broadcast = false;
                    }
                    user.bungeeVotePluginMessaging(service, time, text, !setTotals, wasOnline, broadcast);
                    if (plugin.getBungeeSettings().isPerServerPoints()) {
                        user.addPoints(plugin.getConfigFile().getPointsOnVote());
                    }
                    if (Boolean.valueOf(args.get(5))) {
                        plugin.getServerData().addServiceSite(service);
                    }
                } else {
                    plugin.getLogger().warning("Incompatible version with bungee, please update all servers");
                }
            }
        });
        plugin.getPluginMessaging().add(new PluginMessageHandler("VoteUpdate") {

            @Override
            public void onRecieve(String subChannel, ArrayList<String> args) {
                String player = args.get(0);
                plugin.debug("pluginmessaging voteupdate received for " + player);
                VotingPluginUser user = UserManager.getInstance().getVotingPluginUser(UUID.fromString(player));
                user.clearCache();
                user.offVote();
                if (args.size() > 2) {
                    bungeeVotePartyCurrent = Integer.parseInt(args.get(1));
                    bungeeVotePartyRequired = Integer.parseInt(args.get(2));
                }
                plugin.setUpdate(true);
            }
        });
        plugin.getPluginMessaging().add(new PluginMessageHandler("VoteBroadcast") {

            @Override
            public void onRecieve(String subChannel, ArrayList<String> args) {
                if (args.size() > 2) {
                    String uuid = args.get(0);
                    String service = args.get(2);
                    VotingPluginUser user = UserManager.getInstance().getVotingPluginUser(UUID.fromString(uuid), args.get(1));
                    VoteSite site = plugin.getVoteSite(service, true);
                    if (site != null) {
                        site.broadcastVote(user, false);
                    } else {
                        plugin.getLogger().warning("No votesite for " + service);
                    }
                }
            }
        });
        plugin.getPluginMessaging().add(new PluginMessageHandler("Status") {

            @Override
            public void onRecieve(String subChannel, ArrayList<String> args) {
                String server = args.get(0);
                plugin.getPluginMessaging().sendPluginMessage("statusokay", server);
            }
        });
        plugin.getPluginMessaging().add(new PluginMessageHandler("VotePartyBungee") {

            @Override
            public void onRecieve(String subChannel, ArrayList<String> args) {
                for (Player p : Bukkit.getOnlinePlayers()) {
                    new RewardBuilder(plugin.getBungeeSettings().getData(), "BungeeVotePartyRewards").send(p);
                }
            }
        });
        plugin.getPluginMessaging().add(new PluginMessageHandler("VotePartyBroadcast") {

            @Override
            public void onRecieve(String subChannel, ArrayList<String> args) {
                String broadcast = args.get(0);
                MiscUtils.getInstance().broadcast(broadcast);
            }
        });
    } else if (method.equals(BungeeMethod.SOCKETS)) {
        encryptionHandler = new EncryptionHandler(new File(plugin.getDataFolder(), "secretkey.key"));
        clientHandler = new ClientHandler(plugin.getBungeeSettings().getBungeeServerHost(), plugin.getBungeeSettings().getBungeeServerPort(), encryptionHandler, plugin.getBungeeSettings().isBungeeDebug());
        socketHandler = new SocketHandler(plugin.getVersion(), plugin.getBungeeSettings().getSpigotServerHost(), plugin.getBungeeSettings().getSpigotServerPort(), encryptionHandler, plugin.getBungeeSettings().isBungeeDebug());
        socketHandler.add(new SocketReceiver("bungeevote") {

            @Override
            public void onReceive(String[] data) {
                if (data.length > 5) {
                    plugin.extraDebug("BungeeVote from " + data[2] + ", processing");
                    String uuid = data[1];
                    VotingPluginUser user = null;
                    if (!uuid.isEmpty()) {
                        user = UserManager.getInstance().getVotingPluginUser(UUID.fromString(uuid));
                    } else {
                        user = UserManager.getInstance().getVotingPluginUser(data[2]);
                    }
                    user.clearCache();
                    if (plugin.getBungeeSettings().isPerServerPoints()) {
                        user.addPoints(plugin.getConfigFile().getPointsOnVote());
                    }
                    user.bungeeVote(data[3], new BungeeMessageData(data[4]), !Boolean.valueOf(data[5]));
                }
            }
        });
        socketHandler.add(new SocketReceiver("bungeevoteonline") {

            @Override
            public void onReceive(String[] data) {
                if (data.length > 5) {
                    plugin.extraDebug("BungeeVoteOnline from " + data[2] + ", processing");
                    String uuid = data[1];
                    VotingPluginUser user = null;
                    if (!uuid.isEmpty()) {
                        user = UserManager.getInstance().getVotingPluginUser(UUID.fromString(uuid));
                    } else {
                        user = UserManager.getInstance().getVotingPluginUser(data[2]);
                    }
                    user.clearCache();
                    if (plugin.getBungeeSettings().isPerServerPoints()) {
                        user.addPoints(plugin.getConfigFile().getPointsOnVote());
                    }
                    user.bungeeVoteOnline(data[3], new BungeeMessageData(data[4]), !Boolean.valueOf(data[5]));
                }
            }
        });
        socketHandler.add(new SocketReceiver("BungeeBroadcast") {

            @Override
            public void onReceive(String[] data) {
                if (data.length > 2) {
                    VoteSite site = plugin.getVoteSite(data[1], true);
                    String p = data[3];
                    VotingPluginUser user = UserManager.getInstance().getVotingPluginUser(p);
                    if (site != null) {
                        site.broadcastVote(user, false);
                    } else {
                        plugin.getLogger().warning("No votesite for " + data[1]);
                    }
                }
            }
        });
        socketHandler.add(new SocketReceiver("Status") {

            @Override
            public void onReceive(String[] data) {
                if (data.length > 0) {
                    plugin.getLogger().info("Received status command, sending status back");
                    sendData("StatusOkay", plugin.getOptions().getServer());
                }
            }
        });
        socketHandler.add(new SocketReceiver("BungeeUpdate") {

            @Override
            public void onReceive(String[] data) {
                plugin.setUpdate(true);
            }
        });
        socketHandler.add(new SocketReceiver("VotePartyBungee") {

            @Override
            public void onReceive(String[] data) {
                for (Player p : Bukkit.getOnlinePlayers()) {
                    new RewardBuilder(plugin.getBungeeSettings().getData(), "BungeeVotePartyRewards").send(p);
                }
            }
        });
        socketHandler.add(new SocketReceiver("VotePartyBroadcast") {

            @Override
            public void onReceive(String[] data) {
                String broadcast = data[0];
                MiscUtils.getInstance().broadcast(broadcast);
            }
        });
        if (plugin.getOptions().getServer().equalsIgnoreCase("pleaseset")) {
            plugin.getLogger().warning("Server name for bungee voting is not set, please set it");
        }
    }
}
Also used : Player(org.bukkit.entity.Player) SocketHandler(com.bencodez.advancedcore.bungeeapi.sockets.SocketHandler) SocketReceiver(com.bencodez.advancedcore.bungeeapi.sockets.SocketReceiver) ArrayList(java.util.ArrayList) ClientHandler(com.bencodez.advancedcore.bungeeapi.sockets.ClientHandler) PluginMessageHandler(com.bencodez.advancedcore.bungeeapi.pluginmessage.PluginMessageHandler) EncryptionHandler(com.bencodez.advancedcore.api.misc.encryption.EncryptionHandler) VoteSite(com.bencodez.votingplugin.objects.VoteSite) RewardBuilder(com.bencodez.advancedcore.api.rewards.RewardBuilder) BungeeMessageData(com.bencodez.votingplugin.bungee.BungeeMessageData) File(java.io.File) VotingPluginUser(com.bencodez.votingplugin.user.VotingPluginUser)

Example 3 with RewardBuilder

use of com.bencodez.advancedcore.api.rewards.RewardBuilder in project VotingPlugin by Ben12345rocks.

the class SpecialRewards method giveVoteStreakReward.

public void giveVoteStreakReward(VotingPluginUser user, boolean online, String type, String string, int votes, boolean forceBungee) {
    PlayerSpecialRewardEvent event = new PlayerSpecialRewardEvent(user, SpecialRewardType.VOTESTREAK.setType(type).setAmount(votes));
    Bukkit.getPluginManager().callEvent(event);
    if (event.isCancelled()) {
        return;
    }
    new RewardBuilder(plugin.getSpecialRewardsConfig().getData(), plugin.getSpecialRewardsConfig().getVoteStreakRewardsPath(type, string)).setOnline(online).withPlaceHolder("Type", type).setServer(forceBungee).withPlaceHolder("Streak", "" + votes).send(user);
}
Also used : RewardBuilder(com.bencodez.advancedcore.api.rewards.RewardBuilder) PlayerSpecialRewardEvent(com.bencodez.votingplugin.events.PlayerSpecialRewardEvent)

Example 4 with RewardBuilder

use of com.bencodez.advancedcore.api.rewards.RewardBuilder in project VotingPlugin by Ben12345rocks.

the class SpecialRewards method giveCumulativeVoteReward.

public void giveCumulativeVoteReward(VotingPluginUser user, boolean online, int cumulative, boolean forceBungee) {
    PlayerSpecialRewardEvent event = new PlayerSpecialRewardEvent(user, SpecialRewardType.CUMMULATIVE.setAmount(cumulative));
    Bukkit.getPluginManager().callEvent(event);
    if (event.isCancelled()) {
        return;
    }
    new RewardBuilder(plugin.getSpecialRewardsConfig().getData(), plugin.getSpecialRewardsConfig().getCumulativeRewardsPath(cumulative)).setServer(forceBungee).setOnline(online).withPlaceHolder("Cumulative", "" + cumulative).send(user);
}
Also used : RewardBuilder(com.bencodez.advancedcore.api.rewards.RewardBuilder) PlayerSpecialRewardEvent(com.bencodez.votingplugin.events.PlayerSpecialRewardEvent)

Example 5 with RewardBuilder

use of com.bencodez.advancedcore.api.rewards.RewardBuilder in project VotingPlugin by Ben12345rocks.

the class SpecialRewards method giveMilestoneVoteReward.

public void giveMilestoneVoteReward(VotingPluginUser user, boolean online, int milestone, boolean forceBungee) {
    PlayerSpecialRewardEvent event = new PlayerSpecialRewardEvent(user, SpecialRewardType.MILESTONE.setAmount(milestone));
    Bukkit.getPluginManager().callEvent(event);
    if (event.isCancelled()) {
        return;
    }
    new RewardBuilder(plugin.getSpecialRewardsConfig().getData(), plugin.getSpecialRewardsConfig().getMilestoneRewardsPath(milestone)).setOnline(online).withPlaceHolder("Milestone", "" + milestone).setServer(forceBungee).send(user);
}
Also used : RewardBuilder(com.bencodez.advancedcore.api.rewards.RewardBuilder) PlayerSpecialRewardEvent(com.bencodez.votingplugin.events.PlayerSpecialRewardEvent)

Aggregations

RewardBuilder (com.bencodez.advancedcore.api.rewards.RewardBuilder)6 PlayerSpecialRewardEvent (com.bencodez.votingplugin.events.PlayerSpecialRewardEvent)3 VoteSite (com.bencodez.votingplugin.objects.VoteSite)2 VotingPluginUser (com.bencodez.votingplugin.user.VotingPluginUser)2 Player (org.bukkit.entity.Player)2 BInventory (com.bencodez.advancedcore.api.inventory.BInventory)1 ClickEvent (com.bencodez.advancedcore.api.inventory.BInventory.ClickEvent)1 BInventoryButton (com.bencodez.advancedcore.api.inventory.BInventoryButton)1 UpdatingBInventoryButton (com.bencodez.advancedcore.api.inventory.UpdatingBInventoryButton)1 ItemBuilder (com.bencodez.advancedcore.api.item.ItemBuilder)1 EncryptionHandler (com.bencodez.advancedcore.api.misc.encryption.EncryptionHandler)1 PluginMessageHandler (com.bencodez.advancedcore.bungeeapi.pluginmessage.PluginMessageHandler)1 ClientHandler (com.bencodez.advancedcore.bungeeapi.sockets.ClientHandler)1 SocketHandler (com.bencodez.advancedcore.bungeeapi.sockets.SocketHandler)1 SocketReceiver (com.bencodez.advancedcore.bungeeapi.sockets.SocketReceiver)1 BungeeMessageData (com.bencodez.votingplugin.bungee.BungeeMessageData)1 File (java.io.File)1 ArrayList (java.util.ArrayList)1