mirror of
https://github.com/BenCodez/VotingPlugin.git
synced 2026-11-04 17:10:03 -05:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
b8acfe20ec | ||
|
|
110aaf096e | ||
|
|
171975c3d3 | ||
|
|
ac96d277c5 | ||
|
|
b1ad952950 | ||
|
|
ca30bcb183 | ||
|
|
eecd975731 | ||
|
|
aa55b10e50 | ||
|
|
64f59f8195 | ||
|
|
a51e041430 | ||
|
|
b39f768a46 | ||
|
|
e98bc49add | ||
|
|
8b2209aa59 | ||
|
|
58a0e85d00 | ||
|
|
3febfa4056 | ||
|
|
e5668c862a | ||
|
|
fd4c6a3954 | ||
|
|
9e9472680a | ||
|
|
cbecd7be30 | ||
|
|
fcb1af77cf | ||
|
|
5d9b5b7b6c | ||
|
|
d26d61a6f0 | ||
|
|
3f885aa358 | ||
|
|
d088f2e91a | ||
|
|
a536c53dd9 | ||
|
|
5d2d6f0763 | ||
|
|
0848ed83c2 | ||
|
|
1771fe0889 | ||
|
|
ce5b197e8b | ||
|
|
15489d9c64 | ||
|
|
758632b5a5 | ||
|
|
3dc45b6a63 | ||
|
|
26c9ad98bc | ||
|
|
ee2531af1e | ||
|
|
461e5f8413 | ||
|
|
1c5acbd1a1 | ||
|
|
e855c01854 | ||
|
|
aeec7d9d17 | ||
|
|
4861c041e4 | ||
|
|
d1c6752240 | ||
|
|
caa7058363 | ||
|
|
b67f6a509c | ||
|
|
0edc09dc80 | ||
|
|
19e597e094 | ||
|
|
bfc838bfaa | ||
|
|
9cda17e89e | ||
|
|
54a573a445 | ||
|
|
5432b2a0d3 | ||
|
|
13d3a614ed | ||
|
|
f9641e158d | ||
|
|
a0c1f64aac | ||
|
|
1f88cb0261 | ||
|
|
71ccf6a7b0 | ||
|
|
47a42d2bc8 | ||
|
|
ac41787c1e | ||
|
|
ed4e3968da | ||
|
|
09da81cc4e | ||
|
|
fd35c43c16 | ||
|
|
8060f594c3 | ||
|
|
39aa7062a5 | ||
|
|
7ff7fbb7cb | ||
|
|
231817314b | ||
|
|
a20f10d978 | ||
|
|
997beaae28 | ||
|
|
9acc5861b7 | ||
|
|
f299847d46 | ||
|
|
87ff48366c | ||
|
|
3dde76dcde | ||
|
|
237713a799 | ||
|
|
23141d4ec1 | ||
|
|
2cfbaf4de8 | ||
|
|
c31b83fcd3 | ||
|
|
4cfd887c33 | ||
|
|
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
+29
-16
@@ -4,7 +4,7 @@
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>com.bencodez</groupId>
|
||||
<artifactId>votingplugin</artifactId>
|
||||
<version>6.18.3</version>
|
||||
<version>6.19</version>
|
||||
<packaging>jar</packaging>
|
||||
<name>VotingPlugin</name>
|
||||
<properties>
|
||||
@@ -95,6 +95,14 @@
|
||||
<include>**</include>
|
||||
</includes>
|
||||
</filter>
|
||||
<filter>
|
||||
<artifact>*:*</artifact>
|
||||
<excludes>
|
||||
<exclude>META-INF/*.SF</exclude>
|
||||
<exclude>META-INF/*.DSA</exclude>
|
||||
<exclude>META-INF/*.RSA</exclude>
|
||||
</excludes>
|
||||
</filter>
|
||||
</filters>
|
||||
<relocations>
|
||||
<relocation>
|
||||
@@ -121,11 +129,6 @@
|
||||
<shadedPattern>
|
||||
${project.groupId}.votingplugin.mysqlapi</shadedPattern>
|
||||
</relocation>
|
||||
<relocation>
|
||||
<pattern>com.zaxxer.HikariCP</pattern>
|
||||
<shadedPattern>
|
||||
${project.groupId}.votingplugin.HikariCP</shadedPattern>
|
||||
</relocation>
|
||||
<relocation>
|
||||
<pattern>com.zaxxer.hikari</pattern>
|
||||
<shadedPattern>
|
||||
@@ -206,24 +209,28 @@
|
||||
<url>
|
||||
https://repo.extendedclip.com/content/repositories/placeholderapi/</url>
|
||||
</repository>
|
||||
<repository>
|
||||
<id>scarsz</id>
|
||||
<url>https://nexus.scarsz.me/content/groups/public/</url>
|
||||
</repository>
|
||||
</repositories>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.spigotmc</groupId>
|
||||
<artifactId>spigot-api</artifactId>
|
||||
<version>1.21.4-R0.1-SNAPSHOT</version>
|
||||
<version>1.21.8-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.3</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
@@ -259,13 +266,13 @@
|
||||
<dependency>
|
||||
<groupId>com.bencodez</groupId>
|
||||
<artifactId>advancedcore</artifactId>
|
||||
<version>3.7.14</version>
|
||||
<version>3.7.18</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.junit.jupiter</groupId>
|
||||
<artifactId>junit-jupiter-engine</artifactId>
|
||||
<version>5.12.0</version>
|
||||
<version>5.12.2</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
@@ -274,6 +281,12 @@
|
||||
<version>5.15.2</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.discordsrv</groupId>
|
||||
<artifactId>discordsrv</artifactId>
|
||||
<version>1.30.0</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
<profiles>
|
||||
<profile>
|
||||
@@ -356,7 +369,7 @@
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-javadoc-plugin</artifactId>
|
||||
<version>3.11.2</version>
|
||||
<version>3.11.3</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>attach-javadocs</id>
|
||||
@@ -374,7 +387,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>
|
||||
@@ -431,7 +444,7 @@
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-javadoc-plugin</artifactId>
|
||||
<version>3.11.2</version>
|
||||
<version>3.11.3</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>attach-javadocs</id>
|
||||
@@ -573,7 +586,7 @@
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-javadoc-plugin</artifactId>
|
||||
<version>3.11.2</version>
|
||||
<version>3.11.3</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>attach-javadocs</id>
|
||||
@@ -591,7 +604,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>
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package com.bencodez.votingplugin;
|
||||
|
||||
import java.io.File;
|
||||
import java.sql.SQLException;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.ZoneOffset;
|
||||
import java.util.ArrayList;
|
||||
@@ -9,34 +10,41 @@ import java.util.UUID;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.ScheduledExecutorService;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.eclipse.paho.client.mqttv3.MqttException;
|
||||
|
||||
import com.bencodez.advancedcore.api.misc.MiscUtils;
|
||||
import com.bencodez.advancedcore.api.misc.encryption.EncryptionHandler;
|
||||
import com.bencodez.advancedcore.api.rewards.RewardBuilder;
|
||||
import com.bencodez.advancedcore.api.time.TimeType;
|
||||
import com.bencodez.advancedcore.api.user.UserStorage;
|
||||
import com.bencodez.advancedcore.api.user.usercache.value.DataValue;
|
||||
import com.bencodez.advancedcore.api.user.usercache.value.DataValueBoolean;
|
||||
import com.bencodez.advancedcore.api.user.userstorage.mysql.api.config.MysqlConfigSpigot;
|
||||
import com.bencodez.advancedcore.bungeeapi.GlobalMessage.GlobalMessageHandler;
|
||||
import com.bencodez.advancedcore.bungeeapi.GlobalMessage.GlobalMessageListener;
|
||||
import com.bencodez.advancedcore.bungeeapi.globaldata.GlobalDataHandler;
|
||||
import com.bencodez.advancedcore.bungeeapi.globaldata.GlobalMySQL;
|
||||
import com.bencodez.advancedcore.bungeeapi.pluginmessage.PluginMessageHandler;
|
||||
import com.bencodez.advancedcore.bungeeapi.redis.RedisHandler;
|
||||
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.simpleapi.array.ArrayUtils;
|
||||
import com.bencodez.votingplugin.bungee.BungeeMessageData;
|
||||
import com.bencodez.votingplugin.bungee.BungeeMethod;
|
||||
import com.bencodez.votingplugin.bungee.BungeeVersion;
|
||||
import com.bencodez.simpleapi.encryption.EncryptionHandler;
|
||||
import com.bencodez.simpleapi.messages.MessageAPI;
|
||||
import com.bencodez.simpleapi.servercomm.global.GlobalMessageHandler;
|
||||
import com.bencodez.simpleapi.servercomm.global.GlobalMessageListener;
|
||||
import com.bencodez.simpleapi.servercomm.mqtt.MqttHandler;
|
||||
import com.bencodez.simpleapi.servercomm.mqtt.MqttHandler.MessageHandler;
|
||||
import com.bencodez.simpleapi.servercomm.mqtt.MqttServerComm;
|
||||
import com.bencodez.simpleapi.servercomm.mysql.BackendMessenger;
|
||||
import com.bencodez.simpleapi.servercomm.pluginmessage.PluginMessageHandler;
|
||||
import com.bencodez.simpleapi.servercomm.redis.RedisHandler;
|
||||
import com.bencodez.simpleapi.servercomm.redis.RedisListener;
|
||||
import com.bencodez.simpleapi.servercomm.sockets.ClientHandler;
|
||||
import com.bencodez.simpleapi.servercomm.sockets.SocketHandler;
|
||||
import com.bencodez.simpleapi.servercomm.sockets.SocketReceiver;
|
||||
import com.bencodez.simpleapi.sql.data.DataValue;
|
||||
import com.bencodez.simpleapi.sql.data.DataValueBoolean;
|
||||
import com.bencodez.simpleapi.sql.mysql.config.MysqlConfigSpigot;
|
||||
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;
|
||||
@@ -74,6 +82,9 @@ public class BungeeHandler implements Listener {
|
||||
|
||||
private Thread redisThread;
|
||||
|
||||
@Getter
|
||||
private BackendMessenger backendMysqlMessenger;
|
||||
|
||||
public BungeeHandler(VotingPluginMain plugin) {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
@@ -161,6 +172,10 @@ public class BungeeHandler implements Listener {
|
||||
}
|
||||
|
||||
public void close() {
|
||||
if (backendMysqlMessenger != null) {
|
||||
backendMysqlMessenger.shutdown();
|
||||
}
|
||||
|
||||
if (socketHandler != null) {
|
||||
socketHandler.closeConnection();
|
||||
}
|
||||
@@ -188,7 +203,14 @@ public class BungeeHandler implements Listener {
|
||||
@Override
|
||||
public void sendMessage(String subChannel, String... messageData) {
|
||||
if (method.equals(BungeeMethod.MYSQL)) {
|
||||
plugin.getPluginMessaging().sendPluginMessage(subChannel, messageData);
|
||||
// plugin.getPluginMessaging().sendPluginMessage(subChannel, messageData);
|
||||
|
||||
try {
|
||||
backendMysqlMessenger.sendToProxy(subChannel + "%l%" + String.join("%l%", messageData));
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
} else if (method.equals(BungeeMethod.PLUGINMESSAGING)) {
|
||||
plugin.getPluginMessaging().sendPluginMessage(subChannel, messageData);
|
||||
} else if (method.equals(BungeeMethod.SOCKETS)) {
|
||||
@@ -202,6 +224,17 @@ public class BungeeHandler implements Listener {
|
||||
list.addAll(ArrayUtils.convert(messageData));
|
||||
redisHandler.sendMessage(plugin.getBungeeSettings().getRedisPrefix() + "VotingPlugin",
|
||||
ArrayUtils.convert(list));
|
||||
} else if (method.equals(BungeeMethod.MQTT)) {
|
||||
ArrayList<String> list = new ArrayList<>();
|
||||
list.add(subChannel);
|
||||
list.addAll(ArrayUtils.convert(messageData));
|
||||
try {
|
||||
mqttHandler.publish(plugin.getBungeeSettings().getMqttPrefix() + "votingplugin/servers/proxy",
|
||||
String.join(":", list));
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
};
|
||||
@@ -324,10 +357,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));
|
||||
@@ -403,11 +432,6 @@ public class BungeeHandler implements Listener {
|
||||
|
||||
user.offVote();
|
||||
|
||||
if (args.size() > 3 && plugin.getBungeeSettings().isPerServerMilestones()) {
|
||||
BungeeMessageData text = new BungeeMessageData(args.get(3));
|
||||
plugin.getSpecialRewards().checkMilestone(user, text, true);
|
||||
}
|
||||
|
||||
if (args.size() > 2) {
|
||||
bungeeVotePartyCurrent = Integer.parseInt(args.get(1));
|
||||
bungeeVotePartyRequired = Integer.parseInt(args.get(2));
|
||||
@@ -415,6 +439,26 @@ public class BungeeHandler implements Listener {
|
||||
plugin.getServerData().setBungeeVotePartyRequired(bungeeVotePartyRequired);
|
||||
}
|
||||
|
||||
if (args.size() > 3 && plugin.getBungeeSettings().isPerServerMilestones()) {
|
||||
BungeeMessageData text = new BungeeMessageData(args.get(3));
|
||||
plugin.getSpecialRewards().checkMilestone(user, text, true);
|
||||
}
|
||||
|
||||
if (args.size() > 5) {
|
||||
String service = args.get(4);
|
||||
String data = args.get(5);
|
||||
if (MessageAPI.isLong(data)) {
|
||||
long time = Long.valueOf(data);
|
||||
if (time > 0) {
|
||||
user.setTime(plugin.getVoteSite(service, true), time);
|
||||
} else {
|
||||
if (plugin.getBungeeSettings().isBungeeDebug()) {
|
||||
plugin.debug("Invalid last vote time received from bungee: " + time);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
plugin.setUpdate(true);
|
||||
}
|
||||
});
|
||||
@@ -506,6 +550,27 @@ public class BungeeHandler implements Listener {
|
||||
|
||||
if (method.equals(BungeeMethod.MYSQL)) {
|
||||
plugin.registerBungeeChannels(plugin.getBungeeSettings().getPluginMessagingChannel());
|
||||
|
||||
try {
|
||||
backendMysqlMessenger = new BackendMessenger("VotingPlugin",
|
||||
plugin.getMysql().getMysql().getConnectionManager().getDataSource(),
|
||||
plugin.getOptions().getServer(), msg -> {
|
||||
plugin.debug("Proxy sent: " + msg.payload);
|
||||
|
||||
String[] message = msg.payload.split(Pattern.quote("%l%"));
|
||||
if (message.length > 0) {
|
||||
ArrayList<String> list = new ArrayList<>();
|
||||
for (int i = 1; i < message.length; i++) {
|
||||
list.add(message[i]);
|
||||
}
|
||||
globalMessageHandler.onMessage(message[0], list);
|
||||
}
|
||||
|
||||
});
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
} else if (method.equals(BungeeMethod.REDIS)) {
|
||||
redisHandler = new RedisHandler(plugin.getBungeeSettings().getRedisHost(),
|
||||
plugin.getBungeeSettings().getRedisPort(), plugin.getBungeeSettings().getRedisUsername(),
|
||||
@@ -520,7 +585,9 @@ public class BungeeHandler implements Listener {
|
||||
|
||||
@Override
|
||||
protected void onMessage(String channel, String[] message) {
|
||||
plugin.getLogger().info(channel + ArrayUtils.makeStringList(ArrayUtils.convert(message)));
|
||||
if (plugin.getBungeeSettings().isBungeeDebug()) {
|
||||
plugin.debug(channel + " " + ArrayUtils.makeStringList(ArrayUtils.convert(message)));
|
||||
}
|
||||
if (message.length > 0) {
|
||||
ArrayList<String> list = new ArrayList<>();
|
||||
for (int i = 1; i < message.length; i++) {
|
||||
@@ -547,88 +614,24 @@ public class BungeeHandler implements Listener {
|
||||
plugin.registerBungeeChannels(plugin.getBungeeSettings().getPluginMessagingChannel());
|
||||
|
||||
if (plugin.getBungeeSettings().isPluginMessageEncryption()) {
|
||||
encryptionHandler = new EncryptionHandler(new File(plugin.getDataFolder(), "secretkey.key"));
|
||||
encryptionHandler = new EncryptionHandler(plugin.getName(),
|
||||
new File(plugin.getDataFolder(), "secretkey.key"));
|
||||
plugin.getPluginMessaging().setEncryptionHandler(encryptionHandler);
|
||||
}
|
||||
|
||||
bungeeVotePartyCurrent = plugin.getServerData().getBungeeVotePartyCurrent();
|
||||
bungeeVotePartyRequired = plugin.getServerData().getBungeeVotePartyRequired();
|
||||
|
||||
plugin.getPluginMessaging().setDebug(plugin.getBungeeSettings().isBungeeDebug());
|
||||
|
||||
plugin.getPluginMessaging().add(new PluginMessageHandler("Vote") {
|
||||
plugin.getPluginMessaging().add(new PluginMessageHandler() {
|
||||
@Override
|
||||
public void onRecieve(String subChannel, ArrayList<String> args) {
|
||||
globalMessageHandler.onMessage("Vote", args);
|
||||
}
|
||||
});
|
||||
globalMessageHandler.onMessage(subChannel, args);
|
||||
|
||||
plugin.getPluginMessaging().add(new PluginMessageHandler("VoteOnline") {
|
||||
@Override
|
||||
public void onRecieve(String subChannel, ArrayList<String> args) {
|
||||
globalMessageHandler.onMessage("VoteOnline", args);
|
||||
}
|
||||
});
|
||||
|
||||
plugin.getPluginMessaging().add(new PluginMessageHandler("VoteUpdate") {
|
||||
@Override
|
||||
public void onRecieve(String subChannel, ArrayList<String> args) {
|
||||
globalMessageHandler.onMessage("VoteUpdate", args);
|
||||
}
|
||||
});
|
||||
|
||||
plugin.getPluginMessaging().add(new PluginMessageHandler("BungeeTimeChange") {
|
||||
@Override
|
||||
public void onRecieve(String subChannel, ArrayList<String> args) {
|
||||
globalMessageHandler.onMessage("BungeeTimeChange", args);
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
plugin.getPluginMessaging().add(new PluginMessageHandler("VoteBroadcast") {
|
||||
@Override
|
||||
public void onRecieve(String subChannel, ArrayList<String> args) {
|
||||
globalMessageHandler.onMessage("VoteBroadcast", args);
|
||||
}
|
||||
});
|
||||
|
||||
plugin.getPluginMessaging().add(new PluginMessageHandler("VoteBroadcastOffline") {
|
||||
@Override
|
||||
public void onRecieve(String subChannel, ArrayList<String> args) {
|
||||
globalMessageHandler.onMessage("VoteBroadcastOffline", args);
|
||||
}
|
||||
});
|
||||
|
||||
plugin.getPluginMessaging().add(new PluginMessageHandler("Status") {
|
||||
@Override
|
||||
public void onRecieve(String subChannel, ArrayList<String> args) {
|
||||
globalMessageHandler.onMessage("Status", args);
|
||||
}
|
||||
});
|
||||
|
||||
plugin.getPluginMessaging().add(new PluginMessageHandler("ServerName") {
|
||||
@Override
|
||||
public void onRecieve(String subChannel, ArrayList<String> args) {
|
||||
globalMessageHandler.onMessage("ServerName", args);
|
||||
}
|
||||
});
|
||||
|
||||
plugin.getPluginMessaging().add(new PluginMessageHandler("VotePartyBungee") {
|
||||
@Override
|
||||
public void onRecieve(String subChannel, ArrayList<String> args) {
|
||||
globalMessageHandler.onMessage("VotePartyBungee", args);
|
||||
}
|
||||
});
|
||||
|
||||
plugin.getPluginMessaging().add(new PluginMessageHandler("VotePartyBroadcast") {
|
||||
@Override
|
||||
public void onRecieve(String subChannel, ArrayList<String> args) {
|
||||
globalMessageHandler.onMessage("VotePartyBroadcast", args);
|
||||
}
|
||||
});
|
||||
|
||||
} else if (method.equals(BungeeMethod.SOCKETS)) {
|
||||
encryptionHandler = new EncryptionHandler(new File(plugin.getDataFolder(), "secretkey.key"));
|
||||
encryptionHandler = new EncryptionHandler(plugin.getName(),
|
||||
new File(plugin.getDataFolder(), "secretkey.key"));
|
||||
|
||||
clientHandler = new ClientHandler(plugin.getBungeeSettings().getBungeeServerHost(),
|
||||
plugin.getBungeeSettings().getBungeeServerPort(), encryptionHandler,
|
||||
@@ -644,158 +647,55 @@ public class BungeeHandler implements Listener {
|
||||
}
|
||||
};
|
||||
|
||||
socketHandler.add(new SocketReceiver("bungeevote") {
|
||||
socketHandler.add(new SocketReceiver() {
|
||||
|
||||
@Override
|
||||
public void onReceive(String[] data) {
|
||||
if (data.length > 5) {
|
||||
plugin.extraDebug("BungeeVote from " + data[2] + ", processing");
|
||||
String uuid = data[1];
|
||||
VotingPluginUser user = null;
|
||||
if (!uuid.isEmpty()) {
|
||||
user = plugin.getVotingPluginUserManager().getVotingPluginUser(UUID.fromString(uuid));
|
||||
} else {
|
||||
user = plugin.getVotingPluginUserManager().getVotingPluginUser(data[2]);
|
||||
}
|
||||
|
||||
user.cache();
|
||||
|
||||
if (plugin.getBungeeSettings().isPerServerPoints()) {
|
||||
user.addPoints(plugin.getConfigFile().getPointsOnVote());
|
||||
}
|
||||
|
||||
user.bungeeVote(data[3], new BungeeMessageData(data[4]), !Boolean.valueOf(data[5]));
|
||||
}
|
||||
globalMessageHandler.onMessage(data[0], ArrayUtils.convertAndRemoveFirst(data));
|
||||
}
|
||||
});
|
||||
|
||||
socketHandler.add(new SocketReceiver("BungeeTimeChange") {
|
||||
|
||||
@Override
|
||||
public void onReceive(String[] data) {
|
||||
checkGlobalData();
|
||||
} else if (method.equals(BungeeMethod.MQTT)) {
|
||||
try {
|
||||
String id = plugin.getBungeeSettings().getMqttClientID();
|
||||
if (id.isEmpty()) {
|
||||
id = plugin.getOptions().getServer();
|
||||
}
|
||||
});
|
||||
mqttHandler = new MqttHandler(new MqttServerComm(plugin.getBungeeSettings().getMqttClientID(),
|
||||
plugin.getBungeeSettings().getMqttBrokerURL(), plugin.getBungeeSettings().getMqttUsername(),
|
||||
plugin.getBungeeSettings().getMqttPassword()), 2);
|
||||
mqttHandler.subscribe(plugin.getBungeeSettings().getMqttPrefix() + "votingplugin/servers/"
|
||||
+ plugin.getOptions().getServer(), new MessageHandler() {
|
||||
|
||||
socketHandler.add(new SocketReceiver("bungeevoteonline") {
|
||||
@Override
|
||||
public void onMessage(String topic, String payload) {
|
||||
String[] message = payload.split(":");
|
||||
|
||||
@Override
|
||||
public void onReceive(String[] data) {
|
||||
if (data.length > 5) {
|
||||
plugin.extraDebug("BungeeVoteOnline from " + data[2] + ", processing");
|
||||
String uuid = data[1];
|
||||
VotingPluginUser user = null;
|
||||
if (!uuid.isEmpty()) {
|
||||
user = plugin.getVotingPluginUserManager().getVotingPluginUser(UUID.fromString(uuid));
|
||||
} else {
|
||||
user = plugin.getVotingPluginUserManager().getVotingPluginUser(data[2]);
|
||||
}
|
||||
|
||||
user.cache();
|
||||
|
||||
if (plugin.getBungeeSettings().isPerServerPoints()) {
|
||||
user.addPoints(plugin.getConfigFile().getPointsOnVote());
|
||||
}
|
||||
|
||||
user.bungeeVoteOnline(data[3], new BungeeMessageData(data[4]), !Boolean.valueOf(data[5]));
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
socketHandler.add(new SocketReceiver("BroadcastOffline") {
|
||||
|
||||
@Override
|
||||
public void onReceive(String[] data) {
|
||||
if (data.length > 2) {
|
||||
String votes = data[0];
|
||||
String p = data[1];
|
||||
VotingPluginUser user = plugin.getVotingPluginUserManager().getVotingPluginUser(p);
|
||||
user.offlineBroadcast(user, false, Integer.parseInt(votes));
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
socketHandler.add(new SocketReceiver("BungeeBroadcast") {
|
||||
|
||||
@Override
|
||||
public void onReceive(String[] data) {
|
||||
if (data.length > 2) {
|
||||
VoteSite site = plugin.getVoteSite(data[1], true);
|
||||
String p = data[3];
|
||||
VotingPluginUser user = plugin.getVotingPluginUserManager().getVotingPluginUser(p);
|
||||
if (site != null) {
|
||||
site.broadcastVote(user, false);
|
||||
} else {
|
||||
plugin.getLogger().warning("No votesite for " + data[1]);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
socketHandler.add(new SocketReceiver("Broadcast") {
|
||||
|
||||
@Override
|
||||
public void onReceive(String[] data) {
|
||||
if (data.length > 2) {
|
||||
VoteSite site = plugin.getVoteSite(data[1], true);
|
||||
String p = data[2];
|
||||
VotingPluginUser user = plugin.getVotingPluginUserManager().getVotingPluginUser(p);
|
||||
if (site != null) {
|
||||
site.broadcastVote(user, false);
|
||||
} else {
|
||||
plugin.getLogger().warning("No votesite for " + data[1]);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
socketHandler.add(new SocketReceiver("Status") {
|
||||
|
||||
@Override
|
||||
public void onReceive(String[] data) {
|
||||
if (data.length > 0) {
|
||||
plugin.getLogger().info("Received status command, sending status back");
|
||||
sendData("StatusOkay", plugin.getOptions().getServer());
|
||||
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
socketHandler.add(new SocketReceiver("BungeeUpdate") {
|
||||
|
||||
@Override
|
||||
public void onReceive(String[] data) {
|
||||
plugin.setUpdate(true);
|
||||
}
|
||||
});
|
||||
|
||||
socketHandler.add(new SocketReceiver("VotePartyBungee") {
|
||||
|
||||
@Override
|
||||
public void onReceive(String[] data) {
|
||||
for (Player p : Bukkit.getOnlinePlayers()) {
|
||||
new RewardBuilder(plugin.getBungeeSettings().getData(), "BungeeVotePartyRewards").send(p);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
socketHandler.add(new SocketReceiver("VotePartyBroadcast") {
|
||||
|
||||
@Override
|
||||
public void onReceive(String[] data) {
|
||||
String broadcast = data[0];
|
||||
MiscUtils.getInstance().broadcast(broadcast);
|
||||
}
|
||||
});
|
||||
|
||||
if (plugin.getOptions().getServer().equalsIgnoreCase("pleaseset")) {
|
||||
plugin.getLogger().warning("Server name for bungee voting is not set, please set it");
|
||||
if (message.length > 0) {
|
||||
globalMessageHandler.onMessage(message[0],
|
||||
ArrayUtils.convertAndRemoveFirst(message));
|
||||
}
|
||||
}
|
||||
});
|
||||
} catch (MqttException e) {
|
||||
e.printStackTrace();
|
||||
} catch (Exception e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
bungeeVotePartyCurrent = plugin.getServerData().getBungeeVotePartyCurrent();
|
||||
bungeeVotePartyRequired = plugin.getServerData().getBungeeVotePartyRequired();
|
||||
|
||||
if (plugin.getOptions().getServer().equalsIgnoreCase("pleaseset")) {
|
||||
plugin.getLogger().warning("Server name for bungee voting is not set, please set it");
|
||||
}
|
||||
}
|
||||
|
||||
@Getter
|
||||
private MqttHandler mqttHandler;
|
||||
|
||||
public void loadGlobalMysql() {
|
||||
if (plugin.getBungeeSettings().isGloblalDataEnabled()) {
|
||||
if (timer != null) {
|
||||
@@ -832,12 +732,12 @@ public class BungeeHandler implements Listener {
|
||||
new GlobalMySQL("VotingPlugin_GlobalData", plugin.getMysql().getMysql()) {
|
||||
|
||||
@Override
|
||||
public void debug(Exception e) {
|
||||
public void debugEx(Exception e) {
|
||||
plugin.debug(e);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void debug(String text) {
|
||||
public void debugLog(String text) {
|
||||
plugin.debug(text);
|
||||
}
|
||||
|
||||
@@ -847,7 +747,7 @@ public class BungeeHandler implements Listener {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void severe(String text) {
|
||||
public void logSevere(String text) {
|
||||
plugin.getLogger().severe(text);
|
||||
}
|
||||
|
||||
@@ -862,12 +762,12 @@ public class BungeeHandler implements Listener {
|
||||
plugin.getBungeeSettings().getData().getConfigurationSection("GlobalData"))) {
|
||||
|
||||
@Override
|
||||
public void debug(Exception e) {
|
||||
public void debugEx(Exception e) {
|
||||
plugin.debug(e);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void debug(String text) {
|
||||
public void debugLog(String text) {
|
||||
plugin.debug(text);
|
||||
}
|
||||
|
||||
@@ -877,7 +777,7 @@ public class BungeeHandler implements Listener {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void severe(String text) {
|
||||
public void logSevere(String text) {
|
||||
plugin.getLogger().severe(text);
|
||||
}
|
||||
|
||||
|
||||
@@ -55,11 +55,10 @@ import com.bencodez.advancedcore.api.rewards.injected.RewardInjectInt;
|
||||
import com.bencodez.advancedcore.api.rewards.injected.RewardInjectValidator;
|
||||
import com.bencodez.advancedcore.api.rewards.injectedrequirement.RequirementInjectConfigurationSection;
|
||||
import com.bencodez.advancedcore.api.user.AdvancedCoreUser;
|
||||
import com.bencodez.advancedcore.api.user.userstorage.Column;
|
||||
import com.bencodez.advancedcore.logger.Logger;
|
||||
import com.bencodez.simpleapi.file.YMLConfig;
|
||||
import com.bencodez.simpleapi.nms.NMSManager;
|
||||
import com.bencodez.simpleapi.skull.SkullCache;
|
||||
import com.bencodez.simpleapi.sql.Column;
|
||||
import com.bencodez.simpleapi.updater.Updater;
|
||||
import com.bencodez.votingplugin.broadcast.BroadcastHandler;
|
||||
import com.bencodez.votingplugin.commands.CommandLoader;
|
||||
@@ -76,6 +75,7 @@ import com.bencodez.votingplugin.config.ShopFile;
|
||||
import com.bencodez.votingplugin.config.SpecialRewardsConfig;
|
||||
import com.bencodez.votingplugin.cooldown.CoolDownCheck;
|
||||
import com.bencodez.votingplugin.data.ServerData;
|
||||
import com.bencodez.votingplugin.discord.DiscordHandler;
|
||||
import com.bencodez.votingplugin.listeners.BlockBreak;
|
||||
import com.bencodez.votingplugin.listeners.PlayerInteract;
|
||||
import com.bencodez.votingplugin.listeners.PlayerJoinEvent;
|
||||
@@ -247,6 +247,9 @@ public class VotingPluginMain extends AdvancedCorePlugin {
|
||||
|
||||
private boolean firstTimeLoaded = false;
|
||||
|
||||
@Getter
|
||||
private DiscordHandler discordHandler;
|
||||
|
||||
public void addDirectlyDefinedRewards(DirectlyDefinedReward directlyDefinedReward) {
|
||||
getRewardHandler().addDirectlyDefined(directlyDefinedReward);
|
||||
}
|
||||
@@ -339,6 +342,7 @@ public class VotingPluginMain extends AdvancedCorePlugin {
|
||||
* @param uuid the uuid
|
||||
* @return the user
|
||||
*/
|
||||
@Deprecated
|
||||
public VotingPluginUser getUser(UUID uuid) {
|
||||
return getVotingPluginUserManager().getVotingPluginUser(uuid);
|
||||
}
|
||||
@@ -1198,6 +1202,12 @@ public class VotingPluginMain extends AdvancedCorePlugin {
|
||||
mvdwPlaceholders.loadMVdWPlaceholders();
|
||||
}
|
||||
|
||||
if (Bukkit.getPluginManager().isPluginEnabled("DiscordSRV") && configFile.isDiscordSRVEnabled()) {
|
||||
discordHandler = new DiscordHandler(this);
|
||||
discordHandler.load();
|
||||
debug("DiscordSRV enabled, loading DiscordSRV handler");
|
||||
}
|
||||
|
||||
// Add rewards
|
||||
getRewardHandler().addInjectedReward(new RewardInjectInt("Points", 0) {
|
||||
|
||||
@@ -1384,18 +1394,6 @@ public class VotingPluginMain extends AdvancedCorePlugin {
|
||||
public void onPreLoad() {
|
||||
plugin = this;
|
||||
|
||||
// disable plugin for older versions below 1.12
|
||||
|
||||
if (NMSManager.getInstance().isVersion("1.7", "1.8", "1.9", "1.10", "1.11")) {
|
||||
plugin.getLogger().severe("Detected running " + Bukkit.getVersion()
|
||||
+ ", this version is not supported on this build, read the plugin page. Disabling...");
|
||||
if (!configFile.isOverrideVersionDisable()) {
|
||||
Bukkit.getPluginManager().disablePlugin(this);
|
||||
return;
|
||||
}
|
||||
plugin.getLogger().warning("Overriding version disable, beware of using this! This may cause issues!");
|
||||
}
|
||||
|
||||
setupFiles();
|
||||
|
||||
loadVoteSites();
|
||||
@@ -1712,6 +1710,11 @@ public class VotingPluginMain extends AdvancedCorePlugin {
|
||||
|
||||
checkFirstTimeLoaded();
|
||||
|
||||
if (discordHandler != null) {
|
||||
plugin.extraDebug("Attempting to update DiscordSRV leaderboard");
|
||||
discordHandler.updateDiscordLeaderboard();
|
||||
}
|
||||
|
||||
plugin.getUserManager().getDataManager().clearNonNeededCachedUsers();
|
||||
plugin.extraDebug("Current cached users: "
|
||||
+ plugin.getUserManager().getDataManager().getUserDataCache().keySet().size());
|
||||
|
||||
@@ -31,8 +31,6 @@ import com.bencodez.advancedcore.api.messages.PlaceholderUtils;
|
||||
import com.bencodez.advancedcore.api.misc.PlayerManager;
|
||||
import com.bencodez.advancedcore.api.rewards.RewardOptions;
|
||||
import com.bencodez.advancedcore.api.user.UserStorage;
|
||||
import com.bencodez.advancedcore.api.user.userstorage.Column;
|
||||
import com.bencodez.advancedcore.api.user.userstorage.DataType;
|
||||
import com.bencodez.advancedcore.api.valuerequest.ValueRequest;
|
||||
import com.bencodez.advancedcore.api.valuerequest.listeners.BooleanListener;
|
||||
import com.bencodez.advancedcore.api.valuerequest.listeners.StringListener;
|
||||
@@ -43,6 +41,8 @@ import com.bencodez.simpleapi.command.TabCompleteHandle;
|
||||
import com.bencodez.simpleapi.command.TabCompleteHandler;
|
||||
import com.bencodez.simpleapi.debug.DebugLevel;
|
||||
import com.bencodez.simpleapi.messages.MessageAPI;
|
||||
import com.bencodez.simpleapi.sql.Column;
|
||||
import com.bencodez.simpleapi.sql.DataType;
|
||||
import com.bencodez.simpleapi.updater.Updater;
|
||||
import com.bencodez.votingplugin.VotingPluginMain;
|
||||
import com.bencodez.votingplugin.commands.executers.CommandAliases;
|
||||
@@ -1069,7 +1069,7 @@ public class CommandLoader {
|
||||
sender.sendMessage(MessageAPI.colorize("&cClearing gotten milestones for all players..."));
|
||||
plugin.getUserManager().removeAllKeyValues(path, DataType.STRING);
|
||||
for (Player p : Bukkit.getOnlinePlayers()) {
|
||||
plugin.getUserManager().getDataManager().cacheUser(p.getUniqueId());
|
||||
plugin.getUserManager().getDataManager().cacheUser(p.getUniqueId(), p.getName());
|
||||
}
|
||||
sender.sendMessage(
|
||||
MessageAPI.colorize("&cFinished clearing gotten milestones for all players"));
|
||||
@@ -1842,6 +1842,21 @@ public class CommandLoader {
|
||||
}
|
||||
});
|
||||
|
||||
plugin.getAdminVoteCommand()
|
||||
.add(new CommandHandler(plugin, new String[] { "ClearDiscordMessageID", "(topvoter)" },
|
||||
"VotingPlugin.Commands.AdminVote.ClearDiscordMessageID",
|
||||
"Clear discord message ID for top voter", true, true) {
|
||||
|
||||
@Override
|
||||
public void execute(CommandSender sender, String[] args) {
|
||||
String topVoter = args[1];
|
||||
TopVoter top = TopVoter.getTopVoter(topVoter);
|
||||
plugin.getServerData().setTopVoterMessageId(top, 0);
|
||||
plugin.getDiscordHandler().getTopVoterMessageIds().put(top, 0L);
|
||||
sendMessage(sender, "&cCleared discord message ID for " + top.toString());
|
||||
}
|
||||
});
|
||||
|
||||
plugin.getAdminVoteCommand().add(new CommandHandler(plugin, new String[] {},
|
||||
"VotingPlugin.Commands.AdminVote|" + adminPerm, "Base command") {
|
||||
|
||||
|
||||
+1
@@ -28,6 +28,7 @@ import com.bencodez.votingplugin.user.VotingPluginUser;
|
||||
|
||||
public class AdminVoteTopPoints extends GUIHandler {
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
private int page;
|
||||
private VotingPluginMain plugin;
|
||||
private VotingPluginUser user;
|
||||
|
||||
+30
-16
@@ -186,8 +186,26 @@ public class VoteURL extends GUIHandler {
|
||||
|
||||
@Override
|
||||
public void onChest(Player player) {
|
||||
// normal GUI
|
||||
|
||||
BInventory inv = new BInventory(plugin.getGui().getChestVoteURLName());
|
||||
|
||||
if (!plugin.getConfigFile().isAlwaysCloseInventory()) {
|
||||
inv.dontClose();
|
||||
}
|
||||
|
||||
for (final String str : plugin.getGui().getChestVoteURLExtraItems()) {
|
||||
inv.addButton(new BInventoryButton(new ItemBuilder(plugin.getGui().getChestVoteURLExtraItemsItem(str))) {
|
||||
|
||||
@Override
|
||||
public void onClick(ClickEvent clickEvent) {
|
||||
new RewardBuilder(plugin.getGui().getData(),
|
||||
"CHEST.VoteURL.ExtraItems." + str + "." + clickEvent.getButton().getLastRewardsPath(player))
|
||||
.setGiveOffline(false).send(clickEvent.getPlayer());
|
||||
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
if (plugin.getGui().isChestVoteURLViewAllUrlsButtonEnabled()) {
|
||||
ItemBuilder builderAll = getItemAll();
|
||||
|
||||
@@ -195,6 +213,7 @@ public class VoteURL extends GUIHandler {
|
||||
|
||||
@Override
|
||||
public void onClick(ClickEvent event) {
|
||||
event.closeInventory();
|
||||
VotingPluginUser user = plugin.getVotingPluginUserManager().getVotingPluginUser(event.getPlayer());
|
||||
json = true;
|
||||
if (event.getClick().equals(ClickType.SHIFT_LEFT)
|
||||
@@ -218,6 +237,15 @@ public class VoteURL extends GUIHandler {
|
||||
if (voteSite.getPermissionToView().isEmpty() || player.hasPermission(voteSite.getPermissionToView())) {
|
||||
ItemBuilder builder = getItemVoteSite(voteSite);
|
||||
if (startSlot >= 0) {
|
||||
if (inv.isSlotTaken(startSlot)) {
|
||||
boolean found = false;
|
||||
while (!found) {
|
||||
startSlot++;
|
||||
if (!inv.isSlotTaken(startSlot)) {
|
||||
found = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
builder.setSlot(startSlot);
|
||||
startSlot++;
|
||||
}
|
||||
@@ -226,6 +254,7 @@ public class VoteURL extends GUIHandler {
|
||||
|
||||
@Override
|
||||
public void onClick(ClickEvent event) {
|
||||
event.closeInventory();
|
||||
Player player = event.getPlayer();
|
||||
if (player != null) {
|
||||
VotingPluginUser user = plugin.getVotingPluginUserManager().getVotingPluginUser(player);
|
||||
@@ -252,21 +281,6 @@ public class VoteURL extends GUIHandler {
|
||||
}
|
||||
}
|
||||
|
||||
for (
|
||||
|
||||
final String str : plugin.getGui().getChestVoteURLExtraItems()) {
|
||||
inv.addButton(new BInventoryButton(new ItemBuilder(plugin.getGui().getChestVoteURLExtraItemsItem(str))) {
|
||||
|
||||
@Override
|
||||
public void onClick(ClickEvent clickEvent) {
|
||||
new RewardBuilder(plugin.getGui().getData(),
|
||||
"CHEST.VoteURL.ExtraItems." + str + "." + clickEvent.getButton().getLastRewardsPath(player))
|
||||
.setGiveOffline(false).send(clickEvent.getPlayer());
|
||||
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
if (plugin.getGui().isChestVoteURLBackButton()) {
|
||||
inv.addButton(plugin.getCommandLoader().getBackButton(user));
|
||||
}
|
||||
|
||||
@@ -58,6 +58,26 @@ public class BungeeSettings extends YMLFile {
|
||||
@ConfigDataInt(path = "Redis.Port")
|
||||
@Getter
|
||||
private int RedisPort = 6379;
|
||||
|
||||
@ConfigDataString(path = "MQTT.ClientID")
|
||||
@Getter
|
||||
private String mqttClientID = "";
|
||||
|
||||
@ConfigDataString(path = "MQTT.BrokerURL")
|
||||
@Getter
|
||||
private String mqttBrokerURL = "tcp://localhost:1883";
|
||||
|
||||
@ConfigDataString(path = "MQTT.Username")
|
||||
@Getter
|
||||
private String mqttUsername = "";
|
||||
|
||||
@ConfigDataString(path = "MQTT.Password")
|
||||
@Getter
|
||||
private String mqttPassword = "";
|
||||
|
||||
@ConfigDataString(path = "MQTT.Prefix")
|
||||
@Getter
|
||||
private String mqttPrefix = "";
|
||||
|
||||
@ConfigDataString(path = "BungeeServer.Host")
|
||||
@Getter
|
||||
|
||||
@@ -14,6 +14,7 @@ import com.bencodez.simpleapi.file.annotation.ConfigDataBoolean;
|
||||
import com.bencodez.simpleapi.file.annotation.ConfigDataInt;
|
||||
import com.bencodez.simpleapi.file.annotation.ConfigDataKeys;
|
||||
import com.bencodez.simpleapi.file.annotation.ConfigDataListString;
|
||||
import com.bencodez.simpleapi.file.annotation.ConfigDataLong;
|
||||
import com.bencodez.simpleapi.file.annotation.ConfigDataString;
|
||||
import com.bencodez.votingplugin.VotingPluginMain;
|
||||
import com.bencodez.votingplugin.placeholders.PlaceholderCacheLevel;
|
||||
@@ -67,6 +68,134 @@ public class Config extends YMLFile {
|
||||
@Getter
|
||||
private boolean preloadSkulls = false;
|
||||
|
||||
@ConfigDataBoolean(path = "DiscordSRV.Enabled")
|
||||
@Getter
|
||||
private boolean discordSRVEnabled = false;
|
||||
|
||||
@ConfigDataBoolean(path = "DiscordSRV.TopVoter.AllTime.Enabled")
|
||||
@Getter
|
||||
private boolean discordSRVTopVoterAllTimeEnabled = false;
|
||||
|
||||
@ConfigDataLong(path = "DiscordSRV.TopVoter.AllTime.Channel")
|
||||
@Getter
|
||||
private long discordSRVTopVoterAllTimeChannel = 0;
|
||||
|
||||
@ConfigDataString(path = "DiscordSRV.TopVoter.AllTime.Title")
|
||||
@Getter
|
||||
private String discordSRVTopVoterAllTimeTitle = "All Time Top Voters";
|
||||
|
||||
@ConfigDataString(path = "DiscordSRV.TopVoter.AllTime.RankDisplay")
|
||||
@Getter
|
||||
private String discordSRVTopVoterAllTimeRankDisplay = "%rank%: &6%player% - %votes% Votes";
|
||||
|
||||
@ConfigDataBoolean(path = "DiscordSRV.TopVoter.Monthly.Enabled")
|
||||
@Getter
|
||||
private boolean discordSRVTopVoterMonthlyEnabled = false;
|
||||
|
||||
@ConfigDataLong(path = "DiscordSRV.TopVoter.Monthly.Channel")
|
||||
@Getter
|
||||
private long discordSRVTopVoterMonthlyChannel = 0;
|
||||
|
||||
@ConfigDataString(path = "DiscordSRV.TopVoter.Monthly.Title")
|
||||
@Getter
|
||||
private String discordSRVTopVoterMonthlyTitle = "Top Voters of the Month";
|
||||
|
||||
@ConfigDataString(path = "DiscordSRV.TopVoter.Monthly.RankDisplay")
|
||||
@Getter
|
||||
private String discordSRVTopVoterMonthlyRankDisplay = "%rank%: &6%player% - %votes% Votes";
|
||||
|
||||
@ConfigDataBoolean(path = "DiscordSRV.TopVoter.Weekly.Enabled")
|
||||
@Getter
|
||||
private boolean discordSRVTopVoterWeeklyEnabled = false;
|
||||
|
||||
@ConfigDataLong(path = "DiscordSRV.TopVoter.Weekly.Channel")
|
||||
@Getter
|
||||
private long discordSRVTopVoterWeeklyChannel = 0;
|
||||
|
||||
@ConfigDataString(path = "DiscordSRV.TopVoter.Weekly.Title")
|
||||
@Getter
|
||||
private String discordSRVTopVoterWeeklyTitle = "Top Voters of the Week";
|
||||
|
||||
@ConfigDataString(path = "DiscordSRV.TopVoter.Weekly.RankDisplay")
|
||||
@Getter
|
||||
private String discordSRVTopVoterWeeklyRankDisplay = "%rank%: &6%player% - %votes% Votes";
|
||||
|
||||
@ConfigDataBoolean(path = "DiscordSRV.TopVoter.Daily.Enabled")
|
||||
@Getter
|
||||
private boolean discordSRVTopVoterDailyEnabled = false;
|
||||
|
||||
@ConfigDataLong(path = "DiscordSRV.TopVoter.Daily.Channel")
|
||||
@Getter
|
||||
private long discordSRVTopVoterDailyChannel = 0;
|
||||
|
||||
@ConfigDataString(path = "DiscordSRV.TopVoter.Daily.Title")
|
||||
@Getter
|
||||
private String discordSRVTopVoterDailyTitle = "Top Voters of the Day";
|
||||
|
||||
@ConfigDataString(path = "DiscordSRV.TopVoter.Daily.RankDisplay")
|
||||
@Getter
|
||||
private String discordSRVTopVoterDailyRankDisplay = "%rank%: &6%player% - %votes% Votes";
|
||||
|
||||
public boolean isDiscordSRVTopVoterEnabled(TopVoter topVoter) {
|
||||
switch (topVoter) {
|
||||
case AllTime:
|
||||
return isDiscordSRVTopVoterAllTimeEnabled();
|
||||
case Monthly:
|
||||
return isDiscordSRVTopVoterMonthlyEnabled();
|
||||
case Weekly:
|
||||
return isDiscordSRVTopVoterWeeklyEnabled();
|
||||
case Daily:
|
||||
return isDiscordSRVTopVoterDailyEnabled();
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public long getDiscordSRVTopVoterChannel(TopVoter topVoter) {
|
||||
switch (topVoter) {
|
||||
case AllTime:
|
||||
return getDiscordSRVTopVoterAllTimeChannel();
|
||||
case Monthly:
|
||||
return getDiscordSRVTopVoterMonthlyChannel();
|
||||
case Weekly:
|
||||
return getDiscordSRVTopVoterWeeklyChannel();
|
||||
case Daily:
|
||||
return getDiscordSRVTopVoterDailyChannel();
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
public String getDiscordSRVTopVoterTitle(TopVoter topVoter) {
|
||||
switch (topVoter) {
|
||||
case AllTime:
|
||||
return getDiscordSRVTopVoterAllTimeTitle();
|
||||
case Monthly:
|
||||
return getDiscordSRVTopVoterMonthlyTitle();
|
||||
case Weekly:
|
||||
return getDiscordSRVTopVoterWeeklyTitle();
|
||||
case Daily:
|
||||
return getDiscordSRVTopVoterDailyTitle();
|
||||
default:
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
public String getDiscordSRVTopVoterRankDisplay(TopVoter topVoter) {
|
||||
switch (topVoter) {
|
||||
case AllTime:
|
||||
return getDiscordSRVTopVoterAllTimeRankDisplay();
|
||||
case Monthly:
|
||||
return getDiscordSRVTopVoterMonthlyRankDisplay();
|
||||
case Weekly:
|
||||
return getDiscordSRVTopVoterWeeklyRankDisplay();
|
||||
case Daily:
|
||||
return getDiscordSRVTopVoterDailyRankDisplay();
|
||||
default:
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
@ConfigDataBoolean(path = "AllowUnJoinedCheckServer")
|
||||
@Getter
|
||||
private boolean allowUnJoinedCheckServer = true;
|
||||
|
||||
@@ -41,7 +41,7 @@ public class ConfigVoteSites extends YMLFile {
|
||||
public void generateVoteSite(String siteName) {
|
||||
if (plugin.getConfigFile().isAutoCreateVoteSites()) {
|
||||
String org = siteName;
|
||||
siteName = siteName.replace(".", "_");
|
||||
siteName = siteName.replace(".", "_").replace(" ", "_");
|
||||
plugin.getLogger().warning("VoteSite " + siteName + " does not exist with the servicesite '" + org
|
||||
+ "', creating one, set AutoCreateVoteSites to false to prevent this");
|
||||
setEnabled(siteName, true);
|
||||
|
||||
@@ -16,7 +16,7 @@ import org.bukkit.event.Listener;
|
||||
import com.bencodez.advancedcore.api.rewards.RewardOptions;
|
||||
import com.bencodez.advancedcore.api.user.AdvancedCoreUser;
|
||||
import com.bencodez.advancedcore.api.user.UserStartup;
|
||||
import com.bencodez.advancedcore.api.user.userstorage.Column;
|
||||
import com.bencodez.simpleapi.sql.Column;
|
||||
import com.bencodez.votingplugin.VotingPluginMain;
|
||||
import com.bencodez.votingplugin.events.PlayerVoteCoolDownEndEvent;
|
||||
import com.bencodez.votingplugin.events.PlayerVoteSiteCoolDownEndEvent;
|
||||
|
||||
@@ -16,6 +16,7 @@ import com.bencodez.simpleapi.array.ArrayUtils;
|
||||
import com.bencodez.votingplugin.VotingPluginMain;
|
||||
import com.bencodez.votingplugin.signs.SignHandler;
|
||||
import com.bencodez.votingplugin.timequeue.VoteTimeQueue;
|
||||
import com.bencodez.votingplugin.topvoter.TopVoter;
|
||||
|
||||
// TODO: Auto-generated Javadoc
|
||||
/**
|
||||
@@ -244,6 +245,15 @@ public class ServerData {
|
||||
plugin.getServerDataFile().reloadData();
|
||||
}
|
||||
|
||||
public long getTopVoterMessageId(TopVoter top) {
|
||||
return getData().getLong("DiscordSRV.TopVoterMessageId." + top.toString(), 0);
|
||||
}
|
||||
|
||||
public void setTopVoterMessageId(TopVoter top, long messageId) {
|
||||
getData().set("DiscordSRV.TopVoterMessageId." + top.toString(), messageId);
|
||||
saveData();
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes the sign.
|
||||
*
|
||||
|
||||
@@ -0,0 +1,146 @@
|
||||
package com.bencodez.votingplugin.discord;
|
||||
|
||||
import java.awt.Color;
|
||||
import java.time.Instant;
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
|
||||
import com.bencodez.advancedcore.api.messages.PlaceholderUtils;
|
||||
import com.bencodez.advancedcore.api.rewards.Reward;
|
||||
import com.bencodez.advancedcore.api.rewards.injected.RewardInjectConfigurationSection;
|
||||
import com.bencodez.votingplugin.VotingPluginMain;
|
||||
import com.bencodez.votingplugin.topvoter.TopVoter;
|
||||
import com.bencodez.votingplugin.topvoter.TopVoterPlayer;
|
||||
|
||||
import github.scarsz.discordsrv.DiscordSRV;
|
||||
import github.scarsz.discordsrv.api.Subscribe;
|
||||
import github.scarsz.discordsrv.api.events.DiscordReadyEvent;
|
||||
import github.scarsz.discordsrv.dependencies.jda.api.EmbedBuilder;
|
||||
import github.scarsz.discordsrv.dependencies.jda.api.JDA;
|
||||
import github.scarsz.discordsrv.dependencies.jda.api.entities.TextChannel;
|
||||
import github.scarsz.discordsrv.util.DiscordUtil;
|
||||
import lombok.Getter;
|
||||
|
||||
public class DiscordHandler {
|
||||
|
||||
private final VotingPluginMain plugin;
|
||||
@Getter
|
||||
private final HashMap<TopVoter, Long> topVoterMessageIds = new HashMap<TopVoter, Long>();
|
||||
private final AtomicBoolean discordReady = new AtomicBoolean(false);
|
||||
|
||||
public DiscordHandler(VotingPluginMain plugin) {
|
||||
this.plugin = plugin;
|
||||
for (TopVoter top : TopVoter.values()) {
|
||||
long savedId = plugin.getServerData().getTopVoterMessageId(top);
|
||||
topVoterMessageIds.put(top, savedId);
|
||||
}
|
||||
}
|
||||
|
||||
/** Call this early, e.g. from onEnable() in main plugin class */
|
||||
public void load() {
|
||||
DiscordSRV.api.subscribe(this);
|
||||
plugin.getLogger().info("DiscordHandler loaded; awaiting Discord readiness.");
|
||||
|
||||
// if DiscordSRV is already up and running, mark it ready now
|
||||
if (DiscordUtil.getJda().getStatus() == JDA.Status.CONNECTED) {
|
||||
discordReady.set(true);
|
||||
plugin.getLogger().info("DiscordSRV was already ready; manual update now available.");
|
||||
}
|
||||
|
||||
plugin.getRewardHandler().addInjectedReward(new RewardInjectConfigurationSection("DiscordSRV") {
|
||||
|
||||
@Override
|
||||
public String onRewardRequested(Reward arg0, com.bencodez.advancedcore.api.user.AdvancedCoreUser user,
|
||||
ConfigurationSection section, HashMap<String, String> placeholders) {
|
||||
if (section.getBoolean("Enabled")) {
|
||||
String msg = PlaceholderUtils
|
||||
.replacePlaceHolder(section.getString("Message", "Please set a message"), placeholders);
|
||||
msg = PlaceholderUtils.replacePlaceHolders(user.getOfflinePlayer(), msg);
|
||||
sendRewardMessage(msg, section.getString("ChannelID", "0"));
|
||||
}
|
||||
return null;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/** Fired once JDA is fully initialized */
|
||||
@Subscribe
|
||||
public void onDiscordReady(DiscordReadyEvent event) {
|
||||
discordReady.set(true);
|
||||
plugin.getLogger().info("DiscordSRV is ready; manual update now available.");
|
||||
}
|
||||
|
||||
/**
|
||||
* Public method to update the Top Voter message on demand. Checks Discord
|
||||
* readiness internally.
|
||||
*/
|
||||
public void updateDiscordLeaderboard() {
|
||||
if (!discordReady.get()) {
|
||||
plugin.getLogger().warning("DiscordSRV not ready yet; cannot update Top Voters.");
|
||||
return;
|
||||
}
|
||||
|
||||
for (TopVoter top : TopVoter.values()) {
|
||||
if (plugin.getConfigFile().isDiscordSRVTopVoterEnabled(top)) {
|
||||
plugin.debug("Updating Discord Top Voter: " + top.toString());
|
||||
updateTopVoterMessageId(top);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void updateTopVoterMessageId(TopVoter top) {
|
||||
long channelId = plugin.getConfigFile().getDiscordSRVTopVoterChannel(top);
|
||||
LinkedHashMap<TopVoterPlayer, Integer> topVoters = plugin.getTopVoter(top);
|
||||
|
||||
String title = plugin.getConfigFile().getDiscordSRVTopVoterTitle(top);
|
||||
String rankDisplay = plugin.getConfigFile().getDiscordSRVTopVoterRankDisplay(top);
|
||||
|
||||
EmbedBuilder eb = new EmbedBuilder().setTitle(title).setColor(Color.CYAN).setTimestamp(Instant.now());
|
||||
|
||||
int rank = 1;
|
||||
for (Entry<TopVoterPlayer, Integer> entry : topVoters.entrySet()) {
|
||||
if (rank > 10)
|
||||
break;
|
||||
String line = rankDisplay.replace("%rank%", String.valueOf(rank))
|
||||
.replace("%player%", entry.getKey().getPlayerName())
|
||||
.replace("%votes%", String.valueOf(entry.getValue()));
|
||||
eb.addField("", line, false);
|
||||
rank++;
|
||||
}
|
||||
|
||||
TextChannel channel = DiscordUtil.getJda().getTextChannelById(channelId);
|
||||
if (channel == null) {
|
||||
plugin.getLogger().warning("Discord channel ID " + channelId + " not found: " + top.toString());
|
||||
return;
|
||||
}
|
||||
|
||||
if (topVoterMessageIds.get(top) <= 0) {
|
||||
channel.sendMessageEmbeds(eb.build()).queue(msg -> {
|
||||
long newId = msg.getIdLong();
|
||||
topVoterMessageIds.put(top, newId);
|
||||
plugin.getServerData().setTopVoterMessageId(top, newId);
|
||||
plugin.getLogger().info("Posted new Top Voters " + top.toString() + " (ID: " + newId + ")");
|
||||
}, err -> plugin.getLogger()
|
||||
.warning("Error sending Top Voters " + top.toString() + ": " + err.getMessage()));
|
||||
} else {
|
||||
channel.editMessageEmbedsById(topVoterMessageIds.get(top), eb.build())
|
||||
.queue(m -> plugin.getLogger()
|
||||
.info("Edited Top Voters " + top.toString() + " (ID: " + topVoterMessageIds.get(top) + ")"),
|
||||
err -> plugin.getLogger()
|
||||
.warning("Error editing Top Voters" + top.toString() + ": " + err.getMessage()));
|
||||
}
|
||||
}
|
||||
|
||||
public void sendRewardMessage(String message, String channelId) {
|
||||
TextChannel channel = DiscordUtil.getJda().getTextChannelById(channelId);
|
||||
if (channel != null) {
|
||||
channel.sendMessage(message).queue();
|
||||
} else {
|
||||
plugin.getLogger().warning("Discord channel ID " + channelId + " not found for reward message.");
|
||||
}
|
||||
}
|
||||
}
|
||||
+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,6 @@ 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.user.VotingPluginUser;
|
||||
|
||||
// TODO: Auto-generated Javadoc
|
||||
@@ -50,9 +49,7 @@ public class PlayerJoinEvent implements Listener {
|
||||
|
||||
plugin.getPlaceholders().onUpdate(user, true);
|
||||
|
||||
if (plugin.getBungeeSettings().isUseBungeecoord()
|
||||
&& (plugin.getBungeeHandler().getMethod().equals(BungeeMethod.PLUGINMESSAGING)
|
||||
|| plugin.getBungeeHandler().getMethod().equals(BungeeMethod.REDIS))) {
|
||||
if (plugin.getBungeeSettings().isUseBungeecoord()) {
|
||||
plugin.getBungeeHandler().getGlobalMessageHandler().sendMessage("Login", user.getPlayerName(),
|
||||
user.getUUID(), plugin.getBungeeSettings().getServer());
|
||||
}
|
||||
@@ -76,14 +73,14 @@ public class PlayerJoinEvent implements Listener {
|
||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||
public void onPlayerQuit(PlayerQuitEvent event) {
|
||||
if (plugin != null && plugin.isEnabled()) {
|
||||
final java.util.UUID uuid = event.getPlayer().getUniqueId();
|
||||
final Player player = event.getPlayer();
|
||||
plugin.getLoginTimer().execute(new Runnable() {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
VotingPluginMain.plugin.getAdvancedTab().remove(uuid);
|
||||
VotingPluginMain.plugin.getAdvancedTab().remove(player.getUniqueId());
|
||||
|
||||
VotingPluginUser user = plugin.getVotingPluginUserManager().getVotingPluginUser(uuid);
|
||||
VotingPluginUser user = plugin.getVotingPluginUserManager().getVotingPluginUser(player);
|
||||
user.dontCache();
|
||||
user.logoutRewards();
|
||||
plugin.getPlaceholders().onLogout(user);
|
||||
|
||||
+28
-16
@@ -3,6 +3,7 @@ package com.bencodez.votingplugin.listeners;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.ZoneId;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
@@ -13,7 +14,6 @@ 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;
|
||||
@@ -50,7 +50,25 @@ public class PlayerVoteListener implements Listener {
|
||||
}
|
||||
String playerName = event.getPlayer();
|
||||
plugin.debug("Processing PlayerVoteEvent: " + playerName + "/" + event.getServiceSite());
|
||||
|
||||
boolean notValid = false;
|
||||
if (!PlayerManager.getInstance().isValidUser(playerName, plugin.getConfigFile().isAllowUnJoinedCheckServer())) {
|
||||
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 {
|
||||
notValid = true;
|
||||
}
|
||||
} else {
|
||||
notValid = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (notValid) {
|
||||
if (!plugin.getConfigFile().isAllowUnjoined()) {
|
||||
plugin.getLogger().warning("Player " + playerName
|
||||
+ " has not joined before, disregarding vote, set AllowUnjoined to true to prevent this");
|
||||
@@ -109,6 +127,15 @@ public class PlayerVoteListener implements Listener {
|
||||
// player online
|
||||
user = plugin.getVotingPluginUserManager().getVotingPluginUser(p);
|
||||
} else {
|
||||
// attempt to get exact name from cache matching casing
|
||||
if (!plugin.getOptions().isOnlineMode()) {
|
||||
for (Entry<String, String> entry : plugin.getUuidNameCache().entrySet()) {
|
||||
if (entry.getValue().equalsIgnoreCase(playerName)) {
|
||||
playerName = entry.getValue();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
user = plugin.getVotingPluginUserManager().getVotingPluginUser(playerName);
|
||||
}
|
||||
}
|
||||
@@ -240,21 +267,6 @@ public class PlayerVoteListener implements Listener {
|
||||
plugin.getSpecialRewards().checkMilestone(user, event.getBungeeTextTotals(), event.isForceBungee());
|
||||
plugin.getCoolDownCheck().vote(user, voteSite);
|
||||
|
||||
if (plugin.getBungeeSettings().isUseBungeecoord()) {
|
||||
if (plugin.getBungeeHandler().getMethod().equals(BungeeMethod.MYSQL)) {
|
||||
|
||||
plugin.getBukkitScheduler().runTaskLaterAsynchronously(plugin, new Runnable() {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
if (Bukkit.getOnlinePlayers().size() > 0) {
|
||||
plugin.getBungeeHandler().getGlobalMessageHandler().sendMessage("VoteUpdate", uuid);
|
||||
}
|
||||
}
|
||||
}, 2);
|
||||
}
|
||||
}
|
||||
|
||||
PlayerPostVoteEvent postVoteEvent = new PlayerPostVoteEvent(voteSite, user, event.isRealVote(),
|
||||
event.isForceBungee(), voteTime);
|
||||
plugin.getServer().getPluginManager().callEvent(postVoteEvent);
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -72,9 +72,11 @@ public class VotiferEvent implements Listener {
|
||||
plugin.getServerData().addServiceSite(voteSite);
|
||||
if (plugin.getBungeeSettings().isUseBungeecoord() && !plugin.getBungeeSettings().isVotifierBypass()
|
||||
&& (plugin.getBungeeHandler().getMethod().equals(BungeeMethod.PLUGINMESSAGING)
|
||||
|| plugin.getBungeeHandler().getMethod().equals(BungeeMethod.SOCKETS))) {
|
||||
|| plugin.getBungeeHandler().getMethod().equals(BungeeMethod.SOCKETS)
|
||||
|| plugin.getBungeeHandler().getMethod().equals(BungeeMethod.MQTT)
|
||||
|| plugin.getBungeeHandler().getMethod().equals(BungeeMethod.REDIS))) {
|
||||
plugin.getLogger().severe(
|
||||
"Ignoring vote from votifier since pluginmessaging or socket bungee method is enabled, this means you aren't setup correctly for those methods, please check: https://github.com/BenCodez/VotingPlugin/wiki/Bungeecord-Setups");
|
||||
"Ignoring vote from votifier since pluginmessaging, socket, redis, or mqtt bungee method is enabled, this means you aren't setup correctly for those methods, please check: https://github.com/BenCodez/VotingPlugin/wiki/Bungeecord-Setups");
|
||||
return;
|
||||
}
|
||||
String matchSite = "";
|
||||
|
||||
@@ -16,7 +16,6 @@ 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.user.VotingPluginUser;
|
||||
|
||||
import lombok.Getter;
|
||||
@@ -118,17 +117,9 @@ public class VoteSite {
|
||||
}
|
||||
if (checkBungee && plugin.getBungeeSettings().isBungeeBroadcast()
|
||||
&& plugin.getBungeeSettings().isUseBungeecoord()) {
|
||||
if (plugin.getBungeeHandler().getMethod().equals(BungeeMethod.SOCKETS)) {
|
||||
plugin.getBungeeHandler().sendData("Broadcast", getServiceSite(), user.getPlayerName());
|
||||
} else if (plugin.getBungeeHandler().getMethod().equals(BungeeMethod.MYSQL)
|
||||
|| plugin.getBungeeHandler().getMethod().equals(BungeeMethod.PLUGINMESSAGING)) {
|
||||
String uuid = user.getUUID();
|
||||
String service = getServiceSite();
|
||||
|
||||
if (Bukkit.getOnlinePlayers().size() > 0) {
|
||||
plugin.getPluginMessaging().sendPluginMessage("VoteBroadcast", uuid, service);
|
||||
}
|
||||
}
|
||||
String uuid = user.getUUID();
|
||||
String service = getServiceSite();
|
||||
plugin.getBungeeHandler().getGlobalMessageHandler().sendMessage("VoteBroadcast", uuid, service);
|
||||
|
||||
} else {
|
||||
String bc = MessageAPI.colorize(plugin.getConfigFile().getFormatBroadCastMsg());
|
||||
|
||||
+21
-10
@@ -180,6 +180,8 @@ public class PlaceHolders {
|
||||
}
|
||||
}
|
||||
|
||||
UUID uuid = user.getJavaUUID();
|
||||
|
||||
for (PlaceHolder<VotingPluginUser> placeholder : placeholders) {
|
||||
try {
|
||||
if (placeholder.matches(identifier)) {
|
||||
@@ -190,11 +192,11 @@ public class PlaceHolders {
|
||||
CalculatingPlaceholder<VotingPluginUser> cPlaceholder = (CalculatingPlaceholder<VotingPluginUser>) placeholder;
|
||||
if (placeholder.isUsesCache() && placeholder.isCached(identifier)) {
|
||||
ConcurrentHashMap<UUID, String> cache = placeholder.getCache().get(identifier);
|
||||
if (cache.containsKey(p.getUniqueId())) {
|
||||
if (cPlaceholder.getCacheData().containsKey(user.getJavaUUID())) {
|
||||
if (cache.containsKey(uuid)) {
|
||||
if (cPlaceholder.getCacheData().containsKey(uuid)) {
|
||||
return cPlaceholder.placeholderRequest(user, identifier);
|
||||
}
|
||||
return cache.get(p.getUniqueId());
|
||||
return cache.get(uuid);
|
||||
} else if (!forceProcess) {
|
||||
schedulePlaceholderCheck(user);
|
||||
return "...";
|
||||
@@ -226,8 +228,9 @@ public class PlaceHolders {
|
||||
}
|
||||
if (placeholder.isUsesCache() && placeholder.isCached(identifier)) {
|
||||
ConcurrentHashMap<UUID, String> cache = placeholder.getCache().get(identifier);
|
||||
if (cache.containsKey(p.getUniqueId())) {
|
||||
return cache.get(p.getUniqueId());
|
||||
|
||||
if (cache.containsKey(uuid)) {
|
||||
return cache.get(uuid);
|
||||
} else if (!forceProcess) {
|
||||
schedulePlaceholderCheck(user);
|
||||
return "...";
|
||||
@@ -541,6 +544,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 +653,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 +669,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 +741,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 +792,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 +843,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;
|
||||
|
||||
+6
-2
@@ -1,7 +1,11 @@
|
||||
package com.bencodez.votingplugin.bungee;
|
||||
package com.bencodez.votingplugin.proxy;
|
||||
|
||||
public enum BungeeMethod {
|
||||
MYSQL, PLUGINMESSAGING, SOCKETS, REDIS;
|
||||
MYSQL, PLUGINMESSAGING, SOCKETS, REDIS, MQTT;
|
||||
|
||||
public boolean requiresPlayerOnline() {
|
||||
return this == PLUGINMESSAGING;
|
||||
}
|
||||
|
||||
public static BungeeMethod getByName(String str) {
|
||||
for (BungeeMethod method : values()) {
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
package com.bencodez.votingplugin.bungee;
|
||||
package com.bencodez.votingplugin.proxy;
|
||||
|
||||
public class BungeeVersion {
|
||||
public static int getPluginMessageVersion() {
|
||||
+3
-1
@@ -1,6 +1,7 @@
|
||||
package com.bencodez.votingplugin.bungee;
|
||||
package com.bencodez.votingplugin.proxy;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
public class OfflineBungeeVote {
|
||||
|
||||
@@ -11,6 +12,7 @@ public class OfflineBungeeVote {
|
||||
@Getter
|
||||
private String service;
|
||||
@Getter
|
||||
@Setter
|
||||
private String text;
|
||||
@Getter
|
||||
private long time;
|
||||
@@ -0,0 +1,549 @@
|
||||
package com.bencodez.votingplugin.proxy;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
import com.bencodez.simpleapi.sql.Column;
|
||||
import com.bencodez.simpleapi.sql.DataType;
|
||||
import com.bencodez.simpleapi.sql.data.DataValue;
|
||||
import com.bencodez.simpleapi.sql.data.DataValueInt;
|
||||
import com.bencodez.simpleapi.sql.data.DataValueString;
|
||||
import com.bencodez.simpleapi.sql.mysql.config.MysqlConfig;
|
||||
import com.bencodez.simpleapi.sql.mysql.queries.Query;
|
||||
|
||||
import lombok.Getter;
|
||||
|
||||
public abstract class ProxyMysqlUserTable {
|
||||
private List<String> columns = Collections.synchronizedList(new ArrayList<String>());
|
||||
|
||||
private List<String> intColumns = new ArrayList<>();
|
||||
|
||||
// private HashMap<String, ArrayList<Column>> table;
|
||||
|
||||
// ConcurrentMap<String, ArrayList<Column>> table = new
|
||||
// ConcurrentHashMap<String, ArrayList<Column>>();
|
||||
|
||||
@Getter
|
||||
private com.bencodez.simpleapi.sql.mysql.MySQL mysql;
|
||||
|
||||
private String name;
|
||||
|
||||
private Object object2 = new Object();
|
||||
|
||||
private Object object3 = new Object();
|
||||
|
||||
private Object object4 = new Object();
|
||||
|
||||
private Set<String> uuids = Collections.synchronizedSet(new HashSet<String>());
|
||||
|
||||
public abstract void logSevere(String string);
|
||||
|
||||
public abstract void logInfo(String string);
|
||||
|
||||
public ProxyMysqlUserTable(String tableName, MysqlConfig config, boolean debug) {
|
||||
|
||||
if (config.hasTableNameSet()) {
|
||||
tableName = config.getTableName();
|
||||
}
|
||||
name = tableName;
|
||||
if (config.getTablePrefix() != null) {
|
||||
name = config.getTablePrefix() + tableName;
|
||||
}
|
||||
mysql = new com.bencodez.simpleapi.sql.mysql.MySQL(config.getMaxThreads()) {
|
||||
|
||||
@Override
|
||||
public void debug(SQLException e) {
|
||||
if (debug) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void severe(String string) {
|
||||
logSevere(string);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void debug(String msg) {
|
||||
if (debug) {
|
||||
logInfo("MYSQL DEBUG: " + msg);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
if (!mysql.connect(config)) {
|
||||
|
||||
}
|
||||
try {
|
||||
Query q = new Query(mysql, "USE `" + config.getDatabase() + "`;");
|
||||
q.executeUpdateAsync();
|
||||
} catch (SQLException e) {
|
||||
severe("Failed to send use database query: " + config.getDatabase() + " Error: " + e.getMessage());
|
||||
debug(e);
|
||||
}
|
||||
String sql = "CREATE TABLE IF NOT EXISTS " + getName() + " (";
|
||||
sql += "uuid VARCHAR(37),";
|
||||
sql += "PRIMARY KEY ( uuid )";
|
||||
sql += ");";
|
||||
Query query;
|
||||
try {
|
||||
query = new Query(mysql, sql);
|
||||
|
||||
query.executeUpdate();
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
loadData();
|
||||
|
||||
// tempoary to improve performance from old tables
|
||||
// addToQue("ALTER TABLE " + getName() + " MODIFY uuid VARCHAR(37);");
|
||||
alterColumnType("uuid", "VARCHAR(37)");
|
||||
}
|
||||
|
||||
public void addColumn(String column, DataType dataType) {
|
||||
synchronized (object3) {
|
||||
String sql = "ALTER TABLE " + getName() + " ADD COLUMN `" + column + "` text" + ";";
|
||||
try {
|
||||
Query query = new Query(mysql, sql);
|
||||
query.executeUpdate();
|
||||
|
||||
getColumns().add(column);
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public void alterColumnType(String column, String newType) {
|
||||
checkColumn(column, DataType.STRING);
|
||||
|
||||
try {
|
||||
new Query(mysql, "ALTER TABLE " + getName() + " MODIFY `" + column + "` " + newType + ";")
|
||||
.executeUpdateAsync();
|
||||
} catch (SQLException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
if (newType.contains("INT")) {
|
||||
if (!intColumns.contains(column)) {
|
||||
intColumns.add(column);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void checkColumn(String column, DataType dataType) {
|
||||
synchronized (object4) {
|
||||
if (!getColumns().contains(column)) {
|
||||
if (!getColumnsQueury().contains(column)) {
|
||||
addColumn(column, dataType);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void clearCache() {
|
||||
clearCacheBasic();
|
||||
}
|
||||
|
||||
public void clearCacheBasic() {
|
||||
columns.clear();
|
||||
columns.addAll(getColumnsQueury());
|
||||
uuids.clear();
|
||||
uuids.addAll(getUuidsQuery());
|
||||
}
|
||||
|
||||
public void close() {
|
||||
mysql.disconnect();
|
||||
}
|
||||
|
||||
public boolean containsKeyQuery(String index) {
|
||||
String sqlStr = "SELECT uuid FROM " + getName() + ";";
|
||||
try (Connection conn = mysql.getConnectionManager().getConnection();
|
||||
PreparedStatement sql = conn.prepareStatement(sqlStr)) {
|
||||
ResultSet rs = sql.executeQuery();
|
||||
/*
|
||||
* Query query = new Query(mysql, sql); ResultSet rs = query.executeQuery();
|
||||
*/
|
||||
while (rs.next()) {
|
||||
if (rs.getString("uuid").equals(index)) {
|
||||
rs.close();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
rs.close();
|
||||
} catch (SQLException ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public void copyColumnData(String columnFromName, String columnToName) {
|
||||
checkColumn(columnFromName, DataType.STRING);
|
||||
checkColumn(columnToName, DataType.STRING);
|
||||
String sql = "UPDATE `" + getName() + "` SET `" + columnToName + "` = `" + columnFromName + "`;";
|
||||
try {
|
||||
Query query = new Query(mysql, sql);
|
||||
query.executeUpdate();
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public abstract void debug(SQLException e);
|
||||
|
||||
public List<String> getColumns() {
|
||||
if (columns == null || columns.size() == 0) {
|
||||
loadData();
|
||||
}
|
||||
return columns;
|
||||
}
|
||||
|
||||
public ArrayList<String> getColumnsQueury() {
|
||||
ArrayList<String> columns = new ArrayList<>();
|
||||
try (Connection conn = mysql.getConnectionManager().getConnection();
|
||||
PreparedStatement sql = conn.prepareStatement("SHOW COLUMNS FROM `" + getName() + "`;")) {
|
||||
ResultSet rs = sql.executeQuery();
|
||||
|
||||
while (rs.next()) {
|
||||
String columnName = rs.getString(1);
|
||||
columns.add(columnName);
|
||||
|
||||
}
|
||||
|
||||
rs.close();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return columns;
|
||||
}
|
||||
|
||||
public ArrayList<Column> getExactQuery(Column column) {
|
||||
ArrayList<Column> result = new ArrayList<>();
|
||||
String query = "SELECT * FROM " + getName() + " WHERE `" + column.getName() + "`='"
|
||||
+ column.getValue().getString() + "';";
|
||||
|
||||
try (Connection conn = mysql.getConnectionManager().getConnection();
|
||||
PreparedStatement sql = conn.prepareStatement(query)) {
|
||||
ResultSet rs = sql.executeQuery();
|
||||
|
||||
/*
|
||||
* Query sql = new Query(mysql, query); sql.setParameter(1,
|
||||
* column.getValue().toString()); ResultSet rs = sql.executeQuery();
|
||||
*/
|
||||
if (rs.next()) {
|
||||
for (int i = 1; i <= rs.getMetaData().getColumnCount(); i++) {
|
||||
String columnName = rs.getMetaData().getColumnLabel(i);
|
||||
Column rCol = null;
|
||||
if (intColumns.contains(columnName)) {
|
||||
rCol = new Column(columnName, DataType.INTEGER);
|
||||
rCol.setValue(new DataValueInt(rs.getInt(i)));
|
||||
} else {
|
||||
rCol = new Column(columnName, DataType.STRING);
|
||||
rCol.setValue(new DataValueString(rs.getString(i)));
|
||||
}
|
||||
result.add(rCol);
|
||||
}
|
||||
}
|
||||
rs.close();
|
||||
return result;
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
} catch (ArrayIndexOutOfBoundsException e) {
|
||||
}
|
||||
|
||||
for (String col : getColumns()) {
|
||||
result.add(new Column(col, DataType.STRING));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public ArrayList<String> getNamesQuery() {
|
||||
ArrayList<String> uuids = new ArrayList<>();
|
||||
|
||||
checkColumn("PlayerName", DataType.STRING);
|
||||
ArrayList<Column> rows = getRowsNameQuery();
|
||||
if (rows != null) {
|
||||
for (Column c : rows) {
|
||||
if (c.getValue().isString()) {
|
||||
uuids.add(c.getValue().getString());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return uuids;
|
||||
}
|
||||
|
||||
public ArrayList<Column> getRowsNameQuery() {
|
||||
ArrayList<Column> result = new ArrayList<>();
|
||||
String sqlStr = "SELECT PlayerName FROM " + getName() + ";";
|
||||
|
||||
try (Connection conn = mysql.getConnectionManager().getConnection();
|
||||
PreparedStatement sql = conn.prepareStatement(sqlStr)) {
|
||||
ResultSet rs = sql.executeQuery();
|
||||
/*
|
||||
* Query query = new Query(mysql, sql); ResultSet rs = query.executeQuery();
|
||||
*/
|
||||
|
||||
while (rs.next()) {
|
||||
Column rCol = new Column("PlayerName", new DataValueString(rs.getString("PlayerName")));
|
||||
result.add(rCol);
|
||||
}
|
||||
sql.close();
|
||||
conn.close();
|
||||
} catch (SQLException e) {
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public ArrayList<Column> getRowsQuery() {
|
||||
ArrayList<Column> result = new ArrayList<>();
|
||||
String sqlStr = "SELECT uuid FROM " + getName() + ";";
|
||||
|
||||
try (Connection conn = mysql.getConnectionManager().getConnection();
|
||||
PreparedStatement sql = conn.prepareStatement(sqlStr)) {
|
||||
ResultSet rs = sql.executeQuery();
|
||||
/*
|
||||
* Query query = new Query(mysql, sql); ResultSet rs = query.executeQuery();
|
||||
*/
|
||||
|
||||
while (rs.next()) {
|
||||
Column rCol = new Column("uuid", new DataValueString(rs.getString("uuid")));
|
||||
result.add(rCol);
|
||||
}
|
||||
rs.close();
|
||||
} catch (SQLException e) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public ConcurrentHashMap<UUID, String> getRowsUUIDNameQuery() {
|
||||
ConcurrentHashMap<UUID, String> uuidNames = new ConcurrentHashMap<>();
|
||||
String sqlStr = "SELECT UUID, PlayerName FROM " + getName() + ";";
|
||||
|
||||
try (Connection conn = mysql.getConnectionManager().getConnection();
|
||||
PreparedStatement sql = conn.prepareStatement(sqlStr)) {
|
||||
ResultSet rs = sql.executeQuery();
|
||||
/*
|
||||
* Query query = new Query(mysql, sql); ResultSet rs = query.executeQuery();
|
||||
*/
|
||||
|
||||
while (rs.next()) {
|
||||
String uuid = rs.getString("uuid");
|
||||
String playerName = rs.getString("PlayerName");
|
||||
if (uuid != null && !uuid.isEmpty() && !uuid.equals("null") && playerName != null) {
|
||||
uuidNames.put(UUID.fromString(uuid), playerName);
|
||||
}
|
||||
}
|
||||
sql.close();
|
||||
conn.close();
|
||||
} catch (SQLException e) {
|
||||
}
|
||||
|
||||
return uuidNames;
|
||||
}
|
||||
|
||||
public String getUUID(String playerName) {
|
||||
String query = "SELECT uuid FROM " + getName() + " WHERE " + "PlayerName" + "='" + playerName + "';";
|
||||
try (Connection conn = mysql.getConnectionManager().getConnection();
|
||||
PreparedStatement sql = conn.prepareStatement(query)) {
|
||||
ResultSet rs = sql.executeQuery();
|
||||
/*
|
||||
* Query sql = new Query(mysql, query); ResultSet rs = sql.executeQuery();
|
||||
*/
|
||||
if (rs.next()) {
|
||||
String uuid = rs.getString("uuid");
|
||||
if (uuid != null && !uuid.isEmpty()) {
|
||||
rs.close();
|
||||
return uuid;
|
||||
}
|
||||
}
|
||||
rs.close();
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
} catch (ArrayIndexOutOfBoundsException e) {
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public Set<String> getUuids() {
|
||||
if (uuids == null || uuids.size() == 0) {
|
||||
uuids.clear();
|
||||
uuids.addAll(getUuidsQuery());
|
||||
return uuids;
|
||||
}
|
||||
return uuids;
|
||||
}
|
||||
|
||||
public ArrayList<String> getUuidsQuery() {
|
||||
ArrayList<String> uuids = new ArrayList<>();
|
||||
|
||||
ArrayList<Column> rows = getRowsQuery();
|
||||
for (Column c : rows) {
|
||||
if (c.getValue().isString()) {
|
||||
uuids.add(c.getValue().getString());
|
||||
}
|
||||
}
|
||||
|
||||
return uuids;
|
||||
}
|
||||
|
||||
public void insert(String index, String column, DataValue value) {
|
||||
insertQuery(index, Arrays.asList(new Column(column, value)));
|
||||
}
|
||||
|
||||
public void insertQuery(String index, List<Column> cols) {
|
||||
String query = "INSERT IGNORE " + getName() + " ";
|
||||
|
||||
query += "set uuid='" + index + "', ";
|
||||
|
||||
for (int i = 0; i < cols.size(); i++) {
|
||||
Column col = cols.get(i);
|
||||
if (i == cols.size() - 1) {
|
||||
if (col.getValue().isString()) {
|
||||
query += "`" + col.getName() + "`='" + col.getValue().getString() + "';";
|
||||
} else if (col.getValue().isBoolean()) {
|
||||
query += "`" + col.getName() + "`='" + col.getValue().getBoolean() + "';";
|
||||
} else if (col.getValue().isInt()) {
|
||||
query += "`" + col.getName() + "`='" + col.getValue().getInt() + "';";
|
||||
}
|
||||
} else {
|
||||
if (col.getValue().isString()) {
|
||||
query += "`" + col.getName() + "`='" + col.getValue().getString() + "', ";
|
||||
} else if (col.getValue().isBoolean()) {
|
||||
query += "`" + col.getName() + "`='" + col.getValue().getBoolean() + "', ";
|
||||
} else if (col.getValue().isInt()) {
|
||||
query += "`" + col.getName() + "`='" + col.getValue().getInt() + "', ";
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
try {
|
||||
uuids.add(index);
|
||||
new Query(mysql, query).executeUpdateAsync();
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public boolean isIntColumn(String key) {
|
||||
return intColumns.contains(key);
|
||||
}
|
||||
|
||||
public void loadData() {
|
||||
columns = getColumnsQueury();
|
||||
}
|
||||
|
||||
public abstract void severe(String str);
|
||||
|
||||
public void shutdown() {
|
||||
mysql.disconnect();
|
||||
}
|
||||
|
||||
public void update(String index, List<Column> cols) {
|
||||
for (Column col : cols) {
|
||||
checkColumn(col.getName(), col.getDataType());
|
||||
}
|
||||
if (getUuids().contains(index)) {
|
||||
synchronized (object2) {
|
||||
|
||||
String query = "UPDATE " + getName() + " SET ";
|
||||
|
||||
for (int i = 0; i < cols.size(); i++) {
|
||||
Column col = cols.get(i);
|
||||
if (i == cols.size() - 1) {
|
||||
if (col.getValue().isString()) {
|
||||
query += "`" + col.getName() + "`='" + col.getValue().getString() + "'";
|
||||
} else if (col.getValue().isBoolean()) {
|
||||
query += "`" + col.getName() + "`='" + col.getValue().getBoolean() + "'";
|
||||
} else if (col.getValue().isInt()) {
|
||||
query += "`" + col.getName() + "`='" + col.getValue().getInt() + "'";
|
||||
}
|
||||
} else {
|
||||
if (col.getValue().isString()) {
|
||||
query += "`" + col.getName() + "`='" + col.getValue().getString() + "', ";
|
||||
} else if (col.getValue().isBoolean()) {
|
||||
query += "`" + col.getName() + "`='" + col.getValue().getBoolean() + "', ";
|
||||
} else if (col.getValue().isInt()) {
|
||||
query += "`" + col.getName() + "`='" + col.getValue().getInt() + "', ";
|
||||
}
|
||||
}
|
||||
}
|
||||
query += " WHERE `uuid`=";
|
||||
query += "'" + index + "';";
|
||||
|
||||
try {
|
||||
Query q = new Query(mysql, query);
|
||||
q.executeUpdateAsync();
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
} else {
|
||||
insertQuery(index, cols);
|
||||
}
|
||||
}
|
||||
|
||||
public void update(String index, String column, DataValue value) {
|
||||
checkColumn(column, value.getType());
|
||||
if (getUuids().contains(index)) {
|
||||
synchronized (object2) {
|
||||
String query = "UPDATE " + getName() + " SET ";
|
||||
|
||||
if (value.isString()) {
|
||||
query += column + "='" + value.getString() + "'";
|
||||
} else if (value.isBoolean()) {
|
||||
query += column + "='" + value.getBoolean() + "'";
|
||||
} else if (value.isInt()) {
|
||||
query += column + "='" + value.getInt() + "'";
|
||||
}
|
||||
query += " WHERE `uuid`=";
|
||||
query += "'" + index + "';";
|
||||
|
||||
try {
|
||||
Query q = new Query(mysql, query);
|
||||
q.executeUpdate();
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
} else {
|
||||
insert(index, column, value);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void wipeColumnData(String columnName, DataType dataType) {
|
||||
checkColumn(columnName, dataType);
|
||||
String sql = "UPDATE " + getName() + " SET " + columnName + " = " + dataType.getNoValue() + ";";
|
||||
try {
|
||||
Query query = new Query(mysql, sql);
|
||||
query.executeUpdate();
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
+493
-262
File diff suppressed because it is too large.
Load diff
+2
-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;
|
||||
@@ -71,6 +70,7 @@ public class VotingPluginProxyCommand {
|
||||
return "&aChecking status via sockets. Check console for details.";
|
||||
|
||||
case PLUGINMESSAGING:
|
||||
case MYSQL:
|
||||
case REDIS:
|
||||
plugin.status();
|
||||
plugin.sendServerNameMessage();
|
||||
+25
-1
@@ -1,4 +1,4 @@
|
||||
package com.bencodez.votingplugin.bungee.proxy;
|
||||
package com.bencodez.votingplugin.proxy;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
@@ -28,6 +28,16 @@ public interface VotingPluginProxyConfig {
|
||||
|
||||
public boolean getDebug();
|
||||
|
||||
public String getMqttClientID();
|
||||
|
||||
public String getMqttBrokerURL();
|
||||
|
||||
public String getMqttUsername();
|
||||
|
||||
public String getMqttPassword();
|
||||
|
||||
public String getMqttPrefix();
|
||||
|
||||
public String getFallBack();
|
||||
|
||||
public boolean getGlobalDataEnabled();
|
||||
@@ -120,6 +130,20 @@ public interface VotingPluginProxyConfig {
|
||||
|
||||
public List<String> getWhiteListedServers();
|
||||
|
||||
public Collection<String> getWaitUntilVoteDelaySites();
|
||||
|
||||
public String getWaitUntilVoteDelayService(String site);
|
||||
|
||||
public int getWaitUntilVoteDelayVoteDelay(String site);
|
||||
|
||||
public int getWaitUntilVoteDelayVoteDelayMin(String site);
|
||||
|
||||
public boolean getResetMilestonesMonthly();
|
||||
|
||||
public int getWaitUntilVoteDelayVoteDelayHour(String site);
|
||||
|
||||
public boolean getWaitUntilVoteDelayVoteDelayDaily(String site);
|
||||
|
||||
public void load();
|
||||
|
||||
public void save();
|
||||
+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;
|
||||
+118
-3
@@ -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;
|
||||
@@ -33,226 +33,306 @@ public class Config implements VotingPluginProxyConfig {
|
||||
return map;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean getAllowUnJoined() {
|
||||
return getData().getBoolean("AllowUnJoined", false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getBedrockPlayerPrefix() {
|
||||
return getData().getString("BedrockPlayerPrefix", ".");
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getBlockedServers() {
|
||||
return getData().getStringList("BlockedServers");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean getBroadcast() {
|
||||
return getData().getBoolean("Broadcast", false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getBungeeHost() {
|
||||
return getData().getString("BungeeServer.Host", "");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean getBungeeManageTotals() {
|
||||
return getData().getBoolean("BungeeManageTotals", true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getBungeeMethod() {
|
||||
return getData().getString("BungeeMethod", "SOCKETS");
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getBungeePort() {
|
||||
return getData().getInt("BungeeServer.Port", 1297);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean getDebug() {
|
||||
return getData().getBoolean("Debug", false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getFallBack() {
|
||||
return getData().getString("FallBackServer", "");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean getGlobalDataEnabled() {
|
||||
return getData().getBoolean("GlobalData.Enabled", false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean getGlobalDataUseMainMySQL() {
|
||||
return getData().getBoolean("GlobalData.UseMainMySQL", true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getLimitVotePoints() {
|
||||
return getData().getInt("LimitVotePoints", -1);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMaxAmountOfVotesPerDay() {
|
||||
return getData().getInt("MaxAmountOfVotesPerDay", -1);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getMultiProxyMethod() {
|
||||
return getData().getString("MultiProxyMethod", "SOCKET");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean getMultiProxyOneGlobalReward() {
|
||||
return getData().getBoolean("MultiProxyOneGlobalReward", false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getMultiProxyRedisHost() {
|
||||
return getData().getString("MultiProxyRedis.Host", "");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getMultiProxyRedisPassword() {
|
||||
return getData().getString("MultiProxyRedis.Password", "");
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMultiProxyRedisPort() {
|
||||
return getData().getInt("MultiProxyRedis.Port", 6379);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean getMultiProxyRedisUseExistingConnection() {
|
||||
return getData().getBoolean("MultiProxyRedis.UseExistingConnection", false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getMultiProxyRedisUsername() {
|
||||
return getData().getString("MultiProxyRedis.Username", "");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<String> getMultiProxyServers() {
|
||||
return getData().getSection("MultiProxyServers").getKeys();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Object> getMultiProxyServersConfiguration(String s) {
|
||||
return configToMap(getData().getSection("MultiProxyServers." + s));
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getMultiProxySocketHostHost() {
|
||||
return getData().getString("MultiProxySocketHost.Host", "");
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMultiProxySocketHostPort() {
|
||||
return getData().getInt("MultiProxySocketHost.Port", 1297);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean getMultiProxySupport() {
|
||||
return getData().getBoolean("MultiProxySupport", false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean getOnlineMode() {
|
||||
return getData().getBoolean("OnlineMode", true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getPointsOnVote() {
|
||||
return getData().getInt("PointsOnVote", 1);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean getPrimaryServer() {
|
||||
return getData().getBoolean("PrimaryServer", false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getProxyServerName() {
|
||||
return getData().getString("ProxyServerName", "SOCKET");
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getProxyServers() {
|
||||
return getData().getStringList("ProxyServers");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getRedisHost() {
|
||||
return getData().getString("Redis.Host", "");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getRedisPassword() {
|
||||
return getData().getString("Redis.Password", "");
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getRedisPort() {
|
||||
return getData().getInt("Redis.Port", 6379);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getRedisPrefix() {
|
||||
return getData().getString("Redis.Prefix", "");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getRedisUsername() {
|
||||
return getData().getString("Redis.Username", "");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean getSendVotesToAllServers() {
|
||||
return getData().getBoolean("SendVotesToAllServers");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Object> getSpigotServerConfiguration(String s) {
|
||||
return configToMap(getData().getSection("SpigotServers." + s));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<String> getSpigotServers() {
|
||||
return getData().getSection("SpigotServers").getKeys();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean getStoreMonthTotalsWithDate() {
|
||||
return getData().getBoolean("StoreMonthTotalsWithDate", false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean getTimeChangeFailSafeBypass() {
|
||||
return getData().getBoolean("TimeChangeFailSafeBypass", false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getTimeHourOffSet() {
|
||||
return getData().getInt("TimeHourOffSet");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getTimeZone() {
|
||||
return getData().getString("TimeZone", "");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean getUseMonthDateTotalsAsPrimaryTotal() {
|
||||
return getData().getBoolean("UseMonthDateTotalsAsPrimaryTotal", false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean getUUIDLookup() {
|
||||
return getData().getBoolean("UUIDLookup", true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getVoteCacheTime() {
|
||||
return getData().getInt("VoteCacheTime", -1);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getVotePartyBroadcast() {
|
||||
return getData().getString("VoteParty.Broadcast", "");
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getVotePartyBungeeCommands() {
|
||||
return getData().getStringList("VoteParty.BungeeCommands");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean getVotePartyEnabled() {
|
||||
return getData().getBoolean("VoteParty.Enabled", false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getVotePartyIncreaseVotesRequired() {
|
||||
return getData().getInt("VoteParty.IncreaseVotesRequired", 0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean getVotePartySendToAllServers() {
|
||||
return getData().getBoolean("VoteParty.SendToAllServers", true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getVotePartyServersToSend() {
|
||||
return getData().getStringList("VoteParty.ServersToSend");
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getVotePartyVotesRequired() {
|
||||
return getData().getInt("VoteParty.VotesRequired", 100);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean getWaitForUserOnline() {
|
||||
return getData().getBoolean("WaitForUserOnline", false);
|
||||
return getData().getBoolean("WaitForUserOnline", true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getWhiteListedServers() {
|
||||
return getData().getStringList("WhiteListedServers");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getMqttClientID() {
|
||||
return getData().getString("MQTT.ClientID", "proxy");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getMqttBrokerURL() {
|
||||
return getData().getString("MQTT.BrokerURL", "tcp://localhost:1883");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getMqttUsername() {
|
||||
return getData().getString("MQTT.Username", "");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getMqttPassword() {
|
||||
return getData().getString("MQTT.Password", "");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getMqttPrefix() {
|
||||
return getData().getString("MQTT.Prefix", "");
|
||||
}
|
||||
|
||||
public void load() {
|
||||
if (!bungee.getDataFolder().exists()) {
|
||||
bungee.getDataFolder().mkdir();
|
||||
@@ -294,4 +374,39 @@ public class Config implements VotingPluginProxyConfig {
|
||||
return getData().getBoolean("PluginMessageEncryption", false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<String> getWaitUntilVoteDelaySites() {
|
||||
return getData().getSection("WaitUntilVoteDelay").getKeys();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getWaitUntilVoteDelayService(String site) {
|
||||
return getData().getString("WaitUntilVoteDelay." + site + ".ServiceSite", "");
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getWaitUntilVoteDelayVoteDelay(String site) {
|
||||
return getData().getInt("WaitUntilVoteDelay." + site + ".VoteDelay", 24);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean getWaitUntilVoteDelayVoteDelayDaily(String site) {
|
||||
return getData().getBoolean("WaitUntilVoteDelay." + site + ".VoteDelayDaily", false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getWaitUntilVoteDelayVoteDelayHour(String site) {
|
||||
return getData().getInt("WaitUntilVoteDelay." + site + ".VoteDelayDailyHour", 0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getWaitUntilVoteDelayVoteDelayMin(String site) {
|
||||
return getData().getInt("WaitUntilVoteDelay." + site + ".VoteDelayMin", 0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean getResetMilestonesMonthly() {
|
||||
return getData().getBoolean("ResetMilestonesMonthly", false);
|
||||
}
|
||||
|
||||
}
|
||||
+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;
|
||||
+57
-23
@@ -1,4 +1,4 @@
|
||||
package com.bencodez.votingplugin.bungee;
|
||||
package com.bencodez.votingplugin.proxy.bungee;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.DataInputStream;
|
||||
@@ -15,18 +15,23 @@ import java.util.HashSet;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.ScheduledExecutorService;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.zip.ZipEntry;
|
||||
import java.util.zip.ZipInputStream;
|
||||
|
||||
import com.bencodez.advancedcore.api.time.TimeType;
|
||||
import com.bencodez.advancedcore.api.user.userstorage.DataType;
|
||||
import com.bencodez.advancedcore.api.user.userstorage.mysql.api.config.MysqlConfigBungee;
|
||||
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.simpleapi.sql.DataType;
|
||||
import com.bencodez.simpleapi.sql.mysql.config.MysqlConfigBungee;
|
||||
import com.bencodez.votingplugin.proxy.BungeeMethod;
|
||||
import com.bencodez.votingplugin.proxy.BungeeVersion;
|
||||
import com.bencodez.votingplugin.proxy.OfflineBungeeVote;
|
||||
import com.bencodez.votingplugin.proxy.ProxyMysqlUserTable;
|
||||
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;
|
||||
@@ -60,6 +65,9 @@ public class VotingPluginBungee extends Plugin implements Listener {
|
||||
@Getter
|
||||
private VotingPluginProxy votingPluginProxy;
|
||||
|
||||
@Getter
|
||||
private ScheduledExecutorService timer;
|
||||
|
||||
public void debug(String msg) {
|
||||
if (config.getDebug()) {
|
||||
getLogger().info("Debug: " + msg);
|
||||
@@ -133,7 +141,8 @@ public class VotingPluginBungee extends Plugin implements Listener {
|
||||
}
|
||||
|
||||
private void loadMysql() {
|
||||
votingPluginProxy.setProxyMySQL(new BungeeMySQL(this, "VotingPlugin_Users", config.getData()) {
|
||||
votingPluginProxy.setProxyMySQL(new ProxyMysqlUserTable("VotingPlugin_Users",
|
||||
new MysqlConfigBungee(config.getData()), config.getDebug()) {
|
||||
|
||||
@Override
|
||||
public void debug(SQLException e) {
|
||||
@@ -141,6 +150,23 @@ public class VotingPluginBungee extends Plugin implements Listener {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void logSevere(String string) {
|
||||
getLogger().severe(string);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void logInfo(String string) {
|
||||
getLogger().info(string);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void severe(String string) {
|
||||
getLogger().severe(string);
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
ArrayList<String> servers = new ArrayList<>();
|
||||
@@ -154,14 +180,14 @@ public class VotingPluginBungee extends Plugin implements Listener {
|
||||
new GlobalMySQL("VotingPlugin_GlobalData", getVotingPluginProxy().getProxyMySQL().getMysql()) {
|
||||
|
||||
@Override
|
||||
public void debug(Exception e) {
|
||||
public void debugEx(Exception e) {
|
||||
if (config.getDebug()) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void debug(String text) {
|
||||
public void debugLog(String text) {
|
||||
debug2(text);
|
||||
}
|
||||
|
||||
@@ -172,7 +198,7 @@ public class VotingPluginBungee extends Plugin implements Listener {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void severe(String text) {
|
||||
public void logSevere(String text) {
|
||||
getLogger().severe(text);
|
||||
}
|
||||
|
||||
@@ -203,11 +229,8 @@ public class VotingPluginBungee extends Plugin implements Listener {
|
||||
}
|
||||
for (String s : getAvailableAllServers()) {
|
||||
getVotingPluginProxy().getGlobalDataHandler().setBoolean(s, "ForceUpdate", true);
|
||||
if (getVotingPluginProxy().getMethod().equals(BungeeMethod.PLUGINMESSAGING)) {
|
||||
getVotingPluginProxy().sendPluginMessageServer(s, "BungeeTimeChange", "");
|
||||
} else if (getVotingPluginProxy().getMethod().equals(BungeeMethod.SOCKETS)) {
|
||||
getVotingPluginProxy().sendServerMessage(s, "BungeeTimeChange");
|
||||
}
|
||||
getVotingPluginProxy().getGlobalMessageProxyHandler().sendMessage(s, 1, "BungeeTimeChange",
|
||||
"");
|
||||
}
|
||||
|
||||
getVotingPluginProxy().processQueue();
|
||||
@@ -220,14 +243,14 @@ public class VotingPluginBungee extends Plugin implements Listener {
|
||||
new MysqlConfigBungee(config.getData().getSection("GlobalData"))) {
|
||||
|
||||
@Override
|
||||
public void debug(Exception e) {
|
||||
public void debugEx(Exception e) {
|
||||
if (config.getDebug()) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void debug(String text) {
|
||||
public void debugLog(String text) {
|
||||
debug2(text);
|
||||
}
|
||||
|
||||
@@ -238,7 +261,7 @@ public class VotingPluginBungee extends Plugin implements Listener {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void severe(String text) {
|
||||
public void logSevere(String text) {
|
||||
getLogger().severe(text);
|
||||
}
|
||||
|
||||
@@ -271,11 +294,8 @@ public class VotingPluginBungee extends Plugin implements Listener {
|
||||
}
|
||||
for (String s : getAvailableAllServers()) {
|
||||
getVotingPluginProxy().getGlobalDataHandler().setBoolean(s, "ForceUpdate", true);
|
||||
if (getVotingPluginProxy().getMethod().equals(BungeeMethod.PLUGINMESSAGING)) {
|
||||
getVotingPluginProxy().sendPluginMessageServer(s, "BungeeTimeChange", "");
|
||||
} else if (getVotingPluginProxy().getMethod().equals(BungeeMethod.SOCKETS)) {
|
||||
getVotingPluginProxy().sendServerMessage(s, "BungeeTimeChange");
|
||||
}
|
||||
getVotingPluginProxy().getGlobalMessageProxyHandler().sendMessage(s, 1,
|
||||
"BungeeTimeChange", "");
|
||||
}
|
||||
|
||||
getVotingPluginProxy().processQueue();
|
||||
@@ -392,6 +412,8 @@ public class VotingPluginBungee extends Plugin implements Listener {
|
||||
voteCacheFile.save();
|
||||
nonVotedPlayersCache.save();
|
||||
|
||||
timer.shutdownNow();
|
||||
|
||||
getLogger().info("VotingPlugin disabled");
|
||||
|
||||
}
|
||||
@@ -399,6 +421,8 @@ public class VotingPluginBungee extends Plugin implements Listener {
|
||||
@Override
|
||||
public void onEnable() {
|
||||
|
||||
timer = Executors.newScheduledThreadPool(1);
|
||||
|
||||
getProxy().getPluginManager().registerListener(this, this);
|
||||
|
||||
config = new Config(this);
|
||||
@@ -452,6 +476,11 @@ public class VotingPluginBungee extends Plugin implements Listener {
|
||||
public String getUUID(String playerName) {
|
||||
|
||||
if (!config.getOnlineMode()) {
|
||||
// correct casing
|
||||
ProxiedPlayer p = getProxy().getPlayer(playerName);
|
||||
if (p != null && p.isConnected()) {
|
||||
playerName = p.getName();
|
||||
}
|
||||
return UUID.nameUUIDFromBytes(("OfflinePlayer:" + playerName).getBytes(StandardCharsets.UTF_8))
|
||||
.toString();
|
||||
}
|
||||
@@ -617,6 +646,11 @@ public class VotingPluginBungee extends Plugin implements Listener {
|
||||
reloadPlugin(mysql);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ScheduledExecutorService getScheduler() {
|
||||
return timer;
|
||||
}
|
||||
|
||||
};
|
||||
try {
|
||||
Class.forName("com.vexsoftware.votifier.bungee.events.VotifierEvent");
|
||||
+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("&", "§")));
|
||||
}
|
||||
}
|
||||
|
||||
+9
-9
@@ -1,17 +1,17 @@
|
||||
package com.bencodez.votingplugin.bungee.global.multiproxy;
|
||||
package com.bencodez.votingplugin.proxy.multiproxy;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
import com.bencodez.advancedcore.api.misc.encryption.EncryptionHandler;
|
||||
import com.bencodez.advancedcore.bungeeapi.redis.RedisHandler;
|
||||
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.simpleapi.encryption.EncryptionHandler;
|
||||
import com.bencodez.simpleapi.servercomm.redis.RedisHandler;
|
||||
import com.bencodez.simpleapi.servercomm.redis.RedisListener;
|
||||
import com.bencodez.simpleapi.servercomm.sockets.ClientHandler;
|
||||
import com.bencodez.simpleapi.servercomm.sockets.SocketHandler;
|
||||
import com.bencodez.simpleapi.servercomm.sockets.SocketReceiver;
|
||||
import com.bencodez.votingplugin.proxy.BungeeMessageData;
|
||||
|
||||
import lombok.Getter;
|
||||
|
||||
@@ -83,7 +83,7 @@ public abstract class MultiProxyHandler {
|
||||
if (getMultiProxySupportEnabled()) {
|
||||
if (getMultiProxyMethod().equals(MultiProxyMethod.SOCKETS)) {
|
||||
if (getEncryptionHandler() == null) {
|
||||
setEncryptionHandler(new EncryptionHandler(new File(getPluginDataFolder(), "secretkey.key")));
|
||||
setEncryptionHandler(new EncryptionHandler("VotingPlugin",new File(getPluginDataFolder(), "secretkey.key")));
|
||||
}
|
||||
|
||||
if (multiproxySocketHandler != null) {
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
package com.bencodez.votingplugin.bungee.global.multiproxy;
|
||||
package com.bencodez.votingplugin.proxy.multiproxy;
|
||||
|
||||
public enum MultiProxyMethod {
|
||||
SOCKETS, REDIS;
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
package com.bencodez.votingplugin.bungee.global.multiproxy;
|
||||
package com.bencodez.votingplugin.proxy.multiproxy;
|
||||
|
||||
public interface MultiProxyServerSocketConfiguration {
|
||||
String getHost();
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
package com.bencodez.votingplugin.bungee.global.multiproxy;
|
||||
package com.bencodez.votingplugin.proxy.multiproxy;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
package com.bencodez.votingplugin.bungee.global.multiproxy;
|
||||
package com.bencodez.votingplugin.proxy.multiproxy;
|
||||
|
||||
import ninja.leaping.configurate.ConfigurationNode;
|
||||
|
||||
+118
-3
@@ -1,7 +1,8 @@
|
||||
package com.bencodez.votingplugin.bungee.velocity;
|
||||
package com.bencodez.votingplugin.proxy.velocity;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
@@ -9,7 +10,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;
|
||||
|
||||
@@ -19,90 +20,113 @@ public class Config extends VelocityYMLFile implements VotingPluginProxyConfig {
|
||||
super(file);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean getAllowUnJoined() {
|
||||
return getBoolean(getNode("AllowUnJoined"), false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getBedrockPlayerPrefix() {
|
||||
return getString(getNode("BedrockPlayerPrefix"), ".");
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
public List<String> getBlockedServers() {
|
||||
return getStringList(getNode("BlockedServers"), new ArrayList<>());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean getBroadcast() {
|
||||
return getBoolean(getNode("Broadcast"), false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getBungeeHost() {
|
||||
return getString(getNode("BungeeServer", "Host"), "");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean getBungeeManageTotals() {
|
||||
return getBoolean(getNode("BungeeManageTotals"), true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getBungeeMethod() {
|
||||
return getString(getNode("BungeeMethod"), "PLUGINMESSAGING");
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getBungeePort() {
|
||||
return getInt(getNode("BungeeServer", "Port"), 1297);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean getDebug() {
|
||||
return getBoolean(getNode("Debug"), false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getFallBack() {
|
||||
return getString(getNode("FallBackServer"), "");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean getGlobalDataEnabled() {
|
||||
return getBoolean(getNode("GlobalData", "Enabled"), false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean getGlobalDataUseMainMySQL() {
|
||||
return getBoolean(getNode("GlobalData", "UseMainMySQL"), true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getLimitVotePoints() {
|
||||
return getInt(getNode("LimitVotePoints"), -1);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMaxAmountOfVotesPerDay() {
|
||||
return getInt(getNode("MaxAmountOfVotesPerDay"), -1);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getMultiProxyMethod() {
|
||||
return getString(getNode("MultiProxyMethod"), "SOCKET");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean getMultiProxyOneGlobalReward() {
|
||||
return getBoolean(getNode("MultiProxyOneGlobalReward"), false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getMultiProxyRedisHost() {
|
||||
return getString(getNode("MultiProxyRedis", "Host"), "");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getMultiProxyRedisPassword() {
|
||||
return getString(getNode("MultiProxyRedis", "Password"), "");
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMultiProxyRedisPort() {
|
||||
return getInt(getNode("MultiProxyRedis", "Port"), 6379);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean getMultiProxyRedisUseExistingConnection() {
|
||||
return getBoolean(getNode("MultiProxyRedis", "UseExistingConnection"), false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getMultiProxyRedisUsername() {
|
||||
return getString(getNode("MultiProxyRedis", "Username"), "");
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NonNull List<String> getMultiProxyServers() {
|
||||
return getChildrenAsList(getNode("MultiProxyServers"));
|
||||
}
|
||||
@@ -117,18 +141,22 @@ public class Config extends VelocityYMLFile implements VotingPluginProxyConfig {
|
||||
return children;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Object> getMultiProxyServersConfiguration(String s) {
|
||||
return configToMap(getNode("MultiProxyServers", s));
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getMultiProxySocketHostHost() {
|
||||
return getString(getNode("MultiProxySocketHost", "Host"), "");
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMultiProxySocketHostPort() {
|
||||
return getInt(getNode("MultiProxySocketHost", "Port"), 1297);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean getMultiProxySupport() {
|
||||
return getBoolean(getNode("MultiProxySupport"), false);
|
||||
}
|
||||
@@ -137,54 +165,91 @@ public class Config extends VelocityYMLFile implements VotingPluginProxyConfig {
|
||||
return getNode("MySQL");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean getOnlineMode() {
|
||||
return getBoolean(getNode("OnlineMode"), true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getPointsOnVote() {
|
||||
return getInt(getNode("PointsOnVote"), 1);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean getPrimaryServer() {
|
||||
return getBoolean(getNode("PrimaryServer"), false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getProxyServerName() {
|
||||
return getString(getNode("ProxyServerName"), "SOCKET");
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getProxyServers() {
|
||||
return getStringList(getNode("ProxyServers"), new ArrayList<>());
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getRedisHost() {
|
||||
return getString(getNode("Redis", "Host"), "");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getRedisPassword() {
|
||||
return getString(getNode("Redis", "Password"), "");
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getRedisPort() {
|
||||
return getInt(getNode("Redis", "Port"), 6379);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getRedisPrefix() {
|
||||
return getString(getNode("Redis", "Prefix"), "");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getRedisUsername() {
|
||||
return getString(getNode("Redis", "Username"), "");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean getSendVotesToAllServers() {
|
||||
return getBoolean(getNode("SendVotesToAllServers"), true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Object> getSpigotServerConfiguration(String s) {
|
||||
return configToMap(getNode("SpigotServers", s));
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getMqttClientID() {
|
||||
return getString(getNode("MQTT", "ClientID"), "proxy");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getMqttBrokerURL() {
|
||||
return getString(getNode("MQTT", "BrokerURL"), "tcp://localhost:1883");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getMqttUsername() {
|
||||
return getString(getNode("MQTT", "Username"), "");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getMqttPassword() {
|
||||
return getString(getNode("MQTT", "Password"), "");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getMqttPrefix() {
|
||||
return getString(getNode("MQTT", "Prefix"), "");
|
||||
}
|
||||
|
||||
public Map<String, Object> configToMap(ConfigurationNode config) {
|
||||
Map<String, Object> map = new HashMap<>();
|
||||
if (config != null) {
|
||||
@@ -195,42 +260,52 @@ public class Config extends VelocityYMLFile implements VotingPluginProxyConfig {
|
||||
return map;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NonNull List<String> getSpigotServers() {
|
||||
return getChildrenAsList(getNode("SpigotServers"));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean getStoreMonthTotalsWithDate() {
|
||||
return getBoolean(getNode("StoreMonthTotalsWithDate"), false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean getTimeChangeFailSafeBypass() {
|
||||
return getBoolean(getNode("TimeChangeFailSafeBypass"), false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean getUseMonthDateTotalsAsPrimaryTotal() {
|
||||
return getBoolean(getNode("UseMonthDateTotalsAsPrimaryTotal"), false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean getUUIDLookup() {
|
||||
return getBoolean(getNode("UUIDLookup"), true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getVoteCacheTime() {
|
||||
return getInt(getNode("VoteCacheTime"), -1);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getVotePartyBroadcast() {
|
||||
return getString(getVotePartyNode().getNode("Broadcast"), "");
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getVotePartyBungeeCommands() {
|
||||
return getStringList(getVotePartyNode().getNode("BungeeCommands"), new ArrayList<>());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean getVotePartyEnabled() {
|
||||
return getBoolean(getVotePartyNode().getNode("Enabled"), false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getVotePartyIncreaseVotesRequired() {
|
||||
return getInt(getVotePartyNode().getNode("IncreaseVotesRequired"), 0);
|
||||
}
|
||||
@@ -239,22 +314,27 @@ public class Config extends VelocityYMLFile implements VotingPluginProxyConfig {
|
||||
return getNode("VoteParty");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean getVotePartySendToAllServers() {
|
||||
return getBoolean(getVotePartyNode().getNode("SendToAllServers"), false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getVotePartyServersToSend() {
|
||||
return getStringList(getVotePartyNode().getNode("ServersToSend"), new ArrayList<>());
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getVotePartyVotesRequired() {
|
||||
return getInt(getVotePartyNode().getNode("VotesRequired"), 100);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean getWaitForUserOnline() {
|
||||
return getBoolean(getNode("WaitForUserOnline"), false);
|
||||
return getBoolean(getNode("WaitForUserOnline"), true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getWhiteListedServers() {
|
||||
return getStringList(getNode("WhiteListedServers"), new ArrayList<>());
|
||||
}
|
||||
@@ -285,4 +365,39 @@ public class Config extends VelocityYMLFile implements VotingPluginProxyConfig {
|
||||
return getBoolean(getNode("PluginMessageEncryption"), false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<String> getWaitUntilVoteDelaySites() {
|
||||
return getChildrenAsList(getNode("WaitUntilVoteDelay"));
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getWaitUntilVoteDelayService(String site) {
|
||||
return getString(getNode("WaitUntilVoteDelay", site, "ServiceSite"), "");
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getWaitUntilVoteDelayVoteDelay(String site) {
|
||||
return getInt(getNode("WaitUntilVoteDelay", site, "VoteDelay"), 24);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean getWaitUntilVoteDelayVoteDelayDaily(String site) {
|
||||
return getBoolean(getNode("WaitUntilVoteDelay", site, "VoteDelayDaily"), false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getWaitUntilVoteDelayVoteDelayHour(String site) {
|
||||
return getInt(getNode("WaitUntilVoteDelay", site, "VoteDelayDailyHour"), 0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getWaitUntilVoteDelayVoteDelayMin(String site) {
|
||||
return getInt(getNode("WaitUntilVoteDelay", site, "VoteDelayMin"), 0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean getResetMilestonesMonthly() {
|
||||
return getBoolean(getNode("ResetMilestonesMonthly"), false);
|
||||
}
|
||||
|
||||
}
|
||||
+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;
|
||||
|
||||
+85
-49
@@ -1,4 +1,4 @@
|
||||
package com.bencodez.votingplugin.bungee.velocity;
|
||||
package com.bencodez.votingplugin.proxy.velocity;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.DataInputStream;
|
||||
@@ -31,17 +31,17 @@ import org.bstats.velocity.Metrics;
|
||||
import org.slf4j.Logger;
|
||||
|
||||
import com.bencodez.advancedcore.api.time.TimeType;
|
||||
import com.bencodez.advancedcore.api.user.userstorage.DataType;
|
||||
import com.bencodez.advancedcore.api.user.userstorage.mysql.api.config.MysqlConfigVelocity;
|
||||
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.simpleapi.sql.DataType;
|
||||
import com.bencodez.simpleapi.sql.mysql.config.MysqlConfigVelocity;
|
||||
import com.bencodez.votingplugin.proxy.BungeeMethod;
|
||||
import com.bencodez.votingplugin.proxy.BungeeVersion;
|
||||
import com.bencodez.votingplugin.proxy.OfflineBungeeVote;
|
||||
import com.bencodez.votingplugin.proxy.ProxyMysqlUserTable;
|
||||
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;
|
||||
@@ -59,9 +59,10 @@ import com.velocitypowered.api.proxy.ServerConnection;
|
||||
import com.velocitypowered.api.proxy.messages.ChannelIdentifier;
|
||||
import com.velocitypowered.api.proxy.messages.MinecraftChannelIdentifier;
|
||||
import com.velocitypowered.api.proxy.server.RegisteredServer;
|
||||
import com.velocitypowered.api.scheduler.ScheduledTask;
|
||||
|
||||
import lombok.Getter;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
|
||||
import ninja.leaping.configurate.ConfigurationNode;
|
||||
import ninja.leaping.configurate.yaml.YAMLConfigurationLoader;
|
||||
|
||||
@@ -191,20 +192,31 @@ public class VotingPluginVelocity {
|
||||
}
|
||||
|
||||
private void loadMysql() {
|
||||
votingPluginProxy.setProxyMySQL(new VelocityMySQL("VotingPlugin_Users", config) {
|
||||
votingPluginProxy.setProxyMySQL(
|
||||
new ProxyMysqlUserTable("VotingPlugin_Users", new MysqlConfigVelocity(config), config.getDebug()) {
|
||||
|
||||
@Override
|
||||
public void debug(SQLException e) {
|
||||
if (config.getDebug()) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public void debug(SQLException e) {
|
||||
if (config.getDebug()) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void severe(String str) {
|
||||
getLogger().error(str);
|
||||
}
|
||||
});
|
||||
@Override
|
||||
public void severe(String str) {
|
||||
getLogger().error(str);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void logSevere(String string) {
|
||||
logger.error(string);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void logInfo(String string) {
|
||||
logger.info(string);
|
||||
}
|
||||
});
|
||||
|
||||
ArrayList<String> servers = new ArrayList<>();
|
||||
for (String s : getAvailableAllServers()) {
|
||||
@@ -217,14 +229,14 @@ public class VotingPluginVelocity {
|
||||
new GlobalMySQL("VotingPlugin_GlobalData", getVotingPluginProxy().getProxyMySQL().getMysql()) {
|
||||
|
||||
@Override
|
||||
public void debug(Exception e) {
|
||||
public void debugEx(Exception e) {
|
||||
if (config.getDebug()) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void debug(String text) {
|
||||
public void debugLog(String text) {
|
||||
debug2(text);
|
||||
}
|
||||
|
||||
@@ -234,7 +246,7 @@ public class VotingPluginVelocity {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void severe(String text) {
|
||||
public void logSevere(String text) {
|
||||
logger.error(text);
|
||||
}
|
||||
|
||||
@@ -265,11 +277,8 @@ public class VotingPluginVelocity {
|
||||
}
|
||||
for (String s : getAvailableAllServers()) {
|
||||
getVotingPluginProxy().getGlobalDataHandler().setBoolean(s, "ForceUpdate", true);
|
||||
if (getVotingPluginProxy().getMethod().equals(BungeeMethod.PLUGINMESSAGING)) {
|
||||
getVotingPluginProxy().sendPluginMessageServer(s, "BungeeTimeChange", "");
|
||||
} else if (getVotingPluginProxy().getMethod().equals(BungeeMethod.SOCKETS)) {
|
||||
getVotingPluginProxy().sendServerMessage(s, "BungeeTimeChange");
|
||||
}
|
||||
getVotingPluginProxy().getGlobalMessageProxyHandler().sendMessage(s, 1, "BungeeTimeChange",
|
||||
"");
|
||||
}
|
||||
|
||||
getVotingPluginProxy().processQueue();
|
||||
@@ -280,14 +289,14 @@ public class VotingPluginVelocity {
|
||||
new GlobalMySQL("VotingPlugin_GlobalData", new MysqlConfigVelocity("GlobalData", config)) {
|
||||
|
||||
@Override
|
||||
public void debug(Exception e) {
|
||||
public void debugEx(Exception e) {
|
||||
if (config.getDebug()) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void debug(String text) {
|
||||
public void debugLog(String text) {
|
||||
debug2(text);
|
||||
}
|
||||
|
||||
@@ -297,7 +306,7 @@ public class VotingPluginVelocity {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void severe(String text) {
|
||||
public void logSevere(String text) {
|
||||
logger.error(text);
|
||||
}
|
||||
|
||||
@@ -328,11 +337,8 @@ public class VotingPluginVelocity {
|
||||
}
|
||||
for (String s : getAvailableAllServers()) {
|
||||
getVotingPluginProxy().getGlobalDataHandler().setBoolean(s, "ForceUpdate", true);
|
||||
if (getVotingPluginProxy().getMethod().equals(BungeeMethod.PLUGINMESSAGING)) {
|
||||
getVotingPluginProxy().sendPluginMessageServer(s, "BungeeTimeChange", "");
|
||||
} else if (getVotingPluginProxy().getMethod().equals(BungeeMethod.SOCKETS)) {
|
||||
getVotingPluginProxy().sendServerMessage(s, "BungeeTimeChange");
|
||||
}
|
||||
getVotingPluginProxy().getGlobalMessageProxyHandler().sendMessage(s, 1, "BungeeTimeChange",
|
||||
"");
|
||||
}
|
||||
|
||||
getVotingPluginProxy().processQueue();
|
||||
@@ -395,10 +401,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 {
|
||||
@@ -440,17 +446,27 @@ public class VotingPluginVelocity {
|
||||
num++;
|
||||
}
|
||||
}
|
||||
getVotingPluginProxy().onDisable();
|
||||
|
||||
voteCacheFile.save();
|
||||
nonVotedPlayersCache.save();
|
||||
|
||||
getVotingPluginProxy().onDisable();
|
||||
|
||||
if (voteCheckTask != null)
|
||||
voteCheckTask.cancel();
|
||||
if (cacheSaveTask != null)
|
||||
cacheSaveTask.cancel();
|
||||
|
||||
timer.shutdownNow();
|
||||
logger.info("VotingPlugin disabled");
|
||||
}
|
||||
|
||||
@Getter
|
||||
public VotingPluginProxy votingPluginProxy;
|
||||
|
||||
private ScheduledTask voteCheckTask;
|
||||
private ScheduledTask cacheSaveTask;
|
||||
|
||||
@Subscribe
|
||||
public void onProxyInitialization(ProxyInitializeEvent event) {
|
||||
File configFile = new File(dataDirectory.toFile(), "bungeeconfig.yml");
|
||||
@@ -496,7 +512,8 @@ public class VotingPluginVelocity {
|
||||
|
||||
@Override
|
||||
public void broadcast(String message) {
|
||||
server.getAllPlayers().forEach(player -> player.sendMessage(Component.text(message)));
|
||||
server.getAllPlayers().forEach(
|
||||
player -> player.sendMessage(LegacyComponentSerializer.legacyAmpersand().deserialize(message)));
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -517,8 +534,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 "";
|
||||
}
|
||||
@@ -537,6 +556,18 @@ public class VotingPluginVelocity {
|
||||
public String getUUID(String playerName) {
|
||||
|
||||
if (!config.getOnlineMode()) {
|
||||
// correct case
|
||||
if (server.getPlayer(playerName).isPresent()) {
|
||||
Player p = server.getPlayer(playerName).get();
|
||||
if (p != null && p.isActive()) {
|
||||
playerName = p.getUsername();
|
||||
}
|
||||
}
|
||||
for (Entry<UUID, String> entry : getVotingPluginProxy().getUuidPlayerNameCache().entrySet()) {
|
||||
if (entry.getValue().equalsIgnoreCase(playerName)) {
|
||||
playerName = entry.getValue();
|
||||
}
|
||||
}
|
||||
return UUID.nameUUIDFromBytes(("OfflinePlayer:" + playerName).getBytes(StandardCharsets.UTF_8))
|
||||
.toString();
|
||||
}
|
||||
@@ -713,6 +744,11 @@ public class VotingPluginVelocity {
|
||||
reloadPlugin(mysql);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ScheduledExecutorService getScheduler() {
|
||||
return timer;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
try {
|
||||
@@ -820,7 +856,7 @@ public class VotingPluginVelocity {
|
||||
|
||||
voteCacheFile.clearData();
|
||||
|
||||
server.getScheduler().buildTask(this, () -> {
|
||||
voteCheckTask = server.getScheduler().buildTask(this, () -> {
|
||||
if (getVotingPluginProxy().getGlobalDataHandler() == null
|
||||
|| !getVotingPluginProxy().getGlobalDataHandler().isTimeChangedHappened()) {
|
||||
for (String server : getVotingPluginProxy().getCachedVotes().keySet()) {
|
||||
@@ -836,7 +872,7 @@ public class VotingPluginVelocity {
|
||||
}
|
||||
}).delay(120, TimeUnit.SECONDS).repeat(60, TimeUnit.SECONDS).schedule();
|
||||
|
||||
server.getScheduler().buildTask(this, () -> {
|
||||
cacheSaveTask = server.getScheduler().buildTask(this, () -> {
|
||||
if (nonVotedPlayersCache != null) {
|
||||
debug("Checking nonvotedplayerscache.yml...");
|
||||
nonVotedPlayersCache.check();
|
||||
@@ -903,7 +939,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.time.events.MonthChangeEvent;
|
||||
import com.bencodez.advancedcore.api.time.events.PreDateChangedEvent;
|
||||
import com.bencodez.advancedcore.api.time.events.WeekChangeEvent;
|
||||
import com.bencodez.advancedcore.api.user.UserStorage;
|
||||
import com.bencodez.advancedcore.api.user.userstorage.Column;
|
||||
import com.bencodez.advancedcore.api.user.userstorage.DataType;
|
||||
import com.bencodez.simpleapi.array.ArrayUtils;
|
||||
import com.bencodez.simpleapi.file.YMLFileHandler;
|
||||
import com.bencodez.simpleapi.messages.MessageAPI;
|
||||
import com.bencodez.simpleapi.sql.Column;
|
||||
import com.bencodez.simpleapi.sql.DataType;
|
||||
import com.bencodez.votingplugin.VotingPluginMain;
|
||||
import com.bencodez.votingplugin.user.VotingPluginUser;
|
||||
|
||||
|
||||
@@ -15,7 +15,7 @@ import com.bencodez.advancedcore.api.user.usercache.UserDataManager;
|
||||
import com.bencodez.advancedcore.api.user.usercache.keys.UserDataKeyBoolean;
|
||||
import com.bencodez.advancedcore.api.user.usercache.keys.UserDataKeyInt;
|
||||
import com.bencodez.advancedcore.api.user.usercache.keys.UserDataKeyString;
|
||||
import com.bencodez.advancedcore.api.user.userstorage.Column;
|
||||
import com.bencodez.simpleapi.sql.Column;
|
||||
import com.bencodez.votingplugin.VotingPluginMain;
|
||||
import com.bencodez.votingplugin.topvoter.TopVoter;
|
||||
|
||||
|
||||
@@ -24,15 +24,15 @@ import com.bencodez.advancedcore.api.misc.MiscUtils;
|
||||
import com.bencodez.advancedcore.api.rewards.RewardBuilder;
|
||||
import com.bencodez.advancedcore.api.rewards.RewardOptions;
|
||||
import com.bencodez.advancedcore.api.user.AdvancedCoreUser;
|
||||
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.simpleapi.sql.data.DataValue;
|
||||
import com.bencodez.simpleapi.sql.data.DataValueInt;
|
||||
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()) {
|
||||
@@ -1377,6 +1389,9 @@ public class VotingPluginUser extends com.bencodez.advancedcore.api.user.Advance
|
||||
}
|
||||
|
||||
Player player = getPlayer();
|
||||
if (!plugin.getOptions().isOnlineMode()) {
|
||||
player = Bukkit.getPlayer(getPlayerName());
|
||||
}
|
||||
if (player == null) {
|
||||
return;
|
||||
}
|
||||
@@ -1811,6 +1826,12 @@ public class VotingPluginUser extends com.bencodez.advancedcore.api.user.Advance
|
||||
*/
|
||||
public void setTime(VoteSite voteSite, Long time) {
|
||||
HashMap<VoteSite, Long> lastVotes = getLastVotes();
|
||||
if (lastVotes != null && lastVotes.containsKey(voteSite)) {
|
||||
if (lastVotes.get(voteSite).longValue() == time.longValue()) {
|
||||
plugin.debug("Not setting last vote time for " + voteSite.getKey() + ", already set to " + time);
|
||||
return;
|
||||
}
|
||||
}
|
||||
lastVotes.put(voteSite, time);
|
||||
setLastVotes(lastVotes);
|
||||
}
|
||||
|
||||
@@ -20,9 +20,9 @@ import com.bencodez.advancedcore.api.rewards.RewardBuilder;
|
||||
import com.bencodez.advancedcore.api.time.events.DayChangeEvent;
|
||||
import com.bencodez.advancedcore.api.time.events.MonthChangeEvent;
|
||||
import com.bencodez.advancedcore.api.time.events.WeekChangeEvent;
|
||||
import com.bencodez.advancedcore.api.user.userstorage.DataType;
|
||||
import com.bencodez.simpleapi.array.ArrayUtils;
|
||||
import com.bencodez.simpleapi.messages.MessageAPI;
|
||||
import com.bencodez.simpleapi.sql.DataType;
|
||||
import com.bencodez.votingplugin.VotingPluginMain;
|
||||
import com.bencodez.votingplugin.events.VotePartyEvent;
|
||||
import com.bencodez.votingplugin.user.VotingPluginUser;
|
||||
|
||||
@@ -11,10 +11,11 @@ UseBungeecord: false
|
||||
# Requires restart and set on all servers
|
||||
# https://github.com/BenCodez/VotingPlugin/wiki/Bungeecord-Setups
|
||||
# Available:
|
||||
# SOCKETS
|
||||
# PLUGINMESSAGING (Recommended)
|
||||
# MYSQL
|
||||
# REDIS (2nd Most Recommended)
|
||||
# MQTT
|
||||
# MYSQL
|
||||
# SOCKETS (Not recommended)
|
||||
BungeeMethod: PLUGINMESSAGING
|
||||
|
||||
# Use Redis for between server communication, set BungeeMethod to REDIS to use this
|
||||
@@ -26,6 +27,16 @@ Redis:
|
||||
Password: ''
|
||||
# Set a prefix from an entire proxy network if using multi-proxy setup below
|
||||
Prefix: ''
|
||||
|
||||
MQTT:
|
||||
# clientid must be unique on each server
|
||||
# Default will use the server name below
|
||||
#ClientID: 'server1'
|
||||
BrokerURL: "tcp://localhost:1883"
|
||||
Username: ''
|
||||
Password: ''
|
||||
# Set a prefix from an entire proxy network if using mutli-proxy setup below
|
||||
Prefix: ''
|
||||
|
||||
# Enables more debug messages for communication between servers
|
||||
# Use /votingpluginbungee status for testing communication
|
||||
|
||||
@@ -480,8 +480,8 @@ TreatVanishAsOffline: false
|
||||
# In miliseconds, 1000 = 1 second
|
||||
DelayLoginEvent: 0
|
||||
|
||||
# Wait until user is logged in with AuthMe
|
||||
# Requires AuthMe or LoginSecurity
|
||||
# Wait until user is logged in with AuthMe or NLogin
|
||||
# Requires AuthMe or LoginSecurity or NLogin
|
||||
WaitUntilLoggedIn: true
|
||||
|
||||
###########################################
|
||||
@@ -569,6 +569,9 @@ OnlineMode: true
|
||||
# Disable javascript processing in messages/rewards
|
||||
DisableJavascript: false
|
||||
|
||||
# Enable command /av javascript (javascript)
|
||||
EnableJavascriptCommand: false
|
||||
|
||||
# If true, number of vote shop purchases will be tracked
|
||||
# Data will be tracked in serverdata.yml, may change in the future
|
||||
# No commands to view data currently
|
||||
@@ -611,6 +614,63 @@ StoreMonthTotalsWithDate: false
|
||||
# This setting may be very buggy as it's in early stages
|
||||
UseMonthDateTotalsAsPrimaryTotal: false
|
||||
|
||||
###########################################
|
||||
# DiscordSRV settings
|
||||
###########################################
|
||||
|
||||
DiscordSRV:
|
||||
# Enable DiscordSRV support
|
||||
# Also enables using rewards in discord
|
||||
Enabled: false
|
||||
|
||||
# Show live top voter counts in discord
|
||||
TopVoter:
|
||||
AllTime:
|
||||
# If true, will send top voter messages to discord
|
||||
# Will send a message show top 10 voters
|
||||
Enabled: false
|
||||
|
||||
# DiscordSRV channel to send messages to
|
||||
Channel: 1234565 # Replace with your channel ID
|
||||
|
||||
Title: 'All Time Top Voters'
|
||||
RankDisplay: '%rank%: &6%player% - %votes% Votes'
|
||||
|
||||
Monthly:
|
||||
# If true, will send top voter messages to discord
|
||||
# Will send a message show top 10 voters
|
||||
Enabled: false
|
||||
|
||||
# DiscordSRV channel to send messages to
|
||||
Channel: 1234565 # Replace with your channel ID
|
||||
|
||||
Title: 'Top Voters of the Month'
|
||||
RankDisplay: '%rank%: &6%player% - %votes% Votes'
|
||||
|
||||
Weekly:
|
||||
# If true, will send top voter messages to discord
|
||||
# Will send a message show top 10 voters
|
||||
Enabled: false
|
||||
|
||||
# DiscordSRV channel to send messages to
|
||||
Channel: 1234565 # Replace with your channel ID
|
||||
|
||||
Title: 'Top Voters of the Week'
|
||||
RankDisplay: '%rank%: &6%player% - %votes% Votes'
|
||||
|
||||
Daily:
|
||||
# If true, will send top voter messages to discord
|
||||
# Will send a message show top 10 voters
|
||||
Enabled: false
|
||||
|
||||
# DiscordSRV channel to send messages to
|
||||
Channel: 1234565 # Replace with your channel ID
|
||||
|
||||
Title: 'Top Voters of the Day'
|
||||
RankDisplay: '%rank%: &6%player% - %votes% Votes'
|
||||
|
||||
|
||||
|
||||
###########################################
|
||||
# Skull settings
|
||||
###########################################
|
||||
|
||||
@@ -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
|
||||
@@ -55,9 +55,7 @@ GlobalData:
|
||||
#Attempt to use mariadb driver
|
||||
#UseMariaDB: false
|
||||
|
||||
# Time offset for time changes
|
||||
# Must match on all servers
|
||||
TimeHourOffSet: 0
|
||||
|
||||
|
||||
####################################################################################
|
||||
|
||||
@@ -79,12 +77,22 @@ WhiteListedServers: []
|
||||
# Requires restart and set on all servers
|
||||
# https://github.com/BenCodez/VotingPlugin/wiki/Bungeecoord-Setups
|
||||
# Available:
|
||||
# SOCKETS
|
||||
# PLUGINMESSAGING (Recommended)
|
||||
# MYSQL
|
||||
# REDIS
|
||||
# MQTT
|
||||
# SOCKETS
|
||||
# MYSQL (Not recommended)
|
||||
BungeeMethod: PLUGINMESSAGING
|
||||
|
||||
|
||||
|
||||
######################################################################################
|
||||
# Settings for each setup below
|
||||
|
||||
###########################################
|
||||
# PLUGINMESSAGING settings
|
||||
###########################################
|
||||
|
||||
# Default is vp:vp, can be changed to prevent potential exploits
|
||||
# Must match on all servers
|
||||
# This setting requires a restart
|
||||
@@ -96,6 +104,10 @@ PluginMessageChannel: "vp:vp"
|
||||
# This setting requires a restart
|
||||
PluginMessageEncryption: false
|
||||
|
||||
###########################################
|
||||
# REDIS Settings
|
||||
###########################################
|
||||
|
||||
# Use Redis for between server communication, set BungeeMethod to REDIS to use this
|
||||
Redis:
|
||||
Host: localhost
|
||||
@@ -104,6 +116,33 @@ Redis:
|
||||
Password: ''
|
||||
# Set a prefix from an entire proxy network if using mutli-proxy setup below
|
||||
Prefix: ''
|
||||
|
||||
###########################################
|
||||
# SOCKETS Settings
|
||||
###########################################
|
||||
|
||||
# Settings hidden to avoid confusion, highly recommend other methods first
|
||||
# Settings available here https://github.com/BenCodez/VotingPlugin/wiki/Bungee-Setup-SOCKETS
|
||||
|
||||
###########################################
|
||||
# MQTT Settings
|
||||
###########################################
|
||||
|
||||
MQTT:
|
||||
# clientid must be unique on each server
|
||||
ClientID: 'proxy'
|
||||
BrokerURL: "tcp://localhost:1883"
|
||||
Username: ''
|
||||
Password: ''
|
||||
# Set a prefix from an entire proxy network if using mutli-proxy setup below
|
||||
Prefix: ''
|
||||
|
||||
######################################################################################
|
||||
|
||||
# Votes will be forwarded when specific player is online
|
||||
# If set to false, rewards should still reward when player logs in even when false
|
||||
# but it can fail to reward, this setting has no effect if sendtoallservers is false
|
||||
WaitForUserOnline: true
|
||||
|
||||
# If false, votes will be checked if user is a valid player that has joined to server
|
||||
# Works for PLUGINMESSAGING and SOCKETS methods only
|
||||
@@ -121,7 +160,7 @@ BungeeManageTotals: true
|
||||
|
||||
# Tell servers to broadcast
|
||||
# Set DisableBroadcast to true on spigot servers (BungeeSettings.yml) as well
|
||||
Broadcast: true
|
||||
Broadcast: false
|
||||
|
||||
# Geyser/bedrock player settings
|
||||
# https://github.com/BenCodez/VotingPlugin/wiki/Bedrock-Player-Support
|
||||
@@ -142,6 +181,10 @@ MaxAmountOfVotesPerDay: -1
|
||||
# Maxium amount of vote points possible, -1 to disable
|
||||
LimitVotePoints: -1
|
||||
|
||||
# Time offset for time changes
|
||||
# Must match on all servers
|
||||
TimeHourOffSet: 0
|
||||
|
||||
VoteParty:
|
||||
# If enabled, will trigger vote party reward
|
||||
# in BungeeSettings.yml under BungeeVotePartyReward
|
||||
@@ -161,18 +204,32 @@ VoteParty:
|
||||
Broadcast: '&aVote party has been reached!'
|
||||
|
||||
# Online mode for UUIDS
|
||||
# Offline mode setups are not fully tested and are not supported currently
|
||||
# If using mixed uuids (premium and cracked players leave this enabled and disable UUIDLookup below)
|
||||
# More details here: https://github.com/BenCodez/VotingPlugin/wiki/Online-Offline-Mode
|
||||
OnlineMode: true
|
||||
|
||||
# If true plugin will atempt to lookup uuids if none exist
|
||||
UUIDLookup: true
|
||||
|
||||
# Should be enabled if enabled on backend servers
|
||||
ResetMilestonesMonthly: false
|
||||
|
||||
# If you use this plugin will ignore votes from these service sites for said amount of time
|
||||
WaitUntilVoteDelay:
|
||||
# sitename must match what's in VoteSites.yml on backend servers
|
||||
SITENAME:
|
||||
# Set service site here and vote delay
|
||||
ServiceSite: SERVICESITE
|
||||
VoteDelay: 24
|
||||
VoteDelayMin: 0
|
||||
# If true it resets based on the day isntead
|
||||
VoteDelayDaily: false
|
||||
VoteDelayDailyHour: 0
|
||||
|
||||
###########################################
|
||||
# Month Date Totals
|
||||
# Experimental feature
|
||||
# Settings must match on backend servers
|
||||
# https://github.com/BenCodez/VotingPlugin/wiki/Month-Date-Totals
|
||||
###########################################
|
||||
|
||||
# Experimental
|
||||
@@ -188,15 +245,6 @@ StoreMonthTotalsWithDate: false
|
||||
# This setting may be very buggy as it's in early stages
|
||||
UseMonthDateTotalsAsPrimaryTotal: false
|
||||
|
||||
##########################################
|
||||
# PLUGINMESSAGING Settings
|
||||
##########################################
|
||||
|
||||
# Applies to PLUGINMESSAGING only
|
||||
# Votes will be forwarded when specific player is online
|
||||
# If set to false, rewards should still reward when player logs in (by default)
|
||||
WaitForUserOnline: false
|
||||
|
||||
|
||||
##########################################
|
||||
# Multi-proxy setup
|
||||
@@ -223,7 +271,7 @@ MultiProxyOneGlobalReward: false
|
||||
MultiProxyMethod: SOCKET
|
||||
|
||||
##########################################
|
||||
# REDIS Settings
|
||||
# REDIS multi-proxy settings
|
||||
##########################################
|
||||
|
||||
# Set multiproxymethod to REDIS to use redis
|
||||
@@ -247,7 +295,7 @@ ProxyServers:
|
||||
- proxy3
|
||||
|
||||
##########################################
|
||||
# SOCKET settings for mutli-proxy
|
||||
# SOCKET multi-proxy settings
|
||||
##########################################
|
||||
|
||||
# Set this for each proxy
|
||||
|
||||
@@ -17,6 +17,8 @@ softdepend:
|
||||
- SuperVanish
|
||||
- PremiumVanish
|
||||
- LuckPerms
|
||||
- nLogin
|
||||
- DiscordSRV
|
||||
loadbefore:
|
||||
- MCPerks
|
||||
api-version: 1.13
|
||||
@@ -85,9 +87,6 @@ commands:
|
||||
votechoices:
|
||||
description: A command
|
||||
alaises: vchoices
|
||||
votegivepoints:
|
||||
description: A command
|
||||
alaises: vgivepoints
|
||||
adminvotehelp:
|
||||
description: Open adminvote help
|
||||
aliases: avhelp
|
||||
@@ -170,8 +169,6 @@ commands:
|
||||
adminvoteresyncmilestonesalreadygiven:
|
||||
description: Command Alias
|
||||
aliases: avresyncmilestonesalreadygiven
|
||||
votesetprimaryaccount:
|
||||
description: Command Alias
|
||||
adminvoteclearofflinevotes:
|
||||
description: Command Alias
|
||||
aliases: avclearofflinevotes
|
||||
|
||||
@@ -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,85 @@
|
||||
|
||||
package com.bencodez.votingplugin.tests;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.mockito.Mockito.doNothing;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
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.votingplugin.proxy.ProxyMysqlUserTable;
|
||||
import com.bencodez.votingplugin.proxy.VotingPluginProxy;
|
||||
import com.bencodez.votingplugin.proxy.VotingPluginProxyConfig;
|
||||
import com.bencodez.votingplugin.proxy.multiproxy.MultiProxyHandler;
|
||||
|
||||
public class VotingPluginProxyTest {
|
||||
|
||||
@InjectMocks
|
||||
private VotingPluginProxyTestImpl votingPluginProxy;
|
||||
|
||||
@Mock
|
||||
private ProxyMysqlUserTable 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 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());
|
||||
}
|
||||
}
|
||||
+208
@@ -0,0 +1,208 @@
|
||||
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 java.util.concurrent.ScheduledExecutorService;
|
||||
|
||||
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
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public ScheduledExecutorService getScheduler() {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
+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