From bd5532aa712c123936bb7a938e7eb0c4da80f0ad Mon Sep 17 00:00:00 2001 From: BenCodez Date: Thu, 5 Oct 2023 20:55:20 -0400 Subject: [PATCH] Add vote limit feature to proxy setup --- VotingPlugin/Resources/bungeeconfig.yml | 6 ++++++ .../com/bencodez/votingplugin/bungee/Config.java | 4 ++++ .../votingplugin/bungee/VotingPluginBungee.java | 13 +++++++++++++ .../votingplugin/bungee/velocity/Config.java | 8 ++++++-- .../bungee/velocity/VotingPluginVelocity.java | 12 ++++++++++++ 5 files changed, 41 insertions(+), 2 deletions(-) diff --git a/VotingPlugin/Resources/bungeeconfig.yml b/VotingPlugin/Resources/bungeeconfig.yml index f3e03fd5c..f8ad945c6 100644 --- a/VotingPlugin/Resources/bungeeconfig.yml +++ b/VotingPlugin/Resources/bungeeconfig.yml @@ -117,6 +117,12 @@ GeyserPrefix: '.' # Time in days VoteCacheTime: -1 +# Maxium number of votes possible per day +# Usually matches the amount of votesites +# Will limit vote totals to match accordingly +# Set to -1 to disable +MaxAmountOfVotesPerDay: -1 + VoteParty: # If enabled, will trigger vote party reward # in BungeeSettings.yml under BungeeVotePartyReward diff --git a/VotingPlugin/src/com/bencodez/votingplugin/bungee/Config.java b/VotingPlugin/src/com/bencodez/votingplugin/bungee/Config.java index 5fe23361e..e38a3da44 100644 --- a/VotingPlugin/src/com/bencodez/votingplugin/bungee/Config.java +++ b/VotingPlugin/src/com/bencodez/votingplugin/bungee/Config.java @@ -81,6 +81,10 @@ public boolean getMultiProxySupport() { return getData().getBoolean("MultiProxySupport", false); } + public int getMaxAmountOfVotesPerDay() { + return getData().getInt("MaxAmountOfVotesPerDay", -1); + } + public int getMultiProxySocketHostPort() { return getData().getInt("MultiProxySocketHost.Port", 1297); } diff --git a/VotingPlugin/src/com/bencodez/votingplugin/bungee/VotingPluginBungee.java b/VotingPlugin/src/com/bencodez/votingplugin/bungee/VotingPluginBungee.java index 1f973b10b..e66ba92a4 100644 --- a/VotingPlugin/src/com/bencodez/votingplugin/bungee/VotingPluginBungee.java +++ b/VotingPlugin/src/com/bencodez/votingplugin/bungee/VotingPluginBungee.java @@ -1267,6 +1267,19 @@ public synchronized void vote(String player, String service, boolean realVote, b int dailyTotal = getValue(data, "DailyTotal", 1); int points = getValue(data, "Points", getConfig().getPointsOnVote()); int milestoneCount = getValue(data, "MilestoneCount", 1); + + int maxVotes = getConfig().getMaxAmountOfVotesPerDay(); + if (maxVotes > 0) { + if (dailyTotal > maxVotes) { + dailyTotal = maxVotes; + + } + LocalDateTime cTime = getBungeeTimeChecker().getTime(); + int days = cTime.getDayOfMonth(); + if (monthTotal > days * maxVotes) { + monthTotal = days * maxVotes; + } + } text = new BungeeMessageData(allTimeTotal, monthTotal, weeklyTotal, dailyTotal, points, milestoneCount, votePartyVotes, currentVotePartyVotesRequired); ArrayList update = new ArrayList(); diff --git a/VotingPlugin/src/com/bencodez/votingplugin/bungee/velocity/Config.java b/VotingPlugin/src/com/bencodez/votingplugin/bungee/velocity/Config.java index fc10f7c8f..8ff6bf832 100644 --- a/VotingPlugin/src/com/bencodez/votingplugin/bungee/velocity/Config.java +++ b/VotingPlugin/src/com/bencodez/votingplugin/bungee/velocity/Config.java @@ -60,11 +60,15 @@ public String getBungeeHost() { public int getBungeePort() { return getInt(getNode("BungeeServer", "Port"), 1297); } - + + public int getMaxAmountOfVotesPerDay() { + return getInt(getNode("MaxAmountOfVotesPerDay"), -1); + } + public int getVoteCacheTime() { return getInt(getNode("VoteCacheTime"), -1); } - + public boolean getDebug() { return getBoolean(getNode("Debug"), false); } diff --git a/VotingPlugin/src/com/bencodez/votingplugin/bungee/velocity/VotingPluginVelocity.java b/VotingPlugin/src/com/bencodez/votingplugin/bungee/velocity/VotingPluginVelocity.java index 8779ddf3f..0d91608b0 100644 --- a/VotingPlugin/src/com/bencodez/votingplugin/bungee/velocity/VotingPluginVelocity.java +++ b/VotingPlugin/src/com/bencodez/votingplugin/bungee/velocity/VotingPluginVelocity.java @@ -1303,6 +1303,18 @@ public synchronized void vote(String player, String service, boolean realVote, b int dailyTotal = getValue(data, "DailyTotal", 1); int points = getValue(data, "Points", getConfig().getPointsOnVote()); int milestoneCount = getValue(data, "MilestoneCount", 1); + + int maxVotes = getConfig().getMaxAmountOfVotesPerDay(); + if (maxVotes > 0) { + if (dailyTotal > maxVotes) { + dailyTotal = maxVotes; + } + LocalDateTime cTime = getBungeeTimeChecker().getTime(); + int days = cTime.getDayOfMonth(); + if (monthTotal > days * maxVotes) { + monthTotal = days * maxVotes; + } + } text = new BungeeMessageData(allTimeTotal, monthTotal, weeklyTotal, dailyTotal, points, milestoneCount, votePartyVotes, currentVotePartyVotesRequired); ArrayList update = new ArrayList();