Compare commits

...
61 Commits
Author SHA1 Message Date
BenCodez 16de063e51 Update version number to 6.8.1 2022-01-15 20:43:35 -05:00
BenCodez 1d3ce9ed64 Add another check 2022-01-14 21:50:21 -05:00
BenCodez d357c927c8 Add extra checks to ensure plugin is enabled before processing a vote 2022-01-14 21:47:33 -05:00
BenCodez 1143595238 modify placeholders 2022-01-13 20:57:33 -05:00
BenCodez 0917c36889 Add null check for player in placeholders 2022-01-12 18:57:12 -05:00
BenCodez c113214ae0 Add extra check on placeholders 2022-01-12 16:44:47 -05:00
BenCodez b2c444d125 Add PlayerPostVoteEvent 2022-01-11 21:04:50 -05:00
BenCodez 78fdce0eab fix npe 2022-01-10 18:51:02 -05:00
BenCodez feff09eccb Fix potential NPE 2022-01-09 17:35:57 -05:00
BenCodez d0646472bf Fix typos in votesites.yml 2022-01-09 11:22:29 -05:00
BenCodez 8471f50402 Fix certain placeholders not working 2022-01-06 19:28:13 -05:00
BenCodez 621450dae4 Add option to enable/disable auto placeholder cache 2022-01-03 21:15:16 -05:00
BenCodez 84e415e4bc Update version number to 6.8 2022-01-03 10:41:31 -05:00
BenCodez 54bbc8c740 Adding auto placeholder caching 2022-01-03 10:02:45 -05:00
BenCodez 7b1ab7e833 Code cleanup 2021-12-30 20:27:21 -05:00
BenCodez acb8f8a43f Code cleanup 2021-12-30 20:20:44 -05:00
BenCodez 279759b52f Code cleanup 2021-12-30 20:13:27 -05:00
BenCodez 02ca0b1fc8 Give players vote party reward, even if player has no reward data 2021-12-29 18:36:27 -05:00
BenCodez d57e3d1006 Add option to limit player data loading 2021-12-28 17:35:39 -05:00
BenCodez d54769eb82 Add command alias 2021-12-23 21:57:47 -05:00
BenCodez 35f6a3df15 Start progress on bungee time handling, keeps bungee in sync 2021-12-23 19:35:30 -05:00
BenCodez 46b66466ba Add ability to toggle vote reminders 2021-12-23 19:05:26 -05:00
BenCodez 53fbe4e5e2 Changes to placeholders 2021-12-21 18:55:12 -05:00
BenCodez 53ef7a7086 Add another event 2021-12-20 16:46:36 -05:00
BenCodez b0e08721fa Add scope to redis dependency 2021-12-19 21:00:20 -05:00
BenCodez 29dad6ca25 Add null check for redis 2021-12-19 17:48:03 -05:00
BenCodez 7c3e5eb09b Add bungee vote party placeholders 2021-12-19 14:40:50 -05:00
BenCodez a7776ec97c Hide socket settings by default to avoid confusion 2021-12-19 13:18:27 -05:00
BenCodez d598082c0a Add cache system for placeholders 2021-12-18 21:19:38 -05:00
BenCodez 4539b5b22a Add extra permission checks 2021-12-14 16:53:49 -05:00
BenCodez 02fe645d1e More changes to vote party commands 2021-12-12 12:52:37 -05:00
BenCodez ee8af6a314 Modify voteparty commands, add new ones to set/add totals 2021-12-12 12:49:50 -05:00
BenCodez a4b78c7d16 More fixes for redis 2021-12-11 08:20:20 -05:00
BenCodez d22fe462e5 Test change for redis 2021-12-10 17:02:53 -05:00
BenCodez c19182a2b4 Reuse config option 2021-12-07 17:32:03 -05:00
BenCodez 6905c3988b Remove option, auto enable redis support 2021-12-07 17:28:08 -05:00
BenCodez 23be120adc Small changes 2021-12-07 17:18:19 -05:00
BenCodez dae863f88f Bug fix 2021-12-07 17:07:54 -05:00
BenCodez d12f73d2fa Add option for redis bungee 2021-12-07 17:01:51 -05:00
BenCodez 316ee90713 Slight improvement to login events on bungee 2021-12-07 16:57:13 -05:00
BenCodez 1495fad96f Add softdepend 2021-12-07 16:47:23 -05:00
BenCodez 8e0de1709b Add permission requirements to base admin command 2021-12-06 18:52:57 -05:00
BenCodez ad22802e10 Remove unused command in plugin.yml 2021-12-06 16:53:21 -05:00
BenCodez 6de0345f06 Add option for backbutton on best GUI 2021-12-05 14:20:38 -05:00
BenCodez 7338a7d8ba added best and streak GUI's to vote gui ability to open 2021-12-05 13:32:44 -05:00
BenCodez 3ca12f2c91 Add expiremental redis support, untested 2021-12-05 12:51:13 -05:00
BenCodez 262e7c48c7 Fix socket method on velocity 2021-12-04 18:46:38 -05:00
BenCodez 0b62d99f9d Add debug for velocity socket method 2021-12-04 14:59:31 -05:00
BenCodez ea30de47d1 Update version number to 6.7.1 2021-11-28 19:11:17 -05:00
BenCodez a76daf3aba Modify debug on bungee 2021-11-28 16:46:58 -05:00
BenCodez e1ff13f4bf Add more debug for bungee for testing 2021-11-28 16:35:53 -05:00
BenCodez 12f941cf83 Add option for per server milestones 2021-11-27 20:21:42 -05:00
BenCodez 243377a76a More changes for 1.18 support 2021-11-27 19:38:15 -05:00
BenCodez d7eab03860 Fix bungee debug always active when it shouldn't 2021-11-27 17:21:10 -05:00
BenCodez ddd1f473f1 Properly reset gotten milestones on /av resyncmilestonesalreadygiven 2021-11-23 16:51:57 -05:00
BenCodez 3e52bb0936 Update library to support 1.18 2021-11-21 20:56:55 -05:00
BenCodez eb60220b1e Undo vote thread changes 2021-11-17 16:41:49 -05:00
BenCodez 00902bd597 Add a vote thread to prevent hitting resource limit 2021-11-15 17:22:48 -05:00
BenCodez d3606088cd Add option to only give 1 cumulative at a time 2021-11-07 13:55:18 -05:00
BenCodez ef2512e4e2 Change log level to info for using dev build 2021-11-01 16:41:55 -04:00
BenCodez 7f95a1c7c3 Fix issue with votereminding on shutdown 2021-10-21 16:42:54 -04:00
49 changed files with 1118 additions and 362 deletions

No files matched your search

