Compare commits

...
94 Commits
Author SHA1 Message Date
BuildTools 2dfd8dcfa5 Update version number to 6.8.2 2022-02-13 15:59:08 -05:00
BuildTools 00791766f1 Change default value of config option 2022-02-13 14:28:26 -05:00
ben 4d2c783d85 Improve getting uuid on proxy setups, more efficient 2022-02-11 17:14:05 -05:00
ben 19f1664662 Ignore casing when checking for disabled votesites 2022-02-06 12:34:01 -05:00
ben ca2e6fb530 Add extra null check 2022-02-02 16:57:28 -05:00
Ben eca7c6641a Merge pull request #1220 from pseudoforceyt/patch-1
Fix bungee setup wiki link
2022-01-24 16:46:52 -05:00
Ilamparithi M 47fe6b57e2 Fix bungee setup wiki link 2022-01-24 19:34:57 +05:30
ben 911819c69b Fix weekly top voters rewards feeding off monthly top voters 2022-01-23 14:03:25 -05:00
ben cda72b5c5b Let AdvancedCore handle vanished players 2022-01-23 13:18:16 -05:00
ben 75a3da98fa Change dependency 2022-01-22 15:24:13 -05:00
ben ced74fdee3 Changes to vanish event 2022-01-22 14:22:58 -05:00
ben b8460ff755 Add debug message for vanish login 2022-01-21 22:08:29 -05:00
ben 50bb1facc4 Modify event handling for playershowevent 2022-01-21 21:20:54 -05:00
ben 5ed21949e1 Add soft depends 2022-01-19 21:28:09 -05:00
ben 253e4937db Fix playershowevent not working completely 2022-01-19 19:51:32 -05:00
ben 192685ceec Add playershowevent for vanished players 2022-01-19 17:10:38 -05:00
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
BenCodez 68a2fe27ff Update version number to 6.7 2021-10-10 14:08:38 -04:00
BenCodez b05317c460 Fix a few things with bungee voteparty 2021-10-10 13:50:47 -04:00
BenCodez 62fee6f347 Fix voteshop confirm not going back to main voteshop gui when it should 2021-10-05 20:25:44 -04:00
BenCodez ef7d4254e1 Fix more issues with velocity 2021-10-03 14:07:36 -04:00
BenCodez b6720ccc1f Fix issue on velocity 2021-10-03 13:52:43 -04:00
BenCodez 69d3d33008 Fix issue on velocity 2021-10-03 12:33:18 -04:00
BenCodez 7a193c87a9 Add vote party on bungee, online only, partly tested 2021-09-27 20:16:25 -04:00
BenCodez f2cf2fb734 Fix top voter clicking in GUI 2021-09-25 15:43:53 -04:00
BenCodez 836079b5ea Prevent NPE 2021-09-19 12:02:55 -04:00
BenCodez a7f6456480 Add option for closing inventory on vote 2021-09-17 17:15:51 -04:00
BenCodez 82f25c3899 Add debug message for disabled milstone 2021-09-13 17:23:22 -04:00
BenCodez cb2cdbd4fc Add points placeholder to vote shop 2021-09-08 16:59:15 -04:00
BenCodez 40d2b651a8 Update version number to 6.3.3 2021-09-05 12:26:42 -04:00
BenCodez a999d9e9bb Sync votes better with cache 2021-09-01 18:59:09 -04:00
BenCodez b144f2db9c Small change to caching on voting 2021-09-01 18:50:01 -04:00
BenCodez 24060a10ed Small improvement 2021-09-01 14:56:17 -04:00
BenCodez 4c8919804f Prevent duplicate broadcasts if bungee broadcasts 2021-08-30 15:21:59 -04:00
60 changed files with 1619 additions and 477 deletions

No files matched your search

