mirror of
https://github.com/BenCodez/VotingPlugin.git
synced 2026-11-07 10:12:36 -05:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
f04930e437 | ||
|
|
c45e8356bb | ||
|
|
2f78b7784a | ||
|
|
911642f57f | ||
|
|
5e63c04f6c | ||
|
|
e368f30dd9 | ||
|
|
5d5e8b0d55 | ||
|
|
16e52a4fd7 | ||
|
|
331c8fedf5 | ||
|
|
c085d6823e | ||
|
|
47680b2646 | ||
|
|
60ed0ce73d | ||
|
|
e5ae3184e0 | ||
|
|
dca9c6fe18 | ||
|
|
083e90706f | ||
|
|
fed96bcda1 | ||
|
|
5bad8c8f98 | ||
|
|
e31326395c | ||
|
|
f5b2d27b9e | ||
|
|
42626e3789 | ||
|
|
b35ff9454d | ||
|
|
9ee1547691 | ||
|
|
cb1599fe56 | ||
|
|
59a206617c | ||
|
|
699d74ca3f | ||
|
|
ad6d411e64 | ||
|
|
1b430dc4b8 | ||
|
|
526dcc830e | ||
|
|
75aaae7016 | ||
|
|
89d3372701 | ||
|
|
209f1dbc25 | ||
|
|
bb67de8d0e |
No files matched your search
@@ -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));
|
||||
|
||||
+1
-1
@@ -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
|
||||
|
||||
+18
-7
@@ -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;
|
||||
|
||||
+13
-5
@@ -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
-1
@@ -1,4 +1,4 @@
|
||||
package com.bencodez.votingplugin.bungee;
|
||||
package com.bencodez.votingplugin.proxy;
|
||||
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
package com.bencodez.votingplugin.bungee;
|
||||
package com.bencodez.votingplugin.proxy;
|
||||
|
||||
public enum BungeeMethod {
|
||||
MYSQL, PLUGINMESSAGING, SOCKETS, REDIS;
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
package com.bencodez.votingplugin.bungee;
|
||||
package com.bencodez.votingplugin.proxy;
|
||||
|
||||
public class BungeeVersion {
|
||||
public static int getPluginMessageVersion() {
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
package com.bencodez.votingplugin.bungee;
|
||||
package com.bencodez.votingplugin.proxy;
|
||||
|
||||
import lombok.Getter;
|
||||
|
||||
+34
-22
@@ -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
-2
@@ -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
-1
@@ -1,4 +1,4 @@
|
||||
package com.bencodez.votingplugin.bungee.proxy;
|
||||
package com.bencodez.votingplugin.proxy;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
package com.bencodez.votingplugin.bungee;
|
||||
package com.bencodez.votingplugin.proxy.bungee;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.BufferedWriter;
|
||||
+2
-2
@@ -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
-1
@@ -1,4 +1,4 @@
|
||||
package com.bencodez.votingplugin.bungee;
|
||||
package com.bencodez.votingplugin.proxy.bungee;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
+2
-1
@@ -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
-1
@@ -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;
|
||||
+6
-3
@@ -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;
|
||||
+3
-3
@@ -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("&", "§")));
|
||||
}
|
||||
}
|
||||
|
||||
+2
-2
@@ -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
-1
@@ -1,4 +1,4 @@
|
||||
package com.bencodez.votingplugin.bungee.global.multiproxy;
|
||||
package com.bencodez.votingplugin.proxy.global.multiproxy;
|
||||
|
||||
public enum MultiProxyMethod {
|
||||
SOCKETS, REDIS;
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
package com.bencodez.votingplugin.bungee.global.multiproxy;
|
||||
package com.bencodez.votingplugin.proxy.global.multiproxy;
|
||||
|
||||
public interface MultiProxyServerSocketConfiguration {
|
||||
String getHost();
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
package com.bencodez.votingplugin.bungee.global.multiproxy;
|
||||
package com.bencodez.votingplugin.proxy.global.multiproxy;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
package com.bencodez.votingplugin.bungee.global.multiproxy;
|
||||
package com.bencodez.votingplugin.proxy.global.multiproxy;
|
||||
|
||||
import ninja.leaping.configurate.ConfigurationNode;
|
||||
|
||||
+2
-2
@@ -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
-1
@@ -1,4 +1,4 @@
|
||||
package com.bencodez.votingplugin.bungee.velocity;
|
||||
package com.bencodez.votingplugin.proxy.velocity;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
+2
-2
@@ -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
-1
@@ -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
-1
@@ -1,4 +1,4 @@
|
||||
package com.bencodez.votingplugin.bungee.velocity;
|
||||
package com.bencodez.votingplugin.proxy.velocity;
|
||||
|
||||
import com.velocitypowered.api.proxy.messages.ChannelIdentifier;
|
||||
|
||||
+15
-13
@@ -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()) {
|
||||
+3
-3
@@ -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")) {
|
||||
|
||||
+1
-1
@@ -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,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
|
||||
}
|
||||
}
|
||||
+120
@@ -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());
|
||||
}
|
||||
}
|
||||
+202
@@ -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
|
||||
|
||||
}
|
||||
}
|
||||
+103
@@ -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());
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user