+7 -12
View File
@@ -39,6 +39,11 @@ DisableBroadcast: false
# Requires server name below to be correct
PerServerRewards: false
# If true, milestones work per server
# Please note totals still sync, but milestones can be claimed on each server
# Needs to be set across all needed servers
PerServerMilestones: false
# If true, points will be given on a per server level
# Points will be added when server gets vote from bungee
PerServerPoints: false
@@ -60,15 +65,5 @@ BungeeVotePartyRewards: {}
# -----------------------------
# For socket setup below only
# -----------------------------
# Bungee communication, add bungee host/port here
# For socket method
BungeeServer:
Host: '127.0.0.1'
Port: 1297
# Bungee communication, add this to bungee server
# For socket method
SpigotServer:
Host: '127.0.0.1'
Port: 1298
# Options available here:
# https://github.com/BenCodez/VotingPlugin/wiki/Bungee-Setup-SOCKETS
+24 -1
View File
@@ -27,6 +27,7 @@ MySQL:
Prefix: ''
#UseSSL: true
#PublicKeyRetrieval: false
#MaxLifeTime: -1
#Additional info on connection string
#Line: ''
@@ -76,7 +77,7 @@ VoteReminding:
# This can also be edited via /av gui
Rewards:
Messages:
Player: '&aYou have %sitesavailable% to vote on still!'
Player: '&aYou have %sitesavailable% sites to vote on still!'
Title:
Enabled: false
Title: '&cRemember to vote!'
@@ -248,6 +249,10 @@ Format:
ToggleBroadcasts:
Enabled: '&cYou will now see vote broadcasts'
Disabled: '&cYou will no longer see vote broadcasts'
ToggleReminders:
Enabled: '&cVote reminders enabled'
Disabled: '&cVote reminders disabled'
# Msg on top voter award, will only send message if that place has a reward set
# %place% = place - 1,2,3,etc
@@ -438,6 +443,19 @@ UsePrimaryAccountForPlaceholders: false
# Only affects placeholderapi placeholders
AlwaysWaitForCachePlaceholders: false
# Enable auto caching placeholders
AutoCachePlaceholders: true
# Set which placeholders to cache at all times
# Use for placeholders to are pulled constantly or on the main thread
# Mainly aimed for scoreboards
# Placeholders may auto cache in certain conditions
# Will use additional memory, but not a lot
# Still in early stages, please report bugs
# Please remove VotingPlugin_ from the placeholder listed here
CachedPlaceholders: []
#- Total_AllTime
# If true, permissions will be handled differently
MultiplePermissionsCheck: false
@@ -564,6 +582,11 @@ PreloadSkulls: false
# Will reduce ram usage (very little) if disabled, but slow GUI speeds when using skulls
LoadSkulls: true
# Limit number of users to load in a second
# Effects background tasks mainly
# set to -1 to disable (default value)
#PlayerDataLoadLimit: 500
# Use vault for permission checks
# May not work on some plugins
UseVaultPermissions: false
+1
View File
@@ -204,6 +204,7 @@ CHEST:
Amount: 1
VoteBest:
Name: 'VoteBest: %player%'
BackButton: true
DayBest:
Item:
Material: 'CLOCK'
+6 -1
View File
@@ -18,9 +18,14 @@ AllSites:
Messages:
Player: '&aYou voted on all sites in 1 day!'
# If true only cumulative reward at a time can be given
# The cumulative rewards will go in order as listed under Cumulative, so if true
# the first cumulative (in the order as listed) that can be given will, then will ignore the rest
OnlyOneCumulative: false
# NOTE: This is not a 1 time reward, that's what milestones are for!
# If total votes (Can be changed) divided by cumulative amount
# and as no remainder (So divides perfectly)then a reward is given
# and with no remainder (So divides perfectly) then a reward is given
Cumulative:
# Number of votes required
# Allows multiple cumulative rewards
+2 -2
View File
@@ -26,7 +26,7 @@ VoteSites:
ServiceSite: 'PlanetMinecraft.com'
# vote url for /vote
# Format for this can be set in Format.yml
# Format for this can be set in Config.yml
# Do not include colors here
# If you need to force a url set the url as this:
# VoteURL: '[Text="ANY TEXT TO CLICK ON HERE",url="URLHERE"]'
@@ -62,7 +62,7 @@ VoteSites:
Amount: 1
# Rewards to give
# https://github.com/Ben12345rocks/AdvancedCore/wiki/Rewards
# https://github.com/BenCodez/AdvancedCore/wiki/Rewards
Rewards:
# Execute console commands
Commands:
+3 -1
View File
@@ -1,4 +1,6 @@
name: ${project.name}
version: ${project.version}
main: com.bencodez.votingplugin.bungee.VotingPluginBungee
author: BenCodez
author: BenCodez
softDepends:
- RedisBungee
+6 -23
View File
@@ -11,10 +11,6 @@ Username: ''
Password: ''
# Max number of connections
MaxConnections: 1
# Maxium size of caching mysql
# -1 for no limit
# Affecting this value may affect performance
MaxSize: -1
# Table name prefix, for use with mutliple servers
Prefix: ''
#UseSSL: true
@@ -52,6 +48,10 @@ PointsOnVote: 1
# Recommened to leave true, setting to false setups are currently unsupported
BungeeManageTotals: true
# Support for redis
# experimental
RedisSupport: false
# Tell servers to broadcast
# Set DisableBroadcast to true on spigot servers (BungeeSettings.yml) as well
Broadcast: true
@@ -87,22 +87,5 @@ WaitForUserOnline: false
# SOCKET Settings
# ONLY for SOCKET method
# ----------------------------
# Server to send vote to if player is offline
FallBackServer: factions
# Bungee communication, Add this to each spigot server
# For socket method
BungeeServer:
Host: '127.0.0.1'
Port: 1297
# Bungee communication, add each spigot server here
# For socket method
SpigotServers:
lobby:
Host: '127.0.0.1'
Port: 1298
factions:
Host: '127.0.0.1'
Port: 1999
# Options available here:
# https://github.com/BenCodez/VotingPlugin/wiki/Bungee-Setup-SOCKETS
+8 -12
View File
@@ -8,7 +8,7 @@ softdepend: [MVdWPlaceholders, Votifier, VotifierPlus, NuVotifier, CMI, Vault, P
loadbefore: [MCPerks]
api-version: 1.13
libraries:
- org.openjdk.nashorn:nashorn-core:15.2
- org.openjdk.nashorn:nashorn-core:15.3
commands:
vote:
description: Vote command
@@ -64,6 +64,8 @@ commands:
votepoints:
description: A command
aliases: vpoints
votetogglereminders:
aliases: [vtogglereminder,vtoggle]
votelist:
description: A command
aliases: vlist
@@ -88,9 +90,6 @@ commands:
adminvoteperms:
description: Command Alias
aliases: avperms
adminvoteDownload:
description: Command Alias
aliases: avdownload
adminvotereload:
description: Command Alias
aliases: avreload
@@ -130,6 +129,9 @@ commands:
adminvoteConvertFromData:
description: Command Alias
aliases: avConvertFromData
adminvoteConvertToData:
description: Command Alias
aliases: avConvertFromData
adminvoteClearTotal:
description: Command Alias
adminvoteBackgroundUpdate:
@@ -141,9 +143,9 @@ commands:
adminvoteServiceSites:
description: Command Alias
aliases: avServiceSites
adminvoteSetVotePartyCount:
adminvoteVoteParty:
description: Command Alias
aliases: avSetVotePartyCount
aliases: avVoteParty
adminvoteChoices:
description: Command Alias
aliases: avChoices
@@ -200,9 +202,6 @@ commands:
adminvoteDownloadJenkins:
description: Command Alias
aliases: avDownloadJenkins
adminvoteForceVoteParty:
description: Command Alias
aliases: avForceVoteParty
adminvoteSetRequestMethod:
description: Command Alias
aliases: avSetRequestMethod
@@ -215,9 +214,6 @@ commands:
adminvoteResetPoints:
description: Command Alias
aliases: avResetPoints
adminvoteVotePartyExtraRequired:
description: Command Alias
aliases: avVotePartyExtraRequired
adminvoteRunCMD:
description: Command Alias
aliases: avRunCMD
+12 -4
View File
@@ -1,10 +1,8 @@
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.bencodez</groupId>
<artifactId>votingplugin</artifactId>
<version>6.7</version>
<version>6.8.1</version>
<packaging>jar</packaging>
<name>VotingPlugin</name>
<properties>
@@ -213,8 +211,18 @@
<id>bencodez repo</id>
<url>https://nexus.bencodez.com/repository/maven-public/</url>
</repository>
<repository>
<id>jitpack.io</id>
<url>https://jitpack.io</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>com.github.limework</groupId>
<artifactId>redisbungee</artifactId>
<version>0.6.5</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.spigotmc</groupId>
<artifactId>spigot-api</artifactId>
@@ -6,10 +6,13 @@ import java.util.UUID;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
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.events.DateChangedEvent;
import com.bencodez.advancedcore.bungeeapi.pluginmessage.PluginMessageHandler;
import com.bencodez.advancedcore.bungeeapi.sockets.ClientHandler;
import com.bencodez.advancedcore.bungeeapi.sockets.SocketHandler;
@@ -23,7 +26,7 @@ import com.bencodez.votingplugin.user.VotingPluginUser;
import lombok.Getter;
public class BungeeHandler {
public class BungeeHandler implements Listener {
@Getter
private ClientHandler clientHandler;
@@ -34,6 +37,12 @@ public class BungeeHandler {
private VotingPluginMain plugin;
@Getter
private int bungeeVotePartyCurrent = 0;
@Getter
private int bungeeVotePartyRequired = 0;
@Getter
private SocketHandler socketHandler;
@@ -44,6 +53,16 @@ public class BungeeHandler {
public void close() {
socketHandler.closeConnection();
clientHandler.stopConnection();
plugin.getServerData().setBungeeVotePartyCurrent(bungeeVotePartyCurrent);
plugin.getServerData().setBungeeVotePartyRequired(bungeeVotePartyRequired);
}
@EventHandler
public void onDateChange(DateChangedEvent event) {
if (method.equals(BungeeMethod.PLUGINMESSAGING)) {
plugin.getPluginMessaging().sendPluginMessage("timeupdate", plugin.getServerDataFile().getPrevMonth() + "//"
+ plugin.getServerDataFile().getPrevDay() + "//" + plugin.getServerDataFile().getPrevWeekDay());
}
}
public void load() {
@@ -58,7 +77,10 @@ public class BungeeHandler {
} else if (method.equals(BungeeMethod.PLUGINMESSAGING)) {
plugin.registerBungeeChannels("vp:vp");
plugin.getPluginMessaging().setDebug(true);
bungeeVotePartyCurrent = plugin.getServerData().getBungeeVotePartyCurrent();
bungeeVotePartyRequired = plugin.getServerData().getBungeeVotePartyRequired();
plugin.getPluginMessaging().setDebug(plugin.getBungeeSettings().isBungeeDebug());
plugin.getPluginMessaging().add(new PluginMessageHandler("Vote") {
@Override
@@ -82,6 +104,10 @@ public class BungeeHandler {
BungeeMessageData text = new BungeeMessageData(args.get(6));
bungeeVotePartyCurrent = text.getVotePartyCurrent();
bungeeVotePartyRequired = text.getVotePartyRequired();
plugin.getPlaceholders().onBungeeVotePartyUpdate();
boolean setTotals = Boolean.valueOf(args.get(7));
user.clearCache();
@@ -139,6 +165,11 @@ public class BungeeHandler {
String service = args.get(2);
long time = Long.parseLong(args.get(3));
BungeeMessageData text = new BungeeMessageData(args.get(6));
bungeeVotePartyCurrent = text.getVotePartyCurrent();
bungeeVotePartyRequired = text.getVotePartyRequired();
plugin.getPlaceholders().onBungeeVotePartyUpdate();
plugin.debug(
"pluginmessaging voteonline received from " + player + "/" + uuid + " on " + service);
VotingPluginUser user = UserManager.getInstance().getVotingPluginUser(UUID.fromString(uuid),
@@ -202,6 +233,11 @@ public class BungeeHandler {
user.offVote();
if (args.size() > 2) {
bungeeVotePartyCurrent = Integer.parseInt(args.get(1));
bungeeVotePartyRequired = Integer.parseInt(args.get(2));
}
plugin.setUpdate(true);
}
});
@@ -1103,7 +1103,7 @@ public class VotingPluginMain extends AdvancedCorePlugin {
plugin.getLogger().info("Enabled VotingPlugin " + plugin.getDescription().getVersion());
if (getProfile().contains("dev")) {
plugin.getLogger().warning(
plugin.getLogger().info(
"Using dev build, this is not a stable build, use at your own risk. Build number: " + buildNumber);
}
@@ -1116,7 +1116,7 @@ public class VotingPluginMain extends AdvancedCorePlugin {
if (!site.hasRewards() && !hasRewards) {
issues = false;
plugin.getLogger().warning("No rewards detected for the site: " + site.getKey()
+ ". See https://github.com/BenCodez/VotingPlugin/wiki/Rewards on how to add rewards");
+ ". See https://github.com/BenCodez/VotingPlugin/wiki/Rewards");
}
boolean contains = false;
@@ -1215,8 +1215,10 @@ public class VotingPluginMain extends AdvancedCorePlugin {
// /adminvote, /av
getCommand("adminvote").setExecutor(new CommandAdminVote(this));
getCommand("adminvote").setTabCompleter(new AdminVoteTabCompleter());
getCommand("adminvote").setPermission("VotingPlugin.Commands.AdminVote");
getCommand("av").setExecutor(new CommandAdminVote(this));
getCommand("av").setTabCompleter(new AdminVoteTabCompleter());
getCommand("av").setPermission("VotingPlugin.Commands.AdminVote");
Permission perm = Bukkit.getPluginManager().getPermission("VotingPlugin.Player");
if (perm != null) {
@@ -1297,7 +1299,9 @@ public class VotingPluginMain extends AdvancedCorePlugin {
loadDirectlyDefined();
reloadAdvancedCore(userStorage);
getOptions().setServer(bungeeSettings.getServer());
placeholders.load();
if (userStorage) {
placeholders.load();
}
voteReminding.loadRemindChecking();
coolDownCheck.checkEnabled();
@@ -1342,98 +1346,117 @@ public class VotingPluginMain extends AdvancedCorePlugin {
update = false;
synchronized (plugin) {
getUserManager().getDataManager().clearCacheBasic();
if (plugin != null && plugin.isEnabled()) {
getUserManager().getDataManager().clearCacheBasic();
plugin.debug("Starting background task, current cached users: "
+ plugin.getUserManager().getDataManager().getUserDataCache().keySet().size());
try {
boolean extraBackgroundUpdate = configFile.isExtraBackgroundUpdate();
long startTime = System.currentTimeMillis();
LinkedHashMap<TopVoterPlayer, HashMap<VoteSite, LocalDateTime>> voteToday = new LinkedHashMap<TopVoterPlayer, HashMap<VoteSite, LocalDateTime>>();
LinkedHashMap<TopVoter, LinkedHashMap<TopVoterPlayer, Integer>> tempTopVoter = new LinkedHashMap<TopVoter, LinkedHashMap<TopVoterPlayer, Integer>>();
ArrayList<TopVoter> topVotersToCheck = new ArrayList<TopVoter>();
for (TopVoter top : TopVoter.values()) {
if (plugin.getConfigFile().getLoadTopVoter(top)) {
topVotersToCheck.add(top);
tempTopVoter.put(top, new LinkedHashMap<TopVoterPlayer, Integer>());
}
}
boolean topVoterIgnorePermissionUse = plugin.getConfigFile().getTopVoterIgnorePermission();
ArrayList<String> blackList = plugin.getConfigFile().getBlackList();
ArrayList<String> uuids = UserManager.getInstance().getAllUUIDs();
int currentDay = LocalDateTime.now().getDayOfMonth();
for (String uuid : uuids) {
if (uuid != null && !uuid.isEmpty()) {
VotingPluginUser user = UserManager.getInstance()
.getVotingPluginUser(UUID.fromString(uuid), false);
user.dontCache();
user.tempCache();
user.getUserData().updateCacheWithTemp();
if (!user.isBanned() && !blackList.contains(user.getPlayerName())) {
if (!topVoterIgnorePermissionUse || !user.isTopVoterIgnore()) {
for (TopVoter top : topVotersToCheck) {
int total = user.getTotal(top);
if (total > 0) {
tempTopVoter.get(top).put(user.getTopVoterPlayer(), total);
}
}
}
HashMap<VoteSite, LocalDateTime> times = new HashMap<VoteSite, LocalDateTime>();
for (Entry<VoteSite, Long> entry : user.getLastVotes().entrySet()) {
if (entry.getKey().isEnabled() && !entry.getKey().isHidden()) {
long time = entry.getValue();
if ((currentDay == MiscUtils.getInstance().getDayFromMili(time))
&& (LocalDateTime.now().getMonthValue() == MiscUtils
.getInstance().getMonthFromMili(time))
&& (LocalDateTime.now().getYear() == MiscUtils.getInstance()
.getYearFromMili(time))) {
times.put(entry.getKey(), LocalDateTime.ofInstant(
Instant.ofEpochMilli(time), ZoneId.systemDefault()));
}
}
}
if (times.keySet().size() > 0) {
voteToday.put(user.getTopVoterPlayer(), times);
}
}
if (!extraBackgroundUpdate) {
if (user.isOnline()) {
user.offVote();
}
}
user.clearTempCache();
user = null;
}
}
update = false;
long time1 = ((System.currentTimeMillis() - startTime) / 1000);
plugin.debug("Finished loading player data in " + time1 + " seconds, " + uuids.size()
+ " users, " + plugin.getStorageType().toString());
time1 = System.currentTimeMillis();
topVoterHandler.updateTopVoters(tempTopVoter);
setVoteToday(voteToday);
serverData.updateValues();
getSigns().updateSigns();
tempTopVoter = null;
time1 = ((System.currentTimeMillis() - time1) / 1000);
long totalTime = ((System.currentTimeMillis() - startTime) / 1000);
plugin.debug("Background task finished. Final processing took " + time1
+ " seconds. Total time: " + totalTime + " seconds");
plugin.extraDebug("Current cached users: "
plugin.debug("Starting background task, current cached users: "
+ plugin.getUserManager().getDataManager().getUserDataCache().keySet().size());
checkFirstTimeLoaded();
} catch (Exception ex) {
plugin.getLogger().info("Looks like something went wrong");
ex.printStackTrace();
placeholders.onUpdate();
int dataLoadLimit = getConfigFile().getPlayerDataLoadLimit();
try {
boolean extraBackgroundUpdate = configFile.isExtraBackgroundUpdate();
long startTime = System.currentTimeMillis();
LinkedHashMap<TopVoterPlayer, HashMap<VoteSite, LocalDateTime>> voteToday = new LinkedHashMap<TopVoterPlayer, HashMap<VoteSite, LocalDateTime>>();
LinkedHashMap<TopVoter, LinkedHashMap<TopVoterPlayer, Integer>> tempTopVoter = new LinkedHashMap<TopVoter, LinkedHashMap<TopVoterPlayer, Integer>>();
ArrayList<TopVoter> topVotersToCheck = new ArrayList<TopVoter>();
for (TopVoter top : TopVoter.values()) {
if (plugin.getConfigFile().getLoadTopVoter(top)) {
topVotersToCheck.add(top);
tempTopVoter.put(top, new LinkedHashMap<TopVoterPlayer, Integer>());
}
}
boolean topVoterIgnorePermissionUse = plugin.getConfigFile()
.getTopVoterIgnorePermission();
ArrayList<String> blackList = plugin.getConfigFile().getBlackList();
ArrayList<String> uuids = UserManager.getInstance().getAllUUIDs();
int currentDay = LocalDateTime.now().getDayOfMonth();
int currentDataLoad = 0;
for (String uuid : uuids) {
if (uuid != null && !uuid.isEmpty()) {
VotingPluginUser user = UserManager.getInstance()
.getVotingPluginUser(UUID.fromString(uuid), false);
user.dontCache();
user.tempCache();
user.getUserData().updateCacheWithTemp();
if (!user.isBanned() && !blackList.contains(user.getPlayerName())) {
if (!topVoterIgnorePermissionUse || !user.isTopVoterIgnore()) {
for (TopVoter top : topVotersToCheck) {
int total = user.getTotal(top);
if (total > 0) {
tempTopVoter.get(top).put(user.getTopVoterPlayer(), total);
}
}
}
HashMap<VoteSite, LocalDateTime> times = new HashMap<VoteSite, LocalDateTime>();
for (Entry<VoteSite, Long> entry : user.getLastVotes().entrySet()) {
if (entry.getKey().isEnabled() && !entry.getKey().isHidden()) {
long time = entry.getValue();
if ((currentDay == MiscUtils.getInstance().getDayFromMili(time))
&& (LocalDateTime.now().getMonthValue() == MiscUtils
.getInstance().getMonthFromMili(time))
&& (LocalDateTime.now().getYear() == MiscUtils.getInstance()
.getYearFromMili(time))) {
times.put(entry.getKey(), LocalDateTime.ofInstant(
Instant.ofEpochMilli(time), ZoneId.systemDefault()));
}
}
}
if (times.keySet().size() > 0) {
voteToday.put(user.getTopVoterPlayer(), times);
}
}
if (!extraBackgroundUpdate) {
if (user.isOnline()) {
user.offVote();
}
}
plugin.getPlaceholders().onUpdate(user);
user.clearTempCache();
user = null;
if (dataLoadLimit > 0) {
currentDataLoad++;
if (currentDataLoad >= dataLoadLimit) {
currentDataLoad -= dataLoadLimit;
Thread.sleep(1000);
}
}
}
}
update = false;
long time1 = ((System.currentTimeMillis() - startTime) / 1000);
plugin.debug("Finished loading player data in " + time1 + " seconds, " + uuids.size()
+ " users, " + plugin.getStorageType().toString() + ", data load limit: "
+ dataLoadLimit);
time1 = System.currentTimeMillis();
topVoterHandler.updateTopVoters(tempTopVoter);
setVoteToday(voteToday);
serverData.updateValues();
getSigns().updateSigns();
tempTopVoter = null;
time1 = ((System.currentTimeMillis() - time1) / 1000);
long totalTime = ((System.currentTimeMillis() - startTime) / 1000);
plugin.debug("Background task finished. Final processing took " + time1
+ " seconds. Total time: " + totalTime + " seconds");
plugin.extraDebug("Current cached users: "
+ plugin.getUserManager().getDataManager().getUserDataCache().keySet().size());
checkFirstTimeLoaded();
} catch (Exception ex) {
if (plugin != null) {
plugin.getLogger().info("Looks like something went wrong");
}
ex.printStackTrace();
}
}
}
@@ -7,7 +7,7 @@ import lombok.Getter;
public class BungeeMessageData {
// Message string
// alltimetotal//monthtotal//weeklytotal//dailytotal//points//milestonecount
// alltimetotal//monthtotal//weeklytotal//dailytotal//points//milestonecount//votepartycurrent//votepartyrequired
@Getter
private int allTimeTotal = 0;
@@ -21,15 +21,21 @@ public class BungeeMessageData {
private int points = 0;
@Getter
private int weeklyTotal = 0;
@Getter
private int votePartyCurrent = 0;
@Getter
private int votePartyRequired = 0;
public BungeeMessageData(int allTimeTotal, int monthTotal, int weeklyTotal, int dailyTotal, int points,
int milestoneCount) {
int milestoneCount, int votePartyCurrent, int votePartyRequired) {
this.allTimeTotal = allTimeTotal;
this.monthTotal = monthTotal;
this.weeklyTotal = weeklyTotal;
this.dailyTotal = dailyTotal;
this.points = points;
this.milestoneCount = milestoneCount;
this.votePartyCurrent = votePartyCurrent;
this.votePartyRequired = votePartyRequired;
}
public BungeeMessageData(String str) {
@@ -42,12 +48,16 @@ public class BungeeMessageData {
points = Integer.parseInt(data[4]);
milestoneCount = Integer.parseInt(data[5]);
}
if (data.length >= 8) {
votePartyCurrent = Integer.parseInt(data[6]);
votePartyRequired = Integer.parseInt(data[7]);
}
}
@Override
public String toString() {
return allTimeTotal + "//" + monthTotal + "//" + weeklyTotal + "//" + dailyTotal + "//" + points + "//"
+ milestoneCount;
+ milestoneCount + "//" + votePartyCurrent + "//" + votePartyRequired;
}
}
@@ -33,6 +33,10 @@ public class Config {
return getData().getBoolean("Broadcast", false);
}
public boolean getRedisSupport() {
return getData().getBoolean("RedisSupport", false);
}
public String getBungeeHost() {
return getData().getString("BungeeServer.Host", "");
}
@@ -0,0 +1,48 @@
package com.bencodez.votingplugin.bungee;
import com.imaginarycode.minecraft.redisbungee.RedisBungeeAPI;
import com.imaginarycode.minecraft.redisbungee.events.PlayerChangedServerNetworkEvent;
import com.imaginarycode.minecraft.redisbungee.events.PlayerJoinedNetworkEvent;
import lombok.Getter;
import net.md_5.bungee.api.connection.ProxiedPlayer;
import net.md_5.bungee.api.plugin.Listener;
import net.md_5.bungee.event.EventHandler;
public class RedisBungee implements Listener {
@Getter
private boolean enabled;
private VotingPluginBungee plugin;
public RedisBungee(VotingPluginBungee plugin) {
this.plugin = plugin;
if (plugin.getConfig().getRedisSupport()) {
plugin.getProxy().getPluginManager().registerListener(plugin, this);
plugin.getLogger().info("Loaded expiremental redis support");
enabled = true;
} else {
enabled = false;
}
}
@EventHandler
public void playerJoinedNetworkEvent(PlayerJoinedNetworkEvent event) {
plugin.login(plugin.getProxy().getPlayer(event.getUuid()));
}
@EventHandler
public void playerChangedServerNetworkEventt(PlayerChangedServerNetworkEvent event) {
plugin.login(plugin.getProxy().getPlayer(event.getUuid()));
}
public boolean isOnline(ProxiedPlayer p) {
return RedisBungeeAPI.getRedisBungeeApi().isPlayerOnline(p.getUniqueId());
}
public void destroy() {
if (!enabled) {
return;
}
plugin.getProxy().getPluginManager().unregisterListener(this);
}
}
@@ -0,0 +1,24 @@
package com.bencodez.votingplugin.bungee;
import lombok.Getter;
import lombok.Setter;
public abstract class TimeHandle {
@Getter
@Setter
private String month;
@Getter
@Setter
private int day;
@Getter
@Setter
private int week;
public TimeHandle(String month, int day, int week) {
this.month = month;
this.day = day;
this.week = week;
}
public abstract void save();
}
@@ -21,11 +21,13 @@ import java.util.List;
import java.util.Map.Entry;
import java.util.UUID;
import java.util.concurrent.TimeUnit;
import java.util.regex.Pattern;
import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream;
import com.bencodez.advancedcore.api.misc.ArrayUtils;
import com.bencodez.advancedcore.api.misc.encryption.EncryptionHandler;
import com.bencodez.advancedcore.api.misc.jsonparser.JsonParser;
import com.bencodez.advancedcore.api.user.usercache.value.DataValue;
import com.bencodez.advancedcore.api.user.usercache.value.DataValueInt;
import com.bencodez.advancedcore.api.user.usercache.value.DataValueString;
@@ -36,7 +38,6 @@ import com.bencodez.advancedcore.bungeeapi.sockets.SocketHandler;
import com.bencodez.advancedcore.bungeeapi.sockets.SocketReceiver;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import lombok.Getter;
import net.md_5.bungee.api.ChatColor;
@@ -80,6 +81,12 @@ public class VotingPluginBungee extends Plugin implements Listener {
private boolean votifierEnabled = true;
@Getter
private RedisBungee redis;
@Getter
private TimeHandle timeHandle;
public synchronized void checkCachedVotes(String server) {
if (getProxy().getServerInfo(server) != null) {
if (!getProxy().getServerInfo(server).getPlayers().isEmpty()) {
@@ -91,7 +98,7 @@ public class VotingPluginBungee extends Plugin implements Listener {
boolean toSend = true;
if (getConfig().getWaitForUserOnline()) {
ProxiedPlayer p = getProxy().getPlayer(UUID.fromString(cache.getUuid()));
if (p == null || !p.isConnected()) {
if (isOnline(p)) {
toSend = false;
} else if (p != null && p.isConnected()
&& !p.getServer().getInfo().getName().equals(server)) {
@@ -120,7 +127,7 @@ public class VotingPluginBungee extends Plugin implements Listener {
}
public synchronized void checkOnlineVotes(ProxiedPlayer player, String uuid, String server) {
if (player != null && player.isConnected() && cachedOnlineVotes.containsKey(uuid)) {
if (isOnline(player) && cachedOnlineVotes.containsKey(uuid)) {
ArrayList<OfflineBungeeVote> c = cachedOnlineVotes.get(uuid);
if (!c.isEmpty()) {
if (server == null) {
@@ -160,7 +167,7 @@ public class VotingPluginBungee extends Plugin implements Listener {
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(inputStream));
// Parse JSON response and get UUID
JsonElement element = new JsonParser().parse(bufferedReader);
JsonElement element = JsonParser.parseReader(bufferedReader);
JsonObject object = element.getAsJsonObject();
String uuidAsString = object.get("id").getAsString();
@@ -312,11 +319,15 @@ public class VotingPluginBungee extends Plugin implements Listener {
}
}
}
timeHandle.save();
voteCacheFile.save();
nonVotedPlayersCache.save();
if (mysql != null) {
mysql.shutdown();
}
if (redis != null) {
redis.destroy();
}
getLogger().info("VotingPlugin disabled");
}
@@ -335,9 +346,16 @@ public class VotingPluginBungee extends Plugin implements Listener {
} catch (Exception e) {
}
}
config = new Config(this);
config.load();
try {
redis = new RedisBungee(this);
} catch (Exception e) {
e.printStackTrace();
}
getProxy().getPluginManager().registerCommand(this, new VotingPluginBungeeCommand(this));
boolean mysqlLoaded = true;
@@ -366,6 +384,18 @@ public class VotingPluginBungee extends Plugin implements Listener {
nonVotedPlayersCache = new NonVotedPlayersCache(this);
nonVotedPlayersCache.load();
timeHandle = new TimeHandle(voteCacheFile.getData().getString("Time.Month", ""),
voteCacheFile.getData().getInt("Time.Day"), voteCacheFile.getData().getInt("Time.Week")) {
@Override
public void save() {
voteCacheFile.getData().set("Time.Month", timeHandle.getMonth());
voteCacheFile.getData().set("Time.Day", timeHandle.getDay());
voteCacheFile.getData().set("Time.Week", timeHandle.getWeek());
}
};
if (method.equals(BungeeMethod.PLUGINMESSAGING)) {
try {
@@ -510,8 +540,44 @@ public class VotingPluginBungee extends Plugin implements Listener {
@EventHandler
public void onLogin(PostLoginEvent event) {
if (nonVotedPlayersCache != null) {
nonVotedPlayersCache.addPlayer(event.getPlayer());
getProxy().getScheduler().runAsync(this, new Runnable() {
@Override
public void run() {
if (nonVotedPlayersCache != null) {
nonVotedPlayersCache.addPlayer(event.getPlayer());
}
}
});
}
public boolean isOnline(ProxiedPlayer p) {
if (p != null) {
if (redis != null && redis.isEnabled()) {
return redis.isOnline(p);
} else {
return p.isConnected();
}
}
return false;
}
public void login(ProxiedPlayer p) {
if (isOnline(p)) {
if (p.getServer() != null && p.getServer().getInfo() != null) {
final String server = p.getServer().getInfo().getName();
final ProxiedPlayer proixedPlayer = p;
getProxy().getScheduler().runAsync(this, new Runnable() {
@Override
public void run() {
checkCachedVotes(server);
checkOnlineVotes(proixedPlayer, proixedPlayer.getUniqueId().toString(), server);
}
});
}
}
}
@@ -547,23 +613,17 @@ public class VotingPluginBungee extends Plugin implements Listener {
String player = in.readUTF();
debug("Login: " + player);
ProxiedPlayer p = getProxy().getPlayer(player);
if (p != null && p.isConnected()) {
if (p.getServer() != null && p.getServer().getInfo() != null) {
final String server = p.getServer().getInfo().getName();
final ProxiedPlayer proixedPlayer = p;
getProxy().getScheduler().runAsync(this, new Runnable() {
@Override
public void run() {
checkCachedVotes(server);
checkOnlineVotes(proixedPlayer, proixedPlayer.getUniqueId().toString(), server);
}
});
}
}
login(p);
return;
} else if (subchannel.equalsIgnoreCase("timeupdate")) {
String str = in.readUTF();
String[] data = str.split(Pattern.quote("//"));
if (data.length == 3) {
timeHandle.setMonth(data[0]);
timeHandle.setDay(Integer.parseInt(data[1]));
timeHandle.setWeek(Integer.parseInt(data[2]));
}
} else {
// reforward message
out.writeUTF(subchannel);
out.writeInt(size);
@@ -713,6 +773,7 @@ public class VotingPluginBungee extends Plugin implements Listener {
String uuid = getUUID(player);
if (uuid.isEmpty()) {
if (config.getAllowUnJoined()) {
debug("Fetching UUID online, since allowunjoined is enabled");
UUID u = null;
try {
u = fetchUUID(player);
@@ -736,6 +797,8 @@ public class VotingPluginBungee extends Plugin implements Listener {
BungeeMessageData text = null;
addVoteParty();
if (getConfig().getBungeeManageTotals()) {
if (mysql == null) {
@@ -755,7 +818,8 @@ public class VotingPluginBungee extends Plugin implements Listener {
int dailyTotal = getValue(data, "DailyTotal", 1);
int points = getValue(data, "Points", getConfig().getPointsOnVote());
int milestoneCount = getValue(data, "MilestoneCount", 1);
text = new BungeeMessageData(allTimeTotal, monthTotal, weeklyTotal, dailyTotal, points, milestoneCount);
text = new BungeeMessageData(allTimeTotal, monthTotal, weeklyTotal, dailyTotal, points, milestoneCount,
votePartyVotes, currentVotePartyVotesRequired);
ArrayList<Column> update = new ArrayList<Column>();
update.add(new Column("AllTimeTotal", new DataValueInt(allTimeTotal)));
update.add(new Column("MonthTotal", new DataValueInt(monthTotal)));
@@ -766,11 +830,9 @@ public class VotingPluginBungee extends Plugin implements Listener {
debug("Setting totals " + text.toString());
mysql.update(uuid, update);
} else {
text = new BungeeMessageData(0, 0, 0, 0, 0, 0);
text = new BungeeMessageData(0, 0, 0, 0, 0, 0, votePartyVotes, currentVotePartyVotesRequired);
}
addVoteParty();
long time = LocalDateTime.now().atZone(ZoneId.systemDefault()).toInstant().toEpochMilli();
if (method.equals(BungeeMethod.PLUGINMESSAGING)) {
@@ -781,7 +843,7 @@ public class VotingPluginBungee extends Plugin implements Listener {
ServerInfo info = getProxy().getServerInfo(s);
boolean forceCache = false;
ProxiedPlayer p = getProxy().getPlayer(UUID.fromString(uuid));
if ((p == null || !p.isConnected()) && getConfig().getWaitForUserOnline()) {
if (!isOnline(p) && getConfig().getWaitForUserOnline()) {
forceCache = true;
debug("Forcing vote to cache");
}
@@ -810,8 +872,7 @@ public class VotingPluginBungee extends Plugin implements Listener {
}
} else {
ProxiedPlayer p = getProxy().getPlayer(UUID.fromString(uuid));
if (p != null && p.isConnected()
&& !config.getBlockedServers().contains(p.getServer().getInfo().getName())) {
if (isOnline(p) && !config.getBlockedServers().contains(p.getServer().getInfo().getName())) {
sendPluginMessageServer(p.getServer().getInfo().getName(), "VoteOnline", player, uuid, service,
"" + time, Boolean.TRUE.toString(), "" + realVote, text.toString(),
"" + getConfig().getBungeeManageTotals(), "" + BungeeVersion.getPluginMessageVersion(),
@@ -829,7 +890,8 @@ public class VotingPluginBungee extends Plugin implements Listener {
debug("Caching online vote for " + player + " on " + service);
}
for (String s : getProxy().getServers().keySet()) {
sendPluginMessageServer(s, "VoteUpdate", uuid);
sendPluginMessageServer(s, "VoteUpdate", uuid, "" + votePartyVotes,
"" + currentVotePartyVotesRequired);
if (config.getBroadcast()) {
sendPluginMessageServer(s, "VoteBroadcast", uuid, player, service);
}
@@ -5,6 +5,8 @@ import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import org.checkerframework.checker.nullness.qual.NonNull;
import com.bencodez.advancedcore.bungeeapi.velocity.VelocityYMLFile;
import ninja.leaping.configurate.ConfigurationNode;
@@ -99,12 +101,8 @@ public class Config extends VelocityYMLFile {
return getNode("SpigotServers", s);
}
public Collection<String> getSpigotServers() {
ArrayList<String> list = new ArrayList<String>();
for (ConfigurationNode conf : getNode("SpigotServers").getChildrenList()) {
list.add(conf.getKey().toString());
}
return list;
public @NonNull Collection<? extends ConfigurationNode> getSpigotServers() {
return getNode("SpigotServers").getChildrenMap().values();
}
public boolean getWaitForUserOnline() {
@@ -28,6 +28,7 @@ import java.util.Timer;
import java.util.TimerTask;
import java.util.UUID;
import java.util.concurrent.TimeUnit;
import java.util.regex.Pattern;
import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream;
@@ -37,6 +38,7 @@ import org.slf4j.Logger;
import com.bencodez.advancedcore.api.misc.ArrayUtils;
import com.bencodez.advancedcore.api.misc.encryption.EncryptionHandler;
import com.bencodez.advancedcore.api.misc.jsonparser.JsonParser;
import com.bencodez.advancedcore.api.user.usercache.value.DataValue;
import com.bencodez.advancedcore.api.user.usercache.value.DataValueInt;
import com.bencodez.advancedcore.api.user.usercache.value.DataValueString;
@@ -49,9 +51,9 @@ import com.bencodez.votingplugin.bungee.BungeeMessageData;
import com.bencodez.votingplugin.bungee.BungeeMethod;
import com.bencodez.votingplugin.bungee.BungeeVersion;
import com.bencodez.votingplugin.bungee.OfflineBungeeVote;
import com.bencodez.votingplugin.bungee.TimeHandle;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import com.google.inject.Inject;
import com.velocitypowered.api.command.CommandMeta;
import com.velocitypowered.api.event.Subscribe;
@@ -108,6 +110,9 @@ public class VotingPluginVelocity {
private Timer timer;
@Getter
private TimeHandle timeHandle;
@Inject
public VotingPluginVelocity(ProxyServer server, Logger logger, Metrics.Factory metricsFactory,
@DataDirectory Path dataDirectory) {
@@ -199,7 +204,7 @@ public class VotingPluginVelocity {
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(inputStream));
// Parse JSON response and get UUID
JsonElement element = new JsonParser().parse(bufferedReader);
JsonElement element = JsonParser.parseReader(bufferedReader);
JsonObject object = element.getAsJsonObject();
String uuidAsString = object.get("id").getAsString();
@@ -334,6 +339,14 @@ public class VotingPluginVelocity {
}
}
return;
} else if (subchannel.equalsIgnoreCase("timeupdate")) {
String str = in.readUTF();
String[] data = str.split(Pattern.quote("//"));
if (data.length == 3) {
timeHandle.setMonth(data[0]);
timeHandle.setDay(Integer.parseInt(data[1]));
timeHandle.setWeek(Integer.parseInt(data[2]));
}
} else {
// reforward message
@@ -376,6 +389,7 @@ public class VotingPluginVelocity {
}
}
}
timeHandle.save();
voteCacheFile.save();
nonVotedPlayersCache.save();
if (mysql != null) {
@@ -434,6 +448,18 @@ public class VotingPluginVelocity {
voteCacheFile = new VoteCache(new File(dataDirectory.toFile(), "votecache.yml"));
nonVotedPlayersCache = new NonVotedPlayersCache(
new File(dataDirectory.toFile(), "nonvotedplayerscache.yml"), this);
timeHandle = new TimeHandle(voteCacheFile.getNode("Time", "Month").getString(""),
voteCacheFile.getNode("Time", "Day").getInt(), voteCacheFile.getNode("Time", "Week").getInt()) {
@Override
public void save() {
voteCacheFile.getNode("Time", "Month").setValue(timeHandle.getMonth());
voteCacheFile.getNode("Time", "Day").setValue(timeHandle.getDay());
voteCacheFile.getNode("Time", "Week").setValue(timeHandle.getWeek());
}
};
if (method.equals(BungeeMethod.PLUGINMESSAGING)) {
try {
for (String serverToCheck : voteCacheFile.getServers()) {
@@ -526,10 +552,10 @@ public class VotingPluginVelocity {
clientHandles = new HashMap<String, ClientHandler>();
List<String> l = config.getBlockedServers();
for (String s : config.getSpigotServers()) {
for (ConfigurationNode d : config.getSpigotServers()) {
String s = d.getKey().toString();
if (!l.contains(s)) {
ConfigurationNode d = config.getSpigotServerConfiguration(s);
clientHandles.put(s, new ClientHandler(d.getNode("Host").getString(""),
clientHandles.put(s, new ClientHandler(d.getNode("Host").getString("0.0.0.0"),
d.getNode("Port").getInt(1298), encryptionHandler, config.getDebug()));
}
}
@@ -780,6 +806,7 @@ public class VotingPluginVelocity {
String uuid = getUUID(player);
if (uuid.isEmpty()) {
if (config.getAllowUnJoined()) {
debug("Fetching UUID online, since allowunjoined is enabled");
UUID u = null;
try {
u = fetchUUID(player);
@@ -803,6 +830,8 @@ public class VotingPluginVelocity {
BungeeMessageData text = null;
addVoteParty();
if (getConfig().getBungeeManageTotals()) {
if (mysql == null) {
@@ -822,7 +851,8 @@ public class VotingPluginVelocity {
int dailyTotal = getValue(data, "DailyTotal", 1);
int points = getValue(data, "Points", getConfig().getPointsOnVote());
int milestoneCount = getValue(data, "MilestoneCount", 1);
text = new BungeeMessageData(allTimeTotal, monthTotal, weeklyTotal, dailyTotal, points, milestoneCount);
text = new BungeeMessageData(allTimeTotal, monthTotal, weeklyTotal, dailyTotal, points, milestoneCount,
votePartyVotes, currentVotePartyVotesRequired);
ArrayList<Column> update = new ArrayList<Column>();
update.add(new Column("AllTimeTotal", new DataValueInt(allTimeTotal)));
update.add(new Column("MonthTotal", new DataValueInt(monthTotal)));
@@ -833,7 +863,7 @@ public class VotingPluginVelocity {
debug("Setting totals " + text.toString());
mysql.update(uuid, update);
} else {
text = new BungeeMessageData(0, 0, 0, 0, 0, 0);
text = new BungeeMessageData(0, 0, 0, 0, 0, 0, votePartyVotes, currentVotePartyVotesRequired);
}
/*
@@ -908,7 +938,8 @@ public class VotingPluginVelocity {
}
for (RegisteredServer s : server.getAllServers()) {
sendPluginMessageServer(s, "VoteUpdate", uuid);
sendPluginMessageServer(s, "VoteUpdate", uuid, "" + votePartyVotes,
"" + currentVotePartyVotesRequired);
if (config.getBroadcast()) {
sendPluginMessageServer(s, "VoteBroadcast", uuid, player, service);
}
@@ -318,6 +318,16 @@ public class CommandLoader {
+ user.getMilestoneCount());
user.setHasGotteMilestone(num, true);
}
} else {
if (user.hasGottenMilestone(num)) {
sendMessage(sender,
"&cMilestone " + num + " for " + user.getPlayerName()
+ " already given when it shouldn't be, Current AllTimeTotal: "
+ user.getTotal(TopVoter.AllTime) + ", Current MileStoneCount: "
+ user.getMilestoneCount());
user.setHasGotteMilestone(num, false);
}
}
}
}
@@ -428,7 +438,7 @@ public class CommandLoader {
public void execute(CommandSender sender, String[] args) {
int page = Integer.parseInt(args[1]);
new AdminVoteHelp(plugin, sender, page).open();
;
}
});
@@ -1153,16 +1163,6 @@ public class CommandLoader {
}
});
plugin.getAdminVoteCommand().add(new CommandHandler(new String[] { "SetVotePartyCount", "(number)" },
"VotingPlugin.Commands.AdminVote.SetVotePartyCount|" + adminPerm, "Set voteparty count") {
@Override
public void execute(CommandSender sender, String[] args) {
plugin.getVoteParty().setTotalVotes(Integer.parseInt(args[1]));
sendMessage(sender, "&cSet vote party count to " + args[1]);
}
});
plugin.getAdminVoteCommand().add(new CommandHandler(new String[] { "ClearOfflineVotes" },
"VotingPlugin.Commands.AdminVote.ClearOfflineVotes|" + adminPerm, "Clear all offline votes") {
@@ -1212,8 +1212,8 @@ public class CommandLoader {
});
plugin.getAdminVoteCommand()
.add(new CommandHandler(new String[] { "ForceVoteParty" },
"VotingPlugin.Commands.AdminVote.ForceVoteParty|" + adminPerm,
.add(new CommandHandler(new String[] { "VoteParty", "Force" },
"VotingPlugin.Commands.AdminVote.VoteParty.Force|" + adminPerm,
"Force a voteparty reward, resets vote count") {
@Override
@@ -1222,8 +1222,34 @@ public class CommandLoader {
}
});
plugin.getAdminVoteCommand().add(new CommandHandler(new String[] { "VoteParty", "SetVoteCount", "(Number)" },
"VotingPlugin.Commands.AdminVote.VoteParty.SetVoteCount|" + adminPerm, "Set voteparty count") {
@Override
public void execute(CommandSender sender, String[] args) {
int num = Integer.parseInt(args[2]);
if (num == 0) {
plugin.getVoteParty().reset(true);
sendMessage(sender, "&cVoteparty totals have been set to 0 and all been reset");
} else {
plugin.getVoteParty().setTotalVotes(num);
sendMessage(sender, "&cVoteparty total votes has been set to " + args[2]);
}
}
});
plugin.getAdminVoteCommand().add(new CommandHandler(new String[] { "VoteParty", "AddVoteCount", "(Number)" },
"VotingPlugin.Commands.AdminVote.VoteParty.SetVoteCount|" + adminPerm, "Add voteparty count") {
@Override
public void execute(CommandSender sender, String[] args) {
int num = plugin.getVoteParty().getTotalVotes() + Integer.parseInt(args[2]);
plugin.getVoteParty().setTotalVotes(num);
sendMessage(sender, "&cVoteparty total votes has been set to " + num);
}
});
plugin.getAdminVoteCommand()
.add(new CommandHandler(new String[] { "VotePartyExtraRequired", "(Number)" },
.add(new CommandHandler(new String[] { "VoteParty", "SetExtraRequired", "(Number)" },
"VotingPlugin.Commands.AdminVote.VoteParty.SetExtraRequired|" + adminPerm,
"Set VotePartyExtraRequired value") {
@@ -1380,7 +1406,7 @@ public class CommandLoader {
public void execute(CommandSender sender, String[] args) {
new AdminVotePlaceholdersPlayer(plugin, sender,
UserManager.getInstance().getVotingPluginUser(args[1])).open();
;
}
});
@@ -1499,7 +1525,6 @@ public class CommandLoader {
}
}
}
}
}
@@ -1734,6 +1759,26 @@ public class CommandLoader {
}
});
plugin.getVoteCommand().add(new CommandHandler(new String[] { "ToggleReminders" },
"VotingPlugin.Commands.Vote.ToggleReminders", "Enable/disable vote reminders", false) {
@Override
public void execute(CommandSender sender, String[] args) {
Player p = (Player) sender;
boolean value = false;
if (plugin.getVoteReminding().getRemindersEnabled().containsKey(p.getUniqueId())) {
value = !plugin.getVoteReminding().getRemindersEnabled().get(p.getUniqueId());
}
plugin.getVoteReminding().getRemindersEnabled().put(p.getUniqueId(), value);
if (value) {
sendMessage(sender, plugin.getConfigFile().getFormatCommandsVoteToggleRemindersEnabled());
} else {
sendMessage(sender, plugin.getConfigFile().getFormatCommandsVoteToggleRemindersDisabled());
}
}
});
if (plugin.getGui().getChestVoteShopEnabled()) {
plugin.getVoteCommand().add(new CommandHandler(new String[] { "Shop" },
"VotingPlugin.Commands.Vote.Shop|" + playerPerm, "Open VoteShop GUI", false) {
@@ -2003,7 +2048,8 @@ public class CommandLoader {
@Override
public void execute(CommandSender sender, String[] args) {
new VoteTopVoter(plugin, sender, null, top, 1).open(GUIMethod.valueOf(plugin.getGui().getGuiMethodTopVoter().toUpperCase()));
new VoteTopVoter(plugin, sender, null, top, 1)
.open(GUIMethod.valueOf(plugin.getGui().getGuiMethodTopVoter().toUpperCase()));
}
});
@@ -2013,7 +2059,8 @@ public class CommandLoader {
@Override
public void execute(CommandSender sender, String[] args) {
int page = Integer.parseInt(args[2]);
new VoteTopVoter(plugin, sender, null, top, page).open(GUIMethod.valueOf(plugin.getGui().getGuiMethodTopVoter().toUpperCase()));
new VoteTopVoter(plugin, sender, null, top, page)
.open(GUIMethod.valueOf(plugin.getGui().getGuiMethodTopVoter().toUpperCase()));
}
});
}
@@ -2025,7 +2072,8 @@ public class CommandLoader {
public void execute(CommandSender sender, String[] args) {
int page = Integer.parseInt(args[1]);
new VoteTopVoter(plugin, sender, null, TopVoter.getDefault(), page).open(GUIMethod.valueOf(plugin.getGui().getGuiMethodTopVoter().toUpperCase()));
new VoteTopVoter(plugin, sender, null, TopVoter.getDefault(), page)
.open(GUIMethod.valueOf(plugin.getGui().getGuiMethodTopVoter().toUpperCase()));
}
});
@@ -95,6 +95,15 @@ public class AdminVoteBungeeSettings extends GUIHandler {
}
}));
inv.addButton(new EditGUIButton(
new EditGUIValueBoolean("PerServerMilestones", plugin.getBungeeSettings().isPerServerMilestones()) {
@Override
public void setValue(Player player, boolean value) {
setPathData(getKey(), value);
}
}));
inv.addButton(new EditGUIButton(
new EditGUIValueBoolean("PerServerPoints", plugin.getBungeeSettings().isPerServerPoints()) {
@@ -11,6 +11,7 @@ import com.bencodez.advancedcore.api.bookgui.BookWrapper;
import com.bencodez.advancedcore.api.bookgui.Layout;
import com.bencodez.advancedcore.api.gui.GUIHandler;
import com.bencodez.advancedcore.api.gui.GUIMethod;
import com.bencodez.advancedcore.api.placeholder.NonPlayerPlaceHolder;
import com.bencodez.advancedcore.api.placeholder.PlaceHolder;
import com.bencodez.votingplugin.VotingPluginMain;
import com.bencodez.votingplugin.user.VotingPluginUser;
@@ -53,7 +54,7 @@ public class AdminVotePlaceholders extends GUIHandler {
book.addLayout(layout);
}
for (PlaceHolder<VotingPluginUser> placeholder : plugin.getPlaceholders().getNonPlayerPlaceholders()) {
for (NonPlayerPlaceHolder<VotingPluginUser> placeholder : plugin.getPlaceholders().getNonPlayerPlaceholders()) {
String msg = "";
String identifier = placeholder.getIdentifier();
if (identifier.endsWith("_")) {
@@ -92,7 +93,7 @@ public class AdminVotePlaceholders extends GUIHandler {
}
}
for (PlaceHolder<VotingPluginUser> placeholder : plugin.getPlaceholders().getNonPlayerPlaceholders()) {
for (NonPlayerPlaceHolder<VotingPluginUser> placeholder : plugin.getPlaceholders().getNonPlayerPlaceholders()) {
String identifier = placeholder.getIdentifier();
if (identifier.endsWith("_")) {
identifier += "#";
@@ -11,6 +11,7 @@ import com.bencodez.advancedcore.api.bookgui.BookWrapper;
import com.bencodez.advancedcore.api.bookgui.Layout;
import com.bencodez.advancedcore.api.gui.GUIHandler;
import com.bencodez.advancedcore.api.gui.GUIMethod;
import com.bencodez.advancedcore.api.placeholder.NonPlayerPlaceHolder;
import com.bencodez.advancedcore.api.placeholder.PlaceHolder;
import com.bencodez.votingplugin.VotingPluginMain;
import com.bencodez.votingplugin.user.UserManager;
@@ -43,7 +44,7 @@ public class AdminVotePlaceholdersPlayer extends GUIHandler {
if (identifier.endsWith("_")) {
identifier += "1";
}
String value = placeholder.placeholderRequest(user.getOfflinePlayer(), user, identifier);
String value = placeholder.placeholderRequest(user, identifier);
String msg = identifier + " = " + value;
Layout layout = new Layout(new ArrayList<String>(Arrays.asList("[Json]")));
layout.replaceTextComponent("[Json]", BookUtil.TextBuilder.of(msg).color(ChatColor.AQUA)
@@ -51,13 +52,13 @@ public class AdminVotePlaceholdersPlayer extends GUIHandler {
book.addLayout(layout);
}
for (PlaceHolder<VotingPluginUser> placeholder : plugin.getPlaceholders().getNonPlayerPlaceholders()) {
for (NonPlayerPlaceHolder<VotingPluginUser> placeholder : plugin.getPlaceholders().getNonPlayerPlaceholders()) {
String identifier = placeholder.getIdentifier();
if (identifier.endsWith("_")) {
identifier += "1";
}
String value = placeholder.placeholderRequest(user.getOfflinePlayer(), user, identifier);
String value = placeholder.placeholderRequest(identifier);
String msg = identifier + " = " + value;
Layout layout = new Layout(new ArrayList<String>(Arrays.asList("[Json]")));
@@ -81,18 +82,16 @@ public class AdminVotePlaceholdersPlayer extends GUIHandler {
if (identifier.endsWith("_")) {
identifier += "1";
}
msg.add("VotingPlugin_" + identifier + " = "
+ placeholder.placeholderRequest(user.getOfflinePlayer(), placeholderUser, identifier));
msg.add("VotingPlugin_" + identifier + " = " + placeholder.placeholderRequest(placeholderUser, identifier));
}
for (PlaceHolder<VotingPluginUser> placeholder : plugin.getPlaceholders().getNonPlayerPlaceholders()) {
for (NonPlayerPlaceHolder<VotingPluginUser> placeholder : plugin.getPlaceholders().getNonPlayerPlaceholders()) {
String identifier = placeholder.getIdentifier();
if (identifier.endsWith("_")) {
identifier += "1";
}
msg.add("VotingPlugin_" + identifier + " = "
+ placeholder.placeholderRequest(user.getOfflinePlayer(), placeholderUser, identifier));
msg.add("VotingPlugin_" + identifier + " = " + placeholder.placeholderRequest(identifier));
}
sendMessage(msg);
}
@@ -93,7 +93,7 @@ public class AdminVoteVoteParty extends GUIHandler {
}, new Number[] { 0, 10, 50, 100 })
.currentValue("" + plugin.getServerData().getVotePartyExtraRequired()).allowCustomOption(true)
.request(clickEvent.getPlayer());
;
}
});
@@ -73,7 +73,7 @@ public class AdminVoteCumulative extends GUIHandler {
}
}, options).allowCustomOption(false).usingMethod(InputMethod.INVENTORY)
.request(clickEvent.getPlayer());
;
}
});
@@ -62,7 +62,7 @@ public class AdminVoteCumulativeRemove extends GUIHandler {
new AdminVoteCumulative(plugin, p);
}
}.open();
;
}
});
@@ -62,7 +62,7 @@ public class AdminVoteMilestoneRemove extends GUIHandler {
new AdminVoteMilestones(plugin, p);
}
}.open();
;
}
});
@@ -73,7 +73,7 @@ public class AdminVoteMilestones extends GUIHandler {
}
}, options).allowCustomOption(false).usingMethod(InputMethod.INVENTORY)
.request(clickEvent.getPlayer());
;
}
});
@@ -64,7 +64,7 @@ public class AdminVoteVoteShopItemRemove extends GUIHandler {
new AdminVoteVoteShop(plugin, p).open();
}
}.open();
;
}
}.addData("ident", identifier));
@@ -49,7 +49,7 @@ public class AdminVoteVoteShopItems extends GUIHandler {
public void onClick(ClickEvent clickEvent) {
new AdminVoteVoteShopItem(plugin, clickEvent.getPlayer(), (String) getData("ident"))
.open(GUIMethod.CHEST);
;
}
}.addData("ident", identifier));
}
@@ -87,6 +87,10 @@ public class VoteBest extends GUIHandler {
}
});
if (plugin.getGui().isChestVoteBestBackButton()) {
inv.addButton(plugin.getCommandLoader().getBackButton(user));
}
inv.openInventory(player);
}
@@ -128,6 +128,12 @@ public class VoteGUI extends GUIHandler {
inv.dontClose();
}
if (player.getUniqueId().toString().equals(user.getUUID())) {
inv.requirePermission("VotingPlugin.Commands.Vote.GUI");
} else {
inv.requirePermission("VotingPlugin.Commands.Vote.GUI.Other");
}
inv.addPlaceholder("points", "" + user.getPoints());
inv.addPlaceholder("player", user.getPlayerName());
inv.addPlaceholder("top", plugin.getConfigFile().getVoteTopDefault());
@@ -171,6 +177,10 @@ public class VoteGUI extends GUIHandler {
new VoteShop(plugin, player, user).open(GUIMethod.CHEST);
} else if (slot.equalsIgnoreCase("lastmonth")) {
new VoteTopVoterLastMonth(plugin, player, user).open(GUIMethod.CHEST);
} else if (slot.equalsIgnoreCase("best")) {
new VoteBest(plugin, player, user).open(GUIMethod.CHEST);
} else if (slot.equalsIgnoreCase("streak")) {
new VoteStreak(plugin, player, user).open(GUIMethod.CHEST);
}
}
@@ -134,7 +134,7 @@ public class VoteShop extends GUIHandler {
}
} else {
new VoteShopConfirm(plugin, player, user, identifier).open(GUIMethod.CHEST);
;
}
} else {
user.sendMessage(plugin.getGui().getChestVoteShopLimitReached());
@@ -93,7 +93,7 @@ public class VoteShopConfirm extends GUIHandler {
if (plugin.getGui().getChestVoteShopCloseGUI(identifier)) {
event.getButton().getInv().closeInv(player, null);
} else {
new VoteShop(plugin, event.getPlayer(), user).open();;
new VoteShop(plugin, event.getPlayer(), user).open();
}
}
});
@@ -223,7 +223,7 @@ public class VoteURL extends GUIHandler {
public void onClick(ClickEvent clickEvent) {
new RewardBuilder(plugin.getGui().getData(), "CHEST.VoteURL.ExtraItems." + str + ".Rewards")
.setGiveOffline(false).send(clickEvent.getPlayer());
;
}
});
}
@@ -41,6 +41,10 @@ public class BungeeSettings extends YMLFile {
@Getter
private boolean perServerPoints = false;
@ConfigDataBoolean(path = "PerServerMilestones")
@Getter
private boolean perServerMilestones = false;
@ConfigDataBoolean(path = "PerServerRewards")
@Getter
private boolean perServerRewards = false;
@@ -41,10 +41,18 @@ public class Config extends YMLFile {
@Getter
private boolean preloadSkulls = false;
@ConfigDataBoolean(path = "AutoCachePlaceholders")
@Getter
private boolean autoCachePlaceholders = true;
@ConfigDataBoolean(path = "AllowUnJoinedCheckServer")
@Getter
private boolean allowUnJoinedCheckServer = true;
@ConfigDataInt(path = "PlayerDataLoadLimit")
@Getter
private int playerDataLoadLimit = -1;
@ConfigDataBoolean(path = "AllowVotePointTransfers")
@Getter
private boolean allowVotePointTransfers = false;
@@ -101,6 +109,10 @@ public class Config extends YMLFile {
@Getter
private ArrayList<String> disabledDefaultPermissions = new ArrayList<String>();
@ConfigDataListString(path = "CachedPlaceholders")
@Getter
private ArrayList<String> cachedPlaceholders = new ArrayList<String>();
@ConfigDataBoolean(path = "DisableInteractEvent")
@Getter
private boolean disableInteractEvent = false;
@@ -174,6 +186,14 @@ public class Config extends YMLFile {
@Getter
private String formatCommandsVoteToggleBroadcastEnabled = "&cYou will now see vote broadcasts";
@ConfigDataString(path = "Format.Commands.Vote.ToggleReminders.Disabled")
@Getter
private String formatCommandsVoteToggleRemindersDisabled = "&cVote reminders disabled";
@ConfigDataString(path = "Format.Commands.Vote.ToggleReminders.Enabled")
@Getter
private String formatCommandsVoteToggleRemindersEnabled = "&cVote reminders enabled";
@Getter
private int formatPageSize = 10;
@@ -74,6 +74,10 @@ public class GUI extends YMLFile {
@Getter
private boolean chestVoteShopRequireConfirmation = false;
@ConfigDataBoolean(path = "CHEST.VoteBest.BackButton")
@Getter
private boolean chestVoteBestBackButton = true;
@ConfigDataString(path = "CHEST.VoteToday.IconTitle")
@Getter
private String chestVoteTodayIconTitle = "%player%";
@@ -34,6 +34,10 @@ public class SpecialRewardsConfig extends YMLFile {
@Getter
private boolean enableWeeklyAwards = false;
@ConfigDataBoolean(path = "OnlyOneCumulative")
@Getter
private boolean onlyOneCumulative = false;
@Getter
private String firstVoteRewardsPath = "FirstVote";
@@ -2,6 +2,7 @@ package com.bencodez.votingplugin.data;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import org.bukkit.Bukkit;
@@ -24,6 +25,23 @@ public class ServerData {
this.plugin = plugin;
}
public void addAutoCachedPlaceholder(String placeholder) {
List<String> p = getAutoCachedPlaceholder();
if (!p.contains(placeholder)) {
p.add(placeholder);
setAutoCachedPlaceholder(p);
}
}
public void setAutoCachedPlaceholder(List<String> placeholders) {
getData().set("AutoCachePlaceholders", placeholders);
saveData();
}
public List<String> getAutoCachedPlaceholder() {
return getData().getStringList("AutoCachePlaceholders");
}
public synchronized void addServiceSite(String site) {
ArrayList<String> l = getServiceSites();
if (!getServiceSites().contains(site)) {
@@ -246,6 +264,24 @@ public class ServerData {
saveData();
}
public int getBungeeVotePartyCurrent() {
return getData().getInt("BungeeVotePartyCurrent");
}
public int getBungeeVotePartyRequired() {
return getData().getInt("BungeeVotePartyRequired");
}
public void setBungeeVotePartyCurrent(int current) {
getData().set("BungeeVotePartyCurrent", current);
saveData();
}
public void setBungeeVotePartyRequired(int required) {
getData().set("BungeeVotePartyRequired", required);
saveData();
}
/**
* Update values.
*/
@@ -0,0 +1,81 @@
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.user.VotingPluginUser;
import lombok.Getter;
import lombok.Setter;
// TODO: Auto-generated Javadoc
/**
* The Class PlayerVoteEvent.
*/
public class PlayerPostVoteEvent extends Event {
/** The Constant handlers. */
private static final HandlerList handlers = new HandlerList();
/**
* Gets the handler list.
*
* @return the handler list
*/
public static HandlerList getHandlerList() {
return handlers;
}
@Getter
@Setter
private boolean bungee = false;
@Getter
@Setter
private BungeeMessageData bungeeTextTotals;
@Getter
@Setter
private boolean cancelled;
@Getter
@Setter
private boolean forceBungee = false;
@Getter
@Setter
private VotingPluginUser user;
@Getter
@Setter
private boolean realVote = true;
@Getter
@Setter
private VoteSite voteSite;
@Getter
@Setter
private VotingPluginUser votingPluginUser;
public PlayerPostVoteEvent(VoteSite voteSite, VotingPluginUser user, boolean realVote, boolean forceBungee) {
super(true);
this.user = user;
this.voteSite = voteSite;
this.realVote = realVote;
this.forceBungee = forceBungee;
}
/*
* (non-Javadoc)
*
* @see org.bukkit.event.Event#getHandlers()
*/
@Override
public HandlerList getHandlers() {
return handlers;
}
}
@@ -13,6 +13,7 @@ import com.bencodez.advancedcore.api.misc.ArrayUtils;
import com.bencodez.advancedcore.api.misc.PlayerUtils;
import com.bencodez.votingplugin.VotingPluginMain;
import com.bencodez.votingplugin.bungee.BungeeMethod;
import com.bencodez.votingplugin.events.PlayerPostVoteEvent;
import com.bencodez.votingplugin.events.PlayerVoteEvent;
import com.bencodez.votingplugin.objects.VoteSite;
import com.bencodez.votingplugin.user.UserManager;
@@ -44,6 +45,9 @@ public class PlayerVoteListener implements Listener {
*/
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onplayerVote(PlayerVoteEvent event) {
if (!plugin.isEnabled()) {
return;
}
String playerName = event.getPlayer();
if (!PlayerUtils.getInstance().isValidUser(playerName, plugin.getConfigFile().isAllowUnJoinedCheckServer())) {
if (!plugin.getConfigFile().isAllowUnjoined()) {
@@ -109,6 +113,9 @@ public class PlayerVoteListener implements Listener {
}
synchronized (object) {
if (!plugin.isEnabled()) {
return;
}
// reupdate cache
user.clearCache();
user.cache();
@@ -214,6 +221,10 @@ public class PlayerVoteListener implements Listener {
}
}
PlayerPostVoteEvent postVoteEvent = new PlayerPostVoteEvent(voteSite, user, event.isRealVote(),
event.isForceBungee());
plugin.getServer().getPluginManager().callEvent(postVoteEvent);
plugin.setUpdate(true);
}
@@ -52,13 +52,6 @@ public class VotiferEvent implements Listener {
// ignore own plugin calls of event
return;
}
Bukkit.getScheduler().runTaskAsynchronously(plugin, new Runnable() {
@Override
public void run() {
plugin.getServerData().addServiceSite(voteSite);
}
});
if (voteUsername.length() == 0) {
plugin.getLogger().warning("No name from vote on " + voteSite);
@@ -76,7 +69,7 @@ public class VotiferEvent implements Listener {
@Override
public void run() {
plugin.getServerData().addServiceSite(voteSite);
if (plugin.getBungeeSettings().isUseBungeecoord() && !plugin.getBungeeSettings().isVotifierBypass()
&& (plugin.getBungeeHandler().getMethod().equals(BungeeMethod.PLUGINMESSAGING)
|| plugin.getBungeeHandler().getMethod().equals(BungeeMethod.SOCKETS))) {
@@ -2,6 +2,7 @@ package com.bencodez.votingplugin.placeholders;
import org.bukkit.Bukkit;
import com.bencodez.advancedcore.api.placeholder.NonPlayerPlaceHolder;
import com.bencodez.advancedcore.api.placeholder.PlaceHolder;
import com.bencodez.votingplugin.VotingPluginMain;
import com.bencodez.votingplugin.user.UserManager;
@@ -46,7 +47,7 @@ public class MVdWPlaceholders {
&& user.hasPrimaryAccount()) {
user = UserManager.getInstance().getVotingPluginUser(user.getPrimaryAccount());
}
return place.placeholderRequest(event.getOfflinePlayer(), user,
return place.placeholderRequest(user,
event.getPlaceholder().substring("VotingPlugin_".length()));
}
@@ -55,7 +56,7 @@ public class MVdWPlaceholders {
}
for (final PlaceHolder<VotingPluginUser> place : plugin.getPlaceholders().getNonPlayerPlaceholders()) {
for (final NonPlayerPlaceHolder<VotingPluginUser> place : plugin.getPlaceholders().getNonPlayerPlaceholders()) {
String str = place.getIdentifier();
if (!str.endsWith("_")) {
PlaceholderAPI.registerPlaceholder(VotingPluginMain.plugin, "VotingPlugin_" + str,
@@ -63,7 +64,7 @@ public class MVdWPlaceholders {
@Override
public String onPlaceholderReplace(PlaceholderReplaceEvent event) {
return place.placeholderRequest(event.getOfflinePlayer(), null,
return place.placeholderRequest(
event.getPlaceholder().substring("VotingPlugin_".length()));
}
@@ -5,15 +5,23 @@ import java.time.Duration;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Locale;
import java.util.Map.Entry;
import java.util.Set;
import java.util.UUID;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentLinkedQueue;
import org.bukkit.Bukkit;
import org.bukkit.OfflinePlayer;
import org.bukkit.entity.Player;
import com.bencodez.advancedcore.api.messages.StringParser;
import com.bencodez.advancedcore.api.placeholder.NonPlayerPlaceHolder;
import com.bencodez.advancedcore.api.placeholder.PlaceHolder;
import com.bencodez.advancedcore.api.user.AdvancedCoreUser;
import com.bencodez.advancedcore.api.user.UserDataChanged;
import com.bencodez.votingplugin.VotingPluginMain;
import com.bencodez.votingplugin.objects.VoteSite;
import com.bencodez.votingplugin.topvoter.TopVoter;
@@ -30,7 +38,7 @@ import lombok.Getter;
public class PlaceHolders {
@Getter
private ArrayList<PlaceHolder<VotingPluginUser>> nonPlayerPlaceholders = new ArrayList<PlaceHolder<VotingPluginUser>>();
private ArrayList<NonPlayerPlaceHolder<VotingPluginUser>> nonPlayerPlaceholders = new ArrayList<NonPlayerPlaceHolder<VotingPluginUser>>();
@Getter
private ArrayList<PlaceHolder<VotingPluginUser>> placeholders = new ArrayList<PlaceHolder<VotingPluginUser>>();
@@ -41,37 +49,65 @@ public class PlaceHolders {
this.plugin = plugin;
}
private ArrayList<String> cachedPlaceholders = new ArrayList<String>();
private ConcurrentLinkedQueue<String> placeholdersToSetCacheOn = new ConcurrentLinkedQueue<String>();
public String getPlaceHolder(OfflinePlayer p, String identifier) {
return getPlaceHolder(p, identifier, true);
}
public String getPlaceHolder(OfflinePlayer p, String identifier, boolean javascript) {
if (plugin.getConfigFile().isUseJavascriptPlaceholders() && javascript) {
if (plugin.getConfigFile().isUseJavascriptPlaceholders() && javascript && p != null) {
identifier = StringParser.getInstance().replaceJavascript(p, identifier);
}
for (PlaceHolder<VotingPluginUser> placeholder : nonPlayerPlaceholders) {
if (placeholder.matches(identifier)) {
return placeholder.placeholderRequest(p, null, identifier);
if (!identifier.endsWith("Position")) {
for (NonPlayerPlaceHolder<VotingPluginUser> placeholder : nonPlayerPlaceholders) {
if (placeholder.matches(identifier)) {
String str = placeholder.placeholderRequest(identifier);
if (str != null) {
return str;
}
}
}
}
if (p == null) {
return "no player";
}
VotingPluginUser user = UserManager.getInstance().getVotingPluginUser(p);
if (Bukkit.isPrimaryThread() || plugin.getConfigFile().isAlwaysWaitForCachePlaceholders()) {
user.setWaitForCache(false);
if (!user.isCached()) {
user.loadCache();
return "..";
if (!cachedPlaceholders.contains(identifier)) {
if (Bukkit.isPrimaryThread() || plugin.getConfigFile().isAlwaysWaitForCachePlaceholders()) {
user.setWaitForCache(false);
if (!user.isCached()) {
user.loadCache();
if (plugin.getConfigFile().isAutoCachePlaceholders()) {
placeholdersToSetCacheOn.add(identifier);
}
return "..";
}
}
}
if (plugin.getConfigFile().isUsePrimaryAccountForPlaceholders() && user.hasPrimaryAccount()) {
user = UserManager.getInstance().getVotingPluginUser(user.getPrimaryAccount());
if (plugin.getConfigFile().isUsePrimaryAccountForPlaceholders()) {
if (user.hasPrimaryAccount()) {
user = UserManager.getInstance().getVotingPluginUser(user.getPrimaryAccount());
}
}
for (PlaceHolder<VotingPluginUser> placeholder : placeholders) {
try {
if (placeholder.matches(identifier)) {
return placeholder.placeholderRequest(p, user, identifier);
if (placeholder.isUsesCache() && placeholder.isCached(identifier)) {
ConcurrentHashMap<UUID, String> cache = placeholder.getCache().get(identifier);
if (cache.containsKey(p.getUniqueId())) {
return cache.get(p.getUniqueId());
} else {
return "....";
}
} else {
return placeholder.placeholderRequest(user, identifier);
}
}
} catch (Exception e) {
plugin.debug(e);
@@ -86,7 +122,7 @@ public class PlaceHolders {
if (plugin.getConfigFile().isUseJavascriptPlaceholders()) {
identifier = StringParser.getInstance().replaceJavascript(p, identifier);
}
return getPlaceHolder((OfflinePlayer) p, identifier, false);
return getPlaceHolder(p, identifier, false);
}
public void load() {
@@ -97,54 +133,54 @@ public class PlaceHolders {
placeholders.add(new PlaceHolder<VotingPluginUser>("total") {
@Override
public String placeholderRequest(OfflinePlayer p, VotingPluginUser user, String identifier) {
public String placeholderRequest(VotingPluginUser user, String identifier) {
return Integer.toString(user.getTotal(TopVoter.Monthly));
}
}.withDescription("Month total"));
}.withDescription("Month total").updateDataKey("MonthTotal"));
placeholders.add(new PlaceHolder<VotingPluginUser>("alltimetotal") {
@Override
public String placeholderRequest(OfflinePlayer p, VotingPluginUser user, String identifier) {
public String placeholderRequest(VotingPluginUser user, String identifier) {
return Integer.toString(user.getTotal(TopVoter.AllTime));
}
}.withDescription("Alltime total"));
}.withDescription("Alltime total").updateDataKey("AllTimeTotal"));
placeholders.add(new PlaceHolder<VotingPluginUser>("lastmonthtotal") {
@Override
public String placeholderRequest(OfflinePlayer p, VotingPluginUser user, String identifier) {
public String placeholderRequest(VotingPluginUser user, String identifier) {
return Integer.toString(user.getLastMonthTotal());
}
}.withDescription("Last month total"));
}.withDescription("Last month total").updateDataKey("LastMonthTotal"));
// end of older placeholders
placeholders.add(new PlaceHolder<VotingPluginUser>("DisableBroadcast") {
@Override
public String placeholderRequest(OfflinePlayer p, VotingPluginUser user, String identifier) {
public String placeholderRequest(VotingPluginUser user, String identifier) {
return "" + user.getDisableBroadcast();
}
}.withDescription("Returns true/false if user has broadcast disabled"));
}.withDescription("Returns true/false if user has broadcast disabled").updateDataKey("DisableBroadcast"));
placeholders.add(new PlaceHolder<VotingPluginUser>("MilestoneCount") {
@Override
public String placeholderRequest(OfflinePlayer p, VotingPluginUser user, String identifier) {
public String placeholderRequest(VotingPluginUser user, String identifier) {
return "" + user.getMilestoneCount();
}
}.withDescription("User milestonecount"));
}.withDescription("User milestonecount").updateDataKey("MilestoneCount"));
for (final String identifier : plugin.getGui().getChestShopIdentifiers()) {
if (plugin.getGui().getChestShopIdentifierLimit(identifier) > 0) {
placeholders.add(new PlaceHolder<VotingPluginUser>("VoteShopLimit_" + identifier) {
@Override
public String placeholderRequest(OfflinePlayer p, VotingPluginUser user, String ident) {
public String placeholderRequest(VotingPluginUser user, String ident) {
return "" + user.getVoteShopIdentifierLimit(identifier);
}
}.withDescription("User voteshop limit for " + identifier));
}.withDescription("User voteshop limit for " + identifier).updateDataKey("VoteShopLimit" + identifier));
}
}
@@ -152,121 +188,121 @@ public class PlaceHolders {
placeholders.add(new PlaceHolder<VotingPluginUser>("Total_" + top.toString()) {
@Override
public String placeholderRequest(OfflinePlayer p, VotingPluginUser user, String identifier) {
public String placeholderRequest(VotingPluginUser user, String identifier) {
return Integer.toString(user.getTotal(top));
}
}.withDescription("User total for " + top.getName()));
}.withDescription("User total for " + top.getName()).updateDataKey(top.getColumnName()));
}
placeholders.add(new PlaceHolder<VotingPluginUser>("BestDailyTotal") {
@Override
public String placeholderRequest(OfflinePlayer p, VotingPluginUser user, String identifier) {
public String placeholderRequest(VotingPluginUser user, String identifier) {
return Integer.toString(user.getHighestDailyTotal());
}
}.withDescription("Best daily total"));
}.withDescription("Best daily total").updateDataKey("HighestDailyTotal"));
placeholders.add(new PlaceHolder<VotingPluginUser>("BestWeeklyTotal") {
@Override
public String placeholderRequest(OfflinePlayer p, VotingPluginUser user, String identifier) {
public String placeholderRequest(VotingPluginUser user, String identifier) {
return Integer.toString(user.getHighestWeeklyTotal());
}
}.withDescription("Best weekly total"));
}.withDescription("Best weekly total").updateDataKey("HighestWeeklyTotal"));
placeholders.add(new PlaceHolder<VotingPluginUser>("BestMonthlyTotal") {
@Override
public String placeholderRequest(OfflinePlayer p, VotingPluginUser user, String identifier) {
public String placeholderRequest(VotingPluginUser user, String identifier) {
return Integer.toString(user.getHighestMonthlyTotal());
}
}.withDescription("Best monthly total"));
}.withDescription("Best monthly total").updateDataKey("HighestMonthlyTotal"));
placeholders.add(new PlaceHolder<VotingPluginUser>("DailyVoteStreak") {
@Override
public String placeholderRequest(OfflinePlayer p, VotingPluginUser user, String identifier) {
public String placeholderRequest(VotingPluginUser user, String identifier) {
return Integer.toString(user.getDayVoteStreak());
}
}.withDescription("Current daily votestreak"));
}.withDescription("Current daily votestreak").updateDataKey("DayVoteStreak"));
placeholders.add(new PlaceHolder<VotingPluginUser>("WeeklyVoteStreak") {
@Override
public String placeholderRequest(OfflinePlayer p, VotingPluginUser user, String identifier) {
public String placeholderRequest(VotingPluginUser user, String identifier) {
return Integer.toString(user.getWeekVoteStreak());
}
}.withDescription("Current weekly votestreak"));
}.withDescription("Current weekly votestreak").updateDataKey("WeekVoteStreak"));
placeholders.add(new PlaceHolder<VotingPluginUser>("MonthVoteStreak") {
@Override
public String placeholderRequest(OfflinePlayer p, VotingPluginUser user, String identifier) {
public String placeholderRequest(VotingPluginUser user, String identifier) {
return Integer.toString(user.getMonthVoteStreak());
}
}.withDescription("Current month votestreak"));
}.withDescription("Current month votestreak").updateDataKey("MonthVoteStreak"));
placeholders.add(new PlaceHolder<VotingPluginUser>("BestDailyVoteStreak") {
@Override
public String placeholderRequest(OfflinePlayer p, VotingPluginUser user, String identifier) {
public String placeholderRequest(VotingPluginUser user, String identifier) {
return Integer.toString(user.getBestDayVoteStreak());
}
}.withDescription("Best daily votestreak"));
}.withDescription("Best daily votestreak").updateDataKey("BestDayVoteStreak"));
placeholders.add(new PlaceHolder<VotingPluginUser>("BestWeeklyVoteStreak") {
@Override
public String placeholderRequest(OfflinePlayer p, VotingPluginUser user, String identifier) {
public String placeholderRequest(VotingPluginUser user, String identifier) {
return Integer.toString(user.getBestWeekVoteStreak());
}
}.withDescription("Best weekly votestreak"));
}.withDescription("Best weekly votestreak").updateDataKey("BestWeekVoteStreak"));
placeholders.add(new PlaceHolder<VotingPluginUser>("BestMonthVoteStreak") {
@Override
public String placeholderRequest(OfflinePlayer p, VotingPluginUser user, String identifier) {
public String placeholderRequest(VotingPluginUser user, String identifier) {
return Integer.toString(user.getBestMonthVoteStreak());
}
}.withDescription("Best month votestreak"));
}.withDescription("Best month votestreak").updateDataKey("BestMonthVoteStreak"));
placeholders.add(new PlaceHolder<VotingPluginUser>("Points") {
@Override
public String placeholderRequest(OfflinePlayer p, VotingPluginUser user, String identifier) {
public String placeholderRequest(VotingPluginUser user, String identifier) {
return Integer.toString(user.getPoints());
}
}.withDescription("User points"));
}.withDescription("User points").updateDataKey("Points"));
placeholders.add(new PlaceHolder<VotingPluginUser>("Points_Format") {
@Override
public String placeholderRequest(OfflinePlayer p, VotingPluginUser user, String identifier) {
public String placeholderRequest(VotingPluginUser user, String identifier) {
NumberFormat numberFormat = NumberFormat.getNumberInstance(Locale.US);
return numberFormat.format(user.getPoints());
}
}.withDescription("User points"));
}.withDescription("User points").updateDataKey("Points"));
placeholders.add(new PlaceHolder<VotingPluginUser>("CanVote") {
@Override
public String placeholderRequest(OfflinePlayer p, VotingPluginUser user, String identifier) {
public String placeholderRequest(VotingPluginUser user, String identifier) {
return Boolean.toString(user.canVoteAll());
}
}.withDescription("Return true/false if player can vote on all sites"));
}.withDescription("Return true/false if player can vote on all sites").updateDataKey("LastVotes"));
placeholders.add(new PlaceHolder<VotingPluginUser>("CanVoteSites") {
@Override
public String placeholderRequest(OfflinePlayer p, VotingPluginUser user, String identifier) {
public String placeholderRequest(VotingPluginUser user, String identifier) {
return "" + user.getSitesNotVotedOn();
}
}.withDescription("Return number of votesites available"));
}.withDescription("Return number of votesites available").updateDataKey("LastVotes"));
placeholders.add(new PlaceHolder<VotingPluginUser>("Next_AnySite") {
@Override
public String placeholderRequest(OfflinePlayer p, VotingPluginUser user, String identifier) {
public String placeholderRequest(VotingPluginUser user, String identifier) {
if (user.canVoteAny()) {
return plugin.getConfigFile().getFormatCommandsVoteNextInfoCanVote();
}
@@ -290,39 +326,40 @@ public class PlaceHolders {
return "Error";
}
}.withDescription("How long until user can vote on anysite"));
}.withDescription("How long until user can vote on anysite").updateDataKey("LastVotes"));
for (final VoteSite voteSite : plugin.getVoteSites()) {
placeholders.add(new PlaceHolder<VotingPluginUser>("Next_" + voteSite.getKey()) {
@Override
public String placeholderRequest(OfflinePlayer p, VotingPluginUser user, String identifier) {
public String placeholderRequest(VotingPluginUser user, String identifier) {
return user.voteCommandNextInfo(voteSite);
}
}.withDescription("How long until user can vote on " + voteSite.getKey()));
}.withDescription("How long until user can vote on " + voteSite.getKey()).updateDataKey("LastVotes"));
placeholders.add(new PlaceHolder<VotingPluginUser>("Last_" + voteSite.getKey()) {
@Override
public String placeholderRequest(OfflinePlayer p, VotingPluginUser user, String identifier) {
public String placeholderRequest(VotingPluginUser user, String identifier) {
return user.voteCommandLastDuration(voteSite);
}
}.withDescription("How long ago user voted on " + voteSite.getKey()));
}.withDescription("How long ago user voted on " + voteSite.getKey()).updateDataKey("LastVotes"));
placeholders.add(new PlaceHolder<VotingPluginUser>("CanVote_" + voteSite.getKey()) {
@Override
public String placeholderRequest(OfflinePlayer p, VotingPluginUser user, String identifier) {
public String placeholderRequest(VotingPluginUser user, String identifier) {
return "" + user.canVoteSite(voteSite);
}
}.withDescription("Whether or not player can vote on " + voteSite.getKey()));
}.withDescription("Whether or not player can vote on " + voteSite.getKey()).updateDataKey("LastVotes"));
}
placeholders.add(new PlaceHolder<VotingPluginUser>("Top_All_Position") {
@Override
public String placeholderRequest(OfflinePlayer p, VotingPluginUser user, String identifier) {
public String placeholderRequest(VotingPluginUser user, String identifier) {
int num = 1;
UUID toMatch = UUID.fromString(user.getUUID());
for (Entry<TopVoterPlayer, Integer> entry : plugin.getTopVoter(TopVoter.AllTime).entrySet()) {
if (entry.getKey().getUuid().equals(p.getUniqueId())) {
if (entry.getKey().getUuid().equals(toMatch)) {
return "" + num;
}
num++;
@@ -331,10 +368,10 @@ public class PlaceHolders {
}
}.withDescription("Get user top voter position"));
placeholders.add(new PlaceHolder<VotingPluginUser>("Top_AllVotes_") {
nonPlayerPlaceholders.add(new NonPlayerPlaceHolder<VotingPluginUser>("Top_AllVotes_") {
@Override
public String placeholderRequest(OfflinePlayer p, VotingPluginUser user, String identifier) {
public String placeholderRequest(String identifier) {
int num = 1;
int number = Integer.parseInt(identifier.split("_")[2]);
for (Entry<TopVoterPlayer, Integer> entry : plugin.getTopVoter(TopVoter.AllTime).entrySet()) {
@@ -347,10 +384,13 @@ public class PlaceHolders {
}
}.useStartsWith().withDescription("Get user votes at position in top voter"));
placeholders.add(new PlaceHolder<VotingPluginUser>("Top_All_") {
nonPlayerPlaceholders.add(new NonPlayerPlaceHolder<VotingPluginUser>("Top_All_") {
@Override
public String placeholderRequest(OfflinePlayer p, VotingPluginUser user, String identifier) {
public String placeholderRequest(String identifier) {
if (!StringParser.getInstance().isInt(identifier.split("_")[2])) {
return null;
}
int num = 1;
int number = Integer.parseInt(identifier.split("_")[2]);
for (Entry<TopVoterPlayer, Integer> entry : plugin.getTopVoter(TopVoter.AllTime).entrySet()) {
@@ -366,10 +406,11 @@ public class PlaceHolders {
placeholders.add(new PlaceHolder<VotingPluginUser>("Top_Month_Position") {
@Override
public String placeholderRequest(OfflinePlayer p, VotingPluginUser user, String identifier) {
public String placeholderRequest(VotingPluginUser user, String identifier) {
int num = 1;
UUID toMatch = UUID.fromString(user.getUUID());
for (Entry<TopVoterPlayer, Integer> entry : plugin.getTopVoter(TopVoter.Monthly).entrySet()) {
if (entry.getKey().getUuid().equals(p.getUniqueId())) {
if (entry.getKey().getUuid().equals(toMatch)) {
return "" + num;
}
num++;
@@ -378,10 +419,13 @@ public class PlaceHolders {
}
}.withDescription("Get user top voter position"));
placeholders.add(new PlaceHolder<VotingPluginUser>("Top_Month_") {
nonPlayerPlaceholders.add(new NonPlayerPlaceHolder<VotingPluginUser>("Top_Month_") {
@Override
public String placeholderRequest(OfflinePlayer p, VotingPluginUser user, String identifier) {
public String placeholderRequest(String identifier) {
if (!StringParser.getInstance().isInt(identifier.split("_")[2])) {
return null;
}
int num = 1;
int number = Integer.parseInt(identifier.split("_")[2]);
for (Entry<TopVoterPlayer, Integer> entry : plugin.getTopVoter(TopVoter.Monthly).entrySet()) {
@@ -394,10 +438,10 @@ public class PlaceHolders {
}
}.useStartsWith().withDescription("Get user at position in top voter"));
placeholders.add(new PlaceHolder<VotingPluginUser>("Top_MonthVotes_") {
nonPlayerPlaceholders.add(new NonPlayerPlaceHolder<VotingPluginUser>("Top_MonthVotes_") {
@Override
public String placeholderRequest(OfflinePlayer p, VotingPluginUser user, String identifier) {
public String placeholderRequest(String identifier) {
int num = 1;
int number = Integer.parseInt(identifier.split("_")[2]);
for (Entry<TopVoterPlayer, Integer> entry : plugin.getTopVoter(TopVoter.Monthly).entrySet()) {
@@ -413,10 +457,11 @@ public class PlaceHolders {
placeholders.add(new PlaceHolder<VotingPluginUser>("Top_Week_Position") {
@Override
public String placeholderRequest(OfflinePlayer p, VotingPluginUser user, String identifier) {
public String placeholderRequest(VotingPluginUser user, String identifier) {
int num = 1;
UUID toMatch = UUID.fromString(user.getUUID());
for (Entry<TopVoterPlayer, Integer> entry : plugin.getTopVoter(TopVoter.Weekly).entrySet()) {
if (entry.getKey().getUuid().equals(p.getUniqueId())) {
if (entry.getKey().getUuid().equals(toMatch)) {
return "" + num;
}
num++;
@@ -425,10 +470,13 @@ public class PlaceHolders {
}
}.withDescription("Get user top voter position"));
placeholders.add(new PlaceHolder<VotingPluginUser>("Top_Week_") {
nonPlayerPlaceholders.add(new NonPlayerPlaceHolder<VotingPluginUser>("Top_Week_") {
@Override
public String placeholderRequest(OfflinePlayer p, VotingPluginUser user, String identifier) {
public String placeholderRequest(String identifier) {
if (!StringParser.getInstance().isInt(identifier.split("_")[2])) {
return null;
}
int num = 1;
int number = Integer.parseInt(identifier.split("_")[2]);
for (Entry<TopVoterPlayer, Integer> entry : plugin.getTopVoter(TopVoter.Weekly).entrySet()) {
@@ -441,10 +489,10 @@ public class PlaceHolders {
}
}.useStartsWith().withDescription("Get user at postion in top voter"));
placeholders.add(new PlaceHolder<VotingPluginUser>("Top_WeekVotes_") {
nonPlayerPlaceholders.add(new NonPlayerPlaceHolder<VotingPluginUser>("Top_WeekVotes_") {
@Override
public String placeholderRequest(OfflinePlayer p, VotingPluginUser user, String identifier) {
public String placeholderRequest(String identifier) {
int num = 1;
int number = Integer.parseInt(identifier.split("_")[2]);
for (Entry<TopVoterPlayer, Integer> entry : plugin.getTopVoter(TopVoter.Weekly).entrySet()) {
@@ -460,10 +508,11 @@ public class PlaceHolders {
placeholders.add(new PlaceHolder<VotingPluginUser>("Top_Daily_Position") {
@Override
public String placeholderRequest(OfflinePlayer p, VotingPluginUser user, String identifier) {
public String placeholderRequest(VotingPluginUser user, String identifier) {
int num = 1;
UUID toMatch = UUID.fromString(user.getUUID());
for (Entry<TopVoterPlayer, Integer> entry : plugin.getTopVoter(TopVoter.Daily).entrySet()) {
if (entry.getKey().getUuid().equals(p.getUniqueId())) {
if (entry.getKey().getUuid().equals(toMatch)) {
return "" + num;
}
num++;
@@ -472,10 +521,13 @@ public class PlaceHolders {
}
}.withDescription("Get user top voter position"));
placeholders.add(new PlaceHolder<VotingPluginUser>("Top_Daily_") {
nonPlayerPlaceholders.add(new NonPlayerPlaceHolder<VotingPluginUser>("Top_Daily_") {
@Override
public String placeholderRequest(OfflinePlayer p, VotingPluginUser user, String identifier) {
public String placeholderRequest(String identifier) {
if (!StringParser.getInstance().isInt(identifier.split("_")[2])) {
return null;
}
int num = 1;
int number = Integer.parseInt(identifier.split("_")[2]);
for (Entry<TopVoterPlayer, Integer> entry : plugin.getTopVoter(TopVoter.Daily).entrySet()) {
@@ -491,15 +543,15 @@ public class PlaceHolders {
placeholders.add(new PlaceHolder<VotingPluginUser>("VotePartyContributedVotes") {
@Override
public String placeholderRequest(OfflinePlayer p, VotingPluginUser user, String identifier) {
public String placeholderRequest(VotingPluginUser user, String identifier) {
return "" + user.getVotePartyVotes();
}
}.useStartsWith().withDescription("See vote party placeholders contributed"));
}.useStartsWith().withDescription("See vote party placeholders contributed").updateDataKey("VotePartyVotes"));
placeholders.add(new PlaceHolder<VotingPluginUser>("Top_DailyVotes_") {
nonPlayerPlaceholders.add(new NonPlayerPlaceHolder<VotingPluginUser>("Top_DailyVotes_") {
@Override
public String placeholderRequest(OfflinePlayer p, VotingPluginUser user, String identifier) {
public String placeholderRequest(String identifier) {
int num = 1;
int number = Integer.parseInt(identifier.split("_")[2]);
for (Entry<TopVoterPlayer, Integer> entry : plugin.getTopVoter(TopVoter.Daily).entrySet()) {
@@ -514,34 +566,68 @@ public class PlaceHolders {
// non players
nonPlayerPlaceholders.add(new PlaceHolder<VotingPluginUser>("VotePartyVotesCurrent") {
nonPlayerPlaceholders.add(new NonPlayerPlaceHolder<VotingPluginUser>("VotePartyVotesCurrent") {
@Override
public String placeholderRequest(OfflinePlayer p, VotingPluginUser user, String identifier) {
public String placeholderRequest(String identifier) {
return Integer.toString(plugin.getVoteParty().getTotalVotes());
}
}.withDescription("Current amount of voteparty votes"));
nonPlayerPlaceholders.add(new PlaceHolder<VotingPluginUser>("VotePartyVotesNeeded") {
nonPlayerPlaceholders.add(new NonPlayerPlaceHolder<VotingPluginUser>("VotePartyVotesNeeded") {
@Override
public String placeholderRequest(OfflinePlayer p, VotingPluginUser user, String identifier) {
public String placeholderRequest(String identifier) {
return Integer.toString(plugin.getVoteParty().getNeededVotes());
}
}.withDescription("Voteparty votes needed"));
nonPlayerPlaceholders.add(new PlaceHolder<VotingPluginUser>("VotePartyVotesRequired") {
nonPlayerPlaceholders.add(new NonPlayerPlaceHolder<VotingPluginUser>("VotePartyVotesRequired") {
@Override
public String placeholderRequest(OfflinePlayer p, VotingPluginUser user, String identifier) {
public String placeholderRequest(String identifier) {
return Integer.toString(plugin.getVoteParty().getVotesRequired());
}
}.withDescription("Amount of votes needed for voteparty"));
nonPlayerPlaceholders.add(new PlaceHolder<VotingPluginUser>("GlobalMonthTotal") {
nonPlayerPlaceholders.add(new NonPlayerPlaceHolder<VotingPluginUser>("BungeeVotePartyVotesCurrent") {
@Override
public String placeholderRequest(OfflinePlayer p, VotingPluginUser user, String identifier) {
public String placeholderRequest(String identifier) {
if (plugin.getBungeeHandler() != null) {
return Integer.toString(plugin.getBungeeHandler().getBungeeVotePartyCurrent());
}
return "" + 0;
}
}.withDescription("Current amount of bungee voteparty votes"));
nonPlayerPlaceholders.add(new NonPlayerPlaceHolder<VotingPluginUser>("BungeeVotePartyVotesNeeded") {
@Override
public String placeholderRequest(String identifier) {
if (plugin.getBungeeHandler() != null) {
return Integer.toString(plugin.getBungeeHandler().getBungeeVotePartyRequired()
- plugin.getBungeeHandler().getBungeeVotePartyCurrent());
}
return "" + 0;
}
}.withDescription("Voteparty bungee votes needed"));
nonPlayerPlaceholders.add(new NonPlayerPlaceHolder<VotingPluginUser>("BungeeVotePartyVotesRequired") {
@Override
public String placeholderRequest(String identifier) {
if (plugin.getBungeeHandler() != null) {
return Integer.toString(plugin.getBungeeHandler().getBungeeVotePartyRequired());
}
return "" + 0;
}
}.withDescription("Amount of votes needed for bungee voteparty"));
nonPlayerPlaceholders.add(new NonPlayerPlaceHolder<VotingPluginUser>("GlobalMonthTotal") {
@Override
public String placeholderRequest(String identifier) {
int total = 0;
for (int num : VotingPluginMain.plugin.getTopVoter(TopVoter.Monthly).values()) {
total += num;
@@ -550,10 +636,10 @@ public class PlaceHolders {
}
}.withDescription("Global month total"));
nonPlayerPlaceholders.add(new PlaceHolder<VotingPluginUser>("GlobalAllTimeTotal") {
nonPlayerPlaceholders.add(new NonPlayerPlaceHolder<VotingPluginUser>("GlobalAllTimeTotal") {
@Override
public String placeholderRequest(OfflinePlayer p, VotingPluginUser user, String identifier) {
public String placeholderRequest(String identifier) {
int total = 0;
for (int num : VotingPluginMain.plugin.getTopVoter(TopVoter.AllTime).values()) {
total += num;
@@ -562,10 +648,10 @@ public class PlaceHolders {
}
}.withDescription("Global alltime total"));
nonPlayerPlaceholders.add(new PlaceHolder<VotingPluginUser>("GlobalWeeklyTotal") {
nonPlayerPlaceholders.add(new NonPlayerPlaceHolder<VotingPluginUser>("GlobalWeeklyTotal") {
@Override
public String placeholderRequest(OfflinePlayer p, VotingPluginUser user, String identifier) {
public String placeholderRequest(String identifier) {
int total = 0;
for (int num : VotingPluginMain.plugin.getTopVoter(TopVoter.Weekly).values()) {
total += num;
@@ -574,10 +660,10 @@ public class PlaceHolders {
}
}.withDescription("Global weekly total"));
nonPlayerPlaceholders.add(new PlaceHolder<VotingPluginUser>("GlobalDailyTotal") {
nonPlayerPlaceholders.add(new NonPlayerPlaceHolder<VotingPluginUser>("GlobalDailyTotal") {
@Override
public String placeholderRequest(OfflinePlayer p, VotingPluginUser user, String identifier) {
public String placeholderRequest(String identifier) {
int total = 0;
for (int num : VotingPluginMain.plugin.getTopVoter(TopVoter.Daily).values()) {
total += num;
@@ -586,10 +672,10 @@ public class PlaceHolders {
}
}.withDescription("Global daily total"));
nonPlayerPlaceholders.add(new PlaceHolder<VotingPluginUser>("TimeUntilDayReset") {
nonPlayerPlaceholders.add(new NonPlayerPlaceHolder<VotingPluginUser>("TimeUntilDayReset") {
@Override
public String placeholderRequest(OfflinePlayer p, VotingPluginUser user, String identifier) {
public String placeholderRequest(String identifier) {
LocalDateTime now = LocalDateTime.now();
LocalDateTime offsetoclocktoday = plugin.getTimeChecker().getTime().withHour(0).withMinute(0);
LocalDateTime offsetoclocktomorrow = plugin.getTimeChecker().getTime().plusDays(1).withHour(0)
@@ -623,5 +709,166 @@ public class PlaceHolders {
}
}.withDescription("Time until plugin time day changes"));
Set<String> placeholdersSet = new HashSet<String>();
placeholdersSet.addAll(plugin.getConfigFile().getCachedPlaceholders());
if (plugin.getConfigFile().isAutoCachePlaceholders()) {
placeholdersSet.addAll(plugin.getServerData().getAutoCachedPlaceholder());
}
for (String toCache : placeholdersSet) {
if (toCache.startsWith("VotingPlugin")) {
toCache = toCache.substring("VotingPlugin_".length());
}
for (NonPlayerPlaceHolder<VotingPluginUser> placeholder : nonPlayerPlaceholders) {
if (placeholder.isUseStartsWith()) {
if (toCache.startsWith(placeholder.getIdentifier())) {
placeholder.setUseCache(true, toCache);
cachedPlaceholders.add(toCache);
plugin.extraDebug("Caching placeholder " + toCache);
}
} else {
if (placeholder.getIdentifier().equalsIgnoreCase(toCache)) {
placeholder.setUseCache(true, toCache);
cachedPlaceholders.add(toCache);
plugin.extraDebug("Caching placeholder " + toCache);
}
}
}
for (PlaceHolder<VotingPluginUser> placeholder : placeholders) {
if (placeholder.isUseStartsWith()) {
if (toCache.startsWith(placeholder.getIdentifier())) {
placeholder.setUseCache(true, toCache);
cachedPlaceholders.add(toCache);
plugin.extraDebug("Caching placeholder " + toCache);
}
} else {
if (placeholder.getIdentifier().equalsIgnoreCase(toCache)) {
placeholder.setUseCache(true, toCache);
cachedPlaceholders.add(toCache);
plugin.extraDebug("Caching placeholder " + toCache);
}
}
}
}
plugin.getUserManager().getUserDataChange().add(new UserDataChanged() {
@Override
public void onChange(AdvancedCoreUser user, String... keys) {
for (PlaceHolder<VotingPluginUser> placeholder : placeholders) {
if (placeholder.isUsesCache()) {
for (String key : keys) {
if (placeholder.getUpdateDataKey().equalsIgnoreCase(key)) {
VotingPluginUser vpUser = UserManager.getInstance().getVotingPluginUser(user);
for (String ident : placeholder.getCache().keySet()) {
placeholder.getCache().get(ident).put(vpUser.getJavaUUID(),
placeholder.placeholderRequest(vpUser, ident));
plugin.devDebug("Updated cache for " + vpUser.getUUID() + " on " + key);
}
}
}
}
}
}
});
}
public void onVotePartyUpdate() {
for (NonPlayerPlaceHolder<VotingPluginUser> placeholder : nonPlayerPlaceholders) {
if (placeholder.isUsesCache()) {
if (placeholder.getIdentifier().startsWith("VoteParty")) {
for (String ident : placeholder.getCache().keySet()) {
placeholder.getCache().put(ident, placeholder.placeholderRequest(ident));
}
}
}
}
}
public void onBungeeVotePartyUpdate() {
for (NonPlayerPlaceHolder<VotingPluginUser> placeholder : nonPlayerPlaceholders) {
if (placeholder.isUsesCache()) {
if (placeholder.getIdentifier().startsWith("BungeeVoteParty")) {
for (String ident : placeholder.getCache().keySet()) {
placeholder.getCache().put(ident, placeholder.placeholderRequest(ident));
}
}
}
}
}
public void onUpdate(VotingPluginUser user) {
for (PlaceHolder<VotingPluginUser> placeholder : placeholders) {
if (placeholder.isUsesCache()) {
if (!placeholder.getIdentifier().startsWith("Top_") || placeholder.getCache().isEmpty()
|| placeholder.getUpdateDataKey().isEmpty()) {
for (String ident : placeholder.getCache().keySet()) {
placeholder.getCache().get(ident).put(user.getJavaUUID(),
placeholder.placeholderRequest(user, ident));
}
}
}
}
}
public void onUpdate() {
ArrayList<String> uuids = UserManager.getInstance().getAllUUIDs();
while (!placeholdersToSetCacheOn.isEmpty()) {
String toCache = placeholdersToSetCacheOn.poll();
for (NonPlayerPlaceHolder<VotingPluginUser> placeholder : nonPlayerPlaceholders) {
if (placeholder.matches(toCache)) {
placeholder.setUseCache(true, toCache);
cachedPlaceholders.add(toCache);
plugin.getServerData().addAutoCachedPlaceholder(toCache);
plugin.debug("Auto caching placeholder: " + toCache);
}
}
for (PlaceHolder<VotingPluginUser> placeholder : placeholders) {
if (placeholder.matches(toCache)) {
placeholder.setUseCache(true, toCache);
cachedPlaceholders.add(toCache);
plugin.getServerData().addAutoCachedPlaceholder(toCache);
plugin.debug("Auto caching placeholder: " + toCache);
}
}
}
for (NonPlayerPlaceHolder<VotingPluginUser> placeholder : nonPlayerPlaceholders) {
if (placeholder.isUsesCache()) {
for (String ident : placeholder.getCache().keySet()) {
if (ident != null) {
String str = placeholder.placeholderRequest(ident);
if (str != null) {
placeholder.getCache().put(ident, str);
}
} else {
plugin.debug("ident null: " + placeholder.getIdentifier());
}
}
}
}
for (String uuid : uuids) {
VotingPluginUser user = UserManager.getInstance().getVotingPluginUser(UUID.fromString(uuid));
user.dontCache();
for (PlaceHolder<VotingPluginUser> placeholder : placeholders) {
if (placeholder.isUsesCache()) {
if (placeholder.getIdentifier().startsWith("Top_")) {
for (String ident : placeholder.getCache().keySet()) {
if (ident != null) {
placeholder.getCache().get(ident).put(user.getJavaUUID(),
placeholder.placeholderRequest(user, ident));
} else {
plugin.debug("ident null: " + placeholder.getIdentifier());
}
}
}
}
}
}
}
}
@@ -94,10 +94,14 @@ public class SpecialRewards {
}
if (gotCumulative) {
gotCumulativeAny = true;
plugin.debug(user.getPlayerName() + " got cumulative " + votesRequired + ", total: "
+ top.toString() + ", current total: " + total);
giveCumulativeVoteReward(user, user.isOnline(), votesRequired, forceBungee);
if (!plugin.getSpecialRewardsConfig().isOnlyOneCumulative() || !gotCumulativeAny) {
gotCumulativeAny = true;
plugin.debug(user.getPlayerName() + " got cumulative " + votesRequired + ", total: "
+ top.toString() + ", current total: " + total);
giveCumulativeVoteReward(user, user.isOnline(), votesRequired, forceBungee);
} else {
plugin.debug("Already got one cumulative");
}
} else {
plugin.devDebug(user.getPlayerName() + " not able to get cumulative " + votesRequired
+ ", total required: " + top.toString() + ", current player total: " + total);
@@ -23,7 +23,7 @@ public class TopVoterPlayer {
this.uuid = uuid;
this.playerName = playerName;
}
public ItemStack getPlayerHead() {
return PlayerUtils.getInstance().getPlayerSkull(getPlayerName(), false);
}
@@ -400,7 +400,7 @@ public class VotingPluginUser extends com.bencodez.advancedcore.api.user.Advance
public HashMap<String, Boolean> getHasGottenMilestone() {
HashMap<String, Boolean> hasGottenMilestone = new HashMap<String, Boolean>();
ArrayList<String> milestoneList = getUserData().getStringList("GottenMileStones");
ArrayList<String> milestoneList = getUserData().getStringList(getGottenMilestonesPath());
for (String str : milestoneList) {
String[] data = str.split("//");
if (data.length > 1) {
@@ -788,7 +788,14 @@ public class VotingPluginUser extends com.bencodez.advancedcore.api.user.Advance
String str = entry.getKey() + "//" + entry.getValue().booleanValue();
data.add(str);
}
getUserData().setStringList("GottenMileStones", data);
getUserData().setStringList(getGottenMilestonesPath(), data);
}
public String getGottenMilestonesPath() {
if (plugin.getBungeeSettings().isPerServerMilestones()) {
return plugin.getOptions().getServer() + "_" + "GottenMilestones";
}
return "GottenMileStones";
}
public void setHighestDailyTotal(int total) {
@@ -7,6 +7,7 @@ import java.util.UUID;
import org.bukkit.Bukkit;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
@@ -38,6 +39,7 @@ public class VoteParty implements Listener {
public void addTotal(VotingPluginUser user) {
setTotalVotes(getTotalVotes() + 1);
user.setVotePartyVotes(user.getVotePartyVotes() + 1);
plugin.getPlaceholders().onVotePartyUpdate();
}
/**
@@ -185,13 +187,23 @@ public class VoteParty implements Listener {
if (plugin.getSpecialRewardsConfig().getVotePartyGiveAllPlayers()) {
plugin.debug("Trying to give all players vote party");
for (String uuid : UserManager.getInstance().getAllUUIDs()) {
VotingPluginUser user = UserManager.getInstance().getVotingPluginUser(UUID.fromString(uuid));
ArrayList<String> alreadyGotten = new ArrayList<String>();
for (Player p : Bukkit.getOnlinePlayers()) {
VotingPluginUser user = UserManager.getInstance().getVotingPluginUser(p);
user.dontCache();
if (!plugin.getSpecialRewardsConfig().isVotePartyGiveOnlinePlayersOnly() || user.isOnline()) {
giveReward(user, forceBungee);
}
alreadyGotten.add(p.getUniqueId().toString());
}
for (String uuid : UserManager.getInstance().getAllUUIDs()) {
if (!alreadyGotten.contains(uuid)) {
VotingPluginUser user = UserManager.getInstance().getVotingPluginUser(UUID.fromString(uuid));
user.dontCache();
if (!plugin.getSpecialRewardsConfig().isVotePartyGiveOnlinePlayersOnly() || user.isOnline()) {
giveReward(user, forceBungee);
}
}
}
} else {
plugin.debug("Trying to give all voted players vote party");
@@ -2,6 +2,8 @@ package com.bencodez.votingplugin.votereminding;
import java.util.Timer;
import java.util.TimerTask;
import java.util.UUID;
import java.util.concurrent.ConcurrentHashMap;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
@@ -11,6 +13,8 @@ import com.bencodez.votingplugin.VotingPluginMain;
import com.bencodez.votingplugin.user.UserManager;
import com.bencodez.votingplugin.user.VotingPluginUser;
import lombok.Getter;
// TODO: Auto-generated Javadoc
/**
* The Class VoteReminding.
@@ -22,6 +26,9 @@ public class VoteReminding {
private Timer timer;
@Getter
private ConcurrentHashMap<UUID, Boolean> remindersEnabled = new ConcurrentHashMap<UUID, Boolean>();
public VoteReminding(VotingPluginMain plugin) {
this.plugin = plugin;
}
@@ -62,7 +69,7 @@ public class VoteReminding {
@Override
public void run() {
if (plugin != null) {
if (plugin != null && plugin.isEnabled()) {
for (Player player : Bukkit.getServer().getOnlinePlayers()) {
VotingPluginUser user = UserManager.getInstance().getVotingPluginUser(player);
checkRemind(user);
@@ -95,6 +102,11 @@ public class VoteReminding {
}
public boolean shouldRemind(VotingPluginUser user) {
if (remindersEnabled.containsKey(user.getJavaUUID())) {
if (!remindersEnabled.get(user.getJavaUUID()).booleanValue()) {
return false;
}
}
if (user.shouldBeReminded()) {
boolean hasPermAll = user.hasPermission("VotingPlugin.Login.RemindVotes.All");
if (hasPermAll) {