+14 -13
View File
@@ -9,7 +9,7 @@ UseBungeecord: false
# What type of bungee setup
# Requires restart and set on all servers
# https://github.com/BenCodez/VotingPlugin/wiki/Bungeecoord-Setups
# https://github.com/BenCodez/VotingPlugin/wiki/Bungeecord-Setups
# Available:
# SOCKETS
# PLUGINMESSAGING
@@ -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
@@ -51,18 +56,14 @@ TriggerVotifierEvent: false
# Also can be applied to rewards
Server: PleaseSet
# Rewards from bungee vote party
# Gives to only players only
# Use regular voteparty rewards otherwise
# Can edit via /av gui
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
+29 -5
View File
@@ -22,15 +22,12 @@ MySQL:
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
# Don't use with PLUGINMESSAGING bungee setup
Prefix: ''
#UseSSL: true
#PublicKeyRetrieval: false
#MaxLifeTime: -1
#Additional info on connection string
#Line: ''
@@ -80,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!'
@@ -252,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
@@ -426,6 +427,10 @@ LimitMonthlyVotes: false
# Shoudn't be needed, but enable if you have trouble with milestones
PreventRepeatMilestones: false
# Close inventory on player vote
# This is to prevent any possible exploits
CloseInventoryOnVote: true
# When enabled the command /vote setprimaryaccount (playername)
# will be shown (after restart)
# Primary account will be used instead of the players account to get
@@ -438,6 +443,20 @@ UsePrimaryAccountForPlaceholders: false
# Only affects placeholderapi placeholders
AlwaysWaitForCachePlaceholders: false
# Enable auto caching placeholders
# Generally this works well, but if you need to cache placeholders manually set them below
AutoCachePlaceholders: false
# 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 +583,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
+3 -2
View File
@@ -79,8 +79,8 @@ CHEST:
# Name: 'Extra item'
## Works on most GUI items
# Slot: 10
## Send rewards on click, run commands, check conditions, etc
# Rewards: []
## Send rewards on click, run commands, check conditions, etc
# Rewards: []
# GUI for /vote url, /vote
VoteURL:
@@ -204,6 +204,7 @@ CHEST:
Amount: 1
VoteBest:
Name: 'VoteBest: %player%'
BackButton: true
DayBest:
Item:
Material: 'CLOCK'
+11 -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
@@ -168,6 +173,11 @@ LogoutRewards: {}
EnableMonthlyAwards: true
# TopVoter Placeholders:
#%place% - place in topvoter
#%topvoter% - topvoter type
#%votes% - current total votes related to top voter
# Rewards to give
MonthlyAwards:
# Position. 1 is first in top voter, 2 is second, etc...
+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
+25 -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,10 +48,33 @@ 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
VoteParty:
# If enabled, will trigger vote party reward
# in BungeeSettings.yml under BungeeVotePartyReward
# Only runs rewards for online players
Enabled: false
# Votes required
VotesRequired: 100
# Increase amount required on each vote party
IncreaseVotesRequired: 0
# If false, will only send to servers listed below
SendToAllServers: true
# Servers to send to, if SendToAllServers is false
ServersToSend: []
# List of commands to run on bungee server
# Set spigot commands in BungeeSettings.yml
BungeeCommands: []
Broadcast: '&aVote party has been reached!'
# ----------------------------
# PLUGINMESSAGING Settings
# ----------------------------
@@ -68,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
+9 -13
View File
@@ -4,11 +4,11 @@ main: com.bencodez.votingplugin.VotingPluginMain
description: Highly Customizable Voting Listener!
website: https://www.spigotmc.org/resources/votingplugin.15358/
author: BenCodez
softdepend: [MVdWPlaceholders, Votifier, VotifierPlus, NuVotifier, CMI, Vault, PlaceholderAPI, ProtocolLib, MVdWPlaceholderAPI, AuthMe]
softdepend: [MVdWPlaceholders, Votifier, VotifierPlus, NuVotifier, CMI, Vault, PlaceholderAPI, ProtocolLib, MVdWPlaceholderAPI, AuthMe, SuperVanish, PremiumVanish]
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.6.2</version>
<version>6.8.2</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>
@@ -4,7 +4,15 @@ import java.io.File;
import java.util.ArrayList;
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;
@@ -18,7 +26,7 @@ import com.bencodez.votingplugin.user.VotingPluginUser;
import lombok.Getter;
public class BungeeHandler {
public class BungeeHandler implements Listener {
@Getter
private ClientHandler clientHandler;
@@ -29,6 +37,12 @@ public class BungeeHandler {
private VotingPluginMain plugin;
@Getter
private int bungeeVotePartyCurrent = 0;
@Getter
private int bungeeVotePartyRequired = 0;
@Getter
private SocketHandler socketHandler;
@@ -39,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() {
@@ -53,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
@@ -77,22 +104,36 @@ 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();
boolean broadcast = true;
boolean bungeeBroadcast = false;
if (!plugin.getBungeeSettings().isBungeeBroadcast()&& !plugin.getBungeeSettings().isDisableBroadcast()) {
if (wasOnline || plugin.getBungeeSettings().isBungeeBroadcastAlways()) {
VoteSite site = plugin.getVoteSite(service, true);
if (site != null) {
site.broadcastVote(user, false);
broadcast = false;
} else {
plugin.getLogger().warning("No votesite for " + service);
if (args.size() > 9) {
bungeeBroadcast = Boolean.valueOf(args.get(9));
}
if (!bungeeBroadcast) {
if (!plugin.getBungeeSettings().isBungeeBroadcast()
&& !plugin.getBungeeSettings().isDisableBroadcast()) {
if (wasOnline || plugin.getBungeeSettings().isBungeeBroadcastAlways()) {
VoteSite site = plugin.getVoteSite(service, true);
if (site != null) {
site.broadcastVote(user, false);
broadcast = false;
} else {
plugin.getLogger().warning("No votesite for " + service);
}
}
}
} else {
broadcast = false;
}
user.bungeeVotePluginMessaging(service, time, text, !setTotals, wasOnline, broadcast);
@@ -124,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),
@@ -139,17 +185,28 @@ public class BungeeHandler {
boolean wasOnline = Boolean.valueOf(args.get(4));
boolean broadcast = true;
boolean bungeeBroadcast = false;
if (!plugin.getBungeeSettings().isBungeeBroadcast() && !plugin.getBungeeSettings().isDisableBroadcast()) {
if (Boolean.valueOf(args.get(4)) || plugin.getBungeeSettings().isBungeeBroadcastAlways()) {
VoteSite site = plugin.getVoteSite(service, true);
if (site != null) {
site.broadcastVote(user, false);
broadcast = false;
} else {
plugin.getLogger().warning("No votesite for " + service);
if (args.size() > 9) {
bungeeBroadcast = Boolean.valueOf(args.get(9));
}
if (!bungeeBroadcast) {
if (!plugin.getBungeeSettings().isBungeeBroadcast()
&& !plugin.getBungeeSettings().isDisableBroadcast()) {
if (Boolean.valueOf(args.get(4))
|| plugin.getBungeeSettings().isBungeeBroadcastAlways()) {
VoteSite site = plugin.getVoteSite(service, true);
if (site != null) {
site.broadcastVote(user, false);
broadcast = false;
} else {
plugin.getLogger().warning("No votesite for " + service);
}
}
}
} else {
broadcast = false;
}
user.bungeeVotePluginMessaging(service, time, text, !setTotals, wasOnline, broadcast);
@@ -176,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);
}
});
@@ -207,6 +269,23 @@ public class BungeeHandler {
}
});
plugin.getPluginMessaging().add(new PluginMessageHandler("VotePartyBungee") {
@Override
public void onRecieve(String subChannel, ArrayList<String> args) {
for (Player p : Bukkit.getOnlinePlayers()) {
new RewardBuilder(plugin.getBungeeSettings().getData(), "BungeeVotePartyRewards").send(p);
}
}
});
plugin.getPluginMessaging().add(new PluginMessageHandler("VotePartyBroadcast") {
@Override
public void onRecieve(String subChannel, ArrayList<String> args) {
String broadcast = args.get(0);
MiscUtils.getInstance().broadcast(broadcast);
}
});
} else if (method.equals(BungeeMethod.SOCKETS)) {
encryptionHandler = new EncryptionHandler(new File(plugin.getDataFolder(), "secretkey.key"));
@@ -305,6 +384,25 @@ public class BungeeHandler {
}
});
socketHandler.add(new SocketReceiver("VotePartyBungee") {
@Override
public void onReceive(String[] data) {
for (Player p : Bukkit.getOnlinePlayers()) {
new RewardBuilder(plugin.getBungeeSettings().getData(), "BungeeVotePartyRewards").send(p);
}
}
});
socketHandler.add(new SocketReceiver("VotePartyBroadcast") {
@Override
public void onReceive(String[] data) {
String broadcast = data[0];
MiscUtils.getInstance().broadcast(broadcast);
}
});
if (plugin.getOptions().getServer().equalsIgnoreCase("pleaseset")) {
plugin.getLogger().warning("Server name for bungee voting is not set, please set it");
}
@@ -270,7 +270,11 @@ public class VotingPluginMain extends AdvancedCorePlugin {
}
public LinkedHashMap<TopVoterPlayer, Integer> getTopVoter(TopVoter top) {
return topVoter.get(top);
LinkedHashMap<TopVoterPlayer, Integer> top1 = topVoter.get(top);
if (top1 == null) {
top1 = new LinkedHashMap<TopVoterPlayer, Integer>();
}
return top1;
}
/**
@@ -340,11 +344,10 @@ public class VotingPluginMain extends AdvancedCorePlugin {
return siteName;
}
}
}
for (String siteName : sites) {
if (siteName.equalsIgnoreCase(url)) {
return siteName;
}
}
}
return url;
@@ -846,6 +849,28 @@ public class VotingPluginMain extends AdvancedCorePlugin {
});
}
addDirectlyDefinedRewards(new DirectlyDefinedReward("BungeeVotePartyRewards") {
@Override
public void createSection(String key) {
getBungeeSettings().createSection(key);
}
@Override
public ConfigurationSection getFileData() {
return getBungeeSettings().getData();
}
@Override
public void save() {
getBungeeSettings().saveData();
}
@Override
public void setData(String path, Object value) {
getBungeeSettings().setValue(path, value);
}
});
}
private void loadTimer() {
@@ -1077,7 +1102,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);
}
@@ -1090,7 +1115,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;
@@ -1189,8 +1214,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) {
@@ -1271,7 +1298,9 @@ public class VotingPluginMain extends AdvancedCorePlugin {
loadDirectlyDefined();
reloadAdvancedCore(userStorage);
getOptions().setServer(bungeeSettings.getServer());
placeholders.load();
if (userStorage) {
placeholders.load();
}
voteReminding.loadRemindChecking();
coolDownCheck.checkEnabled();
@@ -1316,98 +1345,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", "");
}
@@ -77,6 +81,34 @@ public class Config {
return getData().getBoolean("WaitForUserOnline", false);
}
public boolean getVotePartyEnabled() {
return getData().getBoolean("VoteParty.Enabled", false);
}
public boolean getVotePartySendToAllServers() {
return getData().getBoolean("VoteParty.SendToAllServers", true);
}
public int getVotePartyVotesRequired() {
return getData().getInt("VoteParty.VotesRequired", 100);
}
public int getVotePartyIncreaseVotesRequired() {
return getData().getInt("VoteParty.IncreaseVotesRequired", 0);
}
public String getVotePartyBroadcast() {
return getData().getString("VoteParty.Broadcast", "");
}
public List<String> getVotePartyServersToSend() {
return getData().getStringList("VoteParty.ServersToSend");
}
public List<String> getVotePartyBungeeCommands() {
return getData().getStringList("VoteParty.BungeeCommands");
}
public void load() {
if (!bungee.getDataFolder().exists()) {
bungee.getDataFolder().mkdir();
@@ -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();
}
@@ -18,6 +18,30 @@ public class VoteCache {
this.bungee = bungee;
}
public int getVotePartyCurrentVotes() {
return getData().getInt("VoteParty.CurrentVotes", 0);
}
public int getVotePartyInreaseVotesRequired() {
return getData().getInt("VoteParty.IncreaseVotes", 0);
}
public void setVotePartyCurrentVotes(int amount) {
getData().set("VoteParty.CurrentVotes", amount);
}
public void setVotePartyInreaseVotesRequired(int amount) {
getData().set("VoteParty.IncreaseVotes", amount);
}
public void setVotePartyCache(String server, int amount) {
getData().set("VoteParty.Cache." + server, amount);
}
public int getVotePartyCache(String server) {
return getData().getInt("VoteParty.Cache." + server, 0);
}
public void addVote(String server, int num, OfflineBungeeVote voteData) {
Configuration section = getData().getSection("VoteCache." + server + "." + num);
section.set("Name", voteData.getPlayerName());
@@ -20,12 +20,15 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map.Entry;
import java.util.UUID;
import java.util.concurrent.ConcurrentHashMap;
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,10 +39,11 @@ 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;
import net.md_5.bungee.api.CommandSender;
import net.md_5.bungee.api.chat.TextComponent;
import net.md_5.bungee.api.config.ServerInfo;
import net.md_5.bungee.api.connection.ProxiedPlayer;
import net.md_5.bungee.api.connection.Server;
@@ -78,6 +82,14 @@ public class VotingPluginBungee extends Plugin implements Listener {
private boolean votifierEnabled = true;
@Getter
private RedisBungee redis;
@Getter
private TimeHandle timeHandle;
private ConcurrentHashMap<UUID, String> uuidPlayerNameCache = new ConcurrentHashMap<UUID, String>();
public synchronized void checkCachedVotes(String server) {
if (getProxy().getServerInfo(server) != null) {
if (!getProxy().getServerInfo(server).getPlayers().isEmpty()) {
@@ -89,7 +101,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)) {
@@ -102,7 +114,7 @@ public class VotingPluginBungee extends Plugin implements Listener {
cache.getService(), "" + cache.getTime(), Boolean.FALSE.toString(),
"" + cache.isRealVote(), cache.getText(),
"" + getConfig().getBungeeManageTotals(),
"" + BungeeVersion.getPluginMessageVersion());
"" + BungeeVersion.getPluginMessageVersion(), "" + config.getBroadcast());
} else {
debug("Not sending vote because user isn't on server " + server + ": "
+ cache.toString());
@@ -118,7 +130,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) {
@@ -129,7 +141,7 @@ public class VotingPluginBungee extends Plugin implements Listener {
sendPluginMessageServer(server, "VoteOnline", cache.getPlayerName(), cache.getUuid(),
cache.getService(), "" + cache.getTime(), Boolean.FALSE.toString(),
"" + cache.isRealVote(), cache.getText(), "" + getConfig().getBungeeManageTotals(),
"" + BungeeVersion.getPluginMessageVersion());
"" + BungeeVersion.getPluginMessageVersion(), "" + config.getBroadcast());
}
cachedOnlineVotes.put(uuid, new ArrayList<OfflineBungeeVote>());
}
@@ -144,6 +156,9 @@ public class VotingPluginBungee extends Plugin implements Listener {
}
public UUID fetchUUID(String playerName) throws Exception {
if (playerName == null || playerName.equalsIgnoreCase("null")) {
return null;
}
// Get response from Mojang API
URL url = new URL("https://api.mojang.com/users/profiles/minecraft/" + playerName);
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
@@ -158,7 +173,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();
@@ -179,6 +194,13 @@ public class VotingPluginBungee extends Plugin implements Listener {
if (p != null && p.isConnected()) {
return p.getUniqueId().toString();
}
for (Entry<UUID, String> entry : uuidPlayerNameCache.entrySet()) {
if (entry.getValue().equalsIgnoreCase(playerName)) {
return entry.getKey().toString();
}
}
if (mysql != null) {
String str = mysql.getUUID(playerName);
if (str != null) {
@@ -309,12 +331,16 @@ public class VotingPluginBungee extends Plugin implements Listener {
num++;
}
}
voteCacheFile.save();
}
timeHandle.save();
voteCacheFile.save();
nonVotedPlayersCache.save();
if (mysql != null) {
mysql.shutdown();
}
if (redis != null) {
redis.destroy();
}
getLogger().info("VotingPlugin disabled");
}
@@ -333,9 +359,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;
@@ -359,15 +392,26 @@ public class VotingPluginBungee extends Plugin implements Listener {
this.getProxy().registerChannel("vp:vp");
if (mysqlLoaded) {
if (method.equals(BungeeMethod.MYSQL)) {
// this.getProxy().registerChannel("vp:vp");
uuidPlayerNameCache = mysql.getRowsUUIDNameQuery();
} else if (method.equals(BungeeMethod.PLUGINMESSAGING)) {
voteCacheFile = new VoteCache(this);
voteCacheFile.load();
voteCacheFile = new VoteCache(this);
voteCacheFile.load();
nonVotedPlayersCache = new NonVotedPlayersCache(this);
nonVotedPlayersCache.load();
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 {
for (String server : voteCacheFile.getServers()) {
@@ -472,6 +516,10 @@ public class VotingPluginBungee extends Plugin implements Listener {
}
}
currentVotePartyVotesRequired = getConfig().getVotePartyVotesRequired()
+ voteCacheFile.getVotePartyInreaseVotesRequired();
votePartyVotes = voteCacheFile.getVotePartyCurrentVotes();
BStatsMetricsBungee metrics = new BStatsMetricsBungee(this, 9453);
metrics.addCustomChart(
@@ -507,8 +555,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);
}
});
}
}
}
@@ -544,23 +628,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);
@@ -598,6 +676,8 @@ public class VotingPluginBungee extends Plugin implements Listener {
public void reload(boolean loadMysql) {
config.load();
currentVotePartyVotesRequired = getConfig().getVotePartyVotesRequired()
+ voteCacheFile.getVotePartyInreaseVotesRequired();
if (loadMysql) {
try {
if (!config.getData().getString("Host", "").isEmpty()) {
@@ -708,6 +788,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);
@@ -731,6 +812,8 @@ public class VotingPluginBungee extends Plugin implements Listener {
BungeeMessageData text = null;
addVoteParty();
if (getConfig().getBungeeManageTotals()) {
if (mysql == null) {
@@ -738,6 +821,7 @@ public class VotingPluginBungee extends Plugin implements Listener {
return;
}
// one time query to insert player
if (!mysql.getUuids().contains(uuid)) {
mysql.update(uuid, "PlayerName", new DataValueString(player));
}
@@ -750,7 +834,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)));
@@ -761,17 +846,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);
}
/*
* String text = mysqlUpdate(data, uuid, "AllTimeTotal", 1) + "//" +
* mysqlUpdate(data, uuid, "MonthTotal", 1) + "//" + mysqlUpdate(data, uuid,
* "WeeklyTotal", 1) + "//" + mysqlUpdate(data, uuid, "DailyTotal", 1) + "//" +
* mysqlUpdate(data, uuid, "Points", 1) + "//" + mysqlUpdate(data, uuid,
* "MilestoneCount", 1);
*/
long time = LocalDateTime.now().atZone(ZoneId.systemDefault()).toInstant().toEpochMilli();
if (method.equals(BungeeMethod.PLUGINMESSAGING)) {
@@ -782,7 +859,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");
}
@@ -802,7 +879,7 @@ public class VotingPluginBungee extends Plugin implements Listener {
sendPluginMessageServer(s, "Vote", player, uuid, service, "" + time,
Boolean.TRUE.toString(), "" + realVote, text.toString(),
"" + getConfig().getBungeeManageTotals(),
"" + BungeeVersion.getPluginMessageVersion());
"" + BungeeVersion.getPluginMessageVersion(), "" + config.getBroadcast());
}
if (config.getBroadcast()) {
sendPluginMessageServer(s, "VoteBroadcast", uuid, player, service);
@@ -811,11 +888,11 @@ 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());
"" + getConfig().getBungeeManageTotals(), "" + BungeeVersion.getPluginMessageVersion(),
"" + config.getBroadcast());
} else {
if (!cachedOnlineVotes.containsKey(uuid)) {
cachedOnlineVotes.put(uuid, new ArrayList<OfflineBungeeVote>());
@@ -829,7 +906,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);
}
@@ -844,4 +922,63 @@ public class VotingPluginBungee extends Plugin implements Listener {
}
private int votePartyVotes = 0;
private int currentVotePartyVotesRequired = 0;
public void addCurrentVotePartyVotes(int amount) {
votePartyVotes += amount;
voteCacheFile.setVotePartyCurrentVotes(votePartyVotes);
debug("Current vote party total: " + votePartyVotes);
}
public void addVoteParty() {
if (getConfig().getVotePartyEnabled()) {
addCurrentVotePartyVotes(1);
if (votePartyVotes >= currentVotePartyVotesRequired) {
debug("Vote party reached");
addCurrentVotePartyVotes(-currentVotePartyVotesRequired);
currentVotePartyVotesRequired += getConfig().getVotePartyIncreaseVotesRequired();
voteCacheFile.setVotePartyInreaseVotesRequired(voteCacheFile.getVotePartyInreaseVotesRequired()
+ getConfig().getVotePartyIncreaseVotesRequired());
if (!getConfig().getVotePartyBroadcast().isEmpty()) {
getProxy().broadcast(new TextComponent(
ChatColor.translateAlternateColorCodes('&', getConfig().getVotePartyBroadcast())));
}
for (String command : getConfig().getVotePartyBungeeCommands()) {
getProxy().getPluginManager().dispatchCommand(getProxy().getConsole(), command);
}
if (method.equals(BungeeMethod.PLUGINMESSAGING)) {
if (getConfig().getVotePartySendToAllServers()) {
for (Entry<String, ServerInfo> entry : getProxy().getServers().entrySet()) {
sendVoteParty(entry.getKey(), entry.getValue());
}
} else {
for (String server : getConfig().getVotePartyServersToSend()) {
ServerInfo serverInfo = getProxy().getServerInfo(server);
if (serverInfo != null) {
sendVoteParty(server, serverInfo);
}
}
}
}
}
voteCacheFile.save();
}
}
public void sendVoteParty(String server, ServerInfo serverInfo) {
if (!serverInfo.getPlayers().isEmpty()) {
if (method.equals(BungeeMethod.PLUGINMESSAGING)) {
sendPluginMessageServer(server, "VotePartyBungee");
} else if (method.equals(BungeeMethod.SOCKETS)) {
sendServerMessageServer(server, "VotePartyBungee");
}
}
}
}
@@ -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;
@@ -63,16 +65,44 @@ public class Config extends VelocityYMLFile {
return getBoolean(getNode("SendVotesToAllServers"), true);
}
public boolean getVotePartyEnabled() {
return getBoolean(getVotePartyNode().getNode("Enabled"), false);
}
public ConfigurationNode getVotePartyNode() {
return getNode("VoteParty");
}
public boolean getVotePartySendToAllServers() {
return getBoolean(getVotePartyNode().getNode("SendToAllServers"), false);
}
public int getVotePartyVotesRequired() {
return getInt(getVotePartyNode().getNode("VotesRequired"), 100);
}
public int getVotePartyIncreaseVotesRequired() {
return getInt(getVotePartyNode().getNode("IncreaseVotesRequired"), 0);
}
public String getVotePartyBroadcast() {
return getString(getVotePartyNode().getNode("Broadcast"), "");
}
public List<String> getVotePartyServersToSend() {
return getStringList(getVotePartyNode().getNode("ServersToSend"), new ArrayList<String>());
}
public List<String> getVotePartyBungeeCommands() {
return getStringList(getVotePartyNode().getNode("BungeeCommands"), new ArrayList<String>());
}
public ConfigurationNode getSpigotServerConfiguration(String s) {
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() {
@@ -14,6 +14,30 @@ public class VoteCache extends VelocityYMLFile {
super(file);
}
public int getVotePartyCurrentVotes() {
return getInt(getNode("VoteParty").getNode("CurrentVotes"), 0);
}
public int getVotePartyInreaseVotesRequired() {
return getInt(getNode("VoteParty").getNode("IncreaseVotes"), 0);
}
public void setVotePartyCurrentVotes(int amount) {
getNode("VoteParty").getNode("CurrentVotes").setValue(amount);
}
public void setVotePartyInreaseVotesRequired(int amount) {
getNode("VoteParty").getNode("IncreaseVotes").setValue(amount);
}
public void setVotePartyCache(String server, int amount) {
getNode("VoteParty").getNode("Cache").getNode(server).setValue(amount);
}
public int getVotePartyCache(String server) {
return getNode("VoteParty").getNode("Cache").getNode(server).getInt(0);
}
public void addVote(String server, int num, OfflineBungeeVote voteData) {
String[] path = new String[] { "VoteCache", server, "" + num };
@@ -20,13 +20,16 @@ import java.sql.SQLException;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map.Entry;
import java.util.Timer;
import java.util.TimerTask;
import java.util.UUID;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.TimeUnit;
import java.util.regex.Pattern;
import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream;
@@ -36,6 +39,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;
@@ -48,9 +52,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;
@@ -107,6 +111,11 @@ public class VotingPluginVelocity {
private Timer timer;
@Getter
private TimeHandle timeHandle;
private ConcurrentHashMap<UUID, String> uuidPlayerNameCache = new ConcurrentHashMap<UUID, String>();
@Inject
public VotingPluginVelocity(ProxyServer server, Logger logger, Metrics.Factory metricsFactory,
@DataDirectory Path dataDirectory) {
@@ -143,7 +152,7 @@ public class VotingPluginVelocity {
sendPluginMessageServer(serverToCheck, "Vote", cache.getPlayerName(), cache.getUuid(),
cache.getService(), "" + cache.getTime(), Boolean.FALSE.toString(),
"" + cache.isRealVote(), cache.getText(), "" + getConfig().getBungeeManageTotals(),
"" + BungeeVersion.getPluginMessageVersion());
"" + BungeeVersion.getPluginMessageVersion(), "" + config.getBroadcast());
} else {
debug("Not sending vote because user isn't on server " + serverToCheck + ": "
+ cache.toString());
@@ -169,7 +178,7 @@ public class VotingPluginVelocity {
sendPluginMessageServer(serverToCheck, "VoteOnline", cache.getPlayerName(), cache.getUuid(),
cache.getService(), "" + cache.getTime(), Boolean.FALSE.toString(),
"" + cache.isRealVote(), cache.getText(), "" + getConfig().getBungeeManageTotals(),
"" + BungeeVersion.getPluginMessageVersion());
"" + BungeeVersion.getPluginMessageVersion(), "" + config.getBroadcast());
}
cachedOnlineVotes.put(uuid, new ArrayList<OfflineBungeeVote>());
}
@@ -198,7 +207,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();
@@ -223,6 +232,11 @@ public class VotingPluginVelocity {
return p.getUniqueId().toString();
}
}
for (Entry<UUID, String> entry : uuidPlayerNameCache.entrySet()) {
if (entry.getValue().equalsIgnoreCase(playerName)) {
return entry.getKey().toString();
}
}
if (mysql != null) {
String str = mysql.getUUID(playerName);
if (str != null) {
@@ -333,6 +347,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
@@ -374,9 +396,9 @@ public class VotingPluginVelocity {
num++;
}
}
voteCacheFile.save();
}
timeHandle.save();
voteCacheFile.save();
nonVotedPlayersCache.save();
if (mysql != null) {
mysql.shutDown();
@@ -431,14 +453,24 @@ public class VotingPluginVelocity {
server.getCommandManager().register(meta, new VotingPluginVelocityCommand(this));
if (mysqlLoaded) {
if (method.equals(BungeeMethod.MYSQL)) {
// this.getProxy().registerChannel("vp:vp");
uuidPlayerNameCache = mysql.getRowsUUIDNameQuery();
} else if (method.equals(BungeeMethod.PLUGINMESSAGING)) {
voteCacheFile = new VoteCache(new File(dataDirectory.toFile(), "votecache.yml"));
nonVotedPlayersCache = new NonVotedPlayersCache(
new File(dataDirectory.toFile(), "nonvotedplayerscache.yml"), this);
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()) {
ArrayList<OfflineBungeeVote> vote = new ArrayList<OfflineBungeeVote>();
@@ -480,7 +512,9 @@ public class VotingPluginVelocity {
}
for (String player : cachedOnlineVotes.keySet()) {
checkOnlineVotes(server.getPlayer(UUID.fromString(player)).get(), player, null);
if (server.getPlayer(UUID.fromString(player)).isPresent()) {
checkOnlineVotes(server.getPlayer(UUID.fromString(player)).get(), player, null);
}
}
}).delay(15L, TimeUnit.SECONDS).repeat(30l, TimeUnit.SECONDS).schedule();
@@ -528,16 +562,20 @@ 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()));
}
}
}
}
currentVotePartyVotesRequired = getConfig().getVotePartyVotesRequired()
+ voteCacheFile.getVotePartyInreaseVotesRequired();
votePartyVotes = voteCacheFile.getVotePartyCurrentVotes();
try {
getVersionFile();
if (versionFile != null) {
@@ -671,6 +709,8 @@ public class VotingPluginVelocity {
public void reload(boolean loadMySQL) {
config.reload();
currentVotePartyVotesRequired = getConfig().getVotePartyVotesRequired()
+ voteCacheFile.getVotePartyInreaseVotesRequired();
if (loadMySQL) {
if (!config.getString(config.getNode("Host"), "").isEmpty()) {
loadMysql();
@@ -776,6 +816,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);
@@ -799,6 +840,8 @@ public class VotingPluginVelocity {
BungeeMessageData text = null;
addVoteParty();
if (getConfig().getBungeeManageTotals()) {
if (mysql == null) {
@@ -818,7 +861,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)));
@@ -829,7 +873,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);
}
/*
@@ -872,7 +916,7 @@ public class VotingPluginVelocity {
sendPluginMessageServer(s, "Vote", player, uuid, service, "" + time,
Boolean.TRUE.toString(), "" + realVote, text.toString(),
"" + getConfig().getBungeeManageTotals(),
"" + BungeeVersion.getPluginMessageVersion());
"" + BungeeVersion.getPluginMessageVersion(), "" + config.getBroadcast());
}
if (config.getBroadcast()) {
sendPluginMessageServer(s, "VoteBroadcast", uuid, player, service);
@@ -880,12 +924,16 @@ public class VotingPluginVelocity {
}
}
} else {
Player p = server.getPlayer(UUID.fromString(uuid)).get();
Player p = null;
if (server.getPlayer(UUID.fromString(uuid)).isPresent()) {
p = server.getPlayer(UUID.fromString(uuid)).get();
}
if (p != null && p.isActive() && !config.getBlockedServers()
.contains(p.getCurrentServer().get().getServerInfo().getName())) {
sendPluginMessageServer(p.getCurrentServer().get().getServer(), "VoteOnline", player, uuid,
service, "" + time, Boolean.TRUE.toString(), "" + realVote, text.toString(),
"" + getConfig().getBungeeManageTotals(), "" + BungeeVersion.getPluginMessageVersion());
"" + getConfig().getBungeeManageTotals(), "" + BungeeVersion.getPluginMessageVersion(),
"" + config.getBroadcast());
} else {
if (!cachedOnlineVotes.containsKey(uuid)) {
cachedOnlineVotes.put(uuid, new ArrayList<OfflineBungeeVote>());
@@ -900,7 +948,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);
}
@@ -913,4 +962,72 @@ public class VotingPluginVelocity {
e.printStackTrace();
}
}
private int votePartyVotes = 0;
private int currentVotePartyVotesRequired = 0;
public void addCurrentVotePartyVotes(int amount) {
votePartyVotes += amount;
voteCacheFile.setVotePartyCurrentVotes(votePartyVotes);
debug("Current vote party total: " + votePartyVotes);
}
public void addVoteParty() {
if (getConfig().getVotePartyEnabled()) {
addCurrentVotePartyVotes(1);
if (votePartyVotes >= currentVotePartyVotesRequired) {
debug("Current vote party total: " + votePartyVotes);
addCurrentVotePartyVotes(-currentVotePartyVotesRequired);
currentVotePartyVotesRequired += getConfig().getVotePartyIncreaseVotesRequired();
voteCacheFile.setVotePartyInreaseVotesRequired(voteCacheFile.getVotePartyInreaseVotesRequired()
+ getConfig().getVotePartyIncreaseVotesRequired());
if (!getConfig().getVotePartyBroadcast().isEmpty()) {
for (RegisteredServer server : getVotePartyServers()) {
if (method.equals(BungeeMethod.PLUGINMESSAGING)) {
sendPluginMessageServer(server, "VotePartyBroadcast", config.getVotePartyBroadcast());
} else if (method.equals(BungeeMethod.SOCKETS)) {
sendServerMessageServer(server.getServerInfo().getName(), config.getVotePartyBroadcast());
}
}
}
for (String command : getConfig().getVotePartyBungeeCommands()) {
server.getCommandManager().executeAsync(server.getConsoleCommandSource(), command);
}
if (method.equals(BungeeMethod.PLUGINMESSAGING)) {
for (RegisteredServer server : getVotePartyServers()) {
sendVoteParty(server);
}
}
}
voteCacheFile.save();
}
}
public Collection<RegisteredServer> getVotePartyServers() {
if (getConfig().getVotePartySendToAllServers()) {
return server.getAllServers();
}
Collection<RegisteredServer> list = new ArrayList<RegisteredServer>();
for (String server : getConfig().getVotePartyServersToSend()) {
if (this.server.getServer(server).isPresent()) {
list.add(this.server.getServer(server).get());
}
}
return list;
}
public void sendVoteParty(RegisteredServer server) {
if (!server.getPlayersConnected().isEmpty()) {
if (method.equals(BungeeMethod.PLUGINMESSAGING)) {
sendPluginMessageServer(server, "VotePartyBungee");
} else if (method.equals(BungeeMethod.SOCKETS)) {
sendServerMessageServer(server.getServerInfo().getName(), "VotePartyBungee");
}
}
}
}
@@ -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()));
}
});
@@ -149,6 +149,15 @@ public class AdminGUI {
}
});
buttons.add(new BInventoryButton(new ItemBuilder(Material.STONE, 1).setName("&cEdit BungeeVotePartyRewards")) {
@Override
public void onClick(ClickEvent clickEvent) {
RewardEditGUI.getInstance().openRewardGUI(clickEvent.getPlayer(),
RewardHandler.getInstance().getDirectlyDefined("BungeeVotePartyRewards"));
}
});
buttons.add(new BInventoryButton(new ItemBuilder("GRASS_BLOCK").setName("&cEdit BungeeSettings.yml")) {
@Override
@@ -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);
}
}
@@ -51,7 +51,11 @@ public class VoteShop extends GUIHandler {
return;
}
if (this.user == null) {
user = plugin.getVotingPluginUserManager().getVotingPluginUser(player);
}
BInventory inv = new BInventory(plugin.getGui().getChestVoteShopName());
inv.addPlaceholder("points", "" + user.getPoints());
inv.dontClose();
for (final String identifier : plugin.getGui().getChestShopIdentifiers()) {
@@ -68,7 +72,6 @@ public class VoteShop extends GUIHandler {
boolean limitPass = true;
if (limit > 0) {
VotingPluginUser user = UserManager.getInstance().getVotingPluginUser(player);
if (user.getVoteShopIdentifierLimit(identifier) >= limit) {
limitPass = false;
}
@@ -131,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);
new VoteShop(plugin, event.getPlayer(), user).open();
}
}
});
@@ -104,8 +104,8 @@ public class VoteTopVoter extends GUIHandler {
@Override
public void onClick(ClickEvent clickEvent) {
if (plugin.getGui().getChestVoteTopOpenMainGUIOnClick()) {
VotingPluginUser user = (VotingPluginUser) getData("User");
new VoteGUI(plugin, player, user)
TopVoterPlayer user = (TopVoterPlayer) getData("User");
new VoteGUI(plugin, player, user.getUser())
.open(GUIMethod.valueOf(plugin.getGui().getGuiMethodGUI().toUpperCase()));
} else {
getInv().forceClose(clickEvent.getPlayer());
@@ -74,8 +74,8 @@ public class VoteTopVoterLastMonth extends GUIHandler {
@Override
public void onClick(ClickEvent clickEvent) {
VotingPluginUser user = (VotingPluginUser) getData("User");
new VoteGUI(plugin, player, user)
TopVoterPlayer user = (TopVoterPlayer) getData("User");
new VoteGUI(plugin, player, user.getUser())
.open(GUIMethod.valueOf(plugin.getGui().getGuiMethodGUI().toUpperCase()));
}
}.addData("player", entry.getKey().getPlayerName()).addData("User", entry.getKey()));
@@ -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;
@@ -117,6 +129,10 @@ public class Config extends YMLFile {
@Getter
private boolean extraAllSitesCheck = false;
@ConfigDataBoolean(path = "CloseInventoryOnVote")
@Getter
private boolean closeInventoryOnVote = true;
@ConfigDataBoolean(path = "ExtraBackgroundUpdate")
@Getter
private boolean extraBackgroundUpdate = false;
@@ -170,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;
}
}
@@ -18,7 +18,7 @@ import com.bencodez.votingplugin.signs.SignHandler;
public class BlockBreak implements Listener {
/** The plugin. */
private static VotingPluginMain plugin;
private VotingPluginMain plugin;
/**
* Instantiates a new block break.
@@ -26,7 +26,7 @@ public class BlockBreak implements Listener {
* @param plugin the plugin
*/
public BlockBreak(VotingPluginMain plugin) {
BlockBreak.plugin = plugin;
this.plugin = plugin;
}
/**
@@ -21,7 +21,7 @@ import com.bencodez.votingplugin.user.UserManager;
public class PlayerInteract implements Listener {
/** The plugin. */
private static VotingPluginMain plugin;
private VotingPluginMain plugin;
/**
* Instantiates a new player interact.
@@ -29,7 +29,7 @@ public class PlayerInteract implements Listener {
* @param plugin the plugin
*/
public PlayerInteract(VotingPluginMain plugin) {
PlayerInteract.plugin = plugin;
this.plugin = plugin;
}
/**
@@ -21,7 +21,7 @@ import com.bencodez.votingplugin.user.VotingPluginUser;
public class PlayerJoinEvent implements Listener {
/** The plugin. */
private static VotingPluginMain plugin;
private VotingPluginMain plugin;
/**
* Instantiates a new player join event.
@@ -29,7 +29,7 @@ public class PlayerJoinEvent implements Listener {
* @param plugin the plugin
*/
public PlayerJoinEvent(VotingPluginMain plugin) {
PlayerJoinEvent.plugin = plugin;
this.plugin = plugin;
}
private void login(Player player) {
@@ -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()) {
@@ -103,22 +107,25 @@ public class PlayerVoteListener implements Listener {
user = UserManager.getInstance().getVotingPluginUser(playerName);
}
// reupdate cache
user.clearCache();
user.updateName(true);
if (voteSite.isWaitUntilVoteDelay() && !user.canVoteSite(voteSite)) {
plugin.getLogger().info(user.getPlayerName() + " must wait until votedelay is over, ignoring vote");
return;
}
synchronized (object) {
if (!plugin.isEnabled()) {
return;
}
// reupdate cache
user.clearCache();
user.cache();
user.updateName(true);
// vote party
plugin.getVoteParty().vote(user, event.isRealVote(), event.isForceBungee());
if (event.isBroadcast() && !plugin.getBungeeSettings().isDisableBroadcast() ) {
if (event.isBroadcast() && !plugin.getBungeeSettings().isDisableBroadcast()) {
// broadcast vote if enabled in config
if (plugin.getConfigFile().isBroadcastVotesEnabled()
&& (plugin.getBungeeSettings().isBungeeBroadcast() || !event.isBungee())) {
@@ -143,8 +150,7 @@ public class PlayerVoteListener implements Listener {
// try logging to file
if (plugin.getConfigFile().isLogVotesToFile()) {
try {
VotingPluginMain.plugin.logVote(
LocalDateTime.now().atZone(ZoneId.systemDefault()).toLocalDateTime(), playerName,
plugin.logVote(LocalDateTime.now().atZone(ZoneId.systemDefault()).toLocalDateTime(), playerName,
voteSite.getKey());
} catch (Exception e) {
e.printStackTrace();
@@ -160,16 +166,17 @@ public class PlayerVoteListener implements Listener {
}
// check if player has voted on all sites in one day
if (((user.isOnline() || voteSite.isGiveOffline())
&& VotingPluginMain.plugin.getOptions().isProcessRewards()) || event.isBungee()) {
if (((user.isOnline() || voteSite.isGiveOffline()) && plugin.getOptions().isProcessRewards())
|| event.isBungee()) {
boolean online = true;
if (event.isBungee()) {
online = event.isWasOnline();
}
user.playerVote(voteSite, online, false, event.isForceBungee());
user.sendVoteEffects(online);
user.closeInv();
if (plugin.getConfigFile().isCloseInventoryOnVote()) {
user.closeInv();
}
} else {
user.addOfflineVote(voteSite.getKey());
plugin.debug(
@@ -212,6 +219,10 @@ public class PlayerVoteListener implements Listener {
}
}
PlayerPostVoteEvent postVoteEvent = new PlayerPostVoteEvent(voteSite, user, event.isRealVote(),
event.isForceBungee());
plugin.getServer().getPluginManager().callEvent(postVoteEvent);
plugin.setUpdate(true);
}
@@ -16,7 +16,7 @@ import com.bencodez.votingplugin.VotingPluginMain;
public class SignChange implements Listener {
/** The plugin. */
private static VotingPluginMain plugin;
private VotingPluginMain plugin;
/**
* Instantiates a new sign change.
@@ -24,7 +24,7 @@ public class SignChange implements Listener {
* @param plugin the plugin
*/
public SignChange(VotingPluginMain plugin) {
SignChange.plugin = plugin;
this.plugin = plugin;
}
/**
@@ -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))) {
@@ -89,7 +82,7 @@ public class VotiferEvent implements Listener {
ArrayList<String> sites = plugin.getConfigVoteSites().getVoteSitesNames(false);
boolean createSite = false;
if (sites != null) {
if (!sites.contains(voteSiteNameStr)) {
if (!ArrayUtils.getInstance().containsIgnoreCase(sites, voteSiteNameStr)) {
createSite = true;
}
} else {
@@ -14,7 +14,7 @@ import com.bencodez.votingplugin.VotingPluginMain;
public class VotingPluginUpdateEvent implements Listener {
/** The plugin. */
private static VotingPluginMain plugin;
private VotingPluginMain plugin;
/**
* Instantiates a new advanced core update event.
@@ -22,7 +22,7 @@ public class VotingPluginUpdateEvent implements Listener {
* @param plugin the plugin
*/
public VotingPluginUpdateEvent(VotingPluginMain plugin) {
VotingPluginUpdateEvent.plugin = plugin;
this.plugin = plugin;
}
/**
@@ -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);
@@ -187,6 +191,8 @@ public class SpecialRewards {
plugin.debug(user.getPlayerName() + " got milestone " + votesRequired);
}
} else {
plugin.debug("Milestone " + votesRequired + " not enabled or has no rewards");
}
}
} else {
@@ -335,7 +335,7 @@ public class TopVoterHandler implements Listener {
int lastTotal = -1;
@SuppressWarnings("unchecked")
LinkedHashMap<TopVoterPlayer, Integer> clone = (LinkedHashMap<TopVoterPlayer, Integer>) plugin
.getTopVoter(TopVoter.Monthly).clone();
.getTopVoter(TopVoter.Weekly).clone();
for (Entry<TopVoterPlayer, Integer> entry : clone.entrySet()) {
VotingPluginUser user = entry.getKey().getUser();
user.dontCache();
@@ -23,7 +23,7 @@ public class TopVoterPlayer {
this.uuid = uuid;
this.playerName = playerName;
}
public ItemStack getPlayerHead() {
return PlayerUtils.getInstance().getPlayerSkull(getPlayerName(), false);
}
@@ -306,12 +306,14 @@ public class VotingPluginUser extends com.bencodez.advancedcore.api.user.Advance
ArrayList<Integer> days = new ArrayList<Integer>();
for (VoteSite voteSite : plugin.getVoteSites()) {
long time = user.getTime(voteSite);
if (time != 0) {
months.add(MiscUtils.getInstance().getMonthFromMili(time));
days.add(MiscUtils.getInstance().getDayFromMili(time));
} else {
return false;
if (voteSite.isEnabled() && !voteSite.isHidden()) {
long time = user.getTime(voteSite);
if (time != 0) {
months.add(MiscUtils.getInstance().getMonthFromMili(time));
days.add(MiscUtils.getInstance().getDayFromMili(time));
} else {
return false;
}
}
}
@@ -398,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) {
@@ -570,27 +572,6 @@ public class VotingPluginUser extends com.bencodez.advancedcore.api.user.Advance
.setOnline(isOnline()).send(this);
}
/*
* public Integer hasLastCumulative(int votesRequired) { HashMap<Integer,
* Integer> lastCumative = getLastCumulatives(); if
* (lastCumative.containsKey(votesRequired)) { return
* lastCumative.get(votesRequired); } return 0; } public HashMap<Integer,
* Integer> getLastCumulatives() { HashMap<Integer, Integer> lastCumulative =
* new HashMap<Integer, Integer>(); ArrayList<String> milestoneList =
* getUserData().getStringList("LastCumulative"); for (String str :
* milestoneList) { String[] data = str.split("//"); if (data.length > 1) { try
* { lastCumulative.put(Integer.parseInt(data[0]), Integer.parseInt(data[1])); }
* catch (Exception e) { e.printStackTrace(); } } } return lastCumulative; }
* public void setLastCumulatives(HashMap<Integer, Integer> lastCumulative) {
* ArrayList<String> data = new ArrayList<String>(); for (Entry<Integer,
* Integer> entry : lastCumulative.entrySet()) { String str = entry.getKey() +
* "//" + entry.getValue(); data.add(str); }
* getUserData().setStringList("LastCumulative", data); } public void
* setLastCumulative(int votesRequired, int value) { HashMap<Integer, Integer>
* lastCumulative = getLastCumulatives(); lastCumulative.put(votesRequired,
* value); setLastCumulatives(lastCumulative); }
*/
public void giveMonthlyTopVoterAward(int place, String path) {
new RewardBuilder(plugin.getSpecialRewardsConfig().getData(),
plugin.getSpecialRewardsConfig().getMonthlyAwardRewardsPath(path)).withPlaceHolder("place", "" + place)
@@ -807,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) {