Search in sources :

Example 1 with Column

use of com.bencodez.advancedcore.api.user.userstorage.Column in project VotingPlugin by Ben12345rocks.

the class VotingPluginVelocity method getValue.

private int getValue(ArrayList<Column> cols, String column, int toAdd) {
    for (Column d : cols) {
        if (d.getName().equalsIgnoreCase(column)) {
            DataValue value = d.getValue();
            int num = 0;
            if (value.isInt()) {
                num = value.getInt();
            } else if (value.isString()) {
                try {
                    num = Integer.parseInt(value.getString());
                } catch (Exception e) {
                }
            }
            return num + toAdd;
        }
    }
    return toAdd;
}
Also used : Column(com.bencodez.advancedcore.api.user.userstorage.Column) DataValue(com.bencodez.advancedcore.api.user.usercache.value.DataValue) SQLException(java.sql.SQLException) IOException(java.io.IOException)

Example 2 with Column

use of com.bencodez.advancedcore.api.user.userstorage.Column in project VotingPlugin by Ben12345rocks.

the class VotingPluginBungee method vote.

public synchronized void vote(String player, String service, boolean realVote) {
    try {
        if (player == null || player.isEmpty()) {
            getLogger().info("No name from vote on " + service);
            return;
        }
        String uuid = getUUID(player);
        if (uuid.isEmpty()) {
            if (config.getAllowUnJoined()) {
                debug("Fetching UUID online, since allowunjoined is enabled");
                UUID u = null;
                try {
                    u = fetchUUID(player);
                } catch (Exception e) {
                    if (getConfig().getDebug()) {
                        e.printStackTrace();
                    }
                }
                if (u == null) {
                    debug("Failed to get uuid for " + player);
                    return;
                }
                uuid = u.toString();
            } else {
                getLogger().info("Ignoring vote from " + player + " since player hasn't joined before");
                return;
            }
        }
        player = getProperName(uuid, player);
        BungeeMessageData text = null;
        addVoteParty();
        if (getConfig().getBungeeManageTotals()) {
            if (mysql == null) {
                getLogger().severe("Mysql is not loaded correctly, stopping vote processing");
                return;
            }
            // one time query to insert player
            if (!mysql.getUuids().contains(uuid)) {
                mysql.update(uuid, "PlayerName", new DataValueString(player));
            }
            ArrayList<Column> data = mysql.getExactQuery(new Column("uuid", new DataValueString(uuid)));
            int allTimeTotal = getValue(data, "AllTimeTotal", 1);
            int monthTotal = getValue(data, "MonthTotal", 1);
            int weeklyTotal = getValue(data, "WeeklyTotal", 1);
            int dailyTotal = getValue(data, "DailyTotal", 1);
            int points = getValue(data, "Points", getConfig().getPointsOnVote());
            int milestoneCount = getValue(data, "MilestoneCount", 1);
            text = new BungeeMessageData(allTimeTotal, monthTotal, weeklyTotal, dailyTotal, points, milestoneCount, votePartyVotes, currentVotePartyVotesRequired);
            ArrayList<Column> update = new ArrayList<Column>();
            update.add(new Column("AllTimeTotal", new DataValueInt(allTimeTotal)));
            update.add(new Column("MonthTotal", new DataValueInt(monthTotal)));
            update.add(new Column("WeeklyTotal", new DataValueInt(weeklyTotal)));
            update.add(new Column("DailyTotal", new DataValueInt(dailyTotal)));
            update.add(new Column("Points", new DataValueInt(points)));
            update.add(new Column("MilestoneCount", new DataValueInt(milestoneCount)));
            debug("Setting totals " + text.toString());
            mysql.update(uuid, update);
        } else {
            text = new BungeeMessageData(0, 0, 0, 0, 0, 0, votePartyVotes, currentVotePartyVotesRequired);
        }
        long time = LocalDateTime.now().atZone(ZoneId.systemDefault()).toInstant().toEpochMilli();
        if (method.equals(BungeeMethod.PLUGINMESSAGING)) {
            if (config.getSendVotesToAllServers()) {
                for (String s : getProxy().getServers().keySet()) {
                    if (!config.getBlockedServers().contains(s)) {
                        ServerInfo info = getProxy().getServerInfo(s);
                        boolean forceCache = false;
                        ProxiedPlayer p = getProxy().getPlayer(UUID.fromString(uuid));
                        if (!isOnline(p) && getConfig().getWaitForUserOnline()) {
                            forceCache = true;
                            debug("Forcing vote to cache");
                        }
                        if (info.getPlayers().isEmpty() || forceCache) {
                            // cache
                            if (!cachedVotes.containsKey(s)) {
                                cachedVotes.put(s, new ArrayList<OfflineBungeeVote>());
                            }
                            ArrayList<OfflineBungeeVote> list = cachedVotes.get(s);
                            list.add(new OfflineBungeeVote(player, uuid, service, time, realVote, text.toString()));
                            cachedVotes.put(s, list);
                            debug("Caching vote for " + player + " on " + service + " for " + s);
                        } else {
                            // send
                            sendPluginMessageServer(s, "Vote", player, uuid, service, "" + time, Boolean.TRUE.toString(), "" + realVote, text.toString(), "" + getConfig().getBungeeManageTotals(), "" + BungeeVersion.getPluginMessageVersion(), "" + config.getBroadcast());
                        }
                        if (config.getBroadcast()) {
                            sendPluginMessageServer(s, "VoteBroadcast", uuid, player, service);
                        }
                    }
                }
            } else {
                ProxiedPlayer p = getProxy().getPlayer(UUID.fromString(uuid));
                if (isOnline(p) && !config.getBlockedServers().contains(p.getServer().getInfo().getName())) {
                    sendPluginMessageServer(p.getServer().getInfo().getName(), "VoteOnline", player, uuid, service, "" + time, Boolean.TRUE.toString(), "" + realVote, text.toString(), "" + getConfig().getBungeeManageTotals(), "" + BungeeVersion.getPluginMessageVersion(), "" + config.getBroadcast());
                } else {
                    if (!cachedOnlineVotes.containsKey(uuid)) {
                        cachedOnlineVotes.put(uuid, new ArrayList<OfflineBungeeVote>());
                    }
                    ArrayList<OfflineBungeeVote> list = cachedOnlineVotes.get(uuid);
                    if (list == null) {
                        list = new ArrayList<OfflineBungeeVote>();
                    }
                    list.add(new OfflineBungeeVote(player, uuid, service, time, realVote, text.toString()));
                    cachedOnlineVotes.put(uuid, list);
                    debug("Caching online vote for " + player + " on " + service);
                }
                for (String s : getProxy().getServers().keySet()) {
                    sendPluginMessageServer(s, "VoteUpdate", uuid, "" + votePartyVotes, "" + currentVotePartyVotesRequired);
                    if (config.getBroadcast()) {
                        sendPluginMessageServer(s, "VoteBroadcast", uuid, player, service);
                    }
                }
            }
        } else if (method.equals(BungeeMethod.SOCKETS)) {
            sendSocketVote(player, service, text);
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}
Also used : ProxiedPlayer(net.md_5.bungee.api.connection.ProxiedPlayer) ServerInfo(net.md_5.bungee.api.config.ServerInfo) ArrayList(java.util.ArrayList) DataValueString(com.bencodez.advancedcore.api.user.usercache.value.DataValueString) SQLException(java.sql.SQLException) DataValueInt(com.bencodez.advancedcore.api.user.usercache.value.DataValueInt) Column(com.bencodez.advancedcore.api.user.userstorage.Column) DataValueString(com.bencodez.advancedcore.api.user.usercache.value.DataValueString) UUID(java.util.UUID)

Example 3 with Column

use of com.bencodez.advancedcore.api.user.userstorage.Column in project VotingPlugin by Ben12345rocks.

the class VotingPluginVelocity method vote.

public synchronized void vote(String player, String service, boolean realVote) {
    try {
        if (player == null || player.isEmpty()) {
            logger.info("No name from vote on " + service);
            return;
        }
        String uuid = getUUID(player);
        if (uuid.isEmpty()) {
            if (config.getAllowUnJoined()) {
                debug("Fetching UUID online, since allowunjoined is enabled");
                UUID u = null;
                try {
                    u = fetchUUID(player);
                } catch (Exception e) {
                    if (getConfig().getDebug()) {
                        e.printStackTrace();
                    }
                }
                if (u == null) {
                    debug("Failed to get uuid for " + player);
                    return;
                }
                uuid = u.toString();
            } else {
                logger.info("Ignoring vote from " + player + " since player hasn't joined before");
                return;
            }
        }
        player = getProperName(uuid, player);
        BungeeMessageData text = null;
        addVoteParty();
        if (getConfig().getBungeeManageTotals()) {
            if (mysql == null) {
                logger.error("Mysql is not loaded correctly, stopping vote processing");
                return;
            }
            if (!mysql.getUuids().contains(uuid)) {
                mysql.update(uuid, "PlayerName", new DataValueString(player));
            }
            ArrayList<Column> data = mysql.getExactQuery(new Column("uuid", new DataValueString(uuid)));
            int allTimeTotal = getValue(data, "AllTimeTotal", 1);
            int monthTotal = getValue(data, "MonthTotal", 1);
            int weeklyTotal = getValue(data, "WeeklyTotal", 1);
            int dailyTotal = getValue(data, "DailyTotal", 1);
            int points = getValue(data, "Points", getConfig().getPointsOnVote());
            int milestoneCount = getValue(data, "MilestoneCount", 1);
            text = new BungeeMessageData(allTimeTotal, monthTotal, weeklyTotal, dailyTotal, points, milestoneCount, votePartyVotes, currentVotePartyVotesRequired);
            ArrayList<Column> update = new ArrayList<Column>();
            update.add(new Column("AllTimeTotal", new DataValueInt(allTimeTotal)));
            update.add(new Column("MonthTotal", new DataValueInt(monthTotal)));
            update.add(new Column("WeeklyTotal", new DataValueInt(weeklyTotal)));
            update.add(new Column("DailyTotal", new DataValueInt(dailyTotal)));
            update.add(new Column("Points", new DataValueInt(points)));
            update.add(new Column("MilestoneCount", new DataValueInt(milestoneCount)));
            debug("Setting totals " + text.toString());
            mysql.update(uuid, update);
        } else {
            text = new BungeeMessageData(0, 0, 0, 0, 0, 0, votePartyVotes, currentVotePartyVotesRequired);
        }
        /*
			 * String text = mysqlUpdate(data, uuid, "AllTimeTotal", 1) + "//" +
			 * mysqlUpdate(data, uuid, "MonthTotal", 1) + "//" + mysqlUpdate(data, uuid,
			 * "WeeklyTotal", 1) + "//" + mysqlUpdate(data, uuid, "DailyTotal", 1) + "//" +
			 * mysqlUpdate(data, uuid, "Points", 1) + "//" + mysqlUpdate(data, uuid,
			 * "MilestoneCount", 1);
			 */
        long time = LocalDateTime.now().atZone(ZoneId.systemDefault()).toInstant().toEpochMilli();
        if (method.equals(BungeeMethod.PLUGINMESSAGING)) {
            if (config.getSendVotesToAllServers()) {
                for (RegisteredServer s : server.getAllServers()) {
                    if (!config.getBlockedServers().contains(s.getServerInfo().getName())) {
                        boolean forceCache = false;
                        Player p = null;
                        if (server.getPlayer(UUID.fromString(uuid)).isPresent()) {
                            p = server.getPlayer(UUID.fromString(uuid)).get();
                        }
                        if ((p == null || !p.isActive()) && getConfig().getWaitForUserOnline()) {
                            forceCache = true;
                            debug("Forcing vote to cache");
                        }
                        if (s.getPlayersConnected().isEmpty() || forceCache) {
                            // cache
                            if (!cachedVotes.containsKey(s)) {
                                cachedVotes.put(s, new ArrayList<OfflineBungeeVote>());
                            }
                            ArrayList<OfflineBungeeVote> list = cachedVotes.get(s);
                            list.add(new OfflineBungeeVote(player, uuid, service, time, realVote, text.toString()));
                            cachedVotes.put(s, list);
                            debug("Caching vote for " + player + " on " + service + " for " + s);
                        } else {
                            // send
                            sendPluginMessageServer(s, "Vote", player, uuid, service, "" + time, Boolean.TRUE.toString(), "" + realVote, text.toString(), "" + getConfig().getBungeeManageTotals(), "" + BungeeVersion.getPluginMessageVersion(), "" + config.getBroadcast());
                        }
                        if (config.getBroadcast()) {
                            sendPluginMessageServer(s, "VoteBroadcast", uuid, player, service);
                        }
                    }
                }
            } else {
                Player p = null;
                if (server.getPlayer(UUID.fromString(uuid)).isPresent()) {
                    p = server.getPlayer(UUID.fromString(uuid)).get();
                }
                if (p != null && p.isActive() && !config.getBlockedServers().contains(p.getCurrentServer().get().getServerInfo().getName())) {
                    sendPluginMessageServer(p.getCurrentServer().get().getServer(), "VoteOnline", player, uuid, service, "" + time, Boolean.TRUE.toString(), "" + realVote, text.toString(), "" + getConfig().getBungeeManageTotals(), "" + BungeeVersion.getPluginMessageVersion(), "" + config.getBroadcast());
                } else {
                    if (!cachedOnlineVotes.containsKey(uuid)) {
                        cachedOnlineVotes.put(uuid, new ArrayList<OfflineBungeeVote>());
                    }
                    ArrayList<OfflineBungeeVote> list = cachedOnlineVotes.get(uuid);
                    if (list == null) {
                        list = new ArrayList<OfflineBungeeVote>();
                    }
                    list.add(new OfflineBungeeVote(player, uuid, service, time, realVote, text.toString()));
                    cachedOnlineVotes.put(uuid, list);
                    debug("Caching online vote for " + player + " on " + service);
                }
                for (RegisteredServer s : server.getAllServers()) {
                    sendPluginMessageServer(s, "VoteUpdate", uuid, "" + votePartyVotes, "" + currentVotePartyVotesRequired);
                    if (config.getBroadcast()) {
                        sendPluginMessageServer(s, "VoteBroadcast", uuid, player, service);
                    }
                }
            }
        } else if (method.equals(BungeeMethod.SOCKETS)) {
            sendSocketVote(player, service, text);
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}
Also used : Player(com.velocitypowered.api.proxy.Player) OfflineBungeeVote(com.bencodez.votingplugin.bungee.OfflineBungeeVote) ArrayList(java.util.ArrayList) DataValueString(com.bencodez.advancedcore.api.user.usercache.value.DataValueString) SQLException(java.sql.SQLException) IOException(java.io.IOException) DataValueInt(com.bencodez.advancedcore.api.user.usercache.value.DataValueInt) Column(com.bencodez.advancedcore.api.user.userstorage.Column) RegisteredServer(com.velocitypowered.api.proxy.server.RegisteredServer) DataValueString(com.bencodez.advancedcore.api.user.usercache.value.DataValueString) UUID(java.util.UUID) BungeeMessageData(com.bencodez.votingplugin.bungee.BungeeMessageData)

Example 4 with Column

use of com.bencodez.advancedcore.api.user.userstorage.Column in project VotingPlugin by Ben12345rocks.

the class VotingPluginBungee method getValue.

private int getValue(ArrayList<Column> cols, String column, int toAdd) {
    for (Column d : cols) {
        if (d.getName().equalsIgnoreCase(column)) {
            DataValue value = d.getValue();
            int num = 0;
            if (value.isInt()) {
                num = value.getInt();
            } else if (value.isString()) {
                try {
                    num = Integer.parseInt(value.getString());
                } catch (Exception e) {
                }
            }
            return num + toAdd;
        }
    }
    return toAdd;
}
Also used : Column(com.bencodez.advancedcore.api.user.userstorage.Column) DataValue(com.bencodez.advancedcore.api.user.usercache.value.DataValue) SQLException(java.sql.SQLException)

Aggregations

Column (com.bencodez.advancedcore.api.user.userstorage.Column)4 SQLException (java.sql.SQLException)4 DataValue (com.bencodez.advancedcore.api.user.usercache.value.DataValue)2 DataValueInt (com.bencodez.advancedcore.api.user.usercache.value.DataValueInt)2 DataValueString (com.bencodez.advancedcore.api.user.usercache.value.DataValueString)2 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 UUID (java.util.UUID)2 BungeeMessageData (com.bencodez.votingplugin.bungee.BungeeMessageData)1 OfflineBungeeVote (com.bencodez.votingplugin.bungee.OfflineBungeeVote)1 Player (com.velocitypowered.api.proxy.Player)1 RegisteredServer (com.velocitypowered.api.proxy.server.RegisteredServer)1 ServerInfo (net.md_5.bungee.api.config.ServerInfo)1 ProxiedPlayer (net.md_5.bungee.api.connection.ProxiedPlayer)1