Compare commits

...
32 Commits
Author SHA1 Message Date
BenCodez f04930e437 Update version number to 6.18.4 2025-04-13 15:47:38 -06:00
Ben c45e8356bb Merge pull request #1432 from BenCodez/dependabot/maven/VotingPlugin/org.projectlombok-lombok-1.18.38
Bump org.projectlombok:lombok from 1.18.36 to 1.18.38 in /VotingPlugin
2025-04-07 07:44:46 -06:00
dependabot[bot] 2f78b7784a Bump org.projectlombok:lombok from 1.18.36 to 1.18.38 in /VotingPlugin
Bumps [org.projectlombok:lombok](https://github.com/projectlombok/lombok) from 1.18.36 to 1.18.38.
- [Changelog](https://github.com/projectlombok/lombok/blob/master/doc/changelog.markdown)
- [Commits](https://github.com/projectlombok/lombok/compare/v1.18.36...v1.18.38)

---
updated-dependencies:
- dependency-name: org.projectlombok:lombok
  dependency-version: 1.18.38
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
2025-04-07 07:15:37 +00:00
BenCodez 911642f57f Update placeholder descriptions to specify "username" instead of "user" 2025-04-03 17:28:54 -06:00
Ben 5e63c04f6c Merge pull request #1430 from BenCodez/dependabot/maven/VotingPlugin/net.md-5-bungeecord-api-1.21-R0.2
Bump net.md-5:bungeecord-api from 1.20-R0.3-SNAPSHOT to 1.21-R0.2 in /VotingPlugin
2025-03-31 07:43:01 -06:00
dependabot[bot] e368f30dd9 Bump net.md-5:bungeecord-api in /VotingPlugin
Bumps [net.md-5:bungeecord-api](https://github.com/SpigotMC/BungeeCord) from 1.20-R0.3-SNAPSHOT to 1.21-R0.2.
- [Commits](https://github.com/SpigotMC/BungeeCord/commits)

---
updated-dependencies:
- dependency-name: net.md-5:bungeecord-api
  dependency-type: direct:production
...

Signed-off-by: dependabot[bot] <support@github.com>
2025-03-31 06:53:42 +00:00
BenCodez 5d5e8b0d55 Modify unit tests, add more tests 2025-03-30 22:08:06 -06:00
BenCodez 16e52a4fd7 Revert placeholder change 2025-03-30 16:58:46 -06:00
BenCodez 331c8fedf5 Adjust next vote placeholder 2025-03-30 14:59:12 -06:00
BenCodez c085d6823e Improve vote cache time checks and add unit tests for VotingPluginProxy
- Add `@Setter` to `cachedOnlineVotes` and `cachedVotes`
- Update vote cache time check logic in `VotingPluginProxy`
- Create `VotingPluginProxyTest` class
- Add tests for removing expired votes from `cachedOnlineVotes`
- Add tests for not removing non-expired votes from `cachedOnlineVotes`
- Add tests for removing expired votes from `cachedVotes`
2025-03-30 14:35:23 -06:00
BenCodez 47680b2646 Slight adjustment to vote cache time handling 2025-03-30 10:35:41 -06:00
BenCodez 60ed0ce73d Force update player heads from signs 2025-03-29 08:11:36 -06:00
BenCodez e5ae3184e0 Fix velocity config not reloading 2025-03-28 07:49:03 -06:00
BenCodez dca9c6fe18 Adjust handling of skulls for signs to use item skull cache 2025-03-27 20:29:38 -06:00
Ben 083e90706f Merge pull request #1429 from tonyjamesstark/patch-1
Update SignHandler.java
2025-03-27 09:04:33 -06:00
tonyjamesstark fed96bcda1 Update SignHandler.java
fix skull displays showing default skins
2025-03-27 07:57:07 -07:00
BenCodez 5bad8c8f98 Update to 1.21.5 2025-03-25 21:36:58 -06:00
BenCodez e31326395c Fix bungee voteparty not working on backend servers 2025-03-18 21:30:37 -06:00
Ben f5b2d27b9e Merge pull request #1425 from BenCodez/dependabot/maven/VotingPlugin/org.junit.jupiter-junit-jupiter-engine-5.12.1
Bump org.junit.jupiter:junit-jupiter-engine from 5.12.0 to 5.12.1 in /VotingPlugin
2025-03-17 07:56:15 -06:00
dependabot[bot] 42626e3789 Bump org.junit.jupiter:junit-jupiter-engine in /VotingPlugin
Bumps [org.junit.jupiter:junit-jupiter-engine](https://github.com/junit-team/junit5) from 5.12.0 to 5.12.1.
- [Release notes](https://github.com/junit-team/junit5/releases)
- [Commits](https://github.com/junit-team/junit5/compare/r5.12.0...r5.12.1)

---
updated-dependencies:
- dependency-name: org.junit.jupiter:junit-jupiter-engine
  dependency-type: direct:development
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
2025-03-17 06:27:11 +00:00
BenCodez b35ff9454d Fix color codes on velocity commands 2025-03-12 19:24:27 -06:00
BenCodez 9ee1547691 Add sitesavailabletotal placeholder - return number of votesites 2025-03-11 10:07:41 -06:00
BenCodez cb1599fe56 Fix double vote points on online proxy votes 2025-03-08 20:18:57 -06:00
BenCodez 59a206617c Adjustments to handling bedrock players 2025-03-07 10:32:58 -06:00
BenCodez 699d74ca3f Change vote party processing order 2025-03-04 08:07:34 -06:00
BenCodez ad6d411e64 Change order of voteparty processing 2025-03-03 12:21:23 -06:00
Ben 1b430dc4b8 Merge pull request #1422 from BenCodez/dependabot/maven/VotingPlugin/org.apache.maven.plugins-maven-deploy-plugin-3.1.4
Bump org.apache.maven.plugins:maven-deploy-plugin from 3.1.3 to 3.1.4 in /VotingPlugin
2025-03-03 07:50:47 -06:00
dependabot[bot] 526dcc830e Bump org.apache.maven.plugins:maven-deploy-plugin in /VotingPlugin
Bumps [org.apache.maven.plugins:maven-deploy-plugin](https://github.com/apache/maven-deploy-plugin) from 3.1.3 to 3.1.4.
- [Release notes](https://github.com/apache/maven-deploy-plugin/releases)
- [Commits](https://github.com/apache/maven-deploy-plugin/compare/maven-deploy-plugin-3.1.3...maven-deploy-plugin-3.1.4)

---
updated-dependencies:
- dependency-name: org.apache.maven.plugins:maven-deploy-plugin
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
2025-03-03 07:02:14 +00:00
BenCodez 75aaae7016 Change layout of packages for proxy files 2025-03-02 19:23:56 -06:00
BenCodez 89d3372701 Make attempt to get bedrock player if votes comes with no prefix 2025-03-02 19:18:02 -06:00
BenCodez 209f1dbc25 Add extra check before checking players current server on velocity 2025-02-25 17:17:40 -06:00
BenCodez bb67de8d0e Update version number to 6.18.4-SNAPSHOT 2025-02-24 15:15:06 -06:00
43 changed files with 619 additions and 112 deletions

No files matched your search

+8 -8
View File
@@ -4,7 +4,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>com.bencodez</groupId>
<artifactId>votingplugin</artifactId>
<version>6.18.3</version>
<version>6.18.4</version>
<packaging>jar</packaging>
<name>VotingPlugin</name>
<properties>
@@ -211,19 +211,19 @@
<dependency>
<groupId>org.spigotmc</groupId>
<artifactId>spigot-api</artifactId>
<version>1.21.4-R0.1-SNAPSHOT</version>
<version>1.21.5-R0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.36</version>
<version>1.18.38</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>net.md-5</groupId>
<artifactId>bungeecord-api</artifactId>
<version>1.20-R0.3-SNAPSHOT</version>
<version>1.21-R0.2</version>
<scope>provided</scope>
</dependency>
<dependency>
@@ -259,13 +259,13 @@
<dependency>
<groupId>com.bencodez</groupId>
<artifactId>advancedcore</artifactId>
<version>3.7.14</version>
<version>3.7.15</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>5.12.0</version>
<version>5.12.1</version>
<scope>test</scope>
</dependency>
<dependency>
@@ -374,7 +374,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-deploy-plugin</artifactId>
<version>3.1.3</version>
<version>3.1.4</version>
<configuration>
<skip>true</skip>
</configuration>
@@ -591,7 +591,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-deploy-plugin</artifactId>
<version>3.1.3</version>
<version>3.1.4</version>
<configuration>
<skip>true</skip>
</configuration>
@@ -33,10 +33,10 @@ import com.bencodez.advancedcore.bungeeapi.sockets.ClientHandler;
import com.bencodez.advancedcore.bungeeapi.sockets.SocketHandler;
import com.bencodez.advancedcore.bungeeapi.sockets.SocketReceiver;
import com.bencodez.simpleapi.array.ArrayUtils;
import com.bencodez.votingplugin.bungee.BungeeMessageData;
import com.bencodez.votingplugin.bungee.BungeeMethod;
import com.bencodez.votingplugin.bungee.BungeeVersion;
import com.bencodez.votingplugin.objects.VoteSite;
import com.bencodez.votingplugin.proxy.BungeeMessageData;
import com.bencodez.votingplugin.proxy.BungeeMethod;
import com.bencodez.votingplugin.proxy.BungeeVersion;
import com.bencodez.votingplugin.user.VotingPluginUser;
import lombok.Getter;
@@ -324,10 +324,6 @@ public class BungeeHandler implements Listener {
.getVotingPluginUser(UUID.fromString(uuid), player);
user.cache();
if (plugin.getBungeeSettings().isPerServerPoints()) {
user.addPoints(plugin.getConfigFile().getPointsOnVote());
}
boolean setTotals = Boolean.valueOf(args.get(7));
boolean wasOnline = Boolean.valueOf(args.get(4));
@@ -3,8 +3,8 @@ package com.bencodez.votingplugin.events;
import org.bukkit.event.Event;
import org.bukkit.event.HandlerList;
import com.bencodez.votingplugin.bungee.BungeeMessageData;
import com.bencodez.votingplugin.objects.VoteSite;
import com.bencodez.votingplugin.proxy.BungeeMessageData;
import com.bencodez.votingplugin.user.VotingPluginUser;
import lombok.Getter;
@@ -3,8 +3,8 @@ package com.bencodez.votingplugin.events;
import org.bukkit.event.Event;
import org.bukkit.event.HandlerList;
import com.bencodez.votingplugin.bungee.BungeeMessageData;
import com.bencodez.votingplugin.objects.VoteSite;
import com.bencodez.votingplugin.proxy.BungeeMessageData;
import com.bencodez.votingplugin.user.VotingPluginUser;
import lombok.Getter;
@@ -8,7 +8,7 @@ import org.bukkit.event.player.PlayerQuitEvent;
import com.bencodez.advancedcore.listeners.AdvancedCoreLoginEvent;
import com.bencodez.votingplugin.VotingPluginMain;
import com.bencodez.votingplugin.bungee.BungeeMethod;
import com.bencodez.votingplugin.proxy.BungeeMethod;
import com.bencodez.votingplugin.user.VotingPluginUser;
// TODO: Auto-generated Javadoc
@@ -13,10 +13,10 @@ import org.bukkit.event.Listener;
import com.bencodez.advancedcore.api.misc.PlayerManager;
import com.bencodez.simpleapi.array.ArrayUtils;
import com.bencodez.votingplugin.VotingPluginMain;
import com.bencodez.votingplugin.bungee.BungeeMethod;
import com.bencodez.votingplugin.events.PlayerPostVoteEvent;
import com.bencodez.votingplugin.events.PlayerVoteEvent;
import com.bencodez.votingplugin.objects.VoteSite;
import com.bencodez.votingplugin.proxy.BungeeMethod;
import com.bencodez.votingplugin.topvoter.TopVoter;
import com.bencodez.votingplugin.user.VotingPluginUser;
@@ -50,14 +50,25 @@ public class PlayerVoteListener implements Listener {
}
String playerName = event.getPlayer();
plugin.debug("Processing PlayerVoteEvent: " + playerName + "/" + event.getServiceSite());
if (!PlayerManager.getInstance().isValidUser(playerName, plugin.getConfigFile().isAllowUnJoinedCheckServer())) {
if (!plugin.getConfigFile().isAllowUnjoined()) {
plugin.getLogger().warning("Player " + playerName
+ " has not joined before, disregarding vote, set AllowUnjoined to true to prevent this");
if (event.isBungee() && plugin.getBungeeSettings().isRemoveInvalidUsers()) {
plugin.getVotingPluginUserManager().getVotingPluginUser(playerName).remove();
if (!playerName.startsWith(plugin.getOptions().getBedrockPlayerPrefix())
&& !plugin.getOptions().getBedrockPlayerPrefix().isEmpty()) {
if (!event.isBungee() && PlayerManager.getInstance().isValidUser(
plugin.getOptions().getBedrockPlayerPrefix() + playerName,
plugin.getConfigFile().isAllowUnJoinedCheckServer())) {
plugin.debug("Detected a bedrock user without bedrock prefix, adjusting");
playerName = plugin.getOptions().getBedrockPlayerPrefix() + playerName;
}
} else {
if (!plugin.getConfigFile().isAllowUnjoined()) {
plugin.getLogger().warning("Player " + playerName
+ " has not joined before, disregarding vote, set AllowUnjoined to true to prevent this");
if (event.isBungee() && plugin.getBungeeSettings().isRemoveInvalidUsers()) {
plugin.getVotingPluginUserManager().getVotingPluginUser(playerName).remove();
}
return;
}
return;
}
}
@@ -8,8 +8,8 @@ import org.bukkit.event.Listener;
import com.bencodez.simpleapi.array.ArrayUtils;
import com.bencodez.votingplugin.VotingPluginMain;
import com.bencodez.votingplugin.bungee.BungeeMethod;
import com.bencodez.votingplugin.events.PlayerVoteEvent;
import com.bencodez.votingplugin.proxy.BungeeMethod;
import com.vexsoftware.votifier.model.Vote;
import com.vexsoftware.votifier.model.VotifierEvent;
@@ -16,7 +16,7 @@ import com.bencodez.advancedcore.api.rewards.RewardBuilder;
import com.bencodez.simpleapi.array.ArrayUtils;
import com.bencodez.simpleapi.messages.MessageAPI;
import com.bencodez.votingplugin.VotingPluginMain;
import com.bencodez.votingplugin.bungee.BungeeMethod;
import com.bencodez.votingplugin.proxy.BungeeMethod;
import com.bencodez.votingplugin.user.VotingPluginUser;
import lombok.Getter;
@@ -541,6 +541,14 @@ public class PlaceHolders {
}
}.withDescription("Get number of sites available to be voted on").updateDataKey("LastVotes"));
placeholders.add(new PlaceHolder<VotingPluginUser>("SitesAvailableTotal") {
@Override
public String placeholderRequest(VotingPluginUser user, String identifier) {
return "" + user.getTotalNumberOfSites();
}
}.withDescription("Get total number of sites available to be voted on"));
for (final VoteSite voteSite : plugin.getVoteSitesEnabled()) {
placeholders.add(new CalculatingPlaceholder<VotingPluginUser>("Next_" + voteSite.getKey()) {
@@ -642,7 +650,7 @@ public class PlaceHolders {
}
return "";
}
}.useStartsWith().withDescription("Get user at postion in top voter"));
}.useStartsWith().withDescription("Get username at postion in top voter"));
placeholders.add(new PlaceHolder<VotingPluginUser>("Top_Month_Position") {
@@ -658,7 +666,7 @@ public class PlaceHolders {
}
return "";
}
}.withDescription("Get user top voter position"));
}.withDescription("Get user's current top voter position"));
if (plugin.getGui().isLastMonthGUI()) {
placeholders.add(new PlaceHolder<VotingPluginUser>("Top_LastMonth_Position") {
@@ -730,7 +738,7 @@ public class PlaceHolders {
}
return "";
}
}.useStartsWith().withDescription("Get user at position in top voter"));
}.useStartsWith().withDescription("Get username at position in top voter"));
nonPlayerPlaceholders.add(new NonPlayerPlaceHolder<VotingPluginUser>("Top_MonthVotes_") {
@@ -781,7 +789,7 @@ public class PlaceHolders {
}
return "";
}
}.useStartsWith().withDescription("Get user at postion in top voter"));
}.useStartsWith().withDescription("Get username at postion in top voter"));
nonPlayerPlaceholders.add(new NonPlayerPlaceHolder<VotingPluginUser>("Top_WeekVotes_") {
@@ -832,7 +840,7 @@ public class PlaceHolders {
}
return "";
}
}.useStartsWith().withDescription("Get user at postion in top voter"));
}.useStartsWith().withDescription("Get username at postion in top voter"));
placeholders.add(new PlaceHolder<VotingPluginUser>("VotePartyContributedVotes") {
@@ -1,4 +1,4 @@
package com.bencodez.votingplugin.bungee;
package com.bencodez.votingplugin.proxy;
import java.util.regex.Pattern;
@@ -1,4 +1,4 @@
package com.bencodez.votingplugin.bungee;
package com.bencodez.votingplugin.proxy;
public enum BungeeMethod {
MYSQL, PLUGINMESSAGING, SOCKETS, REDIS;
@@ -1,4 +1,4 @@
package com.bencodez.votingplugin.bungee;
package com.bencodez.votingplugin.proxy;
public class BungeeVersion {
public static int getPluginMessageVersion() {
@@ -1,4 +1,4 @@
package com.bencodez.votingplugin.bungee;
package com.bencodez.votingplugin.proxy;
import lombok.Getter;
@@ -1,4 +1,4 @@
package com.bencodez.votingplugin.bungee.proxy;
package com.bencodez.votingplugin.proxy;
import java.io.BufferedReader;
import java.io.ByteArrayOutputStream;
@@ -41,14 +41,10 @@ import com.bencodez.advancedcore.bungeeapi.sockets.SocketReceiver;
import com.bencodez.advancedcore.bungeeapi.time.BungeeTimeChecker;
import com.bencodez.simpleapi.array.ArrayUtils;
import com.bencodez.simpleapi.json.JsonParser;
import com.bencodez.votingplugin.bungee.BungeeMessageData;
import com.bencodez.votingplugin.bungee.BungeeMethod;
import com.bencodez.votingplugin.bungee.BungeeVersion;
import com.bencodez.votingplugin.bungee.OfflineBungeeVote;
import com.bencodez.votingplugin.bungee.global.multiproxy.MultiProxyHandler;
import com.bencodez.votingplugin.bungee.global.multiproxy.MultiProxyMethod;
import com.bencodez.votingplugin.bungee.global.multiproxy.MultiProxyServerSocketConfiguration;
import com.bencodez.votingplugin.bungee.global.multiproxy.MultiProxyServerSocketConfigurationBungee;
import com.bencodez.votingplugin.proxy.global.multiproxy.MultiProxyHandler;
import com.bencodez.votingplugin.proxy.global.multiproxy.MultiProxyMethod;
import com.bencodez.votingplugin.proxy.global.multiproxy.MultiProxyServerSocketConfiguration;
import com.bencodez.votingplugin.proxy.global.multiproxy.MultiProxyServerSocketConfigurationBungee;
import com.bencodez.votingplugin.timequeue.VoteTimeQueue;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
@@ -58,6 +54,7 @@ import lombok.Setter;
public abstract class VotingPluginProxy {
@Getter
@Setter
private int votePartyVotes = 0;
@Getter
@@ -71,9 +68,11 @@ public abstract class VotingPluginProxy {
private EncryptionHandler encryptionHandler;
@Getter
@Setter
private ConcurrentHashMap<String, ArrayList<OfflineBungeeVote>> cachedOnlineVotes = new ConcurrentHashMap<>();
@Getter
@Setter
private ConcurrentHashMap<String, ArrayList<OfflineBungeeVote>> cachedVotes = new ConcurrentHashMap<>();
private HashMap<String, ClientHandler> clientHandles;
@@ -97,6 +96,7 @@ public abstract class VotingPluginProxy {
private boolean enabled;
@Getter
@Setter
private MultiProxyHandler multiProxyHandler;
@Getter
@@ -323,7 +323,8 @@ public abstract class VotingPluginProxy {
for (Entry<String, ArrayList<OfflineBungeeVote>> entry : cachedOnlineVotes.entrySet()) {
ArrayList<OfflineBungeeVote> votes = entry.getValue();
for (int i = votes.size() - 1; i >= 0; i--) {
if (cTime - votes.get(i).getTime() > getConfig().getVoteCacheTime() * 24 * 60 * 60 * 1000) {
if (votes.get(i).getTime() + (getConfig().getVoteCacheTime() * 24 * 60 * 60 * 1000) < cTime) {
debug("Removing vote from cache: " + votes.get(i).toString());
votes.remove(i);
}
}
@@ -332,7 +333,8 @@ public abstract class VotingPluginProxy {
for (Entry<String, ArrayList<OfflineBungeeVote>> entry : cachedVotes.entrySet()) {
ArrayList<OfflineBungeeVote> votes = entry.getValue();
for (int i = votes.size() - 1; i >= 0; i--) {
if (cTime - votes.get(i).getTime() > getConfig().getVoteCacheTime() * 24 * 60 * 60 * 1000) {
if (votes.get(i).getTime() + (getConfig().getVoteCacheTime() * 24 * 60 * 60 * 1000) < cTime) {
debug("Removing vote from cache: " + votes.get(i).toString());
votes.remove(i);
}
}
@@ -357,15 +359,16 @@ public abstract class VotingPluginProxy {
runConsoleCommand(command);
}
/*
* if (method.equals(BungeeMethod.PLUGINMESSAGING)) { if
* (getConfig().getVotePartySendToAllServers()) { for (Entry<String, ServerInfo>
* entry : getProxy().getServers().entrySet()) { //sendVoteParty(entry.getKey(),
* entry.getValue()); } } else { for (String server :
* getConfig().getVotePartyServersToSend()) { ServerInfo serverInfo =
* getProxy().getServerInfo(server); if (serverInfo != null) {
* //sendVoteParty(server, serverInfo); } } } }
*/
if (getConfig().getVotePartySendToAllServers()) {
for (String server : getAllAvailableServers()) {
sendVoteParty(server);
}
} else {
for (String server : getConfig().getVotePartyServersToSend()) {
sendVoteParty(server);
}
}
}
saveVoteCacheFile();
}
@@ -580,8 +583,9 @@ public abstract class VotingPluginProxy {
});
}
currentVotePartyVotesRequired = getConfig().getVotePartyVotesRequired()
+ getVoteCacheVotePartyIncreaseVotesRequired();
currentVotePartyVotesRequired =
getConfig().getVotePartyVotesRequired() + getVoteCacheVotePartyIncreaseVotesRequired();
votePartyVotes = getVoteCacheCurrentVotePartyVotes();
loadMultiProxySupport();
@@ -1043,6 +1047,14 @@ public abstract class VotingPluginProxy {
if (uuid == null || uuid.isEmpty()) {
uuid = getUUID(player);
if (uuid.isEmpty() && !player.startsWith(getConfig().getBedrockPlayerPrefix())) {
String uuid1 = getUUID(getConfig().getBedrockPlayerPrefix() + player);
if (!uuid1.isEmpty()) {
debug("Detected bedrock player without prefix, adjusting...");
player = getConfig().getBedrockPlayerPrefix() + player;
uuid = uuid1;
}
}
}
if (uuid.isEmpty()) {
@@ -1,7 +1,6 @@
package com.bencodez.votingplugin.bungee.proxy;
package com.bencodez.votingplugin.proxy;
import com.bencodez.advancedcore.api.time.TimeType;
import com.bencodez.votingplugin.bungee.BungeeMethod;
public class VotingPluginProxyCommand {
private VotingPluginProxy plugin;
@@ -1,4 +1,4 @@
package com.bencodez.votingplugin.bungee.proxy;
package com.bencodez.votingplugin.proxy;
import java.util.Collection;
import java.util.List;
@@ -1,4 +1,4 @@
package com.bencodez.votingplugin.bungee;
package com.bencodez.votingplugin.proxy.bungee;
import java.io.BufferedReader;
import java.io.BufferedWriter;
@@ -1,4 +1,4 @@
package com.bencodez.votingplugin.bungee;
package com.bencodez.votingplugin.proxy.bungee;
import java.io.File;
import java.io.IOException;
@@ -9,7 +9,7 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map;
import com.bencodez.votingplugin.bungee.proxy.VotingPluginProxyConfig;
import com.bencodez.votingplugin.proxy.VotingPluginProxyConfig;
import lombok.Getter;
import net.md_5.bungee.config.Configuration;
@@ -1,4 +1,4 @@
package com.bencodez.votingplugin.bungee;
package com.bencodez.votingplugin.proxy.bungee;
import java.io.File;
@@ -1,9 +1,10 @@
package com.bencodez.votingplugin.bungee;
package com.bencodez.votingplugin.proxy.bungee;
import java.io.File;
import java.util.Collection;
import com.bencodez.simpleapi.file.BungeeJsonFile;
import com.bencodez.votingplugin.proxy.OfflineBungeeVote;
import com.bencodez.votingplugin.timequeue.VoteTimeQueue;
import com.google.gson.JsonElement;
@@ -1,4 +1,4 @@
package com.bencodez.votingplugin.bungee;
package com.bencodez.votingplugin.proxy.bungee;
import com.vexsoftware.votifier.bungee.events.VotifierEvent;
import com.vexsoftware.votifier.model.Vote;
@@ -1,4 +1,4 @@
package com.bencodez.votingplugin.bungee;
package com.bencodez.votingplugin.proxy.bungee;
import java.io.ByteArrayInputStream;
import java.io.DataInputStream;
@@ -25,8 +25,11 @@ import com.bencodez.advancedcore.api.user.userstorage.mysql.api.config.MysqlConf
import com.bencodez.advancedcore.bungeeapi.globaldata.GlobalDataHandlerProxy;
import com.bencodez.advancedcore.bungeeapi.globaldata.GlobalMySQL;
import com.bencodez.advancedcore.bungeeapi.mysql.BungeeMySQL;
import com.bencodez.votingplugin.bungee.proxy.VotingPluginProxy;
import com.bencodez.votingplugin.bungee.proxy.VotingPluginProxyConfig;
import com.bencodez.votingplugin.proxy.BungeeMethod;
import com.bencodez.votingplugin.proxy.BungeeVersion;
import com.bencodez.votingplugin.proxy.OfflineBungeeVote;
import com.bencodez.votingplugin.proxy.VotingPluginProxy;
import com.bencodez.votingplugin.proxy.VotingPluginProxyConfig;
import com.bencodez.votingplugin.timequeue.VoteTimeQueue;
import com.bencodez.votingplugin.topvoter.TopVoter;
import com.google.gson.JsonElement;
@@ -1,6 +1,6 @@
package com.bencodez.votingplugin.bungee;
package com.bencodez.votingplugin.proxy.bungee;
import com.bencodez.votingplugin.bungee.proxy.VotingPluginProxyCommand;
import com.bencodez.votingplugin.proxy.VotingPluginProxyCommand;
import net.md_5.bungee.api.CommandSender;
import net.md_5.bungee.api.chat.TextComponent;
@@ -22,7 +22,7 @@ public class VotingPluginBungeeCommand extends Command {
sender.sendMessage(new TextComponent(result.replace("&", "§")));
}
} else {
sender.sendMessage(new TextComponent("&cYou do not have permission to do this!"));
sender.sendMessage(new TextComponent("&cYou do not have permission to do this!".replace("&", "§")));
}
}
@@ -1,4 +1,4 @@
package com.bencodez.votingplugin.bungee.global.multiproxy;
package com.bencodez.votingplugin.proxy.global.multiproxy;
import java.io.File;
import java.util.Collection;
@@ -11,7 +11,7 @@ import com.bencodez.advancedcore.bungeeapi.redis.RedisListener;
import com.bencodez.advancedcore.bungeeapi.sockets.ClientHandler;
import com.bencodez.advancedcore.bungeeapi.sockets.SocketHandler;
import com.bencodez.advancedcore.bungeeapi.sockets.SocketReceiver;
import com.bencodez.votingplugin.bungee.BungeeMessageData;
import com.bencodez.votingplugin.proxy.BungeeMessageData;
import lombok.Getter;
@@ -1,4 +1,4 @@
package com.bencodez.votingplugin.bungee.global.multiproxy;
package com.bencodez.votingplugin.proxy.global.multiproxy;
public enum MultiProxyMethod {
SOCKETS, REDIS;
@@ -1,4 +1,4 @@
package com.bencodez.votingplugin.bungee.global.multiproxy;
package com.bencodez.votingplugin.proxy.global.multiproxy;
public interface MultiProxyServerSocketConfiguration {
String getHost();
@@ -1,4 +1,4 @@
package com.bencodez.votingplugin.bungee.global.multiproxy;
package com.bencodez.votingplugin.proxy.global.multiproxy;
import java.util.Map;
@@ -1,4 +1,4 @@
package com.bencodez.votingplugin.bungee.global.multiproxy;
package com.bencodez.votingplugin.proxy.global.multiproxy;
import ninja.leaping.configurate.ConfigurationNode;
@@ -1,4 +1,4 @@
package com.bencodez.votingplugin.bungee.velocity;
package com.bencodez.votingplugin.proxy.velocity;
import java.io.File;
import java.util.ArrayList;
@@ -9,7 +9,7 @@ import java.util.Map;
import org.checkerframework.checker.nullness.qual.NonNull;
import com.bencodez.simpleapi.file.velocity.VelocityYMLFile;
import com.bencodez.votingplugin.bungee.proxy.VotingPluginProxyConfig;
import com.bencodez.votingplugin.proxy.VotingPluginProxyConfig;
import ninja.leaping.configurate.ConfigurationNode;
@@ -1,4 +1,4 @@
package com.bencodez.votingplugin.bungee.velocity;
package com.bencodez.votingplugin.proxy.velocity;
import java.io.File;
@@ -1,10 +1,10 @@
package com.bencodez.votingplugin.bungee.velocity;
package com.bencodez.votingplugin.proxy.velocity;
import java.io.File;
import java.util.Collection;
import com.bencodez.simpleapi.file.velocity.VelocityJSONFile;
import com.bencodez.votingplugin.bungee.OfflineBungeeVote;
import com.bencodez.votingplugin.proxy.OfflineBungeeVote;
import com.bencodez.votingplugin.timequeue.VoteTimeQueue;
import ninja.leaping.configurate.ConfigurationNode;
@@ -1,4 +1,4 @@
package com.bencodez.votingplugin.bungee.velocity;
package com.bencodez.votingplugin.proxy.velocity;
import com.velocitypowered.api.event.Subscribe;
import com.vexsoftware.votifier.velocity.event.VotifierEvent;
@@ -1,4 +1,4 @@
package com.bencodez.votingplugin.bungee.velocity;
package com.bencodez.votingplugin.proxy.velocity;
import com.velocitypowered.api.proxy.messages.ChannelIdentifier;
@@ -1,4 +1,4 @@
package com.bencodez.votingplugin.bungee.velocity;
package com.bencodez.votingplugin.proxy.velocity;
import java.io.ByteArrayInputStream;
import java.io.DataInputStream;
@@ -37,11 +37,11 @@ import com.bencodez.advancedcore.bungeeapi.globaldata.GlobalDataHandlerProxy;
import com.bencodez.advancedcore.bungeeapi.globaldata.GlobalMySQL;
import com.bencodez.advancedcore.bungeeapi.mysql.VelocityMySQL;
import com.bencodez.simpleapi.file.velocity.VelocityYMLFile;
import com.bencodez.votingplugin.bungee.BungeeMethod;
import com.bencodez.votingplugin.bungee.BungeeVersion;
import com.bencodez.votingplugin.bungee.OfflineBungeeVote;
import com.bencodez.votingplugin.bungee.proxy.VotingPluginProxy;
import com.bencodez.votingplugin.bungee.proxy.VotingPluginProxyConfig;
import com.bencodez.votingplugin.proxy.BungeeMethod;
import com.bencodez.votingplugin.proxy.BungeeVersion;
import com.bencodez.votingplugin.proxy.OfflineBungeeVote;
import com.bencodez.votingplugin.proxy.VotingPluginProxy;
import com.bencodez.votingplugin.proxy.VotingPluginProxyConfig;
import com.bencodez.votingplugin.timequeue.VoteTimeQueue;
import com.bencodez.votingplugin.topvoter.TopVoter;
import com.google.inject.Inject;
@@ -395,10 +395,10 @@ public class VotingPluginVelocity {
if (event.getIdentifier().getId().equals(CHANNEL.getId())) {
event.setResult(PluginMessageEvent.ForwardResult.handled());
if (!(event.getSource() instanceof ServerConnection)) {
return;
}
if (!(event.getSource() instanceof ServerConnection)) {
return;
}
ByteArrayInputStream instream = new ByteArrayInputStream(event.getData());
DataInputStream in = new DataInputStream(instream);
try {
@@ -517,8 +517,10 @@ public class VotingPluginVelocity {
@Override
public String getCurrentPlayerServer(String player) {
if (server.getPlayer(player).isPresent()) {
return server.getPlayer(player).get().getCurrentServer().get().getServer().getServerInfo()
.getName();
if (server.getPlayer(player).get().getCurrentServer().isPresent()) {
return server.getPlayer(player).get().getCurrentServer().get().getServer().getServerInfo()
.getName();
}
}
return "";
}
@@ -903,7 +905,7 @@ public class VotingPluginVelocity {
}
public void reloadPlugin(boolean loadMysql) {
config.load();
config.reload();
if (loadMysql) {
try {
if (!config.getString(config.getNode("Host"), "").isEmpty()) {
@@ -1,6 +1,6 @@
package com.bencodez.votingplugin.bungee.velocity;
package com.bencodez.votingplugin.proxy.velocity;
import com.bencodez.votingplugin.bungee.proxy.VotingPluginProxyCommand;
import com.bencodez.votingplugin.proxy.VotingPluginProxyCommand;
import com.velocitypowered.api.command.CommandSource;
import com.velocitypowered.api.command.SimpleCommand;
@@ -21,7 +21,7 @@ public class VotingPluginVelocityCommand implements SimpleCommand {
String result = new VotingPluginProxyCommand(plugin.getVotingPluginProxy()).execute(args);
if (result != null) {
source.sendMessage(Component.text(result));
source.sendMessage(Component.text(result.replace("&", "§")));
}
}
@@ -1,6 +1,7 @@
package com.bencodez.votingplugin.signs;
import java.util.ArrayList;
import java.util.UUID;
import org.bukkit.Location;
import org.bukkit.block.Block;
@@ -9,6 +10,7 @@ import org.bukkit.block.BlockState;
import org.bukkit.block.Sign;
import org.bukkit.block.Skull;
import org.bukkit.block.data.Directional;
import org.bukkit.inventory.meta.SkullMeta;
import com.bencodez.advancedcore.api.misc.MiscUtils;
import com.bencodez.simpleapi.array.ArrayUtils;
@@ -37,13 +39,12 @@ public class SignHandler {
@Setter
private Location location;
/** The player name. */
private String playerName;
/** The plugin. */
private UUID uuid;
private VotingPluginMain plugin;
/** The position. */
private int position;
@Getter
@@ -58,7 +59,6 @@ public class SignHandler {
@Setter
private boolean valid;
/** The votes. */
private int votes;
public SignHandler(VotingPluginMain plugin, String sign, Location location, Location skullLocation, String data,
@@ -80,8 +80,17 @@ public class SignHandler {
if (block.getState() instanceof Skull) {
if (!playerName.equals("No Player")) {
Skull skull = (Skull) block.getState();
skull.setOwner(playerName);
skull.update();
try {
SkullMeta meta = (SkullMeta) plugin.getSkullCacheHandler().getSkull(uuid, playerName).getItemMeta();
skull.setOwnerProfile(meta.getOwnerProfile());
skull.update(true, false);
} catch (Exception e) {
plugin.debug("Failed to set skull for " + playerName);
plugin.debug(e);
skull.setOwner(playerName);
skull.update(true, false);
}
}
return true;
}
@@ -200,6 +209,7 @@ public class SignHandler {
if (users != null && users.size() >= position) {
TopVoterPlayer user = users.get(position - 1);
playerName = user.getPlayerName();
uuid = user.getUuid();
votes = 0;
if (data.equalsIgnoreCase("all")) {
@@ -11,9 +11,9 @@ import com.bencodez.advancedcore.api.rewards.RewardBuilder;
import com.bencodez.advancedcore.api.rewards.RewardOptions;
import com.bencodez.simpleapi.messages.MessageAPI;
import com.bencodez.votingplugin.VotingPluginMain;
import com.bencodez.votingplugin.bungee.BungeeMessageData;
import com.bencodez.votingplugin.events.PlayerSpecialRewardEvent;
import com.bencodez.votingplugin.events.SpecialRewardType;
import com.bencodez.votingplugin.proxy.BungeeMessageData;
import com.bencodez.votingplugin.topvoter.TopVoter;
import com.bencodez.votingplugin.user.VotingPluginUser;
@@ -28,11 +28,11 @@ import com.bencodez.advancedcore.api.user.usercache.value.DataValue;
import com.bencodez.advancedcore.api.user.usercache.value.DataValueInt;
import com.bencodez.simpleapi.messages.MessageAPI;
import com.bencodez.votingplugin.VotingPluginMain;
import com.bencodez.votingplugin.bungee.BungeeMessageData;
import com.bencodez.votingplugin.bungee.BungeeMethod;
import com.bencodez.votingplugin.events.PlayerReceivePointsEvent;
import com.bencodez.votingplugin.events.PlayerVoteEvent;
import com.bencodez.votingplugin.objects.VoteSite;
import com.bencodez.votingplugin.proxy.BungeeMessageData;
import com.bencodez.votingplugin.proxy.BungeeMethod;
import com.bencodez.votingplugin.topvoter.TopVoter;
import com.bencodez.votingplugin.topvoter.TopVoterPlayer;
@@ -1010,6 +1010,18 @@ public class VotingPluginUser extends com.bencodez.advancedcore.api.user.Advance
return amount;
}
public int getTotalNumberOfSites() {
int amount = 0;
for (VoteSite site : plugin.getVoteSitesEnabled()) {
if (!site.isHidden()) {
if (site.getPermissionToView().isEmpty() || hasPermission(site.getPermissionToView())) {
amount++;
}
}
}
return amount;
}
public int getSitesVotedOn() {
int amount = 0;
for (VoteSite site : plugin.getVoteSitesEnabled()) {
+1 -1
View File
@@ -1,6 +1,6 @@
name: ${project.name}
version: ${project.version}
main: com.bencodez.votingplugin.bungee.VotingPluginBungee
main: com.bencodez.votingplugin.proxy.bungee.VotingPluginBungee
author: BenCodez
softDepends:
- RedisBungee
@@ -0,0 +1,28 @@
package com.bencodez.votingplugin.tests;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
import java.io.ByteArrayInputStream;
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.URL;
public class HttpURLConnectionMock {
public static void setupMockHttpURLConnection(String playerName, int responseCode, String responseBody)
throws Exception {
// Mock URL and HttpURLConnection
URL mockUrl = mock(URL.class);
HttpURLConnection mockConnection = mock(HttpURLConnection.class);
when(mockUrl.openConnection()).thenReturn(mockConnection);
when(mockConnection.getResponseCode()).thenReturn(responseCode);
InputStream mockInputStream = new ByteArrayInputStream(responseBody.getBytes());
when(mockConnection.getInputStream()).thenReturn(mockInputStream);
// When new URL is called, return the mocked URL
// Note: This requires PowerMockito or a similar tool to mock the `new` keyword
// Here, it's simplified and assumes the method uses a helper that can be mocked
}
}
@@ -0,0 +1,120 @@
package com.bencodez.votingplugin.tests;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.mockito.Mockito.doNothing;
import static org.mockito.Mockito.when;
import java.io.FileNotFoundException;
import java.util.UUID;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.Mockito;
import org.mockito.MockitoAnnotations;
import com.bencodez.advancedcore.bungeeapi.globaldata.GlobalDataHandlerProxy;
import com.bencodez.advancedcore.bungeeapi.mysql.ProxyMySQL;
import com.bencodez.votingplugin.proxy.VotingPluginProxy;
import com.bencodez.votingplugin.proxy.VotingPluginProxyConfig;
import com.bencodez.votingplugin.proxy.global.multiproxy.MultiProxyHandler;
public class VotingPluginProxyTest {
@InjectMocks
private VotingPluginProxyTestImpl votingPluginProxy;
@Mock
private ProxyMySQL proxyMySQL;
@Mock
private VotingPluginProxyConfig config;
@Mock
private GlobalDataHandlerProxy globalDataHandler;
@Mock
private MultiProxyHandler multiProxyHandler;
@BeforeEach
void setUp() {
MockitoAnnotations.openMocks(this);
votingPluginProxy.setProxyMySQL(proxyMySQL);
votingPluginProxy.setGlobalDataHandler(globalDataHandler);
votingPluginProxy.setMultiProxyHandler(multiProxyHandler);
// Mocking config methods
when(config.getVotePartyEnabled()).thenReturn(true);
when(config.getVotePartyVotesRequired()).thenReturn(5);
when(config.getVotePartyIncreaseVotesRequired()).thenReturn(5);
when(config.getBungeeManageTotals()).thenReturn(true);
when(config.getPluginMessageEncryption()).thenReturn(false);
when(config.getDebug()).thenReturn(false);
}
@Test
void testAddVoteParty() {
// Initial votePartyVotes should be 0
assertEquals(0, votingPluginProxy.getVotePartyVotes());
// Spy on the votingPluginProxy object
VotingPluginProxy spyProxy = Mockito.spy(votingPluginProxy);
doNothing().when(spyProxy).checkVoteParty();
// Add one vote party
spyProxy.addCurrentVotePartyVotes(1);
// Verify that votePartyVotes increased by 1
assertEquals(1, spyProxy.getVotePartyVotes());
}
@Test
void testFetchUUID_Success() throws Exception {
String playerName = "TestPlayer";
String apiResponse = "{\"id\":\"aed922d6-5f64-43ce-8b98-efa8e4e288d3\",\"name\":\"TestPlayer\"}";
// Mock the URL connection and response
HttpURLConnectionMock.setupMockHttpURLConnection(playerName, 200, apiResponse);
UUID uuid = votingPluginProxy.fetchUUID(playerName);
assertNotNull(uuid);
assertEquals("aed922d6-5f64-43ce-8b98-efa8e4e288d3", uuid.toString());
}
@Test
void testFetchUUID_NotFound() throws Exception {
String playerName = "NonExistentPlayer";
String apiResponse = "{}";
// Mock the URL connection and response
HttpURLConnectionMock.setupMockHttpURLConnection(playerName, 400, apiResponse);
UUID uuid = null;
try {
uuid = votingPluginProxy.fetchUUID(playerName);
} catch (FileNotFoundException e) {
// Expected exception for non-existent player
}
assertNull(uuid);
}
@Test
void testAddCurrentVotePartyVotes() {
// Initial votePartyVotes should be 0
assertEquals(0, votingPluginProxy.getVotePartyVotes());
// Add 3 votes
votingPluginProxy.addCurrentVotePartyVotes(3);
assertEquals(3, votingPluginProxy.getVotePartyVotes());
// Add 2 more votes
votingPluginProxy.addCurrentVotePartyVotes(2);
assertEquals(5, votingPluginProxy.getVotePartyVotes());
}
}
@@ -0,0 +1,202 @@
package com.bencodez.votingplugin.tests;
import java.io.File;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;
import java.util.UUID;
import org.mockito.Mockito;
import com.bencodez.votingplugin.proxy.VotingPluginProxy;
import com.bencodez.votingplugin.proxy.VotingPluginProxyConfig;
public class VotingPluginProxyTestImpl extends VotingPluginProxy {
@Override
public void addNonVotedPlayer(String uuid, String playerName) {
// Implementation for testing purposes
}
@Override
public void broadcast(String message) {
// Implementation for testing purposes
}
@Override
public Set<String> getAllAvailableServers() {
return new HashSet<>(Arrays.asList("Server1", "Server2"));
}
@Override
public VotingPluginProxyConfig getConfig() {
return Mockito.mock(VotingPluginProxyConfig.class);
}
@Override
public String getCurrentPlayerServer(String player) {
return "Server1";
}
@Override
public File getDataFolderPlugin() {
return new File(".");
}
@Override
public String getProperName(String uuid, String playerName) {
return playerName;
}
@Override
public String getUUID(String playerName) {
return UUID.randomUUID().toString();
}
@Override
public String getPluginVersion() {
return "1.0.0";
}
@Override
public int getVoteCacheCurrentVotePartyVotes() {
return 0;
}
@Override
public long getVoteCacheLastUpdated() {
return System.currentTimeMillis();
}
@Override
public int getVoteCachePrevDay() {
return 1;
}
@Override
public String getVoteCachePrevMonth() {
return "January-2023";
}
@Override
public int getVoteCachePrevWeek() {
return 1;
}
@Override
public int getVoteCacheVotePartyIncreaseVotesRequired() {
return 10;
}
@Override
public boolean isPlayerOnline(String playerName) {
return true;
}
@Override
public boolean isServerValid(String server) {
return true;
}
@Override
public boolean isSomeoneOnlineServer(String server) {
return true;
}
@Override
public boolean isVoteCacheIgnoreTime() {
return false;
}
@Override
public void runAsync(Runnable run) {
run.run();
}
@Override
public void runConsoleCommand(String command) {
// Mocked for testing
}
@Override
public void saveVoteCacheFile() {
// Mocked for testing
}
@Override
public void reloadCore(boolean mysql) {
// Mocked for testing
}
@Override
public void log(String message) {
// For testing, simply print the message
System.out.println("LOG: " + message);
}
@Override
public void logSevere(String message) {
// For testing, simply print the severe message
System.err.println("SEVERE: " + message);
}
@Override
public void warn(String message) {
// For testing, simply print the warning message
System.err.println("WARNING: " + message);
}
@Override
public void debug(String str) {
// TODO Auto-generated method stub
}
@Override
public void sendPluginMessageData(String server, String channel, byte[] data, boolean queue) {
// TODO Auto-generated method stub
}
@Override
public void setVoteCacheLastUpdated() {
// TODO Auto-generated method stub
}
@Override
public void setVoteCachePrevDay(int day) {
// TODO Auto-generated method stub
}
@Override
public void setVoteCachePrevMonth(String text) {
// TODO Auto-generated method stub
}
@Override
public void setVoteCachePrevWeek(int week) {
// TODO Auto-generated method stub
}
@Override
public void setVoteCacheVoteCacheIgnoreTime(boolean ignore) {
// TODO Auto-generated method stub
}
@Override
public void setVoteCacheVotePartyCurrentVotes(int votes) {
// TODO Auto-generated method stub
}
@Override
public void setVoteCacheVotePartyIncreaseVotesRequired(int votes) {
// TODO Auto-generated method stub
}
}
@@ -0,0 +1,103 @@
package com.bencodez.votingplugin.tests;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.CALLS_REAL_METHODS;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.util.ArrayList;
import java.util.UUID;
import java.util.concurrent.ConcurrentHashMap;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import com.bencodez.votingplugin.proxy.OfflineBungeeVote;
import com.bencodez.votingplugin.proxy.VotingPluginProxy;
import com.bencodez.votingplugin.proxy.VotingPluginProxyConfig;
public class VotingPluginProxyVoteCacheTest {
private VotingPluginProxy proxy;
private VotingPluginProxyConfig config;
private ConcurrentHashMap<String, ArrayList<OfflineBungeeVote>> cachedOnlineVotes;
private ConcurrentHashMap<String, ArrayList<OfflineBungeeVote>> cachedVotes;
@BeforeEach
public void setUp() {
proxy = mock(VotingPluginProxy.class, CALLS_REAL_METHODS);
config = mock(VotingPluginProxyConfig.class);
when(proxy.getConfig()).thenReturn(config);
cachedOnlineVotes = new ConcurrentHashMap<>();
cachedVotes = new ConcurrentHashMap<>();
proxy.setCachedOnlineVotes(cachedOnlineVotes);
proxy.setCachedVotes(cachedVotes);
}
@Test
void checkVoteCacheTime_removesExpiredVotesFromCachedOnlineVotes() {
when(config.getVoteCacheTime()).thenReturn(1); // 1 day
long currentTime = LocalDateTime.now().atZone(ZoneId.systemDefault()).toInstant().toEpochMilli();
long expiredTime = currentTime - (2 * 24 * 60 * 60 * 1000); // 2 days ago
ArrayList<OfflineBungeeVote> votes = new ArrayList<>();
votes.add(new OfflineBungeeVote("player1", "uuid1", "service1", expiredTime, true, "text1"));
cachedOnlineVotes.put("server1", votes);
proxy.checkVoteCacheTime();
assertTrue(cachedOnlineVotes.get("server1").isEmpty());
}
@Test
void checkVoteCacheTime_doesNotRemoveNonExpiredVotesFromCachedOnlineVotes() {
when(config.getVoteCacheTime()).thenReturn(1); // 1 day
long currentTime = LocalDateTime.now().atZone(ZoneId.systemDefault()).toInstant().toEpochMilli();
long validTime = currentTime - (12 * 60 * 60 * 1000); // 12 hours ago
ArrayList<OfflineBungeeVote> votes = new ArrayList<>();
votes.add(new OfflineBungeeVote("player1", "uuid1", "service1", validTime, true, "text1"));
cachedOnlineVotes.put("server1", votes);
proxy.checkVoteCacheTime();
assertFalse(cachedOnlineVotes.get("server1").isEmpty());
}
@Test
void checkVoteCacheTime_removesExpiredVotesFromCachedVotes() {
when(config.getVoteCacheTime()).thenReturn(1); // 1 day
long currentTime = LocalDateTime.now().atZone(ZoneId.systemDefault()).toInstant().toEpochMilli();
long expiredTime = currentTime - (2 * 24 * 60 * 60 * 1000); // 2 days ago
ArrayList<OfflineBungeeVote> votes = new ArrayList<>();
votes.add(new OfflineBungeeVote("player1", "uuid1", "service1", expiredTime, true, "text1"));
cachedVotes.put("server1", votes);
proxy.checkVoteCacheTime();
assertTrue(cachedVotes.get("server1").isEmpty());
}
@Test
void checkVoteCacheTime_doesNotRemoveNonExpiredVotesFromCachedVotes() {
when(config.getVoteCacheTime()).thenReturn(1); // 1 day
long currentTime = LocalDateTime.now().atZone(ZoneId.systemDefault()).toInstant().toEpochMilli();
long validTime = currentTime - (12 * 60 * 60 * 1000); // 12 hours ago
ArrayList<OfflineBungeeVote> votes = new ArrayList<>();
votes.add(new OfflineBungeeVote("player1", "uuid1", "service1", validTime, true, "text1"));
cachedVotes.put("server1", votes);
proxy.checkVoteCacheTime();
assertFalse(cachedVotes.get("server1").isEmpty());
}
}