Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
8b03792a52 | ||
|
|
42d9f413f5 | ||
|
|
fdb8a86def | ||
|
|
b54cda1834 | ||
|
|
824a740c96 | ||
|
|
63ed67b137 | ||
|
|
6fd008e1a8 | ||
|
|
13afac8da2 | ||
|
|
31565f20fb | ||
|
|
d4abcec817 | ||
|
|
6675f12205 | ||
|
|
66d2903ff5 | ||
|
|
fffeea6435 | ||
|
|
b9ae8b8c6f | ||
|
|
974029523e | ||
|
|
70abbcc119 | ||
|
|
927be61e93 | ||
|
|
8a3341e7b9 | ||
|
|
e3ace6cf12 | ||
|
|
b84f230179 | ||
|
|
e2fd7347b4 | ||
|
|
223ba96a95 | ||
|
|
766efe0cda | ||
|
|
ab792de3c7 | ||
|
|
7807ef6d88 | ||
|
|
ba7407cca6 | ||
|
|
b83249187e | ||
|
|
2b22e7ea6f | ||
|
|
86b18f3bea | ||
|
|
f3c844b2f8 | ||
|
|
53568b6c6f | ||
|
|
35b034b9e7 | ||
|
|
45367d59d2 | ||
|
|
1ded5a4369 | ||
|
|
940f9a5662 | ||
|
|
319d4ead82 | ||
|
|
cd87ccf6ff | ||
|
|
9604c6c156 | ||
|
|
5b47d1b198 | ||
|
|
97d265045c | ||
|
|
ce508c4009 | ||
|
|
8094e8acec | ||
|
|
2d2cfe8ccf | ||
|
|
cb6d17c6e3 | ||
|
|
1811e18420 | ||
|
|
964aeef138 | ||
|
|
524d001c28 | ||
|
|
976a8f4f62 | ||
|
|
b30ea9c7d3 | ||
|
|
ae60182cd7 | ||
|
|
b28cfac096 | ||
|
|
4b93353022 | ||
|
|
7715b3d66d | ||
|
|
5fbecec78b | ||
|
|
64f15a1bf2 | ||
|
|
9ab08c22be | ||
|
|
f29e4d99ba | ||
|
|
fdb53d550e | ||
|
|
c2ac312522 | ||
|
|
c87b5e5728 | ||
|
|
1eeea835aa | ||
|
|
cf6a6200ca |
No files matched your search
@@ -15,6 +15,16 @@
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.wst.validation.validationbuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.m2e.core.maven2Builder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
</buildSpec>
|
||||
<natures>
|
||||
<nature>org.eclipse.m2e.core.maven2Nature</nature>
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
activeProfiles=
|
||||
activeProfiles=dev
|
||||
eclipse.preferences.version=1
|
||||
resolveWorkspaceProjects=true
|
||||
version=1
|
||||
@@ -0,0 +1,8 @@
|
||||
DELEGATES_PREFERENCE=delegateValidatorList
|
||||
USER_BUILD_PREFERENCE=enabledBuildValidatorList
|
||||
USER_MANUAL_PREFERENCE=enabledManualValidatorList
|
||||
USER_PREFERENCE=overrideGlobalPreferencesfalse
|
||||
eclipse.preferences.version=1
|
||||
override=false
|
||||
suspend=false
|
||||
vf.version=3
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -29,6 +29,7 @@ MySQL:
|
||||
# Table name prefix, for use with mutliple servers
|
||||
Prefix: ''
|
||||
#UseSSL: true
|
||||
#PublicKeyRetrieval: false
|
||||
|
||||
# Let players who never joined before vote
|
||||
# Recommend: False (Will prevent creating random user data)
|
||||
@@ -89,36 +90,16 @@ VoteReminding:
|
||||
# ------------------------------------------------
|
||||
|
||||
# Common PlacesHolders:
|
||||
# Please Note: Not all are usable in all sections
|
||||
# Special PlaceHolders will be commented where available
|
||||
# %player% = player name
|
||||
# %SiteName% = vote site name
|
||||
#
|
||||
# Set Message to '' (2 ') to disable message
|
||||
|
||||
Commands:
|
||||
# Whether or not the following commands will open GUIs rather than display text
|
||||
UseGUI:
|
||||
Today: true
|
||||
TopVoter: true
|
||||
Last: true
|
||||
Next: true
|
||||
Total: true
|
||||
Vote: true
|
||||
Best: true
|
||||
Streak: true
|
||||
# If true, you can right click a votesite from /vote (gui version) and open the vote reward gui for that site
|
||||
# Can be used to display rewards for that site
|
||||
VoteRewardFromVoteURL: false
|
||||
# disable /vote reward commands
|
||||
# Effective after restart
|
||||
DisableVoteRewardGUIs: false
|
||||
# Enable to use book GUI instead of normal GUI
|
||||
VoteBookGUI: false
|
||||
|
||||
Format:
|
||||
# CommandHandler help message
|
||||
HelpLine: '&3&l%Command% - &3%HelpMessage%'
|
||||
# Mainly used in admin help page, see below for /vote help
|
||||
HelpLine: '&6%Command% - &6%HelpMessage%'
|
||||
|
||||
# Broadcast vote message
|
||||
# Set to an empty message to disable
|
||||
@@ -133,7 +114,7 @@ Format:
|
||||
# %url% = site URL
|
||||
Vote:
|
||||
Text:
|
||||
- '&6&lVote for our server!'
|
||||
- '&3&lVote for our server!'
|
||||
|
||||
# If you want to want to use the feature below where the plugin will
|
||||
# automaticly list the sites then set the message in the text above
|
||||
@@ -142,7 +123,7 @@ Format:
|
||||
# make sure to set VoteURL in your VoteSites
|
||||
# Requires above to be true
|
||||
# Text will be sent before this
|
||||
Sites: '&6%num%: &e&l%SiteName% - &e%url%'
|
||||
Sites: '&3%num%: &6&l%SiteName% &6- %url%'
|
||||
|
||||
# If true, links will always be forced as urls
|
||||
ForceLinks: true
|
||||
@@ -211,9 +192,9 @@ Format:
|
||||
# Format for /vote help
|
||||
Help:
|
||||
# Title of /vote help
|
||||
Title: '&3&lVoting Player Help'
|
||||
Title: '&6&lVoting Player Help'
|
||||
# Format for help message in /v help
|
||||
Line: '&3&l%Command% - &3%HelpMessage%'
|
||||
Line: '&6%Command% - &6%HelpMessage%'
|
||||
# Require permission to see command in /v help or /av help
|
||||
RequirePermission: true
|
||||
|
||||
@@ -317,333 +298,9 @@ Format:
|
||||
Monthly: 'Monthly'
|
||||
AllTime: 'AllTime'
|
||||
|
||||
# ------------------------------------------------
|
||||
# GUI Options
|
||||
# ------------------------------------------------
|
||||
|
||||
# Enable command for last month gui
|
||||
# Requires restart to take effect
|
||||
LastMonthGUI: false
|
||||
|
||||
# Configure GUI's here
|
||||
# Note: Slots start at 0 instead of 1, max slot is 53 (don't go over) (E.g: last slot in first row of inventory is 8)
|
||||
# Item Material's can be found here: https://hub.spigotmc.org/javadocs/spigot/org/bukkit/Material.html
|
||||
GUI:
|
||||
# GUI for /vote gui, /vgui, votegui
|
||||
VoteGUI:
|
||||
# Items will be orders as it is below
|
||||
URL:
|
||||
# Standard item format, lore is automaticly applied
|
||||
Item:
|
||||
Material: 'BOW'
|
||||
Data: 0
|
||||
Amount: 1
|
||||
Name: '&4URL'
|
||||
Lore:
|
||||
- '&aClick me for links'
|
||||
# You can set skulls of the player using the following
|
||||
# Remove the # to enable
|
||||
#Skull: '%Player%'
|
||||
Next:
|
||||
Item:
|
||||
Material: 'COMPASS'
|
||||
Data: 0
|
||||
Amount: 1
|
||||
Name: '&4Next'
|
||||
Last:
|
||||
Item:
|
||||
Material: 'CLOCK'
|
||||
Data: 0
|
||||
Amount: 1
|
||||
Name: '&4Last'
|
||||
Total:
|
||||
Item:
|
||||
Material: 'CHEST'
|
||||
Data: 0
|
||||
Amount: 1
|
||||
Name: '&4Total'
|
||||
Top:
|
||||
Item:
|
||||
Material: 'OAK_SIGN'
|
||||
Data: 0
|
||||
Amount: 1
|
||||
Name: '&4Top'
|
||||
Today:
|
||||
Item:
|
||||
Material: 'BOOK'
|
||||
Data: 0
|
||||
Amount: 1
|
||||
Name: '&4Today'
|
||||
Shop:
|
||||
Item:
|
||||
Material: 'DIAMOND'
|
||||
Data: 0
|
||||
Amount: 1
|
||||
Name: '&4Vote Shop'
|
||||
Lore:
|
||||
- '&aYou currently have %points% points'
|
||||
|
||||
# GUI for /vote url
|
||||
# And /vote if enabled in Config.yml
|
||||
VoteURL:
|
||||
# GUI Name
|
||||
Name: '&cVoteURL'
|
||||
BackButton: true
|
||||
SiteName: '&c%Name%'
|
||||
SeeURL: '&cClick to see URL'
|
||||
NextVote: '&cCan Vote In: %Info%'
|
||||
ViewAllUrlsButtonEnabled: true
|
||||
AllUrlsButton:
|
||||
RequireAllSitesVoted: true
|
||||
AlreadyVotedItem:
|
||||
Material: 'REDSTONE_BLOCK'
|
||||
Data: 0
|
||||
Amount: 1
|
||||
Name: '&4All Voting Sites'
|
||||
Lore:
|
||||
- '&cClick Me'
|
||||
CanVoteItem:
|
||||
Material: 'EMERALD_BLOCK'
|
||||
Data: 0
|
||||
Amount: 1
|
||||
Name: '&4All Voting Sites'
|
||||
Lore:
|
||||
- '&cClick Me'
|
||||
AlreadyVotedItem:
|
||||
Material: 'REDSTONE_BLOCK'
|
||||
Data: 0
|
||||
Amount: 1
|
||||
CanVoteItem:
|
||||
Material: 'EMERALD_BLOCK'
|
||||
Data: 0
|
||||
Amount: 1
|
||||
URLText: '%VoteUrl%'
|
||||
|
||||
VoteURLBookGUI:
|
||||
Title: '&cVoteURL'
|
||||
SiteName: '&c%name%'
|
||||
CanVoteText: 'Click me'
|
||||
CanVoteColor: 'GREEN'
|
||||
AlreadyVotedText: 'Click me'
|
||||
AlreadyVotedColor: 'RED'
|
||||
Layout:
|
||||
- '&c%Sitename%'
|
||||
- '[UrlText]'
|
||||
|
||||
VoteRewardBackButton: false
|
||||
# Customize /vote reward
|
||||
# Show players what you get when you vote on each site
|
||||
VoteReward:
|
||||
# Name of votesite
|
||||
ExampleVoteSite:
|
||||
# items in /vote reward sitename
|
||||
Items:
|
||||
# Item
|
||||
# This is not the item display name
|
||||
# Do not have 2 of the same items
|
||||
Diamond:
|
||||
# Item ID
|
||||
Material: 'DIAMOND'
|
||||
# Item Data (Eg 1:4, data is 4)
|
||||
Data: 0
|
||||
# Amount of items
|
||||
# Should be greater than 0
|
||||
Amount: 1
|
||||
# Item name
|
||||
# Remove this line for no name
|
||||
Name: '&4Example'
|
||||
# Lore
|
||||
# Remove this line for no lore
|
||||
Lore:
|
||||
- '&4Line 1'
|
||||
VoteLast:
|
||||
Name: 'VoteLast: %player%'
|
||||
BackButton: true
|
||||
VoteNext:
|
||||
Name: 'VoteNext: %player%'
|
||||
BackButton: true
|
||||
VoteToday:
|
||||
Name: 'VoteToday'
|
||||
Line: '&6%VoteSite% : %Time%'
|
||||
IconTitle: '%player%'
|
||||
BackButton: true
|
||||
UseSkull: true
|
||||
# If UseSkull is false, use this item
|
||||
PlayerItem:
|
||||
Material: 'PAPER'
|
||||
Amount: 1
|
||||
VoteTop:
|
||||
Name: 'VoteTop %topvoter%'
|
||||
BackButton: false
|
||||
Item:
|
||||
Name: '&3&l%position%: &3%player%'
|
||||
Lore: '&3&lVotes: &3%votes%'
|
||||
SwitchItem:
|
||||
Name: '&3Switch TopVoter'
|
||||
Lore: '&bCurrently: %Top%'
|
||||
Material: 'OAK_SIGN'
|
||||
Amount: 1
|
||||
# 8 Slots over from the bottom left
|
||||
Slot: 7
|
||||
# Number of topvoters to display on page +9
|
||||
# 9 Slots on the botton are used for page buttons
|
||||
Size: 27
|
||||
# If true, /vote top will show player heads
|
||||
UseSkull: true
|
||||
# Item for player in GUI if use skull is false
|
||||
PlayerItem:
|
||||
Material: 'PAPER'
|
||||
VoteTotal:
|
||||
Name: 'VoteTotal: %player%'
|
||||
BackButton: true
|
||||
DayTotal:
|
||||
Item:
|
||||
Material: 'CLOCK'
|
||||
Name: '&cDaily Total'
|
||||
Lore: '&c&lTotal: &c%Total%'
|
||||
Amount: 1
|
||||
WeekTotal:
|
||||
Item:
|
||||
Material: 'CLOCK'
|
||||
Name: '&cWeekly Total'
|
||||
Lore: '&c&lTotal: &c%Total%'
|
||||
Amount: 1
|
||||
MonthTotal:
|
||||
Item:
|
||||
Material: 'CLOCK'
|
||||
Name: '&cMonthly Total'
|
||||
Lore: '&c&lTotal: &c%Total%'
|
||||
Amount: 1
|
||||
AllTimeTotal:
|
||||
Item:
|
||||
Material: 'CLOCK'
|
||||
Name: '&cAllTime Total'
|
||||
Lore: '&c&lTotal: &c%Total%'
|
||||
Amount: 1
|
||||
VoteBest:
|
||||
Name: 'VoteBest: %player%'
|
||||
DayBest:
|
||||
Item:
|
||||
Material: 'CLOCK'
|
||||
Name: '&cDaily Best'
|
||||
Lore: '&c&lBest: &c%Best%'
|
||||
Amount: 1
|
||||
WeekBest:
|
||||
Item:
|
||||
Material: 'CLOCK'
|
||||
Name: '&cWeekly Best'
|
||||
Lore: '&c&lBest: &c%Best%'
|
||||
Amount: 1
|
||||
MonthBest:
|
||||
Item:
|
||||
Material: 'CLOCK'
|
||||
Name: '&cMonthly Best'
|
||||
Lore: '&c&lBest: &c%Best%'
|
||||
Amount: 1
|
||||
VoteStreak:
|
||||
Name: 'VoteStreak: %player%'
|
||||
BackButton: false
|
||||
CurrentDayStreak:
|
||||
Item:
|
||||
Material: 'CLOCK'
|
||||
Name: '&cCurrent Daily Streak'
|
||||
Lore: '&c&lStreak: &c%Streak%'
|
||||
Amount: 1
|
||||
CurrentWeekStreak:
|
||||
Item:
|
||||
Material: 'CLOCK'
|
||||
Name: '&cCurrent Weekly Streak'
|
||||
Lore: '&c&lStreak: &c%Streak%'
|
||||
Amount: 1
|
||||
CurrentMonthStreak:
|
||||
Item:
|
||||
Material: 'CLOCK'
|
||||
Name: '&cCurrent Monthly Streak'
|
||||
Lore: '&c&lStreak: &c%Streak%'
|
||||
Amount: 1
|
||||
HighestDayStreak:
|
||||
Item:
|
||||
Material: 'CLOCK'
|
||||
Name: '&cHighest Daily Streak'
|
||||
Lore: '&c&lStreak: &c%Streak%'
|
||||
Amount: 1
|
||||
HighestWeekStreak:
|
||||
Item:
|
||||
Material: 'CLOCK'
|
||||
Name: '&cHighest Weekly Streak'
|
||||
Lore: '&c&lStreak: &c%Streak%'
|
||||
Amount: 1
|
||||
HighestMonthStreak:
|
||||
Item:
|
||||
Material: 'CLOCK'
|
||||
Name: '&cHighest Monthly Streak'
|
||||
Lore: '&c&lStreak: &c%Streak%'
|
||||
Amount: 1
|
||||
VoteURLSite:
|
||||
Name: 'VoteSite: %site%'
|
||||
VoteGUIName: '&cVoteGUI: &c&l%player%'
|
||||
VoteRewardName: 'VoteReward'
|
||||
VoteShopName: 'VoteShop'
|
||||
|
||||
BackButton:
|
||||
Material: 'BARRIER'
|
||||
Data: 0
|
||||
Amount: 1
|
||||
Name: '&8Back to VoteGUI'
|
||||
|
||||
VoteShopBackButton: true
|
||||
VoteShopEnabled: true
|
||||
# Hide items in vote shop which user can not buy
|
||||
VoteShopHideLimitedReached: true
|
||||
# Requires above to be false
|
||||
VoteShopLimitReached: '&aYou reached your limit'
|
||||
VoteShopRequireConfirmation: false
|
||||
VoteShopDisabled: '&cVote shop disabled'
|
||||
Shop:
|
||||
# Identifier
|
||||
# Used in placeholders for formats
|
||||
# Do not have spaces in the identifier
|
||||
Diamond:
|
||||
Identifier_Name: 'Diamond'
|
||||
# Item
|
||||
Material: 'DIAMOND'
|
||||
Data: 0
|
||||
Amount: 1
|
||||
Name: '&4Buy A Diamond'
|
||||
# You can set skulls of the player using the following
|
||||
# Remove the # to enable
|
||||
#Skull: '%Player%'
|
||||
Lore:
|
||||
- '&c&lCost: &c3 Voting Points'
|
||||
# Number of voting points this cost
|
||||
Cost: 3
|
||||
# Permission required, leave blank for no permission
|
||||
Permission: ''
|
||||
# Limit how many times you can buy this
|
||||
#Limit: 3
|
||||
# Reset limit daily/weekly/monthly
|
||||
#Reset:
|
||||
#Daily: false
|
||||
#Weekly: false
|
||||
#Monthly: false
|
||||
# If true, item is not buyable
|
||||
#NotBuyable: false
|
||||
# Rewards to run if player buys successfully
|
||||
Rewards:
|
||||
Items:
|
||||
Diamond:
|
||||
Material: 'DIAMOND'
|
||||
Amount: 1
|
||||
|
||||
# ------------------------------------------------
|
||||
# Extra Rewards
|
||||
# ------------------------------------------------
|
||||
|
||||
# Moved to SpecialRewards.yml
|
||||
# Rewards here will be copied upon updating
|
||||
|
||||
# ------------------------------------------------
|
||||
# Top Voter
|
||||
# Top voter rewards available in specialrewards.yml
|
||||
# ------------------------------------------------
|
||||
|
||||
# Top voter blacklist
|
||||
@@ -717,6 +374,32 @@ LimitMonthlyVotes: false
|
||||
# Shoudn't be needed, but enable if you have trouble with milestones
|
||||
PreventRepeatMilestones: false
|
||||
|
||||
# When enabled the command /vote setprimaryaccount (playername)
|
||||
# will be shown (after restart)
|
||||
# Primary account will be used instead of the players account to get
|
||||
# placeholder and other data such as vote reminding
|
||||
# Mainly to be used for alts and such
|
||||
UsePrimaryAccountForPlaceholders: false
|
||||
|
||||
AddCustomCommands: false
|
||||
|
||||
# Injects custom command to /vote
|
||||
# Requires AddCustomCommand: true to be set
|
||||
CustomCommands:
|
||||
# identifier, not specific name
|
||||
command1:
|
||||
Args:
|
||||
- token
|
||||
# Message to send on command
|
||||
Message: 'token message'
|
||||
# Permission for this command
|
||||
Permission: 'votingplugin.commands.vote.token'
|
||||
# help message
|
||||
HelpMessage: 'See tokens'
|
||||
# Forces player to run this command
|
||||
Commands:
|
||||
- tokencommand
|
||||
|
||||
######################
|
||||
# Debug
|
||||
######################
|
||||
@@ -779,9 +462,6 @@ PurgeMin: 90
|
||||
# Whether or not to create daily backups. (Only the most recent ones get kept)
|
||||
CreateBackups: true
|
||||
|
||||
# If true, plugin will send scoreboards on some commands
|
||||
SendScoreboards: true
|
||||
|
||||
# If true, plugin will automaticly generate votesites
|
||||
# Disable this if you experience issues with sites being created randomly
|
||||
# Most cases this will work all the time
|
||||
|
||||
@@ -0,0 +1,317 @@
|
||||
# Configure GUI's here
|
||||
# Note: Slots start at 0 instead of 1, max slot is 53 (don't go over) (E.g: last slot in first row of inventory is 8)
|
||||
# Item Material's can be found here: https://hub.spigotmc.org/javadocs/spigot/org/bukkit/Material.html
|
||||
#
|
||||
# GUI Methods:
|
||||
# - BOOK
|
||||
# - GUI
|
||||
# - CHAT (Disables GUI)
|
||||
GUIMethod:
|
||||
Today: CHEST #BOOK not available (future update?)
|
||||
TopVoter: CHEST #BOOK not available (future update?)
|
||||
Last: CHEST #BOOK not available (future update?)
|
||||
Next: CHEST
|
||||
Total: CHEST #BOOK not available (future update?)
|
||||
URL: CHEST
|
||||
Best: CHEST #BOOK not available (future update?)
|
||||
Streak: CHEST #BOOK not available (future update?)
|
||||
GUI: CHEST #CHAT/BOOK not availabe for this (future update?)
|
||||
|
||||
# Enable command for last month gui
|
||||
# Requires restart to take effect
|
||||
LastMonthGUI: false
|
||||
|
||||
CHEST:
|
||||
# GUI for /vote gui, /vgui, /votegui
|
||||
VoteGUI:
|
||||
# Items will be orders as it is below
|
||||
URL:
|
||||
# Standard item format, lore is automaticly applied
|
||||
Item:
|
||||
Material: 'BOW'
|
||||
Data: 0
|
||||
Amount: 1
|
||||
Name: '&4URL'
|
||||
Lore:
|
||||
- '&aClick me for links'
|
||||
# You can set skulls of the player using the following
|
||||
# Remove the # to enable
|
||||
#Skull: '%Player%'
|
||||
Next:
|
||||
Item:
|
||||
Material: 'COMPASS'
|
||||
Data: 0
|
||||
Amount: 1
|
||||
Name: '&4Next'
|
||||
Last:
|
||||
Item:
|
||||
Material: 'CLOCK'
|
||||
Data: 0
|
||||
Amount: 1
|
||||
Name: '&4Last'
|
||||
Total:
|
||||
Item:
|
||||
Material: 'CHEST'
|
||||
Data: 0
|
||||
Amount: 1
|
||||
Name: '&4Total'
|
||||
Top:
|
||||
Item:
|
||||
Material: 'OAK_SIGN'
|
||||
Data: 0
|
||||
Amount: 1
|
||||
Name: '&4Top'
|
||||
Today:
|
||||
Item:
|
||||
Material: 'BOOK'
|
||||
Data: 0
|
||||
Amount: 1
|
||||
Name: '&4Today'
|
||||
Shop:
|
||||
Item:
|
||||
Material: 'DIAMOND'
|
||||
Data: 0
|
||||
Amount: 1
|
||||
Name: '&4Vote Shop'
|
||||
Lore:
|
||||
- '&aYou currently have %points% points'
|
||||
|
||||
# GUI for /vote url, /vote
|
||||
VoteURL:
|
||||
# GUI Name
|
||||
Name: '&cVoteURL'
|
||||
BackButton: true
|
||||
SiteName: '&c%Name%'
|
||||
SeeURL: '&cClick to see URL'
|
||||
NextVote: '&cCan Vote In: %Info%'
|
||||
ViewAllUrlsButtonEnabled: true
|
||||
AllUrlsButton:
|
||||
RequireAllSitesVoted: true
|
||||
AlreadyVotedItem:
|
||||
Material: 'REDSTONE_BLOCK'
|
||||
Data: 0
|
||||
Amount: 1
|
||||
Name: '&4All Voting Sites'
|
||||
Lore:
|
||||
- '&cClick Me'
|
||||
CanVoteItem:
|
||||
Material: 'EMERALD_BLOCK'
|
||||
Data: 0
|
||||
Amount: 1
|
||||
Name: '&4All Voting Sites'
|
||||
Lore:
|
||||
- '&cClick Me'
|
||||
AlreadyVotedItem:
|
||||
Material: 'REDSTONE_BLOCK'
|
||||
Data: 0
|
||||
Amount: 1
|
||||
CanVoteItem:
|
||||
Material: 'EMERALD_BLOCK'
|
||||
Data: 0
|
||||
Amount: 1
|
||||
URLText: '%VoteUrl%'
|
||||
|
||||
VoteLast:
|
||||
Name: 'VoteLast: %player%'
|
||||
BackButton: true
|
||||
VoteNext:
|
||||
Name: 'VoteNext: %player%'
|
||||
BackButton: true
|
||||
VoteToday:
|
||||
Name: 'VoteToday'
|
||||
Line: '&6%VoteSite% : %Time%'
|
||||
IconTitle: '%player%'
|
||||
BackButton: true
|
||||
UseSkull: true
|
||||
# If UseSkull is false, use this item
|
||||
PlayerItem:
|
||||
Material: 'PAPER'
|
||||
Amount: 1
|
||||
VoteTop:
|
||||
Name: 'VoteTop %topvoter%'
|
||||
BackButton: false
|
||||
Item:
|
||||
Name: '&3&l%position%: &3%player%'
|
||||
Lore: '&3&lVotes: &3%votes%'
|
||||
SwitchItem:
|
||||
Name: '&3Switch TopVoter'
|
||||
Lore: '&bCurrently: %Top%'
|
||||
Material: 'OAK_SIGN'
|
||||
Amount: 1
|
||||
# 8 Slots over from the bottom left
|
||||
Slot: 7
|
||||
# Number of topvoters to display on page +9
|
||||
# 9 Slots on the botton are used for page buttons
|
||||
Size: 27
|
||||
# If true, /vote top will show player heads
|
||||
UseSkull: true
|
||||
# Item for player in GUI if use skull is false
|
||||
PlayerItem:
|
||||
Material: 'PAPER'
|
||||
VoteTotal:
|
||||
Name: 'VoteTotal: %player%'
|
||||
BackButton: true
|
||||
DayTotal:
|
||||
Item:
|
||||
Material: 'CLOCK'
|
||||
Name: '&cDaily Total'
|
||||
Lore: '&c&lTotal: &c%Total%'
|
||||
Amount: 1
|
||||
WeekTotal:
|
||||
Item:
|
||||
Material: 'CLOCK'
|
||||
Name: '&cWeekly Total'
|
||||
Lore: '&c&lTotal: &c%Total%'
|
||||
Amount: 1
|
||||
MonthTotal:
|
||||
Item:
|
||||
Material: 'CLOCK'
|
||||
Name: '&cMonthly Total'
|
||||
Lore: '&c&lTotal: &c%Total%'
|
||||
Amount: 1
|
||||
AllTimeTotal:
|
||||
Item:
|
||||
Material: 'CLOCK'
|
||||
Name: '&cAllTime Total'
|
||||
Lore: '&c&lTotal: &c%Total%'
|
||||
Amount: 1
|
||||
VoteBest:
|
||||
Name: 'VoteBest: %player%'
|
||||
DayBest:
|
||||
Item:
|
||||
Material: 'CLOCK'
|
||||
Name: '&cDaily Best'
|
||||
Lore: '&c&lBest: &c%Best%'
|
||||
Amount: 1
|
||||
WeekBest:
|
||||
Item:
|
||||
Material: 'CLOCK'
|
||||
Name: '&cWeekly Best'
|
||||
Lore: '&c&lBest: &c%Best%'
|
||||
Amount: 1
|
||||
MonthBest:
|
||||
Item:
|
||||
Material: 'CLOCK'
|
||||
Name: '&cMonthly Best'
|
||||
Lore: '&c&lBest: &c%Best%'
|
||||
Amount: 1
|
||||
VoteStreak:
|
||||
Name: 'VoteStreak: %player%'
|
||||
BackButton: false
|
||||
CurrentDayStreak:
|
||||
Item:
|
||||
Material: 'CLOCK'
|
||||
Name: '&cCurrent Daily Streak'
|
||||
Lore: '&c&lStreak: &c%Streak%'
|
||||
Amount: 1
|
||||
CurrentWeekStreak:
|
||||
Item:
|
||||
Material: 'CLOCK'
|
||||
Name: '&cCurrent Weekly Streak'
|
||||
Lore: '&c&lStreak: &c%Streak%'
|
||||
Amount: 1
|
||||
CurrentMonthStreak:
|
||||
Item:
|
||||
Material: 'CLOCK'
|
||||
Name: '&cCurrent Monthly Streak'
|
||||
Lore: '&c&lStreak: &c%Streak%'
|
||||
Amount: 1
|
||||
HighestDayStreak:
|
||||
Item:
|
||||
Material: 'CLOCK'
|
||||
Name: '&cHighest Daily Streak'
|
||||
Lore: '&c&lStreak: &c%Streak%'
|
||||
Amount: 1
|
||||
HighestWeekStreak:
|
||||
Item:
|
||||
Material: 'CLOCK'
|
||||
Name: '&cHighest Weekly Streak'
|
||||
Lore: '&c&lStreak: &c%Streak%'
|
||||
Amount: 1
|
||||
HighestMonthStreak:
|
||||
Item:
|
||||
Material: 'CLOCK'
|
||||
Name: '&cHighest Monthly Streak'
|
||||
Lore: '&c&lStreak: &c%Streak%'
|
||||
Amount: 1
|
||||
VoteURLSite:
|
||||
Name: 'VoteSite: %site%'
|
||||
VoteGUIName: '&cVoteGUI: &c&l%player%'
|
||||
VoteRewardName: 'VoteReward'
|
||||
VoteShopName: 'VoteShop'
|
||||
|
||||
BackButton:
|
||||
Material: 'BARRIER'
|
||||
Data: 0
|
||||
Amount: 1
|
||||
Name: '&8Back to VoteGUI'
|
||||
|
||||
VoteShopBackButton: true
|
||||
VoteShopEnabled: true
|
||||
# Hide items in vote shop which user can not buy
|
||||
VoteShopHideLimitedReached: true
|
||||
# Requires above to be false
|
||||
VoteShopLimitReached: '&aYou reached your limit'
|
||||
VoteShopRequireConfirmation: false
|
||||
VoteShopDisabled: '&cVote shop disabled'
|
||||
Shop:
|
||||
# Identifier
|
||||
# Used in placeholders for formats
|
||||
# Do not have spaces in the identifier
|
||||
Diamond:
|
||||
Identifier_Name: 'Diamond'
|
||||
# Item
|
||||
Material: 'DIAMOND'
|
||||
Data: 0
|
||||
Amount: 1
|
||||
Name: '&4Buy A Diamond'
|
||||
# You can set skulls of the player using the following
|
||||
# Remove the # to enable
|
||||
#Skull: '%Player%'
|
||||
Lore:
|
||||
- '&c&lCost: &c3 Voting Points'
|
||||
# Number of voting points this cost
|
||||
Cost: 3
|
||||
# Permission required, leave blank for no permission
|
||||
Permission: ''
|
||||
# Whether or not to keep GUI open after purchase
|
||||
CloseGUI: true
|
||||
# Limit how many times you can buy this
|
||||
#Limit: 3
|
||||
# Reset limit daily/weekly/monthly
|
||||
#Reset:
|
||||
#Daily: false
|
||||
#Weekly: false
|
||||
#Monthly: false
|
||||
# If true, item is not buyable
|
||||
#NotBuyable: false
|
||||
# Rewards to run if player buys successfully
|
||||
Rewards:
|
||||
Items:
|
||||
Diamond:
|
||||
Material: 'DIAMOND'
|
||||
Amount: 1
|
||||
|
||||
ShopConfirmPurchase:
|
||||
Title: 'Confirm Purchase?'
|
||||
YesItem:
|
||||
Material: EMERALD_BLOCK
|
||||
Amount: 1
|
||||
Name: '&aYes'
|
||||
NoItem:
|
||||
Material: BARRIER
|
||||
Amount: 1
|
||||
Name: '&cNo'
|
||||
|
||||
|
||||
BOOK:
|
||||
VoteURLBookGUI:
|
||||
Title: '&cVoteURL'
|
||||
CanVoteText: 'Click me'
|
||||
CanVoteColor: 'GREEN'
|
||||
AlreadyVotedText: 'Click me'
|
||||
AlreadyVotedColor: 'RED'
|
||||
Layout:
|
||||
- '&3&l%Sitename%'
|
||||
- '[UrlText]'
|
||||
|
||||
@@ -53,6 +53,8 @@ VoteParty:
|
||||
CountFakeVotes: true
|
||||
# Number of user votes that apply to vote party total the user needs to get rewards
|
||||
UserVotesRequired: 0
|
||||
# Count offline votes
|
||||
CountOfflineVotes: true
|
||||
# Broadcast when vote party reached
|
||||
Broadcast: '&cReached the vote party amount!'
|
||||
# List of commands to execute, these only execute once.
|
||||
@@ -134,7 +136,13 @@ VoteCoolDownEndedReward: []
|
||||
# Use EverySiteReward in VoteSites.yml for a global reward for each site
|
||||
AnySiteRewards: []
|
||||
|
||||
EnableMonthlyAwards: true
|
||||
# Rewards to run when player logs in
|
||||
LoginRewards: []
|
||||
|
||||
# Rewards to run when player logs off
|
||||
# Will queue until player logs in unless forceoffline is enabled
|
||||
LogoutRewards: []
|
||||
|
||||
# Rewards to give
|
||||
MonthlyAwards:
|
||||
# Position. 1 is first in top voter, 2 is second, etc...
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
name: ${project.name}
|
||||
version: ${project.version}
|
||||
main: com.Ben12345rocks.VotingPlugin.bungee.Bungee
|
||||
author: Ben12345rocks
|
||||
main: com.bencodez.votingplugin.bungee.VotingPluginBungee
|
||||
author: BenCodez
|
||||
@@ -18,6 +18,7 @@ MaxSize: -1
|
||||
# Table name prefix, for use with mutliple servers
|
||||
Prefix: ''
|
||||
#UseSSL: true
|
||||
#PublicKeyRetrieval: false
|
||||
|
||||
Debug: false
|
||||
# Have a reward on each server
|
||||
@@ -37,11 +38,12 @@ BlockedServers:
|
||||
# MYSQL
|
||||
BungeeMethod: PLUGINMESSAGING
|
||||
|
||||
# ----------------------------
|
||||
# SOCKET METHOD Only, ignore otherwise
|
||||
# ----------------------------
|
||||
FallBackServer: factions
|
||||
|
||||
# ----------------------------
|
||||
# SOCKET METHOD Settings
|
||||
# ----------------------------
|
||||
|
||||
# Tell servers to broadcast
|
||||
Broadcast: true
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
name: ${project.name}
|
||||
version: ${project.version}
|
||||
main: com.Ben12345rocks.VotingPlugin.Main
|
||||
main: com.bencodez.votingplugin.VotingPluginMain
|
||||
description: Highly Customizable Voting Listener!
|
||||
website: https://www.spigotmc.org/resources/votingplugin.15358/
|
||||
author: BenCodez
|
||||
|
||||
@@ -0,0 +1,2 @@
|
||||
time: '${timestamp}'
|
||||
profile: ${build.profile.id}
|
||||
+64
-47
@@ -2,9 +2,9 @@
|
||||
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.Ben12345rocks</groupId>
|
||||
<artifactId>VotingPlugin</artifactId>
|
||||
<version>5.24.1</version>
|
||||
<groupId>com.bencodez</groupId>
|
||||
<artifactId>votingplugin</artifactId>
|
||||
<version>6.0</version>
|
||||
<packaging>jar</packaging>
|
||||
<name>VotingPlugin</name>
|
||||
<properties>
|
||||
@@ -28,6 +28,7 @@
|
||||
<includes>
|
||||
<include>plugin.yml</include>
|
||||
<include>bungee.yml</include>
|
||||
<include>votingpluginversion.yml</include>
|
||||
</includes>
|
||||
</resource>
|
||||
<resource>
|
||||
@@ -104,8 +105,8 @@
|
||||
<!-- Lets relocate the shaded API so we dont cause any conflicts with
|
||||
other plugins -->
|
||||
<relocation>
|
||||
<pattern>com.Ben12345rocks.AdvancedCore</pattern>
|
||||
<shadedPattern>${project.groupId}.${project.artifactId}.AdvancedCore</shadedPattern>
|
||||
<pattern>com.bencodez.advancedcore</pattern>
|
||||
<shadedPattern>${project.groupId}.${project.artifactId}.advancedcore</shadedPattern>
|
||||
</relocation>
|
||||
<!-- Lets relocate the shaded API so we dont cause any conflicts with
|
||||
other plugins -->
|
||||
@@ -210,7 +211,7 @@
|
||||
<resource>
|
||||
<directory>${basedir}/target</directory>
|
||||
<includes>
|
||||
<include>${project.artifactId}.jar</include>
|
||||
<include>VotingPlugin.jar</include>
|
||||
</includes>
|
||||
</resource>
|
||||
</resources>
|
||||
@@ -248,18 +249,14 @@
|
||||
</repository>
|
||||
</repositories>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>com.github.Ben12345rocks</groupId>
|
||||
<artifactId>AdvancedCore</artifactId>
|
||||
<version>master-SNAPSHOT</version>
|
||||
</dependency>
|
||||
<!--<dependency> <groupId>com.github.Ben12345rocks</groupId> <artifactId>AdvancedCore</artifactId>
|
||||
<version>3.0-SNAPSHOT</version> </dependency> -->
|
||||
|
||||
|
||||
<!--<dependency> <groupId>com.Ben12345rocks</groupId> <artifactId>AdvancedCore</artifactId>
|
||||
<version>LATEST</version> <scope>compile</scope> </dependency> -->
|
||||
<dependency>
|
||||
<groupId>org.spigotmc</groupId>
|
||||
<artifactId>spigot-api</artifactId>
|
||||
<version>1.16.3-R0.1-SNAPSHOT</version>
|
||||
<version>1.16.4-R0.1-SNAPSHOT</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
@@ -269,40 +266,12 @@
|
||||
<scope>system</scope>
|
||||
<systemPath>${project.basedir}/Jars/Votifier.jar</systemPath>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.swifteh</groupId>
|
||||
<artifactId>GAL</artifactId>
|
||||
<version>1.3.2</version>
|
||||
<scope>system</scope>
|
||||
<systemPath>${project.basedir}/Jars/GAListener.jar</systemPath>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.mythicacraft</groupId>
|
||||
<artifactId>voteroulette</artifactId>
|
||||
<version>3.2.2</version>
|
||||
<scope>system</scope>
|
||||
<systemPath>${project.basedir}/Jars/VoteRoulette.jar</systemPath>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.projectlombok</groupId>
|
||||
<artifactId>lombok</artifactId>
|
||||
<version>1.18.2</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.mimimum.minecraft</groupId>
|
||||
<artifactId>SuperbVote</artifactId>
|
||||
<version>0.5.3</version>
|
||||
<scope>system</scope>
|
||||
<systemPath>${project.basedir}/Jars/SuperbVote-0.5.3.jar</systemPath>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>be.maximvdw</groupId>
|
||||
<artifactId>MVdWPlaceholderAPI</artifactId>
|
||||
<version>LATEST</version>
|
||||
<scope>system</scope>
|
||||
<systemPath>${project.basedir}/Jars/MVdWPlaceholderAPI.jar</systemPath>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>net.md-5</groupId>
|
||||
<artifactId>bungeecord-api</artifactId>
|
||||
@@ -320,16 +289,64 @@
|
||||
<artifactId>ConfigUpdater</artifactId>
|
||||
<version>1.1-SNAPSHOT</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>xyz.upperlevel.spigot.book</groupId>
|
||||
<artifactId>spigot-book-api</artifactId>
|
||||
<version>1.3</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.httpcomponents</groupId>
|
||||
<artifactId>httpclient</artifactId>
|
||||
<version>4.5.6</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>be.maximvdw</groupId>
|
||||
<artifactId>MVdWPlaceholderAPI</artifactId>
|
||||
<version>LATEST</version>
|
||||
<scope>system</scope>
|
||||
<systemPath>${project.basedir}/Jars/MVdWPlaceholderAPI.jar</systemPath>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
<profiles>
|
||||
<profile>
|
||||
<id>prod</id>
|
||||
<activation>
|
||||
<activeByDefault>true</activeByDefault>
|
||||
</activation>
|
||||
<properties>
|
||||
<build.profile.id>prod</build.profile.id>
|
||||
</properties>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>com.github.bencodez</groupId>
|
||||
<artifactId>advancedcore</artifactId>
|
||||
<version>master-SNAPSHOT</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</profile>
|
||||
<profile>
|
||||
<id>prod2</id>
|
||||
<properties>
|
||||
<build.profile.id>prod2</build.profile.id>
|
||||
</properties>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>com.bencodez</groupId>
|
||||
<artifactId>AdvancedCore</artifactId>
|
||||
<version>LATEST</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</profile>
|
||||
<profile>
|
||||
<id>dev</id>
|
||||
<properties>
|
||||
<build.profile.id>dev</build.profile.id>
|
||||
</properties>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>com.bencodez</groupId>
|
||||
<artifactId>AdvancedCore</artifactId>
|
||||
<version>LATEST</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</profile>
|
||||
</profiles>
|
||||
</project>
|
||||
@@ -1,247 +0,0 @@
|
||||
package com.Ben12345rocks.VotingPlugin;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.UUID;
|
||||
|
||||
import com.Ben12345rocks.AdvancedCore.Util.Encryption.EncryptionHandler;
|
||||
import com.Ben12345rocks.AdvancedCore.Util.PluginMessage.PluginMessage;
|
||||
import com.Ben12345rocks.AdvancedCore.Util.PluginMessage.PluginMessageHandler;
|
||||
import com.Ben12345rocks.AdvancedCore.Util.Sockets.ClientHandler;
|
||||
import com.Ben12345rocks.AdvancedCore.Util.Sockets.SocketHandler;
|
||||
import com.Ben12345rocks.AdvancedCore.Util.Sockets.SocketReceiver;
|
||||
import com.Ben12345rocks.VotingPlugin.Config.BungeeSettings;
|
||||
import com.Ben12345rocks.VotingPlugin.Data.ServerData;
|
||||
import com.Ben12345rocks.VotingPlugin.Objects.User;
|
||||
import com.Ben12345rocks.VotingPlugin.Objects.VoteSite;
|
||||
import com.Ben12345rocks.VotingPlugin.UserManager.UserManager;
|
||||
import com.Ben12345rocks.VotingPlugin.bungee.BungeeMethod;
|
||||
|
||||
import lombok.Getter;
|
||||
|
||||
public class BungeeHandler {
|
||||
private static BungeeHandler instance = new BungeeHandler();
|
||||
|
||||
public static BungeeHandler getInstance() {
|
||||
return instance;
|
||||
}
|
||||
|
||||
@Getter
|
||||
private SocketHandler socketHandler;
|
||||
|
||||
@Getter
|
||||
private ClientHandler clientHandler;
|
||||
|
||||
private EncryptionHandler encryptionHandler;
|
||||
|
||||
@Getter
|
||||
private BungeeMethod method;
|
||||
|
||||
public void close() {
|
||||
socketHandler.closeConnection();
|
||||
clientHandler.stopConnection();
|
||||
}
|
||||
|
||||
public void load() {
|
||||
Main.plugin.debug("Loading bungee handler");
|
||||
|
||||
method = BungeeMethod.getByName(BungeeSettings.getInstance().getBungeeMethod());
|
||||
|
||||
Main.plugin.getLogger().info("Using BungeeMethod: " + method.toString());
|
||||
|
||||
if (method.equals(BungeeMethod.PLUGINMESSAGING)) {
|
||||
Main.plugin.registerBungeeChannels();
|
||||
|
||||
PluginMessage.getInstance().add(new PluginMessageHandler("Vote") {
|
||||
@Override
|
||||
public void onRecieve(String subChannel, ArrayList<String> args) {
|
||||
String player = args.get(0);
|
||||
String uuid = args.get(1);
|
||||
String service = args.get(2);
|
||||
long time = Long.parseLong(args.get(3));
|
||||
Main.plugin.debug("pluginmessaging vote received from " + player + " on " + service);
|
||||
User user = UserManager.getInstance().getVotingPluginUser(UUID.fromString(uuid));
|
||||
user.clearCache();
|
||||
|
||||
user.bungeeVotePluginMessaging(service, time);
|
||||
|
||||
if (!BungeeSettings.getInstance().isBungeeBroadcast()) {
|
||||
if (Boolean.valueOf(args.get(4)) || BungeeSettings.getInstance().isBungeeBroadcastAlways()) {
|
||||
VoteSite site = Main.plugin.getVoteSite(service);
|
||||
if (site != null) {
|
||||
site.broadcastVote(user, false);
|
||||
} else {
|
||||
Main.plugin.getLogger().warning("No votesite for " + service);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (args.size() > 4 && Boolean.valueOf(args.get(5))) {
|
||||
ServerData.getInstance().addServiceSite(service);
|
||||
}
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
PluginMessage.getInstance().add(new PluginMessageHandler("VoteOnline") {
|
||||
@Override
|
||||
public void onRecieve(String subChannel, ArrayList<String> args) {
|
||||
String player = args.get(0);
|
||||
String uuid = args.get(1);
|
||||
String service = args.get(2);
|
||||
long time = Long.parseLong(args.get(3));
|
||||
Main.plugin.debug("pluginmessaging voteonline received from " + player + " on " + service);
|
||||
User user = UserManager.getInstance().getVotingPluginUser(UUID.fromString(uuid));
|
||||
user.clearCache();
|
||||
|
||||
user.bungeeVotePluginMessaging(service, time);
|
||||
|
||||
if (!BungeeSettings.getInstance().isBungeeBroadcast()) {
|
||||
if (Boolean.valueOf(args.get(4)) || BungeeSettings.getInstance().isBungeeBroadcastAlways()) {
|
||||
VoteSite site = Main.plugin.getVoteSite(service);
|
||||
if (site != null) {
|
||||
site.broadcastVote(user, false);
|
||||
} else {
|
||||
Main.plugin.getLogger().warning("No votesite for " + service);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (args.size() > 4 && Boolean.valueOf(args.get(5))) {
|
||||
ServerData.getInstance().addServiceSite(service);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
PluginMessage.getInstance().add(new PluginMessageHandler("VoteUpdate") {
|
||||
@Override
|
||||
public void onRecieve(String subChannel, ArrayList<String> args) {
|
||||
String player = args.get(0);
|
||||
Main.plugin.debug("pluginmessaging voteupdate received for " + player);
|
||||
User user = UserManager.getInstance().getVotingPluginUser(UUID.fromString(player));
|
||||
user.clearCache();
|
||||
|
||||
user.offVote();
|
||||
|
||||
Main.plugin.setUpdate(true);
|
||||
}
|
||||
});
|
||||
|
||||
PluginMessage.getInstance().add(new PluginMessageHandler("VoteBroadcast") {
|
||||
@Override
|
||||
public void onRecieve(String subChannel, ArrayList<String> args) {
|
||||
String uuid = args.get(0);
|
||||
String service = args.get(1);
|
||||
User user = UserManager.getInstance().getVotingPluginUser(UUID.fromString(uuid));
|
||||
VoteSite site = Main.plugin.getVoteSite(service);
|
||||
if (site != null) {
|
||||
site.broadcastVote(user, false);
|
||||
} else {
|
||||
Main.plugin.getLogger().warning("No votesite for " + service);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
} else if (method.equals(BungeeMethod.SOCKETS)) {
|
||||
encryptionHandler = new EncryptionHandler(new File(Main.plugin.getDataFolder(), "secretkey.key"));
|
||||
|
||||
clientHandler = new ClientHandler(BungeeSettings.getInstance().getBungeeServerHost(),
|
||||
BungeeSettings.getInstance().getBungeeServerPort(), encryptionHandler,
|
||||
BungeeSettings.getInstance().isBungeeDebug());
|
||||
|
||||
socketHandler = new SocketHandler(Main.plugin.getVersion(),
|
||||
BungeeSettings.getInstance().getSpigotServerHost(),
|
||||
BungeeSettings.getInstance().getSpigotServerPort(), encryptionHandler,
|
||||
BungeeSettings.getInstance().isBungeeDebug());
|
||||
|
||||
socketHandler.add(new SocketReceiver("bungeevote") {
|
||||
|
||||
@Override
|
||||
public void onReceive(String[] data) {
|
||||
if (data.length > 3) {
|
||||
Main.plugin.extraDebug("BungeeVote from " + data[2] + ", processing");
|
||||
String uuid = data[1];
|
||||
User user = null;
|
||||
if (!uuid.isEmpty()) {
|
||||
user = UserManager.getInstance().getVotingPluginUser(UUID.fromString(uuid));
|
||||
} else {
|
||||
user = UserManager.getInstance().getVotingPluginUser(data[2]);
|
||||
}
|
||||
|
||||
user.clearCache();
|
||||
|
||||
user.bungeeVote(data[3]);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
socketHandler.add(new SocketReceiver("bungeevoteonline") {
|
||||
|
||||
@Override
|
||||
public void onReceive(String[] data) {
|
||||
if (data.length > 3) {
|
||||
Main.plugin.extraDebug("BungeeVoteOnline from " + data[2] + ", processing");
|
||||
String uuid = data[1];
|
||||
User user = null;
|
||||
if (!uuid.isEmpty()) {
|
||||
user = UserManager.getInstance().getVotingPluginUser(UUID.fromString(uuid));
|
||||
} else {
|
||||
user = UserManager.getInstance().getVotingPluginUser(data[2]);
|
||||
}
|
||||
|
||||
user.clearCache();
|
||||
|
||||
user.bungeeVoteOnline(data[3]);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
socketHandler.add(new SocketReceiver("BungeeBroadcast") {
|
||||
|
||||
@Override
|
||||
public void onReceive(String[] data) {
|
||||
if (data.length > 2) {
|
||||
VoteSite site = Main.plugin.getVoteSite(data[1]);
|
||||
String p = data[3];
|
||||
User user = UserManager.getInstance().getVotingPluginUser(p);
|
||||
if (site != null) {
|
||||
site.broadcastVote(user, false);
|
||||
} else {
|
||||
Main.plugin.getLogger().warning("No votesite for " + data[1]);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
socketHandler.add(new SocketReceiver("Status") {
|
||||
|
||||
@Override
|
||||
public void onReceive(String[] data) {
|
||||
if (data.length > 0) {
|
||||
Main.plugin.getLogger().info("Received status command, sending status back");
|
||||
sendData("StatusOkay", Main.plugin.getOptions().getServer());
|
||||
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
socketHandler.add(new SocketReceiver("BungeeUpdate") {
|
||||
|
||||
@Override
|
||||
public void onReceive(String[] data) {
|
||||
Main.plugin.setUpdate(true);
|
||||
}
|
||||
});
|
||||
|
||||
if (Main.plugin.getOptions().getServer().equalsIgnoreCase("pleaseset")) {
|
||||
Main.plugin.getLogger().warning("Server name for bungee voting is not set, please set it");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void sendData(String... strings) {
|
||||
clientHandler.sendMessage(strings);
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large.
Load diff
-76
@@ -1,76 +0,0 @@
|
||||
package com.Ben12345rocks.VotingPlugin.Commands.Executers;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
import com.Ben12345rocks.AdvancedCore.CommandAPI.CommandHandler;
|
||||
import com.Ben12345rocks.VotingPlugin.Main;
|
||||
import com.Ben12345rocks.VotingPlugin.Config.Config;
|
||||
import com.Ben12345rocks.VotingPlugin.Config.ConfigVoteSites;
|
||||
|
||||
// TODO: Auto-generated Javadoc
|
||||
/**
|
||||
* The Class CommandAdminVote.
|
||||
*/
|
||||
public class CommandAdminVote implements CommandExecutor {
|
||||
|
||||
/** The instance. */
|
||||
private static CommandAdminVote instance = new CommandAdminVote();
|
||||
|
||||
/**
|
||||
* Gets the single instance of CommandAdminVote.
|
||||
*
|
||||
* @return single instance of CommandAdminVote
|
||||
*/
|
||||
public static CommandAdminVote getInstance() {
|
||||
return instance;
|
||||
}
|
||||
|
||||
/** The config. */
|
||||
Config config = Config.getInstance();
|
||||
|
||||
/** The plugin. */
|
||||
private Main plugin = Main.plugin;
|
||||
|
||||
/** The vote sites. */
|
||||
ConfigVoteSites voteSites = ConfigVoteSites.getInstance();
|
||||
|
||||
/**
|
||||
* Instantiates a new command admin vote.
|
||||
*/
|
||||
private CommandAdminVote() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Instantiates a new command admin vote.
|
||||
*
|
||||
* @param plugin
|
||||
* the plugin
|
||||
*/
|
||||
public CommandAdminVote(Main plugin) {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.bukkit.command.CommandExecutor#onCommand(org.bukkit.command.
|
||||
* CommandSender , org.bukkit.command.Command, java.lang.String,
|
||||
* java.lang.String[])
|
||||
*/
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
|
||||
for (CommandHandler commandHandler : plugin.getAdminVoteCommand()) {
|
||||
if (commandHandler.runCommand(sender, args)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
// invalid command
|
||||
sender.sendMessage(ChatColor.RED + "No valid arguments, see /adminvote help!");
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,962 +0,0 @@
|
||||
package com.Ben12345rocks.VotingPlugin.Commands.GUI;
|
||||
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.Set;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.inventory.ClickType;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import com.Ben12345rocks.AdvancedCore.NMSManager.NMSManager;
|
||||
import com.Ben12345rocks.AdvancedCore.Rewards.RewardHandler;
|
||||
import com.Ben12345rocks.AdvancedCore.Rewards.RewardOptions;
|
||||
import com.Ben12345rocks.AdvancedCore.Util.Inventory.BInventory;
|
||||
import com.Ben12345rocks.AdvancedCore.Util.Inventory.BInventory.ClickEvent;
|
||||
import com.Ben12345rocks.AdvancedCore.Util.Inventory.BInventoryButton;
|
||||
import com.Ben12345rocks.AdvancedCore.Util.Item.ItemBuilder;
|
||||
import com.Ben12345rocks.AdvancedCore.Util.Messages.StringParser;
|
||||
import com.Ben12345rocks.AdvancedCore.Util.Misc.ArrayUtils;
|
||||
import com.Ben12345rocks.AdvancedCore.Util.Misc.PlayerUtils;
|
||||
import com.Ben12345rocks.VotingPlugin.Main;
|
||||
import com.Ben12345rocks.VotingPlugin.Commands.Commands;
|
||||
import com.Ben12345rocks.VotingPlugin.Config.BungeeSettings;
|
||||
import com.Ben12345rocks.VotingPlugin.Config.Config;
|
||||
import com.Ben12345rocks.VotingPlugin.Objects.User;
|
||||
import com.Ben12345rocks.VotingPlugin.Objects.VoteSite;
|
||||
import com.Ben12345rocks.VotingPlugin.TopVoter.TopVoter;
|
||||
import com.Ben12345rocks.VotingPlugin.TopVoter.TopVoterHandler;
|
||||
import com.Ben12345rocks.VotingPlugin.UserManager.UserManager;
|
||||
|
||||
import net.md_5.bungee.api.chat.BaseComponent;
|
||||
import net.md_5.bungee.api.chat.TextComponent;
|
||||
import xyz.upperlevel.spigot.book.BookUtil;
|
||||
|
||||
public class PlayerGUIs {
|
||||
static PlayerGUIs instance = new PlayerGUIs();
|
||||
|
||||
/**
|
||||
* Gets the single instance of Commands.
|
||||
*
|
||||
* @return single instance of Commands
|
||||
*/
|
||||
public static PlayerGUIs getInstance() {
|
||||
return instance;
|
||||
}
|
||||
|
||||
/** The plugin. */
|
||||
Main plugin = Main.plugin;
|
||||
|
||||
/**
|
||||
* Instantiates a new commands.
|
||||
*/
|
||||
private PlayerGUIs() {
|
||||
}
|
||||
|
||||
public BInventoryButton getBackButton() {
|
||||
ConfigurationSection sec = Config.getInstance().getBackButton();
|
||||
ItemBuilder item;
|
||||
if (sec != null) {
|
||||
item = new ItemBuilder(sec);
|
||||
} else {
|
||||
item = new ItemBuilder(Material.BARRIER, 1).setName("&8Back to VoteGUI");
|
||||
}
|
||||
|
||||
BInventoryButton b = new BInventoryButton(item) {
|
||||
|
||||
@Override
|
||||
public void onClick(ClickEvent event) {
|
||||
openVoteGUI(event.getWhoClicked(), getSelectedPlayer(event.getWhoClicked()));
|
||||
}
|
||||
};
|
||||
|
||||
if (!Config.getInstance().isAlwaysCloseInventory()) {
|
||||
b.dontClose();
|
||||
}
|
||||
|
||||
return b;
|
||||
}
|
||||
|
||||
public User getSelectedPlayer(Player player) {
|
||||
User str = (User) PlayerUtils.getInstance().getPlayerMeta(player, "SelectedPlayerGUIs");
|
||||
return str;
|
||||
}
|
||||
|
||||
public void openVoteBest(Player player, User user) {
|
||||
setSelectedPlayer(player, user);
|
||||
BInventory inv = new BInventory(Config.getInstance().getGUIVoteBestName());
|
||||
inv.addPlaceholder("player", user.getPlayerName());
|
||||
|
||||
inv.addButton(new BInventoryButton(new ItemBuilder(Config.getInstance().getGUIVoteBestDayBestItem())
|
||||
.addPlaceholder("Best", "" + user.getBestDayVoteStreak())) {
|
||||
|
||||
@Override
|
||||
public void onClick(ClickEvent clickEvent) {
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
inv.addButton(new BInventoryButton(new ItemBuilder(Config.getInstance().getGUIVoteBestWeekBestItem())
|
||||
.addPlaceholder("Best", "" + user.getBestWeekVoteStreak())) {
|
||||
|
||||
@Override
|
||||
public void onClick(ClickEvent clickEvent) {
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
inv.addButton(new BInventoryButton(new ItemBuilder(Config.getInstance().getGUIVoteBestMonthBestItem())
|
||||
.addPlaceholder("Best", "" + user.getBestMonthVoteStreak())) {
|
||||
|
||||
@Override
|
||||
public void onClick(ClickEvent clickEvent) {
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
inv.openInventory(player);
|
||||
}
|
||||
|
||||
public void openVoteGUI(Player player, User user) {
|
||||
if (user == null) {
|
||||
user = UserManager.getInstance().getVotingPluginUser(player);
|
||||
setSelectedPlayer(player, user);
|
||||
}
|
||||
if ((!player.getName().equals(user.getPlayerName())
|
||||
&& !player.hasPermission("VotingPlugin.Commands.Vote.GUI.Other")
|
||||
&& !player.hasPermission("VotingPlugin.Mod"))
|
||||
|| (!player.hasPermission("VotingPlugin.Commands.Vote.GUI")
|
||||
&& !player.hasPermission("VotingPlugin.Player"))) {
|
||||
player.sendMessage(StringParser.getInstance().colorize(Main.plugin.getOptions().getFormatNoPerms()));
|
||||
return;
|
||||
}
|
||||
setSelectedPlayer(player, user);
|
||||
BInventory inv = new BInventory(Config.getInstance().getGUIVoteGUIName());
|
||||
if (!Config.getInstance().isAlwaysCloseInventory()) {
|
||||
inv.dontClose();
|
||||
}
|
||||
|
||||
inv.addPlaceholder("points", "" + user.getPoints());
|
||||
inv.addPlaceholder("player", user.getPlayerName());
|
||||
inv.addPlaceholder("top", Config.getInstance().getVoteTopDefault());
|
||||
|
||||
for (String slot : Config.getInstance().getVoteGUISlots()) {
|
||||
ItemBuilder builder = new ItemBuilder(Config.getInstance().getVoteGUISlotSection(slot));
|
||||
|
||||
String[] lore = new String[1];
|
||||
|
||||
lore = ArrayUtils.getInstance().convert(Config.getInstance().getVoteGUISlotLore(slot));
|
||||
|
||||
String str = Config.getInstance().getVoteTopDefault();
|
||||
if (lore.length == 0) {
|
||||
if (slot.equalsIgnoreCase("url")) {
|
||||
lore = new String[] { "&aClick me" };
|
||||
} else if (slot.equalsIgnoreCase("next")) {
|
||||
lore = Commands.getInstance().voteCommandNext(user);
|
||||
} else if (slot.equalsIgnoreCase("last")) {
|
||||
lore = Commands.getInstance().voteCommandLast(user);
|
||||
} else if (slot.equalsIgnoreCase("total")) {
|
||||
lore = Commands.getInstance().voteCommandTotal(user);
|
||||
} else if (slot.equalsIgnoreCase("top")) {
|
||||
|
||||
if (str.equalsIgnoreCase("monthly")) {
|
||||
lore = TopVoterHandler.getInstance().topVoterMonthly(1);
|
||||
} else if (str.equalsIgnoreCase("weekly")) {
|
||||
lore = TopVoterHandler.getInstance().topVoterWeekly(1);
|
||||
} else if (str.equalsIgnoreCase("daily")) {
|
||||
lore = TopVoterHandler.getInstance().topVoterDaily(1);
|
||||
} else {
|
||||
lore = TopVoterHandler.getInstance().topVoterAllTime(1);
|
||||
}
|
||||
} else if (slot.equalsIgnoreCase("today")) {
|
||||
lore = Commands.getInstance().voteToday();
|
||||
} else if (slot.equalsIgnoreCase("help")) {
|
||||
lore = new String[] { "Click to view help" };
|
||||
}
|
||||
}
|
||||
|
||||
builder.setLore(ArrayUtils.getInstance().convert(lore));
|
||||
|
||||
inv.addButton(new BInventoryButton(builder) {
|
||||
|
||||
@Override
|
||||
public void onClick(ClickEvent event) {
|
||||
|
||||
Player player = event.getWhoClicked();
|
||||
String cmd = Config.getInstance().getVoteGUISlotCommand(slot);
|
||||
User user = getSelectedPlayer(player);
|
||||
if (cmd.equalsIgnoreCase("none")) {
|
||||
return;
|
||||
} else if (!cmd.equals("")) {
|
||||
event.runSync(new Runnable() {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
player.performCommand(cmd);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
if (slot.equalsIgnoreCase("url")) {
|
||||
user.sendMessage(Commands.getInstance().voteURLs(user, true));
|
||||
event.closeInventory();
|
||||
} else if (slot.equalsIgnoreCase("next")) {
|
||||
openVoteNext(player, user);
|
||||
} else if (slot.equalsIgnoreCase("last")) {
|
||||
openVoteLast(player, user);
|
||||
} else if (slot.equalsIgnoreCase("total")) {
|
||||
openVoteTotal(player, user);
|
||||
} else if (slot.equalsIgnoreCase("top")) {
|
||||
openVoteTop(player, null);
|
||||
} else if (slot.equalsIgnoreCase("today")) {
|
||||
openVoteToday(player);
|
||||
} else if (slot.equalsIgnoreCase("help")) {
|
||||
player.performCommand("vote help");
|
||||
} else if (slot.equalsIgnoreCase("shop")) {
|
||||
openVoteShop(player);
|
||||
} else if (slot.equalsIgnoreCase("lastmonth")) {
|
||||
openVoteTopLastMonth(player);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
inv.openInventory(player);
|
||||
}
|
||||
|
||||
public void openVoteLast(Player player, User user) {
|
||||
setSelectedPlayer(player, user);
|
||||
BInventory inv = new BInventory(Config.getInstance().getGUIVoteLastName());
|
||||
inv.addPlaceholder("player", user.getPlayerName());
|
||||
for (VoteSite site : plugin.getVoteSites()) {
|
||||
inv.addButton(inv.getNextSlot(), new BInventoryButton(site.getItem().setName(site.getDisplayName())
|
||||
.setLore(Commands.getInstance().voteCommandLastLine(user, site)).setAmountNone(1)) {
|
||||
|
||||
@Override
|
||||
public void onClick(ClickEvent clickEvent) {
|
||||
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
if (Config.getInstance().getGUIVoteLastBackButton()) {
|
||||
inv.addButton(getBackButton());
|
||||
}
|
||||
|
||||
inv.openInventory(player);
|
||||
}
|
||||
|
||||
public void openVoteNext(Player player, User user) {
|
||||
setSelectedPlayer(player, user);
|
||||
BInventory inv = new BInventory(Config.getInstance().getGUIVoteNextName());
|
||||
inv.addPlaceholder("player", user.getPlayerName());
|
||||
for (VoteSite site : plugin.getVoteSites()) {
|
||||
inv.addButton(inv.getNextSlot(), new BInventoryButton(site.getItem().setName(site.getDisplayName())
|
||||
.setLore(Commands.getInstance().voteCommandNextInfo(user, site)).setAmountNone(1)) {
|
||||
|
||||
@Override
|
||||
public void onClick(ClickEvent clickEvent) {
|
||||
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
if (Config.getInstance().getGUIVoteNextBackButton()) {
|
||||
inv.addButton(getBackButton());
|
||||
}
|
||||
inv.openInventory(player);
|
||||
}
|
||||
|
||||
public void openVoteShop(Player player) {
|
||||
if (!Config.getInstance().getVoteShopEnabled()) {
|
||||
player.sendMessage(StringParser.getInstance().colorize(Config.getInstance().getVoteShopDisabled()));
|
||||
return;
|
||||
}
|
||||
|
||||
BInventory inv = new BInventory(Config.getInstance().getVoteShopName());
|
||||
|
||||
for (final String identifier : Config.getInstance().getIdentifiers()) {
|
||||
|
||||
String perm = Config.getInstance().getVoteShopPermission(identifier);
|
||||
boolean hasPerm = false;
|
||||
if (perm.isEmpty()) {
|
||||
hasPerm = true;
|
||||
} else {
|
||||
hasPerm = player.hasPermission(perm);
|
||||
}
|
||||
|
||||
int limit = Config.getInstance().getIdentifierLimit(identifier);
|
||||
|
||||
boolean limitPass = true;
|
||||
if (limit > 0) {
|
||||
User user = UserManager.getInstance().getVotingPluginUser(player);
|
||||
if (user.getVoteShopIdentifierLimit(identifier) >= limit) {
|
||||
limitPass = false;
|
||||
}
|
||||
}
|
||||
|
||||
if (!Config.getInstance().getVoteShopNotBuyable(identifier)) {
|
||||
if (hasPerm && (limitPass || !Config.getInstance().isVoteShopHideLimitedReached())) {
|
||||
ItemBuilder builder = new ItemBuilder(Config.getInstance().getIdentifierSection(identifier));
|
||||
|
||||
inv.addButton(new BInventoryButton(builder) {
|
||||
|
||||
@Override
|
||||
public void onClick(ClickEvent event) {
|
||||
Player player = event.getWhoClicked();
|
||||
event.getButton().getInv().closeInv(player, null);
|
||||
|
||||
User user = UserManager.getInstance().getVotingPluginUser(player);
|
||||
if (Config.getInstance().isClearCacheOnVoteShopPurchase()
|
||||
|| BungeeSettings.getInstance().isUseBungeecoord()) {
|
||||
user.clearCache();
|
||||
}
|
||||
String identifier = (String) getData("identifier");
|
||||
int limit = (int) getData("Limit");
|
||||
int points = Config.getInstance().getIdentifierCost(identifier);
|
||||
if (identifier != null) {
|
||||
|
||||
// limit fail-safe, should never be needed, except in rare cases
|
||||
boolean limitPass = true;
|
||||
if (limit > 0) {
|
||||
if (user.getVoteShopIdentifierLimit(identifier) >= limit) {
|
||||
limitPass = false;
|
||||
}
|
||||
}
|
||||
|
||||
if (limitPass) {
|
||||
if (!Config.getInstance().isVoteShopRequireConfirmation()) {
|
||||
HashMap<String, String> placeholders = new HashMap<String, String>();
|
||||
placeholders.put("identifier",
|
||||
Config.getInstance().getIdentifierIdentifierName(identifier));
|
||||
placeholders.put("points", "" + points);
|
||||
placeholders.put("limit", "" + limit);
|
||||
if (user.removePoints(points)) {
|
||||
|
||||
RewardHandler.getInstance().giveReward(user, Config.getInstance().getData(),
|
||||
Config.getInstance().getIdentifierRewardsPath(identifier),
|
||||
new RewardOptions().setPlaceholders(placeholders));
|
||||
|
||||
user.sendMessage(StringParser.getInstance().replacePlaceHolder(
|
||||
Config.getInstance().getFormatShopPurchaseMsg(), placeholders));
|
||||
if (limit > 0) {
|
||||
user.setVoteShopIdentifierLimit(identifier,
|
||||
user.getVoteShopIdentifierLimit(identifier) + 1);
|
||||
}
|
||||
} else {
|
||||
user.sendMessage(StringParser.getInstance().replacePlaceHolder(
|
||||
Config.getInstance().getFormatShopFailedMsg(), placeholders));
|
||||
}
|
||||
} else {
|
||||
openVoteShopConfirmation(player, identifier);
|
||||
}
|
||||
} else {
|
||||
user.sendMessage(Config.getInstance().getVoteShopLimitReached());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}.addData("identifier", identifier).addData("Limit", limit));
|
||||
}
|
||||
} else {
|
||||
if (hasPerm) {
|
||||
ItemBuilder builder = new ItemBuilder(Config.getInstance().getIdentifierSection(identifier));
|
||||
inv.addButton(new BInventoryButton(builder) {
|
||||
|
||||
@Override
|
||||
public void onClick(ClickEvent event) {
|
||||
|
||||
}
|
||||
|
||||
}.dontClose().addData("identifier", identifier).addData("Limit", limit));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (Config.getInstance().getVoteShopBackButton()) {
|
||||
inv.addButton(getBackButton());
|
||||
}
|
||||
|
||||
inv.openInventory(player);
|
||||
}
|
||||
|
||||
public void openVoteShopConfirmation(Player player, String identifier) {
|
||||
PlayerUtils.getInstance().setPlayerMeta(player, "ident", identifier);
|
||||
BInventory inv = new BInventory("Confirm Purchase?");
|
||||
inv.addButton(new BInventoryButton(new ItemBuilder(Material.EMERALD_BLOCK).setName("&aYes")) {
|
||||
|
||||
@Override
|
||||
public void onClick(ClickEvent event) {
|
||||
String ident = (String) PlayerUtils.getInstance().getPlayerMeta(event.getPlayer(), "ident");
|
||||
User user = UserManager.getInstance().getVotingPluginUser(event.getPlayer());
|
||||
int points = Config.getInstance().getIdentifierCost(ident);
|
||||
int limit = Config.getInstance().getIdentifierLimit(identifier);
|
||||
HashMap<String, String> placeholders = new HashMap<String, String>();
|
||||
placeholders.put("identifier", identifier);
|
||||
placeholders.put("points", "" + points);
|
||||
placeholders.put("limit", "" + limit);
|
||||
if (user.removePoints(points)) {
|
||||
|
||||
RewardHandler.getInstance().giveReward(user, Config.getInstance().getData(),
|
||||
Config.getInstance().getIdentifierRewardsPath(identifier),
|
||||
new RewardOptions().setPlaceholders(placeholders));
|
||||
|
||||
user.sendMessage(StringParser.getInstance()
|
||||
.replacePlaceHolder(Config.getInstance().getFormatShopPurchaseMsg(), placeholders));
|
||||
if (limit > 0) {
|
||||
user.setVoteShopIdentifierLimit(identifier, user.getVoteShopIdentifierLimit(identifier) + 1);
|
||||
}
|
||||
} else {
|
||||
user.sendMessage(StringParser.getInstance()
|
||||
.replacePlaceHolder(Config.getInstance().getFormatShopFailedMsg(), placeholders));
|
||||
}
|
||||
Bukkit.getScheduler().runTask(plugin, new Runnable() {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
event.getPlayer().closeInventory();
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
});
|
||||
inv.addButton(new BInventoryButton(new ItemBuilder(Material.BARRIER).setName("&cNo")) {
|
||||
|
||||
@Override
|
||||
public void onClick(ClickEvent event) {
|
||||
event.getPlayer().closeInventory();
|
||||
}
|
||||
});
|
||||
inv.openInventory(player);
|
||||
}
|
||||
|
||||
public void openVoteStreak(Player player, User user) {
|
||||
setSelectedPlayer(player, user);
|
||||
BInventory inv = new BInventory(Config.getInstance().getGUIVoteStreakName());
|
||||
inv.addPlaceholder("player", user.getPlayerName());
|
||||
|
||||
inv.addButton(new BInventoryButton(new ItemBuilder(Config.getInstance().getGUIVoteStreakCurrentDayStreakItem())
|
||||
.addPlaceholder("Streak", "" + user.getDayVoteStreak())) {
|
||||
|
||||
@Override
|
||||
public void onClick(ClickEvent clickEvent) {
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
inv.addButton(new BInventoryButton(new ItemBuilder(Config.getInstance().getGUIVoteStreakCurrentWeekStreakItem())
|
||||
.addPlaceholder("Streak", "" + user.getWeekVoteStreak())) {
|
||||
|
||||
@Override
|
||||
public void onClick(ClickEvent clickEvent) {
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
inv.addButton(
|
||||
new BInventoryButton(new ItemBuilder(Config.getInstance().getGUIVoteStreakCurrentMonthStreakItem())
|
||||
.addPlaceholder("Streak", "" + user.getMonthVoteStreak())) {
|
||||
|
||||
@Override
|
||||
public void onClick(ClickEvent clickEvent) {
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
inv.addButton(new BInventoryButton(new ItemBuilder(Config.getInstance().getGUIVoteStreakHighestDayStreakItem())
|
||||
.addPlaceholder("Streak", "" + user.getBestDayVoteStreak())) {
|
||||
|
||||
@Override
|
||||
public void onClick(ClickEvent clickEvent) {
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
inv.addButton(new BInventoryButton(new ItemBuilder(Config.getInstance().getGUIVoteStreakHighestWeekStreakItem())
|
||||
.addPlaceholder("Streak", "" + user.getBestWeekVoteStreak())) {
|
||||
|
||||
@Override
|
||||
public void onClick(ClickEvent clickEvent) {
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
inv.addButton(
|
||||
new BInventoryButton(new ItemBuilder(Config.getInstance().getGUIVoteStreakHighestMonthStreakItem())
|
||||
.addPlaceholder("Streak", "" + user.getBestMonthVoteStreak())) {
|
||||
|
||||
@Override
|
||||
public void onClick(ClickEvent clickEvent) {
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
if (Config.getInstance().getGUIVoteStreakBackButton()) {
|
||||
inv.addButton(getBackButton());
|
||||
}
|
||||
|
||||
inv.openInventory(player);
|
||||
}
|
||||
|
||||
public void openVoteToday(Player player) {
|
||||
setSelectedPlayer(player, null);
|
||||
BInventory inv = new BInventory(Config.getInstance().getGUIVoteTodayName());
|
||||
if (!Config.getInstance().isAlwaysCloseInventory()) {
|
||||
inv.dontClose();
|
||||
}
|
||||
for (User user : plugin.getVoteToday().keySet()) {
|
||||
|
||||
for (VoteSite voteSite : plugin.getVoteToday().get(user).keySet()) {
|
||||
DateTimeFormatter formatter = DateTimeFormatter.ofPattern(Config.getInstance().getFormatTimeFormat());
|
||||
String timeString = plugin.getVoteToday().get(user).get(voteSite).format(formatter);
|
||||
String msg = Config.getInstance().getGUIVoteTodayLine();
|
||||
HashMap<String, String> placeholders = new HashMap<String, String>();
|
||||
placeholders.put("VoteSite", voteSite.getDisplayName());
|
||||
placeholders.put("Time", timeString);
|
||||
msg = StringParser.getInstance().replacePlaceHolder(msg, placeholders);
|
||||
ItemBuilder item = null;
|
||||
if (Config.getInstance().isGUIVoteTodayUseSkull() && !NMSManager.getInstance().isVersion("1.12")) {
|
||||
item = new ItemBuilder(new ItemStack(Material.PLAYER_HEAD, 1)).setSkullOwner(player);
|
||||
} else {
|
||||
item = new ItemBuilder(Config.getInstance().getGUIVoteTodayPlayerItem());
|
||||
}
|
||||
item.setName(StringParser.getInstance().replacePlaceHolder(
|
||||
Config.getInstance().getGUIVoteTodayIconTitle(), "player", user.getPlayerName()));
|
||||
item.setLore(msg);
|
||||
inv.addButton(inv.getNextSlot(), new BInventoryButton(item) {
|
||||
|
||||
@Override
|
||||
public void onClick(ClickEvent clickEvent) {
|
||||
User user = UserManager.getInstance()
|
||||
.getVotingPluginUser(clickEvent.getClickedItem().getItemMeta().getDisplayName());
|
||||
openVoteGUI(player, user);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
if (Config.getInstance().getGUIVoteTodayBackButton()) {
|
||||
inv.addButton(getBackButton());
|
||||
}
|
||||
inv.openInventory(player);
|
||||
}
|
||||
|
||||
public void openVoteTop(Player player, TopVoter top) {
|
||||
try {
|
||||
if (top == null) {
|
||||
top = TopVoter.getDefault();
|
||||
}
|
||||
Set<Entry<User, Integer>> users = null;
|
||||
|
||||
String topVoter = top.getName();
|
||||
@SuppressWarnings("unchecked")
|
||||
LinkedHashMap<User, Integer> topVotes = (LinkedHashMap<User, Integer>) plugin.getTopVoter(top).clone();
|
||||
users = topVotes.entrySet();
|
||||
|
||||
BInventory inv = new BInventory(Config.getInstance().getGUIVoteTopName());
|
||||
inv.addPlaceholder("topvoter", topVoter);
|
||||
if (!Config.getInstance().isAlwaysCloseInventory()) {
|
||||
inv.dontClose();
|
||||
}
|
||||
|
||||
int pos = 1;
|
||||
for (Entry<User, Integer> entry : users) {
|
||||
ItemBuilder playerItem;
|
||||
|
||||
if (Config.getInstance().isGuiVoteTopUseSkull()) {
|
||||
playerItem = new ItemBuilder(entry.getKey().getPlayerHead());
|
||||
} else {
|
||||
playerItem = new ItemBuilder(
|
||||
Material.valueOf(Config.getInstance().getGuiVoteTopPlayerItemMaterial()));
|
||||
}
|
||||
|
||||
playerItem.setLore(new ArrayList<String>());
|
||||
|
||||
inv.addButton(new BInventoryButton(playerItem.setName(Config.getInstance().getGUIVoteTopItemName())
|
||||
.addLoreLine(Config.getInstance().getGUIVoteTopItemLore()).addPlaceholder("position", "" + pos)
|
||||
.addPlaceholder("player", entry.getKey().getPlayerName())
|
||||
.addPlaceholder("votes", "" + entry.getValue())) {
|
||||
|
||||
@Override
|
||||
public void onClick(ClickEvent clickEvent) {
|
||||
User user = (User) getData("User");
|
||||
openVoteGUI(player, user);
|
||||
}
|
||||
}.addData("player", entry.getKey().getPlayerName()).addData("User", entry.getKey()));
|
||||
pos++;
|
||||
}
|
||||
|
||||
final TopVoter cur = top;
|
||||
inv.getPageButtons().add(new BInventoryButton(
|
||||
new ItemBuilder(Config.getInstance().getGUIVoteTopSwitchItem()).addPlaceholder("Top", topVoter)) {
|
||||
|
||||
@Override
|
||||
public void onClick(ClickEvent clickEvent) {
|
||||
if (!clickEvent.getClick().equals(ClickType.RIGHT)) {
|
||||
openVoteTop(player, cur.next());
|
||||
} else {
|
||||
openVoteTop(player, cur.prev());
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
if (Config.getInstance().getGUIVoteTopBackButton()) {
|
||||
inv.getPageButtons().add(getBackButton().setSlot(1));
|
||||
}
|
||||
|
||||
inv.setPages(true);
|
||||
inv.setMaxInvSize(Config.getInstance().getGUIVoteTopSize());
|
||||
inv.openInventory(player);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public void openVoteTopLastMonth(Player player) {
|
||||
Set<Entry<User, Integer>> users = null;
|
||||
|
||||
users = plugin.getLastMonthTopVoter().entrySet();
|
||||
|
||||
BInventory inv = new BInventory(Config.getInstance().getGUIVoteTopName());
|
||||
inv.addPlaceholder("topvoter", "Last Month");
|
||||
if (!Config.getInstance().isAlwaysCloseInventory()) {
|
||||
inv.dontClose();
|
||||
}
|
||||
|
||||
int pos = 1;
|
||||
for (Entry<User, Integer> entry : users) {
|
||||
ItemBuilder playerItem;
|
||||
|
||||
if (Config.getInstance().isGuiVoteTopUseSkull()) {
|
||||
playerItem = new ItemBuilder(entry.getKey().getPlayerHead());
|
||||
} else {
|
||||
playerItem = new ItemBuilder(Material.valueOf(Config.getInstance().getGuiVoteTopPlayerItemMaterial()));
|
||||
}
|
||||
|
||||
playerItem.setLore(new ArrayList<String>());
|
||||
|
||||
inv.addButton(new BInventoryButton(playerItem.setName(Config.getInstance().getGUIVoteTopItemName())
|
||||
.addLoreLine(Config.getInstance().getGUIVoteTopItemLore()).addPlaceholder("position", "" + pos)
|
||||
.addPlaceholder("player", entry.getKey().getPlayerName())
|
||||
.addPlaceholder("votes", "" + entry.getValue())) {
|
||||
|
||||
@Override
|
||||
public void onClick(ClickEvent clickEvent) {
|
||||
User user = (User) getData("User");
|
||||
openVoteGUI(player, user);
|
||||
}
|
||||
}.addData("player", entry.getKey().getPlayerName()).addData("User", entry.getKey()));
|
||||
pos++;
|
||||
}
|
||||
|
||||
if (Config.getInstance().getGUIVoteTopBackButton()) {
|
||||
inv.getPageButtons().add(getBackButton().setSlot(1));
|
||||
}
|
||||
|
||||
inv.setPages(true);
|
||||
inv.setMaxInvSize(Config.getInstance().getGUIVoteTopSize());
|
||||
inv.openInventory(player);
|
||||
|
||||
}
|
||||
|
||||
public void openVoteTotal(Player player, User user) {
|
||||
setSelectedPlayer(player, user);
|
||||
BInventory inv = new BInventory(Config.getInstance().getGUIVoteTotalName());
|
||||
inv.addPlaceholder("player", user.getPlayerName());
|
||||
|
||||
for (TopVoter top : TopVoter.values()) {
|
||||
inv.addButton(new BInventoryButton(new ItemBuilder(Config.getInstance().getGUIVoteTotalItem(top))
|
||||
.addPlaceholder("Total", "" + user.getTotal(top)).addPlaceholder("topvoter", top.getName())) {
|
||||
|
||||
@Override
|
||||
public void onClick(ClickEvent clickEvent) {
|
||||
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
if (Config.getInstance().getGUIVoteTotalBackButton()) {
|
||||
inv.addButton(getBackButton());
|
||||
}
|
||||
inv.openInventory(player);
|
||||
}
|
||||
|
||||
/**
|
||||
* Vote URL.
|
||||
*
|
||||
* @param player
|
||||
* the player
|
||||
*/
|
||||
public void openVoteURL(Player player) {
|
||||
setSelectedPlayer(player, null);
|
||||
User user = UserManager.getInstance().getVotingPluginUser(player);
|
||||
if (!Config.getInstance().isCommandsVoteBookGUI()) {
|
||||
// normal GUI
|
||||
BInventory inv = new BInventory(Config.getInstance().getGUIVoteURLName());
|
||||
|
||||
int count = 0;
|
||||
if (Config.getInstance().getVoteURLViewAllUrlsButtonEnabled()) {
|
||||
ItemBuilder builderAll = new ItemBuilder(
|
||||
Config.getInstance().getVoteURLAlreadyVotedAllUrlsButtonItemSection());
|
||||
if (Config.getInstance().isGuiVoteURLAllUrlsButtonrequireAllSitesVoted()) {
|
||||
if (user.canVoteAny()) {
|
||||
builderAll = new ItemBuilder(Config.getInstance().getVoteURLCanVoteAllUrlsButtonItemSection());
|
||||
}
|
||||
} else {
|
||||
if (user.canVoteAll()) {
|
||||
builderAll = new ItemBuilder(Config.getInstance().getVoteURLCanVoteAllUrlsButtonItemSection());
|
||||
}
|
||||
}
|
||||
|
||||
if (!builderAll.hasCustomDisplayName()) {
|
||||
builderAll.setName("&4All Voting Sites");
|
||||
}
|
||||
if (!builderAll.hasCustomLore()) {
|
||||
builderAll.setLore("&cClick Me");
|
||||
}
|
||||
|
||||
inv.addButton(count, new BInventoryButton(builderAll) {
|
||||
|
||||
@Override
|
||||
public void onClick(ClickEvent event) {
|
||||
User user = UserManager.getInstance().getVotingPluginUser(event.getPlayer());
|
||||
user.sendMessage(Commands.getInstance().voteURLs(user, true));
|
||||
}
|
||||
});
|
||||
|
||||
count++;
|
||||
}
|
||||
|
||||
for (final VoteSite voteSite : plugin.getVoteSites()) {
|
||||
ItemBuilder builder = new ItemBuilder(Config.getInstance().getVoteURLAlreadyVotedItemSection());
|
||||
if (user.canVoteSite(voteSite)) {
|
||||
builder = new ItemBuilder(Config.getInstance().getVoteURLCanVoteItemSection());
|
||||
} else {
|
||||
builder.addLoreLine(Config.getInstance().getVoteURLNextVote().replace("%Info%",
|
||||
Commands.getInstance().voteCommandNextInfo(user, voteSite)));
|
||||
}
|
||||
|
||||
builder.setName(Config.getInstance().getVoteURLSiteName().replace("%Name%", voteSite.getDisplayName()));
|
||||
|
||||
inv.addButton(count, new BInventoryButton(builder) {
|
||||
|
||||
@Override
|
||||
public void onClick(ClickEvent event) {
|
||||
Player player = event.getPlayer();
|
||||
if (player != null) {
|
||||
if (Config.getInstance().isCommandsVoteRewardFromVoteURL()
|
||||
&& event.getClick().equals(ClickType.RIGHT)) {
|
||||
voteReward(player, voteSite.getKey());
|
||||
} else {
|
||||
User user = UserManager.getInstance().getVotingPluginUser(player);
|
||||
user.sendMessage(
|
||||
StringParser.getInstance()
|
||||
.replacePlaceHolder(
|
||||
StringParser.getInstance()
|
||||
.replacePlaceHolder(
|
||||
StringParser.getInstance().replacePlaceHolder(
|
||||
Config.getInstance()
|
||||
.getGUIVoteURLURLText(),
|
||||
"voteurl", voteSite.getVoteURL()),
|
||||
"sitename", voteSite.getDisplayName()),
|
||||
"player", player.getName()));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
});
|
||||
count++;
|
||||
}
|
||||
|
||||
if (Config.getInstance().getGUIVoteURLBackButton()) {
|
||||
inv.addButton(getBackButton());
|
||||
}
|
||||
|
||||
inv.openInventory(player);
|
||||
} else {
|
||||
// book gui
|
||||
ArrayList<BaseComponent[]> builder = new ArrayList<BaseComponent[]>();
|
||||
BookUtil.PageBuilder currentPage = new BookUtil.PageBuilder();
|
||||
int lines = 0;
|
||||
for (final VoteSite site : plugin.getVoteSites()) {
|
||||
|
||||
try {
|
||||
ArrayList<String> layout = Config.getInstance().getGUIVoteURLBookGUILayout();
|
||||
|
||||
lines += layout.size();
|
||||
if (lines > 14) {
|
||||
builder.add(currentPage.build());
|
||||
currentPage = new BookUtil.PageBuilder();
|
||||
lines = layout.size();
|
||||
plugin.debug("New page");
|
||||
}
|
||||
|
||||
HashMap<String, String> placeholders = new HashMap<String, String>();
|
||||
placeholders.put("Sitename", site.getDisplayName());
|
||||
ChatColor color = ChatColor.valueOf(Config.getInstance().getGUIVoteURLBookGUIAlreadyVotedColor());
|
||||
String text = Config.getInstance().getGUIVoteURLBookGUIAlreadyVotedText();
|
||||
if (user.canVoteSite(site)) {
|
||||
color = ChatColor.valueOf(Config.getInstance().getGUIVoteURLBookGUICanVoteColor());
|
||||
text = Config.getInstance().getGUIVoteURLBookGUICanVoteText();
|
||||
}
|
||||
String url = ChatColor.stripColor(StringParser.getInstance()
|
||||
.colorize(StringParser.getInstance().parseJson(site.getVoteURL(false)).toPlainText()));
|
||||
if (!url.startsWith("http")) {
|
||||
if (!url.startsWith("www.")) {
|
||||
url = "https://www." + url;
|
||||
} else {
|
||||
url = "https://" + url;
|
||||
}
|
||||
}
|
||||
|
||||
for (String str : layout) {
|
||||
str = StringParser.getInstance().replacePlaceHolder(str, placeholders);
|
||||
|
||||
if (StringParser.getInstance().containsIgnorecase(str, "[UrlText]")) {
|
||||
String[] split = str.split("[UrlText]");
|
||||
String s = split[0].substring(0, split[0].length() - 1);
|
||||
BaseComponent comp = new TextComponent(StringParser.getInstance().colorize(s));
|
||||
comp.addExtra(BookUtil.TextBuilder.of(text).color(color)
|
||||
.onClick(BookUtil.ClickAction.openUrl(url))
|
||||
.onHover(BookUtil.HoverAction.showText(url)).build());
|
||||
comp.addExtra(StringParser.getInstance().colorize(str.substring(s.length() + 9)));
|
||||
currentPage.add(comp);
|
||||
} else {
|
||||
currentPage.add(StringParser.getInstance().colorize(str));
|
||||
}
|
||||
currentPage.newLine();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
builder.add(currentPage.build());
|
||||
|
||||
ItemStack book = BookUtil.writtenBook().author(player.getName())
|
||||
.title(StringParser.getInstance().colorize(Config.getInstance().getGUIVoteURLBookGUITitle()))
|
||||
.pages(builder).build();
|
||||
|
||||
Bukkit.getScheduler().runTask(plugin, new Runnable() {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
BookUtil.openPlayer(player, book);
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public void openVoteURL(Player player, String voteSite) {
|
||||
if (!plugin.isVoteSite(voteSite)) {
|
||||
player.sendMessage("Not a valid votesite");
|
||||
return;
|
||||
}
|
||||
User user = UserManager.getInstance().getVotingPluginUser(player);
|
||||
VoteSite site = plugin.getVoteSite(voteSite);
|
||||
BInventory inv = new BInventory(Config.getInstance().getGUIVoteURLSiteName());
|
||||
inv.addPlaceholder("site", site.getDisplayName());
|
||||
inv.setMeta(player, "VoteSite", site);
|
||||
if (!Config.getInstance().isAlwaysCloseInventory()) {
|
||||
inv.dontClose();
|
||||
}
|
||||
|
||||
inv.addButton(
|
||||
new BInventoryButton(new ItemBuilder(Material.BOW).setName("&4URL").addLoreLine("Click to see URL")) {
|
||||
|
||||
@Override
|
||||
public void onClick(ClickEvent clickEvent) {
|
||||
VoteSite site = (VoteSite) clickEvent.getMeta("VoteSite");
|
||||
clickEvent.getWhoClicked().sendMessage(site.getVoteURL());
|
||||
}
|
||||
});
|
||||
|
||||
inv.addButton(new BInventoryButton(new ItemBuilder(Material.COMPASS).setName("&4Next Vote")
|
||||
.addLoreLine(Commands.getInstance().voteCommandNextInfo(user, site))) {
|
||||
|
||||
@Override
|
||||
public void onClick(ClickEvent clickEvent) {
|
||||
openVoteURL(clickEvent.getPlayer());
|
||||
}
|
||||
});
|
||||
|
||||
inv.addButton(new BInventoryButton(new ItemBuilder(Material.CLOCK).setName("&4Last Vote")
|
||||
.addLoreLine(Commands.getInstance().voteCommandLastLine(user, site))) {
|
||||
|
||||
@Override
|
||||
public void onClick(ClickEvent clickEvent) {
|
||||
openVoteURL(clickEvent.getPlayer());
|
||||
}
|
||||
});
|
||||
|
||||
if (Config.getInstance().getGUIVoteURLBackButton()) {
|
||||
inv.addButton(getBackButton());
|
||||
}
|
||||
inv.openInventory(player);
|
||||
}
|
||||
|
||||
public void setSelectedPlayer(Player player, User user) {
|
||||
PlayerUtils.getInstance().setPlayerMeta(player, "SelectedPlayerGUIs", user);
|
||||
}
|
||||
|
||||
/**
|
||||
* Vote reward.
|
||||
*
|
||||
* @param player
|
||||
* the player
|
||||
* @param siteName
|
||||
* the site name
|
||||
*/
|
||||
public void voteReward(Player player, String siteName) {
|
||||
BInventory inv = new BInventory(Config.getInstance().getGUIVoteRewardName());
|
||||
|
||||
if ((siteName == null) || (siteName == "")) {
|
||||
for (VoteSite voteSite : plugin.getVoteSites()) {
|
||||
try {
|
||||
ItemBuilder builder = voteSite.getItem();
|
||||
|
||||
inv.addButton(new BInventoryButton(builder) {
|
||||
|
||||
@Override
|
||||
public void onClick(ClickEvent event) {
|
||||
Player player = event.getWhoClicked();
|
||||
|
||||
voteReward(player, (String) getData("site"));
|
||||
}
|
||||
}.addData("site", voteSite.getKey()));
|
||||
} catch (Exception ex) {
|
||||
|
||||
}
|
||||
}
|
||||
} else {
|
||||
for (String itemName : Config.getInstance().getVoteSiteItems(siteName)) {
|
||||
ItemBuilder builder = new ItemBuilder(Config.getInstance().getVoteSiteItemsSection(siteName, itemName));
|
||||
|
||||
inv.addButton(Config.getInstance().getVoteSiteItemsSlot(siteName, itemName),
|
||||
new BInventoryButton(builder) {
|
||||
|
||||
@Override
|
||||
public void onClick(ClickEvent event) {
|
||||
|
||||
}
|
||||
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
if (Config.getInstance().isVoteRewardBackButton()) {
|
||||
inv.addButton(getBackButton());
|
||||
}
|
||||
|
||||
inv.openInventory(player);
|
||||
}
|
||||
}
|
||||
@@ -1,91 +0,0 @@
|
||||
package com.Ben12345rocks.VotingPlugin.CoolDown;
|
||||
|
||||
import java.util.TimerTask;
|
||||
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
|
||||
import com.Ben12345rocks.AdvancedCore.Rewards.RewardHandler;
|
||||
import com.Ben12345rocks.AdvancedCore.Rewards.RewardOptions;
|
||||
import com.Ben12345rocks.AdvancedCore.TimeChecker.Events.DateChangedEvent;
|
||||
import com.Ben12345rocks.AdvancedCore.UserManager.UUID;
|
||||
import com.Ben12345rocks.VotingPlugin.Main;
|
||||
import com.Ben12345rocks.VotingPlugin.Config.SpecialRewardsConfig;
|
||||
import com.Ben12345rocks.VotingPlugin.Events.PlayerVoteCoolDownEndEvent;
|
||||
import com.Ben12345rocks.VotingPlugin.Objects.User;
|
||||
import com.Ben12345rocks.VotingPlugin.UserManager.UserManager;
|
||||
|
||||
// TODO: Auto-generated Javadoc
|
||||
/**
|
||||
* The Class VoteReminding.
|
||||
*/
|
||||
public class CoolDownCheck implements Listener {
|
||||
|
||||
/** The instance. */
|
||||
static CoolDownCheck instance = new CoolDownCheck();
|
||||
|
||||
/** The plugin. */
|
||||
static Main plugin = Main.plugin;
|
||||
|
||||
/**
|
||||
* Gets the single instance of VoteReminding.
|
||||
*
|
||||
* @return single instance of VoteReminding
|
||||
*/
|
||||
public static CoolDownCheck getInstance() {
|
||||
return instance;
|
||||
}
|
||||
|
||||
/**
|
||||
* Instantiates a new vote reminding.
|
||||
*/
|
||||
private CoolDownCheck() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Instantiates a new vote reminding.
|
||||
*
|
||||
* @param plugin
|
||||
* the plugin
|
||||
*/
|
||||
public CoolDownCheck(Main plugin) {
|
||||
CoolDownCheck.plugin = plugin;
|
||||
}
|
||||
|
||||
public void checkAll() {
|
||||
Main.plugin.getTimer().schedule(new TimerTask() {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
if (Main.plugin != null) {
|
||||
for (String uuid : UserManager.getInstance().getAllUUIDs()) {
|
||||
if (Main.plugin != null) {
|
||||
User user = UserManager.getInstance().getVotingPluginUser(new UUID(uuid));
|
||||
if (user.getUserData().hasData() && user.hasLoggedOnBefore()) {
|
||||
user.checkCoolDownEvents();
|
||||
}
|
||||
} else {
|
||||
cancel();
|
||||
}
|
||||
}
|
||||
} else {
|
||||
cancel();
|
||||
}
|
||||
}
|
||||
}, 1000 * 60 * 3);
|
||||
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
|
||||
public void onCoolDownEnd(PlayerVoteCoolDownEndEvent event) {
|
||||
RewardHandler.getInstance().giveReward(event.getPlayer(), SpecialRewardsConfig.getInstance().getData(),
|
||||
"VoteCoolDownEndedReward",
|
||||
new RewardOptions().addPlaceholder("Votesite", event.getVoteSite().getDisplayName()));
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
|
||||
public void onDayChangeEnd(DateChangedEvent event) {
|
||||
checkAll();
|
||||
}
|
||||
}
|
||||
-95
@@ -1,95 +0,0 @@
|
||||
package com.Ben12345rocks.VotingPlugin.Listeners;
|
||||
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
|
||||
import com.Ben12345rocks.AdvancedCore.Listeners.PluginUpdateVersionEvent;
|
||||
import com.Ben12345rocks.VotingPlugin.Main;
|
||||
import com.Ben12345rocks.VotingPlugin.Config.BungeeSettings;
|
||||
import com.Ben12345rocks.VotingPlugin.Config.Config;
|
||||
import com.Ben12345rocks.VotingPlugin.Config.SpecialRewardsConfig;
|
||||
|
||||
// TODO: Auto-generated Javadoc
|
||||
/**
|
||||
* The Class AdvancedCoreUpdateEvent.
|
||||
*/
|
||||
public class VotingPluginUpdateEvent implements Listener {
|
||||
|
||||
/** The plugin. */
|
||||
private static Main plugin;
|
||||
|
||||
/**
|
||||
* Instantiates a new advanced core update event.
|
||||
*
|
||||
* @param plugin
|
||||
* the plugin
|
||||
*/
|
||||
public VotingPluginUpdateEvent(Main plugin) {
|
||||
VotingPluginUpdateEvent.plugin = plugin;
|
||||
}
|
||||
|
||||
/**
|
||||
* On plugin update.
|
||||
*
|
||||
* @param event
|
||||
* the event
|
||||
*/
|
||||
@SuppressWarnings("deprecation")
|
||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||
public void onPluginUpdate(PluginUpdateVersionEvent event) {
|
||||
if (event.getPlugin().getName().equals(plugin.getDescription().getName())) {
|
||||
if (!event.getOldVersion().equals("")) {
|
||||
plugin.getLogger().info("VotingPlugin Updated to " + plugin.getDescription().getVersion() + " from "
|
||||
+ event.getOldVersion());
|
||||
|
||||
if (SpecialRewardsConfig.getInstance().isJustCreated()) {
|
||||
// copy old data over
|
||||
plugin.getLogger().info("Coping data from Config.yml into SpecialRewards.yml");
|
||||
|
||||
String[] copies = new String[] { "VoteCoolDownEndedReward", "AnySiteRewards", "VoteStreak",
|
||||
"MileStones", "VoteParty", "Cumulative", "AllSites", "FirstVote", "DailyAwards",
|
||||
"WeeklyAwards", "MonthlyAwards" };
|
||||
for (String str : copies) {
|
||||
SpecialRewardsConfig.getInstance().getData().set(str,
|
||||
Config.getInstance().getData().getConfigurationSection(str));
|
||||
}
|
||||
|
||||
String[] copies1 = new String[] { "ResetMilestonesMonthly", "EnableMonthlyAwards",
|
||||
"EnableWeeklyAwards", "EnableDailyRewards" };
|
||||
for (String str : copies1) {
|
||||
SpecialRewardsConfig.getInstance().getData().set(str,
|
||||
Config.getInstance().getData().getBoolean(str));
|
||||
}
|
||||
SpecialRewardsConfig.getInstance().saveData();
|
||||
}
|
||||
|
||||
if (BungeeSettings.getInstance().isJustCreated()) {
|
||||
// copy old data over
|
||||
plugin.getLogger().info("Coping data from Config.yml into BungeeSettings.yml");
|
||||
|
||||
String[] copies = new String[] { "BungeeServer", "SpigotServer" };
|
||||
for (String str : copies) {
|
||||
BungeeSettings.getInstance().getData().set(str,
|
||||
Config.getInstance().getData().getConfigurationSection(str));
|
||||
}
|
||||
|
||||
BungeeSettings.getInstance().getData().set("UseBungeecord",
|
||||
Config.getInstance().isUseBungeecoord());
|
||||
|
||||
String[] copies1 = new String[] { "BungeeBroadcastAlways", "BungeeDebug", "BungeeBroadcast" };
|
||||
for (String str : copies1) {
|
||||
BungeeSettings.getInstance().getData().set(str, Config.getInstance().getData().getBoolean(str));
|
||||
}
|
||||
|
||||
String[] copies2 = new String[] { "BungeeMethod", "Server" };
|
||||
for (String str : copies2) {
|
||||
BungeeSettings.getInstance().getData().set(str, Config.getInstance().getData().getString(str));
|
||||
}
|
||||
BungeeSettings.getInstance().saveData();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,248 +0,0 @@
|
||||
package com.Ben12345rocks.VotingPlugin.Objects;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import com.Ben12345rocks.AdvancedCore.Rewards.RewardBuilder;
|
||||
import com.Ben12345rocks.AdvancedCore.Rewards.RewardHandler;
|
||||
import com.Ben12345rocks.AdvancedCore.Util.Item.ItemBuilder;
|
||||
import com.Ben12345rocks.AdvancedCore.Util.Messages.StringParser;
|
||||
import com.Ben12345rocks.AdvancedCore.Util.Misc.ArrayUtils;
|
||||
import com.Ben12345rocks.AdvancedCore.Util.Misc.MiscUtils;
|
||||
import com.Ben12345rocks.AdvancedCore.Util.Misc.PlayerUtils;
|
||||
import com.Ben12345rocks.AdvancedCore.Util.PluginMessage.PluginMessage;
|
||||
import com.Ben12345rocks.VotingPlugin.BungeeHandler;
|
||||
import com.Ben12345rocks.VotingPlugin.Main;
|
||||
import com.Ben12345rocks.VotingPlugin.Config.BungeeSettings;
|
||||
import com.Ben12345rocks.VotingPlugin.Config.Config;
|
||||
import com.Ben12345rocks.VotingPlugin.Config.ConfigVoteSites;
|
||||
import com.Ben12345rocks.VotingPlugin.Data.ServerData;
|
||||
import com.Ben12345rocks.VotingPlugin.UserManager.UserManager;
|
||||
import com.Ben12345rocks.VotingPlugin.bungee.BungeeMethod;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
/**
|
||||
* The Class VoteSite.
|
||||
*/
|
||||
public class VoteSite {
|
||||
|
||||
/** The config. */
|
||||
static Config config = Config.getInstance();
|
||||
|
||||
/** The config vote sites. */
|
||||
static ConfigVoteSites configVoteSites = ConfigVoteSites.getInstance();
|
||||
|
||||
/** The plugin. */
|
||||
static Main plugin = Main.plugin;
|
||||
|
||||
@Setter
|
||||
private String voteURL;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
private String serviceSite;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
private String key;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
private String displayName;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
private double voteDelay;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
private double voteDelayMin;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
private double timeOffSet;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
private boolean enabled;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
private boolean voteDelayDaily;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
private int priority;
|
||||
|
||||
@Setter
|
||||
private ConfigurationSection item;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
private boolean giveOffline;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
private boolean waitUntilVoteDelay;
|
||||
|
||||
/**
|
||||
* Instantiates a new vote site.
|
||||
*
|
||||
* @param plugin
|
||||
* the plugin
|
||||
*/
|
||||
public VoteSite(Main plugin) {
|
||||
VoteSite.plugin = plugin;
|
||||
}
|
||||
|
||||
/**
|
||||
* Instantiates a new vote site.
|
||||
*
|
||||
* @param siteName
|
||||
* the site name
|
||||
*/
|
||||
public VoteSite(String siteName) {
|
||||
key = siteName.replace(".", "_");
|
||||
init();
|
||||
}
|
||||
|
||||
public void broadcastVote(User user) {
|
||||
broadcastVote(user, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Broadcast vote.
|
||||
*
|
||||
* @param user
|
||||
* the user
|
||||
* @param checkBungee
|
||||
* check bungee broadcast
|
||||
*/
|
||||
public void broadcastVote(User user, boolean checkBungee) {
|
||||
if (!user.isVanished()) {
|
||||
if (checkBungee && BungeeSettings.getInstance().isBungeeBroadcast()
|
||||
&& BungeeSettings.getInstance().isUseBungeecoord()) {
|
||||
if (BungeeHandler.getInstance().getMethod().equals(BungeeMethod.SOCKETS)) {
|
||||
BungeeHandler.getInstance().sendData("Broadcast", getServiceSite(), user.getPlayerName());
|
||||
} else if (BungeeHandler.getInstance().getMethod().equals(BungeeMethod.MYSQL)
|
||||
|| BungeeHandler.getInstance().getMethod().equals(BungeeMethod.PLUGINMESSAGING)) {
|
||||
String uuid = user.getUUID();
|
||||
String service = getServiceSite();
|
||||
|
||||
if (Bukkit.getOnlinePlayers().size() > 0) {
|
||||
PluginMessage.getInstance().sendPluginMessage(PlayerUtils.getInstance().getRandomOnlinePlayer(),
|
||||
"VoteBroadcast", uuid, service);
|
||||
}
|
||||
}
|
||||
|
||||
} else {
|
||||
String playerName = user.getPlayerName();
|
||||
if (config.getVotingBroadcastBlacklist().contains(playerName)) {
|
||||
plugin.getLogger().info("Not broadcasting for " + playerName + ", in blacklist");
|
||||
return;
|
||||
}
|
||||
String bc = StringParser.getInstance().colorize(config.getFormatBroadCastMsg());
|
||||
HashMap<String, String> placeholders = new HashMap<String, String>();
|
||||
placeholders.put("player", playerName);
|
||||
placeholders.put("nickname",
|
||||
(user.getPlayer() != null) ? user.getPlayer().getDisplayName() : user.getPlayerName());
|
||||
placeholders.put("sitename", getDisplayName());
|
||||
placeholders.put("servicesite", getServiceSite());
|
||||
bc = StringParser.getInstance().replacePlaceHolder(bc, placeholders);
|
||||
bc = StringParser.getInstance().replacePlaceHolders(user.getOfflinePlayer(), bc);
|
||||
ArrayList<Player> players = new ArrayList<Player>();
|
||||
for (Player p : Bukkit.getOnlinePlayers()) {
|
||||
if (!UserManager.getInstance().getVotingPluginUser(p).getDisableBroadcast()) {
|
||||
players.add(p);
|
||||
}
|
||||
}
|
||||
|
||||
MiscUtils.getInstance().broadcast(bc, players);
|
||||
}
|
||||
} else {
|
||||
plugin.debug(user.getPlayerName() + " is vanished, not broadcasting");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the item
|
||||
*/
|
||||
public ItemBuilder getItem() {
|
||||
if (item == null) {
|
||||
plugin.getLogger().warning("Invalid item section in site: " + key);
|
||||
return new ItemBuilder(Material.STONE, 1).setName("&cInvalid item for site: " + key)
|
||||
.setLore("&cInvalid item for site: " + key);
|
||||
} else {
|
||||
return new ItemBuilder(item);
|
||||
}
|
||||
}
|
||||
|
||||
public ConfigurationSection getSiteData() {
|
||||
return configVoteSites.getData(key);
|
||||
}
|
||||
|
||||
public String getVoteURL() {
|
||||
return getVoteURL(true);
|
||||
}
|
||||
|
||||
public String getVoteURL(boolean json) {
|
||||
if (!Config.getInstance().isFormatCommandsVoteForceLinks() || !json) {
|
||||
return voteURL;
|
||||
} else {
|
||||
if (!voteURL.startsWith("http")) {
|
||||
return "[Text=\"" + voteURL + "\",url=\"http://" + voteURL + "\"]";
|
||||
}
|
||||
return "[Text=\"" + voteURL + "\",url=\"" + voteURL + "\"]";
|
||||
}
|
||||
}
|
||||
|
||||
public void giveRewards(User user, boolean online, boolean bungee) {
|
||||
new RewardBuilder(configVoteSites.getData(), configVoteSites.getRewardsPath(key)).setOnline(online)
|
||||
.withPlaceHolder("ServiceSite", getServiceSite()).withPlaceHolder("SiteName", getDisplayName())
|
||||
.withPlaceHolder("VoteDelay", "" + getVoteDelay()).withPlaceHolder("VoteURL", getVoteURL())
|
||||
.setServer(bungee).send(user);
|
||||
|
||||
new RewardBuilder(configVoteSites.getData(), configVoteSites.getEverySiteRewardPath()).setOnline(online)
|
||||
.withPlaceHolder("ServiceSite", getServiceSite()).withPlaceHolder("SiteName", getDisplayName())
|
||||
.withPlaceHolder("VoteDelay", "" + getVoteDelay()).withPlaceHolder("VoteURL", getVoteURL())
|
||||
.setServer(bungee).send(user);
|
||||
}
|
||||
|
||||
public boolean hasRewards() {
|
||||
return RewardHandler.getInstance().hasRewards(configVoteSites.getData(), configVoteSites.getRewardsPath(key));
|
||||
}
|
||||
|
||||
/**
|
||||
* Inits the.
|
||||
*/
|
||||
public void init() {
|
||||
setVoteURL(configVoteSites.getVoteURL(key));
|
||||
setServiceSite(configVoteSites.getServiceSite(key));
|
||||
setVoteDelay(configVoteSites.getVoteDelay(key));
|
||||
setVoteDelayMin(configVoteSites.getVoteDelayMin(key));
|
||||
setEnabled(configVoteSites.getVoteSiteEnabled(key));
|
||||
setPriority(configVoteSites.getPriority(key));
|
||||
displayName = configVoteSites.getDisplayName(key);
|
||||
if (displayName == null || displayName.equals("")) {
|
||||
displayName = key;
|
||||
}
|
||||
item = configVoteSites.getItem(key);
|
||||
voteDelayDaily = configVoteSites.getVoteSiteResetVoteDelayDaily(key);
|
||||
giveOffline = configVoteSites.getVoteSiteGiveOffline(key);
|
||||
waitUntilVoteDelay = configVoteSites.getWaitUntilVoteDelay(key);
|
||||
timeOffSet = configVoteSites.getTimeOffSet(key);
|
||||
}
|
||||
|
||||
public boolean isVaidServiceSite() {
|
||||
return ArrayUtils.getInstance().containsIgnoreCase(ServerData.getInstance().getServiceSites(),
|
||||
getServiceSite());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,107 +0,0 @@
|
||||
package com.Ben12345rocks.VotingPlugin.Signs;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import org.bukkit.Location;
|
||||
|
||||
import com.Ben12345rocks.VotingPlugin.Main;
|
||||
import com.Ben12345rocks.VotingPlugin.Data.ServerData;
|
||||
|
||||
// TODO: Auto-generated Javadoc
|
||||
/**
|
||||
* The Class Signs.
|
||||
*/
|
||||
public class Signs {
|
||||
|
||||
/** The instance. */
|
||||
static Signs instance = new Signs();
|
||||
|
||||
/** The plugin. */
|
||||
static Main plugin = Main.plugin;
|
||||
|
||||
/**
|
||||
* Gets the single instance of Signs.
|
||||
*
|
||||
* @return single instance of Signs
|
||||
*/
|
||||
public static Signs getInstance() {
|
||||
return instance;
|
||||
}
|
||||
|
||||
/**
|
||||
* Instantiates a new signs.
|
||||
*/
|
||||
private Signs() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Instantiates a new signs.
|
||||
*
|
||||
* @param plugin
|
||||
* the plugin
|
||||
*/
|
||||
public Signs(Main plugin) {
|
||||
Signs.plugin = plugin;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the sign from location.
|
||||
*
|
||||
* @param loc
|
||||
* the loc
|
||||
* @return the sign from location
|
||||
*/
|
||||
public String getSignFromLocation(Location loc) {
|
||||
for (String sign : ServerData.getInstance().getSigns()) {
|
||||
if (ServerData.getInstance().getSignLocation(sign).equals(loc)) {
|
||||
return sign;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Load signs.
|
||||
*/
|
||||
public void loadSigns() {
|
||||
plugin.setSigns(new ArrayList<SignHandler>());
|
||||
for (String sign : ServerData.getInstance().getSigns()) {
|
||||
// plugin.getLogger().info("Loading sign " + sign);
|
||||
plugin.getSigns().add(new SignHandler(sign, ServerData.getInstance().getSignLocation(sign),
|
||||
ServerData.getInstance().getSignSkullLocation(sign), ServerData.getInstance().getSignData(sign),
|
||||
ServerData.getInstance().getSignPosition(sign)));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Store signs.
|
||||
*/
|
||||
public void storeSigns() {
|
||||
for (SignHandler sign : plugin.getSigns()) {
|
||||
sign.storeSign();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Update signs.
|
||||
*/
|
||||
public void updateSigns() {
|
||||
int time = 0;
|
||||
for (int i = plugin.getSigns().size() - 1; i >= 0; i--) {
|
||||
if (!plugin.getSigns().get(i).isValid()) {
|
||||
plugin.debug("Sign " + i + " invalid, removing from data: "
|
||||
+ plugin.getSigns().get(i).getLocation().toString());
|
||||
plugin.getSigns().get(i).removeSign();
|
||||
plugin.getSigns().remove(i);
|
||||
} else {
|
||||
plugin.getSigns().get(i).updateLines();
|
||||
plugin.getSigns().get(i).updateSign(time);
|
||||
time += 5;
|
||||
}
|
||||
}
|
||||
|
||||
plugin.debug("Signs updated");
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,350 +0,0 @@
|
||||
package com.Ben12345rocks.VotingPlugin.SpecialRewards;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Set;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
|
||||
import com.Ben12345rocks.AdvancedCore.Rewards.RewardBuilder;
|
||||
import com.Ben12345rocks.AdvancedCore.Rewards.RewardHandler;
|
||||
import com.Ben12345rocks.AdvancedCore.Rewards.RewardOptions;
|
||||
import com.Ben12345rocks.AdvancedCore.Util.Messages.StringParser;
|
||||
import com.Ben12345rocks.VotingPlugin.Main;
|
||||
import com.Ben12345rocks.VotingPlugin.Config.Config;
|
||||
import com.Ben12345rocks.VotingPlugin.Config.ConfigVoteSites;
|
||||
import com.Ben12345rocks.VotingPlugin.Config.SpecialRewardsConfig;
|
||||
import com.Ben12345rocks.VotingPlugin.Events.PlayerSpecialRewardEvent;
|
||||
import com.Ben12345rocks.VotingPlugin.Events.SpecialRewardType;
|
||||
import com.Ben12345rocks.VotingPlugin.Objects.User;
|
||||
import com.Ben12345rocks.VotingPlugin.TopVoter.TopVoter;
|
||||
|
||||
// TODO: Auto-generated Javadoc
|
||||
/**
|
||||
* The Class OtherVoteReward.
|
||||
*/
|
||||
public class SpecialRewards {
|
||||
|
||||
/** The config. */
|
||||
static Config config = Config.getInstance();
|
||||
|
||||
/** The config vote sites. */
|
||||
static ConfigVoteSites configVoteSites = ConfigVoteSites.getInstance();
|
||||
|
||||
/** The instance. */
|
||||
static SpecialRewards instance = new SpecialRewards();
|
||||
|
||||
/** The plugin. */
|
||||
static Main plugin = Main.plugin;
|
||||
|
||||
/**
|
||||
* Gets the single instance of OtherVoteReward.
|
||||
*
|
||||
* @return single instance of OtherVoteReward
|
||||
*/
|
||||
public static SpecialRewards getInstance() {
|
||||
return instance;
|
||||
}
|
||||
|
||||
/**
|
||||
* Instantiates a new other vote reward.
|
||||
*/
|
||||
private SpecialRewards() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Instantiates a new other vote reward.
|
||||
*
|
||||
* @param plugin
|
||||
* the plugin
|
||||
*/
|
||||
public SpecialRewards(Main plugin) {
|
||||
SpecialRewards.plugin = plugin;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check all sites.
|
||||
*
|
||||
* @param user
|
||||
* the user
|
||||
* @return true, if successful
|
||||
*/
|
||||
public boolean checkAllSites(User user) {
|
||||
boolean checkAllVotes = user.checkAllVotes();
|
||||
if (checkAllVotes) {
|
||||
giveAllSitesRewards(user, user.isOnline());
|
||||
}
|
||||
return checkAllVotes;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check cumualative votes.
|
||||
*
|
||||
* @param user
|
||||
* the user
|
||||
* @return true, if successful
|
||||
*/
|
||||
public boolean checkCumualativeVotes(User user) {
|
||||
boolean gotCumulative = false;
|
||||
Set<String> votes = SpecialRewardsConfig.getInstance().getCumulativeVotes();
|
||||
for (String vote : votes) {
|
||||
if (StringParser.getInstance().isInt(vote)) {
|
||||
int votesRequired = Integer.parseInt(vote);
|
||||
if (votesRequired != 0) {
|
||||
if (SpecialRewardsConfig.getInstance().getCumulativeRewardEnabled(votesRequired)
|
||||
&& RewardHandler.getInstance().hasRewards(SpecialRewardsConfig.getInstance().getData(),
|
||||
SpecialRewardsConfig.getInstance().getCumulativeRewardsPath(votesRequired))) {
|
||||
int total = 0;
|
||||
if (SpecialRewardsConfig.getInstance().getCumulativeVotesInSameDay(votesRequired)) {
|
||||
total = user.getTotal(TopVoter.Daily);
|
||||
} else if (SpecialRewardsConfig.getInstance().getCumulativeVotesInSameWeek(votesRequired)) {
|
||||
total = user.getTotal(TopVoter.Weekly);
|
||||
} else if (SpecialRewardsConfig.getInstance().getCumulativeVotesInSameMonth(votesRequired)) {
|
||||
total = user.getTotal(TopVoter.Monthly);
|
||||
} else {
|
||||
total = user.getTotal(TopVoter.AllTime);
|
||||
}
|
||||
|
||||
if ((total % votesRequired) == 0 && total != 0) {
|
||||
giveCumulativeVoteReward(user, user.isOnline(), votesRequired);
|
||||
gotCumulative = true;
|
||||
}
|
||||
|
||||
if (gotCumulative) {
|
||||
plugin.debug(user.getPlayerName() + " got cumulative " + votesRequired);
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
plugin.debug("Invalid cumulative number: " + vote);
|
||||
}
|
||||
}
|
||||
return gotCumulative;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check first vote.
|
||||
*
|
||||
* @param user
|
||||
* the user
|
||||
* @return true, if successful
|
||||
*/
|
||||
public boolean checkFirstVote(User user) {
|
||||
if (RewardHandler.getInstance().hasRewards(SpecialRewardsConfig.getInstance().getData(),
|
||||
SpecialRewardsConfig.getInstance().getFirstVoteRewardsPath())) {
|
||||
if (!user.hasGottenFirstVote()) {
|
||||
giveFirstVoteRewards(user, user.isOnline());
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check milestone.
|
||||
*
|
||||
* @param user
|
||||
* the user
|
||||
* @return true, if successful
|
||||
*/
|
||||
public boolean checkMilestone(User user) {
|
||||
if (Config.getInstance().isPreventRepeatMilestones()) {
|
||||
ArrayList<Integer> nums = new ArrayList<Integer>();
|
||||
|
||||
for (String str : SpecialRewardsConfig.getInstance().getMilestoneVotes()) {
|
||||
try {
|
||||
nums.add(Integer.parseInt(str));
|
||||
} catch (Exception e) {
|
||||
plugin.getLogger().warning("Failed to get number from " + str);
|
||||
}
|
||||
}
|
||||
|
||||
int milestoneCount = user.getMilestoneCount();
|
||||
for (int num : nums) {
|
||||
if (milestoneCount >= num) {
|
||||
if (!user.hasGottenMilestone(num)) {
|
||||
plugin.getLogger().info("Milestone " + num + " for " + user.getPlayerName()
|
||||
+ " not already given when it should be, Current AllTimeTotal: "
|
||||
+ user.getTotal(TopVoter.AllTime) + ", Current MileStoneCount: "
|
||||
+ user.getMilestoneCount());
|
||||
user.setHasGotteMilestone(num, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
boolean gotMilestone = false;
|
||||
Set<String> votes = SpecialRewardsConfig.getInstance().getMilestoneVotes();
|
||||
for (String vote : votes) {
|
||||
if (StringParser.getInstance().isInt(vote)) {
|
||||
int votesRequired = Integer.parseInt(vote);
|
||||
if (votesRequired != 0) {
|
||||
if (SpecialRewardsConfig.getInstance().getMilestoneRewardEnabled(votesRequired)
|
||||
&& RewardHandler.getInstance().hasRewards(SpecialRewardsConfig.getInstance().getData(),
|
||||
SpecialRewardsConfig.getInstance().getMilestoneRewardsPath(votesRequired))) {
|
||||
|
||||
int userVotesTotal = user.getMilestoneCount();
|
||||
if (userVotesTotal >= votesRequired && !user.hasGottenMilestone(votesRequired)) {
|
||||
giveMilestoneVoteReward(user, user.isOnline(), votesRequired);
|
||||
user.setHasGotteMilestone(votesRequired, true);
|
||||
plugin.debug(user.getPlayerName() + " got milestone " + votesRequired);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
plugin.debug("Invalid milestone number: " + vote);
|
||||
}
|
||||
}
|
||||
return gotMilestone;
|
||||
}
|
||||
|
||||
public boolean checkVoteStreak(User user, String type) {
|
||||
boolean gotReward = false;
|
||||
|
||||
Set<String> streaks = SpecialRewardsConfig.getInstance().getVoteStreakVotes(type);
|
||||
for (String streak : streaks) {
|
||||
String s = streak.replaceAll("-", "");
|
||||
boolean multiple = false;
|
||||
if (streak.contains("-")) {
|
||||
// multiple
|
||||
multiple = true;
|
||||
}
|
||||
if (StringParser.getInstance().isInt(s)) {
|
||||
int streakRequired = Integer.parseInt(s);
|
||||
if (streakRequired != 0) {
|
||||
if (SpecialRewardsConfig.getInstance().getVoteStreakRewardEnabled(type, streak)
|
||||
&& RewardHandler.getInstance().hasRewards(SpecialRewardsConfig.getInstance().getData(),
|
||||
SpecialRewardsConfig.getInstance().getVoteStreakRewardsPath(type, "" + streak))) {
|
||||
int curStreak = 0;
|
||||
if (type.equalsIgnoreCase("day")) {
|
||||
curStreak = user.getDayVoteStreak();
|
||||
} else if (type.equalsIgnoreCase("week")) {
|
||||
curStreak = user.getWeekVoteStreak();
|
||||
} else if (type.equalsIgnoreCase("month")) {
|
||||
curStreak = user.getMonthVoteStreak();
|
||||
}
|
||||
if (!multiple) {
|
||||
if (curStreak == streakRequired) {
|
||||
giveVoteStreakReward(user, user.isOnline(), type, "" + streakRequired, curStreak);
|
||||
gotReward = true;
|
||||
plugin.debug(
|
||||
user.getPlayerName() + " got VoteStreak " + streakRequired + " for " + type);
|
||||
}
|
||||
} else {
|
||||
if (curStreak != 0 && curStreak % streakRequired == 0) {
|
||||
giveVoteStreakReward(user, user.isOnline(), type, streakRequired + "-", curStreak);
|
||||
gotReward = true;
|
||||
plugin.debug(
|
||||
user.getPlayerName() + " got VoteStreak " + streakRequired + "* for " + type);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return gotReward;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Give all sites rewards.
|
||||
*
|
||||
* @param user
|
||||
* the user
|
||||
* @param online
|
||||
* the online
|
||||
*/
|
||||
public void giveAllSitesRewards(User user, boolean online) {
|
||||
PlayerSpecialRewardEvent event = new PlayerSpecialRewardEvent(user, SpecialRewardType.ALLSITE);
|
||||
Bukkit.getPluginManager().callEvent(event);
|
||||
|
||||
if (event.isCancelled()) {
|
||||
return;
|
||||
}
|
||||
RewardHandler.getInstance().giveReward(user, SpecialRewardsConfig.getInstance().getData(),
|
||||
SpecialRewardsConfig.getInstance().getAllSitesRewardPath(), new RewardOptions().setOnline(online));
|
||||
}
|
||||
|
||||
/**
|
||||
* Give cumulative vote reward.
|
||||
*
|
||||
* @param user
|
||||
* the user
|
||||
* @param online
|
||||
* the online
|
||||
* @param cumulative
|
||||
* the cumulative
|
||||
*/
|
||||
public void giveCumulativeVoteReward(User user, boolean online, int cumulative) {
|
||||
PlayerSpecialRewardEvent event = new PlayerSpecialRewardEvent(user,
|
||||
SpecialRewardType.CUMMULATIVE.setAmount(cumulative));
|
||||
Bukkit.getPluginManager().callEvent(event);
|
||||
|
||||
if (event.isCancelled()) {
|
||||
return;
|
||||
}
|
||||
|
||||
new RewardBuilder(SpecialRewardsConfig.getInstance().getData(),
|
||||
SpecialRewardsConfig.getInstance().getCumulativeRewardsPath(cumulative)).setOnline(online)
|
||||
.withPlaceHolder("Cumulative", "" + cumulative).send(user);
|
||||
}
|
||||
|
||||
/**
|
||||
* Give first vote rewards.
|
||||
*
|
||||
* @param user
|
||||
* the user
|
||||
* @param online
|
||||
* the online
|
||||
*/
|
||||
public void giveFirstVoteRewards(User user, boolean online) {
|
||||
PlayerSpecialRewardEvent event = new PlayerSpecialRewardEvent(user, SpecialRewardType.FIRSTVOTE);
|
||||
Bukkit.getPluginManager().callEvent(event);
|
||||
|
||||
if (event.isCancelled()) {
|
||||
return;
|
||||
}
|
||||
RewardHandler.getInstance().giveReward(user, SpecialRewardsConfig.getInstance().getData(),
|
||||
SpecialRewardsConfig.getInstance().getFirstVoteRewardsPath(), new RewardOptions().setOnline(online));
|
||||
}
|
||||
|
||||
/**
|
||||
* Give milestone vote reward.
|
||||
*
|
||||
* @param user
|
||||
* the user
|
||||
* @param online
|
||||
* the online
|
||||
* @param milestone
|
||||
* the milestone
|
||||
*/
|
||||
public void giveMilestoneVoteReward(User user, boolean online, int milestone) {
|
||||
PlayerSpecialRewardEvent event = new PlayerSpecialRewardEvent(user,
|
||||
SpecialRewardType.MILESTONE.setAmount(milestone));
|
||||
Bukkit.getPluginManager().callEvent(event);
|
||||
|
||||
if (event.isCancelled()) {
|
||||
return;
|
||||
}
|
||||
new RewardBuilder(SpecialRewardsConfig.getInstance().getData(),
|
||||
SpecialRewardsConfig.getInstance().getMilestoneRewardsPath(milestone)).setOnline(online)
|
||||
.withPlaceHolder("Milestone", "" + milestone).send(user);
|
||||
}
|
||||
|
||||
public void giveVoteStreakReward(User user, boolean online, String type, String string, int votes) {
|
||||
PlayerSpecialRewardEvent event = new PlayerSpecialRewardEvent(user,
|
||||
SpecialRewardType.VOTESTREAK.setType(type).setAmount(votes));
|
||||
Bukkit.getPluginManager().callEvent(event);
|
||||
|
||||
if (event.isCancelled()) {
|
||||
return;
|
||||
}
|
||||
new RewardBuilder(SpecialRewardsConfig.getInstance().getData(),
|
||||
SpecialRewardsConfig.getInstance().getVoteStreakRewardsPath(type, string)).setOnline(online)
|
||||
.withPlaceHolder("Type", type).withPlaceHolder("Streak", "" + votes).send(user);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,125 +0,0 @@
|
||||
package com.Ben12345rocks.VotingPlugin.Updater;
|
||||
|
||||
import java.util.Timer;
|
||||
import java.util.TimerTask;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
|
||||
import com.Ben12345rocks.AdvancedCore.Util.Updater.Updater;
|
||||
import com.Ben12345rocks.VotingPlugin.Main;
|
||||
import com.Ben12345rocks.VotingPlugin.Config.Config;
|
||||
|
||||
// TODO: Auto-generated Javadoc
|
||||
/**
|
||||
* The Class CheckUpdate.
|
||||
*/
|
||||
public class CheckUpdate {
|
||||
|
||||
/** The instance. */
|
||||
static CheckUpdate instance = new CheckUpdate();
|
||||
|
||||
/** The plugin. */
|
||||
static Main plugin = Main.plugin;
|
||||
|
||||
/**
|
||||
* Gets the single instance of CheckUpdate.
|
||||
*
|
||||
* @return single instance of CheckUpdate
|
||||
*/
|
||||
public static CheckUpdate getInstance() {
|
||||
return instance;
|
||||
}
|
||||
|
||||
/**
|
||||
* Instantiates a new check update.
|
||||
*/
|
||||
private CheckUpdate() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Instantiates a new check update.
|
||||
*
|
||||
* @param plugin
|
||||
* the plugin
|
||||
*/
|
||||
public CheckUpdate(Main plugin) {
|
||||
CheckUpdate.plugin = plugin;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check update.
|
||||
*/
|
||||
public void checkUpdate() {
|
||||
if (Config.getInstance().isDisableUpdateChecking()) {
|
||||
return;
|
||||
}
|
||||
plugin.setUpdater(new Updater(plugin, 15358, false));
|
||||
final Updater.UpdateResult result = plugin.getUpdater().getResult();
|
||||
switch (result) {
|
||||
case FAIL_SPIGOT: {
|
||||
plugin.getLogger().info("Failed to check for update for " + plugin.getName() + "!");
|
||||
break;
|
||||
}
|
||||
case NO_UPDATE: {
|
||||
plugin.getLogger()
|
||||
.info(plugin.getName() + " is up to date! Version: " + plugin.getUpdater().getVersion());
|
||||
break;
|
||||
}
|
||||
case UPDATE_AVAILABLE: {
|
||||
plugin.getLogger()
|
||||
.info(plugin.getName() + " has an update available! Your Version: "
|
||||
+ plugin.getDescription().getVersion() + " New Version: "
|
||||
+ plugin.getUpdater().getVersion() + " Use /av download to get the latest update!");
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void checkUpdateBasic() {
|
||||
if (Config.getInstance().isDisableUpdateChecking()) {
|
||||
return;
|
||||
}
|
||||
plugin.setUpdater(new Updater(plugin, 15358, false));
|
||||
final Updater.UpdateResult result = plugin.getUpdater().getResult();
|
||||
switch (result) {
|
||||
case UPDATE_AVAILABLE: {
|
||||
plugin.getLogger()
|
||||
.info(plugin.getName() + " has an update available! Your Version: "
|
||||
+ plugin.getDescription().getVersion() + " New Version: "
|
||||
+ plugin.getUpdater().getVersion() + " Use /av download to get the latest update!");
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Start up.
|
||||
*/
|
||||
public void startUp() {
|
||||
if (Config.getInstance().isDisableUpdateChecking()) {
|
||||
return;
|
||||
}
|
||||
Bukkit.getScheduler().runTaskLaterAsynchronously(plugin, new Runnable() {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
checkUpdate();
|
||||
new Timer().schedule(new TimerTask() {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
checkUpdateBasic();
|
||||
}
|
||||
}, 1000 * 60 * 1200, 1000 * 60 * 1200);
|
||||
|
||||
}
|
||||
}, 10l);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,60 +0,0 @@
|
||||
package com.Ben12345rocks.VotingPlugin.UserManager;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import com.Ben12345rocks.AdvancedCore.UserManager.UUID;
|
||||
import com.Ben12345rocks.VotingPlugin.Main;
|
||||
import com.Ben12345rocks.VotingPlugin.Objects.User;
|
||||
|
||||
public class UserManager {
|
||||
/** The instance. */
|
||||
static UserManager instance = new UserManager();
|
||||
/** The plugin. */
|
||||
static Main plugin = Main.plugin;
|
||||
|
||||
/**
|
||||
* Gets the single instance of UserManager.
|
||||
*
|
||||
* @return single instance of UserManager
|
||||
*/
|
||||
public static UserManager getInstance() {
|
||||
return instance;
|
||||
}
|
||||
|
||||
public UserManager() {
|
||||
super();
|
||||
}
|
||||
|
||||
public ArrayList<String> getAllUUIDs() {
|
||||
return com.Ben12345rocks.AdvancedCore.UserManager.UserManager.getInstance().getAllUUIDs();
|
||||
}
|
||||
|
||||
public User getVotingPluginUser(com.Ben12345rocks.AdvancedCore.UserManager.User user) {
|
||||
return getVotingPluginUser(java.util.UUID.fromString(user.getUUID()));
|
||||
}
|
||||
|
||||
public User getVotingPluginUser(java.util.UUID uuid) {
|
||||
return getVotingPluginUser(new UUID(uuid.toString()));
|
||||
}
|
||||
|
||||
public User getVotingPluginUser(OfflinePlayer player) {
|
||||
return getVotingPluginUser(player.getName());
|
||||
}
|
||||
|
||||
public User getVotingPluginUser(Player player) {
|
||||
return getVotingPluginUser(player.getName());
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
public User getVotingPluginUser(String playerName) {
|
||||
return new User(com.Ben12345rocks.AdvancedCore.UserManager.UserManager.getInstance().getProperName(playerName));
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
public User getVotingPluginUser(UUID uuid) {
|
||||
return new User(uuid);
|
||||
}
|
||||
}
|
||||
-88
@@ -1,88 +0,0 @@
|
||||
package com.Ben12345rocks.VotingPlugin.Util.PlaceHolders;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
|
||||
import com.Ben12345rocks.AdvancedCore.Util.Placeholder.PlaceHolder;
|
||||
import com.Ben12345rocks.VotingPlugin.Main;
|
||||
import com.Ben12345rocks.VotingPlugin.Objects.User;
|
||||
import com.Ben12345rocks.VotingPlugin.UserManager.UserManager;
|
||||
|
||||
import be.maximvdw.placeholderapi.PlaceholderAPI;
|
||||
import be.maximvdw.placeholderapi.PlaceholderReplaceEvent;
|
||||
import be.maximvdw.placeholderapi.PlaceholderReplacer;
|
||||
|
||||
// TODO: Auto-generated Javadoc
|
||||
/**
|
||||
* The Class PlaceHolders.
|
||||
*/
|
||||
public class MVdWPlaceholders {
|
||||
|
||||
/** The instance. */
|
||||
static MVdWPlaceholders instance = new MVdWPlaceholders();
|
||||
|
||||
/** The plugin. */
|
||||
static Main plugin = Main.plugin;
|
||||
|
||||
/**
|
||||
* Gets the single instance of PlaceHolders.
|
||||
*
|
||||
* @return single instance of PlaceHolders
|
||||
*/
|
||||
public static MVdWPlaceholders getInstance() {
|
||||
return instance;
|
||||
}
|
||||
|
||||
/**
|
||||
* Instantiates a new place holders.
|
||||
*/
|
||||
private MVdWPlaceholders() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Instantiates a new place holders.
|
||||
*
|
||||
* @param plugin
|
||||
* the plugin
|
||||
*/
|
||||
public MVdWPlaceholders(Main plugin) {
|
||||
MVdWPlaceholders.plugin = plugin;
|
||||
}
|
||||
|
||||
public void loadMVdWPlaceholders() {
|
||||
if (Bukkit.getPluginManager().isPluginEnabled("MVdWPlaceholderAPI")) {
|
||||
// The plugin is enabled
|
||||
for (final PlaceHolder<User> place : PlaceHolders.getInstance().getPlaceholders()) {
|
||||
String str = place.getIdentifier();
|
||||
if (!str.endsWith("_")) {
|
||||
PlaceholderAPI.registerPlaceholder(Main.plugin, "VotingPlugin_" + str, new PlaceholderReplacer() {
|
||||
|
||||
@Override
|
||||
public String onPlaceholderReplace(PlaceholderReplaceEvent event) {
|
||||
return place.placeholderRequest(event.getOfflinePlayer(),
|
||||
UserManager.getInstance().getVotingPluginUser(event.getOfflinePlayer()),
|
||||
event.getPlaceholder().substring("VotingPlugin_".length()));
|
||||
}
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
for (final PlaceHolder<User> place : PlaceHolders.getInstance().getNonPlayerPlaceholders()) {
|
||||
String str = place.getIdentifier();
|
||||
if (!str.endsWith("_")) {
|
||||
PlaceholderAPI.registerPlaceholder(Main.plugin, "VotingPlugin_" + str, new PlaceholderReplacer() {
|
||||
|
||||
@Override
|
||||
public String onPlaceholderReplace(PlaceholderReplaceEvent event) {
|
||||
return place.placeholderRequest(event.getOfflinePlayer(), null,
|
||||
event.getPlaceholder().substring("VotingPlugin_".length()));
|
||||
}
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,578 +0,0 @@
|
||||
package com.Ben12345rocks.VotingPlugin.Util.PlaceHolders;
|
||||
|
||||
import java.text.NumberFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.Locale;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import com.Ben12345rocks.AdvancedCore.Util.Messages.StringParser;
|
||||
import com.Ben12345rocks.AdvancedCore.Util.Placeholder.PlaceHolder;
|
||||
import com.Ben12345rocks.VotingPlugin.Main;
|
||||
import com.Ben12345rocks.VotingPlugin.Commands.Commands;
|
||||
import com.Ben12345rocks.VotingPlugin.Config.Config;
|
||||
import com.Ben12345rocks.VotingPlugin.Objects.User;
|
||||
import com.Ben12345rocks.VotingPlugin.Objects.VoteSite;
|
||||
import com.Ben12345rocks.VotingPlugin.TopVoter.TopVoter;
|
||||
import com.Ben12345rocks.VotingPlugin.UserManager.UserManager;
|
||||
import com.Ben12345rocks.VotingPlugin.VoteParty.VoteParty;
|
||||
|
||||
import lombok.Getter;
|
||||
|
||||
// TODO: Auto-generated Javadoc
|
||||
/**
|
||||
* The Class PlaceHolders.
|
||||
*/
|
||||
public class PlaceHolders {
|
||||
|
||||
/** The instance. */
|
||||
static PlaceHolders instance = new PlaceHolders();
|
||||
|
||||
/** The plugin. */
|
||||
static Main plugin = Main.plugin;
|
||||
|
||||
/**
|
||||
* Gets the single instance of PlaceHolders.
|
||||
*
|
||||
* @return single instance of PlaceHolders
|
||||
*/
|
||||
public static PlaceHolders getInstance() {
|
||||
return instance;
|
||||
}
|
||||
|
||||
@Getter
|
||||
private ArrayList<PlaceHolder<User>> placeholders = new ArrayList<PlaceHolder<User>>();
|
||||
|
||||
@Getter
|
||||
private ArrayList<PlaceHolder<User>> nonPlayerPlaceholders = new ArrayList<PlaceHolder<User>>();
|
||||
|
||||
/**
|
||||
* Instantiates a new place holders.
|
||||
*/
|
||||
private PlaceHolders() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Instantiates a new place holders.
|
||||
*
|
||||
* @param plugin
|
||||
* the plugin
|
||||
*/
|
||||
public PlaceHolders(Main plugin) {
|
||||
PlaceHolders.plugin = plugin;
|
||||
}
|
||||
|
||||
public String getPlaceHolder(OfflinePlayer p, String identifier) {
|
||||
if (Config.getInstance().isUseJavascriptPlaceholders()) {
|
||||
identifier = StringParser.getInstance().replaceJavascript(p, identifier);
|
||||
}
|
||||
|
||||
for (PlaceHolder<User> placeholder : nonPlayerPlaceholders) {
|
||||
if (placeholder.matches(identifier)) {
|
||||
return placeholder.placeholderRequest(p, null, identifier);
|
||||
}
|
||||
}
|
||||
|
||||
User user = UserManager.getInstance().getVotingPluginUser(p);
|
||||
|
||||
for (PlaceHolder<User> placeholder : placeholders) {
|
||||
if (placeholder.matches(identifier)) {
|
||||
return placeholder.placeholderRequest(p, user, identifier);
|
||||
}
|
||||
}
|
||||
|
||||
return "Not a valid placeholder";
|
||||
}
|
||||
|
||||
public String getPlaceHolder(Player p, String identifier) {
|
||||
if (Config.getInstance().isUseJavascriptPlaceholders()) {
|
||||
identifier = StringParser.getInstance().replaceJavascript(p, identifier);
|
||||
}
|
||||
return getPlaceHolder((OfflinePlayer) p, identifier);
|
||||
}
|
||||
|
||||
public void load() {
|
||||
placeholders.clear();
|
||||
nonPlayerPlaceholders.clear();
|
||||
|
||||
// older placeholders, might be removed in the future
|
||||
placeholders.add(new PlaceHolder<User>("total") {
|
||||
|
||||
@Override
|
||||
public String placeholderRequest(OfflinePlayer p, User user, String identifier) {
|
||||
return Integer.toString(user.getTotal(TopVoter.Monthly));
|
||||
}
|
||||
}.withDescription("Month total"));
|
||||
|
||||
placeholders.add(new PlaceHolder<User>("alltimetotal") {
|
||||
|
||||
@Override
|
||||
public String placeholderRequest(OfflinePlayer p, User user, String identifier) {
|
||||
return Integer.toString(user.getTotal(TopVoter.AllTime));
|
||||
}
|
||||
}.withDescription("Alltime total"));
|
||||
|
||||
placeholders.add(new PlaceHolder<User>("lastmonthtotal") {
|
||||
|
||||
@Override
|
||||
public String placeholderRequest(OfflinePlayer p, User user, String identifier) {
|
||||
return Integer.toString(user.getLastMonthTotal());
|
||||
}
|
||||
}.withDescription("Last month total"));
|
||||
|
||||
// end of older placeholders
|
||||
|
||||
placeholders.add(new PlaceHolder<User>("DisableBroadcast") {
|
||||
|
||||
@Override
|
||||
public String placeholderRequest(OfflinePlayer p, User user, String identifier) {
|
||||
return "" + user.getDisableBroadcast();
|
||||
}
|
||||
}.withDescription("Returns true/false if user has broadcast disabled"));
|
||||
|
||||
placeholders.add(new PlaceHolder<User>("MilestoneCount") {
|
||||
|
||||
@Override
|
||||
public String placeholderRequest(OfflinePlayer p, User user, String identifier) {
|
||||
return "" + user.getMilestoneCount();
|
||||
}
|
||||
}.withDescription("User milestonecount"));
|
||||
|
||||
for (final String identifier : Config.getInstance().getIdentifiers()) {
|
||||
if (Config.getInstance().getIdentifierLimit(identifier) > 0) {
|
||||
placeholders.add(new PlaceHolder<User>("VoteShopLimit_" + identifier) {
|
||||
|
||||
@Override
|
||||
public String placeholderRequest(OfflinePlayer p, User user, String ident) {
|
||||
return "" + user.getVoteShopIdentifierLimit(identifier);
|
||||
}
|
||||
}.withDescription("User voteshop limit for " + identifier));
|
||||
}
|
||||
}
|
||||
|
||||
for (final TopVoter top : TopVoter.values()) {
|
||||
placeholders.add(new PlaceHolder<User>("Total_" + top.toString()) {
|
||||
|
||||
@Override
|
||||
public String placeholderRequest(OfflinePlayer p, User user, String identifier) {
|
||||
return Integer.toString(user.getTotal(top));
|
||||
}
|
||||
}.withDescription("User total for " + top.getName()));
|
||||
}
|
||||
|
||||
placeholders.add(new PlaceHolder<User>("BestDailyTotal") {
|
||||
|
||||
@Override
|
||||
public String placeholderRequest(OfflinePlayer p, User user, String identifier) {
|
||||
return Integer.toString(user.getHighestDailyTotal());
|
||||
}
|
||||
}.withDescription("Best daily total"));
|
||||
|
||||
placeholders.add(new PlaceHolder<User>("BestWeeklyTotal") {
|
||||
|
||||
@Override
|
||||
public String placeholderRequest(OfflinePlayer p, User user, String identifier) {
|
||||
return Integer.toString(user.getHighestWeeklyTotal());
|
||||
}
|
||||
}.withDescription("Best weekly total"));
|
||||
|
||||
placeholders.add(new PlaceHolder<User>("BestMonthlyTotal") {
|
||||
|
||||
@Override
|
||||
public String placeholderRequest(OfflinePlayer p, User user, String identifier) {
|
||||
return Integer.toString(user.getHighestMonthlyTotal());
|
||||
}
|
||||
}.withDescription("Best monthly total"));
|
||||
|
||||
placeholders.add(new PlaceHolder<User>("DailyVoteStreak") {
|
||||
|
||||
@Override
|
||||
public String placeholderRequest(OfflinePlayer p, User user, String identifier) {
|
||||
return Integer.toString(user.getDayVoteStreak());
|
||||
}
|
||||
}.withDescription("Current daily votestreak"));
|
||||
|
||||
placeholders.add(new PlaceHolder<User>("WeeklyVoteStreak") {
|
||||
|
||||
@Override
|
||||
public String placeholderRequest(OfflinePlayer p, User user, String identifier) {
|
||||
return Integer.toString(user.getWeekVoteStreak());
|
||||
}
|
||||
}.withDescription("Current weekly votestreak"));
|
||||
|
||||
placeholders.add(new PlaceHolder<User>("MonthVoteStreak") {
|
||||
|
||||
@Override
|
||||
public String placeholderRequest(OfflinePlayer p, User user, String identifier) {
|
||||
return Integer.toString(user.getMonthVoteStreak());
|
||||
}
|
||||
}.withDescription("Current month votestreak"));
|
||||
|
||||
placeholders.add(new PlaceHolder<User>("BestDailyVoteStreak") {
|
||||
|
||||
@Override
|
||||
public String placeholderRequest(OfflinePlayer p, User user, String identifier) {
|
||||
return Integer.toString(user.getBestDayVoteStreak());
|
||||
}
|
||||
}.withDescription("Best daily votestreak"));
|
||||
|
||||
placeholders.add(new PlaceHolder<User>("BestWeeklyVoteStreak") {
|
||||
|
||||
@Override
|
||||
public String placeholderRequest(OfflinePlayer p, User user, String identifier) {
|
||||
return Integer.toString(user.getBestWeekVoteStreak());
|
||||
}
|
||||
}.withDescription("Best weekly votestreak"));
|
||||
|
||||
placeholders.add(new PlaceHolder<User>("BestMonthVoteStreak") {
|
||||
|
||||
@Override
|
||||
public String placeholderRequest(OfflinePlayer p, User user, String identifier) {
|
||||
return Integer.toString(user.getBestMonthVoteStreak());
|
||||
}
|
||||
}.withDescription("Best month votestreak"));
|
||||
|
||||
placeholders.add(new PlaceHolder<User>("Points") {
|
||||
|
||||
@Override
|
||||
public String placeholderRequest(OfflinePlayer p, User user, String identifier) {
|
||||
return Integer.toString(user.getPoints());
|
||||
}
|
||||
}.withDescription("User points"));
|
||||
|
||||
placeholders.add(new PlaceHolder<User>("Points_Format") {
|
||||
|
||||
@Override
|
||||
public String placeholderRequest(OfflinePlayer p, User user, String identifier) {
|
||||
NumberFormat numberFormat = NumberFormat.getNumberInstance(Locale.US);
|
||||
return numberFormat.format(user.getPoints());
|
||||
}
|
||||
}.withDescription("User points"));
|
||||
|
||||
placeholders.add(new PlaceHolder<User>("CanVote") {
|
||||
|
||||
@Override
|
||||
public String placeholderRequest(OfflinePlayer p, User user, String identifier) {
|
||||
return Boolean.toString(user.canVoteAll());
|
||||
}
|
||||
}.withDescription("Return true/false if player can vote on all sites"));
|
||||
|
||||
placeholders.add(new PlaceHolder<User>("Next_AnySite") {
|
||||
|
||||
@Override
|
||||
public String placeholderRequest(OfflinePlayer p, User user, String identifier) {
|
||||
if (user.canVoteAny()) {
|
||||
return Config.getInstance().getFormatCommandsVoteNextInfoCanVote();
|
||||
}
|
||||
long smallest = -1;
|
||||
HashMap<Long, VoteSite> times = new HashMap<Long, VoteSite>();
|
||||
for (VoteSite site : plugin.getVoteSites()) {
|
||||
long t = Commands.getInstance().voteNextDurationTime(user, site);
|
||||
if (smallest == -1) {
|
||||
smallest = t;
|
||||
}
|
||||
if (t < smallest) {
|
||||
smallest = t;
|
||||
}
|
||||
times.put(t, site);
|
||||
}
|
||||
for (Entry<Long, VoteSite> entry : times.entrySet()) {
|
||||
if (entry.getKey().longValue() == smallest) {
|
||||
return Commands.getInstance().voteCommandNextInfo(user, entry.getValue());
|
||||
}
|
||||
}
|
||||
|
||||
return "Error";
|
||||
}
|
||||
}.withDescription("How long until user can vote on anysite"));
|
||||
|
||||
for (final VoteSite voteSite : plugin.getVoteSites()) {
|
||||
placeholders.add(new PlaceHolder<User>("Next_" + voteSite.getKey()) {
|
||||
|
||||
@Override
|
||||
public String placeholderRequest(OfflinePlayer p, User user, String identifier) {
|
||||
return Commands.getInstance().voteCommandNextInfo(user, voteSite);
|
||||
}
|
||||
}.withDescription("How long until user can vote on " + voteSite.getKey()));
|
||||
placeholders.add(new PlaceHolder<User>("Last_" + voteSite.getKey()) {
|
||||
|
||||
@Override
|
||||
public String placeholderRequest(OfflinePlayer p, User user, String identifier) {
|
||||
return Commands.getInstance().voteCommandLastDuration(user, voteSite);
|
||||
}
|
||||
}.withDescription("How long ago user voted on " + voteSite.getKey()));
|
||||
placeholders.add(new PlaceHolder<User>("CanVote_" + voteSite.getKey()) {
|
||||
|
||||
@Override
|
||||
public String placeholderRequest(OfflinePlayer p, User user, String identifier) {
|
||||
return "" + user.canVoteSite(voteSite);
|
||||
}
|
||||
}.withDescription("Whether or not player can vote on " + voteSite.getKey()));
|
||||
}
|
||||
|
||||
placeholders.add(new PlaceHolder<User>("Top_All_Position") {
|
||||
|
||||
@Override
|
||||
public String placeholderRequest(OfflinePlayer p, User user, String identifier) {
|
||||
int num = 1;
|
||||
for (Entry<User, Integer> entry : plugin.getTopVoter(TopVoter.AllTime).entrySet()) {
|
||||
if (entry.getKey().getUUID().equals(p.getUniqueId().toString())) {
|
||||
return "" + num;
|
||||
}
|
||||
num++;
|
||||
}
|
||||
return "";
|
||||
}
|
||||
}.withDescription("Get user top voter position"));
|
||||
|
||||
placeholders.add(new PlaceHolder<User>("Top_AllVotes_") {
|
||||
|
||||
@Override
|
||||
public String placeholderRequest(OfflinePlayer p, User user, String identifier) {
|
||||
int num = 1;
|
||||
int number = Integer.parseInt(identifier.split("_")[2]);
|
||||
for (Entry<User, Integer> entry : plugin.getTopVoter(TopVoter.AllTime).entrySet()) {
|
||||
if (num == number) {
|
||||
return "" + entry.getKey().getTotal(TopVoter.AllTime);
|
||||
}
|
||||
num++;
|
||||
}
|
||||
return "";
|
||||
}
|
||||
}.useStartsWith().withDescription("Get user votes at position in top voter"));
|
||||
|
||||
placeholders.add(new PlaceHolder<User>("Top_All_") {
|
||||
|
||||
@Override
|
||||
public String placeholderRequest(OfflinePlayer p, User user, String identifier) {
|
||||
int num = 1;
|
||||
int number = Integer.parseInt(identifier.split("_")[2]);
|
||||
for (Entry<User, Integer> entry : plugin.getTopVoter(TopVoter.AllTime).entrySet()) {
|
||||
if (num == number) {
|
||||
return entry.getKey().getPlayerName();
|
||||
}
|
||||
num++;
|
||||
}
|
||||
return "";
|
||||
}
|
||||
}.useStartsWith().withDescription("Get user at postion in top voter"));
|
||||
|
||||
placeholders.add(new PlaceHolder<User>("Top_Month_Position") {
|
||||
|
||||
@Override
|
||||
public String placeholderRequest(OfflinePlayer p, User user, String identifier) {
|
||||
int num = 1;
|
||||
for (Entry<User, Integer> entry : plugin.getTopVoter(TopVoter.Monthly).entrySet()) {
|
||||
if (entry.getKey().getUUID().equals(p.getUniqueId().toString())) {
|
||||
return "" + num;
|
||||
}
|
||||
num++;
|
||||
}
|
||||
return "";
|
||||
}
|
||||
}.withDescription("Get user top voter position"));
|
||||
|
||||
placeholders.add(new PlaceHolder<User>("Top_Month_") {
|
||||
|
||||
@Override
|
||||
public String placeholderRequest(OfflinePlayer p, User user, String identifier) {
|
||||
int num = 1;
|
||||
int number = Integer.parseInt(identifier.split("_")[2]);
|
||||
for (Entry<User, Integer> entry : plugin.getTopVoter(TopVoter.Monthly).entrySet()) {
|
||||
if (num == number) {
|
||||
return entry.getKey().getPlayerName();
|
||||
}
|
||||
num++;
|
||||
}
|
||||
return "";
|
||||
}
|
||||
}.useStartsWith().withDescription("Get user at position in top voter"));
|
||||
|
||||
placeholders.add(new PlaceHolder<User>("Top_MonthVotes_") {
|
||||
|
||||
@Override
|
||||
public String placeholderRequest(OfflinePlayer p, User user, String identifier) {
|
||||
int num = 1;
|
||||
int number = Integer.parseInt(identifier.split("_")[2]);
|
||||
for (Entry<User, Integer> entry : plugin.getTopVoter(TopVoter.Monthly).entrySet()) {
|
||||
if (num == number) {
|
||||
return "" + entry.getKey().getTotal(TopVoter.Monthly);
|
||||
}
|
||||
num++;
|
||||
}
|
||||
return "";
|
||||
}
|
||||
}.useStartsWith().withDescription("Get user votes at position in top voter"));
|
||||
|
||||
placeholders.add(new PlaceHolder<User>("Top_Week_Position") {
|
||||
|
||||
@Override
|
||||
public String placeholderRequest(OfflinePlayer p, User user, String identifier) {
|
||||
int num = 1;
|
||||
for (Entry<User, Integer> entry : plugin.getTopVoter(TopVoter.Weekly).entrySet()) {
|
||||
if (entry.getKey().getUUID().equals(p.getUniqueId().toString())) {
|
||||
return "" + num;
|
||||
}
|
||||
num++;
|
||||
}
|
||||
return "";
|
||||
}
|
||||
}.withDescription("Get user top voter position"));
|
||||
|
||||
placeholders.add(new PlaceHolder<User>("Top_Week_") {
|
||||
|
||||
@Override
|
||||
public String placeholderRequest(OfflinePlayer p, User user, String identifier) {
|
||||
int num = 1;
|
||||
int number = Integer.parseInt(identifier.split("_")[2]);
|
||||
for (Entry<User, Integer> entry : plugin.getTopVoter(TopVoter.Weekly).entrySet()) {
|
||||
if (num == number) {
|
||||
return entry.getKey().getPlayerName();
|
||||
}
|
||||
num++;
|
||||
}
|
||||
return "";
|
||||
}
|
||||
}.useStartsWith().withDescription("Get user at postion in top voter"));
|
||||
|
||||
placeholders.add(new PlaceHolder<User>("Top_WeekVotes_") {
|
||||
|
||||
@Override
|
||||
public String placeholderRequest(OfflinePlayer p, User user, String identifier) {
|
||||
int num = 1;
|
||||
int number = Integer.parseInt(identifier.split("_")[2]);
|
||||
for (Entry<User, Integer> entry : plugin.getTopVoter(TopVoter.Weekly).entrySet()) {
|
||||
if (num == number) {
|
||||
return "" + entry.getKey().getTotal(TopVoter.Weekly);
|
||||
}
|
||||
num++;
|
||||
}
|
||||
return "";
|
||||
}
|
||||
}.useStartsWith().withDescription("Get user votes at position in top voter"));
|
||||
|
||||
placeholders.add(new PlaceHolder<User>("Top_Daily_Position") {
|
||||
|
||||
@Override
|
||||
public String placeholderRequest(OfflinePlayer p, User user, String identifier) {
|
||||
int num = 1;
|
||||
for (Entry<User, Integer> entry : plugin.getTopVoter(TopVoter.Daily).entrySet()) {
|
||||
if (entry.getKey().getUUID().equals(p.getUniqueId().toString())) {
|
||||
return "" + num;
|
||||
}
|
||||
num++;
|
||||
}
|
||||
return "";
|
||||
}
|
||||
}.withDescription("Get user top voter position"));
|
||||
|
||||
placeholders.add(new PlaceHolder<User>("Top_Daily_") {
|
||||
|
||||
@Override
|
||||
public String placeholderRequest(OfflinePlayer p, User user, String identifier) {
|
||||
int num = 1;
|
||||
int number = Integer.parseInt(identifier.split("_")[2]);
|
||||
for (Entry<User, Integer> entry : plugin.getTopVoter(TopVoter.Daily).entrySet()) {
|
||||
if (num == number) {
|
||||
return entry.getKey().getPlayerName();
|
||||
}
|
||||
num++;
|
||||
}
|
||||
return "";
|
||||
}
|
||||
}.useStartsWith().withDescription("Get user at postion in top voter"));
|
||||
|
||||
placeholders.add(new PlaceHolder<User>("Top_DailyVotes_") {
|
||||
|
||||
@Override
|
||||
public String placeholderRequest(OfflinePlayer p, User user, String identifier) {
|
||||
int num = 1;
|
||||
int number = Integer.parseInt(identifier.split("_")[2]);
|
||||
for (Entry<User, Integer> entry : plugin.getTopVoter(TopVoter.Daily).entrySet()) {
|
||||
if (num == number) {
|
||||
return "" + entry.getKey().getTotal(TopVoter.Daily);
|
||||
}
|
||||
num++;
|
||||
}
|
||||
return "";
|
||||
}
|
||||
}.useStartsWith().withDescription("Get user votes at position in top voter"));
|
||||
|
||||
// non players
|
||||
|
||||
nonPlayerPlaceholders.add(new PlaceHolder<User>("VotePartyVotesCurrent") {
|
||||
|
||||
@Override
|
||||
public String placeholderRequest(OfflinePlayer p, User user, String identifier) {
|
||||
return Integer.toString(VoteParty.getInstance().getTotalVotes());
|
||||
}
|
||||
}.withDescription("Current amount of voteparty votes"));
|
||||
|
||||
nonPlayerPlaceholders.add(new PlaceHolder<User>("VotePartyVotesNeeded") {
|
||||
|
||||
@Override
|
||||
public String placeholderRequest(OfflinePlayer p, User user, String identifier) {
|
||||
return Integer.toString(VoteParty.getInstance().getNeededVotes());
|
||||
}
|
||||
}.withDescription("Voteparty votes needed"));
|
||||
|
||||
nonPlayerPlaceholders.add(new PlaceHolder<User>("VotePartyVotesRequired") {
|
||||
|
||||
@Override
|
||||
public String placeholderRequest(OfflinePlayer p, User user, String identifier) {
|
||||
return Integer.toString(VoteParty.getInstance().getVotesRequired());
|
||||
}
|
||||
}.withDescription("Amount of votes needed for voteparty"));
|
||||
|
||||
nonPlayerPlaceholders.add(new PlaceHolder<User>("GlobalMonthTotal") {
|
||||
|
||||
@Override
|
||||
public String placeholderRequest(OfflinePlayer p, User user, String identifier) {
|
||||
int total = 0;
|
||||
for (int num : Main.plugin.getTopVoter(TopVoter.Monthly).values()) {
|
||||
total += num;
|
||||
}
|
||||
return Integer.toString(total);
|
||||
}
|
||||
}.withDescription("Global month total"));
|
||||
|
||||
nonPlayerPlaceholders.add(new PlaceHolder<User>("GlobalAllTimeTotal") {
|
||||
|
||||
@Override
|
||||
public String placeholderRequest(OfflinePlayer p, User user, String identifier) {
|
||||
int total = 0;
|
||||
for (int num : Main.plugin.getTopVoter(TopVoter.AllTime).values()) {
|
||||
total += num;
|
||||
}
|
||||
return Integer.toString(total);
|
||||
}
|
||||
}.withDescription("Global alltime total"));
|
||||
|
||||
nonPlayerPlaceholders.add(new PlaceHolder<User>("GlobalWeeklyTotal") {
|
||||
|
||||
@Override
|
||||
public String placeholderRequest(OfflinePlayer p, User user, String identifier) {
|
||||
int total = 0;
|
||||
for (int num : Main.plugin.getTopVoter(TopVoter.Weekly).values()) {
|
||||
total += num;
|
||||
}
|
||||
return Integer.toString(total);
|
||||
}
|
||||
}.withDescription("Global weekly total"));
|
||||
|
||||
nonPlayerPlaceholders.add(new PlaceHolder<User>("GlobalDailyTotal") {
|
||||
|
||||
@Override
|
||||
public String placeholderRequest(OfflinePlayer p, User user, String identifier) {
|
||||
int total = 0;
|
||||
for (int num : Main.plugin.getTopVoter(TopVoter.Daily).values()) {
|
||||
total += num;
|
||||
}
|
||||
return Integer.toString(total);
|
||||
}
|
||||
}.withDescription("Global daily total"));
|
||||
}
|
||||
}
|
||||
@@ -1,292 +0,0 @@
|
||||
|
||||
package com.Ben12345rocks.VotingPlugin.VoteParty;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
|
||||
import com.Ben12345rocks.AdvancedCore.Rewards.RewardBuilder;
|
||||
import com.Ben12345rocks.AdvancedCore.TimeChecker.Events.DayChangeEvent;
|
||||
import com.Ben12345rocks.AdvancedCore.TimeChecker.Events.MonthChangeEvent;
|
||||
import com.Ben12345rocks.AdvancedCore.UserManager.UUID;
|
||||
import com.Ben12345rocks.AdvancedCore.Util.Messages.StringParser;
|
||||
import com.Ben12345rocks.AdvancedCore.Util.Misc.ArrayUtils;
|
||||
import com.Ben12345rocks.AdvancedCore.Util.Misc.MiscUtils;
|
||||
import com.Ben12345rocks.VotingPlugin.Main;
|
||||
import com.Ben12345rocks.VotingPlugin.Config.Config;
|
||||
import com.Ben12345rocks.VotingPlugin.Config.SpecialRewardsConfig;
|
||||
import com.Ben12345rocks.VotingPlugin.Data.ServerData;
|
||||
import com.Ben12345rocks.VotingPlugin.Events.VotePartyEvent;
|
||||
import com.Ben12345rocks.VotingPlugin.Objects.User;
|
||||
import com.Ben12345rocks.VotingPlugin.UserManager.UserManager;
|
||||
|
||||
// TODO: Auto-generated Javadoc
|
||||
/**
|
||||
* The Class VoteParty.
|
||||
*/
|
||||
public class VoteParty implements Listener {
|
||||
|
||||
/** The instance. */
|
||||
static VoteParty instance = new VoteParty();
|
||||
|
||||
/** The plugin. */
|
||||
static Main plugin = Main.plugin;
|
||||
|
||||
/**
|
||||
* Gets the single instance of VoteParty.
|
||||
*
|
||||
* @return single instance of VoteParty
|
||||
*/
|
||||
public static VoteParty getInstance() {
|
||||
return instance;
|
||||
}
|
||||
|
||||
/**
|
||||
* Instantiates a new vote party.
|
||||
*/
|
||||
private VoteParty() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Instantiates a new vote party.
|
||||
*
|
||||
* @param plugin
|
||||
* the plugin
|
||||
*/
|
||||
public VoteParty(Main plugin) {
|
||||
VoteParty.plugin = plugin;
|
||||
}
|
||||
|
||||
public void addTotal(User user) {
|
||||
setTotalVotes(getTotalVotes() + 1);
|
||||
user.setVotePartyVotes(user.getVotePartyVotes() + 1);
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds the vote player.
|
||||
*
|
||||
* @param user
|
||||
* the user
|
||||
*/
|
||||
public void addVotePlayer(User user) {
|
||||
String uuid = user.getUUID();
|
||||
ArrayList<String> voted = getVotedUsers();
|
||||
if (voted == null) {
|
||||
voted = new ArrayList<String>();
|
||||
}
|
||||
if (!voted.contains(uuid)) {
|
||||
voted.add(uuid);
|
||||
setVotedUsers(voted);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Check.
|
||||
*/
|
||||
public void check() {
|
||||
if (getTotalVotes() >= getVotesRequired()) {
|
||||
setTotalVotes(getTotalVotes() - getVotesRequired());
|
||||
|
||||
VotePartyEvent event = new VotePartyEvent();
|
||||
Bukkit.getPluginManager().callEvent(event);
|
||||
if (event.isCancelled()) {
|
||||
return;
|
||||
}
|
||||
MiscUtils.getInstance().broadcast(SpecialRewardsConfig.getInstance().getVotePartyBroadcast());
|
||||
giveRewards();
|
||||
|
||||
if (SpecialRewardsConfig.getInstance().getVotePartyIncreaseVotesRquired() > 0) {
|
||||
ServerData.getInstance().setVotePartyExtraRequired(ServerData.getInstance().getVotePartyExtraRequired()
|
||||
+ SpecialRewardsConfig.getInstance().getVotePartyIncreaseVotesRquired());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Command vote party.
|
||||
*
|
||||
* @param sender
|
||||
* the sender
|
||||
*/
|
||||
public void commandVoteParty(CommandSender sender) {
|
||||
if (SpecialRewardsConfig.getInstance().getVotePartyEnabled()) {
|
||||
ArrayList<String> msg = Config.getInstance().getFormatCommandsVoteParty();
|
||||
int votesRequired = getVotesRequired();
|
||||
int votes = getTotalVotes();
|
||||
int neededVotes = votesRequired - votes;
|
||||
HashMap<String, String> placeholders = new HashMap<String, String>();
|
||||
placeholders.put("votesrequired", "" + votesRequired);
|
||||
placeholders.put("neededvotes", "" + neededVotes);
|
||||
placeholders.put("votes", "" + votes);
|
||||
msg = ArrayUtils.getInstance().colorize(ArrayUtils.getInstance().replacePlaceHolder(msg, placeholders));
|
||||
sender.sendMessage(ArrayUtils.getInstance().convert(msg));
|
||||
} else {
|
||||
sender.sendMessage(StringParser.getInstance().colorize("&cVoteParty not enabled"));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the needed votes.
|
||||
*
|
||||
* @return the needed votes
|
||||
*/
|
||||
public int getNeededVotes() {
|
||||
int votesRequired = getVotesRequired();
|
||||
int votes = getTotalVotes();
|
||||
int neededVotes = votesRequired - votes;
|
||||
return neededVotes;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the total votes.
|
||||
*
|
||||
* @return the total votes
|
||||
*/
|
||||
public int getTotalVotes() {
|
||||
return ServerData.getInstance().getData().getInt("VoteParty.Total");
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the voted users.
|
||||
*
|
||||
* @return the voted users
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public ArrayList<String> getVotedUsers() {
|
||||
ArrayList<String> list = (ArrayList<String>) ServerData.getInstance().getData().getList("VoteParty.Voted");
|
||||
if (list != null) {
|
||||
return list;
|
||||
}
|
||||
return new ArrayList<String>();
|
||||
}
|
||||
|
||||
public int getVotesRequired() {
|
||||
int required = SpecialRewardsConfig.getInstance().getVotePartyVotesRequired();
|
||||
int extra = ServerData.getInstance().getVotePartyExtraRequired();
|
||||
if (extra > 0) {
|
||||
return required + extra;
|
||||
}
|
||||
return required;
|
||||
}
|
||||
|
||||
public void giveReward(User user) {
|
||||
if (SpecialRewardsConfig.getInstance().getVotePartyUserVotesRequired() > 0) {
|
||||
if (user.getVotePartyVotes() < SpecialRewardsConfig.getInstance().getVotePartyUserVotesRequired()) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
giveReward(user, user.isOnline());
|
||||
}
|
||||
|
||||
public void giveReward(User user, boolean online) {
|
||||
new RewardBuilder(SpecialRewardsConfig.getInstance().getData(),
|
||||
SpecialRewardsConfig.getInstance().getVotePartyRewardsPath()).setOnline(online)
|
||||
.withPlaceHolder("VotesRequired",
|
||||
"" + SpecialRewardsConfig.getInstance().getVotePartyVotesRequired())
|
||||
.send(user);
|
||||
}
|
||||
|
||||
/**
|
||||
* Give rewards.
|
||||
*/
|
||||
public void giveRewards() {
|
||||
for (final String cmd : SpecialRewardsConfig.getInstance().getVotePartyCommands()) {
|
||||
Bukkit.getScheduler().runTask(plugin, new Runnable() {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
Bukkit.getServer().dispatchCommand(Bukkit.getConsoleSender(), cmd);
|
||||
}
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
if (SpecialRewardsConfig.getInstance().getVotePartyGiveAllPlayers()) {
|
||||
plugin.debug("Trying to give all players vote party");
|
||||
for (String uuid : UserManager.getInstance().getAllUUIDs()) {
|
||||
User user = UserManager.getInstance().getVotingPluginUser(new UUID(uuid));
|
||||
giveReward(user);
|
||||
}
|
||||
} else {
|
||||
plugin.debug("Trying to give all online players vote party");
|
||||
plugin.debug(ArrayUtils.getInstance().makeStringList(getVotedUsers()));
|
||||
for (String uuid : getVotedUsers()) {
|
||||
User user = UserManager.getInstance().getVotingPluginUser(new UUID(uuid));
|
||||
giveReward(user);
|
||||
}
|
||||
}
|
||||
reset();
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onDayChange(DayChangeEvent event) {
|
||||
if (SpecialRewardsConfig.getInstance().getVotePartyResetEachDay()) {
|
||||
reset();
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onMonthChange(MonthChangeEvent event) {
|
||||
if (SpecialRewardsConfig.getInstance().getVotePartyResetMontly()) {
|
||||
reset();
|
||||
}
|
||||
|
||||
if (SpecialRewardsConfig.getInstance().isVotePartyResetExtraVotesMonthly()) {
|
||||
ServerData.getInstance().setVotePartyExtraRequired(0);
|
||||
}
|
||||
}
|
||||
|
||||
public void register() {
|
||||
plugin.getServer().getPluginManager().registerEvents(this, plugin);
|
||||
}
|
||||
|
||||
public void reset() {
|
||||
setVotedUsers(new ArrayList<String>());
|
||||
setTotalVotes(0);
|
||||
for (String uuid : UserManager.getInstance().getAllUUIDs()) {
|
||||
User user = UserManager.getInstance().getVotingPluginUser(new UUID(uuid));
|
||||
if (user.getVotePartyVotes() != 0) {
|
||||
user.setVotePartyVotes(0);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the total votes.
|
||||
*
|
||||
* @param value
|
||||
* the new total votes
|
||||
*/
|
||||
public void setTotalVotes(int value) {
|
||||
ServerData.getInstance().getData().set("VoteParty.Total", value);
|
||||
ServerData.getInstance().saveData();
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the voted users.
|
||||
*
|
||||
* @param value
|
||||
* the new voted users
|
||||
*/
|
||||
public void setVotedUsers(ArrayList<String> value) {
|
||||
ServerData.getInstance().getData().set("VoteParty.Voted", value);
|
||||
ServerData.getInstance().saveData();
|
||||
}
|
||||
|
||||
public synchronized void vote(User user, boolean realVote) {
|
||||
if (SpecialRewardsConfig.getInstance().getVotePartyEnabled()) {
|
||||
if (SpecialRewardsConfig.getInstance().getVotePartyCountFakeVotes() || realVote) {
|
||||
addTotal(user);
|
||||
addVotePlayer(user);
|
||||
check();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,127 +0,0 @@
|
||||
package com.Ben12345rocks.VotingPlugin.VoteReminding;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import com.Ben12345rocks.AdvancedCore.Rewards.RewardBuilder;
|
||||
import com.Ben12345rocks.AdvancedCore.Util.Misc.PlayerUtils;
|
||||
import com.Ben12345rocks.VotingPlugin.Main;
|
||||
import com.Ben12345rocks.VotingPlugin.Config.Config;
|
||||
import com.Ben12345rocks.VotingPlugin.Objects.User;
|
||||
import com.Ben12345rocks.VotingPlugin.UserManager.UserManager;
|
||||
|
||||
// TODO: Auto-generated Javadoc
|
||||
/**
|
||||
* The Class VoteReminding.
|
||||
*/
|
||||
public class VoteReminding {
|
||||
|
||||
/** The instance. */
|
||||
static VoteReminding instance = new VoteReminding();
|
||||
|
||||
/** The plugin. */
|
||||
static Main plugin = Main.plugin;
|
||||
|
||||
/**
|
||||
* Gets the single instance of VoteReminding.
|
||||
*
|
||||
* @return single instance of VoteReminding
|
||||
*/
|
||||
public static VoteReminding getInstance() {
|
||||
return instance;
|
||||
}
|
||||
|
||||
/**
|
||||
* Instantiates a new vote reminding.
|
||||
*/
|
||||
private VoteReminding() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Instantiates a new vote reminding.
|
||||
*
|
||||
* @param plugin
|
||||
* the plugin
|
||||
*/
|
||||
public VoteReminding(Main plugin) {
|
||||
VoteReminding.plugin = plugin;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check remind.
|
||||
*
|
||||
* @param user
|
||||
* the user
|
||||
*/
|
||||
public void checkRemind(User user) {
|
||||
String playerName = user.getPlayerName();
|
||||
|
||||
if (PlayerUtils.getInstance().hasServerPermission(playerName, "VotingPlugin.Login.RemindVotes")
|
||||
|| PlayerUtils.getInstance().hasServerPermission(playerName, "VotingPlugin.Player")) {
|
||||
if (user.canVoteAll() || (user.canVoteAny() && user.hasPermission("VotingPlugin.Login.RemindVotes.Any"))) {
|
||||
Player player = Bukkit.getPlayer(playerName);
|
||||
if (player != null) {
|
||||
if (!Config.getInstance().getVoteRemindingRemindOnlyOnce()) {
|
||||
runRemind(user);
|
||||
user.setReminded(true);
|
||||
} else if (!user.isReminded()) {
|
||||
runRemind(user);
|
||||
user.setReminded(true);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
private void giveReward(User user) {
|
||||
new RewardBuilder(Config.getInstance().getData(), Config.getInstance().getVoteRemindingRewardsPath())
|
||||
.setGiveOffline(false).send(user);
|
||||
}
|
||||
|
||||
/**
|
||||
* Load remind checking.
|
||||
*/
|
||||
public void loadRemindChecking() {
|
||||
Bukkit.getScheduler().runTaskTimerAsynchronously(plugin, new Runnable() {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
for (Player player : Bukkit.getServer().getOnlinePlayers()) {
|
||||
User user = UserManager.getInstance().getVotingPluginUser(player);
|
||||
checkRemind(user);
|
||||
}
|
||||
}
|
||||
}, 10, Config.getInstance().getVoteRemindingRemindDelay() * 20 * 60);
|
||||
}
|
||||
|
||||
/**
|
||||
* Run remind.
|
||||
*
|
||||
* @param user
|
||||
* the user
|
||||
*/
|
||||
public void runRemind(User user) {
|
||||
if (Config.getInstance().getVoteRemindingEnabled() && user.canVoteAll() && user.shouldBeReminded()) {
|
||||
user.setReminded(true);
|
||||
giveReward(user);
|
||||
|
||||
plugin.debug(user.getPlayerName() + " was reminded!");
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public void runRemindLogin(User user) {
|
||||
if (Config.getInstance().getVoteRemindingEnabled()
|
||||
&& (!UserManager.getInstance().getAllUUIDs().contains(user.getUUID()) || user.canVoteAll())
|
||||
&& user.shouldBeReminded()) {
|
||||
giveReward(user);
|
||||
if (user.getData().hasData()) {
|
||||
user.setReminded(true);
|
||||
}
|
||||
plugin.debug(user.getPlayerName() + " was reminded!");
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,251 @@
|
||||
package com.bencodez.votingplugin;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.UUID;
|
||||
|
||||
import com.bencodez.advancedcore.api.misc.encryption.EncryptionHandler;
|
||||
import com.bencodez.advancedcore.bungeeapi.pluginmessage.PluginMessageHandler;
|
||||
import com.bencodez.advancedcore.bungeeapi.sockets.ClientHandler;
|
||||
import com.bencodez.advancedcore.bungeeapi.sockets.SocketHandler;
|
||||
import com.bencodez.advancedcore.bungeeapi.sockets.SocketReceiver;
|
||||
import com.bencodez.votingplugin.bungee.BungeeMethod;
|
||||
import com.bencodez.votingplugin.objects.VoteSite;
|
||||
import com.bencodez.votingplugin.user.UserManager;
|
||||
import com.bencodez.votingplugin.user.VotingPluginUser;
|
||||
|
||||
import lombok.Getter;
|
||||
|
||||
public class BungeeHandler {
|
||||
@Getter
|
||||
private ClientHandler clientHandler;
|
||||
|
||||
private EncryptionHandler encryptionHandler;
|
||||
|
||||
@Getter
|
||||
private BungeeMethod method;
|
||||
|
||||
private VotingPluginMain plugin;
|
||||
|
||||
@Getter
|
||||
private SocketHandler socketHandler;
|
||||
|
||||
public BungeeHandler(VotingPluginMain plugin) {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
public void close() {
|
||||
socketHandler.closeConnection();
|
||||
clientHandler.stopConnection();
|
||||
}
|
||||
|
||||
public void load() {
|
||||
plugin.debug("Loading bungee handler");
|
||||
|
||||
method = BungeeMethod.getByName(plugin.getBungeeSettings().getBungeeMethod());
|
||||
|
||||
plugin.getLogger().info("Using BungeeMethod: " + method.toString());
|
||||
|
||||
if (method.equals(BungeeMethod.MYSQL)) {
|
||||
plugin.registerBungeeChannels();
|
||||
} else if (method.equals(BungeeMethod.PLUGINMESSAGING)) {
|
||||
plugin.registerBungeeChannels();
|
||||
|
||||
plugin.getPluginMessaging().add(new PluginMessageHandler("Vote") {
|
||||
@Override
|
||||
public void onRecieve(String subChannel, ArrayList<String> args) {
|
||||
String player = args.get(0);
|
||||
String uuid = args.get(1);
|
||||
String service = args.get(2);
|
||||
long time = Long.parseLong(args.get(3));
|
||||
plugin.debug("pluginmessaging vote received from " + player + " on " + service);
|
||||
VotingPluginUser user = UserManager.getInstance().getVotingPluginUser(UUID.fromString(uuid));
|
||||
|
||||
boolean wasOnline = Boolean.valueOf(args.get(4));
|
||||
|
||||
String text = args.get(6);
|
||||
|
||||
user.clearCache();
|
||||
|
||||
user.bungeeVotePluginMessaging(service, time, text);
|
||||
|
||||
if (!plugin.getBungeeSettings().isBungeeBroadcast()) {
|
||||
if (wasOnline || plugin.getBungeeSettings().isBungeeBroadcastAlways()) {
|
||||
VoteSite site = plugin.getVoteSite(service);
|
||||
if (site != null) {
|
||||
site.broadcastVote(user, false);
|
||||
} else {
|
||||
plugin.getLogger().warning("No votesite for " + service);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (args.size() > 4 && Boolean.valueOf(args.get(5))) {
|
||||
plugin.getServerData().addServiceSite(service);
|
||||
}
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
plugin.getPluginMessaging().add(new PluginMessageHandler("VoteOnline") {
|
||||
@Override
|
||||
public void onRecieve(String subChannel, ArrayList<String> args) {
|
||||
String player = args.get(0);
|
||||
String uuid = args.get(1);
|
||||
String service = args.get(2);
|
||||
long time = Long.parseLong(args.get(3));
|
||||
String text = args.get(6);
|
||||
plugin.debug("pluginmessaging voteonline received from " + player + " on " + service);
|
||||
VotingPluginUser user = UserManager.getInstance().getVotingPluginUser(UUID.fromString(uuid));
|
||||
user.clearCache();
|
||||
|
||||
user.bungeeVotePluginMessaging(service, time, text);
|
||||
|
||||
if (!plugin.getBungeeSettings().isBungeeBroadcast()) {
|
||||
if (Boolean.valueOf(args.get(4)) || plugin.getBungeeSettings().isBungeeBroadcastAlways()) {
|
||||
VoteSite site = plugin.getVoteSite(service);
|
||||
if (site != null) {
|
||||
site.broadcastVote(user, false);
|
||||
} else {
|
||||
plugin.getLogger().warning("No votesite for " + service);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (args.size() > 4 && Boolean.valueOf(args.get(5))) {
|
||||
plugin.getServerData().addServiceSite(service);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
plugin.getPluginMessaging().add(new PluginMessageHandler("VoteUpdate") {
|
||||
@Override
|
||||
public void onRecieve(String subChannel, ArrayList<String> args) {
|
||||
String player = args.get(0);
|
||||
plugin.debug("pluginmessaging voteupdate received for " + player);
|
||||
VotingPluginUser user = UserManager.getInstance().getVotingPluginUser(UUID.fromString(player));
|
||||
user.clearCache();
|
||||
|
||||
user.offVote();
|
||||
|
||||
plugin.setUpdate(true);
|
||||
}
|
||||
});
|
||||
|
||||
plugin.getPluginMessaging().add(new PluginMessageHandler("VoteBroadcast") {
|
||||
@Override
|
||||
public void onRecieve(String subChannel, ArrayList<String> args) {
|
||||
String uuid = args.get(0);
|
||||
String service = args.get(1);
|
||||
VotingPluginUser user = UserManager.getInstance().getVotingPluginUser(UUID.fromString(uuid));
|
||||
VoteSite site = plugin.getVoteSite(service);
|
||||
if (site != null) {
|
||||
site.broadcastVote(user, false);
|
||||
} else {
|
||||
plugin.getLogger().warning("No votesite for " + service);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
} else if (method.equals(BungeeMethod.SOCKETS)) {
|
||||
encryptionHandler = new EncryptionHandler(new File(plugin.getDataFolder(), "secretkey.key"));
|
||||
|
||||
clientHandler = new ClientHandler(plugin.getBungeeSettings().getBungeeServerHost(),
|
||||
plugin.getBungeeSettings().getBungeeServerPort(), encryptionHandler,
|
||||
plugin.getBungeeSettings().isBungeeDebug());
|
||||
|
||||
socketHandler = new SocketHandler(plugin.getVersion(), plugin.getBungeeSettings().getSpigotServerHost(),
|
||||
plugin.getBungeeSettings().getSpigotServerPort(), encryptionHandler,
|
||||
plugin.getBungeeSettings().isBungeeDebug());
|
||||
|
||||
socketHandler.add(new SocketReceiver("bungeevote") {
|
||||
|
||||
@Override
|
||||
public void onReceive(String[] data) {
|
||||
if (data.length > 3) {
|
||||
plugin.extraDebug("BungeeVote from " + data[2] + ", processing");
|
||||
String uuid = data[1];
|
||||
VotingPluginUser user = null;
|
||||
if (!uuid.isEmpty()) {
|
||||
user = UserManager.getInstance().getVotingPluginUser(UUID.fromString(uuid));
|
||||
} else {
|
||||
user = UserManager.getInstance().getVotingPluginUser(data[2]);
|
||||
}
|
||||
|
||||
user.clearCache();
|
||||
|
||||
user.bungeeVote(data[3]);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
socketHandler.add(new SocketReceiver("bungeevoteonline") {
|
||||
|
||||
@Override
|
||||
public void onReceive(String[] data) {
|
||||
if (data.length > 3) {
|
||||
plugin.extraDebug("BungeeVoteOnline from " + data[2] + ", processing");
|
||||
String uuid = data[1];
|
||||
VotingPluginUser user = null;
|
||||
if (!uuid.isEmpty()) {
|
||||
user = UserManager.getInstance().getVotingPluginUser(UUID.fromString(uuid));
|
||||
} else {
|
||||
user = UserManager.getInstance().getVotingPluginUser(data[2]);
|
||||
}
|
||||
|
||||
user.clearCache();
|
||||
|
||||
user.bungeeVoteOnline(data[3]);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
socketHandler.add(new SocketReceiver("BungeeBroadcast") {
|
||||
|
||||
@Override
|
||||
public void onReceive(String[] data) {
|
||||
if (data.length > 2) {
|
||||
VoteSite site = plugin.getVoteSite(data[1]);
|
||||
String p = data[3];
|
||||
VotingPluginUser user = UserManager.getInstance().getVotingPluginUser(p);
|
||||
if (site != null) {
|
||||
site.broadcastVote(user, false);
|
||||
} else {
|
||||
plugin.getLogger().warning("No votesite for " + data[1]);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
socketHandler.add(new SocketReceiver("Status") {
|
||||
|
||||
@Override
|
||||
public void onReceive(String[] data) {
|
||||
if (data.length > 0) {
|
||||
plugin.getLogger().info("Received status command, sending status back");
|
||||
sendData("StatusOkay", plugin.getOptions().getServer());
|
||||
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
socketHandler.add(new SocketReceiver("BungeeUpdate") {
|
||||
|
||||
@Override
|
||||
public void onReceive(String[] data) {
|
||||
plugin.setUpdate(true);
|
||||
}
|
||||
});
|
||||
|
||||
if (plugin.getOptions().getServer().equalsIgnoreCase("pleaseset")) {
|
||||
plugin.getLogger().warning("Server name for bungee voting is not set, please set it");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void sendData(String... strings) {
|
||||
clientHandler.sendMessage(strings);
|
||||
}
|
||||
}
|
||||
+7
-7
@@ -1,9 +1,9 @@
|
||||
package com.Ben12345rocks.VotingPlugin;
|
||||
package com.bencodez.votingplugin;
|
||||
|
||||
import com.Ben12345rocks.AdvancedCore.Rewards.RewardHandler;
|
||||
import com.Ben12345rocks.AdvancedCore.Rewards.Injected.RewardInject;
|
||||
import com.Ben12345rocks.AdvancedCore.Rewards.InjectedRequirement.RequirementInject;
|
||||
import com.Ben12345rocks.VotingPlugin.UserManager.UserManager;
|
||||
import com.bencodez.advancedcore.api.rewards.RewardHandler;
|
||||
import com.bencodez.advancedcore.api.rewards.injected.RewardInject;
|
||||
import com.bencodez.advancedcore.api.rewards.injectedrequirement.RequirementInject;
|
||||
import com.bencodez.votingplugin.user.UserManager;
|
||||
|
||||
public class VotingPluginHooks {
|
||||
private static VotingPluginHooks instance = new VotingPluginHooks();
|
||||
@@ -20,8 +20,8 @@ public class VotingPluginHooks {
|
||||
RewardHandler.getInstance().addInjectedReward(inject);
|
||||
}
|
||||
|
||||
public Main getMainClass() {
|
||||
return Main.plugin;
|
||||
public VotingPluginMain getMainClass() {
|
||||
return VotingPluginMain.plugin;
|
||||
}
|
||||
|
||||
public UserManager getUserManager() {
|
||||
+330
-487
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,243 @@
|
||||
package com.bencodez.votingplugin;
|
||||
|
||||
import com.bencodez.advancedcore.api.metrics.BStatsMetrics;
|
||||
import com.bencodez.advancedcore.api.rewards.RewardHandler;
|
||||
import com.bencodez.votingplugin.user.UserManager;
|
||||
|
||||
public class VotingPluginMetrics {
|
||||
|
||||
public void load(VotingPluginMain plugin) {
|
||||
BStatsMetrics metrics = new BStatsMetrics(plugin);
|
||||
|
||||
metrics.addCustomChart(new BStatsMetrics.SimplePie("extrarewards_firstvote") {
|
||||
|
||||
@Override
|
||||
public String getValue() {
|
||||
if (RewardHandler.getInstance().hasRewards(plugin.getSpecialRewardsConfig().getData(),
|
||||
plugin.getSpecialRewardsConfig().getFirstVoteRewardsPath())) {
|
||||
return "True";
|
||||
} else {
|
||||
return "False";
|
||||
}
|
||||
}
|
||||
});
|
||||
metrics.addCustomChart(new BStatsMetrics.SimplePie("extrarewards_everysite") {
|
||||
|
||||
@Override
|
||||
public String getValue() {
|
||||
if (RewardHandler.getInstance().hasRewards(plugin.getConfigVoteSites().getData(),
|
||||
plugin.getConfigVoteSites().getEverySiteRewardPath())) {
|
||||
return "True";
|
||||
} else {
|
||||
return "False";
|
||||
}
|
||||
}
|
||||
});
|
||||
metrics.addCustomChart(new BStatsMetrics.SimplePie("extrarewards_allsites") {
|
||||
|
||||
@Override
|
||||
public String getValue() {
|
||||
if (RewardHandler.getInstance().hasRewards(plugin.getSpecialRewardsConfig().getData(),
|
||||
plugin.getSpecialRewardsConfig().getAllSitesRewardPath())) {
|
||||
return "True";
|
||||
} else {
|
||||
return "False";
|
||||
}
|
||||
}
|
||||
});
|
||||
metrics.addCustomChart(new BStatsMetrics.SimplePie("extrarewards_cumulative") {
|
||||
|
||||
@Override
|
||||
public String getValue() {
|
||||
if (plugin.getSpecialRewardsConfig().getCumulativeVotes().size() == 0) {
|
||||
return "False";
|
||||
} else {
|
||||
for (String cum : plugin.getSpecialRewardsConfig().getCumulativeVotes()) {
|
||||
if (plugin.getSpecialRewardsConfig().getCumulativeRewardEnabled(Integer.parseInt(cum))) {
|
||||
return "True";
|
||||
}
|
||||
}
|
||||
return "False";
|
||||
}
|
||||
}
|
||||
});
|
||||
metrics.addCustomChart(new BStatsMetrics.SimplePie("extrarewards_voteparty") {
|
||||
|
||||
@Override
|
||||
public String getValue() {
|
||||
if (!plugin.getSpecialRewardsConfig().getVotePartyEnabled()) {
|
||||
return "False";
|
||||
} else {
|
||||
return "True";
|
||||
}
|
||||
}
|
||||
});
|
||||
metrics.addCustomChart(new BStatsMetrics.SimplePie("extrarewards_milestone") {
|
||||
|
||||
@Override
|
||||
public String getValue() {
|
||||
if (plugin.getSpecialRewardsConfig().getMilestoneVotes().size() == 0) {
|
||||
return "False";
|
||||
} else {
|
||||
for (String milestone : plugin.getSpecialRewardsConfig().getMilestoneVotes()) {
|
||||
if (plugin.getSpecialRewardsConfig().getMilestoneRewardEnabled(Integer.parseInt(milestone))) {
|
||||
return "True";
|
||||
}
|
||||
}
|
||||
return "False";
|
||||
}
|
||||
}
|
||||
});
|
||||
metrics.addCustomChart(new BStatsMetrics.SimplePie("extrarewards_anysitereward") {
|
||||
|
||||
@Override
|
||||
public String getValue() {
|
||||
if (RewardHandler.getInstance().hasRewards(plugin.getSpecialRewardsConfig().getData(),
|
||||
plugin.getSpecialRewardsConfig().getAnySiteRewardsPath())) {
|
||||
return "True";
|
||||
} else {
|
||||
return "False";
|
||||
}
|
||||
}
|
||||
});
|
||||
metrics.addCustomChart(new BStatsMetrics.SimplePie("extrarewards_votestreakday") {
|
||||
|
||||
@Override
|
||||
public String getValue() {
|
||||
for (String s : plugin.getSpecialRewardsConfig().getVoteStreakVotes("Day")) {
|
||||
|
||||
if (plugin.getSpecialRewardsConfig().getVoteStreakRewardEnabled("Day", s)
|
||||
&& RewardHandler.getInstance().hasRewards(plugin.getSpecialRewardsConfig().getData(),
|
||||
plugin.getSpecialRewardsConfig().getVoteStreakRewardsPath("Day", s))) {
|
||||
return "True";
|
||||
}
|
||||
|
||||
}
|
||||
return "False";
|
||||
}
|
||||
});
|
||||
|
||||
metrics.addCustomChart(new BStatsMetrics.SimplePie("extrarewards_votestreakweek") {
|
||||
|
||||
@Override
|
||||
public String getValue() {
|
||||
for (String s : plugin.getSpecialRewardsConfig().getVoteStreakVotes("Week")) {
|
||||
|
||||
if (plugin.getSpecialRewardsConfig().getVoteStreakRewardEnabled("Week", s)
|
||||
&& RewardHandler.getInstance().hasRewards(plugin.getSpecialRewardsConfig().getData(),
|
||||
plugin.getSpecialRewardsConfig().getVoteStreakRewardsPath("Week", s))) {
|
||||
return "True";
|
||||
}
|
||||
}
|
||||
|
||||
return "False";
|
||||
}
|
||||
});
|
||||
|
||||
metrics.addCustomChart(new BStatsMetrics.SimplePie("extrarewards_votestreakmonth") {
|
||||
|
||||
@Override
|
||||
public String getValue() {
|
||||
for (String s : plugin.getSpecialRewardsConfig().getVoteStreakVotes("Month")) {
|
||||
|
||||
if (plugin.getSpecialRewardsConfig().getVoteStreakRewardEnabled("Month", s)
|
||||
&& RewardHandler.getInstance().hasRewards(plugin.getSpecialRewardsConfig().getData(),
|
||||
plugin.getSpecialRewardsConfig().getVoteStreakRewardsPath("Month", s))) {
|
||||
return "True";
|
||||
}
|
||||
}
|
||||
|
||||
return "False";
|
||||
}
|
||||
});
|
||||
metrics.addCustomChart(new BStatsMetrics.SimplePie("numberofsites") {
|
||||
|
||||
@Override
|
||||
public String getValue() {
|
||||
return "" + plugin.getVoteSites().size();
|
||||
}
|
||||
});
|
||||
metrics.addCustomChart(new BStatsMetrics.SimplePie("numberofrewards") {
|
||||
|
||||
@Override
|
||||
public String getValue() {
|
||||
return "" + RewardHandler.getInstance().getRewards().size();
|
||||
}
|
||||
});
|
||||
metrics.addCustomChart(new BStatsMetrics.SimplePie("autocreatevotesites") {
|
||||
|
||||
@Override
|
||||
public String getValue() {
|
||||
return "" + plugin.getConfigFile().isAutoCreateVoteSites();
|
||||
}
|
||||
});
|
||||
|
||||
metrics.addCustomChart(new BStatsMetrics.SimplePie("numberofusers") {
|
||||
|
||||
@Override
|
||||
public String getValue() {
|
||||
int total = UserManager.getInstance().getAllUUIDs().size();
|
||||
if (total < 1000) {
|
||||
return "<1000";
|
||||
} else if (total > 10000) {
|
||||
return ">10000";
|
||||
} else {
|
||||
return "1000-10000";
|
||||
}
|
||||
}
|
||||
});
|
||||
metrics.addCustomChart(new BStatsMetrics.SimplePie("data_storage") {
|
||||
|
||||
@Override
|
||||
public String getValue() {
|
||||
return plugin.getOptions().getStorageType().toString();
|
||||
}
|
||||
});
|
||||
metrics.addCustomChart(new BStatsMetrics.SimplePie("DisableCheckOnWorldChange") {
|
||||
|
||||
@Override
|
||||
public String getValue() {
|
||||
return "" + plugin.getOptions().isDisableCheckOnWorldChange();
|
||||
}
|
||||
});
|
||||
metrics.addCustomChart(new BStatsMetrics.SimplePie("votereminding_enabled") {
|
||||
|
||||
@Override
|
||||
public String getValue() {
|
||||
return "" + plugin.getConfigFile().getVoteRemindingEnabled();
|
||||
}
|
||||
});
|
||||
metrics.addCustomChart(new BStatsMetrics.SimplePie("LoadTopVoter_Monthly") {
|
||||
|
||||
@Override
|
||||
public String getValue() {
|
||||
return "" + plugin.getConfigFile().getLoadTopVoterMonthly();
|
||||
}
|
||||
});
|
||||
metrics.addCustomChart(new BStatsMetrics.SimplePie("LoadTopVoter_Weekly") {
|
||||
|
||||
@Override
|
||||
public String getValue() {
|
||||
return "" + plugin.getConfigFile().getLoadTopVoterWeekly();
|
||||
}
|
||||
});
|
||||
metrics.addCustomChart(new BStatsMetrics.SimplePie("LoadTopVoter_Daily") {
|
||||
|
||||
@Override
|
||||
public String getValue() {
|
||||
return "" + plugin.getConfigFile().getLoadTopVoterDaily();
|
||||
}
|
||||
});
|
||||
metrics.addCustomChart(new BStatsMetrics.SimplePie("bungeemethod") {
|
||||
|
||||
@Override
|
||||
public String getValue() {
|
||||
if (plugin.getBungeeSettings().isUseBungeecoord()) {
|
||||
return "" + plugin.getBungeeHandler().getMethod().toString();
|
||||
} else {
|
||||
return "Disabled";
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,771 @@
|
||||
package com.bencodez.votingplugin.bungee;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.BufferedWriter;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.File;
|
||||
import java.io.FileReader;
|
||||
import java.io.FileWriter;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.net.URL;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.Callable;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
import java.util.zip.GZIPOutputStream;
|
||||
|
||||
import javax.net.ssl.HttpsURLConnection;
|
||||
|
||||
import com.google.gson.JsonArray;
|
||||
import com.google.gson.JsonObject;
|
||||
import com.google.gson.JsonPrimitive;
|
||||
|
||||
import net.md_5.bungee.api.plugin.Plugin;
|
||||
import net.md_5.bungee.config.Configuration;
|
||||
import net.md_5.bungee.config.ConfigurationProvider;
|
||||
import net.md_5.bungee.config.YamlConfiguration;
|
||||
|
||||
/**
|
||||
* bStats collects some data for plugin authors.
|
||||
* <p>
|
||||
* Check out https://bStats.org/ to learn more about bStats!
|
||||
*/
|
||||
public class BStatsMetricsBungee {
|
||||
|
||||
static {
|
||||
// You can use the property to disable the check in your test environment
|
||||
if (System.getProperty("bstats.relocatecheck") == null
|
||||
|| !System.getProperty("bstats.relocatecheck").equals("false")) {
|
||||
// Maven's Relocate is clever and changes strings, too. So we have to use this
|
||||
// little "trick" ... :D
|
||||
final String defaultPackage = new String(new byte[] { 'o', 'r', 'g', '.', 'b', 's', 't', 'a', 't', 's', '.',
|
||||
'b', 'u', 'n', 'g', 'e', 'e', 'c', 'o', 'r', 'd' });
|
||||
final String examplePackage = new String(
|
||||
new byte[] { 'y', 'o', 'u', 'r', '.', 'p', 'a', 'c', 'k', 'a', 'g', 'e' });
|
||||
// We want to make sure nobody just copy & pastes the example and use the wrong
|
||||
// package names
|
||||
if (BStatsMetricsBungee.class.getPackage().getName().equals(defaultPackage)
|
||||
|| BStatsMetricsBungee.class.getPackage().getName().equals(examplePackage)) {
|
||||
throw new IllegalStateException("bStats Metrics class has not been relocated correctly!");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// The version of this bStats class
|
||||
public static final int B_STATS_VERSION = 1;
|
||||
|
||||
// The url to which the data is sent
|
||||
private static final String URL = "https://bStats.org/submitData/bungeecord";
|
||||
|
||||
// The plugin
|
||||
private final Plugin plugin;
|
||||
|
||||
// The plugin id
|
||||
private final int pluginId;
|
||||
|
||||
// Is bStats enabled on this server?
|
||||
private boolean enabled;
|
||||
|
||||
// The uuid of the server
|
||||
private String serverUUID;
|
||||
|
||||
// Should failed requests be logged?
|
||||
private boolean logFailedRequests = false;
|
||||
|
||||
// Should the sent data be logged?
|
||||
private static boolean logSentData;
|
||||
|
||||
// Should the response text be logged?
|
||||
private static boolean logResponseStatusText;
|
||||
|
||||
// A list with all known metrics class objects including this one
|
||||
private static final List<Object> knownMetricsInstances = new ArrayList<>();
|
||||
|
||||
// A list with all custom charts
|
||||
private final List<CustomChart> charts = new ArrayList<>();
|
||||
|
||||
/**
|
||||
* Class constructor.
|
||||
*
|
||||
* @param plugin The plugin which stats should be submitted.
|
||||
* @param pluginId The id of the plugin. It can be found at
|
||||
* <a href="https://bstats.org/what-is-my-plugin-id">What is my
|
||||
* plugin id?</a>
|
||||
*/
|
||||
public BStatsMetricsBungee(Plugin plugin, int pluginId) {
|
||||
this.plugin = plugin;
|
||||
this.pluginId = pluginId;
|
||||
|
||||
try {
|
||||
loadConfig();
|
||||
} catch (IOException e) {
|
||||
// Failed to load configuration
|
||||
plugin.getLogger().log(Level.WARNING, "Failed to load bStats config!", e);
|
||||
return;
|
||||
}
|
||||
|
||||
// We are not allowed to send data about this server :(
|
||||
if (!enabled) {
|
||||
return;
|
||||
}
|
||||
|
||||
Class<?> usedMetricsClass = getFirstBStatsClass();
|
||||
if (usedMetricsClass == null) {
|
||||
// Failed to get first metrics class
|
||||
return;
|
||||
}
|
||||
if (usedMetricsClass == getClass()) {
|
||||
// We are the first! :)
|
||||
linkMetrics(this);
|
||||
startSubmitting();
|
||||
} else {
|
||||
// We aren't the first so we link to the first metrics class
|
||||
try {
|
||||
usedMetricsClass.getMethod("linkMetrics", Object.class).invoke(null, this);
|
||||
} catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException e) {
|
||||
if (logFailedRequests) {
|
||||
plugin.getLogger().log(Level.WARNING,
|
||||
"Failed to link to first metrics class " + usedMetricsClass.getName() + "!", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if bStats is enabled.
|
||||
*
|
||||
* @return Whether bStats is enabled or not.
|
||||
*/
|
||||
public boolean isEnabled() {
|
||||
return enabled;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a custom chart.
|
||||
*
|
||||
* @param chart The chart to add.
|
||||
*/
|
||||
public void addCustomChart(CustomChart chart) {
|
||||
if (chart == null) {
|
||||
plugin.getLogger().log(Level.WARNING, "Chart cannot be null");
|
||||
}
|
||||
charts.add(chart);
|
||||
}
|
||||
|
||||
/**
|
||||
* Links an other metrics class with this class. This method is called using
|
||||
* Reflection.
|
||||
*
|
||||
* @param metrics An object of the metrics class to link.
|
||||
*/
|
||||
public static void linkMetrics(Object metrics) {
|
||||
knownMetricsInstances.add(metrics);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the plugin specific data. This method is called using Reflection.
|
||||
*
|
||||
* @return The plugin specific data.
|
||||
*/
|
||||
public JsonObject getPluginData() {
|
||||
JsonObject data = new JsonObject();
|
||||
|
||||
String pluginName = plugin.getDescription().getName();
|
||||
String pluginVersion = plugin.getDescription().getVersion();
|
||||
|
||||
data.addProperty("pluginName", pluginName);
|
||||
data.addProperty("id", pluginId);
|
||||
data.addProperty("pluginVersion", pluginVersion);
|
||||
|
||||
JsonArray customCharts = new JsonArray();
|
||||
for (CustomChart customChart : charts) {
|
||||
// Add the data of the custom charts
|
||||
JsonObject chart = customChart.getRequestJsonObject(plugin.getLogger(), logFailedRequests);
|
||||
if (chart == null) { // If the chart is null, we skip it
|
||||
continue;
|
||||
}
|
||||
customCharts.add(chart);
|
||||
}
|
||||
data.add("customCharts", customCharts);
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
private void startSubmitting() {
|
||||
// The data collection is async, as well as sending the data
|
||||
// Bungeecord does not have a main thread, everything is async
|
||||
plugin.getProxy().getScheduler().schedule(plugin, this::submitData, 2, 30, TimeUnit.MINUTES);
|
||||
// Submit the data every 30 minutes, first time after 2 minutes to give other
|
||||
// plugins enough time to start
|
||||
// WARNING: Changing the frequency has no effect but your plugin WILL be
|
||||
// blocked/deleted!
|
||||
// WARNING: Just don't do it!
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the server specific data.
|
||||
*
|
||||
* @return The server specific data.
|
||||
*/
|
||||
@SuppressWarnings("deprecation")
|
||||
private JsonObject getServerData() {
|
||||
// Minecraft specific data
|
||||
int playerAmount = Math.min(plugin.getProxy().getOnlineCount(), 500);
|
||||
int onlineMode = plugin.getProxy().getConfig().isOnlineMode() ? 1 : 0;
|
||||
String bungeecordVersion = plugin.getProxy().getVersion();
|
||||
int managedServers = plugin.getProxy().getServers().size();
|
||||
|
||||
// OS/Java specific data
|
||||
String javaVersion = System.getProperty("java.version");
|
||||
String osName = System.getProperty("os.name");
|
||||
String osArch = System.getProperty("os.arch");
|
||||
String osVersion = System.getProperty("os.version");
|
||||
int coreCount = Runtime.getRuntime().availableProcessors();
|
||||
|
||||
JsonObject data = new JsonObject();
|
||||
|
||||
data.addProperty("serverUUID", serverUUID);
|
||||
|
||||
data.addProperty("playerAmount", playerAmount);
|
||||
data.addProperty("managedServers", managedServers);
|
||||
data.addProperty("onlineMode", onlineMode);
|
||||
data.addProperty("bungeecordVersion", bungeecordVersion);
|
||||
|
||||
data.addProperty("javaVersion", javaVersion);
|
||||
data.addProperty("osName", osName);
|
||||
data.addProperty("osArch", osArch);
|
||||
data.addProperty("osVersion", osVersion);
|
||||
data.addProperty("coreCount", coreCount);
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Collects the data and sends it afterwards.
|
||||
*/
|
||||
private void submitData() {
|
||||
final JsonObject data = getServerData();
|
||||
|
||||
final JsonArray pluginData = new JsonArray();
|
||||
// Search for all other bStats Metrics classes to get their plugin data
|
||||
for (Object metrics : knownMetricsInstances) {
|
||||
try {
|
||||
Object plugin = metrics.getClass().getMethod("getPluginData").invoke(metrics);
|
||||
if (plugin instanceof JsonObject) {
|
||||
pluginData.add((JsonObject) plugin);
|
||||
}
|
||||
} catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException ignored) {
|
||||
}
|
||||
}
|
||||
|
||||
data.add("plugins", pluginData);
|
||||
|
||||
try {
|
||||
// Send the data
|
||||
sendData(plugin, data);
|
||||
} catch (Exception e) {
|
||||
// Something went wrong! :(
|
||||
if (logFailedRequests) {
|
||||
plugin.getLogger().log(Level.WARNING, "Could not submit plugin stats!", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads the bStats configuration.
|
||||
*
|
||||
* @throws IOException If something did not work :(
|
||||
*/
|
||||
private void loadConfig() throws IOException {
|
||||
File bStatsFolder = new File(plugin.getDataFolder().getParentFile(), "bStats");
|
||||
bStatsFolder.mkdirs();
|
||||
File configFile = new File(bStatsFolder, "config.yml");
|
||||
if (!configFile.exists()) {
|
||||
writeFile(configFile,
|
||||
"#bStats collects some data for plugin authors like how many servers are using their plugins.",
|
||||
"#To honor their work, you should not disable it.",
|
||||
"#This has nearly no effect on the server performance!",
|
||||
"#Check out https://bStats.org/ to learn more :)", "enabled: true",
|
||||
"serverUuid: \"" + UUID.randomUUID() + "\"", "logFailedRequests: false", "logSentData: false",
|
||||
"logResponseStatusText: false");
|
||||
}
|
||||
|
||||
Configuration configuration = ConfigurationProvider.getProvider(YamlConfiguration.class).load(configFile);
|
||||
|
||||
// Load configuration
|
||||
enabled = configuration.getBoolean("enabled", true);
|
||||
serverUUID = configuration.getString("serverUuid");
|
||||
logFailedRequests = configuration.getBoolean("logFailedRequests", false);
|
||||
logSentData = configuration.getBoolean("logSentData", false);
|
||||
logResponseStatusText = configuration.getBoolean("logResponseStatusText", false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the first bStat Metrics class.
|
||||
*
|
||||
* @return The first bStats metrics class.
|
||||
*/
|
||||
private Class<?> getFirstBStatsClass() {
|
||||
File bStatsFolder = new File(plugin.getDataFolder().getParentFile(), "bStats");
|
||||
bStatsFolder.mkdirs();
|
||||
File tempFile = new File(bStatsFolder, "temp.txt");
|
||||
|
||||
try {
|
||||
String className = readFile(tempFile);
|
||||
if (className != null) {
|
||||
try {
|
||||
// Let's check if a class with the given name exists.
|
||||
return Class.forName(className);
|
||||
} catch (ClassNotFoundException ignored) {
|
||||
}
|
||||
}
|
||||
writeFile(tempFile, getClass().getName());
|
||||
return getClass();
|
||||
} catch (IOException e) {
|
||||
if (logFailedRequests) {
|
||||
plugin.getLogger().log(Level.WARNING, "Failed to get first bStats class!", e);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads the first line of the file.
|
||||
*
|
||||
* @param file The file to read. Cannot be null.
|
||||
* @return The first line of the file or {@code null} if the file does not exist
|
||||
* or is empty.
|
||||
* @throws IOException If something did not work :(
|
||||
*/
|
||||
private String readFile(File file) throws IOException {
|
||||
if (!file.exists()) {
|
||||
return null;
|
||||
}
|
||||
try (BufferedReader bufferedReader = new BufferedReader(new FileReader(file))) {
|
||||
return bufferedReader.readLine();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Writes a String to a file. It also adds a note for the user,
|
||||
*
|
||||
* @param file The file to write to. Cannot be null.
|
||||
* @param lines The lines to write.
|
||||
* @throws IOException If something did not work :(
|
||||
*/
|
||||
private void writeFile(File file, String... lines) throws IOException {
|
||||
try (BufferedWriter bufferedWriter = new BufferedWriter(new FileWriter(file))) {
|
||||
for (String line : lines) {
|
||||
bufferedWriter.write(line);
|
||||
bufferedWriter.newLine();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sends the data to the bStats server.
|
||||
*
|
||||
* @param plugin Any plugin. It's just used to get a logger instance.
|
||||
* @param data The data to send.
|
||||
* @throws Exception If the request failed.
|
||||
*/
|
||||
private static void sendData(Plugin plugin, JsonObject data) throws Exception {
|
||||
if (data == null) {
|
||||
throw new IllegalArgumentException("Data cannot be null");
|
||||
}
|
||||
if (logSentData) {
|
||||
plugin.getLogger().info("Sending data to bStats: " + data);
|
||||
}
|
||||
|
||||
HttpsURLConnection connection = (HttpsURLConnection) new URL(URL).openConnection();
|
||||
|
||||
// Compress the data to save bandwidth
|
||||
byte[] compressedData = compress(data.toString());
|
||||
|
||||
// Add headers
|
||||
connection.setRequestMethod("POST");
|
||||
connection.addRequestProperty("Accept", "application/json");
|
||||
connection.addRequestProperty("Connection", "close");
|
||||
connection.addRequestProperty("Content-Encoding", "gzip"); // We gzip our request
|
||||
connection.addRequestProperty("Content-Length", String.valueOf(compressedData.length));
|
||||
connection.setRequestProperty("Content-Type", "application/json"); // We send our data in JSON format
|
||||
connection.setRequestProperty("User-Agent", "MC-Server/" + B_STATS_VERSION);
|
||||
|
||||
// Send data
|
||||
connection.setDoOutput(true);
|
||||
try (DataOutputStream outputStream = new DataOutputStream(connection.getOutputStream())) {
|
||||
outputStream.write(compressedData);
|
||||
}
|
||||
|
||||
StringBuilder builder = new StringBuilder();
|
||||
|
||||
try (BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(connection.getInputStream()))) {
|
||||
String line;
|
||||
while ((line = bufferedReader.readLine()) != null) {
|
||||
builder.append(line);
|
||||
}
|
||||
}
|
||||
|
||||
if (logResponseStatusText) {
|
||||
plugin.getLogger().info("Sent data to bStats and received response: " + builder);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gzips the given String.
|
||||
*
|
||||
* @param str The string to gzip.
|
||||
* @return The gzipped String.
|
||||
* @throws IOException If the compression failed.
|
||||
*/
|
||||
private static byte[] compress(final String str) throws IOException {
|
||||
if (str == null) {
|
||||
return null;
|
||||
}
|
||||
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
|
||||
try (GZIPOutputStream gzip = new GZIPOutputStream(outputStream)) {
|
||||
gzip.write(str.getBytes(StandardCharsets.UTF_8));
|
||||
}
|
||||
return outputStream.toByteArray();
|
||||
}
|
||||
|
||||
/**
|
||||
* Represents a custom chart.
|
||||
*/
|
||||
public static abstract class CustomChart {
|
||||
|
||||
// The id of the chart
|
||||
private final String chartId;
|
||||
|
||||
/**
|
||||
* Class constructor.
|
||||
*
|
||||
* @param chartId The id of the chart.
|
||||
*/
|
||||
CustomChart(String chartId) {
|
||||
if (chartId == null || chartId.isEmpty()) {
|
||||
throw new IllegalArgumentException("ChartId cannot be null or empty!");
|
||||
}
|
||||
this.chartId = chartId;
|
||||
}
|
||||
|
||||
private JsonObject getRequestJsonObject(Logger logger, boolean logFailedRequests) {
|
||||
JsonObject chart = new JsonObject();
|
||||
chart.addProperty("chartId", chartId);
|
||||
try {
|
||||
JsonObject data = getChartData();
|
||||
if (data == null) {
|
||||
// If the data is null we don't send the chart.
|
||||
return null;
|
||||
}
|
||||
chart.add("data", data);
|
||||
} catch (Throwable t) {
|
||||
if (logFailedRequests) {
|
||||
logger.log(Level.WARNING, "Failed to get data for custom chart with id " + chartId, t);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
return chart;
|
||||
}
|
||||
|
||||
protected abstract JsonObject getChartData() throws Exception;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Represents a custom simple pie.
|
||||
*/
|
||||
public static class SimplePie extends CustomChart {
|
||||
|
||||
private final Callable<String> callable;
|
||||
|
||||
/**
|
||||
* Class constructor.
|
||||
*
|
||||
* @param chartId The id of the chart.
|
||||
* @param callable The callable which is used to request the chart data.
|
||||
*/
|
||||
public SimplePie(String chartId, Callable<String> callable) {
|
||||
super(chartId);
|
||||
this.callable = callable;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected JsonObject getChartData() throws Exception {
|
||||
JsonObject data = new JsonObject();
|
||||
String value = callable.call();
|
||||
if (value == null || value.isEmpty()) {
|
||||
// Null = skip the chart
|
||||
return null;
|
||||
}
|
||||
data.addProperty("value", value);
|
||||
return data;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Represents a custom advanced pie.
|
||||
*/
|
||||
public static class AdvancedPie extends CustomChart {
|
||||
|
||||
private final Callable<Map<String, Integer>> callable;
|
||||
|
||||
/**
|
||||
* Class constructor.
|
||||
*
|
||||
* @param chartId The id of the chart.
|
||||
* @param callable The callable which is used to request the chart data.
|
||||
*/
|
||||
public AdvancedPie(String chartId, Callable<Map<String, Integer>> callable) {
|
||||
super(chartId);
|
||||
this.callable = callable;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected JsonObject getChartData() throws Exception {
|
||||
JsonObject data = new JsonObject();
|
||||
JsonObject values = new JsonObject();
|
||||
Map<String, Integer> map = callable.call();
|
||||
if (map == null || map.isEmpty()) {
|
||||
// Null = skip the chart
|
||||
return null;
|
||||
}
|
||||
boolean allSkipped = true;
|
||||
for (Map.Entry<String, Integer> entry : map.entrySet()) {
|
||||
if (entry.getValue() == 0) {
|
||||
continue; // Skip this invalid
|
||||
}
|
||||
allSkipped = false;
|
||||
values.addProperty(entry.getKey(), entry.getValue());
|
||||
}
|
||||
if (allSkipped) {
|
||||
// Null = skip the chart
|
||||
return null;
|
||||
}
|
||||
data.add("values", values);
|
||||
return data;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Represents a custom drilldown pie.
|
||||
*/
|
||||
public static class DrilldownPie extends CustomChart {
|
||||
|
||||
private final Callable<Map<String, Map<String, Integer>>> callable;
|
||||
|
||||
/**
|
||||
* Class constructor.
|
||||
*
|
||||
* @param chartId The id of the chart.
|
||||
* @param callable The callable which is used to request the chart data.
|
||||
*/
|
||||
public DrilldownPie(String chartId, Callable<Map<String, Map<String, Integer>>> callable) {
|
||||
super(chartId);
|
||||
this.callable = callable;
|
||||
}
|
||||
|
||||
@Override
|
||||
public JsonObject getChartData() throws Exception {
|
||||
JsonObject data = new JsonObject();
|
||||
JsonObject values = new JsonObject();
|
||||
Map<String, Map<String, Integer>> map = callable.call();
|
||||
if (map == null || map.isEmpty()) {
|
||||
// Null = skip the chart
|
||||
return null;
|
||||
}
|
||||
boolean reallyAllSkipped = true;
|
||||
for (Map.Entry<String, Map<String, Integer>> entryValues : map.entrySet()) {
|
||||
JsonObject value = new JsonObject();
|
||||
boolean allSkipped = true;
|
||||
for (Map.Entry<String, Integer> valueEntry : map.get(entryValues.getKey()).entrySet()) {
|
||||
value.addProperty(valueEntry.getKey(), valueEntry.getValue());
|
||||
allSkipped = false;
|
||||
}
|
||||
if (!allSkipped) {
|
||||
reallyAllSkipped = false;
|
||||
values.add(entryValues.getKey(), value);
|
||||
}
|
||||
}
|
||||
if (reallyAllSkipped) {
|
||||
// Null = skip the chart
|
||||
return null;
|
||||
}
|
||||
data.add("values", values);
|
||||
return data;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Represents a custom single line chart.
|
||||
*/
|
||||
public static class SingleLineChart extends CustomChart {
|
||||
|
||||
private final Callable<Integer> callable;
|
||||
|
||||
/**
|
||||
* Class constructor.
|
||||
*
|
||||
* @param chartId The id of the chart.
|
||||
* @param callable The callable which is used to request the chart data.
|
||||
*/
|
||||
public SingleLineChart(String chartId, Callable<Integer> callable) {
|
||||
super(chartId);
|
||||
this.callable = callable;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected JsonObject getChartData() throws Exception {
|
||||
JsonObject data = new JsonObject();
|
||||
int value = callable.call();
|
||||
if (value == 0) {
|
||||
// Null = skip the chart
|
||||
return null;
|
||||
}
|
||||
data.addProperty("value", value);
|
||||
return data;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Represents a custom multi line chart.
|
||||
*/
|
||||
public static class MultiLineChart extends CustomChart {
|
||||
|
||||
private final Callable<Map<String, Integer>> callable;
|
||||
|
||||
/**
|
||||
* Class constructor.
|
||||
*
|
||||
* @param chartId The id of the chart.
|
||||
* @param callable The callable which is used to request the chart data.
|
||||
*/
|
||||
public MultiLineChart(String chartId, Callable<Map<String, Integer>> callable) {
|
||||
super(chartId);
|
||||
this.callable = callable;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected JsonObject getChartData() throws Exception {
|
||||
JsonObject data = new JsonObject();
|
||||
JsonObject values = new JsonObject();
|
||||
Map<String, Integer> map = callable.call();
|
||||
if (map == null || map.isEmpty()) {
|
||||
// Null = skip the chart
|
||||
return null;
|
||||
}
|
||||
boolean allSkipped = true;
|
||||
for (Map.Entry<String, Integer> entry : map.entrySet()) {
|
||||
if (entry.getValue() == 0) {
|
||||
continue; // Skip this invalid
|
||||
}
|
||||
allSkipped = false;
|
||||
values.addProperty(entry.getKey(), entry.getValue());
|
||||
}
|
||||
if (allSkipped) {
|
||||
// Null = skip the chart
|
||||
return null;
|
||||
}
|
||||
data.add("values", values);
|
||||
return data;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Represents a custom simple bar chart.
|
||||
*/
|
||||
public static class SimpleBarChart extends CustomChart {
|
||||
|
||||
private final Callable<Map<String, Integer>> callable;
|
||||
|
||||
/**
|
||||
* Class constructor.
|
||||
*
|
||||
* @param chartId The id of the chart.
|
||||
* @param callable The callable which is used to request the chart data.
|
||||
*/
|
||||
public SimpleBarChart(String chartId, Callable<Map<String, Integer>> callable) {
|
||||
super(chartId);
|
||||
this.callable = callable;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected JsonObject getChartData() throws Exception {
|
||||
JsonObject data = new JsonObject();
|
||||
JsonObject values = new JsonObject();
|
||||
Map<String, Integer> map = callable.call();
|
||||
if (map == null || map.isEmpty()) {
|
||||
// Null = skip the chart
|
||||
return null;
|
||||
}
|
||||
for (Map.Entry<String, Integer> entry : map.entrySet()) {
|
||||
JsonArray categoryValues = new JsonArray();
|
||||
categoryValues.add(new JsonPrimitive(entry.getValue()));
|
||||
values.add(entry.getKey(), categoryValues);
|
||||
}
|
||||
data.add("values", values);
|
||||
return data;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Represents a custom advanced bar chart.
|
||||
*/
|
||||
public static class AdvancedBarChart extends CustomChart {
|
||||
|
||||
private final Callable<Map<String, int[]>> callable;
|
||||
|
||||
/**
|
||||
* Class constructor.
|
||||
*
|
||||
* @param chartId The id of the chart.
|
||||
* @param callable The callable which is used to request the chart data.
|
||||
*/
|
||||
public AdvancedBarChart(String chartId, Callable<Map<String, int[]>> callable) {
|
||||
super(chartId);
|
||||
this.callable = callable;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected JsonObject getChartData() throws Exception {
|
||||
JsonObject data = new JsonObject();
|
||||
JsonObject values = new JsonObject();
|
||||
Map<String, int[]> map = callable.call();
|
||||
if (map == null || map.isEmpty()) {
|
||||
// Null = skip the chart
|
||||
return null;
|
||||
}
|
||||
boolean allSkipped = true;
|
||||
for (Map.Entry<String, int[]> entry : map.entrySet()) {
|
||||
if (entry.getValue().length == 0) {
|
||||
continue; // Skip this invalid
|
||||
}
|
||||
allSkipped = false;
|
||||
JsonArray categoryValues = new JsonArray();
|
||||
for (int categoryValue : entry.getValue()) {
|
||||
categoryValues.add(new JsonPrimitive(categoryValue));
|
||||
}
|
||||
values.add(entry.getKey(), categoryValues);
|
||||
}
|
||||
if (allSkipped) {
|
||||
// Null = skip the chart
|
||||
return null;
|
||||
}
|
||||
data.add("values", values);
|
||||
return data;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
+2
-2
@@ -1,7 +1,7 @@
|
||||
package com.Ben12345rocks.VotingPlugin.bungee;
|
||||
package com.bencodez.votingplugin.bungee;
|
||||
|
||||
public enum BungeeMethod {
|
||||
SOCKETS, PLUGINMESSAGING, MYSQL;
|
||||
MYSQL, PLUGINMESSAGING, SOCKETS;
|
||||
|
||||
public static BungeeMethod getByName(String str) {
|
||||
for (BungeeMethod method : values()) {
|
||||
+104
-100
@@ -1,4 +1,4 @@
|
||||
package com.Ben12345rocks.VotingPlugin.bungee;
|
||||
package com.bencodez.votingplugin.bungee;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
@@ -6,30 +6,31 @@ import java.sql.ResultSet;
|
||||
import java.sql.ResultSetMetaData;
|
||||
import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import com.Ben12345rocks.AdvancedCore.UserStorage.mysql.api.queries.Query;
|
||||
import com.Ben12345rocks.AdvancedCore.UserStorage.sql.Column;
|
||||
import com.Ben12345rocks.AdvancedCore.UserStorage.sql.DataType;
|
||||
import com.bencodez.advancedcore.api.user.userstorage.mysql.api.queries.Query;
|
||||
import com.bencodez.advancedcore.api.user.userstorage.sql.Column;
|
||||
import com.bencodez.advancedcore.api.user.userstorage.sql.DataType;
|
||||
|
||||
import net.md_5.bungee.config.Configuration;
|
||||
|
||||
public class BungeeMySQL {
|
||||
private com.Ben12345rocks.AdvancedCore.UserStorage.mysql.api.MySQL mysql;
|
||||
|
||||
private List<String> columns = Collections.synchronizedList(new ArrayList<String>());
|
||||
|
||||
private List<String> intColumns = new ArrayList<String>();
|
||||
|
||||
// private HashMap<String, ArrayList<Column>> table;
|
||||
|
||||
// ConcurrentMap<String, ArrayList<Column>> table = new
|
||||
// ConcurrentHashMap<String, ArrayList<Column>>();
|
||||
|
||||
private String name;
|
||||
private com.bencodez.advancedcore.api.user.userstorage.mysql.api.MySQL mysql;
|
||||
|
||||
private Set<String> uuids = Collections.synchronizedSet(new HashSet<String>());
|
||||
private String name;
|
||||
|
||||
private Object object2 = new Object();
|
||||
|
||||
@@ -37,7 +38,7 @@ public class BungeeMySQL {
|
||||
|
||||
private Object object4 = new Object();
|
||||
|
||||
private List<String> intColumns = new ArrayList<String>();
|
||||
private Set<String> uuids = Collections.synchronizedSet(new HashSet<String>());
|
||||
|
||||
public BungeeMySQL(String tableName, Configuration section) {
|
||||
String tablePrefix = section.getString("Prefix");
|
||||
@@ -53,6 +54,7 @@ public class BungeeMySQL {
|
||||
maxThreads = 1;
|
||||
}
|
||||
boolean useSSL = section.getBoolean("UseSSL", false);
|
||||
boolean publicKeyRetrieval = section.getBoolean("PublicKeyRetrieval", false);
|
||||
if (!section.getString("Name", "").isEmpty()) {
|
||||
tableName = section.getString("Name", "");
|
||||
}
|
||||
@@ -61,8 +63,8 @@ public class BungeeMySQL {
|
||||
if (tablePrefix != null) {
|
||||
name = tablePrefix + tableName;
|
||||
}
|
||||
mysql = new com.Ben12345rocks.AdvancedCore.UserStorage.mysql.api.MySQL(maxThreads);
|
||||
if (!mysql.connect(hostName, "" + port, user, pass, database, useSSL, lifeTime, str)) {
|
||||
mysql = new com.bencodez.advancedcore.api.user.userstorage.mysql.api.MySQL(maxThreads);
|
||||
if (!mysql.connect(hostName, "" + port, user, pass, database, useSSL, lifeTime, str, publicKeyRetrieval)) {
|
||||
|
||||
}
|
||||
try {
|
||||
@@ -157,26 +159,19 @@ public class BungeeMySQL {
|
||||
|
||||
public boolean containsKeyQuery(String index) {
|
||||
String sqlStr = "SELECT uuid FROM " + getName() + ";";
|
||||
try {
|
||||
ResultSet rs = null;
|
||||
|
||||
Connection conn = mysql.getConnectionManager().getConnection();
|
||||
PreparedStatement sql = conn.prepareStatement(sqlStr);
|
||||
|
||||
rs = sql.executeQuery();
|
||||
try (Connection conn = mysql.getConnectionManager().getConnection();
|
||||
PreparedStatement sql = conn.prepareStatement(sqlStr)) {
|
||||
ResultSet rs = sql.executeQuery();
|
||||
/*
|
||||
* Query query = new Query(mysql, sql);
|
||||
* ResultSet rs = query.executeQuery();
|
||||
* Query query = new Query(mysql, sql); ResultSet rs = query.executeQuery();
|
||||
*/
|
||||
while (rs.next()) {
|
||||
if (rs.getString("uuid").equals(index)) {
|
||||
sql.close();
|
||||
conn.close();
|
||||
rs.close();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
sql.close();
|
||||
conn.close();
|
||||
rs.close();
|
||||
} catch (SQLException ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
@@ -192,16 +187,12 @@ public class BungeeMySQL {
|
||||
|
||||
public ArrayList<String> getColumnsQueury() {
|
||||
ArrayList<String> columns = new ArrayList<String>();
|
||||
try {
|
||||
ResultSet rs = null;
|
||||
|
||||
Connection conn = mysql.getConnectionManager().getConnection();
|
||||
PreparedStatement sql = conn.prepareStatement("SELECT * FROM " + getName() + ";");
|
||||
|
||||
rs = sql.executeQuery();
|
||||
try (Connection conn = mysql.getConnectionManager().getConnection();
|
||||
PreparedStatement sql = conn.prepareStatement("SELECT * FROM " + getName() + ";")) {
|
||||
ResultSet rs = sql.executeQuery();
|
||||
/*
|
||||
* Query query = new Query(mysql, "SELECT * FROM " + getName() + ";");
|
||||
* ResultSet rs = query.executeQuery();
|
||||
* Query query = new Query(mysql, "SELECT * FROM " + getName() + ";"); ResultSet
|
||||
* rs = query.executeQuery();
|
||||
*/
|
||||
|
||||
ResultSetMetaData metadata = rs.getMetaData();
|
||||
@@ -213,12 +204,10 @@ public class BungeeMySQL {
|
||||
String columnName = metadata.getColumnName(i);
|
||||
columns.add(columnName);
|
||||
}
|
||||
sql.close();
|
||||
conn.close();
|
||||
rs.close();
|
||||
return columns;
|
||||
}
|
||||
sql.close();
|
||||
conn.close();
|
||||
rs.close();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
@@ -231,18 +220,13 @@ public class BungeeMySQL {
|
||||
String query = "SELECT * FROM " + getName() + " WHERE `" + column.getName() + "`='"
|
||||
+ column.getValue().toString() + "';";
|
||||
|
||||
try {
|
||||
ResultSet rs = null;
|
||||
|
||||
Connection conn = mysql.getConnectionManager().getConnection();
|
||||
PreparedStatement sql = conn.prepareStatement(query);
|
||||
|
||||
rs = sql.executeQuery();
|
||||
try (Connection conn = mysql.getConnectionManager().getConnection();
|
||||
PreparedStatement sql = conn.prepareStatement(query)) {
|
||||
ResultSet rs = sql.executeQuery();
|
||||
|
||||
/*
|
||||
* Query sql = new Query(mysql, query);
|
||||
* sql.setParameter(1, column.getValue().toString());
|
||||
* ResultSet rs = sql.executeQuery();
|
||||
* Query sql = new Query(mysql, query); sql.setParameter(1,
|
||||
* column.getValue().toString()); ResultSet rs = sql.executeQuery();
|
||||
*/
|
||||
if (rs.next()) {
|
||||
for (int i = 1; i <= rs.getMetaData().getColumnCount(); i++) {
|
||||
@@ -260,8 +244,7 @@ public class BungeeMySQL {
|
||||
result.add(rCol);
|
||||
}
|
||||
}
|
||||
sql.close();
|
||||
conn.close();
|
||||
rs.close();
|
||||
return result;
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
@@ -296,16 +279,11 @@ public class BungeeMySQL {
|
||||
ArrayList<Column> result = new ArrayList<Column>();
|
||||
String sqlStr = "SELECT PlayerName FROM " + getName() + ";";
|
||||
|
||||
try {
|
||||
ResultSet rs = null;
|
||||
|
||||
Connection conn = mysql.getConnectionManager().getConnection();
|
||||
PreparedStatement sql = conn.prepareStatement(sqlStr);
|
||||
|
||||
rs = sql.executeQuery();
|
||||
try (Connection conn = mysql.getConnectionManager().getConnection();
|
||||
PreparedStatement sql = conn.prepareStatement(sqlStr)) {
|
||||
ResultSet rs = sql.executeQuery();
|
||||
/*
|
||||
* Query query = new Query(mysql, sql);
|
||||
* ResultSet rs = query.executeQuery();
|
||||
* Query query = new Query(mysql, sql); ResultSet rs = query.executeQuery();
|
||||
*/
|
||||
|
||||
while (rs.next()) {
|
||||
@@ -324,24 +302,18 @@ public class BungeeMySQL {
|
||||
ArrayList<Column> result = new ArrayList<Column>();
|
||||
String sqlStr = "SELECT uuid FROM " + getName() + ";";
|
||||
|
||||
try {
|
||||
ResultSet rs = null;
|
||||
|
||||
Connection conn = mysql.getConnectionManager().getConnection();
|
||||
PreparedStatement sql = conn.prepareStatement(sqlStr);
|
||||
|
||||
rs = sql.executeQuery();
|
||||
try (Connection conn = mysql.getConnectionManager().getConnection();
|
||||
PreparedStatement sql = conn.prepareStatement(sqlStr)) {
|
||||
ResultSet rs = sql.executeQuery();
|
||||
/*
|
||||
* Query query = new Query(mysql, sql);
|
||||
* ResultSet rs = query.executeQuery();
|
||||
* Query query = new Query(mysql, sql); ResultSet rs = query.executeQuery();
|
||||
*/
|
||||
|
||||
while (rs.next()) {
|
||||
Column rCol = new Column("uuid", rs.getString("uuid"), DataType.STRING);
|
||||
result.add(rCol);
|
||||
}
|
||||
sql.close();
|
||||
conn.close();
|
||||
rs.close();
|
||||
} catch (SQLException e) {
|
||||
return null;
|
||||
}
|
||||
@@ -351,27 +323,20 @@ public class BungeeMySQL {
|
||||
|
||||
public String getUUID(String playerName) {
|
||||
String query = "SELECT uuid FROM " + getName() + " WHERE " + "PlayerName" + "='" + playerName + "';";
|
||||
try {
|
||||
ResultSet rs = null;
|
||||
|
||||
Connection conn = mysql.getConnectionManager().getConnection();
|
||||
PreparedStatement sql = conn.prepareStatement(query);
|
||||
|
||||
rs = sql.executeQuery();
|
||||
try (Connection conn = mysql.getConnectionManager().getConnection();
|
||||
PreparedStatement sql = conn.prepareStatement(query)) {
|
||||
ResultSet rs = sql.executeQuery();
|
||||
/*
|
||||
* Query sql = new Query(mysql, query);
|
||||
* ResultSet rs = sql.executeQuery();
|
||||
* Query sql = new Query(mysql, query); ResultSet rs = sql.executeQuery();
|
||||
*/
|
||||
if (rs.next()) {
|
||||
String uuid = rs.getString("uuid");
|
||||
if (uuid != null && !uuid.isEmpty()) {
|
||||
sql.close();
|
||||
conn.close();
|
||||
rs.close();
|
||||
return uuid;
|
||||
}
|
||||
}
|
||||
sql.close();
|
||||
conn.close();
|
||||
rs.close();
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
} catch (ArrayIndexOutOfBoundsException e) {
|
||||
@@ -400,25 +365,31 @@ public class BungeeMySQL {
|
||||
}
|
||||
|
||||
public void insert(String index, String column, Object value, DataType dataType) {
|
||||
insertQuery(index, column, value, dataType);
|
||||
|
||||
insertQuery(index, Arrays.asList(new Column(column, value, dataType)));
|
||||
}
|
||||
|
||||
public void insertQuery(String index, String column, Object value, DataType dataType) {
|
||||
synchronized (object2) {
|
||||
String query = "INSERT " + getName() + " ";
|
||||
public void insertQuery(String index, List<Column> cols) {
|
||||
String query = "INSERT " + getName() + " ";
|
||||
|
||||
query += "set uuid='" + index + "', ";
|
||||
query += column + "='" + value.toString() + "';";
|
||||
// AdvancedCorePlugin.getInstance().extraDebug(query);
|
||||
query += "set uuid='" + index + "', ";
|
||||
|
||||
try {
|
||||
uuids.add(index);
|
||||
new Query(mysql, query).executeUpdateAsync();
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
for (int i = 0; i < cols.size(); i++) {
|
||||
Column col = cols.get(i);
|
||||
if (i == cols.size() - 1) {
|
||||
query += col.getName() + "='" + col.getValue().toString() + "';";
|
||||
} else {
|
||||
query += col.getName() + "='" + col.getValue().toString() + "', ";
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
try {
|
||||
uuids.add(index);
|
||||
new Query(mysql, query).executeUpdateAsync();
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public boolean isIntColumn(String key) {
|
||||
@@ -427,13 +398,46 @@ public class BungeeMySQL {
|
||||
|
||||
public void loadData() {
|
||||
columns = getColumnsQueury();
|
||||
}
|
||||
|
||||
try {
|
||||
Connection con = mysql.getConnectionManager().getConnection();
|
||||
con.close();
|
||||
public void update(String index, List<Column> cols, boolean queue) {
|
||||
for (Column col : cols) {
|
||||
checkColumn(col.getName(), col.getDataType());
|
||||
}
|
||||
if (getUuids().contains(index)) {
|
||||
synchronized (object2) {
|
||||
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
String query = "UPDATE " + getName() + " SET ";
|
||||
|
||||
for (int i = 0; i < cols.size(); i++) {
|
||||
Column col = cols.get(i);
|
||||
if (i == cols.size() - 1) {
|
||||
if (col.getDataType().equals(DataType.STRING)) {
|
||||
query += col.getName() + "='" + col.getValue().toString() + "';";
|
||||
} else {
|
||||
query += col.getName() + "=" + col.getValue().toString() + ";";
|
||||
}
|
||||
} else {
|
||||
if (col.getDataType().equals(DataType.STRING)) {
|
||||
query += col.getName() + "='" + col.getValue().toString() + "', ";
|
||||
} else {
|
||||
query += col.getName() + "=" + col.getValue().toString() + ", ";
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
query += " WHERE `uuid`=";
|
||||
query += "'" + index + "';";
|
||||
|
||||
try {
|
||||
Query q = new Query(mysql, query);
|
||||
q.executeUpdateAsync();
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
} else {
|
||||
insertQuery(index, cols);
|
||||
}
|
||||
}
|
||||
|
||||
+3
-7
@@ -1,4 +1,4 @@
|
||||
package com.Ben12345rocks.VotingPlugin.bungee;
|
||||
package com.bencodez.votingplugin.bungee;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
@@ -13,11 +13,11 @@ import net.md_5.bungee.config.ConfigurationProvider;
|
||||
import net.md_5.bungee.config.YamlConfiguration;
|
||||
|
||||
public class Config {
|
||||
private Bungee bungee;
|
||||
private VotingPluginBungee bungee;
|
||||
@Getter
|
||||
private Configuration data;
|
||||
|
||||
public Config(Bungee bungee) {
|
||||
public Config(VotingPluginBungee bungee) {
|
||||
this.bungee = bungee;
|
||||
}
|
||||
|
||||
@@ -49,10 +49,6 @@ public class Config {
|
||||
return getData().getString("FallBackServer", "");
|
||||
}
|
||||
|
||||
public boolean getSendToOnlineServer() {
|
||||
return getData().getBoolean("SendToOnlineServer");
|
||||
}
|
||||
|
||||
public boolean getSendVotesToAllServers() {
|
||||
return getData().getBoolean("SendVotesToAllServers");
|
||||
}
|
||||
+7
-4
@@ -1,4 +1,4 @@
|
||||
package com.Ben12345rocks.VotingPlugin.bungee;
|
||||
package com.bencodez.votingplugin.bungee;
|
||||
|
||||
import lombok.Getter;
|
||||
|
||||
@@ -7,20 +7,23 @@ public class OfflineBungeeVote {
|
||||
@Getter
|
||||
private String playerName;
|
||||
@Getter
|
||||
private String uuid;
|
||||
private boolean realVote;
|
||||
@Getter
|
||||
private String service;
|
||||
@Getter
|
||||
private String text;
|
||||
@Getter
|
||||
private long time;
|
||||
@Getter
|
||||
private boolean realVote;
|
||||
private String uuid;
|
||||
|
||||
public OfflineBungeeVote(String playerName, String uuid, String service, long time, boolean realVote) {
|
||||
public OfflineBungeeVote(String playerName, String uuid, String service, long time, boolean realVote, String text) {
|
||||
this.playerName = playerName;
|
||||
this.uuid = uuid;
|
||||
this.service = service;
|
||||
this.time = time;
|
||||
this.realVote = realVote;
|
||||
this.text = text;
|
||||
}
|
||||
|
||||
}
|
||||
+5
-3
@@ -1,4 +1,4 @@
|
||||
package com.Ben12345rocks.VotingPlugin.bungee;
|
||||
package com.bencodez.votingplugin.bungee;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
@@ -10,11 +10,11 @@ import net.md_5.bungee.config.ConfigurationProvider;
|
||||
import net.md_5.bungee.config.YamlConfiguration;
|
||||
|
||||
public class VoteCache {
|
||||
private Bungee bungee;
|
||||
private VotingPluginBungee bungee;
|
||||
@Getter
|
||||
private Configuration data;
|
||||
|
||||
public VoteCache(Bungee bungee) {
|
||||
public VoteCache(VotingPluginBungee bungee) {
|
||||
this.bungee = bungee;
|
||||
}
|
||||
|
||||
@@ -25,6 +25,7 @@ public class VoteCache {
|
||||
section.set("UUID", voteData.getUuid());
|
||||
section.set("Time", voteData.getTime());
|
||||
section.set("Real", voteData.isRealVote());
|
||||
section.set("Text", voteData.getText());
|
||||
save();
|
||||
}
|
||||
|
||||
@@ -35,6 +36,7 @@ public class VoteCache {
|
||||
section.set("UUID", voteData.getUuid());
|
||||
section.set("Time", voteData.getTime());
|
||||
section.set("Real", voteData.isRealVote());
|
||||
section.set("Text", voteData.getText());
|
||||
save();
|
||||
}
|
||||
|
||||
+80
-55
@@ -1,4 +1,4 @@
|
||||
package com.Ben12345rocks.VotingPlugin.bungee;
|
||||
package com.bencodez.votingplugin.bungee;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.ByteArrayInputStream;
|
||||
@@ -19,13 +19,13 @@ import java.util.Map.Entry;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import com.Ben12345rocks.AdvancedCore.UserStorage.sql.Column;
|
||||
import com.Ben12345rocks.AdvancedCore.UserStorage.sql.DataType;
|
||||
import com.Ben12345rocks.AdvancedCore.Util.Encryption.EncryptionHandler;
|
||||
import com.Ben12345rocks.AdvancedCore.Util.Misc.ArrayUtils;
|
||||
import com.Ben12345rocks.AdvancedCore.Util.Sockets.ClientHandler;
|
||||
import com.Ben12345rocks.AdvancedCore.Util.Sockets.SocketHandler;
|
||||
import com.Ben12345rocks.AdvancedCore.Util.Sockets.SocketReceiver;
|
||||
import com.bencodez.advancedcore.api.misc.ArrayUtils;
|
||||
import com.bencodez.advancedcore.api.misc.encryption.EncryptionHandler;
|
||||
import com.bencodez.advancedcore.api.user.userstorage.sql.Column;
|
||||
import com.bencodez.advancedcore.api.user.userstorage.sql.DataType;
|
||||
import com.bencodez.advancedcore.bungeeapi.sockets.ClientHandler;
|
||||
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;
|
||||
@@ -42,39 +42,39 @@ import net.md_5.bungee.api.plugin.Plugin;
|
||||
import net.md_5.bungee.config.Configuration;
|
||||
import net.md_5.bungee.event.EventHandler;
|
||||
|
||||
public class Bungee extends Plugin implements net.md_5.bungee.api.plugin.Listener {
|
||||
public class VotingPluginBungee extends Plugin implements net.md_5.bungee.api.plugin.Listener {
|
||||
|
||||
private HashMap<String, ArrayList<OfflineBungeeVote>> cachedOnlineVotes = new HashMap<String, ArrayList<OfflineBungeeVote>>();
|
||||
|
||||
private HashMap<String, ArrayList<OfflineBungeeVote>> cachedVotes = new HashMap<String, ArrayList<OfflineBungeeVote>>();
|
||||
|
||||
private HashMap<String, ClientHandler> clientHandles;
|
||||
|
||||
@Getter
|
||||
private Config config;
|
||||
|
||||
@Getter
|
||||
private BungeeMySQL mysql;
|
||||
|
||||
private SocketHandler socketHandler;
|
||||
|
||||
private HashMap<String, ClientHandler> clientHandles;
|
||||
|
||||
private EncryptionHandler encryptionHandler;
|
||||
|
||||
@Getter
|
||||
private BungeeMethod method;
|
||||
|
||||
private HashMap<String, ArrayList<OfflineBungeeVote>> cachedVotes = new HashMap<String, ArrayList<OfflineBungeeVote>>();
|
||||
@Getter
|
||||
private BungeeMySQL mysql;
|
||||
|
||||
private HashMap<String, ArrayList<OfflineBungeeVote>> cachedOnlineVotes = new HashMap<String, ArrayList<OfflineBungeeVote>>();
|
||||
private SocketHandler socketHandler;
|
||||
|
||||
private VoteCache voteCacheFile;
|
||||
|
||||
public void checkCachedVotes(String server) {
|
||||
if (getProxy().getServerInfo(server) != null) {
|
||||
if (!getProxy().getServerInfo(server).getPlayers().isEmpty()) {
|
||||
if (cachedVotes.containsKey(server)) {
|
||||
if (cachedVotes.containsKey(server) && !config.getBlockedServers().contains(server)) {
|
||||
ArrayList<OfflineBungeeVote> c = cachedVotes.get(server);
|
||||
if (!c.isEmpty()) {
|
||||
for (OfflineBungeeVote cache : c) {
|
||||
sendPluginMessageServer(server, "Vote", cache.getPlayerName(), cache.getUuid(),
|
||||
cache.getService(), "" + cache.getTime(), Boolean.FALSE.toString(),
|
||||
"" + cache.isRealVote());
|
||||
"" + cache.isRealVote(), cache.getText());
|
||||
}
|
||||
cachedVotes.put(server, new ArrayList<OfflineBungeeVote>());
|
||||
}
|
||||
@@ -87,12 +87,16 @@ public class Bungee extends Plugin implements net.md_5.bungee.api.plugin.Listene
|
||||
if (player != null && player.isConnected() && cachedOnlineVotes.containsKey(uuid)) {
|
||||
ArrayList<OfflineBungeeVote> c = cachedOnlineVotes.get(uuid);
|
||||
if (!c.isEmpty()) {
|
||||
for (OfflineBungeeVote cache : c) {
|
||||
sendPluginMessageServer(getProxy().getPlayer(UUID.fromString(uuid)).getServer().getInfo().getName(),
|
||||
"VoteOnline", cache.getPlayerName(), cache.getUuid(), cache.getService(),
|
||||
"" + cache.getTime(), Boolean.FALSE.toString(), "" + cache.isRealVote());
|
||||
String server = getProxy().getPlayer(UUID.fromString(uuid)).getServer().getInfo().getName();
|
||||
if (!config.getBlockedServers().contains(server)) {
|
||||
for (OfflineBungeeVote cache : c) {
|
||||
|
||||
sendPluginMessageServer(server, "VoteOnline", cache.getPlayerName(), cache.getUuid(),
|
||||
cache.getService(), "" + cache.getTime(), Boolean.FALSE.toString(),
|
||||
"" + cache.isRealVote(), cache.getText());
|
||||
}
|
||||
cachedOnlineVotes.put(uuid, new ArrayList<OfflineBungeeVote>());
|
||||
}
|
||||
cachedOnlineVotes.put(uuid, new ArrayList<OfflineBungeeVote>());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -146,6 +150,36 @@ public class Bungee extends Plugin implements net.md_5.bungee.api.plugin.Listene
|
||||
return "";
|
||||
}
|
||||
|
||||
private int getValue(ArrayList<Column> cols, String column) {
|
||||
for (Column d : cols) {
|
||||
if (d.getName().equalsIgnoreCase(column)) {
|
||||
|
||||
Object value = d.getValue();
|
||||
int num = 0;
|
||||
if (value instanceof Integer) {
|
||||
try {
|
||||
num = (int) value;
|
||||
} catch (ClassCastException | NullPointerException ex) {
|
||||
}
|
||||
} else if (value instanceof String) {
|
||||
try {
|
||||
num = Integer.parseInt((String) value);
|
||||
} catch (Exception e) {
|
||||
}
|
||||
}
|
||||
return num;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
private int mysqlUpdate(ArrayList<Column> cols, String uuid, String column, int toAdd) {
|
||||
int num = getValue(cols, column) + toAdd;
|
||||
debug("Setting " + column + " to " + num + " for " + uuid);
|
||||
mysql.update(uuid, column, num, DataType.INTEGER);
|
||||
return num;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDisable() {
|
||||
if (method.equals(BungeeMethod.PLUGINMESSAGING)) {
|
||||
@@ -218,7 +252,8 @@ public class Bungee extends Plugin implements net.md_5.bungee.api.plugin.Listene
|
||||
for (String num : voteCacheFile.getServerVotes(server)) {
|
||||
Configuration data = voteCacheFile.getServerVotes(server, num);
|
||||
vote.add(new OfflineBungeeVote(data.getString("Name"), data.getString("UUID"),
|
||||
data.getString("Service"), data.getLong("Time"), data.getBoolean("Real")));
|
||||
data.getString("Service"), data.getLong("Time"), data.getBoolean("Real"),
|
||||
data.getString("Text")));
|
||||
}
|
||||
cachedVotes.put(server, vote);
|
||||
}
|
||||
@@ -232,7 +267,8 @@ public class Bungee extends Plugin implements net.md_5.bungee.api.plugin.Listene
|
||||
for (String num : voteCacheFile.getServerVotes(player)) {
|
||||
Configuration data = voteCacheFile.getOnlineVotes(player, num);
|
||||
vote.add(new OfflineBungeeVote(data.getString("Name"), data.getString("UUID"),
|
||||
data.getString("Service"), data.getLong("Time"), data.getBoolean("Real")));
|
||||
data.getString("Service"), data.getLong("Time"), data.getBoolean("Real"),
|
||||
data.getString("Text")));
|
||||
}
|
||||
cachedOnlineVotes.put(player, vote);
|
||||
}
|
||||
@@ -303,6 +339,14 @@ public class Bungee extends Plugin implements net.md_5.bungee.api.plugin.Listene
|
||||
}
|
||||
}
|
||||
|
||||
BStatsMetricsBungee metrics = new BStatsMetricsBungee(this, 9453);
|
||||
|
||||
metrics.addCustomChart(
|
||||
new BStatsMetricsBungee.SimplePie("bungee_method", () -> getConfig().getBungeeMethod().toString()));
|
||||
|
||||
metrics.addCustomChart(new BStatsMetricsBungee.SimplePie("sendtoallservers",
|
||||
() -> "" + getConfig().getSendVotesToAllServers()));
|
||||
|
||||
getLogger().info("VotingPlugin loaded, using method: " + method.toString());
|
||||
}
|
||||
|
||||
@@ -478,31 +522,11 @@ public class Bungee extends Plugin implements net.md_5.bungee.api.plugin.Listene
|
||||
mysql.update(uuid, "PlayerName", player, DataType.STRING);
|
||||
}
|
||||
|
||||
// add totals here
|
||||
ArrayList<Column> data = mysql.getExactQuery(new Column("uuid", uuid, DataType.STRING));
|
||||
for (Column d : data) {
|
||||
if (d.getName().equalsIgnoreCase("alltimetotal") || d.getName().equalsIgnoreCase("monthtotal")
|
||||
|| d.getName().equalsIgnoreCase("weeklytotal") || d.getName().equalsIgnoreCase("dailytotal")
|
||||
|| d.getName().equalsIgnoreCase("Points") || d.getName().equalsIgnoreCase("MilestoneCount")) {
|
||||
Object value = d.getValue();
|
||||
int num = 0;
|
||||
if (value instanceof Integer) {
|
||||
try {
|
||||
num = (int) value;
|
||||
} catch (ClassCastException | NullPointerException ex) {
|
||||
}
|
||||
} else if (value instanceof String) {
|
||||
try {
|
||||
num = Integer.parseInt((String) value);
|
||||
} catch (Exception e) {
|
||||
}
|
||||
}
|
||||
mysql.update(uuid, d.getName(), num + 1, DataType.STRING);
|
||||
|
||||
debug("Setting " + d.getName() + " to " + (num + 1));
|
||||
|
||||
}
|
||||
}
|
||||
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();
|
||||
|
||||
@@ -516,7 +540,7 @@ public class Bungee extends Plugin implements net.md_5.bungee.api.plugin.Listene
|
||||
cachedVotes.put(s, new ArrayList<OfflineBungeeVote>());
|
||||
}
|
||||
ArrayList<OfflineBungeeVote> list = cachedVotes.get(s);
|
||||
list.add(new OfflineBungeeVote(player, uuid, service, time, realVote));
|
||||
list.add(new OfflineBungeeVote(player, uuid, service, time, realVote, text));
|
||||
cachedVotes.put(s, list);
|
||||
|
||||
debug("Caching vote for " + player + " on " + service + " for " + s);
|
||||
@@ -524,15 +548,16 @@ public class Bungee extends Plugin implements net.md_5.bungee.api.plugin.Listene
|
||||
} else {
|
||||
// send
|
||||
sendPluginMessageServer(s, "Vote", player, uuid, service, "" + time,
|
||||
Boolean.TRUE.toString(), "" + realVote);
|
||||
Boolean.TRUE.toString(), "" + realVote, text);
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
ProxiedPlayer p = getProxy().getPlayer(UUID.fromString(uuid));
|
||||
if (p != null && p.isConnected()) {
|
||||
if (p != null && p.isConnected()
|
||||
&& !config.getBlockedServers().contains(p.getServer().getInfo().getName())) {
|
||||
sendPluginMessageServer(p.getServer().getInfo().getName(), "VoteOnline", player, uuid, service,
|
||||
"" + time, Boolean.TRUE.toString(), "" + realVote);
|
||||
"" + time, Boolean.TRUE.toString(), "" + realVote, text);
|
||||
} else {
|
||||
if (!cachedOnlineVotes.containsKey(uuid)) {
|
||||
cachedOnlineVotes.put(uuid, new ArrayList<OfflineBungeeVote>());
|
||||
@@ -541,7 +566,7 @@ public class Bungee extends Plugin implements net.md_5.bungee.api.plugin.Listene
|
||||
if (list == null) {
|
||||
list = new ArrayList<OfflineBungeeVote>();
|
||||
}
|
||||
list.add(new OfflineBungeeVote(player, uuid, service, time, realVote));
|
||||
list.add(new OfflineBungeeVote(player, uuid, service, time, realVote, text));
|
||||
cachedOnlineVotes.put(uuid, list);
|
||||
debug("Caching online vote for " + player + " on " + service);
|
||||
}
|
||||
+3
-3
@@ -1,13 +1,13 @@
|
||||
package com.Ben12345rocks.VotingPlugin.bungee;
|
||||
package com.bencodez.votingplugin.bungee;
|
||||
|
||||
import net.md_5.bungee.api.CommandSender;
|
||||
import net.md_5.bungee.api.chat.TextComponent;
|
||||
import net.md_5.bungee.api.plugin.Command;
|
||||
|
||||
public class VotingPluginBungeeCommand extends Command {
|
||||
private Bungee bungee;
|
||||
private VotingPluginBungee bungee;
|
||||
|
||||
public VotingPluginBungeeCommand(Bungee bungee) {
|
||||
public VotingPluginBungeeCommand(VotingPluginBungee bungee) {
|
||||
super("votingpluginbungee", "votingplugin.admin");
|
||||
this.bungee = bungee;
|
||||
}
|
||||
+2021
-2425
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,44 @@
|
||||
package com.bencodez.votingplugin.commands.executers;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
import com.bencodez.advancedcore.api.command.CommandHandler;
|
||||
import com.bencodez.votingplugin.VotingPluginMain;
|
||||
|
||||
// TODO: Auto-generated Javadoc
|
||||
/**
|
||||
* The Class CommandAdminVote.
|
||||
*/
|
||||
public class CommandAdminVote implements CommandExecutor {
|
||||
|
||||
private VotingPluginMain plugin;
|
||||
|
||||
public CommandAdminVote(VotingPluginMain plugin) {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see org.bukkit.command.CommandExecutor#onCommand(org.bukkit.command.
|
||||
* CommandSender , org.bukkit.command.Command, java.lang.String,
|
||||
* java.lang.String[])
|
||||
*/
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
|
||||
for (CommandHandler commandHandler : plugin.getAdminVoteCommand()) {
|
||||
if (commandHandler.runCommand(sender, args)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
// invalid command
|
||||
sender.sendMessage(ChatColor.RED + "No valid arguments, see /adminvote help!");
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
+100
-99
@@ -1,99 +1,100 @@
|
||||
package com.Ben12345rocks.VotingPlugin.Commands.Executers;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
import com.Ben12345rocks.AdvancedCore.CommandAPI.CommandHandler;
|
||||
import com.Ben12345rocks.AdvancedCore.Util.Misc.ArrayUtils;
|
||||
import com.Ben12345rocks.VotingPlugin.Main;
|
||||
|
||||
// TODO: Auto-generated Javadoc
|
||||
/**
|
||||
* The Class CommandAliases.
|
||||
*/
|
||||
public class CommandAliases implements CommandExecutor {
|
||||
|
||||
/** The plugin. */
|
||||
private Main plugin = Main.plugin;
|
||||
|
||||
/** The cmd handle. */
|
||||
private CommandHandler cmdHandle;
|
||||
|
||||
private boolean adminCommand;
|
||||
|
||||
public CommandAliases(CommandHandler cmdHandle, boolean adminCommand) {
|
||||
this.cmdHandle = cmdHandle;
|
||||
this.adminCommand = adminCommand;
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.bukkit.command.CommandExecutor#onCommand(org.bukkit.command.
|
||||
* CommandSender , org.bukkit.command.Command, java.lang.String,
|
||||
* java.lang.String[])
|
||||
*/
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
|
||||
|
||||
ArrayList<String> argsNew = new ArrayList<String>();
|
||||
argsNew.add(cmdHandle.getArgs()[0]);
|
||||
for (String arg : args) {
|
||||
argsNew.add(arg);
|
||||
}
|
||||
plugin.debug("Attempting cmd...");
|
||||
plugin.debug("Inputed args: " + ArrayUtils.getInstance().makeStringList(argsNew));
|
||||
|
||||
ArrayList<CommandHandler> handles = new ArrayList<CommandHandler>();
|
||||
if (adminCommand) {
|
||||
handles.addAll(plugin.getAdminVoteCommand());
|
||||
} else {
|
||||
handles.addAll(plugin.getVoteCommand());
|
||||
}
|
||||
|
||||
for (CommandHandler cmdHandle : handles) {
|
||||
if (cmdHandle.getArgs().length > args.length) {
|
||||
for (String arg : cmdHandle.getArgs()[0].split("&")) {
|
||||
if (cmd.getName().equalsIgnoreCase("vote" + arg)
|
||||
|| cmd.getName().equalsIgnoreCase("adminvote" + arg)) {
|
||||
argsNew.set(0, arg);
|
||||
|
||||
boolean argsMatch = true;
|
||||
for (int i = 0; i < argsNew.size(); i++) {
|
||||
if (i < cmdHandle.getArgs().length) {
|
||||
if (!cmdHandle.argsMatch(argsNew.get(i), i)) {
|
||||
argsMatch = false;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if (argsMatch) {
|
||||
if (cmdHandle.runCommand(sender, ArrayUtils.getInstance().convert(argsNew))) {
|
||||
plugin.debug("cmd found, ran cmd");
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* for (String arg : cmdHandle.getArgs()[0].split("&")) { argsNew.set(0, arg);
|
||||
* if (cmdHandle.runCommand(sender, Utils.getInstance().convertArray(argsNew)))
|
||||
* { plugin.debug( "cmd found, ran cmd"); return true; } }
|
||||
*/
|
||||
|
||||
// invalid command
|
||||
if (adminCommand) {
|
||||
sender.sendMessage(ChatColor.RED + "No valid arguments, see /adminvote help!");
|
||||
} else {
|
||||
sender.sendMessage(ChatColor.RED + "No valid arguments, see /vote help!");
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
package com.bencodez.votingplugin.commands.executers;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
import com.bencodez.advancedcore.api.command.CommandHandler;
|
||||
import com.bencodez.advancedcore.api.misc.ArrayUtils;
|
||||
import com.bencodez.votingplugin.VotingPluginMain;
|
||||
|
||||
// TODO: Auto-generated Javadoc
|
||||
/**
|
||||
* The Class CommandAliases.
|
||||
*/
|
||||
public class CommandAliases implements CommandExecutor {
|
||||
|
||||
private boolean adminCommand;
|
||||
|
||||
/** The cmd handle. */
|
||||
private CommandHandler cmdHandle;
|
||||
|
||||
/** The plugin. */
|
||||
private VotingPluginMain plugin = VotingPluginMain.plugin;
|
||||
|
||||
public CommandAliases(CommandHandler cmdHandle, boolean adminCommand) {
|
||||
this.cmdHandle = cmdHandle;
|
||||
this.adminCommand = adminCommand;
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see org.bukkit.command.CommandExecutor#onCommand(org.bukkit.command.
|
||||
* CommandSender , org.bukkit.command.Command, java.lang.String,
|
||||
* java.lang.String[])
|
||||
*/
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
|
||||
|
||||
ArrayList<String> argsNew = new ArrayList<String>();
|
||||
argsNew.add(cmdHandle.getArgs()[0]);
|
||||
for (String arg : args) {
|
||||
argsNew.add(arg);
|
||||
}
|
||||
plugin.debug("Attempting cmd...");
|
||||
plugin.debug("Inputed args: " + ArrayUtils.getInstance().makeStringList(argsNew));
|
||||
|
||||
ArrayList<CommandHandler> handles = new ArrayList<CommandHandler>();
|
||||
if (adminCommand) {
|
||||
handles.addAll(plugin.getAdminVoteCommand());
|
||||
} else {
|
||||
handles.addAll(plugin.getVoteCommand());
|
||||
}
|
||||
|
||||
for (CommandHandler cmdHandle : handles) {
|
||||
if (cmdHandle.getArgs().length > args.length) {
|
||||
for (String arg : cmdHandle.getArgs()[0].split("&")) {
|
||||
if (cmd.getName().equalsIgnoreCase("vote" + arg)
|
||||
|| cmd.getName().equalsIgnoreCase("adminvote" + arg)) {
|
||||
argsNew.set(0, arg);
|
||||
|
||||
boolean argsMatch = true;
|
||||
for (int i = 0; i < argsNew.size(); i++) {
|
||||
if (i < cmdHandle.getArgs().length) {
|
||||
if (!cmdHandle.argsMatch(argsNew.get(i), i)) {
|
||||
argsMatch = false;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if (argsMatch) {
|
||||
if (cmdHandle.runCommand(sender, ArrayUtils.getInstance().convert(argsNew))) {
|
||||
plugin.debug("cmd found, ran cmd");
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* for (String arg : cmdHandle.getArgs()[0].split("&")) { argsNew.set(0, arg);
|
||||
* if (cmdHandle.runCommand(sender, Utils.getInstance().convertArray(argsNew)))
|
||||
* { plugin.debug( "cmd found, ran cmd"); return true; } }
|
||||
*/
|
||||
|
||||
// invalid command
|
||||
if (adminCommand) {
|
||||
sender.sendMessage(ChatColor.RED + "No valid arguments, see /adminvote help!");
|
||||
} else {
|
||||
sender.sendMessage(ChatColor.RED + "No valid arguments, see /vote help!");
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
+68
-68
@@ -1,68 +1,68 @@
|
||||
package com.Ben12345rocks.VotingPlugin.Commands.Executers;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
import com.Ben12345rocks.AdvancedCore.CommandAPI.CommandHandler;
|
||||
import com.Ben12345rocks.VotingPlugin.Main;
|
||||
|
||||
// TODO: Auto-generated Javadoc
|
||||
/**
|
||||
* The Class CommandVote.
|
||||
*/
|
||||
public class CommandVote implements CommandExecutor {
|
||||
|
||||
/** The instance. */
|
||||
private static CommandVote instance = new CommandVote();
|
||||
|
||||
/** The plugin. */
|
||||
private static Main plugin;
|
||||
|
||||
/**
|
||||
* Gets the single instance of CommandVote.
|
||||
*
|
||||
* @return single instance of CommandVote
|
||||
*/
|
||||
public static CommandVote getInstance() {
|
||||
return instance;
|
||||
}
|
||||
|
||||
/**
|
||||
* Instantiates a new command vote.
|
||||
*/
|
||||
private CommandVote() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Instantiates a new command vote.
|
||||
*
|
||||
* @param plugin
|
||||
* the plugin
|
||||
*/
|
||||
public CommandVote(Main plugin) {
|
||||
CommandVote.plugin = plugin;
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.bukkit.command.CommandExecutor#onCommand(org.bukkit.command.
|
||||
* CommandSender , org.bukkit.command.Command, java.lang.String,
|
||||
* java.lang.String[])
|
||||
*/
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
|
||||
|
||||
for (CommandHandler commandHandler : plugin.getVoteCommand()) {
|
||||
if (commandHandler.runCommand(sender, args)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
// invalid command
|
||||
sender.sendMessage(ChatColor.RED + "No valid arguments, see /vote help!");
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
package com.bencodez.votingplugin.commands.executers;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
import com.bencodez.advancedcore.api.command.CommandHandler;
|
||||
import com.bencodez.votingplugin.VotingPluginMain;
|
||||
|
||||
// TODO: Auto-generated Javadoc
|
||||
/**
|
||||
* The Class CommandVote.
|
||||
*/
|
||||
public class CommandVote implements CommandExecutor {
|
||||
|
||||
/** The instance. */
|
||||
private static CommandVote instance = new CommandVote();
|
||||
|
||||
/** The plugin. */
|
||||
private static VotingPluginMain plugin;
|
||||
|
||||
/**
|
||||
* Gets the single instance of CommandVote.
|
||||
*
|
||||
* @return single instance of CommandVote
|
||||
*/
|
||||
public static CommandVote getInstance() {
|
||||
return instance;
|
||||
}
|
||||
|
||||
/**
|
||||
* Instantiates a new command vote.
|
||||
*/
|
||||
private CommandVote() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Instantiates a new command vote.
|
||||
*
|
||||
* @param plugin the plugin
|
||||
*/
|
||||
public CommandVote(VotingPluginMain plugin) {
|
||||
CommandVote.plugin = plugin;
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see org.bukkit.command.CommandExecutor#onCommand(org.bukkit.command.
|
||||
* CommandSender , org.bukkit.command.Command, java.lang.String,
|
||||
* java.lang.String[])
|
||||
*/
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
|
||||
|
||||
for (CommandHandler commandHandler : plugin.getVoteCommand()) {
|
||||
if (commandHandler.runCommand(sender, args)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
// invalid command
|
||||
sender.sendMessage(ChatColor.RED + "No valid arguments, see /vote help!");
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
+253
-270
@@ -1,270 +1,253 @@
|
||||
package com.Ben12345rocks.VotingPlugin.Commands.GUI;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.inventory.ClickType;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import com.Ben12345rocks.AdvancedCore.Util.EditGUI.EditGUI;
|
||||
import com.Ben12345rocks.AdvancedCore.Util.EditGUI.EditGUIButton;
|
||||
import com.Ben12345rocks.AdvancedCore.Util.EditGUI.ValueTypes.EditGUIValueBoolean;
|
||||
import com.Ben12345rocks.AdvancedCore.Util.EditGUI.ValueTypes.EditGUIValueList;
|
||||
import com.Ben12345rocks.AdvancedCore.Util.EditGUI.ValueTypes.EditGUIValueNumber;
|
||||
import com.Ben12345rocks.AdvancedCore.Util.EditGUI.ValueTypes.EditGUIValueString;
|
||||
import com.Ben12345rocks.AdvancedCore.Util.Inventory.BInventory;
|
||||
import com.Ben12345rocks.AdvancedCore.Util.Inventory.BInventory.ClickEvent;
|
||||
import com.Ben12345rocks.AdvancedCore.Util.Inventory.BInventoryButton;
|
||||
import com.Ben12345rocks.AdvancedCore.Util.Misc.ArrayUtils;
|
||||
import com.Ben12345rocks.AdvancedCore.Util.Misc.PlayerUtils;
|
||||
import com.Ben12345rocks.AdvancedCore.Util.ValueRequest.InputMethod;
|
||||
import com.Ben12345rocks.AdvancedCore.Util.ValueRequest.ValueRequest;
|
||||
import com.Ben12345rocks.AdvancedCore.Util.ValueRequest.ValueRequestBuilder;
|
||||
import com.Ben12345rocks.AdvancedCore.Util.ValueRequest.Listeners.StringListener;
|
||||
import com.Ben12345rocks.VotingPlugin.Main;
|
||||
import com.Ben12345rocks.VotingPlugin.Config.ConfigVoteSites;
|
||||
import com.Ben12345rocks.VotingPlugin.Events.PlayerVoteEvent;
|
||||
import com.Ben12345rocks.VotingPlugin.Objects.VoteSite;
|
||||
|
||||
public class AdminGUI {
|
||||
static AdminGUI instance = new AdminGUI();
|
||||
|
||||
/**
|
||||
* Gets the single instance of Commands.
|
||||
*
|
||||
* @return single instance of Commands
|
||||
*/
|
||||
public static AdminGUI getInstance() {
|
||||
return instance;
|
||||
}
|
||||
|
||||
/** The plugin. */
|
||||
Main plugin = Main.plugin;
|
||||
|
||||
/**
|
||||
* Instantiates a new commands.
|
||||
*/
|
||||
private AdminGUI() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Open admin GUI.
|
||||
*
|
||||
* @return ArrayList of buttons
|
||||
*/
|
||||
public ArrayList<BInventoryButton> adminGUIButtons() {
|
||||
ArrayList<BInventoryButton> buttons = new ArrayList<BInventoryButton>();
|
||||
buttons.add(new BInventoryButton("&cVoteSites",
|
||||
new String[] { "&cOnly enabled sites are listed in this section", "&cMiddle Click to create" },
|
||||
new ItemStack(Material.STONE)) {
|
||||
|
||||
@Override
|
||||
public void onClick(ClickEvent event) {
|
||||
Player player = event.getPlayer();
|
||||
if (event.getClick().equals(ClickType.MIDDLE)) {
|
||||
new ValueRequest().requestString(player, new StringListener() {
|
||||
|
||||
@Override
|
||||
public void onInput(Player player, String value) {
|
||||
ConfigVoteSites.getInstance().generateVoteSite(value);
|
||||
player.sendMessage("Generated site");
|
||||
plugin.reload();
|
||||
}
|
||||
});
|
||||
} else {
|
||||
openAdminGUIVoteSites(player);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
buttons.add(new BInventoryButton("&cReload Plugin", new String[] {}, new ItemStack(Material.STONE, 1)) {
|
||||
|
||||
@Override
|
||||
public void onClick(ClickEvent event) {
|
||||
plugin.reload();
|
||||
}
|
||||
|
||||
});
|
||||
return buttons;
|
||||
}
|
||||
|
||||
public void loadHook() {
|
||||
for (BInventoryButton b : adminGUIButtons()) {
|
||||
com.Ben12345rocks.AdvancedCore.Commands.GUI.AdminGUI.getInstance().addButton(b);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Open admin GUI vote sites.
|
||||
*
|
||||
* @param player
|
||||
* the player
|
||||
*/
|
||||
public void openAdminGUIVoteSites(Player player) {
|
||||
BInventory inv = new BInventory("VoteSites");
|
||||
int count = 0;
|
||||
for (VoteSite voteSite : plugin.getVoteSites()) {
|
||||
ArrayList<String> lore = new ArrayList<String>();
|
||||
lore.add("Priority: " + voteSite.getPriority());
|
||||
lore.add("Name: " + voteSite.getDisplayName());
|
||||
lore.add("ServiceSite: " + voteSite.getServiceSite());
|
||||
lore.add("VoteURL: " + voteSite.getVoteURL());
|
||||
lore.add("VoteDelay: " + voteSite.getVoteDelay());
|
||||
|
||||
inv.addButton(count, new BInventoryButton(voteSite.getKey(), ArrayUtils.getInstance().convert(lore),
|
||||
new ItemStack(Material.STONE)) {
|
||||
|
||||
@Override
|
||||
public void onClick(ClickEvent event) {
|
||||
|
||||
Player player = event.getWhoClicked();
|
||||
openAdminGUIVoteSiteSite(player, voteSite);
|
||||
|
||||
}
|
||||
});
|
||||
count++;
|
||||
}
|
||||
inv.openInventory(player);
|
||||
}
|
||||
|
||||
/**
|
||||
* Open admin GUI vote site site.
|
||||
*
|
||||
* @param player
|
||||
* the player
|
||||
* @param voteSite
|
||||
* the vote site
|
||||
*/
|
||||
public void openAdminGUIVoteSiteSite(Player player, VoteSite voteSite) {
|
||||
EditGUI inv = new EditGUI("VoteSite: " + voteSite.getDisplayName());
|
||||
inv.setMeta(player, "VoteSite", voteSite);
|
||||
|
||||
inv.addButton(new BInventoryButton(voteSite.getItem().setName("&cForce vote")) {
|
||||
|
||||
@Override
|
||||
public void onClick(ClickEvent event) {
|
||||
ArrayList<String> playerNames = new ArrayList<String>();
|
||||
for (Player p : Bukkit.getOnlinePlayers()) {
|
||||
playerNames.add(p.getName());
|
||||
}
|
||||
new ValueRequestBuilder(new StringListener() {
|
||||
|
||||
@Override
|
||||
public void onInput(Player player, String value) {
|
||||
Object ob = PlayerUtils.getInstance().getPlayerMeta(player, "VoteSite");
|
||||
if (ob != null) {
|
||||
VoteSite site = (VoteSite) ob;
|
||||
PlayerVoteEvent voteEvent = new PlayerVoteEvent(site, value, site.getServiceSite(), false);
|
||||
plugin.getServer().getPluginManager().callEvent(voteEvent);
|
||||
}
|
||||
}
|
||||
}, ArrayUtils.getInstance().convert(playerNames)).usingMethod(InputMethod.INVENTORY)
|
||||
.allowCustomOption(true).request(event.getWhoClicked());
|
||||
}
|
||||
});
|
||||
|
||||
inv.addButton(new EditGUIButton(new EditGUIValueNumber("Priority", voteSite.getPriority()) {
|
||||
|
||||
@Override
|
||||
public void setValue(Player player, Number num) {
|
||||
VoteSite voteSite = (VoteSite) getInv().getMeta(player, "VoteSite");
|
||||
ConfigVoteSites.getInstance().setPriority(voteSite.getKey(), num.intValue());
|
||||
plugin.reload();
|
||||
}
|
||||
}));
|
||||
|
||||
inv.addButton(new EditGUIButton(new EditGUIValueString("ServiceSite", voteSite.getServiceSite()) {
|
||||
|
||||
@Override
|
||||
public void setValue(Player player, String value) {
|
||||
VoteSite voteSite = (VoteSite) getInv().getMeta(player, "VoteSite");
|
||||
String siteName = voteSite.getKey();
|
||||
ConfigVoteSites.getInstance().setServiceSite(siteName, value);
|
||||
plugin.reload();
|
||||
}
|
||||
}));
|
||||
|
||||
inv.addButton(new EditGUIButton(new EditGUIValueString("Name", voteSite.getDisplayName()) {
|
||||
|
||||
@Override
|
||||
public void setValue(Player player, String value) {
|
||||
VoteSite voteSite = (VoteSite) getInv().getMeta(player, "VoteSite");
|
||||
ConfigVoteSites.getInstance().setDisplayName(voteSite.getKey(), value);
|
||||
plugin.reload();
|
||||
}
|
||||
}));
|
||||
|
||||
inv.addButton(new EditGUIButton(new EditGUIValueString("VoteURL", voteSite.getVoteURL()) {
|
||||
|
||||
@Override
|
||||
public void setValue(Player player, String value) {
|
||||
VoteSite voteSite = (VoteSite) getInv().getMeta(player, "VoteSite");
|
||||
String siteName = voteSite.getKey();
|
||||
ConfigVoteSites.getInstance().setVoteURL(siteName, value);
|
||||
plugin.reload();
|
||||
}
|
||||
}));
|
||||
|
||||
inv.addButton(new EditGUIButton(new EditGUIValueNumber("VoteDelay", voteSite.getVoteDelay()) {
|
||||
|
||||
@Override
|
||||
public void setValue(Player player, Number num) {
|
||||
VoteSite voteSite = (VoteSite) getInv().getMeta(player, "VoteSite");
|
||||
String siteName = voteSite.getKey();
|
||||
ConfigVoteSites.getInstance().setVoteDelay(siteName, num.intValue());
|
||||
plugin.reload();
|
||||
}
|
||||
}));
|
||||
|
||||
inv.addButton(new EditGUIButton(new EditGUIValueBoolean("Enabled", voteSite.isEnabled()) {
|
||||
|
||||
@Override
|
||||
public void setValue(Player player, boolean value) {
|
||||
VoteSite voteSite = (VoteSite) getInv().getMeta(player, "VoteSite");
|
||||
String siteName = voteSite.getKey();
|
||||
ConfigVoteSites.getInstance().setEnabled(siteName, value);
|
||||
plugin.reload();
|
||||
}
|
||||
}));
|
||||
|
||||
inv.addButton(new EditGUIButton(new EditGUIValueBoolean("ForceOffline", voteSite.isGiveOffline()) {
|
||||
|
||||
@Override
|
||||
public void setValue(Player player, boolean value) {
|
||||
VoteSite voteSite = (VoteSite) getInv().getMeta(player, "VoteSite");
|
||||
String siteName = voteSite.getKey();
|
||||
ConfigVoteSites.getInstance().setForceOffline(siteName, value);
|
||||
plugin.reload();
|
||||
}
|
||||
}));
|
||||
|
||||
inv.addButton(new EditGUIButton(new EditGUIValueBoolean("VoteDelayDaily", voteSite.isVoteDelayDaily()) {
|
||||
|
||||
@Override
|
||||
public void setValue(Player player, boolean value) {
|
||||
VoteSite voteSite = (VoteSite) getInv().getMeta(player, "VoteSite");
|
||||
String siteName = voteSite.getKey();
|
||||
ConfigVoteSites.getInstance().setVoteDelayDaily(siteName, value);
|
||||
plugin.reload();
|
||||
}
|
||||
}));
|
||||
|
||||
if (voteSite.getSiteData().isList("Rewards")) {
|
||||
|
||||
inv.addButton(
|
||||
new EditGUIButton(new EditGUIValueList("Rewards", voteSite.getSiteData().getStringList("Rewards")) {
|
||||
|
||||
@Override
|
||||
public void setValue(Player p, ArrayList<String> rewards) {
|
||||
VoteSite voteSite = (VoteSite) getInv().getMeta(player, "VoteSite");
|
||||
ConfigVoteSites.getInstance().set(voteSite.getKey(), "Rewards", rewards);
|
||||
plugin.reload();
|
||||
}
|
||||
}));
|
||||
}
|
||||
|
||||
inv.openInventory(player);
|
||||
}
|
||||
}
|
||||
package com.bencodez.votingplugin.commands.gui;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.inventory.ClickType;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import com.bencodez.advancedcore.api.inventory.BInventory;
|
||||
import com.bencodez.advancedcore.api.inventory.BInventory.ClickEvent;
|
||||
import com.bencodez.advancedcore.api.inventory.BInventoryButton;
|
||||
import com.bencodez.advancedcore.api.inventory.editgui.EditGUI;
|
||||
import com.bencodez.advancedcore.api.inventory.editgui.EditGUIButton;
|
||||
import com.bencodez.advancedcore.api.inventory.editgui.valuetypes.EditGUIValueBoolean;
|
||||
import com.bencodez.advancedcore.api.inventory.editgui.valuetypes.EditGUIValueList;
|
||||
import com.bencodez.advancedcore.api.inventory.editgui.valuetypes.EditGUIValueNumber;
|
||||
import com.bencodez.advancedcore.api.inventory.editgui.valuetypes.EditGUIValueString;
|
||||
import com.bencodez.advancedcore.api.misc.ArrayUtils;
|
||||
import com.bencodez.advancedcore.api.misc.PlayerUtils;
|
||||
import com.bencodez.advancedcore.api.valuerequest.InputMethod;
|
||||
import com.bencodez.advancedcore.api.valuerequest.ValueRequest;
|
||||
import com.bencodez.advancedcore.api.valuerequest.ValueRequestBuilder;
|
||||
import com.bencodez.advancedcore.api.valuerequest.listeners.StringListener;
|
||||
import com.bencodez.votingplugin.VotingPluginMain;
|
||||
import com.bencodez.votingplugin.events.PlayerVoteEvent;
|
||||
import com.bencodez.votingplugin.objects.VoteSite;
|
||||
|
||||
public class AdminGUI {
|
||||
|
||||
private VotingPluginMain plugin;
|
||||
|
||||
public AdminGUI(VotingPluginMain plugin) {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
/**
|
||||
* Open admin GUI.
|
||||
*
|
||||
* @return ArrayList of buttons
|
||||
*/
|
||||
public ArrayList<BInventoryButton> adminGUIButtons() {
|
||||
ArrayList<BInventoryButton> buttons = new ArrayList<BInventoryButton>();
|
||||
buttons.add(new BInventoryButton("&cVoteSites",
|
||||
new String[] { "&cOnly enabled sites are listed in this section", "&cMiddle Click to create" },
|
||||
new ItemStack(Material.STONE)) {
|
||||
|
||||
@Override
|
||||
public void onClick(ClickEvent event) {
|
||||
Player player = event.getPlayer();
|
||||
if (event.getClick().equals(ClickType.MIDDLE)) {
|
||||
new ValueRequest().requestString(player, new StringListener() {
|
||||
|
||||
@Override
|
||||
public void onInput(Player player, String value) {
|
||||
plugin.getConfigVoteSites().generateVoteSite(value);
|
||||
player.sendMessage("Generated site");
|
||||
plugin.reload();
|
||||
}
|
||||
});
|
||||
} else {
|
||||
openAdminGUIVoteSites(player);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
buttons.add(new BInventoryButton("&cReload Plugin", new String[] {}, new ItemStack(Material.STONE, 1)) {
|
||||
|
||||
@Override
|
||||
public void onClick(ClickEvent event) {
|
||||
plugin.reload();
|
||||
}
|
||||
|
||||
});
|
||||
return buttons;
|
||||
}
|
||||
|
||||
public void loadHook() {
|
||||
for (BInventoryButton b : adminGUIButtons()) {
|
||||
com.bencodez.advancedcore.command.gui.AdminGUI.getInstance().addButton(b);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Open admin GUI vote sites.
|
||||
*
|
||||
* @param player the player
|
||||
*/
|
||||
public void openAdminGUIVoteSites(Player player) {
|
||||
BInventory inv = new BInventory("VoteSites");
|
||||
int count = 0;
|
||||
for (VoteSite voteSite : plugin.getVoteSites()) {
|
||||
ArrayList<String> lore = new ArrayList<String>();
|
||||
lore.add("Priority: " + voteSite.getPriority());
|
||||
lore.add("Name: " + voteSite.getDisplayName());
|
||||
lore.add("ServiceSite: " + voteSite.getServiceSite());
|
||||
lore.add("VoteURL: " + voteSite.getVoteURL());
|
||||
lore.add("VoteDelay: " + voteSite.getVoteDelay());
|
||||
|
||||
inv.addButton(count, new BInventoryButton(voteSite.getKey(), ArrayUtils.getInstance().convert(lore),
|
||||
new ItemStack(Material.STONE)) {
|
||||
|
||||
@Override
|
||||
public void onClick(ClickEvent event) {
|
||||
|
||||
Player player = event.getWhoClicked();
|
||||
openAdminGUIVoteSiteSite(player, voteSite);
|
||||
|
||||
}
|
||||
});
|
||||
count++;
|
||||
}
|
||||
inv.openInventory(player);
|
||||
}
|
||||
|
||||
/**
|
||||
* Open admin GUI vote site site.
|
||||
*
|
||||
* @param player the player
|
||||
* @param voteSite the vote site
|
||||
*/
|
||||
public void openAdminGUIVoteSiteSite(Player player, VoteSite voteSite) {
|
||||
EditGUI inv = new EditGUI("VoteSite: " + voteSite.getDisplayName());
|
||||
inv.setMeta(player, "VoteSite", voteSite);
|
||||
|
||||
inv.addButton(new BInventoryButton(voteSite.getItem().setName("&cForce vote")) {
|
||||
|
||||
@Override
|
||||
public void onClick(ClickEvent event) {
|
||||
ArrayList<String> playerNames = new ArrayList<String>();
|
||||
for (Player p : Bukkit.getOnlinePlayers()) {
|
||||
playerNames.add(p.getName());
|
||||
}
|
||||
new ValueRequestBuilder(new StringListener() {
|
||||
|
||||
@Override
|
||||
public void onInput(Player player, String value) {
|
||||
Object ob = PlayerUtils.getInstance().getPlayerMeta(player, "VoteSite");
|
||||
if (ob != null) {
|
||||
VoteSite site = (VoteSite) ob;
|
||||
PlayerVoteEvent voteEvent = new PlayerVoteEvent(site, value, site.getServiceSite(), false);
|
||||
plugin.getServer().getPluginManager().callEvent(voteEvent);
|
||||
}
|
||||
}
|
||||
}, ArrayUtils.getInstance().convert(playerNames)).usingMethod(InputMethod.INVENTORY)
|
||||
.allowCustomOption(true).request(event.getWhoClicked());
|
||||
}
|
||||
});
|
||||
|
||||
inv.addButton(new EditGUIButton(new EditGUIValueNumber("Priority", voteSite.getPriority()) {
|
||||
|
||||
@Override
|
||||
public void setValue(Player player, Number num) {
|
||||
VoteSite voteSite = (VoteSite) getInv().getMeta(player, "VoteSite");
|
||||
plugin.getConfigVoteSites().setPriority(voteSite.getKey(), num.intValue());
|
||||
plugin.reload();
|
||||
}
|
||||
}));
|
||||
|
||||
inv.addButton(new EditGUIButton(new EditGUIValueString("ServiceSite", voteSite.getServiceSite()) {
|
||||
|
||||
@Override
|
||||
public void setValue(Player player, String value) {
|
||||
VoteSite voteSite = (VoteSite) getInv().getMeta(player, "VoteSite");
|
||||
String siteName = voteSite.getKey();
|
||||
plugin.getConfigVoteSites().setServiceSite(siteName, value);
|
||||
plugin.reload();
|
||||
}
|
||||
}));
|
||||
|
||||
inv.addButton(new EditGUIButton(new EditGUIValueString("Name", voteSite.getDisplayName()) {
|
||||
|
||||
@Override
|
||||
public void setValue(Player player, String value) {
|
||||
VoteSite voteSite = (VoteSite) getInv().getMeta(player, "VoteSite");
|
||||
plugin.getConfigVoteSites().setDisplayName(voteSite.getKey(), value);
|
||||
plugin.reload();
|
||||
}
|
||||
}));
|
||||
|
||||
inv.addButton(new EditGUIButton(new EditGUIValueString("VoteURL", voteSite.getVoteURL()) {
|
||||
|
||||
@Override
|
||||
public void setValue(Player player, String value) {
|
||||
VoteSite voteSite = (VoteSite) getInv().getMeta(player, "VoteSite");
|
||||
String siteName = voteSite.getKey();
|
||||
plugin.getConfigVoteSites().setVoteURL(siteName, value);
|
||||
plugin.reload();
|
||||
}
|
||||
}));
|
||||
|
||||
inv.addButton(new EditGUIButton(new EditGUIValueNumber("VoteDelay", voteSite.getVoteDelay()) {
|
||||
|
||||
@Override
|
||||
public void setValue(Player player, Number num) {
|
||||
VoteSite voteSite = (VoteSite) getInv().getMeta(player, "VoteSite");
|
||||
String siteName = voteSite.getKey();
|
||||
plugin.getConfigVoteSites().setVoteDelay(siteName, num.intValue());
|
||||
plugin.reload();
|
||||
}
|
||||
}));
|
||||
|
||||
inv.addButton(new EditGUIButton(new EditGUIValueBoolean("Enabled", voteSite.isEnabled()) {
|
||||
|
||||
@Override
|
||||
public void setValue(Player player, boolean value) {
|
||||
VoteSite voteSite = (VoteSite) getInv().getMeta(player, "VoteSite");
|
||||
String siteName = voteSite.getKey();
|
||||
plugin.getConfigVoteSites().setEnabled(siteName, value);
|
||||
plugin.reload();
|
||||
}
|
||||
}));
|
||||
|
||||
inv.addButton(new EditGUIButton(new EditGUIValueBoolean("ForceOffline", voteSite.isGiveOffline()) {
|
||||
|
||||
@Override
|
||||
public void setValue(Player player, boolean value) {
|
||||
VoteSite voteSite = (VoteSite) getInv().getMeta(player, "VoteSite");
|
||||
String siteName = voteSite.getKey();
|
||||
plugin.getConfigVoteSites().setForceOffline(siteName, value);
|
||||
plugin.reload();
|
||||
}
|
||||
}));
|
||||
|
||||
inv.addButton(new EditGUIButton(new EditGUIValueBoolean("VoteDelayDaily", voteSite.isVoteDelayDaily()) {
|
||||
|
||||
@Override
|
||||
public void setValue(Player player, boolean value) {
|
||||
VoteSite voteSite = (VoteSite) getInv().getMeta(player, "VoteSite");
|
||||
String siteName = voteSite.getKey();
|
||||
plugin.getConfigVoteSites().setVoteDelayDaily(siteName, value);
|
||||
plugin.reload();
|
||||
}
|
||||
}));
|
||||
|
||||
if (voteSite.getSiteData().isList("Rewards")) {
|
||||
|
||||
inv.addButton(
|
||||
new EditGUIButton(new EditGUIValueList("Rewards", voteSite.getSiteData().getStringList("Rewards")) {
|
||||
|
||||
@Override
|
||||
public void setValue(Player p, ArrayList<String> rewards) {
|
||||
VoteSite voteSite = (VoteSite) getInv().getMeta(player, "VoteSite");
|
||||
plugin.getConfigVoteSites().set(voteSite.getKey(), "Rewards", rewards);
|
||||
plugin.reload();
|
||||
}
|
||||
}));
|
||||
}
|
||||
|
||||
inv.openInventory(player);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,110 @@
|
||||
package com.bencodez.votingplugin.commands.gui.admin;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import com.bencodez.advancedcore.api.command.CommandHandler;
|
||||
import com.bencodez.advancedcore.api.gui.GUIHandler;
|
||||
import com.bencodez.advancedcore.api.gui.GUIMethod;
|
||||
import com.bencodez.advancedcore.api.messages.StringParser;
|
||||
import com.bencodez.votingplugin.VotingPluginMain;
|
||||
|
||||
import net.md_5.bungee.api.chat.TextComponent;
|
||||
|
||||
public class AdminVoteHelp extends GUIHandler {
|
||||
|
||||
private int page;
|
||||
private VotingPluginMain plugin;
|
||||
|
||||
public AdminVoteHelp(VotingPluginMain plugin, CommandSender player, int page) {
|
||||
super(player);
|
||||
this.plugin = plugin;
|
||||
this.page = page;
|
||||
}
|
||||
|
||||
/**
|
||||
* Admin help.
|
||||
*
|
||||
* @param sender the sender
|
||||
* @param page the page
|
||||
* @return the array list
|
||||
*/
|
||||
public ArrayList<TextComponent> adminHelp(CommandSender sender, int page) {
|
||||
int pagesize = plugin.getConfigFile().getFormatPageSize();
|
||||
ArrayList<TextComponent> msg = new ArrayList<TextComponent>();
|
||||
ArrayList<TextComponent> text = adminHelpText(sender);
|
||||
|
||||
int maxPage = text.size() / pagesize;
|
||||
if ((text.size() % pagesize) != 0) {
|
||||
maxPage++;
|
||||
}
|
||||
|
||||
msg.add(StringParser.getInstance().stringToComp("&6&lVotingPlugin Admin Help " + (page) + "/" + maxPage));
|
||||
msg.add(StringParser.getInstance().stringToComp("&6&l() = Needed"));
|
||||
msg.add(StringParser.getInstance().stringToComp("&6&lAliases: adminvote, av"));
|
||||
|
||||
for (int i = pagesize * (page - 1); (i < text.size()) && (i < ((page) * pagesize)); i++) {
|
||||
msg.add(text.get(i));
|
||||
}
|
||||
|
||||
return msg;
|
||||
}
|
||||
|
||||
/**
|
||||
* Admin help text.
|
||||
*
|
||||
* @param sender the sender
|
||||
* @return the array list
|
||||
*/
|
||||
public ArrayList<TextComponent> adminHelpText(CommandSender sender) {
|
||||
ArrayList<TextComponent> msg = new ArrayList<TextComponent>();
|
||||
HashMap<String, TextComponent> unsorted = new HashMap<String, TextComponent>();
|
||||
|
||||
boolean requirePerms = plugin.getConfigFile().getFormatCommandsVoteHelpRequirePermission();
|
||||
|
||||
for (CommandHandler cmdHandle : plugin.getAdminVoteCommand()) {
|
||||
if (requirePerms && sender.hasPermission(cmdHandle.getPerm())) {
|
||||
unsorted.put(cmdHandle.getHelpLineCommand("/adminvote"), cmdHandle.getHelpLine("/adminvote"));
|
||||
} else {
|
||||
unsorted.put(cmdHandle.getHelpLineCommand("/adminvote"), cmdHandle.getHelpLine("/adminvote"));
|
||||
}
|
||||
}
|
||||
ArrayList<String> unsortedList = new ArrayList<String>();
|
||||
unsortedList.addAll(unsorted.keySet());
|
||||
Collections.sort(unsortedList, String.CASE_INSENSITIVE_ORDER);
|
||||
for (String cmd : unsortedList) {
|
||||
msg.add(unsorted.get(cmd));
|
||||
}
|
||||
|
||||
return msg;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ArrayList<String> getChat(CommandSender sender) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBook(Player player) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onChat(CommandSender sender) {
|
||||
sendMessageJson(adminHelp(sender, page));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onChest(Player player) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void open() {
|
||||
open(GUIMethod.CHAT);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,161 @@
|
||||
package com.bencodez.votingplugin.commands.gui.admin;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.permissions.Permission;
|
||||
|
||||
import com.bencodez.advancedcore.api.command.CommandHandler;
|
||||
import com.bencodez.advancedcore.api.gui.GUIHandler;
|
||||
import com.bencodez.advancedcore.api.gui.GUIMethod;
|
||||
import com.bencodez.advancedcore.api.misc.ArrayUtils;
|
||||
import com.bencodez.votingplugin.VotingPluginMain;
|
||||
|
||||
public class AdminVotePerms extends GUIHandler {
|
||||
|
||||
private int page;
|
||||
private String playerName;
|
||||
private VotingPluginMain plugin;
|
||||
|
||||
public AdminVotePerms(VotingPluginMain plugin, CommandSender player) {
|
||||
super(player);
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
public AdminVotePerms(VotingPluginMain plugin, CommandSender player, int page, String playerName) {
|
||||
super(player);
|
||||
this.plugin = plugin;
|
||||
this.page = page;
|
||||
this.playerName = playerName;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ArrayList<String> getChat(CommandSender sender) {
|
||||
return null;
|
||||
}
|
||||
|
||||
public String[] listPerms(CommandSender sender) {
|
||||
ArrayList<String> msg = new ArrayList<String>();
|
||||
msg.add("&c&lCommand : Permissions (seperated by |)");
|
||||
|
||||
for (CommandHandler handle : plugin.getVoteCommand()) {
|
||||
if (sender instanceof Player) {
|
||||
if (handle.hasPerm(sender)) {
|
||||
msg.add("&a" + handle.getHelpLineCommand("/vote") + " : " + handle.getPerm() + " : true");
|
||||
} else {
|
||||
msg.add("&c" + handle.getHelpLineCommand("/vote") + " : " + handle.getPerm() + " : false");
|
||||
}
|
||||
} else {
|
||||
msg.add(handle.getHelpLineCommand("/vote") + " : " + handle.getPerm());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
for (CommandHandler handle : plugin.getAdminVoteCommand()) {
|
||||
if (sender instanceof Player) {
|
||||
if (handle.hasPerm(sender)) {
|
||||
msg.add("&a" + handle.getHelpLineCommand("/av") + " : " + handle.getPerm() + " : true");
|
||||
} else {
|
||||
msg.add("&c" + handle.getHelpLineCommand("/av") + " : " + handle.getPerm() + " : false");
|
||||
}
|
||||
} else {
|
||||
msg.add(handle.getHelpLineCommand("/av") + " : " + handle.getPerm());
|
||||
}
|
||||
}
|
||||
|
||||
for (Permission perm : plugin.getDescription().getPermissions()) {
|
||||
if (sender instanceof Player) {
|
||||
if (sender.hasPermission(perm)) {
|
||||
msg.add("&a" + perm.getName() + " : true");
|
||||
} else {
|
||||
msg.add("&c" + perm.getName() + " : false");
|
||||
}
|
||||
} else {
|
||||
msg.add(perm.getName());
|
||||
}
|
||||
}
|
||||
|
||||
msg = ArrayUtils.getInstance().colorize(msg);
|
||||
|
||||
return ArrayUtils.getInstance().convert(msg);
|
||||
}
|
||||
|
||||
public ArrayList<String> listPerms(CommandSender sender, String player, int page) {
|
||||
Player p = Bukkit.getPlayer(player);
|
||||
ArrayList<String> text = new ArrayList<String>();
|
||||
if (p != null) {
|
||||
|
||||
ArrayList<String> msg = new ArrayList<String>();
|
||||
|
||||
for (CommandHandler handle : plugin.getVoteCommand()) {
|
||||
if (handle.hasPerm(p)) {
|
||||
msg.add("&a" + handle.getHelpLineCommand("/vote") + " : " + handle.getPerm() + " : true");
|
||||
} else {
|
||||
msg.add("&c" + handle.getHelpLineCommand("/vote") + " : " + handle.getPerm() + " : false");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
for (CommandHandler handle : plugin.getAdminVoteCommand()) {
|
||||
if (handle.hasPerm(p)) {
|
||||
msg.add("&a" + handle.getHelpLineCommand("/av") + " : " + handle.getPerm() + " : true");
|
||||
} else {
|
||||
msg.add("&c" + handle.getHelpLineCommand("/av") + " : " + handle.getPerm() + " : false");
|
||||
}
|
||||
}
|
||||
|
||||
for (Permission perm : plugin.getDescription().getPermissions()) {
|
||||
if (p.hasPermission(perm)) {
|
||||
msg.add("&a" + perm.getName() + " : true");
|
||||
} else {
|
||||
msg.add("&c" + perm.getName() + " : false");
|
||||
}
|
||||
}
|
||||
|
||||
msg = ArrayUtils.getInstance().colorize(msg);
|
||||
|
||||
int pagesize = plugin.getConfigFile().getFormatPageSize();
|
||||
|
||||
int maxPage = msg.size() / pagesize;
|
||||
if ((msg.size() % pagesize) != 0) {
|
||||
maxPage++;
|
||||
}
|
||||
|
||||
text.add("&c&lCommand : Permissions (seperated by |) " + page + "/" + maxPage);
|
||||
|
||||
for (int i = pagesize * page - pagesize; i < msg.size() && i < pagesize * page; i++) {
|
||||
text.add(msg.get(i));
|
||||
}
|
||||
} else {
|
||||
text.add("&cPlayer not online: " + player);
|
||||
}
|
||||
return ArrayUtils.getInstance().colorize(text);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBook(Player player) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onChat(CommandSender sender) {
|
||||
if (playerName != null) {
|
||||
sendMessage(listPerms(sender, playerName, page));
|
||||
} else {
|
||||
sendMessage(listPerms(sender));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onChest(Player player) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void open() {
|
||||
open(GUIMethod.CHAT);
|
||||
}
|
||||
|
||||
}
|
||||
+121
@@ -0,0 +1,121 @@
|
||||
package com.bencodez.votingplugin.commands.gui.admin;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
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.PlaceHolder;
|
||||
import com.bencodez.votingplugin.VotingPluginMain;
|
||||
import com.bencodez.votingplugin.user.VotingPluginUser;
|
||||
|
||||
import xyz.upperlevel.spigot.book.BookUtil;
|
||||
|
||||
public class AdminVotePlaceholders extends GUIHandler {
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
private VotingPluginMain plugin;
|
||||
|
||||
public AdminVotePlaceholders(VotingPluginMain plugin, CommandSender player) {
|
||||
super(player);
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ArrayList<String> getChat(CommandSender sender) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBook(Player player) {
|
||||
BookWrapper book = new BookWrapper("Placeholders");
|
||||
|
||||
for (PlaceHolder<VotingPluginUser> placeholder : plugin.getPlaceholders().getPlaceholders()) {
|
||||
String msg = "";
|
||||
String identifier = placeholder.getIdentifier();
|
||||
if (identifier.endsWith("_")) {
|
||||
identifier += "#";
|
||||
}
|
||||
if (placeholder.hasDescription()) {
|
||||
msg = "%VotingPlugin_" + identifier + "% - " + placeholder.getDescription();
|
||||
} else {
|
||||
msg = "%VotingPlugin_" + identifier + "%";
|
||||
}
|
||||
|
||||
Layout layout = new Layout(new ArrayList<String>(Arrays.asList("[Json]")));
|
||||
layout.replaceTextComponent("[Json]", BookUtil.TextBuilder.of(identifier).color(ChatColor.AQUA)
|
||||
.onHover(BookUtil.HoverAction.showText(msg)).build());
|
||||
book.addLayout(layout);
|
||||
}
|
||||
|
||||
for (PlaceHolder<VotingPluginUser> placeholder : plugin.getPlaceholders().getNonPlayerPlaceholders()) {
|
||||
String msg = "";
|
||||
String identifier = placeholder.getIdentifier();
|
||||
if (identifier.endsWith("_")) {
|
||||
identifier += "#";
|
||||
}
|
||||
if (placeholder.hasDescription()) {
|
||||
msg = "%VotingPlugin_" + identifier + "% - " + placeholder.getDescription();
|
||||
} else {
|
||||
msg = "%VotingPlugin_" + identifier + "%";
|
||||
}
|
||||
|
||||
Layout layout = new Layout(new ArrayList<String>(Arrays.asList("[Json]")));
|
||||
layout.replaceTextComponent("[Json]", BookUtil.TextBuilder.of(identifier).color(ChatColor.AQUA)
|
||||
.onHover(BookUtil.HoverAction.showText(msg)).build());
|
||||
book.addLayout(layout);
|
||||
|
||||
}
|
||||
|
||||
book.open(player);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onChat(CommandSender sender) {
|
||||
ArrayList<String> msg = new ArrayList<String>();
|
||||
msg.add("&cPlaceholders:");
|
||||
for (PlaceHolder<VotingPluginUser> placeholder : plugin.getPlaceholders().getPlaceholders()) {
|
||||
String identifier = placeholder.getIdentifier();
|
||||
if (identifier.endsWith("_")) {
|
||||
identifier += "#";
|
||||
}
|
||||
if (placeholder.hasDescription()) {
|
||||
msg.add("%VotingPlugin_" + identifier + "% - " + placeholder.getDescription());
|
||||
} else {
|
||||
msg.add("%VotingPlugin_" + identifier + "%");
|
||||
}
|
||||
}
|
||||
|
||||
for (PlaceHolder<VotingPluginUser> placeholder : plugin.getPlaceholders().getNonPlayerPlaceholders()) {
|
||||
String identifier = placeholder.getIdentifier();
|
||||
if (identifier.endsWith("_")) {
|
||||
identifier += "#";
|
||||
}
|
||||
if (placeholder.hasDescription()) {
|
||||
msg.add("%VotingPlugin_" + identifier + "% - " + placeholder.getDescription());
|
||||
} else {
|
||||
msg.add("%VotingPlugin_" + identifier + "%");
|
||||
}
|
||||
}
|
||||
|
||||
sendMessage(msg);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onChest(Player player) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void open() {
|
||||
open(GUIMethod.CHAT);
|
||||
}
|
||||
|
||||
}
|
||||
+111
@@ -0,0 +1,111 @@
|
||||
package com.bencodez.votingplugin.commands.gui.admin;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
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.PlaceHolder;
|
||||
import com.bencodez.votingplugin.VotingPluginMain;
|
||||
import com.bencodez.votingplugin.user.UserManager;
|
||||
import com.bencodez.votingplugin.user.VotingPluginUser;
|
||||
|
||||
import xyz.upperlevel.spigot.book.BookUtil;
|
||||
|
||||
public class AdminVotePlaceholdersPlayer extends GUIHandler {
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
private VotingPluginMain plugin;
|
||||
private VotingPluginUser user;
|
||||
|
||||
public AdminVotePlaceholdersPlayer(VotingPluginMain plugin, CommandSender player, VotingPluginUser user) {
|
||||
super(player);
|
||||
this.plugin = plugin;
|
||||
this.user = user;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ArrayList<String> getChat(CommandSender sender) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBook(Player player) {
|
||||
BookWrapper book = new BookWrapper("Placeholders");
|
||||
|
||||
for (PlaceHolder<VotingPluginUser> placeholder : plugin.getPlaceholders().getPlaceholders()) {
|
||||
String identifier = placeholder.getIdentifier();
|
||||
if (identifier.endsWith("_")) {
|
||||
identifier += "1";
|
||||
}
|
||||
String value = placeholder.placeholderRequest(user.getOfflinePlayer(), 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)
|
||||
.onHover(BookUtil.HoverAction.showText(value)).build());
|
||||
book.addLayout(layout);
|
||||
}
|
||||
|
||||
for (PlaceHolder<VotingPluginUser> placeholder : plugin.getPlaceholders().getNonPlayerPlaceholders()) {
|
||||
|
||||
String identifier = placeholder.getIdentifier();
|
||||
if (identifier.endsWith("_")) {
|
||||
identifier += "1";
|
||||
}
|
||||
String value = placeholder.placeholderRequest(user.getOfflinePlayer(), 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)
|
||||
.onHover(BookUtil.HoverAction.showText(value)).build());
|
||||
book.addLayout(layout);
|
||||
}
|
||||
book.open(player);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onChat(CommandSender sender) {
|
||||
ArrayList<String> msg = new ArrayList<String>();
|
||||
msg.add("&cPlaceholders:");
|
||||
VotingPluginUser placeholderUser = user;
|
||||
if (plugin.getConfigFile().isUsePrimaryAccountForPlaceholders() && user.hasPrimaryAccount()) {
|
||||
placeholderUser = UserManager.getInstance().getVotingPluginUser(user.getPrimaryAccount());
|
||||
}
|
||||
for (PlaceHolder<VotingPluginUser> placeholder : plugin.getPlaceholders().getPlaceholders()) {
|
||||
String identifier = placeholder.getIdentifier();
|
||||
if (identifier.endsWith("_")) {
|
||||
identifier += "1";
|
||||
}
|
||||
msg.add("%VotingPlugin_" + identifier + "% = "
|
||||
+ placeholder.placeholderRequest(user.getOfflinePlayer(), placeholderUser, identifier));
|
||||
}
|
||||
|
||||
for (PlaceHolder<VotingPluginUser> placeholder : plugin.getPlaceholders().getNonPlayerPlaceholders()) {
|
||||
String identifier = placeholder.getIdentifier();
|
||||
if (identifier.endsWith("_")) {
|
||||
identifier += "1";
|
||||
}
|
||||
|
||||
msg.add("%VotingPlugin_" + identifier + "% = "
|
||||
+ placeholder.placeholderRequest(user.getOfflinePlayer(), placeholderUser, identifier));
|
||||
}
|
||||
sendMessage(msg);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onChest(Player player) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void open() {
|
||||
open(GUIMethod.CHAT);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,99 @@
|
||||
package com.bencodez.votingplugin.commands.gui.player;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import com.bencodez.advancedcore.api.gui.GUIHandler;
|
||||
import com.bencodez.advancedcore.api.gui.GUIMethod;
|
||||
import com.bencodez.advancedcore.api.inventory.BInventory;
|
||||
import com.bencodez.advancedcore.api.inventory.BInventory.ClickEvent;
|
||||
import com.bencodez.advancedcore.api.inventory.BInventoryButton;
|
||||
import com.bencodez.advancedcore.api.item.ItemBuilder;
|
||||
import com.bencodez.advancedcore.api.misc.ArrayUtils;
|
||||
import com.bencodez.votingplugin.VotingPluginMain;
|
||||
import com.bencodez.votingplugin.user.VotingPluginUser;
|
||||
|
||||
public class VoteBest extends GUIHandler {
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
private VotingPluginMain plugin;
|
||||
private VotingPluginUser user;
|
||||
|
||||
public VoteBest(VotingPluginMain plugin, CommandSender player, VotingPluginUser user) {
|
||||
super(player);
|
||||
this.plugin = plugin;
|
||||
this.user = user;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ArrayList<String> getChat(CommandSender sender) {
|
||||
ArrayList<String> msg = new ArrayList<String>();
|
||||
msg.add(plugin.getConfigFile().getFormatCommandsVoteBestTitle());
|
||||
msg.addAll(plugin.getConfigFile().getFormatCommandsVoteBestLines());
|
||||
|
||||
HashMap<String, String> placeholders = new HashMap<String, String>();
|
||||
placeholders.put("HighestDailyTotal", "" + user.getHighestDailyTotal());
|
||||
placeholders.put("HighestWeeklyTotal", "" + user.getHighestWeeklyTotal());
|
||||
placeholders.put("HighestMonthlyTotal", "" + user.getHighestMonthlyTotal());
|
||||
|
||||
placeholders.put("player", user.getPlayerName());
|
||||
|
||||
msg = ArrayUtils.getInstance().replacePlaceHolder(msg, placeholders);
|
||||
|
||||
return ArrayUtils.getInstance().colorize(msg);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBook(Player player) {
|
||||
// TODO
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onChat(CommandSender sender) {
|
||||
sendMessage(getChat(sender));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onChest(Player player) {
|
||||
BInventory inv = new BInventory(plugin.getGui().getChestVoteBestName());
|
||||
inv.addPlaceholder("player", user.getPlayerName());
|
||||
|
||||
inv.addButton(new BInventoryButton(new ItemBuilder(plugin.getGui().getChestVoteBestDayBestItem())
|
||||
.addPlaceholder("Best", "" + user.getBestDayVoteStreak())) {
|
||||
|
||||
@Override
|
||||
public void onClick(ClickEvent clickEvent) {
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
inv.addButton(new BInventoryButton(new ItemBuilder(plugin.getGui().getChestVoteBestWeekBestItem())
|
||||
.addPlaceholder("Best", "" + user.getBestWeekVoteStreak())) {
|
||||
|
||||
@Override
|
||||
public void onClick(ClickEvent clickEvent) {
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
inv.addButton(new BInventoryButton(new ItemBuilder(plugin.getGui().getChestVoteBestMonthBestItem())
|
||||
.addPlaceholder("Best", "" + user.getBestMonthVoteStreak())) {
|
||||
|
||||
@Override
|
||||
public void onClick(ClickEvent clickEvent) {
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
inv.openInventory(player);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void open() {
|
||||
open(GUIMethod.valueOf(plugin.getGui().getGuiMethodBest().toUpperCase()));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,197 @@
|
||||
package com.bencodez.votingplugin.commands.gui.player;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import com.bencodez.advancedcore.api.gui.GUIHandler;
|
||||
import com.bencodez.advancedcore.api.gui.GUIMethod;
|
||||
import com.bencodez.advancedcore.api.inventory.BInventory;
|
||||
import com.bencodez.advancedcore.api.inventory.BInventory.ClickEvent;
|
||||
import com.bencodez.advancedcore.api.inventory.UpdatingBInventoryButton;
|
||||
import com.bencodez.advancedcore.api.item.ItemBuilder;
|
||||
import com.bencodez.advancedcore.api.messages.StringParser;
|
||||
import com.bencodez.advancedcore.api.misc.ArrayUtils;
|
||||
import com.bencodez.votingplugin.VotingPluginMain;
|
||||
import com.bencodez.votingplugin.topvoter.TopVoter;
|
||||
import com.bencodez.votingplugin.user.UserManager;
|
||||
import com.bencodez.votingplugin.user.VotingPluginUser;
|
||||
|
||||
public class VoteGUI extends GUIHandler {
|
||||
|
||||
private VotingPluginMain plugin;
|
||||
private VotingPluginUser user;
|
||||
|
||||
public VoteGUI(VotingPluginMain plugin, CommandSender player, VotingPluginUser user) {
|
||||
super(player);
|
||||
this.plugin = plugin;
|
||||
this.user = user;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ArrayList<String> getChat(CommandSender arg0) {
|
||||
return null;
|
||||
}
|
||||
|
||||
private ItemBuilder getItemSlot(String slot, Player player) {
|
||||
ItemBuilder builder = new ItemBuilder(plugin.getGui().getChestVoteGUISlotSection(slot));
|
||||
|
||||
String[] lore = new String[1];
|
||||
lore = ArrayUtils.getInstance().convert(plugin.getGui().getChestVoteGUISlotLore(slot));
|
||||
|
||||
String str = plugin.getConfigFile().getVoteTopDefault();
|
||||
if (lore.length == 0) {
|
||||
if (slot.equalsIgnoreCase("url")) {
|
||||
lore = new String[] { "&aClick me" };
|
||||
} else if (slot.equalsIgnoreCase("next")) {
|
||||
lore = ArrayUtils.getInstance().convert(new VoteNext(plugin, player, user).getChat(player));
|
||||
} else if (slot.equalsIgnoreCase("last")) {
|
||||
lore = ArrayUtils.getInstance().convert(new VoteLast(plugin, player, user).getChat(player));
|
||||
} else if (slot.equalsIgnoreCase("total")) {
|
||||
lore = ArrayUtils.getInstance().convert(new VoteTotal(plugin, player, user).getChat(player));
|
||||
} else if (slot.equalsIgnoreCase("top")) {
|
||||
|
||||
if (str.equalsIgnoreCase("monthly")) {
|
||||
lore = plugin.getTopVoterHandler().topVoterMonthly(1);
|
||||
} else if (str.equalsIgnoreCase("weekly")) {
|
||||
lore = plugin.getTopVoterHandler().topVoterWeekly(1);
|
||||
} else if (str.equalsIgnoreCase("daily")) {
|
||||
lore = plugin.getTopVoterHandler().topVoterDaily(1);
|
||||
} else {
|
||||
lore = plugin.getTopVoterHandler().topVoterAllTime(1);
|
||||
}
|
||||
} else if (slot.equalsIgnoreCase("today")) {
|
||||
lore = new VoteToday(plugin, player, user, 1).voteToday();
|
||||
} else if (slot.equalsIgnoreCase("help")) {
|
||||
lore = new String[] { "Click to view help" };
|
||||
}
|
||||
}
|
||||
builder.setLore(ArrayUtils.getInstance().convert(lore));
|
||||
return builder;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBook(Player player) {
|
||||
/*
|
||||
* BookWrapper book = new
|
||||
* BookWrapper(plugin.getGui().getBookVoteURLBookGUITitle());
|
||||
*
|
||||
* // url - click to open Layout urlLayout = new Layout(new
|
||||
* ArrayList<String>(Arrays.asList("[Json]")));
|
||||
* urlLayout.replaceTextComponent("[Json]",
|
||||
* BookUtil.TextBuilder.of(book.colorize("Click me")).onClick(BookUtil.
|
||||
* ClickAction.runCommand("/vote url"))
|
||||
* .onHover(BookUtil.HoverAction.showText("Clicking me opens url GUI")).build())
|
||||
* ; book.addLayout(urlLayout); book.addLine();
|
||||
*
|
||||
* // next - click to open for (VoteSite site : plugin.getVoteSites()) { Layout
|
||||
* nextLayout = new Layout(new ArrayList<String>(Arrays.asList("[Json]")));
|
||||
* nextLayout.replaceTextComponent("[Json]",
|
||||
* BookUtil.TextBuilder.of(site.getDisplayName())
|
||||
* .onClick(BookUtil.ClickAction.openUrl(site.getVoteURLJsonStrip()))
|
||||
* .onHover(BookUtil.HoverAction.showText(user.voteCommandNextInfo(site))).build
|
||||
* ()); book.addLayout(nextLayout); } book.addLine();
|
||||
*
|
||||
* // total - click to open
|
||||
*
|
||||
* // top = click to open
|
||||
*
|
||||
* // today - click to open
|
||||
*
|
||||
* // shop - click to open
|
||||
*
|
||||
* book.open(player);
|
||||
*/
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onChat(CommandSender sender) {
|
||||
// not available
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onChest(Player player) {
|
||||
if ((!player.getName().equals(user.getPlayerName())
|
||||
&& !player.hasPermission("VotingPlugin.Commands.Vote.GUI.Other")
|
||||
&& !player.hasPermission("VotingPlugin.Mod"))
|
||||
|| (!player.hasPermission("VotingPlugin.Commands.Vote.GUI")
|
||||
&& !player.hasPermission("VotingPlugin.Player"))) {
|
||||
player.sendMessage(
|
||||
StringParser.getInstance().colorize(VotingPluginMain.plugin.getOptions().getFormatNoPerms()));
|
||||
return;
|
||||
}
|
||||
BInventory inv = new BInventory(plugin.getGui().getChestVoteGUIName());
|
||||
if (!plugin.getConfigFile().isAlwaysCloseInventory()) {
|
||||
inv.dontClose();
|
||||
}
|
||||
|
||||
inv.addPlaceholder("points", "" + user.getPoints());
|
||||
inv.addPlaceholder("player", user.getPlayerName());
|
||||
inv.addPlaceholder("top", plugin.getConfigFile().getVoteTopDefault());
|
||||
|
||||
for (String slot : plugin.getGui().getChestVoteGUISlots()) {
|
||||
ItemBuilder builder = getItemSlot(slot, player);
|
||||
|
||||
inv.addButton(new UpdatingBInventoryButton(builder, 1000, 1000) {
|
||||
|
||||
@Override
|
||||
public void onClick(ClickEvent event) {
|
||||
|
||||
Player player = event.getWhoClicked();
|
||||
String cmd = plugin.getGui().getChestVoteGUISlotCommand(slot);
|
||||
if (cmd.equalsIgnoreCase("none")) {
|
||||
return;
|
||||
} else if (!cmd.equals("")) {
|
||||
event.runSync(new Runnable() {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
player.performCommand(cmd);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
if (slot.equalsIgnoreCase("url")) {
|
||||
new VoteURL(plugin, player, user, true).open();
|
||||
} else if (slot.equalsIgnoreCase("next")) {
|
||||
new VoteNext(plugin, player, user).open(GUIMethod.CHEST);
|
||||
} else if (slot.equalsIgnoreCase("last")) {
|
||||
new VoteLast(plugin, player, user).open(GUIMethod.CHEST);
|
||||
} else if (slot.equalsIgnoreCase("total")) {
|
||||
new VoteTotal(plugin, player, user).open(GUIMethod.CHEST);
|
||||
} else if (slot.equalsIgnoreCase("top")) {
|
||||
new VoteTopVoter(plugin, player, user, TopVoter.getDefault(), 1).open(GUIMethod.CHEST);
|
||||
} else if (slot.equalsIgnoreCase("today")) {
|
||||
new VoteToday(plugin, player, user, 1).open(GUIMethod.CHEST);
|
||||
} else if (slot.equalsIgnoreCase("help")) {
|
||||
player.performCommand("vote help");
|
||||
} else if (slot.equalsIgnoreCase("shop")) {
|
||||
new VoteShop(plugin, player, user).open(GUIMethod.CHEST);
|
||||
} else if (slot.equalsIgnoreCase("lastmonth")) {
|
||||
new VoteTopVoterLastMonth(plugin, player, user).open(GUIMethod.CHEST);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemBuilder onUpdate(Player player) {
|
||||
ItemBuilder item = getItemSlot(slot, player);
|
||||
VotingPluginUser user = UserManager.getInstance().getVotingPluginUser(player);
|
||||
item.addPlaceholder("points", "" + user.getPoints());
|
||||
item.addPlaceholder("player", user.getPlayerName());
|
||||
item.addPlaceholder("top", plugin.getConfigFile().getVoteTopDefault());
|
||||
return item;
|
||||
}
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
inv.openInventory(player);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void open() {
|
||||
open(GUIMethod.valueOf(plugin.getGui().getGuiMethodGUI().toUpperCase()));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,98 @@
|
||||
package com.bencodez.votingplugin.commands.gui.player;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import com.bencodez.advancedcore.api.command.CommandHandler;
|
||||
import com.bencodez.advancedcore.api.gui.GUIHandler;
|
||||
import com.bencodez.advancedcore.api.gui.GUIMethod;
|
||||
import com.bencodez.advancedcore.api.messages.StringParser;
|
||||
import com.bencodez.votingplugin.VotingPluginMain;
|
||||
|
||||
import net.md_5.bungee.api.chat.TextComponent;
|
||||
|
||||
public class VoteHelp extends GUIHandler {
|
||||
|
||||
private int page;
|
||||
private VotingPluginMain plugin;
|
||||
|
||||
public VoteHelp(VotingPluginMain plugin, CommandSender player, int page) {
|
||||
super(player);
|
||||
this.plugin = plugin;
|
||||
this.page = page;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ArrayList<String> getChat(CommandSender sender) {
|
||||
return null;
|
||||
}
|
||||
|
||||
public ArrayList<TextComponent> helpText(CommandSender sender) {
|
||||
ArrayList<TextComponent> msg = new ArrayList<TextComponent>();
|
||||
HashMap<String, TextComponent> unsorted = new HashMap<String, TextComponent>();
|
||||
|
||||
boolean requirePerms = plugin.getConfigFile().getFormatCommandsVoteHelpRequirePermission();
|
||||
|
||||
for (CommandHandler cmdHandle : plugin.getVoteCommand()) {
|
||||
if (requirePerms && sender.hasPermission(cmdHandle.getPerm())) {
|
||||
unsorted.put(cmdHandle.getHelpLineCommand("/vote"),
|
||||
cmdHandle.getHelpLine("/vote", plugin.getConfigFile().getFormatCommandsVoteHelpLine()));
|
||||
} else {
|
||||
unsorted.put(cmdHandle.getHelpLineCommand("/vote"), cmdHandle.getHelpLine("/vote"));
|
||||
}
|
||||
}
|
||||
ArrayList<String> unsortedList = new ArrayList<String>();
|
||||
unsortedList.addAll(unsorted.keySet());
|
||||
Collections.sort(unsortedList, String.CASE_INSENSITIVE_ORDER);
|
||||
for (String cmd : unsortedList) {
|
||||
msg.add(unsorted.get(cmd));
|
||||
}
|
||||
|
||||
return msg;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBook(Player player) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onChat(CommandSender sender) {
|
||||
sendMessageJson(voteHelpText(sender));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onChest(Player player) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void open() {
|
||||
open(GUIMethod.CHAT);
|
||||
}
|
||||
|
||||
public ArrayList<TextComponent> voteHelpText(CommandSender sender) {
|
||||
int pagesize = plugin.getConfigFile().getFormatPageSize();
|
||||
ArrayList<TextComponent> msg = new ArrayList<TextComponent>();
|
||||
ArrayList<TextComponent> text = helpText(sender);
|
||||
|
||||
int maxPage = text.size() / pagesize;
|
||||
if ((text.size() % pagesize) != 0) {
|
||||
maxPage++;
|
||||
}
|
||||
|
||||
msg.add(StringParser.getInstance()
|
||||
.stringToComp(plugin.getConfigFile().getFormatCommandsVoteHelpTitle() + " " + page + "/" + maxPage));
|
||||
|
||||
for (int i = pagesize * (page - 1); (i < text.size()) && (i < ((page) * pagesize)); i++) {
|
||||
msg.add(text.get(i));
|
||||
}
|
||||
|
||||
return msg;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,90 @@
|
||||
package com.bencodez.votingplugin.commands.gui.player;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import com.bencodez.advancedcore.api.gui.GUIHandler;
|
||||
import com.bencodez.advancedcore.api.gui.GUIMethod;
|
||||
import com.bencodez.advancedcore.api.inventory.BInventory;
|
||||
import com.bencodez.advancedcore.api.inventory.BInventory.ClickEvent;
|
||||
import com.bencodez.advancedcore.api.inventory.UpdatingBInventoryButton;
|
||||
import com.bencodez.advancedcore.api.item.ItemBuilder;
|
||||
import com.bencodez.advancedcore.api.messages.StringParser;
|
||||
import com.bencodez.advancedcore.api.misc.ArrayUtils;
|
||||
import com.bencodez.votingplugin.VotingPluginMain;
|
||||
import com.bencodez.votingplugin.objects.VoteSite;
|
||||
import com.bencodez.votingplugin.user.VotingPluginUser;
|
||||
|
||||
public class VoteLast extends GUIHandler {
|
||||
|
||||
private VotingPluginMain plugin;
|
||||
private VotingPluginUser user;
|
||||
|
||||
public VoteLast(VotingPluginMain plugin, CommandSender player, VotingPluginUser user) {
|
||||
super(player);
|
||||
this.plugin = plugin;
|
||||
this.user = user;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ArrayList<String> getChat(CommandSender sender) {
|
||||
ArrayList<String> msg = new ArrayList<String>();
|
||||
|
||||
String playerName = user.getPlayerName();
|
||||
|
||||
msg.add(StringParser.getInstance().replaceIgnoreCase(plugin.getConfigFile().getFormatCommandsVoteLastTitle(),
|
||||
"%player%", playerName));
|
||||
|
||||
for (VoteSite voteSite : plugin.getVoteSites()) {
|
||||
msg.add(user.voteCommandLastLine(voteSite));
|
||||
}
|
||||
|
||||
return ArrayUtils.getInstance().colorize(msg);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBook(Player player) {
|
||||
// TODO
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onChat(CommandSender sender) {
|
||||
sendMessage(getChat(sender));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onChest(Player player) {
|
||||
BInventory inv = new BInventory(plugin.getGui().getChestVoteLastName());
|
||||
inv.addPlaceholder("player", user.getPlayerName());
|
||||
for (VoteSite site : plugin.getVoteSites()) {
|
||||
inv.addButton(inv.getNextSlot(), new UpdatingBInventoryButton(site.getItem().setName(site.getDisplayName())
|
||||
.setLore(user.voteCommandLastLine(site)).setAmountNone(1), 1000, 1000) {
|
||||
|
||||
@Override
|
||||
public void onClick(ClickEvent clickEvent) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemBuilder onUpdate(Player p) {
|
||||
return site.getItem().setName(site.getDisplayName()).setLore(user.voteCommandLastLine(site))
|
||||
.setAmountNone(1);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
if (plugin.getGui().getChestVoteLastBackButton()) {
|
||||
inv.addButton(plugin.getCommandLoader().getBackButton(user));
|
||||
}
|
||||
|
||||
inv.openInventory(player);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void open() {
|
||||
open(GUIMethod.valueOf(plugin.getGui().getGuiMethodLast().toUpperCase()));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,113 @@
|
||||
package com.bencodez.votingplugin.commands.gui.player;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
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.inventory.BInventory;
|
||||
import com.bencodez.advancedcore.api.inventory.BInventory.ClickEvent;
|
||||
import com.bencodez.advancedcore.api.inventory.UpdatingBInventoryButton;
|
||||
import com.bencodez.advancedcore.api.item.ItemBuilder;
|
||||
import com.bencodez.advancedcore.api.messages.StringParser;
|
||||
import com.bencodez.votingplugin.VotingPluginMain;
|
||||
import com.bencodez.votingplugin.objects.VoteSite;
|
||||
import com.bencodez.votingplugin.user.VotingPluginUser;
|
||||
|
||||
import xyz.upperlevel.spigot.book.BookUtil;
|
||||
|
||||
public class VoteNext extends GUIHandler {
|
||||
|
||||
private VotingPluginMain plugin;
|
||||
private VotingPluginUser user;
|
||||
|
||||
public VoteNext(VotingPluginMain plugin, CommandSender player, VotingPluginUser user) {
|
||||
super(player);
|
||||
this.plugin = plugin;
|
||||
this.user = user;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ArrayList<String> getChat(CommandSender sender) {
|
||||
ArrayList<String> msg = new ArrayList<String>();
|
||||
|
||||
String playerName = user.getPlayerName();
|
||||
|
||||
msg.add(StringParser.getInstance().colorize(StringParser.getInstance()
|
||||
.replaceIgnoreCase(plugin.getConfigFile().getFormatCommandsVoteNextTitle(), "%player%", playerName)));
|
||||
|
||||
for (VoteSite voteSite : plugin.getVoteSites()) {
|
||||
|
||||
String msgLine = plugin.getConfigFile().getFormatCommandsVoteNextLayout();
|
||||
|
||||
msgLine = StringParser.getInstance().replaceIgnoreCase(msgLine, "%info%",
|
||||
user.voteCommandNextInfo(voteSite));
|
||||
|
||||
msgLine = StringParser.getInstance().replaceIgnoreCase(msgLine, "%SiteName%", voteSite.getDisplayName());
|
||||
msg.add(StringParser.getInstance().colorize(msgLine));
|
||||
|
||||
}
|
||||
return msg;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBook(Player player) {
|
||||
BookWrapper book = new BookWrapper(plugin.getGui().getBookVoteURLBookGUITitle());
|
||||
|
||||
// add colors/config options
|
||||
for (VoteSite site : plugin.getVoteSites()) {
|
||||
Layout nextLayout = new Layout(new ArrayList<String>(Arrays.asList("[Json]")));
|
||||
nextLayout.replaceTextComponent("[Json]",
|
||||
BookUtil.TextBuilder.of(book.colorize(site.getDisplayName()))
|
||||
.onClick(BookUtil.ClickAction.openUrl(site.getVoteURLJsonStrip()))
|
||||
.onHover(BookUtil.HoverAction.showText(user.voteCommandNextInfo(site))).build());
|
||||
book.addLayout(nextLayout);
|
||||
}
|
||||
book.addLine();
|
||||
|
||||
book.open(player);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onChat(CommandSender sender) {
|
||||
sendMessage(getChat(sender));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onChest(Player player) {
|
||||
BInventory inv = new BInventory(plugin.getGui().getChestVoteNextName());
|
||||
inv.addPlaceholder("player", user.getPlayerName());
|
||||
for (VoteSite site : plugin.getVoteSites()) {
|
||||
inv.addButton(inv.getNextSlot(), new UpdatingBInventoryButton(site.getItem().setName(site.getDisplayName())
|
||||
.setLore(user.voteCommandNextInfo(site)).setAmountNone(1), 1000, 1000) {
|
||||
|
||||
@Override
|
||||
public void onClick(ClickEvent clickEvent) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemBuilder onUpdate(Player player) {
|
||||
return site.getItem().setName(site.getDisplayName()).setLore(user.voteCommandNextInfo(site))
|
||||
.setAmountNone(1).addPlaceholder("player", user.getPlayerName());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
if (plugin.getGui().getChestVoteNextBackButton()) {
|
||||
inv.addButton(plugin.getCommandLoader().getBackButton(user));
|
||||
}
|
||||
inv.openInventory(player);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void open() {
|
||||
open(GUIMethod.valueOf(plugin.getGui().getGuiMethodNext().toUpperCase()));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,170 @@
|
||||
package com.bencodez.votingplugin.commands.gui.player;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import com.bencodez.advancedcore.api.gui.GUIHandler;
|
||||
import com.bencodez.advancedcore.api.gui.GUIMethod;
|
||||
import com.bencodez.advancedcore.api.inventory.BInventory;
|
||||
import com.bencodez.advancedcore.api.inventory.BInventory.ClickEvent;
|
||||
import com.bencodez.advancedcore.api.inventory.BInventoryButton;
|
||||
import com.bencodez.advancedcore.api.item.ItemBuilder;
|
||||
import com.bencodez.advancedcore.api.messages.StringParser;
|
||||
import com.bencodez.advancedcore.api.rewards.RewardHandler;
|
||||
import com.bencodez.advancedcore.api.rewards.RewardOptions;
|
||||
import com.bencodez.votingplugin.VotingPluginMain;
|
||||
import com.bencodez.votingplugin.user.UserManager;
|
||||
import com.bencodez.votingplugin.user.VotingPluginUser;
|
||||
|
||||
public class VoteShop extends GUIHandler {
|
||||
|
||||
private VotingPluginMain plugin;
|
||||
private VotingPluginUser user;
|
||||
|
||||
public VoteShop(VotingPluginMain plugin, CommandSender player, VotingPluginUser user) {
|
||||
super(player);
|
||||
this.plugin = plugin;
|
||||
this.user = user;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ArrayList<String> getChat(CommandSender arg0) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBook(Player player) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onChat(CommandSender sender) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onChest(Player player) {
|
||||
if (!plugin.getGui().getChestVoteShopEnabled()) {
|
||||
player.sendMessage(StringParser.getInstance().colorize(plugin.getGui().getChestVoteShopDisabled()));
|
||||
return;
|
||||
}
|
||||
|
||||
BInventory inv = new BInventory(plugin.getGui().getChestVoteShopName());
|
||||
inv.dontClose();
|
||||
|
||||
for (final String identifier : plugin.getGui().getChestShopIdentifiers()) {
|
||||
|
||||
String perm = plugin.getGui().getChestVoteShopPermission(identifier);
|
||||
boolean hasPerm = false;
|
||||
if (perm.isEmpty()) {
|
||||
hasPerm = true;
|
||||
} else {
|
||||
hasPerm = player.hasPermission(perm);
|
||||
}
|
||||
|
||||
int limit = plugin.getGui().getChestShopIdentifierLimit(identifier);
|
||||
|
||||
boolean limitPass = true;
|
||||
if (limit > 0) {
|
||||
VotingPluginUser user = UserManager.getInstance().getVotingPluginUser(player);
|
||||
if (user.getVoteShopIdentifierLimit(identifier) >= limit) {
|
||||
limitPass = false;
|
||||
}
|
||||
}
|
||||
|
||||
if (!plugin.getGui().getChestVoteShopNotBuyable(identifier)) {
|
||||
if (hasPerm && (limitPass || !plugin.getGui().isChestVoteShopHideLimitedReached())) {
|
||||
ItemBuilder builder = new ItemBuilder(plugin.getGui().getChestShopIdentifierSection(identifier));
|
||||
|
||||
inv.addButton(new BInventoryButton(builder) {
|
||||
|
||||
@Override
|
||||
public void onClick(ClickEvent event) {
|
||||
Player player = event.getWhoClicked();
|
||||
|
||||
VotingPluginUser user = UserManager.getInstance().getVotingPluginUser(player);
|
||||
if (plugin.getConfigFile().isClearCacheOnVoteShopPurchase()
|
||||
|| plugin.getBungeeSettings().isUseBungeecoord()) {
|
||||
user.clearCache();
|
||||
}
|
||||
String identifier = (String) getData("identifier");
|
||||
int limit = (int) getData("Limit");
|
||||
int points = plugin.getGui().getChestShopIdentifierCost(identifier);
|
||||
if (identifier != null) {
|
||||
if (plugin.getGui().getChestVoteShopCloseGUI(identifier)) {
|
||||
event.getButton().getInv().closeInv(player, null);
|
||||
}
|
||||
|
||||
// limit fail-safe, should never be needed, except in rare cases
|
||||
boolean limitPass = true;
|
||||
if (limit > 0) {
|
||||
if (user.getVoteShopIdentifierLimit(identifier) >= limit) {
|
||||
limitPass = false;
|
||||
}
|
||||
}
|
||||
|
||||
if (limitPass) {
|
||||
if (!plugin.getGui().isChestVoteShopRequireConfirmation()) {
|
||||
HashMap<String, String> placeholders = new HashMap<String, String>();
|
||||
placeholders.put("identifier",
|
||||
plugin.getGui().getChestShopIdentifierIdentifierName(identifier));
|
||||
placeholders.put("points", "" + points);
|
||||
placeholders.put("limit", "" + limit);
|
||||
if (user.removePoints(points)) {
|
||||
|
||||
RewardHandler.getInstance().giveReward(user, plugin.getGui().getData(),
|
||||
plugin.getGui().getChestShopIdentifierRewardsPath(identifier),
|
||||
new RewardOptions().setPlaceholders(placeholders));
|
||||
|
||||
user.sendMessage(StringParser.getInstance().replacePlaceHolder(
|
||||
plugin.getConfigFile().getFormatShopPurchaseMsg(), placeholders));
|
||||
if (limit > 0) {
|
||||
user.setVoteShopIdentifierLimit(identifier,
|
||||
user.getVoteShopIdentifierLimit(identifier) + 1);
|
||||
}
|
||||
} else {
|
||||
user.sendMessage(StringParser.getInstance().replacePlaceHolder(
|
||||
plugin.getConfigFile().getFormatShopFailedMsg(), placeholders));
|
||||
}
|
||||
} else {
|
||||
new VoteShopConfirm(plugin, player, user, identifier).open(GUIMethod.CHEST);
|
||||
;
|
||||
}
|
||||
} else {
|
||||
user.sendMessage(plugin.getGui().getChestVoteShopLimitReached());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}.addData("identifier", identifier).addData("Limit", limit));
|
||||
}
|
||||
} else {
|
||||
if (hasPerm) {
|
||||
ItemBuilder builder = new ItemBuilder(plugin.getGui().getChestShopIdentifierSection(identifier));
|
||||
inv.addButton(new BInventoryButton(builder) {
|
||||
|
||||
@Override
|
||||
public void onClick(ClickEvent event) {
|
||||
|
||||
}
|
||||
|
||||
}.dontClose().addData("identifier", identifier).addData("Limit", limit));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (plugin.getGui().getChestVoteShopBackButton()) {
|
||||
inv.addButton(plugin.getCommandLoader().getBackButton(user));
|
||||
}
|
||||
|
||||
inv.openInventory(player);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void open() {
|
||||
open(GUIMethod.CHEST);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,104 @@
|
||||
package com.bencodez.votingplugin.commands.gui.player;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import com.bencodez.advancedcore.api.gui.GUIHandler;
|
||||
import com.bencodez.advancedcore.api.gui.GUIMethod;
|
||||
import com.bencodez.advancedcore.api.inventory.BInventory;
|
||||
import com.bencodez.advancedcore.api.inventory.BInventory.ClickEvent;
|
||||
import com.bencodez.advancedcore.api.inventory.BInventoryButton;
|
||||
import com.bencodez.advancedcore.api.item.ItemBuilder;
|
||||
import com.bencodez.advancedcore.api.messages.StringParser;
|
||||
import com.bencodez.advancedcore.api.misc.PlayerUtils;
|
||||
import com.bencodez.advancedcore.api.rewards.RewardHandler;
|
||||
import com.bencodez.advancedcore.api.rewards.RewardOptions;
|
||||
import com.bencodez.votingplugin.VotingPluginMain;
|
||||
import com.bencodez.votingplugin.user.VotingPluginUser;
|
||||
|
||||
public class VoteShopConfirm extends GUIHandler {
|
||||
|
||||
private String identifier;
|
||||
private VotingPluginMain plugin;
|
||||
private VotingPluginUser user;
|
||||
|
||||
public VoteShopConfirm(VotingPluginMain plugin, CommandSender player, VotingPluginUser user, String identifier) {
|
||||
super(player);
|
||||
this.plugin = plugin;
|
||||
this.user = user;
|
||||
this.identifier = identifier;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ArrayList<String> getChat(CommandSender arg0) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBook(Player player) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onChat(CommandSender sender) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onChest(Player player) {
|
||||
PlayerUtils.getInstance().setPlayerMeta(player, "ident", identifier);
|
||||
BInventory inv = new BInventory(plugin.getGui().getChestShopConfirmPurchaseTitle());
|
||||
inv.addButton(new BInventoryButton(new ItemBuilder(plugin.getGui().getChestShopConfirmPurchaseYesItem())) {
|
||||
|
||||
@Override
|
||||
public void onClick(ClickEvent event) {
|
||||
int points = plugin.getGui().getChestShopIdentifierCost(identifier);
|
||||
int limit = plugin.getGui().getChestShopIdentifierLimit(identifier);
|
||||
HashMap<String, String> placeholders = new HashMap<String, String>();
|
||||
placeholders.put("identifier", identifier);
|
||||
placeholders.put("points", "" + points);
|
||||
placeholders.put("limit", "" + limit);
|
||||
if (user.removePoints(points)) {
|
||||
|
||||
RewardHandler.getInstance().giveReward(user, plugin.getGui().getData(),
|
||||
plugin.getGui().getChestShopIdentifierRewardsPath(identifier),
|
||||
new RewardOptions().setPlaceholders(placeholders));
|
||||
|
||||
user.sendMessage(StringParser.getInstance()
|
||||
.replacePlaceHolder(plugin.getConfigFile().getFormatShopPurchaseMsg(), placeholders));
|
||||
if (limit > 0) {
|
||||
user.setVoteShopIdentifierLimit(identifier, user.getVoteShopIdentifierLimit(identifier) + 1);
|
||||
}
|
||||
} else {
|
||||
user.sendMessage(StringParser.getInstance()
|
||||
.replacePlaceHolder(plugin.getConfigFile().getFormatShopFailedMsg(), placeholders));
|
||||
}
|
||||
if (plugin.getGui().getChestVoteShopCloseGUI(identifier)) {
|
||||
event.getButton().getInv().closeInv(player, null);
|
||||
} else {
|
||||
new VoteShop(plugin, event.getPlayer(), user);
|
||||
}
|
||||
|
||||
}
|
||||
});
|
||||
inv.addButton(new BInventoryButton(new ItemBuilder(plugin.getGui().getChestShopConfirmPurchaseNoItem())) {
|
||||
|
||||
@Override
|
||||
public void onClick(ClickEvent event) {
|
||||
if (plugin.getGui().getChestVoteShopCloseGUI(identifier)) {
|
||||
event.getButton().getInv().closeInv(player, null);
|
||||
} else {
|
||||
new VoteShop(plugin, event.getPlayer(), user);
|
||||
}
|
||||
}
|
||||
});
|
||||
inv.openInventory(player);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void open() {
|
||||
open(GUIMethod.CHEST);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,134 @@
|
||||
package com.bencodez.votingplugin.commands.gui.player;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import com.bencodez.advancedcore.api.gui.GUIHandler;
|
||||
import com.bencodez.advancedcore.api.gui.GUIMethod;
|
||||
import com.bencodez.advancedcore.api.inventory.BInventory;
|
||||
import com.bencodez.advancedcore.api.inventory.BInventory.ClickEvent;
|
||||
import com.bencodez.advancedcore.api.inventory.BInventoryButton;
|
||||
import com.bencodez.advancedcore.api.item.ItemBuilder;
|
||||
import com.bencodez.advancedcore.api.misc.ArrayUtils;
|
||||
import com.bencodez.votingplugin.VotingPluginMain;
|
||||
import com.bencodez.votingplugin.user.VotingPluginUser;
|
||||
|
||||
public class VoteStreak extends GUIHandler {
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
private VotingPluginMain plugin;
|
||||
private VotingPluginUser user;
|
||||
|
||||
public VoteStreak(VotingPluginMain plugin, CommandSender player, VotingPluginUser user) {
|
||||
super(player);
|
||||
this.plugin = plugin;
|
||||
this.user = user;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ArrayList<String> getChat(CommandSender sender) {
|
||||
ArrayList<String> msg = new ArrayList<String>();
|
||||
msg.add(plugin.getConfigFile().getFormatCommandsVoteStreakTitle());
|
||||
msg.addAll(plugin.getConfigFile().getFormatCommandsVoteStreakLines());
|
||||
|
||||
HashMap<String, String> placeholders = new HashMap<String, String>();
|
||||
placeholders.put("DailyStreak", "" + user.getDayVoteStreak());
|
||||
placeholders.put("WeeklyStreak", "" + user.getWeekVoteStreak());
|
||||
placeholders.put("MonthlyStreak", "" + user.getMonthVoteStreak());
|
||||
|
||||
placeholders.put("BestDailyStreak", "" + user.getBestDayVoteStreak());
|
||||
placeholders.put("BestWeeklyStreak", "" + user.getBestWeekVoteStreak());
|
||||
placeholders.put("BestMonthlyStreak", "" + user.getBestMonthVoteStreak());
|
||||
|
||||
placeholders.put("player", user.getPlayerName());
|
||||
|
||||
msg = ArrayUtils.getInstance().replacePlaceHolder(msg, placeholders);
|
||||
|
||||
return ArrayUtils.getInstance().colorize(msg);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBook(Player player) {
|
||||
// TODO
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onChat(CommandSender sender) {
|
||||
sendMessage(getChat(sender));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onChest(Player player) {
|
||||
BInventory inv = new BInventory(plugin.getGui().getChestVoteStreakName());
|
||||
inv.addPlaceholder("player", user.getPlayerName());
|
||||
|
||||
inv.addButton(new BInventoryButton(new ItemBuilder(plugin.getGui().getChestVoteStreakCurrentDayStreakItem())
|
||||
.addPlaceholder("Streak", "" + user.getDayVoteStreak())) {
|
||||
|
||||
@Override
|
||||
public void onClick(ClickEvent clickEvent) {
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
inv.addButton(new BInventoryButton(new ItemBuilder(plugin.getGui().getChestVoteStreakCurrentWeekStreakItem())
|
||||
.addPlaceholder("Streak", "" + user.getWeekVoteStreak())) {
|
||||
|
||||
@Override
|
||||
public void onClick(ClickEvent clickEvent) {
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
inv.addButton(new BInventoryButton(new ItemBuilder(plugin.getGui().getChestVoteStreakCurrentMonthStreakItem())
|
||||
.addPlaceholder("Streak", "" + user.getMonthVoteStreak())) {
|
||||
|
||||
@Override
|
||||
public void onClick(ClickEvent clickEvent) {
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
inv.addButton(new BInventoryButton(new ItemBuilder(plugin.getGui().getChestVoteStreakHighestDayStreakItem())
|
||||
.addPlaceholder("Streak", "" + user.getBestDayVoteStreak())) {
|
||||
|
||||
@Override
|
||||
public void onClick(ClickEvent clickEvent) {
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
inv.addButton(new BInventoryButton(new ItemBuilder(plugin.getGui().getChestVoteStreakHighestWeekStreakItem())
|
||||
.addPlaceholder("Streak", "" + user.getBestWeekVoteStreak())) {
|
||||
|
||||
@Override
|
||||
public void onClick(ClickEvent clickEvent) {
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
inv.addButton(new BInventoryButton(new ItemBuilder(plugin.getGui().getChestVoteStreakHighestMonthStreakItem())
|
||||
.addPlaceholder("Streak", "" + user.getBestMonthVoteStreak())) {
|
||||
|
||||
@Override
|
||||
public void onClick(ClickEvent clickEvent) {
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
if (plugin.getGui().getChestVoteStreakBackButton()) {
|
||||
inv.addButton(plugin.getCommandLoader().getBackButton(user));
|
||||
}
|
||||
|
||||
inv.openInventory(player);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void open() {
|
||||
open(GUIMethod.valueOf(plugin.getGui().getGuiMethodStreak().toUpperCase()));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,144 @@
|
||||
package com.bencodez.votingplugin.commands.gui.player;
|
||||
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import com.bencodez.advancedcore.api.gui.GUIHandler;
|
||||
import com.bencodez.advancedcore.api.gui.GUIMethod;
|
||||
import com.bencodez.advancedcore.api.inventory.BInventory;
|
||||
import com.bencodez.advancedcore.api.inventory.BInventory.ClickEvent;
|
||||
import com.bencodez.advancedcore.api.inventory.BInventoryButton;
|
||||
import com.bencodez.advancedcore.api.item.ItemBuilder;
|
||||
import com.bencodez.advancedcore.api.messages.StringParser;
|
||||
import com.bencodez.advancedcore.api.misc.ArrayUtils;
|
||||
import com.bencodez.advancedcore.nms.NMSManager;
|
||||
import com.bencodez.votingplugin.VotingPluginMain;
|
||||
import com.bencodez.votingplugin.objects.VoteSite;
|
||||
import com.bencodez.votingplugin.user.UserManager;
|
||||
import com.bencodez.votingplugin.user.VotingPluginUser;
|
||||
|
||||
public class VoteToday extends GUIHandler {
|
||||
|
||||
private int page;
|
||||
private VotingPluginMain plugin;
|
||||
private VotingPluginUser user;
|
||||
|
||||
public VoteToday(VotingPluginMain plugin, CommandSender player, VotingPluginUser user, int page) {
|
||||
super(player);
|
||||
this.plugin = plugin;
|
||||
this.user = user;
|
||||
this.page = page;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ArrayList<String> getChat(CommandSender arg0) {
|
||||
int pagesize = plugin.getConfigFile().getFormatPageSize();
|
||||
if (page < 1) {
|
||||
page = 1;
|
||||
}
|
||||
ArrayList<String> msg = new ArrayList<String>();
|
||||
String[] voteToday = voteToday();
|
||||
|
||||
int maxPage = voteToday.length / pagesize;
|
||||
if ((voteToday.length % pagesize) != 0) {
|
||||
maxPage++;
|
||||
}
|
||||
|
||||
msg.add("&cToday's Votes " + page + "/" + maxPage);
|
||||
msg.add("&cPlayerName : VoteSite : Time");
|
||||
page--;
|
||||
|
||||
for (int i = pagesize * page; (i < voteToday.length) && (i < ((page + 1) * pagesize)); i++) {
|
||||
msg.add(voteToday[i]);
|
||||
}
|
||||
|
||||
return ArrayUtils.getInstance().colorize(msg);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBook(Player player) {
|
||||
// TODO
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onChat(CommandSender sender) {
|
||||
sendMessage(getChat(sender));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onChest(Player player) {
|
||||
BInventory inv = new BInventory(plugin.getGui().getChestVoteTodayName());
|
||||
if (!plugin.getConfigFile().isAlwaysCloseInventory()) {
|
||||
inv.dontClose();
|
||||
}
|
||||
for (VotingPluginUser user : plugin.getVoteToday().keySet()) {
|
||||
|
||||
for (VoteSite voteSite : plugin.getVoteToday().get(user).keySet()) {
|
||||
DateTimeFormatter formatter = DateTimeFormatter.ofPattern(plugin.getConfigFile().getFormatTimeFormat());
|
||||
String timeString = plugin.getVoteToday().get(user).get(voteSite).format(formatter);
|
||||
String msg = plugin.getGui().getChestVoteTodayLine();
|
||||
HashMap<String, String> placeholders = new HashMap<String, String>();
|
||||
placeholders.put("VoteSite", voteSite.getDisplayName());
|
||||
placeholders.put("Time", timeString);
|
||||
msg = StringParser.getInstance().replacePlaceHolder(msg, placeholders);
|
||||
ItemBuilder item = null;
|
||||
if (plugin.getGui().isChestVoteTodayUseSkull() && !NMSManager.getInstance().isVersion("1.12")) {
|
||||
item = new ItemBuilder(new ItemStack(Material.PLAYER_HEAD, 1)).setSkullOwner(player);
|
||||
} else {
|
||||
item = new ItemBuilder(plugin.getGui().getChestVoteTodayPlayerItem());
|
||||
}
|
||||
item.setName(StringParser.getInstance().replacePlaceHolder(plugin.getGui().getChestVoteTodayIconTitle(),
|
||||
"player", user.getPlayerName()));
|
||||
item.setLore(msg);
|
||||
inv.addButton(inv.getNextSlot(), new BInventoryButton(item) {
|
||||
|
||||
@Override
|
||||
public void onClick(ClickEvent clickEvent) {
|
||||
VotingPluginUser user = UserManager.getInstance()
|
||||
.getVotingPluginUser(clickEvent.getClickedItem().getItemMeta().getDisplayName());
|
||||
new VoteGUI(plugin, player, user)
|
||||
.open(GUIMethod.valueOf(plugin.getGui().getGuiMethodGUI().toUpperCase()));
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
if (plugin.getGui().getChestVoteTodayBackButton()) {
|
||||
inv.addButton(plugin.getCommandLoader().getBackButton(user));
|
||||
}
|
||||
inv.openInventory(player);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void open() {
|
||||
open(GUIMethod.valueOf(plugin.getGui().getGuiMethodToday().toUpperCase()));
|
||||
}
|
||||
|
||||
public String[] voteToday() {
|
||||
ArrayList<String> msg = new ArrayList<String>();
|
||||
for (VotingPluginUser user : plugin.getVoteToday().keySet()) {
|
||||
|
||||
for (VoteSite voteSite : plugin.getVoteToday().get(user).keySet()) {
|
||||
DateTimeFormatter formatter = DateTimeFormatter.ofPattern(plugin.getConfigFile().getFormatTimeFormat());
|
||||
String timeString = plugin.getVoteToday().get(user).get(voteSite).format(formatter);
|
||||
HashMap<String, String> placeholders = new HashMap<String, String>();
|
||||
placeholders.put("player", user.getPlayerName());
|
||||
placeholders.put("votesite", voteSite.getKey());
|
||||
placeholders.put("time", timeString);
|
||||
msg.add(StringParser.getInstance()
|
||||
.replacePlaceHolder(plugin.getConfigFile().getFormatCommandsVoteTodayLine(), placeholders));
|
||||
// msg.add("&6" + user.getPlayerName() + " : " + voteSite.getKey() + " : " +
|
||||
// timeString);
|
||||
}
|
||||
}
|
||||
msg = ArrayUtils.getInstance().colorize(msg);
|
||||
return ArrayUtils.getInstance().convert(msg);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,144 @@
|
||||
package com.bencodez.votingplugin.commands.gui.player;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.Set;
|
||||
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.inventory.ClickType;
|
||||
|
||||
import com.bencodez.advancedcore.api.gui.GUIHandler;
|
||||
import com.bencodez.advancedcore.api.gui.GUIMethod;
|
||||
import com.bencodez.advancedcore.api.inventory.BInventory;
|
||||
import com.bencodez.advancedcore.api.inventory.BInventory.ClickEvent;
|
||||
import com.bencodez.advancedcore.api.inventory.BInventoryButton;
|
||||
import com.bencodez.advancedcore.api.item.ItemBuilder;
|
||||
import com.bencodez.advancedcore.api.misc.ArrayUtils;
|
||||
import com.bencodez.votingplugin.VotingPluginMain;
|
||||
import com.bencodez.votingplugin.topvoter.TopVoter;
|
||||
import com.bencodez.votingplugin.user.VotingPluginUser;
|
||||
|
||||
public class VoteTopVoter extends GUIHandler {
|
||||
|
||||
private int page;
|
||||
private VotingPluginMain plugin;
|
||||
private TopVoter top;
|
||||
private VotingPluginUser user;
|
||||
|
||||
public VoteTopVoter(VotingPluginMain plugin, CommandSender player, VotingPluginUser user, TopVoter top, int page) {
|
||||
super(player);
|
||||
this.plugin = plugin;
|
||||
this.user = user;
|
||||
this.top = top;
|
||||
this.page = page;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ArrayList<String> getChat(CommandSender sender) {
|
||||
switch (top) {
|
||||
case AllTime:
|
||||
return ArrayUtils.getInstance().convert(plugin.getTopVoterHandler().topVoterAllTime(page));
|
||||
case Daily:
|
||||
return ArrayUtils.getInstance().convert(plugin.getTopVoterHandler().topVoterDaily(page));
|
||||
case Monthly:
|
||||
return ArrayUtils.getInstance().convert(plugin.getTopVoterHandler().topVoterMonthly(page));
|
||||
case Weekly:
|
||||
return ArrayUtils.getInstance().convert(plugin.getTopVoterHandler().topVoterWeekly(page));
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return new ArrayList<String>();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBook(Player player) {
|
||||
// TODO
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onChat(CommandSender sender) {
|
||||
sendMessage(getChat(sender));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onChest(Player player) {
|
||||
try {
|
||||
if (top == null) {
|
||||
top = TopVoter.getDefault();
|
||||
}
|
||||
Set<Entry<VotingPluginUser, Integer>> users = null;
|
||||
|
||||
String topVoter = top.getName();
|
||||
@SuppressWarnings("unchecked")
|
||||
LinkedHashMap<VotingPluginUser, Integer> topVotes = (LinkedHashMap<VotingPluginUser, Integer>) plugin
|
||||
.getTopVoter(top).clone();
|
||||
users = topVotes.entrySet();
|
||||
|
||||
BInventory inv = new BInventory(plugin.getGui().getChestVoteTopName());
|
||||
inv.addPlaceholder("topvoter", topVoter);
|
||||
if (!plugin.getConfigFile().isAlwaysCloseInventory()) {
|
||||
inv.dontClose();
|
||||
}
|
||||
|
||||
int pos = 1;
|
||||
for (Entry<VotingPluginUser, Integer> entry : users) {
|
||||
ItemBuilder playerItem;
|
||||
|
||||
if (plugin.getGui().isChestVoteTopUseSkull()) {
|
||||
playerItem = new ItemBuilder(entry.getKey().getPlayerHead());
|
||||
} else {
|
||||
playerItem = new ItemBuilder(Material.valueOf(plugin.getGui().getChestVoteTopPlayerItemMaterial()));
|
||||
}
|
||||
|
||||
playerItem.setLore(new ArrayList<String>());
|
||||
|
||||
inv.addButton(new BInventoryButton(playerItem.setName(plugin.getGui().getChestVoteTopItemName())
|
||||
.addLoreLine(plugin.getGui().getChestVoteTopItemLore()).addPlaceholder("position", "" + pos)
|
||||
.addPlaceholder("player", entry.getKey().getPlayerName())
|
||||
.addPlaceholder("votes", "" + entry.getValue())) {
|
||||
|
||||
@Override
|
||||
public void onClick(ClickEvent clickEvent) {
|
||||
VotingPluginUser user = (VotingPluginUser) getData("User");
|
||||
new VoteGUI(plugin, player, user)
|
||||
.open(GUIMethod.valueOf(plugin.getGui().getGuiMethodGUI().toUpperCase()));
|
||||
}
|
||||
}.addData("player", entry.getKey().getPlayerName()).addData("User", entry.getKey()));
|
||||
pos++;
|
||||
}
|
||||
|
||||
final TopVoter cur = top;
|
||||
inv.getPageButtons().add(new BInventoryButton(
|
||||
new ItemBuilder(plugin.getGui().getChestVoteTopSwitchItem()).addPlaceholder("Top", topVoter)) {
|
||||
|
||||
@Override
|
||||
public void onClick(ClickEvent clickEvent) {
|
||||
if (!clickEvent.getClick().equals(ClickType.RIGHT)) {
|
||||
new VoteTopVoter(plugin, player, user, cur.next(), 0).open(GUIMethod.CHEST);
|
||||
} else {
|
||||
new VoteTopVoter(plugin, player, user, cur.prev(), 0).open(GUIMethod.CHEST);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
if (plugin.getGui().getChestVoteTopBackButton()) {
|
||||
inv.getPageButtons().add(plugin.getCommandLoader().getBackButton(user).setSlot(1));
|
||||
}
|
||||
|
||||
inv.setPages(true);
|
||||
inv.setMaxInvSize(plugin.getGui().getChestVoteTopSize());
|
||||
inv.openInventory(player);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void open() {
|
||||
open(GUIMethod.valueOf(plugin.getGui().getGuiMethodTopVoter().toUpperCase()));
|
||||
}
|
||||
|
||||
}
|
||||
+98
@@ -0,0 +1,98 @@
|
||||
package com.bencodez.votingplugin.commands.gui.player;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.Set;
|
||||
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import com.bencodez.advancedcore.api.gui.GUIHandler;
|
||||
import com.bencodez.advancedcore.api.gui.GUIMethod;
|
||||
import com.bencodez.advancedcore.api.inventory.BInventory;
|
||||
import com.bencodez.advancedcore.api.inventory.BInventory.ClickEvent;
|
||||
import com.bencodez.advancedcore.api.inventory.BInventoryButton;
|
||||
import com.bencodez.advancedcore.api.item.ItemBuilder;
|
||||
import com.bencodez.votingplugin.VotingPluginMain;
|
||||
import com.bencodez.votingplugin.user.VotingPluginUser;
|
||||
|
||||
public class VoteTopVoterLastMonth extends GUIHandler {
|
||||
|
||||
private VotingPluginMain plugin;
|
||||
private VotingPluginUser user;
|
||||
|
||||
public VoteTopVoterLastMonth(VotingPluginMain plugin, CommandSender player, VotingPluginUser user) {
|
||||
super(player);
|
||||
this.plugin = plugin;
|
||||
this.user = user;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ArrayList<String> getChat(CommandSender arg0) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBook(Player player) {
|
||||
// TODO
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onChat(CommandSender sender) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onChest(Player player) {
|
||||
Set<Entry<VotingPluginUser, Integer>> users = null;
|
||||
|
||||
users = plugin.getLastMonthTopVoter().entrySet();
|
||||
|
||||
BInventory inv = new BInventory(plugin.getGui().getChestVoteTopName());
|
||||
inv.addPlaceholder("topvoter", "Last Month");
|
||||
if (!plugin.getConfigFile().isAlwaysCloseInventory()) {
|
||||
inv.dontClose();
|
||||
}
|
||||
|
||||
int pos = 1;
|
||||
for (Entry<VotingPluginUser, Integer> entry : users) {
|
||||
ItemBuilder playerItem;
|
||||
|
||||
if (plugin.getGui().isChestVoteTopUseSkull()) {
|
||||
playerItem = new ItemBuilder(entry.getKey().getPlayerHead());
|
||||
} else {
|
||||
playerItem = new ItemBuilder(Material.valueOf(plugin.getGui().getChestVoteTopPlayerItemMaterial()));
|
||||
}
|
||||
|
||||
playerItem.setLore(new ArrayList<String>());
|
||||
|
||||
inv.addButton(new BInventoryButton(playerItem.setName(plugin.getGui().getChestVoteTopItemName())
|
||||
.addLoreLine(plugin.getGui().getChestVoteTopItemLore()).addPlaceholder("position", "" + pos)
|
||||
.addPlaceholder("player", entry.getKey().getPlayerName())
|
||||
.addPlaceholder("votes", "" + entry.getValue())) {
|
||||
|
||||
@Override
|
||||
public void onClick(ClickEvent clickEvent) {
|
||||
VotingPluginUser user = (VotingPluginUser) getData("User");
|
||||
new VoteGUI(plugin, player, user)
|
||||
.open(GUIMethod.valueOf(plugin.getGui().getGuiMethodGUI().toUpperCase()));
|
||||
}
|
||||
}.addData("player", entry.getKey().getPlayerName()).addData("User", entry.getKey()));
|
||||
pos++;
|
||||
}
|
||||
|
||||
if (plugin.getGui().getChestVoteTopBackButton()) {
|
||||
inv.getPageButtons().add(plugin.getCommandLoader().getBackButton(user).setSlot(1));
|
||||
}
|
||||
|
||||
inv.setPages(true);
|
||||
inv.setMaxInvSize(plugin.getGui().getChestVoteTopSize());
|
||||
inv.openInventory(player);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void open() {
|
||||
open(GUIMethod.CHEST);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,99 @@
|
||||
package com.bencodez.votingplugin.commands.gui.player;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import com.bencodez.advancedcore.api.gui.GUIHandler;
|
||||
import com.bencodez.advancedcore.api.gui.GUIMethod;
|
||||
import com.bencodez.advancedcore.api.inventory.BInventory;
|
||||
import com.bencodez.advancedcore.api.inventory.BInventory.ClickEvent;
|
||||
import com.bencodez.advancedcore.api.inventory.UpdatingBInventoryButton;
|
||||
import com.bencodez.advancedcore.api.item.ItemBuilder;
|
||||
import com.bencodez.advancedcore.api.messages.StringParser;
|
||||
import com.bencodez.advancedcore.api.misc.ArrayUtils;
|
||||
import com.bencodez.votingplugin.VotingPluginMain;
|
||||
import com.bencodez.votingplugin.topvoter.TopVoter;
|
||||
import com.bencodez.votingplugin.user.VotingPluginUser;
|
||||
|
||||
public class VoteTotal extends GUIHandler {
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
private VotingPluginMain plugin;
|
||||
private VotingPluginUser user;
|
||||
|
||||
public VoteTotal(VotingPluginMain plugin, CommandSender player, VotingPluginUser user) {
|
||||
super(player);
|
||||
this.plugin = plugin;
|
||||
this.user = user;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ArrayList<String> getChat(CommandSender arg0) {
|
||||
ArrayList<String> msg = new ArrayList<String>();
|
||||
|
||||
int daily = user.getTotal(TopVoter.Daily);
|
||||
int weekly = user.getTotal(TopVoter.Weekly);
|
||||
int month = user.getTotal(TopVoter.Monthly);
|
||||
int all = user.getTotal(TopVoter.AllTime);
|
||||
|
||||
for (String s : plugin.getConfigFile().getFormatCommandsVoteTotal()) {
|
||||
String str = StringParser.getInstance().replaceIgnoreCase(s, "%DailyTotal%", "" + daily);
|
||||
str = StringParser.getInstance().replaceIgnoreCase(str, "%WeeklyTotal%", "" + weekly);
|
||||
str = StringParser.getInstance().replaceIgnoreCase(str, "%MonthlyTotal%", "" + month);
|
||||
str = StringParser.getInstance().replaceIgnoreCase(str, "%AllTimeTotal%", "" + all);
|
||||
str = StringParser.getInstance().replaceIgnoreCase(str, "%player%", user.getPlayerName());
|
||||
msg.add(str);
|
||||
}
|
||||
|
||||
return ArrayUtils.getInstance().colorize(msg);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBook(Player player) {
|
||||
// future release?
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onChat(CommandSender sender) {
|
||||
sendMessage(getChat(sender));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onChest(Player player) {
|
||||
BInventory inv = new BInventory(plugin.getGui().getChestVoteTotalName());
|
||||
inv.addPlaceholder("player", user.getPlayerName());
|
||||
|
||||
for (final TopVoter top : TopVoter.values()) {
|
||||
inv.addButton(new UpdatingBInventoryButton(
|
||||
new ItemBuilder(plugin.getGui().getChestVoteTotalItem(top))
|
||||
.addPlaceholder("Total", "" + user.getTotal(top)).addPlaceholder("topvoter", top.getName()),
|
||||
1000, 1000) {
|
||||
|
||||
@Override
|
||||
public void onClick(ClickEvent clickEvent) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemBuilder onUpdate(Player arg0) {
|
||||
return new ItemBuilder(plugin.getGui().getChestVoteTotalItem(top))
|
||||
.addPlaceholder("Total", "" + user.getTotal(top)).addPlaceholder("topvoter", top.getName())
|
||||
.addPlaceholder("player", user.getPlayerName());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
if (plugin.getGui().getChestVoteTotalBackButton()) {
|
||||
inv.addButton(plugin.getCommandLoader().getBackButton(user));
|
||||
}
|
||||
inv.openInventory(player);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void open() {
|
||||
open(GUIMethod.valueOf(plugin.getGui().getGuiMethodTotal().toUpperCase()));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,220 @@
|
||||
package com.bencodez.votingplugin.commands.gui.player;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
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.inventory.BInventory;
|
||||
import com.bencodez.advancedcore.api.inventory.BInventory.ClickEvent;
|
||||
import com.bencodez.advancedcore.api.inventory.UpdatingBInventoryButton;
|
||||
import com.bencodez.advancedcore.api.item.ItemBuilder;
|
||||
import com.bencodez.advancedcore.api.messages.MessageBuilder;
|
||||
import com.bencodez.advancedcore.api.messages.StringParser;
|
||||
import com.bencodez.advancedcore.api.misc.ArrayUtils;
|
||||
import com.bencodez.votingplugin.VotingPluginMain;
|
||||
import com.bencodez.votingplugin.objects.VoteSite;
|
||||
import com.bencodez.votingplugin.topvoter.TopVoter;
|
||||
import com.bencodez.votingplugin.user.UserManager;
|
||||
import com.bencodez.votingplugin.user.VotingPluginUser;
|
||||
|
||||
import xyz.upperlevel.spigot.book.BookUtil;
|
||||
|
||||
public class VoteURL extends GUIHandler {
|
||||
|
||||
private boolean json;
|
||||
private VotingPluginMain plugin;
|
||||
private VotingPluginUser user;
|
||||
|
||||
public VoteURL(VotingPluginMain plugin, CommandSender player, VotingPluginUser user, boolean json) {
|
||||
super(player);
|
||||
this.plugin = plugin;
|
||||
this.user = user;
|
||||
this.json = json;
|
||||
if (user == null && player instanceof Player) {
|
||||
this.user = UserManager.getInstance().getVotingPluginUser((Player) player);
|
||||
}
|
||||
if (player.getName().equals(user.getPlayerName())) {
|
||||
if (plugin.getConfigFile().isUsePrimaryAccountForPlaceholders() && user.hasPrimaryAccount()) {
|
||||
user = UserManager.getInstance().getVotingPluginUser(user.getPrimaryAccount());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ArrayList<String> getChat(CommandSender arg0) {
|
||||
ArrayList<String> sites = new ArrayList<String>();
|
||||
|
||||
List<String> title = plugin.getConfigFile().getFormatCommandsVoteText();
|
||||
if (title != null) {
|
||||
sites.addAll(title);
|
||||
}
|
||||
if (plugin.getConfigFile().getFormatCommandsVoteAutoInputSites()) {
|
||||
int counter = 0;
|
||||
for (VoteSite voteSite : plugin.getVoteSites()) {
|
||||
counter++;
|
||||
String voteURL = voteSite.getVoteURL(json);
|
||||
MessageBuilder message = new MessageBuilder(plugin.getConfigFile().getFormatCommandsVoteURLS());
|
||||
message.replacePlaceholder("num", Integer.toString(counter)).replacePlaceholder("url", voteURL)
|
||||
.replacePlaceholder("SiteName", voteSite.getDisplayName());
|
||||
if (user != null && user.getPlayerName() != null) {
|
||||
message.replacePlaceholder("player", "" + user.getPlayerName()).replacePlaceholder("Next",
|
||||
"" + user.voteCommandNextInfo(voteSite));
|
||||
}
|
||||
sites.add(message.colorize().getText());
|
||||
}
|
||||
}
|
||||
if (user != null) {
|
||||
HashMap<String, String> phs = new HashMap<String, String>();
|
||||
phs.put("DailyTotal", "" + user.getTotal(TopVoter.Daily));
|
||||
phs.put("WeekTotal", "" + user.getTotal(TopVoter.Weekly));
|
||||
phs.put("MonthTotal", "" + user.getTotal(TopVoter.Monthly));
|
||||
phs.put("Total", "" + user.getTotal(TopVoter.AllTime));
|
||||
|
||||
sites = ArrayUtils.getInstance().replacePlaceHolder(sites, phs);
|
||||
}
|
||||
|
||||
return ArrayUtils.getInstance().colorize(sites);
|
||||
}
|
||||
|
||||
private ItemBuilder getItemAll() {
|
||||
ItemBuilder builderAll = new ItemBuilder(plugin.getGui().getChestVoteURLAlreadyVotedAllUrlsButtonItemSection());
|
||||
if (plugin.getGui().isChestVoteURLAllUrlsButtonrequireAllSitesVoted()) {
|
||||
if (user.canVoteAny()) {
|
||||
builderAll = new ItemBuilder(plugin.getGui().getChestVoteURLCanVoteAllUrlsButtonItemSection());
|
||||
}
|
||||
} else {
|
||||
if (user.canVoteAll()) {
|
||||
builderAll = new ItemBuilder(plugin.getGui().getChestVoteURLCanVoteAllUrlsButtonItemSection());
|
||||
}
|
||||
}
|
||||
|
||||
if (!builderAll.hasCustomDisplayName()) {
|
||||
builderAll.setName("&4All Voting Sites");
|
||||
}
|
||||
if (!builderAll.hasCustomLore()) {
|
||||
builderAll.setLore("&cClick Me");
|
||||
}
|
||||
return builderAll;
|
||||
}
|
||||
|
||||
private ItemBuilder getItemVoteSite(VoteSite voteSite) {
|
||||
ItemBuilder builder = new ItemBuilder(plugin.getGui().getChestVoteURLAlreadyVotedItemSection());
|
||||
if (user.canVoteSite(voteSite)) {
|
||||
builder = new ItemBuilder(plugin.getGui().getChestVoteURLCanVoteItemSection());
|
||||
} else {
|
||||
builder.addLoreLine(
|
||||
plugin.getGui().getChestVoteURLNextVote().replace("%Info%", user.voteCommandNextInfo(voteSite)));
|
||||
}
|
||||
|
||||
builder.setName(plugin.getGui().getChestVoteURLGUISiteName().replace("%Name%", voteSite.getDisplayName()));
|
||||
return builder;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBook(Player player) {
|
||||
BookWrapper book = new BookWrapper(plugin.getGui().getBookVoteURLBookGUITitle());
|
||||
|
||||
for (VoteSite site : plugin.getVoteSites()) {
|
||||
Layout layout = new Layout(plugin.getGui().getBookVoteURLBookGUILayout()).addPlaceholder("sitename",
|
||||
site.getDisplayName());
|
||||
String text = plugin.getGui().getBookVoteURLBookGUIAlreadyVotedText();
|
||||
ChatColor color = ChatColor.valueOf(plugin.getGui().getBookVoteURLBookGUIAlreadyVotedColor());
|
||||
if (user.canVoteSite(site)) {
|
||||
color = ChatColor.valueOf(plugin.getGui().getBookVoteURLBookGUICanVoteColor());
|
||||
text = plugin.getGui().getBookVoteURLBookGUICanVoteText();
|
||||
}
|
||||
String url = StringParser.getInstance().replacePlaceHolder(site.getVoteURLJsonStrip(), "player",
|
||||
user.getPlayerName());
|
||||
layout.replaceTextComponent("[UrlText]", BookUtil.TextBuilder.of(text).color(color)
|
||||
.onClick(BookUtil.ClickAction.openUrl(url)).onHover(BookUtil.HoverAction.showText(url)).build());
|
||||
book.addLayout(layout);
|
||||
|
||||
}
|
||||
|
||||
book.open(player);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onChat(CommandSender sender) {
|
||||
sendMessage(getChat(sender));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onChest(Player player) {
|
||||
// normal GUI
|
||||
BInventory inv = new BInventory(plugin.getGui().getChestVoteURLName());
|
||||
|
||||
int count = 0;
|
||||
if (plugin.getGui().getChestVoteURLViewAllUrlsButtonEnabled()) {
|
||||
ItemBuilder builderAll = getItemAll();
|
||||
|
||||
inv.addButton(count, new UpdatingBInventoryButton(builderAll, 1000, 1000) {
|
||||
|
||||
@Override
|
||||
public void onClick(ClickEvent event) {
|
||||
VotingPluginUser user = UserManager.getInstance().getVotingPluginUser(event.getPlayer());
|
||||
json = true;
|
||||
user.sendMessage(getChat(player));
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemBuilder onUpdate(Player player) {
|
||||
return getItemAll();
|
||||
}
|
||||
});
|
||||
|
||||
count++;
|
||||
}
|
||||
|
||||
for (final VoteSite voteSite : plugin.getVoteSites()) {
|
||||
ItemBuilder builder = getItemVoteSite(voteSite);
|
||||
|
||||
inv.addButton(count, new UpdatingBInventoryButton(builder, 1000, 1000) {
|
||||
|
||||
@Override
|
||||
public void onClick(ClickEvent event) {
|
||||
Player player = event.getPlayer();
|
||||
if (player != null) {
|
||||
VotingPluginUser user = UserManager.getInstance().getVotingPluginUser(player);
|
||||
user.sendMessage(StringParser.getInstance().replacePlaceHolder(
|
||||
StringParser.getInstance()
|
||||
.replacePlaceHolder(StringParser.getInstance().replacePlaceHolder(
|
||||
plugin.getGui().getChestVoteURLURLText(), "voteurl",
|
||||
voteSite.getVoteURL()), "sitename", voteSite.getDisplayName()),
|
||||
"player", player.getName()));
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemBuilder onUpdate(Player player) {
|
||||
return getItemVoteSite(voteSite);
|
||||
}
|
||||
|
||||
});
|
||||
count++;
|
||||
}
|
||||
|
||||
if (plugin.getGui().getChestVoteURLBackButton()) {
|
||||
inv.addButton(plugin.getCommandLoader().getBackButton(user));
|
||||
}
|
||||
|
||||
inv.openInventory(player);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void open() {
|
||||
open(GUIMethod.valueOf(plugin.getGui().getGuiMethodURL().toUpperCase()));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,109 @@
|
||||
package com.bencodez.votingplugin.commands.gui.player;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import com.bencodez.advancedcore.api.gui.GUIHandler;
|
||||
import com.bencodez.advancedcore.api.gui.GUIMethod;
|
||||
import com.bencodez.advancedcore.api.inventory.BInventory;
|
||||
import com.bencodez.advancedcore.api.inventory.BInventory.ClickEvent;
|
||||
import com.bencodez.advancedcore.api.inventory.BInventoryButton;
|
||||
import com.bencodez.advancedcore.api.inventory.UpdatingBInventoryButton;
|
||||
import com.bencodez.advancedcore.api.item.ItemBuilder;
|
||||
import com.bencodez.votingplugin.VotingPluginMain;
|
||||
import com.bencodez.votingplugin.objects.VoteSite;
|
||||
import com.bencodez.votingplugin.user.VotingPluginUser;
|
||||
|
||||
public class VoteURLVoteSite extends GUIHandler {
|
||||
|
||||
private VotingPluginMain plugin;
|
||||
private VotingPluginUser user;
|
||||
private String voteSite;
|
||||
|
||||
public VoteURLVoteSite(VotingPluginMain plugin, CommandSender player, VotingPluginUser user, String voteSite) {
|
||||
super(player);
|
||||
this.plugin = plugin;
|
||||
this.user = user;
|
||||
this.voteSite = voteSite;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ArrayList<String> getChat(CommandSender arg0) {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBook(Player player) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onChat(CommandSender sender) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onChest(Player player) {
|
||||
if (!plugin.isVoteSite(voteSite)) {
|
||||
player.sendMessage("Not a valid votesite");
|
||||
return;
|
||||
}
|
||||
VoteSite site = plugin.getVoteSite(voteSite);
|
||||
BInventory inv = new BInventory(plugin.getGui().getChestVoteURLSiteName());
|
||||
inv.addPlaceholder("site", site.getDisplayName());
|
||||
inv.setMeta(player, "VoteSite", site);
|
||||
if (!plugin.getConfigFile().isAlwaysCloseInventory()) {
|
||||
inv.dontClose();
|
||||
}
|
||||
|
||||
inv.addButton(
|
||||
new BInventoryButton(new ItemBuilder(Material.BOW).setName("&4URL").addLoreLine("Click to see URL")) {
|
||||
|
||||
@Override
|
||||
public void onClick(ClickEvent clickEvent) {
|
||||
VoteSite site = (VoteSite) clickEvent.getMeta("VoteSite");
|
||||
clickEvent.getWhoClicked().sendMessage(site.getVoteURL());
|
||||
}
|
||||
});
|
||||
|
||||
inv.addButton(new UpdatingBInventoryButton(
|
||||
new ItemBuilder(Material.COMPASS).setName("&4Next Vote").addLoreLine(user.voteCommandNextInfo(site)),
|
||||
1000, 1000) {
|
||||
|
||||
@Override
|
||||
public void onClick(ClickEvent clickEvent) {
|
||||
new VoteURL(plugin, clickEvent.getPlayer(), user, true).open();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemBuilder onUpdate(Player arg0) {
|
||||
return new ItemBuilder(Material.COMPASS).setName("&4Next Vote")
|
||||
.addLoreLine(user.voteCommandNextInfo(site));
|
||||
}
|
||||
});
|
||||
|
||||
inv.addButton(new BInventoryButton(
|
||||
new ItemBuilder(Material.CLOCK).setName("&4Last Vote").addLoreLine(user.voteCommandLastLine(site))) {
|
||||
|
||||
@Override
|
||||
public void onClick(ClickEvent clickEvent) {
|
||||
new VoteURL(plugin, clickEvent.getPlayer(), user, true).open();
|
||||
}
|
||||
});
|
||||
|
||||
if (plugin.getGui().getChestVoteURLBackButton()) {
|
||||
inv.addButton(plugin.getCommandLoader().getBackButton(user));
|
||||
}
|
||||
inv.openInventory(player);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void open() {
|
||||
open(GUIMethod.CHEST);
|
||||
}
|
||||
|
||||
}
|
||||
+53
-52
@@ -1,52 +1,53 @@
|
||||
package com.Ben12345rocks.VotingPlugin.Commands.TabCompleter;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.command.TabCompleter;
|
||||
|
||||
import com.Ben12345rocks.AdvancedCore.CommandAPI.TabCompleteHandler;
|
||||
import com.Ben12345rocks.AdvancedCore.Util.Messages.StringParser;
|
||||
import com.Ben12345rocks.VotingPlugin.Main;
|
||||
|
||||
/**
|
||||
* The Class AdminVoteTabCompleter.
|
||||
*/
|
||||
public class AdminVoteTabCompleter implements TabCompleter {
|
||||
|
||||
/** The plugin. */
|
||||
Main plugin = Main.plugin;
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.bukkit.command.TabCompleter#onTabComplete(org.bukkit.command.
|
||||
* CommandSender, org.bukkit.command.Command, java.lang.String,
|
||||
* java.lang.String[])
|
||||
*/
|
||||
@Override
|
||||
public List<String> onTabComplete(CommandSender sender, Command cmd, String alias, String[] args) {
|
||||
|
||||
List<String> tab = new ArrayList<String>();
|
||||
|
||||
Set<String> cmds = new HashSet<String>();
|
||||
|
||||
cmds.addAll(TabCompleteHandler.getInstance().getTabCompleteOptions(plugin.getAdminVoteCommand(), sender, args,
|
||||
args.length - 1));
|
||||
|
||||
for (String str : cmds) {
|
||||
if (StringParser.getInstance().startsWithIgnoreCase(str, args[args.length - 1])) {
|
||||
tab.add(str);
|
||||
}
|
||||
}
|
||||
|
||||
Collections.sort(tab, String.CASE_INSENSITIVE_ORDER);
|
||||
return tab;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
package com.bencodez.votingplugin.commands.tabcompleter;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.command.TabCompleter;
|
||||
|
||||
import com.bencodez.advancedcore.api.command.TabCompleteHandler;
|
||||
import com.bencodez.advancedcore.api.messages.StringParser;
|
||||
import com.bencodez.votingplugin.VotingPluginMain;
|
||||
|
||||
/**
|
||||
* The Class AdminVoteTabCompleter.
|
||||
*/
|
||||
public class AdminVoteTabCompleter implements TabCompleter {
|
||||
|
||||
/** The plugin. */
|
||||
VotingPluginMain plugin = VotingPluginMain.plugin;
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see org.bukkit.command.TabCompleter#onTabComplete(org.bukkit.command.
|
||||
* CommandSender, org.bukkit.command.Command, java.lang.String,
|
||||
* java.lang.String[])
|
||||
*/
|
||||
@Override
|
||||
public List<String> onTabComplete(CommandSender sender, Command cmd, String alias, String[] args) {
|
||||
|
||||
List<String> tab = new ArrayList<String>();
|
||||
|
||||
Set<String> cmds = new HashSet<String>();
|
||||
|
||||
cmds.addAll(TabCompleteHandler.getInstance().getTabCompleteOptions(plugin.getAdminVoteCommand(), sender, args,
|
||||
args.length - 1));
|
||||
|
||||
for (String str : cmds) {
|
||||
if (StringParser.getInstance().startsWithIgnoreCase(str, args[args.length - 1])) {
|
||||
tab.add(str);
|
||||
}
|
||||
}
|
||||
|
||||
Collections.sort(tab, String.CASE_INSENSITIVE_ORDER);
|
||||
return tab;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
+107
-106
@@ -1,106 +1,107 @@
|
||||
package com.Ben12345rocks.VotingPlugin.Commands.TabCompleter;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.command.TabCompleter;
|
||||
|
||||
import com.Ben12345rocks.AdvancedCore.CommandAPI.CommandHandler;
|
||||
import com.Ben12345rocks.AdvancedCore.CommandAPI.TabCompleteHandler;
|
||||
import com.Ben12345rocks.AdvancedCore.Util.Messages.StringParser;
|
||||
import com.Ben12345rocks.AdvancedCore.Util.Misc.ArrayUtils;
|
||||
import com.Ben12345rocks.VotingPlugin.Main;
|
||||
|
||||
/**
|
||||
* The Class AliasesTabCompleter.
|
||||
*/
|
||||
public class AliasesTabCompleter implements TabCompleter {
|
||||
|
||||
/** The plugin. */
|
||||
Main plugin = Main.plugin;
|
||||
|
||||
/** The cmd handle. */
|
||||
public CommandHandler cmdHandle;
|
||||
|
||||
private boolean adminCommand;
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.bukkit.command.TabCompleter#onTabComplete(org.bukkit.command.
|
||||
* CommandSender, org.bukkit.command.Command, java.lang.String,
|
||||
* java.lang.String[])
|
||||
*/
|
||||
@Override
|
||||
public List<String> onTabComplete(CommandSender sender, Command cmd, String alias, String[] argsIn) {
|
||||
ArrayList<String> msgArray = new ArrayList<String>();
|
||||
msgArray.add("");
|
||||
for (String arg : argsIn) {
|
||||
msgArray.add(arg);
|
||||
}
|
||||
|
||||
String[] args = ArrayUtils.getInstance().convert(msgArray);
|
||||
|
||||
ArrayList<String> tab = new ArrayList<String>();
|
||||
|
||||
Set<String> cmds = new HashSet<String>();
|
||||
|
||||
ArrayList<CommandHandler> cmdHandlers = new ArrayList<CommandHandler>();
|
||||
|
||||
if (adminCommand) {
|
||||
cmdHandlers.addAll(plugin.getAdminVoteCommand());
|
||||
} else {
|
||||
cmdHandlers.addAll(plugin.getVoteCommand());
|
||||
}
|
||||
ConcurrentHashMap<String, ArrayList<String>> tabCompletes = TabCompleteHandler.getInstance()
|
||||
.getTabCompleteOptions();
|
||||
for (CommandHandler cmdHandle : cmdHandlers) {
|
||||
if (cmdHandle.getArgs().length >= argsIn.length) {
|
||||
for (String arg : cmdHandle.getArgs()[0].split("&")) {
|
||||
if (cmd.getName().equalsIgnoreCase("vote" + arg)
|
||||
|| cmd.getName().equalsIgnoreCase("adminvote" + arg)) {
|
||||
// plugin.debug("Found cmd... attempting to get tab
|
||||
// complete");
|
||||
args[0] = arg;
|
||||
boolean argsMatch = true;
|
||||
for (int i = 0; i < argsIn.length; i++) {
|
||||
if (args.length >= i) {
|
||||
if (!cmdHandle.argsMatch(args[i], i)) {
|
||||
argsMatch = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (argsMatch) {
|
||||
|
||||
cmds.addAll(cmdHandle.getTabCompleteOptions(sender, args, argsIn.length, tabCompletes));
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (String str : cmds) {
|
||||
if (StringParser.getInstance().startsWithIgnoreCase(str, args[args.length - 1])) {
|
||||
tab.add(str);
|
||||
}
|
||||
}
|
||||
|
||||
Collections.sort(tab, String.CASE_INSENSITIVE_ORDER);
|
||||
|
||||
return tab;
|
||||
}
|
||||
|
||||
public AliasesTabCompleter setCMDHandle(CommandHandler cmd, boolean adminCommand) {
|
||||
cmdHandle = cmd;
|
||||
this.adminCommand = adminCommand;
|
||||
return this;
|
||||
}
|
||||
|
||||
}
|
||||
package com.bencodez.votingplugin.commands.tabcompleter;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.command.TabCompleter;
|
||||
|
||||
import com.bencodez.advancedcore.api.command.CommandHandler;
|
||||
import com.bencodez.advancedcore.api.command.TabCompleteHandler;
|
||||
import com.bencodez.advancedcore.api.messages.StringParser;
|
||||
import com.bencodez.advancedcore.api.misc.ArrayUtils;
|
||||
import com.bencodez.votingplugin.VotingPluginMain;
|
||||
|
||||
/**
|
||||
* The Class AliasesTabCompleter.
|
||||
*/
|
||||
public class AliasesTabCompleter implements TabCompleter {
|
||||
|
||||
private boolean adminCommand;
|
||||
|
||||
/** The cmd handle. */
|
||||
public CommandHandler cmdHandle;
|
||||
|
||||
/** The plugin. */
|
||||
VotingPluginMain plugin = VotingPluginMain.plugin;
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see org.bukkit.command.TabCompleter#onTabComplete(org.bukkit.command.
|
||||
* CommandSender, org.bukkit.command.Command, java.lang.String,
|
||||
* java.lang.String[])
|
||||
*/
|
||||
@Override
|
||||
public List<String> onTabComplete(CommandSender sender, Command cmd, String alias, String[] argsIn) {
|
||||
ArrayList<String> msgArray = new ArrayList<String>();
|
||||
msgArray.add("");
|
||||
for (String arg : argsIn) {
|
||||
msgArray.add(arg);
|
||||
}
|
||||
|
||||
String[] args = ArrayUtils.getInstance().convert(msgArray);
|
||||
|
||||
ArrayList<String> tab = new ArrayList<String>();
|
||||
|
||||
Set<String> cmds = new HashSet<String>();
|
||||
|
||||
ArrayList<CommandHandler> cmdHandlers = new ArrayList<CommandHandler>();
|
||||
|
||||
if (adminCommand) {
|
||||
cmdHandlers.addAll(plugin.getAdminVoteCommand());
|
||||
} else {
|
||||
cmdHandlers.addAll(plugin.getVoteCommand());
|
||||
}
|
||||
ConcurrentHashMap<String, ArrayList<String>> tabCompletes = TabCompleteHandler.getInstance()
|
||||
.getTabCompleteOptions();
|
||||
for (CommandHandler cmdHandle : cmdHandlers) {
|
||||
if (cmdHandle.getArgs().length >= argsIn.length) {
|
||||
for (String arg : cmdHandle.getArgs()[0].split("&")) {
|
||||
if (cmd.getName().equalsIgnoreCase("vote" + arg)
|
||||
|| cmd.getName().equalsIgnoreCase("adminvote" + arg)) {
|
||||
// plugin.debug("Found cmd... attempting to get tab
|
||||
// complete");
|
||||
args[0] = arg;
|
||||
boolean argsMatch = true;
|
||||
for (int i = 0; i < argsIn.length; i++) {
|
||||
if (args.length >= i) {
|
||||
if (!cmdHandle.argsMatch(args[i], i)) {
|
||||
argsMatch = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (argsMatch) {
|
||||
|
||||
cmds.addAll(cmdHandle.getTabCompleteOptions(sender, args, argsIn.length, tabCompletes));
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (String str : cmds) {
|
||||
if (StringParser.getInstance().startsWithIgnoreCase(str, args[args.length - 1])) {
|
||||
tab.add(str);
|
||||
}
|
||||
}
|
||||
|
||||
Collections.sort(tab, String.CASE_INSENSITIVE_ORDER);
|
||||
|
||||
return tab;
|
||||
}
|
||||
|
||||
public AliasesTabCompleter setCMDHandle(CommandHandler cmd, boolean adminCommand) {
|
||||
cmdHandle = cmd;
|
||||
this.adminCommand = adminCommand;
|
||||
return this;
|
||||
}
|
||||
|
||||
}
|
||||
+54
-53
@@ -1,53 +1,54 @@
|
||||
package com.Ben12345rocks.VotingPlugin.Commands.TabCompleter;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.command.TabCompleter;
|
||||
|
||||
import com.Ben12345rocks.AdvancedCore.CommandAPI.TabCompleteHandler;
|
||||
import com.Ben12345rocks.AdvancedCore.Util.Messages.StringParser;
|
||||
import com.Ben12345rocks.VotingPlugin.Main;
|
||||
|
||||
// TODO: Auto-generated Javadoc
|
||||
/**
|
||||
* The Class VoteTabCompleter.
|
||||
*/
|
||||
public class VoteTabCompleter implements TabCompleter {
|
||||
|
||||
/** The plugin. */
|
||||
Main plugin = Main.plugin;
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.bukkit.command.TabCompleter#onTabComplete(org.bukkit.command.
|
||||
* CommandSender, org.bukkit.command.Command, java.lang.String,
|
||||
* java.lang.String[])
|
||||
*/
|
||||
@Override
|
||||
public List<String> onTabComplete(CommandSender sender, Command cmd, String alias, String[] args) {
|
||||
|
||||
ArrayList<String> tab = new ArrayList<String>();
|
||||
|
||||
Set<String> cmds = new HashSet<String>();
|
||||
|
||||
cmds.addAll(TabCompleteHandler.getInstance().getTabCompleteOptions(plugin.getVoteCommand(), sender, args,
|
||||
args.length - 1));
|
||||
|
||||
for (String str : cmds) {
|
||||
if (StringParser.getInstance().startsWithIgnoreCase(str, args[args.length - 1])) {
|
||||
tab.add(str);
|
||||
}
|
||||
}
|
||||
|
||||
Collections.sort(tab, String.CASE_INSENSITIVE_ORDER);
|
||||
|
||||
return tab;
|
||||
}
|
||||
|
||||
}
|
||||
package com.bencodez.votingplugin.commands.tabcompleter;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.command.TabCompleter;
|
||||
|
||||
import com.bencodez.advancedcore.api.command.TabCompleteHandler;
|
||||
import com.bencodez.advancedcore.api.messages.StringParser;
|
||||
import com.bencodez.votingplugin.VotingPluginMain;
|
||||
|
||||
// TODO: Auto-generated Javadoc
|
||||
/**
|
||||
* The Class VoteTabCompleter.
|
||||
*/
|
||||
public class VoteTabCompleter implements TabCompleter {
|
||||
|
||||
/** The plugin. */
|
||||
VotingPluginMain plugin = VotingPluginMain.plugin;
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see org.bukkit.command.TabCompleter#onTabComplete(org.bukkit.command.
|
||||
* CommandSender, org.bukkit.command.Command, java.lang.String,
|
||||
* java.lang.String[])
|
||||
*/
|
||||
@Override
|
||||
public List<String> onTabComplete(CommandSender sender, Command cmd, String alias, String[] args) {
|
||||
|
||||
ArrayList<String> tab = new ArrayList<String>();
|
||||
|
||||
Set<String> cmds = new HashSet<String>();
|
||||
|
||||
cmds.addAll(TabCompleteHandler.getInstance().getTabCompleteOptions(plugin.getVoteCommand(), sender, args,
|
||||
args.length - 1));
|
||||
|
||||
for (String str : cmds) {
|
||||
if (StringParser.getInstance().startsWithIgnoreCase(str, args[args.length - 1])) {
|
||||
tab.add(str);
|
||||
}
|
||||
}
|
||||
|
||||
Collections.sort(tab, String.CASE_INSENSITIVE_ORDER);
|
||||
|
||||
return tab;
|
||||
}
|
||||
|
||||
}
|
||||
+19
-32
@@ -1,35 +1,17 @@
|
||||
package com.Ben12345rocks.VotingPlugin.Config;
|
||||
package com.bencodez.votingplugin.config;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
import com.Ben12345rocks.AdvancedCore.Util.Annotation.AnnotationHandler;
|
||||
import com.Ben12345rocks.AdvancedCore.Util.Annotation.ConfigDataBoolean;
|
||||
import com.Ben12345rocks.AdvancedCore.Util.Annotation.ConfigDataInt;
|
||||
import com.Ben12345rocks.AdvancedCore.Util.Annotation.ConfigDataString;
|
||||
import com.Ben12345rocks.AdvancedCore.YML.YMLFile;
|
||||
import com.Ben12345rocks.VotingPlugin.Main;
|
||||
import com.bencodez.advancedcore.api.yml.YMLFile;
|
||||
import com.bencodez.advancedcore.api.yml.annotation.AnnotationHandler;
|
||||
import com.bencodez.advancedcore.api.yml.annotation.ConfigDataBoolean;
|
||||
import com.bencodez.advancedcore.api.yml.annotation.ConfigDataInt;
|
||||
import com.bencodez.advancedcore.api.yml.annotation.ConfigDataString;
|
||||
import com.bencodez.votingplugin.VotingPluginMain;
|
||||
|
||||
import lombok.Getter;
|
||||
|
||||
public class BungeeSettings extends YMLFile {
|
||||
/** The instance. */
|
||||
static BungeeSettings instance = new BungeeSettings();
|
||||
|
||||
/** The plugin. */
|
||||
static Main plugin = Main.plugin;
|
||||
|
||||
/**
|
||||
* Gets the single instance of Config.
|
||||
*
|
||||
* @return single instance of Config
|
||||
*/
|
||||
public static BungeeSettings getInstance() {
|
||||
return instance;
|
||||
}
|
||||
|
||||
@ConfigDataBoolean(path = "UseBungeecord", secondPath = "UseBungeecoord")
|
||||
@Getter
|
||||
private boolean useBungeecoord = false;
|
||||
|
||||
@ConfigDataBoolean(path = "BungeeBroadcast")
|
||||
@Getter
|
||||
@@ -51,6 +33,10 @@ public class BungeeSettings extends YMLFile {
|
||||
@Getter
|
||||
private String bungeeServerHost = "";
|
||||
|
||||
@ConfigDataInt(path = "BungeeServer.Port")
|
||||
@Getter
|
||||
private int bungeeServerPort = 1297;
|
||||
|
||||
@ConfigDataString(path = "Server")
|
||||
@Getter
|
||||
private String server = "PleaseSet";
|
||||
@@ -59,24 +45,25 @@ public class BungeeSettings extends YMLFile {
|
||||
@Getter
|
||||
private String spigotServerHost = "";
|
||||
|
||||
@ConfigDataInt(path = "BungeeServer.Port")
|
||||
@Getter
|
||||
private int bungeeServerPort = 1297;
|
||||
|
||||
@ConfigDataInt(path = "SpigotServer.Port")
|
||||
@Getter
|
||||
private int spigotServerPort = 1298;
|
||||
|
||||
public BungeeSettings() {
|
||||
super(new File(Main.plugin.getDataFolder(), "BungeeSettings.yml"));
|
||||
@ConfigDataBoolean(path = "UseBungeecord", secondPath = "UseBungeecoord")
|
||||
@Getter
|
||||
private boolean useBungeecoord = false;
|
||||
|
||||
public BungeeSettings(VotingPluginMain plugin) {
|
||||
super(plugin, new File(plugin.getDataFolder(), "BungeeSettings.yml"));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void loadValues() {
|
||||
new AnnotationHandler().load(getData(), this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFileCreation() {
|
||||
plugin.saveResource("BungeeSettings.yml", true);
|
||||
getPlugin().saveResource("BungeeSettings.yml", true);
|
||||
}
|
||||
}
|
||||
+186
-702
File diff suppressed because it is too large.
Load diff
+43
-89
@@ -1,4 +1,4 @@
|
||||
package com.Ben12345rocks.VotingPlugin.Config;
|
||||
package com.bencodez.votingplugin.config;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
@@ -13,11 +13,11 @@ import org.bukkit.configuration.file.FileConfiguration;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import com.Ben12345rocks.AdvancedCore.Util.Messages.StringParser;
|
||||
import com.Ben12345rocks.AdvancedCore.Util.Misc.ArrayUtils;
|
||||
import com.Ben12345rocks.AdvancedCore.YML.YMLFile;
|
||||
import com.Ben12345rocks.VotingPlugin.Main;
|
||||
import com.Ben12345rocks.VotingPlugin.Objects.VoteSite;
|
||||
import com.bencodez.advancedcore.api.messages.StringParser;
|
||||
import com.bencodez.advancedcore.api.misc.ArrayUtils;
|
||||
import com.bencodez.advancedcore.api.yml.YMLFile;
|
||||
import com.bencodez.votingplugin.VotingPluginMain;
|
||||
import com.bencodez.votingplugin.objects.VoteSite;
|
||||
|
||||
// TODO: Auto-generated Javadoc
|
||||
/**
|
||||
@@ -25,36 +25,20 @@ import com.Ben12345rocks.VotingPlugin.Objects.VoteSite;
|
||||
*/
|
||||
public class ConfigVoteSites extends YMLFile {
|
||||
|
||||
/** The instance. */
|
||||
static ConfigVoteSites instance = new ConfigVoteSites();
|
||||
private VotingPluginMain plugin;
|
||||
|
||||
/** The plugin. */
|
||||
static Main plugin = Main.plugin;
|
||||
|
||||
/**
|
||||
* Gets the single instance of ConfigVoteSites.
|
||||
*
|
||||
* @return single instance of ConfigVoteSites
|
||||
*/
|
||||
public static ConfigVoteSites getInstance() {
|
||||
return instance;
|
||||
}
|
||||
|
||||
/**
|
||||
* Instantiates a new config vote sites.
|
||||
*/
|
||||
public ConfigVoteSites() {
|
||||
super(new File(Main.plugin.getDataFolder(), "VoteSites.yml"));
|
||||
public ConfigVoteSites(VotingPluginMain plugin) {
|
||||
super(plugin, new File(plugin.getDataFolder(), "VoteSites.yml"));
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate vote site.
|
||||
*
|
||||
* @param siteName
|
||||
* the site name
|
||||
* @param siteName the site name
|
||||
*/
|
||||
public void generateVoteSite(String siteName) {
|
||||
if (Config.getInstance().isAutoCreateVoteSites()) {
|
||||
if (plugin.getConfigFile().isAutoCreateVoteSites()) {
|
||||
String org = siteName;
|
||||
siteName = siteName.replace(".", "_");
|
||||
plugin.getLogger().warning("VoteSite " + siteName
|
||||
@@ -81,8 +65,7 @@ public class ConfigVoteSites extends YMLFile {
|
||||
/**
|
||||
* Gets the data.
|
||||
*
|
||||
* @param siteName
|
||||
* the site name
|
||||
* @param siteName the site name
|
||||
* @return the data
|
||||
*/
|
||||
public ConfigurationSection getData(String siteName) {
|
||||
@@ -107,8 +90,7 @@ public class ConfigVoteSites extends YMLFile {
|
||||
/**
|
||||
* Gets the priority.
|
||||
*
|
||||
* @param siteName
|
||||
* the site name
|
||||
* @param siteName the site name
|
||||
* @return the priority
|
||||
*/
|
||||
public int getPriority(String siteName) {
|
||||
@@ -118,8 +100,7 @@ public class ConfigVoteSites extends YMLFile {
|
||||
/**
|
||||
* Gets the rewards.
|
||||
*
|
||||
* @param siteName
|
||||
* the site name
|
||||
* @param siteName the site name
|
||||
* @return the rewards
|
||||
*/
|
||||
public String getRewardsPath(String siteName) {
|
||||
@@ -129,8 +110,7 @@ public class ConfigVoteSites extends YMLFile {
|
||||
/**
|
||||
* Gets the service site.
|
||||
*
|
||||
* @param siteName
|
||||
* the site name
|
||||
* @param siteName the site name
|
||||
* @return the service site
|
||||
*/
|
||||
public String getServiceSite(String siteName) {
|
||||
@@ -144,8 +124,7 @@ public class ConfigVoteSites extends YMLFile {
|
||||
/**
|
||||
* Gets the vote delay.
|
||||
*
|
||||
* @param siteName
|
||||
* the site name
|
||||
* @param siteName the site name
|
||||
* @return the vote delay
|
||||
*/
|
||||
public int getVoteDelay(String siteName) {
|
||||
@@ -159,8 +138,7 @@ public class ConfigVoteSites extends YMLFile {
|
||||
/**
|
||||
* Gets the vote site enabled.
|
||||
*
|
||||
* @param siteName
|
||||
* the site name
|
||||
* @param siteName the site name
|
||||
* @return the vote site enabled
|
||||
*/
|
||||
public boolean getVoteSiteEnabled(String siteName) {
|
||||
@@ -170,8 +148,7 @@ public class ConfigVoteSites extends YMLFile {
|
||||
/**
|
||||
* Gets the vote site file.
|
||||
*
|
||||
* @param siteName
|
||||
* the site name
|
||||
* @param siteName the site name
|
||||
* @return the vote site file
|
||||
*/
|
||||
public File getVoteSiteFile(String siteName) {
|
||||
@@ -211,7 +188,7 @@ public class ConfigVoteSites extends YMLFile {
|
||||
if (!siteCheck(site)) {
|
||||
plugin.getLogger().warning("Failed to load site " + site + ", see above");
|
||||
} else {
|
||||
voteSites.add(new VoteSite(site));
|
||||
voteSites.add(new VoteSite(plugin, site));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -265,8 +242,7 @@ public class ConfigVoteSites extends YMLFile {
|
||||
/**
|
||||
* Gets the vote URL.
|
||||
*
|
||||
* @param siteName
|
||||
* the site name
|
||||
* @param siteName the site name
|
||||
* @return the vote URL
|
||||
*/
|
||||
public String getVoteURL(String siteName) {
|
||||
@@ -280,8 +256,7 @@ public class ConfigVoteSites extends YMLFile {
|
||||
/**
|
||||
* Checks if is service site good.
|
||||
*
|
||||
* @param siteName
|
||||
* the site name
|
||||
* @param siteName the site name
|
||||
* @return true, if is service site good
|
||||
*/
|
||||
public boolean isServiceSiteGood(String siteName) {
|
||||
@@ -294,8 +269,7 @@ public class ConfigVoteSites extends YMLFile {
|
||||
/**
|
||||
* Checks if is vote URL good.
|
||||
*
|
||||
* @param siteName
|
||||
* the site name
|
||||
* @param siteName the site name
|
||||
* @return true, if is vote URL good
|
||||
*/
|
||||
public boolean isVoteURLGood(String siteName) {
|
||||
@@ -314,10 +288,8 @@ public class ConfigVoteSites extends YMLFile {
|
||||
/**
|
||||
* Rename vote site.
|
||||
*
|
||||
* @param siteName
|
||||
* the site name
|
||||
* @param newName
|
||||
* the new name
|
||||
* @param siteName the site name
|
||||
* @param newName the new name
|
||||
* @return true, if successful
|
||||
*/
|
||||
public boolean renameVoteSite(String siteName, String newName) {
|
||||
@@ -328,12 +300,9 @@ public class ConfigVoteSites extends YMLFile {
|
||||
/**
|
||||
* Sets the.
|
||||
*
|
||||
* @param siteName
|
||||
* the site name
|
||||
* @param path
|
||||
* the path
|
||||
* @param value
|
||||
* the value
|
||||
* @param siteName the site name
|
||||
* @param path the path
|
||||
* @param value the value
|
||||
*/
|
||||
public void set(String siteName, String path, Object value) {
|
||||
// String playerName = user.getPlayerName();
|
||||
@@ -349,10 +318,8 @@ public class ConfigVoteSites extends YMLFile {
|
||||
/**
|
||||
* Sets the cumulative rewards.
|
||||
*
|
||||
* @param siteName
|
||||
* the site name
|
||||
* @param value
|
||||
* the value
|
||||
* @param siteName the site name
|
||||
* @param value the value
|
||||
*/
|
||||
public void setCumulativeRewards(String siteName, ArrayList<String> value) {
|
||||
set(siteName, "Cumulative.Rewards", value);
|
||||
@@ -369,10 +336,8 @@ public class ConfigVoteSites extends YMLFile {
|
||||
/**
|
||||
* Sets the enabled.
|
||||
*
|
||||
* @param siteName
|
||||
* the site name
|
||||
* @param disabled
|
||||
* the disabled
|
||||
* @param siteName the site name
|
||||
* @param disabled the disabled
|
||||
*/
|
||||
public void setEnabled(String siteName, boolean disabled) {
|
||||
set(siteName, "Enabled", disabled);
|
||||
@@ -386,10 +351,8 @@ public class ConfigVoteSites extends YMLFile {
|
||||
/**
|
||||
* Sets the priority.
|
||||
*
|
||||
* @param siteName
|
||||
* the site name
|
||||
* @param value
|
||||
* the value
|
||||
* @param siteName the site name
|
||||
* @param value the value
|
||||
*/
|
||||
public void setPriority(String siteName, int value) {
|
||||
set(siteName, "Priority", value);
|
||||
@@ -398,10 +361,8 @@ public class ConfigVoteSites extends YMLFile {
|
||||
/**
|
||||
* Sets the rewards.
|
||||
*
|
||||
* @param siteName
|
||||
* the site name
|
||||
* @param value
|
||||
* the value
|
||||
* @param siteName the site name
|
||||
* @param value the value
|
||||
*/
|
||||
public void setRewards(String siteName, ArrayList<String> value) {
|
||||
set(siteName, "Rewards", value);
|
||||
@@ -410,10 +371,8 @@ public class ConfigVoteSites extends YMLFile {
|
||||
/**
|
||||
* Sets the service site.
|
||||
*
|
||||
* @param siteName
|
||||
* the site name
|
||||
* @param serviceSite
|
||||
* the service site
|
||||
* @param siteName the site name
|
||||
* @param serviceSite the service site
|
||||
*/
|
||||
public void setServiceSite(String siteName, String serviceSite) {
|
||||
set(siteName, "ServiceSite", serviceSite);
|
||||
@@ -422,10 +381,8 @@ public class ConfigVoteSites extends YMLFile {
|
||||
/**
|
||||
* Sets the vote delay.
|
||||
*
|
||||
* @param siteName
|
||||
* the site name
|
||||
* @param voteDelay
|
||||
* the vote delay
|
||||
* @param siteName the site name
|
||||
* @param voteDelay the vote delay
|
||||
*/
|
||||
public void setVoteDelay(String siteName, int voteDelay) {
|
||||
set(siteName, "VoteDelay", voteDelay);
|
||||
@@ -438,10 +395,8 @@ public class ConfigVoteSites extends YMLFile {
|
||||
/**
|
||||
* Sets the vote URL.
|
||||
*
|
||||
* @param siteName
|
||||
* the site name
|
||||
* @param url
|
||||
* the url
|
||||
* @param siteName the site name
|
||||
* @param url the url
|
||||
*/
|
||||
public void setVoteURL(String siteName, String url) {
|
||||
set(siteName, "VoteURL", url);
|
||||
@@ -450,8 +405,7 @@ public class ConfigVoteSites extends YMLFile {
|
||||
/**
|
||||
* Site check.
|
||||
*
|
||||
* @param siteName
|
||||
* the site name
|
||||
* @param siteName the site name
|
||||
* @return true, if successful
|
||||
*/
|
||||
public boolean siteCheck(String siteName) {
|
||||
@@ -0,0 +1,500 @@
|
||||
package com.bencodez.votingplugin.config;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
|
||||
import com.bencodez.advancedcore.api.misc.ArrayUtils;
|
||||
import com.bencodez.advancedcore.api.yml.YMLFile;
|
||||
import com.bencodez.advancedcore.api.yml.annotation.AnnotationHandler;
|
||||
import com.bencodez.advancedcore.api.yml.annotation.ConfigDataBoolean;
|
||||
import com.bencodez.advancedcore.api.yml.annotation.ConfigDataConfigurationSection;
|
||||
import com.bencodez.advancedcore.api.yml.annotation.ConfigDataListString;
|
||||
import com.bencodez.advancedcore.api.yml.annotation.ConfigDataString;
|
||||
import com.bencodez.votingplugin.VotingPluginMain;
|
||||
import com.bencodez.votingplugin.topvoter.TopVoter;
|
||||
|
||||
import lombok.Getter;
|
||||
|
||||
public class GUI extends YMLFile {
|
||||
|
||||
@ConfigDataString(path = "BOOK.VoteURLBookGUI.AlreadyVotedColor")
|
||||
@Getter
|
||||
private String bookVoteURLBookGUIAlreadyVotedColor = "RED";
|
||||
|
||||
@ConfigDataString(path = "BOOK.VoteURLBookGUI.AlreadyVotedText")
|
||||
@Getter
|
||||
private String bookVoteURLBookGUIAlreadyVotedText = "Click me";
|
||||
|
||||
@ConfigDataString(path = "BOOK.VoteURLBookGUI.CanVoteColor")
|
||||
@Getter
|
||||
private String bookVoteURLBookGUICanVoteColor = "GREEN";
|
||||
|
||||
@ConfigDataString(path = "BOOK.VoteURLBookGUI.CanVoteText")
|
||||
@Getter
|
||||
private String bookVoteURLBookGUICanVoteText = "Click me";
|
||||
|
||||
@ConfigDataListString(path = "BOOK.VoteURLBookGUI.Layout")
|
||||
@Getter
|
||||
private ArrayList<String> bookVoteURLBookGUILayout = ArrayUtils.getInstance()
|
||||
.convert(new String[] { "&c%Sitename%", "[UrlText]" });
|
||||
|
||||
@ConfigDataString(path = "BOOK.VoteURLBookGUI.Title")
|
||||
@Getter
|
||||
private String bookVoteURLBookGUITitle = "&cVoteURL";
|
||||
|
||||
@Getter
|
||||
@ConfigDataConfigurationSection(path = "CHEST.ShopConfirmPurchase.NoItem")
|
||||
private ConfigurationSection chestShopConfirmPurchaseNoItem;
|
||||
|
||||
@Getter
|
||||
@ConfigDataString(path = "CHEST.ShopConfirmPurchase.Title")
|
||||
private String chestShopConfirmPurchaseTitle = "Confirm Purchase?";
|
||||
|
||||
@Getter
|
||||
@ConfigDataConfigurationSection(path = "CHEST.ShopConfirmPurchase.YesItem")
|
||||
private ConfigurationSection chestShopConfirmPurchaseYesItem;
|
||||
|
||||
@Getter
|
||||
@ConfigDataString(path = "CHEST.VoteShopDisabled")
|
||||
private String chestVoteShopDisabled = "&cVote shop disabled";
|
||||
|
||||
@ConfigDataBoolean(path = "CHEST.VoteShopHideLimitedReached")
|
||||
@Getter
|
||||
private boolean chestVoteShopHideLimitedReached = true;
|
||||
|
||||
@ConfigDataString(path = "CHEST.VoteShopLimitReached")
|
||||
@Getter
|
||||
private String chestVoteShopLimitReached = "&aYou reached your limit";
|
||||
|
||||
@ConfigDataBoolean(path = "CHEST.VoteShopRequireConfirmation")
|
||||
@Getter
|
||||
private boolean chestVoteShopRequireConfirmation = false;
|
||||
|
||||
@ConfigDataString(path = "CHEST.VoteToday.IconTitle")
|
||||
@Getter
|
||||
private String chestVoteTodayIconTitle = "%player%";
|
||||
|
||||
@ConfigDataString(path = "CHEST.VoteToday.Line")
|
||||
@Getter
|
||||
private String chestVoteTodayLine = "&6%VoteSite% : %Time%";
|
||||
|
||||
@ConfigDataConfigurationSection(path = "CHEST.VoteToday.PlayerItem")
|
||||
@Getter
|
||||
private ConfigurationSection chestVoteTodayPlayerItem;
|
||||
|
||||
@ConfigDataBoolean(path = "CHEST.VoteToday.UseSkull", defaultValue = true)
|
||||
@Getter
|
||||
private boolean chestVoteTodayUseSkull = true;
|
||||
|
||||
@ConfigDataString(path = "CHEST.VoteTop.PlayerItem.Material")
|
||||
@Getter
|
||||
private String chestVoteTopPlayerItemMaterial = "PAPER";
|
||||
|
||||
@ConfigDataBoolean(path = "CHEST.VoteTop.UseSkull")
|
||||
@Getter
|
||||
private boolean chestVoteTopUseSkull = true;
|
||||
|
||||
@ConfigDataBoolean(path = "CHEST.VoteURL.AllUrlsButton.RequireAllSitesVoted")
|
||||
@Getter
|
||||
private boolean chestVoteURLAllUrlsButtonrequireAllSitesVoted = true;
|
||||
|
||||
@ConfigDataString(path = "GUIMethod.Best")
|
||||
@Getter
|
||||
private String guiMethodBest = "CHEST";
|
||||
|
||||
@ConfigDataString(path = "GUIMethod.GUI")
|
||||
@Getter
|
||||
private String guiMethodGUI = "CHEST";
|
||||
|
||||
@ConfigDataString(path = "GUIMethod.Last")
|
||||
@Getter
|
||||
private String guiMethodLast = "CHEST";
|
||||
|
||||
@ConfigDataString(path = "GUIMethod.Next")
|
||||
@Getter
|
||||
private String guiMethodNext = "CHEST";
|
||||
|
||||
@ConfigDataString(path = "GUIMethod.Streak")
|
||||
@Getter
|
||||
private String guiMethodStreak = "CHEST";
|
||||
|
||||
@ConfigDataString(path = "GUIMethod.Today")
|
||||
@Getter
|
||||
private String guiMethodToday = "CHEST";
|
||||
|
||||
@ConfigDataString(path = "GUIMethod.TopVoter")
|
||||
@Getter
|
||||
private String guiMethodTopVoter = "CHEST";
|
||||
|
||||
@ConfigDataString(path = "GUIMethod.Total")
|
||||
@Getter
|
||||
private String guiMethodTotal = "CHEST";
|
||||
|
||||
@ConfigDataString(path = "GUIMethod.URL")
|
||||
@Getter
|
||||
private String guiMethodURL = "CHEST";
|
||||
|
||||
@ConfigDataBoolean(path = "LastMonthGUI")
|
||||
@Getter
|
||||
private boolean lastMonthGUI = false;
|
||||
|
||||
private VotingPluginMain plugin;
|
||||
|
||||
public GUI(VotingPluginMain plugin) {
|
||||
super(plugin, new File(plugin.getDataFolder(), "GUI.yml"));
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
public ConfigurationSection getCHESTBackButton() {
|
||||
return getData().getConfigurationSection("CHEST.BackButton");
|
||||
}
|
||||
|
||||
public int getChestShopIdentifierCost(String identifier) {
|
||||
return getData().getInt("CHEST.Shop." + identifier + ".Cost");
|
||||
}
|
||||
|
||||
public String getChestShopIdentifierIdentifierName(String identifier) {
|
||||
return getData().getString("CHEST.Shop." + identifier + ".Identifier_Name", identifier);
|
||||
}
|
||||
|
||||
public int getChestShopIdentifierLimit(String identifier) {
|
||||
return getData().getInt("CHEST.Shop." + identifier + ".Limit", -1);
|
||||
}
|
||||
|
||||
public String getChestShopIdentifierRewardsPath(String identifier) {
|
||||
return "CHEST.Shop." + identifier + ".Rewards";
|
||||
|
||||
}
|
||||
|
||||
public Set<String> getChestShopIdentifiers() {
|
||||
ConfigurationSection shop = getData().getConfigurationSection("CHEST.Shop");
|
||||
if (shop != null) {
|
||||
return shop.getKeys(false);
|
||||
}
|
||||
return new HashSet<String>();
|
||||
}
|
||||
|
||||
public ConfigurationSection getChestShopIdentifierSection(String identifier) {
|
||||
return getData().getConfigurationSection("CHEST.Shop." + identifier);
|
||||
}
|
||||
|
||||
public ConfigurationSection getChestVoteBestDayBestItem() {
|
||||
return getData().getConfigurationSection("CHEST.VoteBest.DayBest.Item");
|
||||
}
|
||||
|
||||
public ConfigurationSection getChestVoteBestMonthBestItem() {
|
||||
return getData().getConfigurationSection("CHEST.VoteBest.MonthBest.Item");
|
||||
}
|
||||
|
||||
public String getChestVoteBestName() {
|
||||
return getData().getString("CHEST.VoteBest.Name", "VoteBest: %player%");
|
||||
}
|
||||
|
||||
public ConfigurationSection getChestVoteBestWeekBestItem() {
|
||||
return getData().getConfigurationSection("CHEST.VoteBest.WeekBest.Item");
|
||||
}
|
||||
|
||||
public String getChestVoteGUIName() {
|
||||
return getData().getString("CHEST.VoteGUIName", "&cVoteGUI: &c&l%player%");
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the vote GUI slot command.
|
||||
*
|
||||
* @param slot the slot
|
||||
* @return the vote GUI slot command
|
||||
*/
|
||||
|
||||
public String getChestVoteGUISlotCommand(String slot) {
|
||||
return getData().getString("CHEST.VoteGUI." + slot + ".Command", "");
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the vote GUI slot lore.
|
||||
*
|
||||
* @param slot the slot
|
||||
* @return the vote GUI slot lore
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public ArrayList<String> getChestVoteGUISlotLore(String slot) {
|
||||
return (ArrayList<String>) getData().getList("CHEST.VoteGUI." + slot + ".Item.Lore", new ArrayList<String>());
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the vote GUI slots.
|
||||
*
|
||||
* @return the vote GUI slots
|
||||
*/
|
||||
public Set<String> getChestVoteGUISlots() {
|
||||
try {
|
||||
return getData().getConfigurationSection("CHEST.VoteGUI").getKeys(false);
|
||||
} catch (Exception ex) {
|
||||
return new HashSet<String>();
|
||||
}
|
||||
}
|
||||
|
||||
public ConfigurationSection getChestVoteGUISlotSection(String slot) {
|
||||
return getData().getConfigurationSection("CHEST.VoteGUI." + slot + ".Item");
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the vote GUI slot slot.
|
||||
*
|
||||
* @param slot the slot
|
||||
* @return the vote GUI slot slot
|
||||
*/
|
||||
public int getChestVoteGUISlotSlot(String slot) {
|
||||
return getData().getInt("CHEST.VoteGUI." + slot + ".Slot", -1);
|
||||
}
|
||||
|
||||
public boolean getChestVoteLastBackButton() {
|
||||
return getData().getBoolean("CHEST.VoteLast.BackButton");
|
||||
}
|
||||
|
||||
public String getChestVoteLastName() {
|
||||
return getData().getString("CHEST.VoteLast.Name", "VoteLast: %player%");
|
||||
}
|
||||
|
||||
public boolean getChestVoteNextBackButton() {
|
||||
return getData().getBoolean("CHEST.VoteNext.BackButton");
|
||||
}
|
||||
|
||||
public String getChestVoteNextName() {
|
||||
return getData().getString("CHEST.VoteNext.Name", "VoteNext: %player%");
|
||||
}
|
||||
|
||||
public String getChestVoteRewardName() {
|
||||
return getData().getString("CHEST.VoteRewardName", "VoteReward");
|
||||
}
|
||||
|
||||
public boolean getChestVoteShopBackButton() {
|
||||
return getData().getBoolean("CHEST.VoteShopBackButton", true);
|
||||
}
|
||||
|
||||
public boolean getChestVoteShopCloseGUI(String shop) {
|
||||
return getData().getBoolean("CHEST.Shop." + shop + ".CloseGUI", true);
|
||||
}
|
||||
|
||||
public boolean getChestVoteShopEnabled() {
|
||||
return getData().getBoolean("CHEST.VoteShopEnabled", true);
|
||||
}
|
||||
|
||||
public String getChestVoteShopName() {
|
||||
return getData().getString("CHEST.VoteShopName", "VoteShop");
|
||||
}
|
||||
|
||||
public boolean getChestVoteShopNotBuyable(String shop) {
|
||||
return getData().getBoolean("CHEST.Shop." + shop + ".NotBuyable", false);
|
||||
}
|
||||
|
||||
public String getChestVoteShopPermission(String ident) {
|
||||
return getData().getString("CHEST.Shop." + ident + ".Permission", "");
|
||||
}
|
||||
|
||||
public boolean getChestVoteShopResetDaily(String shop) {
|
||||
return getData().getBoolean("CHEST.Shop." + shop + ".Reset.Daily", false);
|
||||
}
|
||||
|
||||
public boolean getChestVoteShopResetMonthly(String shop) {
|
||||
return getData().getBoolean("CHEST.Shop." + shop + ".Reset.Monthly", false);
|
||||
}
|
||||
|
||||
public boolean getChestVoteShopResetWeekly(String shop) {
|
||||
return getData().getBoolean("CHEST.Shop." + shop + ".Reset.Weekly", false);
|
||||
}
|
||||
|
||||
public boolean getChestVoteStreakBackButton() {
|
||||
return getData().getBoolean("CHEST.VoteStreak.BackButton");
|
||||
}
|
||||
|
||||
public ConfigurationSection getChestVoteStreakCurrentDayStreakItem() {
|
||||
return getData().getConfigurationSection("CHEST.VoteStreak.CurrentDayStreak.Item");
|
||||
}
|
||||
|
||||
public ConfigurationSection getChestVoteStreakCurrentMonthStreakItem() {
|
||||
return getData().getConfigurationSection("CHEST.VoteStreak.CurrentMonthStreak.Item");
|
||||
}
|
||||
|
||||
public ConfigurationSection getChestVoteStreakCurrentWeekStreakItem() {
|
||||
return getData().getConfigurationSection("CHEST.VoteStreak.CurrentWeekStreak.Item");
|
||||
}
|
||||
|
||||
public ConfigurationSection getChestVoteStreakHighestDayStreakItem() {
|
||||
return getData().getConfigurationSection("CHEST.VoteStreak.HighestDayStreak.Item");
|
||||
}
|
||||
|
||||
public ConfigurationSection getChestVoteStreakHighestMonthStreakItem() {
|
||||
return getData().getConfigurationSection("CHEST.VoteStreak.HighestMonthStreak.Item");
|
||||
}
|
||||
|
||||
public ConfigurationSection getChestVoteStreakHighestWeekStreakItem() {
|
||||
return getData().getConfigurationSection("CHEST.VoteStreak.HighestWeekStreak.Item");
|
||||
}
|
||||
|
||||
public String getChestVoteStreakName() {
|
||||
return getData().getString("CHEST.VoteStreak.Name", "VoteStreak");
|
||||
}
|
||||
|
||||
public boolean getChestVoteTodayBackButton() {
|
||||
return getData().getBoolean("CHEST.VoteToday.BackButton");
|
||||
}
|
||||
|
||||
public String getChestVoteTodayName() {
|
||||
return getData().getString("CHEST.VoteToday.Name", "VoteToday");
|
||||
}
|
||||
|
||||
public boolean getChestVoteTopBackButton() {
|
||||
return getData().getBoolean("CHEST.VoteToday.BackButton");
|
||||
}
|
||||
|
||||
public String getChestVoteTopItemLore() {
|
||||
return getData().getString("CHEST.VoteTop.Item.Lore", "&3&lVotes: &3%votes%");
|
||||
}
|
||||
|
||||
public String getChestVoteTopItemName() {
|
||||
return getData().getString("CHEST.VoteTop.Item.Name", "&3&l%position%: &3%player%");
|
||||
}
|
||||
|
||||
public String getChestVoteTopName() {
|
||||
return getData().getString("CHEST.VoteTop.Name", "VoteTop %topvoter%");
|
||||
}
|
||||
|
||||
public int getChestVoteTopSize() {
|
||||
return getData().getInt("CHEST.VoteTop.Size", 27);
|
||||
}
|
||||
|
||||
public ConfigurationSection getChestVoteTopSwitchItem() {
|
||||
return getData().getConfigurationSection("CHEST.VoteTop.SwitchItem");
|
||||
}
|
||||
|
||||
public ConfigurationSection getChestVoteTotalAllTimeTotalItem() {
|
||||
return getData().getConfigurationSection("CHEST.VoteTotal.AllTimeTotal.Item");
|
||||
}
|
||||
|
||||
public boolean getChestVoteTotalBackButton() {
|
||||
return getData().getBoolean("CHEST.VoteTotal.BackButton");
|
||||
}
|
||||
|
||||
public ConfigurationSection getChestVoteTotalDayTotalItem() {
|
||||
return getData().getConfigurationSection("CHEST.VoteTotal.DayTotal.Item");
|
||||
}
|
||||
|
||||
public ConfigurationSection getChestVoteTotalItem(TopVoter top) {
|
||||
switch (top) {
|
||||
case AllTime:
|
||||
return getChestVoteTotalAllTimeTotalItem();
|
||||
case Daily:
|
||||
return getChestVoteTotalDayTotalItem();
|
||||
case Monthly:
|
||||
return getChestVoteTotalMonthTotalItem();
|
||||
case Weekly:
|
||||
return getChestVoteTotalWeekTotalItem();
|
||||
default:
|
||||
return getChestVoteTotalAllTimeTotalItem();
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public ConfigurationSection getChestVoteTotalMonthTotalItem() {
|
||||
return getData().getConfigurationSection("CHEST.VoteTotal.MonthTotal.Item");
|
||||
}
|
||||
|
||||
public String getChestVoteTotalName() {
|
||||
return getData().getString("CHEST.VoteTotal.Name", "VoteTotal: %player%");
|
||||
}
|
||||
|
||||
public ConfigurationSection getChestVoteTotalWeekTotalItem() {
|
||||
return getData().getConfigurationSection("CHEST.VoteTotal.WeekTotal.Item");
|
||||
}
|
||||
|
||||
public ConfigurationSection getChestVoteURLAlreadyVotedAllUrlsButtonItemSection() {
|
||||
if (getData().isConfigurationSection("CHEST.VoteURL.AllUrlsButton.AlreadyVotedItem")) {
|
||||
return getData().getConfigurationSection("CHEST.VoteURL.AllUrlsButton.AlreadyVotedItem");
|
||||
} else {
|
||||
return getData().getConfigurationSection("CHEST.VoteURL.AlreadyVotedItem");
|
||||
}
|
||||
}
|
||||
|
||||
public ConfigurationSection getChestVoteURLAlreadyVotedItemSection() {
|
||||
return getData().getConfigurationSection("CHEST.VoteURL.AlreadyVotedItem");
|
||||
}
|
||||
|
||||
public boolean getChestVoteURLBackButton() {
|
||||
return getData().getBoolean("CHEST.VoteURL.BackButton");
|
||||
}
|
||||
|
||||
public ConfigurationSection getChestVoteURLCanVoteAllUrlsButtonItemSection() {
|
||||
if (getData().isConfigurationSection("CHEST.VoteURL.AllUrlsButton.CanVoteItem")) {
|
||||
return getData().getConfigurationSection("CHEST.VoteURL.AllUrlsButton.CanVoteItem");
|
||||
} else {
|
||||
return getData().getConfigurationSection("CHEST.VoteURL.CanVoteItem");
|
||||
}
|
||||
}
|
||||
|
||||
public ConfigurationSection getChestVoteURLCanVoteItemSection() {
|
||||
return getData().getConfigurationSection("CHEST.VoteURL.CanVoteItem");
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the vote URL site name.
|
||||
*
|
||||
* @return the vote URL site name
|
||||
*/
|
||||
public String getChestVoteURLGUISiteName() {
|
||||
return getData().getString("CHEST.VoteURL.SiteName", "&c%Name%");
|
||||
}
|
||||
|
||||
public String getChestVoteURLName() {
|
||||
return getData().getString("CHEST.VoteURL.Name", "&cVoteURL");
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the vote URL next vote.
|
||||
*
|
||||
* @return the vote URL next vote
|
||||
*/
|
||||
public String getChestVoteURLNextVote() {
|
||||
return getData().getString("CHEST.VoteURL.NextVote", "&cCan Vote In: %Info%");
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the vote URL see URL.
|
||||
*
|
||||
* @return the vote URL see URL
|
||||
*/
|
||||
public String getChestVoteURLSeeURL() {
|
||||
return getData().getString("CHEST.VoteURL.SeeURL", "&cClick to see URL");
|
||||
}
|
||||
|
||||
public String getChestVoteURLSiteName() {
|
||||
return getData().getString("CHEST.VoteURLSite.Name", "VoteSite %site%");
|
||||
}
|
||||
|
||||
public String getChestVoteURLURLText() {
|
||||
return getData().getString("CHEST.VoteURL.URLText", "%VoteUrl%");
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the vote URL view all urls button enabled.
|
||||
*
|
||||
* @return the vote URL view all urls button enabled
|
||||
*/
|
||||
public boolean getChestVoteURLViewAllUrlsButtonEnabled() {
|
||||
return getData().getBoolean("CHEST.VoteURL.ViewAllUrlsButtonEnabled");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void loadValues() {
|
||||
new AnnotationHandler().load(getData(), this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFileCreation() {
|
||||
plugin.saveResource("GUI.yml", true);
|
||||
}
|
||||
}
|
||||
+38
-46
@@ -1,37 +1,25 @@
|
||||
package com.Ben12345rocks.VotingPlugin.Config;
|
||||
package com.bencodez.votingplugin.config;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import com.Ben12345rocks.AdvancedCore.Util.Annotation.AnnotationHandler;
|
||||
import com.Ben12345rocks.AdvancedCore.Util.Annotation.ConfigDataBoolean;
|
||||
import com.Ben12345rocks.AdvancedCore.Util.Annotation.ConfigDataDouble;
|
||||
import com.Ben12345rocks.AdvancedCore.YML.YMLFile;
|
||||
import com.Ben12345rocks.VotingPlugin.Main;
|
||||
import com.bencodez.advancedcore.api.yml.YMLFile;
|
||||
import com.bencodez.advancedcore.api.yml.annotation.AnnotationHandler;
|
||||
import com.bencodez.advancedcore.api.yml.annotation.ConfigDataBoolean;
|
||||
import com.bencodez.advancedcore.api.yml.annotation.ConfigDataDouble;
|
||||
import com.bencodez.votingplugin.VotingPluginMain;
|
||||
|
||||
import lombok.Getter;
|
||||
|
||||
public class SpecialRewardsConfig extends YMLFile {
|
||||
/** The instance. */
|
||||
static SpecialRewardsConfig instance = new SpecialRewardsConfig();
|
||||
|
||||
/** The plugin. */
|
||||
static Main plugin = Main.plugin;
|
||||
|
||||
/**
|
||||
* Gets the single instance of Config.
|
||||
*
|
||||
* @return single instance of Config
|
||||
*/
|
||||
public static SpecialRewardsConfig getInstance() {
|
||||
return instance;
|
||||
}
|
||||
|
||||
@ConfigDataBoolean(path = "EnableWeeklyAwards")
|
||||
@Getter
|
||||
private boolean enableWeeklyAwards = false;
|
||||
private String allSitesRewardPath = "AllSites";
|
||||
|
||||
@Getter
|
||||
private String anySiteRewardsPath = "AnySiteRewards";
|
||||
|
||||
@ConfigDataBoolean(path = "EnableDailyRewards")
|
||||
@Getter
|
||||
@@ -41,17 +29,27 @@ public class SpecialRewardsConfig extends YMLFile {
|
||||
@Getter
|
||||
private boolean enableMonthlyAwards = false;
|
||||
|
||||
@ConfigDataBoolean(path = "EnableWeeklyAwards")
|
||||
@Getter
|
||||
private String anySiteRewardsPath = "AnySiteRewards";
|
||||
private boolean enableWeeklyAwards = false;
|
||||
|
||||
@Getter
|
||||
private String firstVoteRewardsPath = "FirstVote";
|
||||
|
||||
/** The plugin. */
|
||||
private VotingPluginMain plugin;
|
||||
|
||||
@ConfigDataBoolean(path = "VoteParty.ResetExtraVotesMonthly")
|
||||
@Getter
|
||||
private boolean votePartyResetExtraVotesMonthly = false;
|
||||
|
||||
@Getter
|
||||
private String votePartyRewardsPath = "VoteParty.Rewards";
|
||||
|
||||
@ConfigDataDouble(path = "VoteStreak.Requirement.Day")
|
||||
@Getter
|
||||
private double voteStreakRequirementDay = 50;
|
||||
|
||||
@ConfigDataDouble(path = "VoteStreak.Requirement.Week")
|
||||
@Getter
|
||||
private double voteStreakRequirementWeek = 50;
|
||||
|
||||
@ConfigDataDouble(path = "VoteStreak.Requirement.Month")
|
||||
@Getter
|
||||
private double voteStreakRequirementMonth = 50;
|
||||
@@ -60,21 +58,13 @@ public class SpecialRewardsConfig extends YMLFile {
|
||||
@Getter
|
||||
private boolean voteStreakRequirementUsePercentage = false;
|
||||
|
||||
@ConfigDataBoolean(path = "VoteParty.ResetExtraVotesMonthly")
|
||||
@ConfigDataDouble(path = "VoteStreak.Requirement.Week")
|
||||
@Getter
|
||||
private boolean votePartyResetExtraVotesMonthly = false;
|
||||
private double voteStreakRequirementWeek = 50;
|
||||
|
||||
@Getter
|
||||
private String allSitesRewardPath = "AllSites";
|
||||
|
||||
@Getter
|
||||
private String votePartyRewardsPath = "VoteParty.Rewards";
|
||||
|
||||
@Getter
|
||||
private String firstVoteRewardsPath = "FirstVote";
|
||||
|
||||
public SpecialRewardsConfig() {
|
||||
super(new File(Main.plugin.getDataFolder(), "SpecialRewards.yml"));
|
||||
public SpecialRewardsConfig(VotingPluginMain plugin) {
|
||||
super(plugin, new File(plugin.getDataFolder(), "SpecialRewards.yml"));
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
public boolean getCumulativeRewardEnabled(int cumulative) {
|
||||
@@ -105,8 +95,7 @@ public class SpecialRewardsConfig extends YMLFile {
|
||||
/**
|
||||
* Gets the cumulative votes in same day.
|
||||
*
|
||||
* @param cumulative
|
||||
* the cumulative
|
||||
* @param cumulative the cumulative
|
||||
* @return the cumulative votes in same day
|
||||
*/
|
||||
public boolean getCumulativeVotesInSameDay(int cumulative) {
|
||||
@@ -142,8 +131,7 @@ public class SpecialRewardsConfig extends YMLFile {
|
||||
/**
|
||||
* Gets the milestone reward enabled.
|
||||
*
|
||||
* @param milestones
|
||||
* the milestones
|
||||
* @param milestones the milestones
|
||||
* @return the milestone reward enabled
|
||||
*/
|
||||
public boolean getMilestoneRewardEnabled(int milestones) {
|
||||
@@ -153,8 +141,7 @@ public class SpecialRewardsConfig extends YMLFile {
|
||||
/**
|
||||
* Gets the milestone rewards.
|
||||
*
|
||||
* @param milestones
|
||||
* the milestones
|
||||
* @param milestones the milestones
|
||||
* @return the milestone rewards
|
||||
*/
|
||||
public String getMilestoneRewardsPath(int milestones) {
|
||||
@@ -212,6 +199,10 @@ public class SpecialRewardsConfig extends YMLFile {
|
||||
return getData().getBoolean("VoteParty.CountFakeVotes", true);
|
||||
}
|
||||
|
||||
public boolean getVotePartyCountOfflineVotes() {
|
||||
return getData().getBoolean("VoteParty.CountOfflineVotes", true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the vote party enabled.
|
||||
*
|
||||
@@ -292,6 +283,7 @@ public class SpecialRewardsConfig extends YMLFile {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void loadValues() {
|
||||
new AnnotationHandler().load(getData(), this);
|
||||
}
|
||||
@@ -0,0 +1,70 @@
|
||||
package com.bencodez.votingplugin.cooldown;
|
||||
|
||||
import java.util.TimerTask;
|
||||
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
|
||||
import com.bencodez.advancedcore.api.rewards.RewardHandler;
|
||||
import com.bencodez.advancedcore.api.rewards.RewardOptions;
|
||||
import com.bencodez.advancedcore.api.time.events.DateChangedEvent;
|
||||
import com.bencodez.advancedcore.api.user.UUID;
|
||||
import com.bencodez.votingplugin.VotingPluginMain;
|
||||
import com.bencodez.votingplugin.events.PlayerVoteCoolDownEndEvent;
|
||||
import com.bencodez.votingplugin.user.UserManager;
|
||||
import com.bencodez.votingplugin.user.VotingPluginUser;
|
||||
|
||||
// TODO: Auto-generated Javadoc
|
||||
/**
|
||||
* The Class VoteReminding.
|
||||
*/
|
||||
public class CoolDownCheck implements Listener {
|
||||
|
||||
private VotingPluginMain plugin;
|
||||
|
||||
/**
|
||||
* Instantiates a new vote reminding.
|
||||
*
|
||||
* @param plugin the plugin
|
||||
*/
|
||||
public CoolDownCheck(VotingPluginMain plugin) {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
public void checkAll() {
|
||||
plugin.getTimer().schedule(new TimerTask() {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
if (VotingPluginMain.plugin != null) {
|
||||
for (String uuid : UserManager.getInstance().getAllUUIDs()) {
|
||||
if (VotingPluginMain.plugin != null) {
|
||||
VotingPluginUser user = UserManager.getInstance().getVotingPluginUser(new UUID(uuid));
|
||||
if (user.getUserData().hasData() && user.hasLoggedOnBefore()) {
|
||||
user.checkCoolDownEvents();
|
||||
}
|
||||
} else {
|
||||
cancel();
|
||||
}
|
||||
}
|
||||
} else {
|
||||
cancel();
|
||||
}
|
||||
}
|
||||
}, 1000 * 60 * 3);
|
||||
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
|
||||
public void onCoolDownEnd(PlayerVoteCoolDownEndEvent event) {
|
||||
RewardHandler.getInstance().giveReward(event.getPlayer(), plugin.getSpecialRewardsConfig().getData(),
|
||||
"VoteCoolDownEndedReward",
|
||||
new RewardOptions().addPlaceholder("Votesite", event.getVoteSite().getDisplayName()));
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
|
||||
public void onDayChangeEnd(DateChangedEvent event) {
|
||||
checkAll();
|
||||
}
|
||||
}
|
||||
+22
-57
@@ -1,4 +1,4 @@
|
||||
package com.Ben12345rocks.VotingPlugin.Data;
|
||||
package com.bencodez.votingplugin.data;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
@@ -8,9 +8,9 @@ import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
|
||||
import com.Ben12345rocks.AdvancedCore.Util.Misc.ArrayUtils;
|
||||
import com.Ben12345rocks.VotingPlugin.Main;
|
||||
import com.Ben12345rocks.VotingPlugin.Signs.SignHandler;
|
||||
import com.bencodez.advancedcore.api.misc.ArrayUtils;
|
||||
import com.bencodez.votingplugin.VotingPluginMain;
|
||||
import com.bencodez.votingplugin.signs.SignHandler;
|
||||
|
||||
// TODO: Auto-generated Javadoc
|
||||
/**
|
||||
@@ -18,35 +18,10 @@ import com.Ben12345rocks.VotingPlugin.Signs.SignHandler;
|
||||
*/
|
||||
public class ServerData {
|
||||
|
||||
/** The instance. */
|
||||
static ServerData instance = new ServerData();
|
||||
private VotingPluginMain plugin = VotingPluginMain.plugin;
|
||||
|
||||
/** The plugin. */
|
||||
static Main plugin = Main.plugin;
|
||||
|
||||
/**
|
||||
* Gets the single instance of ServerData.
|
||||
*
|
||||
* @return single instance of ServerData
|
||||
*/
|
||||
public static ServerData getInstance() {
|
||||
return instance;
|
||||
}
|
||||
|
||||
/**
|
||||
* Instantiates a new server data.
|
||||
*/
|
||||
private ServerData() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Instantiates a new server data.
|
||||
*
|
||||
* @param plugin
|
||||
* the plugin
|
||||
*/
|
||||
public ServerData(Main plugin) {
|
||||
ServerData.plugin = plugin;
|
||||
public ServerData(VotingPluginMain plugin) {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
public synchronized void addServiceSite(String site) {
|
||||
@@ -60,12 +35,9 @@ public class ServerData {
|
||||
/**
|
||||
* Adds the sign.
|
||||
*
|
||||
* @param location
|
||||
* the location
|
||||
* @param data
|
||||
* the data
|
||||
* @param position
|
||||
* the position
|
||||
* @param location the location
|
||||
* @param data the data
|
||||
* @param position the position
|
||||
*/
|
||||
public void addSign(Location location, String data, int position) {
|
||||
|
||||
@@ -78,8 +50,8 @@ public class ServerData {
|
||||
getData().set("Signs." + count + ".Data", data);
|
||||
getData().set("Signs." + count + ".Position", position);
|
||||
saveData();
|
||||
plugin.getSigns().add(new SignHandler("" + count, getSignLocation("" + count), getSignSkullLocation("" + count),
|
||||
getSignData("" + count), getSignPosition("" + count)));
|
||||
plugin.getSigns().getSigns().add(new SignHandler(plugin, "" + count, getSignLocation("" + count),
|
||||
getSignSkullLocation("" + count), getSignData("" + count), getSignPosition("" + count)));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -88,12 +60,10 @@ public class ServerData {
|
||||
* @return the data
|
||||
*/
|
||||
public ConfigurationSection getData() {
|
||||
ConfigurationSection data = com.Ben12345rocks.AdvancedCore.Data.ServerData.getInstance().getData()
|
||||
.getConfigurationSection("VotingPlugin");
|
||||
ConfigurationSection data = plugin.getServerDataFile().getData().getConfigurationSection("VotingPlugin");
|
||||
if (data == null) {
|
||||
com.Ben12345rocks.AdvancedCore.Data.ServerData.getInstance().getData().createSection("VotingPlugin");
|
||||
data = com.Ben12345rocks.AdvancedCore.Data.ServerData.getInstance().getData()
|
||||
.getConfigurationSection("VotingPlugin");
|
||||
plugin.getServerDataFile().getData().createSection("VotingPlugin");
|
||||
data = plugin.getServerDataFile().getData().getConfigurationSection("VotingPlugin");
|
||||
}
|
||||
return data;
|
||||
}
|
||||
@@ -106,8 +76,7 @@ public class ServerData {
|
||||
/**
|
||||
* Gets the sign data.
|
||||
*
|
||||
* @param sign
|
||||
* the sign
|
||||
* @param sign the sign
|
||||
* @return the sign data
|
||||
*/
|
||||
public String getSignData(String sign) {
|
||||
@@ -117,8 +86,7 @@ public class ServerData {
|
||||
/**
|
||||
* Gets the sign location.
|
||||
*
|
||||
* @param sign
|
||||
* the sign
|
||||
* @param sign the sign
|
||||
* @return the sign location
|
||||
*/
|
||||
public Location getSignLocation(String sign) {
|
||||
@@ -130,8 +98,7 @@ public class ServerData {
|
||||
/**
|
||||
* Gets the sign position.
|
||||
*
|
||||
* @param sign
|
||||
* the sign
|
||||
* @param sign the sign
|
||||
* @return the sign position
|
||||
*/
|
||||
public int getSignPosition(String sign) {
|
||||
@@ -154,8 +121,7 @@ public class ServerData {
|
||||
/**
|
||||
* Gets the sign location.
|
||||
*
|
||||
* @param sign
|
||||
* the sign
|
||||
* @param sign the sign
|
||||
* @return the sign location
|
||||
*/
|
||||
public Location getSignSkullLocation(String sign) {
|
||||
@@ -193,14 +159,13 @@ public class ServerData {
|
||||
* Reload data.
|
||||
*/
|
||||
public void reloadData() {
|
||||
com.Ben12345rocks.AdvancedCore.Data.ServerData.getInstance().reloadData();
|
||||
plugin.getServerDataFile().reloadData();
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes the sign.
|
||||
*
|
||||
* @param sign
|
||||
* the sign
|
||||
* @param sign the sign
|
||||
*/
|
||||
public void removeSign(String sign) {
|
||||
getData().set("Signs." + sign + ".World", null);
|
||||
@@ -221,7 +186,7 @@ public class ServerData {
|
||||
* Save data.
|
||||
*/
|
||||
public synchronized void saveData() {
|
||||
com.Ben12345rocks.AdvancedCore.Data.ServerData.getInstance().saveData();
|
||||
plugin.getServerDataFile().saveData();
|
||||
}
|
||||
|
||||
public void setServiceSites(ArrayList<String> list) {
|
||||
+9
-8
@@ -1,9 +1,9 @@
|
||||
package com.Ben12345rocks.VotingPlugin.Events;
|
||||
package com.bencodez.votingplugin.events;
|
||||
|
||||
import org.bukkit.event.Event;
|
||||
import org.bukkit.event.HandlerList;
|
||||
|
||||
import com.Ben12345rocks.VotingPlugin.Objects.User;
|
||||
import com.bencodez.votingplugin.user.VotingPluginUser;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
@@ -28,21 +28,21 @@ public class PlayerReceivePointsEvent extends Event {
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
private User player;
|
||||
private boolean cancelled;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
private VotingPluginUser player;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
private int points;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
private boolean cancelled;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
private String serviceSite = "";
|
||||
|
||||
public PlayerReceivePointsEvent(User user, int points) {
|
||||
public PlayerReceivePointsEvent(VotingPluginUser user, int points) {
|
||||
super(true);
|
||||
this.player = user;
|
||||
this.points = points;
|
||||
@@ -50,6 +50,7 @@ public class PlayerReceivePointsEvent extends Event {
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see org.bukkit.event.Event#getHandlers()
|
||||
*/
|
||||
@Override
|
||||
+6
-5
@@ -1,9 +1,9 @@
|
||||
package com.Ben12345rocks.VotingPlugin.Events;
|
||||
package com.bencodez.votingplugin.events;
|
||||
|
||||
import org.bukkit.event.Event;
|
||||
import org.bukkit.event.HandlerList;
|
||||
|
||||
import com.Ben12345rocks.VotingPlugin.Objects.User;
|
||||
import com.bencodez.votingplugin.user.VotingPluginUser;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
@@ -28,7 +28,7 @@ public class PlayerSpecialRewardEvent extends Event {
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
private User user;
|
||||
private boolean cancelled;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@@ -36,9 +36,9 @@ public class PlayerSpecialRewardEvent extends Event {
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
private boolean cancelled;
|
||||
private VotingPluginUser user;
|
||||
|
||||
public PlayerSpecialRewardEvent(User user, SpecialRewardType type) {
|
||||
public PlayerSpecialRewardEvent(VotingPluginUser user, SpecialRewardType type) {
|
||||
super(true);
|
||||
this.type = type;
|
||||
this.user = user;
|
||||
@@ -46,6 +46,7 @@ public class PlayerSpecialRewardEvent extends Event {
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see org.bukkit.event.Event#getHandlers()
|
||||
*/
|
||||
@Override
|
||||
+10
-9
@@ -1,10 +1,10 @@
|
||||
package com.Ben12345rocks.VotingPlugin.Events;
|
||||
package com.bencodez.votingplugin.events;
|
||||
|
||||
import org.bukkit.event.Event;
|
||||
import org.bukkit.event.HandlerList;
|
||||
|
||||
import com.Ben12345rocks.VotingPlugin.Objects.User;
|
||||
import com.Ben12345rocks.VotingPlugin.Objects.VoteSite;
|
||||
import com.bencodez.votingplugin.objects.VoteSite;
|
||||
import com.bencodez.votingplugin.user.VotingPluginUser;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
@@ -29,17 +29,17 @@ public class PlayerVoteCoolDownEndEvent extends Event {
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
private User player;
|
||||
private boolean cancelled;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
private VotingPluginUser player;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
private VoteSite voteSite;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
private boolean cancelled;
|
||||
|
||||
public PlayerVoteCoolDownEndEvent(User user, VoteSite site) {
|
||||
public PlayerVoteCoolDownEndEvent(VotingPluginUser user, VoteSite site) {
|
||||
super(true);
|
||||
player = user;
|
||||
voteSite = site;
|
||||
@@ -47,6 +47,7 @@ public class PlayerVoteCoolDownEndEvent extends Event {
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see org.bukkit.event.Event#getHandlers()
|
||||
*/
|
||||
@Override
|
||||
+16
-11
@@ -1,9 +1,9 @@
|
||||
package com.Ben12345rocks.VotingPlugin.Events;
|
||||
package com.bencodez.votingplugin.events;
|
||||
|
||||
import org.bukkit.event.Event;
|
||||
import org.bukkit.event.HandlerList;
|
||||
|
||||
import com.Ben12345rocks.VotingPlugin.Objects.VoteSite;
|
||||
import com.bencodez.votingplugin.objects.VoteSite;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
@@ -28,11 +28,15 @@ public class PlayerVoteEvent extends Event {
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
private String player;
|
||||
private boolean addTotals = true;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
private VoteSite voteSite;
|
||||
private boolean bungee = false;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
private String bungeeTextTotals;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@@ -40,11 +44,15 @@ public class PlayerVoteEvent extends Event {
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
private boolean realVote = true;
|
||||
private boolean forceBungee = false;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
private boolean addTotals = true;
|
||||
private String player;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
private boolean realVote = true;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@@ -56,11 +64,7 @@ public class PlayerVoteEvent extends Event {
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
private boolean bungee = false;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
private boolean forceBungee = false;
|
||||
private VoteSite voteSite;
|
||||
|
||||
public PlayerVoteEvent(VoteSite voteSite, String voteUsername, String serviceSite, boolean realVote) {
|
||||
super(true);
|
||||
@@ -72,6 +76,7 @@ public class PlayerVoteEvent extends Event {
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see org.bukkit.event.Event#getHandlers()
|
||||
*/
|
||||
@Override
|
||||
+2
-2
@@ -1,9 +1,9 @@
|
||||
package com.Ben12345rocks.VotingPlugin.Events;
|
||||
package com.bencodez.votingplugin.events;
|
||||
|
||||
import lombok.Getter;
|
||||
|
||||
public enum SpecialRewardType {
|
||||
ALLSITE, CUMMULATIVE, MILESTONE, VOTESTREAK, FIRSTVOTE;
|
||||
ALLSITE, CUMMULATIVE, FIRSTVOTE, MILESTONE, VOTESTREAK;
|
||||
|
||||
@Getter
|
||||
private int amount = -1;
|
||||
+2
-1
@@ -1,4 +1,4 @@
|
||||
package com.Ben12345rocks.VotingPlugin.Events;
|
||||
package com.bencodez.votingplugin.events;
|
||||
|
||||
import org.bukkit.event.Event;
|
||||
import org.bukkit.event.HandlerList;
|
||||
@@ -34,6 +34,7 @@ public class VotePartyEvent extends Event {
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see org.bukkit.event.Event#getHandlers()
|
||||
*/
|
||||
@Override
|
||||
+8
-10
@@ -1,4 +1,4 @@
|
||||
package com.Ben12345rocks.VotingPlugin.Listeners;
|
||||
package com.bencodez.votingplugin.listeners;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
@@ -8,8 +8,8 @@ import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.block.BlockBreakEvent;
|
||||
|
||||
import com.Ben12345rocks.VotingPlugin.Main;
|
||||
import com.Ben12345rocks.VotingPlugin.Signs.SignHandler;
|
||||
import com.bencodez.votingplugin.VotingPluginMain;
|
||||
import com.bencodez.votingplugin.signs.SignHandler;
|
||||
|
||||
// TODO: Auto-generated Javadoc
|
||||
/**
|
||||
@@ -18,23 +18,21 @@ import com.Ben12345rocks.VotingPlugin.Signs.SignHandler;
|
||||
public class BlockBreak implements Listener {
|
||||
|
||||
/** The plugin. */
|
||||
private static Main plugin;
|
||||
private static VotingPluginMain plugin;
|
||||
|
||||
/**
|
||||
* Instantiates a new block break.
|
||||
*
|
||||
* @param plugin
|
||||
* the plugin
|
||||
* @param plugin the plugin
|
||||
*/
|
||||
public BlockBreak(Main plugin) {
|
||||
public BlockBreak(VotingPluginMain plugin) {
|
||||
BlockBreak.plugin = plugin;
|
||||
}
|
||||
|
||||
/**
|
||||
* On block break.
|
||||
*
|
||||
* @param event
|
||||
* the event
|
||||
* @param event the event
|
||||
*/
|
||||
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
|
||||
public void onBlockBreak(BlockBreakEvent event) {
|
||||
@@ -45,7 +43,7 @@ public class BlockBreak implements Listener {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
for (SignHandler sign : plugin.getSigns()) {
|
||||
for (SignHandler sign : plugin.getSigns().getSigns()) {
|
||||
if (sign.getLocation().equals(loc)) {
|
||||
sign.removeSign();
|
||||
sign.setValid(false);
|
||||
+11
-13
@@ -1,4 +1,4 @@
|
||||
package com.Ben12345rocks.VotingPlugin.Listeners;
|
||||
package com.bencodez.votingplugin.listeners;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
@@ -7,9 +7,7 @@ import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.PlayerCommandSendEvent;
|
||||
|
||||
import com.Ben12345rocks.VotingPlugin.Main;
|
||||
import com.Ben12345rocks.VotingPlugin.Commands.CommandLoader;
|
||||
import com.Ben12345rocks.VotingPlugin.Config.Config;
|
||||
import com.bencodez.votingplugin.VotingPluginMain;
|
||||
|
||||
// TODO: Auto-generated Javadoc
|
||||
/**
|
||||
@@ -18,23 +16,23 @@ import com.Ben12345rocks.VotingPlugin.Config.Config;
|
||||
public class PlayerCommandSendListener implements Listener {
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
private static Main plugin;
|
||||
private VotingPluginMain plugin;
|
||||
|
||||
public PlayerCommandSendListener(Main plugin) {
|
||||
PlayerCommandSendListener.plugin = plugin;
|
||||
public PlayerCommandSendListener(VotingPluginMain plugin) {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||
public void onTab(PlayerCommandSendEvent event) {
|
||||
if (Config.getInstance().isDisableAdvancedTab()) {
|
||||
if (plugin.getConfigFile().isDisableAdvancedTab()) {
|
||||
return;
|
||||
}
|
||||
ArrayList<String> removeCmds = new ArrayList<String>();
|
||||
if (!Main.plugin.getAdvancedTab().containsKey(event.getPlayer().getUniqueId())) {
|
||||
if (!VotingPluginMain.plugin.getAdvancedTab().containsKey(event.getPlayer().getUniqueId())) {
|
||||
ArrayList<String> whiteListed = new ArrayList<String>();
|
||||
for (String cmd : event.getCommands()) {
|
||||
if (CommandLoader.getInstance().isVotingPluginCommand(event.getPlayer(), cmd)) {
|
||||
if (!CommandLoader.getInstance().hasPermission(event.getPlayer(), cmd)
|
||||
if (plugin.getCommandLoader().isVotingPluginCommand(event.getPlayer(), cmd)) {
|
||||
if (!plugin.getCommandLoader().hasPermission(event.getPlayer(), cmd)
|
||||
&& !whiteListed.contains(cmd)) {
|
||||
removeCmds.add(cmd);
|
||||
// plugin.debug("removed " + cmd);
|
||||
@@ -45,9 +43,9 @@ public class PlayerCommandSendListener implements Listener {
|
||||
}
|
||||
}
|
||||
}
|
||||
Main.plugin.getAdvancedTab().put(event.getPlayer().getUniqueId(), removeCmds);
|
||||
VotingPluginMain.plugin.getAdvancedTab().put(event.getPlayer().getUniqueId(), removeCmds);
|
||||
} else {
|
||||
removeCmds = Main.plugin.getAdvancedTab().get(event.getPlayer().getUniqueId());
|
||||
removeCmds = VotingPluginMain.plugin.getAdvancedTab().get(event.getPlayer().getUniqueId());
|
||||
}
|
||||
event.getCommands().removeAll(removeCmds);
|
||||
}
|
||||
+11
-13
@@ -1,4 +1,4 @@
|
||||
package com.Ben12345rocks.VotingPlugin.Listeners;
|
||||
package com.bencodez.votingplugin.listeners;
|
||||
|
||||
import org.bukkit.block.Sign;
|
||||
import org.bukkit.block.Skull;
|
||||
@@ -9,10 +9,10 @@ import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.block.Action;
|
||||
import org.bukkit.event.player.PlayerInteractEvent;
|
||||
|
||||
import com.Ben12345rocks.AdvancedCore.Util.Misc.PlayerUtils;
|
||||
import com.Ben12345rocks.VotingPlugin.Main;
|
||||
import com.Ben12345rocks.VotingPlugin.Signs.SignHandler;
|
||||
import com.Ben12345rocks.VotingPlugin.UserManager.UserManager;
|
||||
import com.bencodez.advancedcore.api.misc.PlayerUtils;
|
||||
import com.bencodez.votingplugin.VotingPluginMain;
|
||||
import com.bencodez.votingplugin.signs.SignHandler;
|
||||
import com.bencodez.votingplugin.user.UserManager;
|
||||
|
||||
// TODO: Auto-generated Javadoc
|
||||
/**
|
||||
@@ -21,23 +21,21 @@ import com.Ben12345rocks.VotingPlugin.UserManager.UserManager;
|
||||
public class PlayerInteract implements Listener {
|
||||
|
||||
/** The plugin. */
|
||||
private static Main plugin;
|
||||
private static VotingPluginMain plugin;
|
||||
|
||||
/**
|
||||
* Instantiates a new player interact.
|
||||
*
|
||||
* @param plugin
|
||||
* the plugin
|
||||
* @param plugin the plugin
|
||||
*/
|
||||
public PlayerInteract(Main plugin) {
|
||||
public PlayerInteract(VotingPluginMain plugin) {
|
||||
PlayerInteract.plugin = plugin;
|
||||
}
|
||||
|
||||
/**
|
||||
* On player interact.
|
||||
*
|
||||
* @param event
|
||||
* the event
|
||||
* @param event the event
|
||||
*/
|
||||
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
|
||||
public void onPlayerInteract(PlayerInteractEvent event) {
|
||||
@@ -46,7 +44,7 @@ public class PlayerInteract implements Listener {
|
||||
// plugin.debug("Checking for sign click");
|
||||
if (event.getClickedBlock().getState() instanceof Sign) {
|
||||
// plugin.debug(player.getName() + " right clicked a sign");
|
||||
for (SignHandler sign : plugin.getSigns()) {
|
||||
for (SignHandler sign : plugin.getSigns().getSigns()) {
|
||||
if (sign.isLocationSame(event.getClickedBlock().getLocation())) {
|
||||
// plugin.debug(player.getName() +
|
||||
// " right clicked a top voter sign, sending message");
|
||||
@@ -68,7 +66,7 @@ public class PlayerInteract implements Listener {
|
||||
Object ob = PlayerUtils.getInstance().getPlayerMeta(player, "skullset");
|
||||
if (ob != null) {
|
||||
String sign1 = (String) ob;
|
||||
for (SignHandler sign : plugin.getSigns()) {
|
||||
for (SignHandler sign : plugin.getSigns().getSigns()) {
|
||||
if (sign.getSign().equals(sign1)) {
|
||||
sign.setSkullLocation(event.getClickedBlock().getLocation());
|
||||
sign.storeSign();
|
||||
+20
-19
@@ -1,4 +1,4 @@
|
||||
package com.Ben12345rocks.VotingPlugin.Listeners;
|
||||
package com.bencodez.votingplugin.listeners;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
@@ -7,12 +7,11 @@ import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.PlayerQuitEvent;
|
||||
|
||||
import com.Ben12345rocks.AdvancedCore.Listeners.AdvancedCoreLoginEvent;
|
||||
import com.Ben12345rocks.AdvancedCore.UserManager.UserStorage;
|
||||
import com.Ben12345rocks.VotingPlugin.Main;
|
||||
import com.Ben12345rocks.VotingPlugin.Config.Config;
|
||||
import com.Ben12345rocks.VotingPlugin.Objects.User;
|
||||
import com.Ben12345rocks.VotingPlugin.UserManager.UserManager;
|
||||
import com.bencodez.advancedcore.api.user.UserStorage;
|
||||
import com.bencodez.advancedcore.listeners.AdvancedCoreLoginEvent;
|
||||
import com.bencodez.votingplugin.VotingPluginMain;
|
||||
import com.bencodez.votingplugin.user.UserManager;
|
||||
import com.bencodez.votingplugin.user.VotingPluginUser;
|
||||
|
||||
// TODO: Auto-generated Javadoc
|
||||
/**
|
||||
@@ -21,34 +20,31 @@ import com.Ben12345rocks.VotingPlugin.UserManager.UserManager;
|
||||
public class PlayerJoinEvent implements Listener {
|
||||
|
||||
/** The plugin. */
|
||||
@SuppressWarnings("unused")
|
||||
private static Main plugin;
|
||||
private static VotingPluginMain plugin;
|
||||
|
||||
/**
|
||||
* Instantiates a new player join event.
|
||||
*
|
||||
* @param plugin
|
||||
* the plugin
|
||||
* @param plugin the plugin
|
||||
*/
|
||||
public PlayerJoinEvent(Main plugin) {
|
||||
public PlayerJoinEvent(VotingPluginMain plugin) {
|
||||
PlayerJoinEvent.plugin = plugin;
|
||||
}
|
||||
|
||||
/**
|
||||
* On player login.
|
||||
*
|
||||
* @param event
|
||||
* the event
|
||||
* @param event the event
|
||||
*/
|
||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||
public void onPlayerLogin(AdvancedCoreLoginEvent event) {
|
||||
if (event.getPlayer() == null
|
||||
|| (Main.plugin.getStorageType().equals(UserStorage.MYSQL) && Main.plugin.getMysql() == null)) {
|
||||
if (event.getPlayer() == null || (VotingPluginMain.plugin.getStorageType().equals(UserStorage.MYSQL)
|
||||
&& VotingPluginMain.plugin.getMysql() == null)) {
|
||||
return;
|
||||
}
|
||||
Player player = event.getPlayer();
|
||||
|
||||
User user = UserManager.getInstance().getVotingPluginUser(player);
|
||||
VotingPluginUser user = UserManager.getInstance().getVotingPluginUser(player);
|
||||
if (player.isOp() && plugin.isYmlError()) {
|
||||
user.sendMessage("&cVotingPlugin: Detected yml error, please check console for details");
|
||||
}
|
||||
@@ -62,11 +58,13 @@ public class PlayerJoinEvent implements Listener {
|
||||
// give offline vote (if they voted offline)
|
||||
user.offVote();
|
||||
}
|
||||
|
||||
user.loginRewards();
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||
public void onPlayerQuit(PlayerQuitEvent event) {
|
||||
if (Config.getInstance().isDisableAdvancedTab()) {
|
||||
if (plugin.getConfigFile().isDisableAdvancedTab()) {
|
||||
return;
|
||||
}
|
||||
final java.util.UUID uuid = event.getPlayer().getUniqueId();
|
||||
@@ -74,7 +72,10 @@ public class PlayerJoinEvent implements Listener {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
Main.plugin.getAdvancedTab().remove(uuid);
|
||||
VotingPluginMain.plugin.getAdvancedTab().remove(uuid);
|
||||
|
||||
VotingPluginUser user = UserManager.getInstance().getVotingPluginUser(uuid);
|
||||
user.logoutRewards();
|
||||
}
|
||||
});
|
||||
|
||||
+45
-55
@@ -1,4 +1,4 @@
|
||||
package com.Ben12345rocks.VotingPlugin.Listeners;
|
||||
package com.bencodez.votingplugin.listeners;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.ZoneId;
|
||||
@@ -9,21 +9,14 @@ import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
|
||||
import com.Ben12345rocks.AdvancedCore.Util.Misc.ArrayUtils;
|
||||
import com.Ben12345rocks.AdvancedCore.Util.Misc.PlayerUtils;
|
||||
import com.Ben12345rocks.AdvancedCore.Util.PluginMessage.PluginMessage;
|
||||
import com.Ben12345rocks.VotingPlugin.BungeeHandler;
|
||||
import com.Ben12345rocks.VotingPlugin.Main;
|
||||
import com.Ben12345rocks.VotingPlugin.Config.BungeeSettings;
|
||||
import com.Ben12345rocks.VotingPlugin.Config.Config;
|
||||
import com.Ben12345rocks.VotingPlugin.Config.ConfigVoteSites;
|
||||
import com.Ben12345rocks.VotingPlugin.Events.PlayerVoteEvent;
|
||||
import com.Ben12345rocks.VotingPlugin.Objects.User;
|
||||
import com.Ben12345rocks.VotingPlugin.Objects.VoteSite;
|
||||
import com.Ben12345rocks.VotingPlugin.SpecialRewards.SpecialRewards;
|
||||
import com.Ben12345rocks.VotingPlugin.UserManager.UserManager;
|
||||
import com.Ben12345rocks.VotingPlugin.VoteParty.VoteParty;
|
||||
import com.Ben12345rocks.VotingPlugin.bungee.BungeeMethod;
|
||||
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.PlayerVoteEvent;
|
||||
import com.bencodez.votingplugin.objects.VoteSite;
|
||||
import com.bencodez.votingplugin.user.UserManager;
|
||||
import com.bencodez.votingplugin.user.VotingPluginUser;
|
||||
|
||||
// TODO: Auto-generated Javadoc
|
||||
/**
|
||||
@@ -31,49 +24,45 @@ import com.Ben12345rocks.VotingPlugin.bungee.BungeeMethod;
|
||||
*/
|
||||
public class PlayerVoteListener implements Listener {
|
||||
|
||||
/** The config. */
|
||||
static Config config = Config.getInstance();
|
||||
|
||||
/** The config vote sites. */
|
||||
static ConfigVoteSites configVoteSites = ConfigVoteSites.getInstance();
|
||||
|
||||
/** The plugin. */
|
||||
static Main plugin = Main.plugin;
|
||||
|
||||
private static Object object = new Object();
|
||||
|
||||
private VotingPluginMain plugin;
|
||||
|
||||
/**
|
||||
* Instantiates a new votifer event.
|
||||
*
|
||||
* @param plugin
|
||||
* the plugin
|
||||
* @param plugin the plugin
|
||||
*/
|
||||
public PlayerVoteListener(Main plugin) {
|
||||
PlayerVoteListener.plugin = plugin;
|
||||
public PlayerVoteListener(VotingPluginMain plugin) {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
/**
|
||||
* On votifer event.
|
||||
*
|
||||
* @param event
|
||||
* the event
|
||||
* @param event the event
|
||||
*/
|
||||
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
|
||||
public void onplayerVote(PlayerVoteEvent event) {
|
||||
String playerName = event.getPlayer();
|
||||
if (!PlayerUtils.getInstance().isValidUser(playerName, Config.getInstance().isAllowUnJoinedCheckServer())) {
|
||||
if (!config.isAllowUnjoined()) {
|
||||
if (!PlayerUtils.getInstance().isValidUser(playerName, plugin.getConfigFile().isAllowUnJoinedCheckServer())) {
|
||||
if (!plugin.getConfigFile().isAllowUnjoined()) {
|
||||
plugin.getLogger().warning("Player " + playerName
|
||||
+ " has not joined before, disregarding vote, set AllowUnjoined to true to prevent this");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (event.isBungee()) {
|
||||
plugin.debug("BungeePlayerVote forcebungee: " + event.isForceBungee() + ", bungeetotals: "
|
||||
+ event.getBungeeTextTotals());
|
||||
}
|
||||
|
||||
VoteSite voteSite = event.getVoteSite();
|
||||
|
||||
// check valid service sites
|
||||
if (voteSite == null) {
|
||||
if (!Config.getInstance().isDisableNoServiceSiteMessage()) {
|
||||
if (!plugin.getConfigFile().isDisableNoServiceSiteMessage()) {
|
||||
plugin.getLogger().warning("No voting site with the service site: '" + event.getServiceSite() + "'");
|
||||
plugin.getLogger().warning(
|
||||
"Please read here on how to fix it: https://github.com/Ben12345rocks/VotingPlugin/wiki/Common-Problems");
|
||||
@@ -88,10 +77,10 @@ public class PlayerVoteListener implements Listener {
|
||||
return;
|
||||
}
|
||||
|
||||
User user = UserManager.getInstance().getVotingPluginUser(playerName);
|
||||
user.updateName();
|
||||
VotingPluginUser user = UserManager.getInstance().getVotingPluginUser(playerName);
|
||||
user.updateName(true);
|
||||
|
||||
if (Config.getInstance().isClearCacheOnVote() || BungeeSettings.getInstance().isUseBungeecoord()) {
|
||||
if (plugin.getConfigFile().isClearCacheOnVote() || plugin.getBungeeSettings().isUseBungeecoord()) {
|
||||
user.clearCache();
|
||||
}
|
||||
|
||||
@@ -103,12 +92,12 @@ public class PlayerVoteListener implements Listener {
|
||||
synchronized (object) {
|
||||
|
||||
// vote party
|
||||
VoteParty.getInstance().vote(user, event.isRealVote());
|
||||
plugin.getVoteParty().vote(user, event.isRealVote());
|
||||
|
||||
// broadcast vote if enabled in config
|
||||
if (config.isBroadcastVotesEnabled()
|
||||
&& (BungeeSettings.getInstance().isBungeeBroadcast() || !event.isBungee())) {
|
||||
if (!Config.getInstance().getFormatBroadcastWhenOnline() || user.isOnline()) {
|
||||
if (plugin.getConfigFile().isBroadcastVotesEnabled()
|
||||
&& (plugin.getBungeeSettings().isBungeeBroadcast() || !event.isBungee())) {
|
||||
if (!plugin.getConfigFile().getFormatBroadcastWhenOnline() || user.isOnline()) {
|
||||
voteSite.broadcastVote(user);
|
||||
}
|
||||
}
|
||||
@@ -122,17 +111,18 @@ public class PlayerVoteListener implements Listener {
|
||||
user.setLastVoteCoolDownCheck(false, voteSite);
|
||||
|
||||
// try logging to file
|
||||
if (Config.getInstance().isLogVotesToFile()) {
|
||||
if (plugin.getConfigFile().isLogVotesToFile()) {
|
||||
try {
|
||||
Main.plugin.logVote(LocalDateTime.now().atZone(ZoneId.systemDefault()).toLocalDateTime(),
|
||||
playerName, voteSite.getKey());
|
||||
VotingPluginMain.plugin.logVote(
|
||||
LocalDateTime.now().atZone(ZoneId.systemDefault()).toLocalDateTime(), playerName,
|
||||
voteSite.getKey());
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
// check first vote rewards
|
||||
SpecialRewards.getInstance().checkFirstVote(user);
|
||||
plugin.getSpecialRewards().checkFirstVote(user);
|
||||
|
||||
if (user.isReminded()) {
|
||||
user.setReminded(false);
|
||||
@@ -140,8 +130,8 @@ public class PlayerVoteListener implements Listener {
|
||||
|
||||
// check if player has voted on all sites in one day
|
||||
|
||||
if (((user.isOnline() || voteSite.isGiveOffline()) && Main.plugin.getOptions().isProcessRewards())
|
||||
|| event.isBungee()) {
|
||||
if (((user.isOnline() || voteSite.isGiveOffline())
|
||||
&& VotingPluginMain.plugin.getOptions().isProcessRewards()) || event.isBungee()) {
|
||||
user.playerVote(voteSite, true, false, event.isForceBungee());
|
||||
user.closeInv();
|
||||
} else {
|
||||
@@ -151,8 +141,8 @@ public class PlayerVoteListener implements Listener {
|
||||
}
|
||||
|
||||
// add to total votes
|
||||
if ((Config.getInstance().isCountFakeVotes() || event.isRealVote()) && event.isAddTotals()) {
|
||||
if (Config.getInstance().isAddTotals()) {
|
||||
if ((plugin.getConfigFile().isCountFakeVotes() || event.isRealVote()) && event.isAddTotals()) {
|
||||
if (plugin.getConfigFile().isAddTotals()) {
|
||||
user.addTotal();
|
||||
user.addTotalDaily();
|
||||
user.addTotalWeekly();
|
||||
@@ -163,19 +153,19 @@ public class PlayerVoteListener implements Listener {
|
||||
user.checkDayVoteStreak();
|
||||
|
||||
// other rewards
|
||||
SpecialRewards.getInstance().checkAllSites(user);
|
||||
SpecialRewards.getInstance().checkCumualativeVotes(user);
|
||||
SpecialRewards.getInstance().checkMilestone(user);
|
||||
plugin.getSpecialRewards().checkAllSites(user);
|
||||
plugin.getSpecialRewards().checkCumualativeVotes(user, event.getBungeeTextTotals());
|
||||
plugin.getSpecialRewards().checkMilestone(user, event.getBungeeTextTotals());
|
||||
|
||||
if (BungeeSettings.getInstance().isUseBungeecoord()) {
|
||||
if (BungeeHandler.getInstance().getMethod().equals(BungeeMethod.MYSQL)) {
|
||||
if (plugin.getBungeeSettings().isUseBungeecoord()) {
|
||||
if (plugin.getBungeeHandler().getMethod().equals(BungeeMethod.MYSQL)) {
|
||||
final String uuid = user.getUUID();
|
||||
Bukkit.getScheduler().runTaskLaterAsynchronously(plugin, new Runnable() {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
if (Bukkit.getOnlinePlayers().size() > 0) {
|
||||
PluginMessage.getInstance().sendPluginMessage(
|
||||
plugin.getPluginMessaging().sendPluginMessage(
|
||||
PlayerUtils.getInstance().getRandomOnlinePlayer(), "VoteUpdate", uuid);
|
||||
}
|
||||
}
|
||||
+12
-16
@@ -1,16 +1,13 @@
|
||||
package com.Ben12345rocks.VotingPlugin.Listeners;
|
||||
package com.bencodez.votingplugin.listeners;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.block.SignChangeEvent;
|
||||
|
||||
import com.Ben12345rocks.AdvancedCore.Util.Messages.StringParser;
|
||||
import com.Ben12345rocks.AdvancedCore.Util.Misc.PlayerUtils;
|
||||
import com.Ben12345rocks.VotingPlugin.Main;
|
||||
import com.Ben12345rocks.VotingPlugin.Config.Config;
|
||||
import com.Ben12345rocks.VotingPlugin.Data.ServerData;
|
||||
import com.Ben12345rocks.VotingPlugin.Signs.Signs;
|
||||
import com.bencodez.advancedcore.api.messages.StringParser;
|
||||
import com.bencodez.advancedcore.api.misc.PlayerUtils;
|
||||
import com.bencodez.votingplugin.VotingPluginMain;
|
||||
|
||||
// TODO: Auto-generated Javadoc
|
||||
/**
|
||||
@@ -19,23 +16,21 @@ import com.Ben12345rocks.VotingPlugin.Signs.Signs;
|
||||
public class SignChange implements Listener {
|
||||
|
||||
/** The plugin. */
|
||||
private static Main plugin;
|
||||
private static VotingPluginMain plugin;
|
||||
|
||||
/**
|
||||
* Instantiates a new sign change.
|
||||
*
|
||||
* @param plugin
|
||||
* the plugin
|
||||
* @param plugin the plugin
|
||||
*/
|
||||
public SignChange(Main plugin) {
|
||||
public SignChange(VotingPluginMain plugin) {
|
||||
SignChange.plugin = plugin;
|
||||
}
|
||||
|
||||
/**
|
||||
* On sign change.
|
||||
*
|
||||
* @param event
|
||||
* the event
|
||||
* @param event the event
|
||||
*/
|
||||
@EventHandler(ignoreCancelled = true)
|
||||
public void onSignChange(SignChangeEvent event) {
|
||||
@@ -49,14 +44,15 @@ public class SignChange implements Listener {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
ServerData.getInstance().addSign(event.getBlock().getLocation(), event.getLine(2),
|
||||
plugin.getServerData().addSign(event.getBlock().getLocation(), event.getLine(2),
|
||||
Integer.parseInt(event.getLine(1)));
|
||||
event.getPlayer().sendMessage(StringParser.getInstance().colorize("&aAdded sign!"));
|
||||
Bukkit.getScheduler().runTaskAsynchronously(plugin, new Runnable() {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
Signs.getInstance().updateSigns();
|
||||
plugin.getSigns().updateSigns();
|
||||
plugin.getSigns().storeSigns();
|
||||
}
|
||||
});
|
||||
} catch (Exception ex) {
|
||||
@@ -65,7 +61,7 @@ public class SignChange implements Listener {
|
||||
}
|
||||
} else {
|
||||
event.getPlayer()
|
||||
.sendMessage(StringParser.getInstance().colorize(Config.getInstance().getFormatNoPerms()));
|
||||
.sendMessage(StringParser.getInstance().colorize(plugin.getConfigFile().getFormatNoPerms()));
|
||||
}
|
||||
}
|
||||
|
||||
+14
-25
@@ -1,4 +1,4 @@
|
||||
package com.Ben12345rocks.VotingPlugin.Listeners;
|
||||
package com.bencodez.votingplugin.listeners;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
@@ -7,13 +7,10 @@ import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
|
||||
import com.Ben12345rocks.AdvancedCore.Util.Misc.ArrayUtils;
|
||||
import com.Ben12345rocks.VotingPlugin.Main;
|
||||
import com.Ben12345rocks.VotingPlugin.Config.Config;
|
||||
import com.Ben12345rocks.VotingPlugin.Config.ConfigVoteSites;
|
||||
import com.Ben12345rocks.VotingPlugin.Data.ServerData;
|
||||
import com.Ben12345rocks.VotingPlugin.Events.PlayerVoteEvent;
|
||||
import com.Ben12345rocks.VotingPlugin.Objects.VoteSite;
|
||||
import com.bencodez.advancedcore.api.misc.ArrayUtils;
|
||||
import com.bencodez.votingplugin.VotingPluginMain;
|
||||
import com.bencodez.votingplugin.events.PlayerVoteEvent;
|
||||
import com.bencodez.votingplugin.objects.VoteSite;
|
||||
import com.vexsoftware.votifier.model.Vote;
|
||||
import com.vexsoftware.votifier.model.VotifierEvent;
|
||||
|
||||
@@ -23,30 +20,22 @@ import com.vexsoftware.votifier.model.VotifierEvent;
|
||||
*/
|
||||
public class VotiferEvent implements Listener {
|
||||
|
||||
/** The config. */
|
||||
static Config config = Config.getInstance();
|
||||
|
||||
/** The config vote sites. */
|
||||
static ConfigVoteSites configVoteSites = ConfigVoteSites.getInstance();
|
||||
|
||||
/** The plugin. */
|
||||
static Main plugin = Main.plugin;
|
||||
private VotingPluginMain plugin;
|
||||
|
||||
/**
|
||||
* Instantiates a new votifer event.
|
||||
*
|
||||
* @param plugin
|
||||
* the plugin
|
||||
* @param plugin the plugin
|
||||
*/
|
||||
public VotiferEvent(Main plugin) {
|
||||
VotiferEvent.plugin = plugin;
|
||||
public VotiferEvent(VotingPluginMain plugin) {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
/**
|
||||
* On votifer event.
|
||||
*
|
||||
* @param event
|
||||
* the event
|
||||
* @param event the event
|
||||
*/
|
||||
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
|
||||
public void onVotiferEvent(VotifierEvent event) {
|
||||
@@ -59,7 +48,7 @@ public class VotiferEvent implements Listener {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
ServerData.getInstance().addServiceSite(voteSite);
|
||||
plugin.getServerData().addServiceSite(voteSite);
|
||||
}
|
||||
});
|
||||
|
||||
@@ -81,7 +70,7 @@ public class VotiferEvent implements Listener {
|
||||
public void run() {
|
||||
String voteSiteName = plugin.getVoteSiteName(voteSite);
|
||||
|
||||
ArrayList<String> sites = configVoteSites.getVoteSitesNames();
|
||||
ArrayList<String> sites = plugin.getConfigVoteSites().getVoteSitesNames();
|
||||
boolean createSite = false;
|
||||
if (sites != null) {
|
||||
if (!sites.contains(voteSiteName)) {
|
||||
@@ -91,10 +80,10 @@ public class VotiferEvent implements Listener {
|
||||
createSite = true;
|
||||
}
|
||||
|
||||
if (Config.getInstance().isAutoCreateVoteSites() && createSite) {
|
||||
if (plugin.getConfigFile().isAutoCreateVoteSites() && createSite) {
|
||||
plugin.getLogger().warning("VoteSite with service site '" + voteSiteName
|
||||
+ "' does not exist, attempting to generaterate...");
|
||||
ConfigVoteSites.getInstance().generateVoteSite(voteSiteName);
|
||||
plugin.getConfigVoteSites().generateVoteSite(voteSiteName);
|
||||
|
||||
ArrayList<String> services = new ArrayList<String>();
|
||||
for (VoteSite site : plugin.getVoteSites()) {
|
||||
@@ -0,0 +1,43 @@
|
||||
package com.bencodez.votingplugin.listeners;
|
||||
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
|
||||
import com.bencodez.advancedcore.listeners.PluginUpdateVersionEvent;
|
||||
import com.bencodez.votingplugin.VotingPluginMain;
|
||||
|
||||
// TODO: Auto-generated Javadoc
|
||||
/**
|
||||
* The Class AdvancedCoreUpdateEvent.
|
||||
*/
|
||||
public class VotingPluginUpdateEvent implements Listener {
|
||||
|
||||
/** The plugin. */
|
||||
private static VotingPluginMain plugin;
|
||||
|
||||
/**
|
||||
* Instantiates a new advanced core update event.
|
||||
*
|
||||
* @param plugin the plugin
|
||||
*/
|
||||
public VotingPluginUpdateEvent(VotingPluginMain plugin) {
|
||||
VotingPluginUpdateEvent.plugin = plugin;
|
||||
}
|
||||
|
||||
/**
|
||||
* On plugin update.
|
||||
*
|
||||
* @param event the event
|
||||
*/
|
||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||
public void onPluginUpdate(PluginUpdateVersionEvent event) {
|
||||
if (event.getPlugin().getName().equals(plugin.getDescription().getName())) {
|
||||
if (!event.getOldVersion().equals("")) {
|
||||
plugin.getLogger().info("VotingPlugin Updated to " + plugin.getDescription().getVersion() + " from "
|
||||
+ event.getOldVersion());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,232 @@
|
||||
package com.bencodez.votingplugin.objects;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import com.bencodez.advancedcore.api.item.ItemBuilder;
|
||||
import com.bencodez.advancedcore.api.messages.StringParser;
|
||||
import com.bencodez.advancedcore.api.misc.ArrayUtils;
|
||||
import com.bencodez.advancedcore.api.misc.MiscUtils;
|
||||
import com.bencodez.advancedcore.api.misc.PlayerUtils;
|
||||
import com.bencodez.advancedcore.api.rewards.RewardBuilder;
|
||||
import com.bencodez.advancedcore.api.rewards.RewardHandler;
|
||||
import com.bencodez.votingplugin.VotingPluginMain;
|
||||
import com.bencodez.votingplugin.bungee.BungeeMethod;
|
||||
import com.bencodez.votingplugin.user.UserManager;
|
||||
import com.bencodez.votingplugin.user.VotingPluginUser;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
/**
|
||||
* The Class VoteSite.
|
||||
*/
|
||||
public class VoteSite {
|
||||
@Getter
|
||||
@Setter
|
||||
private String displayName;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
private boolean enabled;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
private boolean giveOffline;
|
||||
|
||||
@Setter
|
||||
private ConfigurationSection item;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
private String key;
|
||||
|
||||
private VotingPluginMain plugin;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
private int priority;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
private String serviceSite;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
private double timeOffSet;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
private double voteDelay;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
private boolean voteDelayDaily;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
private double voteDelayMin;
|
||||
|
||||
@Setter
|
||||
private String voteURL;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
private boolean waitUntilVoteDelay;
|
||||
|
||||
public VoteSite(VotingPluginMain plugin, String siteName) {
|
||||
this.plugin = plugin;
|
||||
key = siteName.replace(".", "_");
|
||||
init();
|
||||
}
|
||||
|
||||
public void broadcastVote(VotingPluginUser user) {
|
||||
broadcastVote(user, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Broadcast vote.
|
||||
*
|
||||
* @param user the user
|
||||
* @param checkBungee check bungee broadcast
|
||||
*/
|
||||
public void broadcastVote(VotingPluginUser user, boolean checkBungee) {
|
||||
if (!user.isVanished()) {
|
||||
if (checkBungee && plugin.getBungeeSettings().isBungeeBroadcast()
|
||||
&& plugin.getBungeeSettings().isUseBungeecoord()) {
|
||||
if (plugin.getBungeeHandler().getMethod().equals(BungeeMethod.SOCKETS)) {
|
||||
plugin.getBungeeHandler().sendData("Broadcast", getServiceSite(), user.getPlayerName());
|
||||
} else if (plugin.getBungeeHandler().getMethod().equals(BungeeMethod.MYSQL)
|
||||
|| plugin.getBungeeHandler().getMethod().equals(BungeeMethod.PLUGINMESSAGING)) {
|
||||
String uuid = user.getUUID();
|
||||
String service = getServiceSite();
|
||||
|
||||
if (Bukkit.getOnlinePlayers().size() > 0) {
|
||||
plugin.getPluginMessaging().sendPluginMessage(PlayerUtils.getInstance().getRandomOnlinePlayer(),
|
||||
"VoteBroadcast", uuid, service);
|
||||
}
|
||||
}
|
||||
|
||||
} else {
|
||||
String playerName = user.getPlayerName();
|
||||
if (plugin.getConfigFile().getVotingBroadcastBlacklist().contains(playerName)) {
|
||||
plugin.getLogger().info("Not broadcasting for " + playerName + ", in blacklist");
|
||||
return;
|
||||
}
|
||||
String bc = StringParser.getInstance().colorize(plugin.getConfigFile().getFormatBroadCastMsg());
|
||||
HashMap<String, String> placeholders = new HashMap<String, String>();
|
||||
placeholders.put("player", playerName);
|
||||
placeholders.put("nickname",
|
||||
(user.getPlayer() != null) ? user.getPlayer().getDisplayName() : user.getPlayerName());
|
||||
placeholders.put("sitename", getDisplayName());
|
||||
placeholders.put("servicesite", getServiceSite());
|
||||
bc = StringParser.getInstance().replacePlaceHolder(bc, placeholders);
|
||||
bc = StringParser.getInstance().replacePlaceHolders(user.getOfflinePlayer(), bc);
|
||||
ArrayList<Player> players = new ArrayList<Player>();
|
||||
for (Player p : Bukkit.getOnlinePlayers()) {
|
||||
if (!UserManager.getInstance().getVotingPluginUser(p).getDisableBroadcast()) {
|
||||
players.add(p);
|
||||
}
|
||||
}
|
||||
|
||||
MiscUtils.getInstance().broadcast(bc, players);
|
||||
}
|
||||
} else {
|
||||
plugin.debug(user.getPlayerName() + " is vanished, not broadcasting");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the item
|
||||
*/
|
||||
public ItemBuilder getItem() {
|
||||
if (item == null) {
|
||||
plugin.getLogger().warning("Invalid item section in site: " + key);
|
||||
return new ItemBuilder(Material.STONE, 1).setName("&cInvalid item for site: " + key)
|
||||
.setLore("&cInvalid item for site: " + key);
|
||||
} else {
|
||||
return new ItemBuilder(item);
|
||||
}
|
||||
}
|
||||
|
||||
public ConfigurationSection getSiteData() {
|
||||
return plugin.getConfigVoteSites().getData(key);
|
||||
}
|
||||
|
||||
public String getVoteURL() {
|
||||
return getVoteURL(true);
|
||||
}
|
||||
|
||||
public String getVoteURL(boolean json) {
|
||||
if (!plugin.getConfigFile().isFormatCommandsVoteForceLinks() || !json) {
|
||||
return voteURL;
|
||||
} else {
|
||||
if (!voteURL.startsWith("http")) {
|
||||
return "[Text=\"" + voteURL + "\",url=\"http://" + voteURL + "\"]";
|
||||
}
|
||||
return "[Text=\"" + voteURL + "\",url=\"" + voteURL + "\"]";
|
||||
}
|
||||
}
|
||||
|
||||
public String getVoteURLJsonStrip() {
|
||||
String url = ChatColor.stripColor(StringParser.getInstance()
|
||||
.colorize(StringParser.getInstance().parseJson(getVoteURL(false)).toPlainText()));
|
||||
if (!url.startsWith("http")) {
|
||||
if (!url.startsWith("www.")) {
|
||||
url = "https://www." + url;
|
||||
} else {
|
||||
url = "https://" + url;
|
||||
}
|
||||
}
|
||||
return url;
|
||||
}
|
||||
|
||||
public void giveRewards(VotingPluginUser user, boolean online, boolean bungee) {
|
||||
new RewardBuilder(plugin.getConfigVoteSites().getData(), plugin.getConfigVoteSites().getRewardsPath(key))
|
||||
.setOnline(online).withPlaceHolder("ServiceSite", getServiceSite())
|
||||
.withPlaceHolder("SiteName", getDisplayName()).withPlaceHolder("VoteDelay", "" + getVoteDelay())
|
||||
.withPlaceHolder("VoteURL", getVoteURL()).setServer(bungee).send(user);
|
||||
|
||||
new RewardBuilder(plugin.getConfigVoteSites().getData(), plugin.getConfigVoteSites().getEverySiteRewardPath())
|
||||
.setOnline(online).withPlaceHolder("ServiceSite", getServiceSite())
|
||||
.withPlaceHolder("SiteName", getDisplayName()).withPlaceHolder("VoteDelay", "" + getVoteDelay())
|
||||
.withPlaceHolder("VoteURL", getVoteURL()).setServer(bungee).send(user);
|
||||
}
|
||||
|
||||
public boolean hasRewards() {
|
||||
return RewardHandler.getInstance().hasRewards(plugin.getConfigVoteSites().getData(),
|
||||
plugin.getConfigVoteSites().getRewardsPath(key));
|
||||
}
|
||||
|
||||
/**
|
||||
* Inits the.
|
||||
*/
|
||||
public void init() {
|
||||
setVoteURL(plugin.getConfigVoteSites().getVoteURL(key));
|
||||
setServiceSite(plugin.getConfigVoteSites().getServiceSite(key));
|
||||
setVoteDelay(plugin.getConfigVoteSites().getVoteDelay(key));
|
||||
setVoteDelayMin(plugin.getConfigVoteSites().getVoteDelayMin(key));
|
||||
setEnabled(plugin.getConfigVoteSites().getVoteSiteEnabled(key));
|
||||
setPriority(plugin.getConfigVoteSites().getPriority(key));
|
||||
displayName = plugin.getConfigVoteSites().getDisplayName(key);
|
||||
if (displayName == null || displayName.equals("")) {
|
||||
displayName = key;
|
||||
}
|
||||
item = plugin.getConfigVoteSites().getItem(key);
|
||||
voteDelayDaily = plugin.getConfigVoteSites().getVoteSiteResetVoteDelayDaily(key);
|
||||
giveOffline = plugin.getConfigVoteSites().getVoteSiteGiveOffline(key);
|
||||
waitUntilVoteDelay = plugin.getConfigVoteSites().getWaitUntilVoteDelay(key);
|
||||
timeOffSet = plugin.getConfigVoteSites().getTimeOffSet(key);
|
||||
}
|
||||
|
||||
public boolean isVaidServiceSite() {
|
||||
return ArrayUtils.getInstance().containsIgnoreCase(plugin.getServerData().getServiceSites(), getServiceSite());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,76 @@
|
||||
package com.bencodez.votingplugin.placeholders;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
|
||||
import com.bencodez.advancedcore.api.placeholder.PlaceHolder;
|
||||
import com.bencodez.votingplugin.VotingPluginMain;
|
||||
import com.bencodez.votingplugin.user.UserManager;
|
||||
import com.bencodez.votingplugin.user.VotingPluginUser;
|
||||
|
||||
import be.maximvdw.placeholderapi.PlaceholderAPI;
|
||||
import be.maximvdw.placeholderapi.PlaceholderReplaceEvent;
|
||||
import be.maximvdw.placeholderapi.PlaceholderReplacer;
|
||||
|
||||
// TODO: Auto-generated Javadoc
|
||||
/**
|
||||
* The Class PlaceHolders.
|
||||
*/
|
||||
public class MVdWPlaceholders {
|
||||
|
||||
/** The plugin. */
|
||||
private VotingPluginMain plugin;
|
||||
|
||||
/**
|
||||
* Instantiates a new place holders.
|
||||
*
|
||||
* @param plugin the plugin
|
||||
*/
|
||||
public MVdWPlaceholders(VotingPluginMain plugin) {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
public void loadMVdWPlaceholders() {
|
||||
if (Bukkit.getPluginManager().isPluginEnabled("MVdWPlaceholderAPI")) {
|
||||
// The plugin is enabled
|
||||
for (final PlaceHolder<VotingPluginUser> place : plugin.getPlaceholders().getPlaceholders()) {
|
||||
String str = place.getIdentifier();
|
||||
if (!str.endsWith("_")) {
|
||||
PlaceholderAPI.registerPlaceholder(VotingPluginMain.plugin, "VotingPlugin_" + str,
|
||||
new PlaceholderReplacer() {
|
||||
|
||||
@Override
|
||||
public String onPlaceholderReplace(PlaceholderReplaceEvent event) {
|
||||
VotingPluginUser user = UserManager.getInstance()
|
||||
.getVotingPluginUser(event.getOfflinePlayer());
|
||||
if (plugin.getConfigFile().isUsePrimaryAccountForPlaceholders()
|
||||
&& user.hasPrimaryAccount()) {
|
||||
user = UserManager.getInstance().getVotingPluginUser(user.getPrimaryAccount());
|
||||
}
|
||||
return place.placeholderRequest(event.getOfflinePlayer(), user,
|
||||
event.getPlaceholder().substring("VotingPlugin_".length()));
|
||||
}
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
for (final PlaceHolder<VotingPluginUser> place : plugin.getPlaceholders().getNonPlayerPlaceholders()) {
|
||||
String str = place.getIdentifier();
|
||||
if (!str.endsWith("_")) {
|
||||
PlaceholderAPI.registerPlaceholder(VotingPluginMain.plugin, "VotingPlugin_" + str,
|
||||
new PlaceholderReplacer() {
|
||||
|
||||
@Override
|
||||
public String onPlaceholderReplace(PlaceholderReplaceEvent event) {
|
||||
return place.placeholderRequest(event.getOfflinePlayer(), null,
|
||||
event.getPlaceholder().substring("VotingPlugin_".length()));
|
||||
}
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,573 @@
|
||||
package com.bencodez.votingplugin.placeholders;
|
||||
|
||||
import java.text.NumberFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.Locale;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
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.PlaceHolder;
|
||||
import com.bencodez.votingplugin.VotingPluginMain;
|
||||
import com.bencodez.votingplugin.objects.VoteSite;
|
||||
import com.bencodez.votingplugin.topvoter.TopVoter;
|
||||
import com.bencodez.votingplugin.user.UserManager;
|
||||
import com.bencodez.votingplugin.user.VotingPluginUser;
|
||||
|
||||
import lombok.Getter;
|
||||
|
||||
// TODO: Auto-generated Javadoc
|
||||
/**
|
||||
* The Class PlaceHolders.
|
||||
*/
|
||||
public class PlaceHolders {
|
||||
|
||||
@Getter
|
||||
private ArrayList<PlaceHolder<VotingPluginUser>> nonPlayerPlaceholders = new ArrayList<PlaceHolder<VotingPluginUser>>();
|
||||
|
||||
@Getter
|
||||
private ArrayList<PlaceHolder<VotingPluginUser>> placeholders = new ArrayList<PlaceHolder<VotingPluginUser>>();
|
||||
|
||||
private VotingPluginMain plugin;
|
||||
|
||||
public PlaceHolders(VotingPluginMain plugin) {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
public String getPlaceHolder(OfflinePlayer p, String identifier) {
|
||||
if (plugin.getConfigFile().isUseJavascriptPlaceholders()) {
|
||||
identifier = StringParser.getInstance().replaceJavascript(p, identifier);
|
||||
}
|
||||
|
||||
for (PlaceHolder<VotingPluginUser> placeholder : nonPlayerPlaceholders) {
|
||||
if (placeholder.matches(identifier)) {
|
||||
return placeholder.placeholderRequest(p, null, identifier);
|
||||
}
|
||||
}
|
||||
|
||||
VotingPluginUser user = UserManager.getInstance().getVotingPluginUser(p);
|
||||
if (Bukkit.isPrimaryThread()) {
|
||||
user.setWaitForCache(false);
|
||||
}
|
||||
if (plugin.getConfigFile().isUsePrimaryAccountForPlaceholders() && user.hasPrimaryAccount()) {
|
||||
user = UserManager.getInstance().getVotingPluginUser(user.getPrimaryAccount());
|
||||
if (Bukkit.isPrimaryThread()) {
|
||||
user.setWaitForCache(false);
|
||||
}
|
||||
}
|
||||
|
||||
for (PlaceHolder<VotingPluginUser> placeholder : placeholders) {
|
||||
try {
|
||||
if (placeholder.matches(identifier)) {
|
||||
return placeholder.placeholderRequest(p, user, identifier);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
plugin.debug(e);
|
||||
return "...";
|
||||
}
|
||||
}
|
||||
|
||||
return "Not a valid placeholder";
|
||||
}
|
||||
|
||||
public String getPlaceHolder(Player p, String identifier) {
|
||||
if (plugin.getConfigFile().isUseJavascriptPlaceholders()) {
|
||||
identifier = StringParser.getInstance().replaceJavascript(p, identifier);
|
||||
}
|
||||
return getPlaceHolder((OfflinePlayer) p, identifier);
|
||||
}
|
||||
|
||||
public void load() {
|
||||
placeholders.clear();
|
||||
nonPlayerPlaceholders.clear();
|
||||
|
||||
// older placeholders, might be removed in the future
|
||||
placeholders.add(new PlaceHolder<VotingPluginUser>("total") {
|
||||
|
||||
@Override
|
||||
public String placeholderRequest(OfflinePlayer p, VotingPluginUser user, String identifier) {
|
||||
return Integer.toString(user.getTotal(TopVoter.Monthly));
|
||||
}
|
||||
}.withDescription("Month total"));
|
||||
|
||||
placeholders.add(new PlaceHolder<VotingPluginUser>("alltimetotal") {
|
||||
|
||||
@Override
|
||||
public String placeholderRequest(OfflinePlayer p, VotingPluginUser user, String identifier) {
|
||||
return Integer.toString(user.getTotal(TopVoter.AllTime));
|
||||
}
|
||||
}.withDescription("Alltime total"));
|
||||
|
||||
placeholders.add(new PlaceHolder<VotingPluginUser>("lastmonthtotal") {
|
||||
|
||||
@Override
|
||||
public String placeholderRequest(OfflinePlayer p, VotingPluginUser user, String identifier) {
|
||||
return Integer.toString(user.getLastMonthTotal());
|
||||
}
|
||||
}.withDescription("Last month total"));
|
||||
|
||||
// end of older placeholders
|
||||
|
||||
placeholders.add(new PlaceHolder<VotingPluginUser>("DisableBroadcast") {
|
||||
|
||||
@Override
|
||||
public String placeholderRequest(OfflinePlayer p, VotingPluginUser user, String identifier) {
|
||||
return "" + user.getDisableBroadcast();
|
||||
}
|
||||
}.withDescription("Returns true/false if user has broadcast disabled"));
|
||||
|
||||
placeholders.add(new PlaceHolder<VotingPluginUser>("MilestoneCount") {
|
||||
|
||||
@Override
|
||||
public String placeholderRequest(OfflinePlayer p, VotingPluginUser user, String identifier) {
|
||||
return "" + user.getMilestoneCount();
|
||||
}
|
||||
}.withDescription("User 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) {
|
||||
return "" + user.getVoteShopIdentifierLimit(identifier);
|
||||
}
|
||||
}.withDescription("User voteshop limit for " + identifier));
|
||||
}
|
||||
}
|
||||
|
||||
for (final TopVoter top : TopVoter.values()) {
|
||||
placeholders.add(new PlaceHolder<VotingPluginUser>("Total_" + top.toString()) {
|
||||
|
||||
@Override
|
||||
public String placeholderRequest(OfflinePlayer p, VotingPluginUser user, String identifier) {
|
||||
return Integer.toString(user.getTotal(top));
|
||||
}
|
||||
}.withDescription("User total for " + top.getName()));
|
||||
}
|
||||
|
||||
placeholders.add(new PlaceHolder<VotingPluginUser>("BestDailyTotal") {
|
||||
|
||||
@Override
|
||||
public String placeholderRequest(OfflinePlayer p, VotingPluginUser user, String identifier) {
|
||||
return Integer.toString(user.getHighestDailyTotal());
|
||||
}
|
||||
}.withDescription("Best daily total"));
|
||||
|
||||
placeholders.add(new PlaceHolder<VotingPluginUser>("BestWeeklyTotal") {
|
||||
|
||||
@Override
|
||||
public String placeholderRequest(OfflinePlayer p, VotingPluginUser user, String identifier) {
|
||||
return Integer.toString(user.getHighestWeeklyTotal());
|
||||
}
|
||||
}.withDescription("Best weekly total"));
|
||||
|
||||
placeholders.add(new PlaceHolder<VotingPluginUser>("BestMonthlyTotal") {
|
||||
|
||||
@Override
|
||||
public String placeholderRequest(OfflinePlayer p, VotingPluginUser user, String identifier) {
|
||||
return Integer.toString(user.getHighestMonthlyTotal());
|
||||
}
|
||||
}.withDescription("Best monthly total"));
|
||||
|
||||
placeholders.add(new PlaceHolder<VotingPluginUser>("DailyVoteStreak") {
|
||||
|
||||
@Override
|
||||
public String placeholderRequest(OfflinePlayer p, VotingPluginUser user, String identifier) {
|
||||
return Integer.toString(user.getDayVoteStreak());
|
||||
}
|
||||
}.withDescription("Current daily votestreak"));
|
||||
|
||||
placeholders.add(new PlaceHolder<VotingPluginUser>("WeeklyVoteStreak") {
|
||||
|
||||
@Override
|
||||
public String placeholderRequest(OfflinePlayer p, VotingPluginUser user, String identifier) {
|
||||
return Integer.toString(user.getWeekVoteStreak());
|
||||
}
|
||||
}.withDescription("Current weekly votestreak"));
|
||||
|
||||
placeholders.add(new PlaceHolder<VotingPluginUser>("MonthVoteStreak") {
|
||||
|
||||
@Override
|
||||
public String placeholderRequest(OfflinePlayer p, VotingPluginUser user, String identifier) {
|
||||
return Integer.toString(user.getMonthVoteStreak());
|
||||
}
|
||||
}.withDescription("Current month votestreak"));
|
||||
|
||||
placeholders.add(new PlaceHolder<VotingPluginUser>("BestDailyVoteStreak") {
|
||||
|
||||
@Override
|
||||
public String placeholderRequest(OfflinePlayer p, VotingPluginUser user, String identifier) {
|
||||
return Integer.toString(user.getBestDayVoteStreak());
|
||||
}
|
||||
}.withDescription("Best daily votestreak"));
|
||||
|
||||
placeholders.add(new PlaceHolder<VotingPluginUser>("BestWeeklyVoteStreak") {
|
||||
|
||||
@Override
|
||||
public String placeholderRequest(OfflinePlayer p, VotingPluginUser user, String identifier) {
|
||||
return Integer.toString(user.getBestWeekVoteStreak());
|
||||
}
|
||||
}.withDescription("Best weekly votestreak"));
|
||||
|
||||
placeholders.add(new PlaceHolder<VotingPluginUser>("BestMonthVoteStreak") {
|
||||
|
||||
@Override
|
||||
public String placeholderRequest(OfflinePlayer p, VotingPluginUser user, String identifier) {
|
||||
return Integer.toString(user.getBestMonthVoteStreak());
|
||||
}
|
||||
}.withDescription("Best month votestreak"));
|
||||
|
||||
placeholders.add(new PlaceHolder<VotingPluginUser>("Points") {
|
||||
|
||||
@Override
|
||||
public String placeholderRequest(OfflinePlayer p, VotingPluginUser user, String identifier) {
|
||||
return Integer.toString(user.getPoints());
|
||||
}
|
||||
}.withDescription("User points"));
|
||||
|
||||
placeholders.add(new PlaceHolder<VotingPluginUser>("Points_Format") {
|
||||
|
||||
@Override
|
||||
public String placeholderRequest(OfflinePlayer p, VotingPluginUser user, String identifier) {
|
||||
NumberFormat numberFormat = NumberFormat.getNumberInstance(Locale.US);
|
||||
return numberFormat.format(user.getPoints());
|
||||
}
|
||||
}.withDescription("User points"));
|
||||
|
||||
placeholders.add(new PlaceHolder<VotingPluginUser>("CanVote") {
|
||||
|
||||
@Override
|
||||
public String placeholderRequest(OfflinePlayer p, VotingPluginUser user, String identifier) {
|
||||
return Boolean.toString(user.canVoteAll());
|
||||
}
|
||||
}.withDescription("Return true/false if player can vote on all sites"));
|
||||
|
||||
placeholders.add(new PlaceHolder<VotingPluginUser>("Next_AnySite") {
|
||||
|
||||
@Override
|
||||
public String placeholderRequest(OfflinePlayer p, VotingPluginUser user, String identifier) {
|
||||
if (user.canVoteAny()) {
|
||||
return plugin.getConfigFile().getFormatCommandsVoteNextInfoCanVote();
|
||||
}
|
||||
long smallest = -1;
|
||||
HashMap<Long, VoteSite> times = new HashMap<Long, VoteSite>();
|
||||
for (VoteSite site : plugin.getVoteSites()) {
|
||||
long t = user.voteNextDurationTime(site);
|
||||
if (smallest == -1) {
|
||||
smallest = t;
|
||||
}
|
||||
if (t < smallest) {
|
||||
smallest = t;
|
||||
}
|
||||
times.put(t, site);
|
||||
}
|
||||
for (Entry<Long, VoteSite> entry : times.entrySet()) {
|
||||
if (entry.getKey().longValue() == smallest) {
|
||||
return user.voteCommandNextInfo(entry.getValue());
|
||||
}
|
||||
}
|
||||
|
||||
return "Error";
|
||||
}
|
||||
}.withDescription("How long until user can vote on anysite"));
|
||||
|
||||
for (final VoteSite voteSite : plugin.getVoteSites()) {
|
||||
placeholders.add(new PlaceHolder<VotingPluginUser>("Next_" + voteSite.getKey()) {
|
||||
|
||||
@Override
|
||||
public String placeholderRequest(OfflinePlayer p, VotingPluginUser user, String identifier) {
|
||||
return user.voteCommandNextInfo(voteSite);
|
||||
}
|
||||
}.withDescription("How long until user can vote on " + voteSite.getKey()));
|
||||
placeholders.add(new PlaceHolder<VotingPluginUser>("Last_" + voteSite.getKey()) {
|
||||
|
||||
@Override
|
||||
public String placeholderRequest(OfflinePlayer p, VotingPluginUser user, String identifier) {
|
||||
return user.voteCommandLastDuration(voteSite);
|
||||
}
|
||||
}.withDescription("How long ago user voted on " + voteSite.getKey()));
|
||||
placeholders.add(new PlaceHolder<VotingPluginUser>("CanVote_" + voteSite.getKey()) {
|
||||
|
||||
@Override
|
||||
public String placeholderRequest(OfflinePlayer p, VotingPluginUser user, String identifier) {
|
||||
return "" + user.canVoteSite(voteSite);
|
||||
}
|
||||
}.withDescription("Whether or not player can vote on " + voteSite.getKey()));
|
||||
}
|
||||
|
||||
placeholders.add(new PlaceHolder<VotingPluginUser>("Top_All_Position") {
|
||||
|
||||
@Override
|
||||
public String placeholderRequest(OfflinePlayer p, VotingPluginUser user, String identifier) {
|
||||
int num = 1;
|
||||
for (Entry<VotingPluginUser, Integer> entry : plugin.getTopVoter(TopVoter.AllTime).entrySet()) {
|
||||
if (entry.getKey().getUUID().equals(p.getUniqueId().toString())) {
|
||||
return "" + num;
|
||||
}
|
||||
num++;
|
||||
}
|
||||
return "";
|
||||
}
|
||||
}.withDescription("Get user top voter position"));
|
||||
|
||||
placeholders.add(new PlaceHolder<VotingPluginUser>("Top_AllVotes_") {
|
||||
|
||||
@Override
|
||||
public String placeholderRequest(OfflinePlayer p, VotingPluginUser user, String identifier) {
|
||||
int num = 1;
|
||||
int number = Integer.parseInt(identifier.split("_")[2]);
|
||||
for (Entry<VotingPluginUser, Integer> entry : plugin.getTopVoter(TopVoter.AllTime).entrySet()) {
|
||||
if (num == number) {
|
||||
return "" + entry.getKey().getTotal(TopVoter.AllTime);
|
||||
}
|
||||
num++;
|
||||
}
|
||||
return "";
|
||||
}
|
||||
}.useStartsWith().withDescription("Get user votes at position in top voter"));
|
||||
|
||||
placeholders.add(new PlaceHolder<VotingPluginUser>("Top_All_") {
|
||||
|
||||
@Override
|
||||
public String placeholderRequest(OfflinePlayer p, VotingPluginUser user, String identifier) {
|
||||
int num = 1;
|
||||
int number = Integer.parseInt(identifier.split("_")[2]);
|
||||
for (Entry<VotingPluginUser, Integer> entry : plugin.getTopVoter(TopVoter.AllTime).entrySet()) {
|
||||
if (num == number) {
|
||||
return entry.getKey().getPlayerName();
|
||||
}
|
||||
num++;
|
||||
}
|
||||
return "";
|
||||
}
|
||||
}.useStartsWith().withDescription("Get user at postion in top voter"));
|
||||
|
||||
placeholders.add(new PlaceHolder<VotingPluginUser>("Top_Month_Position") {
|
||||
|
||||
@Override
|
||||
public String placeholderRequest(OfflinePlayer p, VotingPluginUser user, String identifier) {
|
||||
int num = 1;
|
||||
for (Entry<VotingPluginUser, Integer> entry : plugin.getTopVoter(TopVoter.Monthly).entrySet()) {
|
||||
if (entry.getKey().getUUID().equals(p.getUniqueId().toString())) {
|
||||
return "" + num;
|
||||
}
|
||||
num++;
|
||||
}
|
||||
return "";
|
||||
}
|
||||
}.withDescription("Get user top voter position"));
|
||||
|
||||
placeholders.add(new PlaceHolder<VotingPluginUser>("Top_Month_") {
|
||||
|
||||
@Override
|
||||
public String placeholderRequest(OfflinePlayer p, VotingPluginUser user, String identifier) {
|
||||
int num = 1;
|
||||
int number = Integer.parseInt(identifier.split("_")[2]);
|
||||
for (Entry<VotingPluginUser, Integer> entry : plugin.getTopVoter(TopVoter.Monthly).entrySet()) {
|
||||
if (num == number) {
|
||||
return entry.getKey().getPlayerName();
|
||||
}
|
||||
num++;
|
||||
}
|
||||
return "";
|
||||
}
|
||||
}.useStartsWith().withDescription("Get user at position in top voter"));
|
||||
|
||||
placeholders.add(new PlaceHolder<VotingPluginUser>("Top_MonthVotes_") {
|
||||
|
||||
@Override
|
||||
public String placeholderRequest(OfflinePlayer p, VotingPluginUser user, String identifier) {
|
||||
int num = 1;
|
||||
int number = Integer.parseInt(identifier.split("_")[2]);
|
||||
for (Entry<VotingPluginUser, Integer> entry : plugin.getTopVoter(TopVoter.Monthly).entrySet()) {
|
||||
if (num == number) {
|
||||
return "" + entry.getKey().getTotal(TopVoter.Monthly);
|
||||
}
|
||||
num++;
|
||||
}
|
||||
return "";
|
||||
}
|
||||
}.useStartsWith().withDescription("Get user votes at position in top voter"));
|
||||
|
||||
placeholders.add(new PlaceHolder<VotingPluginUser>("Top_Week_Position") {
|
||||
|
||||
@Override
|
||||
public String placeholderRequest(OfflinePlayer p, VotingPluginUser user, String identifier) {
|
||||
int num = 1;
|
||||
for (Entry<VotingPluginUser, Integer> entry : plugin.getTopVoter(TopVoter.Weekly).entrySet()) {
|
||||
if (entry.getKey().getUUID().equals(p.getUniqueId().toString())) {
|
||||
return "" + num;
|
||||
}
|
||||
num++;
|
||||
}
|
||||
return "";
|
||||
}
|
||||
}.withDescription("Get user top voter position"));
|
||||
|
||||
placeholders.add(new PlaceHolder<VotingPluginUser>("Top_Week_") {
|
||||
|
||||
@Override
|
||||
public String placeholderRequest(OfflinePlayer p, VotingPluginUser user, String identifier) {
|
||||
int num = 1;
|
||||
int number = Integer.parseInt(identifier.split("_")[2]);
|
||||
for (Entry<VotingPluginUser, Integer> entry : plugin.getTopVoter(TopVoter.Weekly).entrySet()) {
|
||||
if (num == number) {
|
||||
return entry.getKey().getPlayerName();
|
||||
}
|
||||
num++;
|
||||
}
|
||||
return "";
|
||||
}
|
||||
}.useStartsWith().withDescription("Get user at postion in top voter"));
|
||||
|
||||
placeholders.add(new PlaceHolder<VotingPluginUser>("Top_WeekVotes_") {
|
||||
|
||||
@Override
|
||||
public String placeholderRequest(OfflinePlayer p, VotingPluginUser user, String identifier) {
|
||||
int num = 1;
|
||||
int number = Integer.parseInt(identifier.split("_")[2]);
|
||||
for (Entry<VotingPluginUser, Integer> entry : plugin.getTopVoter(TopVoter.Weekly).entrySet()) {
|
||||
if (num == number) {
|
||||
return "" + entry.getKey().getTotal(TopVoter.Weekly);
|
||||
}
|
||||
num++;
|
||||
}
|
||||
return "";
|
||||
}
|
||||
}.useStartsWith().withDescription("Get user votes at position in top voter"));
|
||||
|
||||
placeholders.add(new PlaceHolder<VotingPluginUser>("Top_Daily_Position") {
|
||||
|
||||
@Override
|
||||
public String placeholderRequest(OfflinePlayer p, VotingPluginUser user, String identifier) {
|
||||
int num = 1;
|
||||
for (Entry<VotingPluginUser, Integer> entry : plugin.getTopVoter(TopVoter.Daily).entrySet()) {
|
||||
if (entry.getKey().getUUID().equals(p.getUniqueId().toString())) {
|
||||
return "" + num;
|
||||
}
|
||||
num++;
|
||||
}
|
||||
return "";
|
||||
}
|
||||
}.withDescription("Get user top voter position"));
|
||||
|
||||
placeholders.add(new PlaceHolder<VotingPluginUser>("Top_Daily_") {
|
||||
|
||||
@Override
|
||||
public String placeholderRequest(OfflinePlayer p, VotingPluginUser user, String identifier) {
|
||||
int num = 1;
|
||||
int number = Integer.parseInt(identifier.split("_")[2]);
|
||||
for (Entry<VotingPluginUser, Integer> entry : plugin.getTopVoter(TopVoter.Daily).entrySet()) {
|
||||
if (num == number) {
|
||||
return entry.getKey().getPlayerName();
|
||||
}
|
||||
num++;
|
||||
}
|
||||
return "";
|
||||
}
|
||||
}.useStartsWith().withDescription("Get user at postion in top voter"));
|
||||
|
||||
placeholders.add(new PlaceHolder<VotingPluginUser>("VotePartyContributedVotes") {
|
||||
|
||||
@Override
|
||||
public String placeholderRequest(OfflinePlayer p, VotingPluginUser user, String identifier) {
|
||||
return "" + user.getVotePartyVotes();
|
||||
}
|
||||
}.useStartsWith().withDescription("See vote party placeholders contributed"));
|
||||
|
||||
placeholders.add(new PlaceHolder<VotingPluginUser>("Top_DailyVotes_") {
|
||||
|
||||
@Override
|
||||
public String placeholderRequest(OfflinePlayer p, VotingPluginUser user, String identifier) {
|
||||
int num = 1;
|
||||
int number = Integer.parseInt(identifier.split("_")[2]);
|
||||
for (Entry<VotingPluginUser, Integer> entry : plugin.getTopVoter(TopVoter.Daily).entrySet()) {
|
||||
if (num == number) {
|
||||
return "" + entry.getKey().getTotal(TopVoter.Daily);
|
||||
}
|
||||
num++;
|
||||
}
|
||||
return "";
|
||||
}
|
||||
}.useStartsWith().withDescription("Get user votes at position in top voter"));
|
||||
|
||||
// non players
|
||||
|
||||
nonPlayerPlaceholders.add(new PlaceHolder<VotingPluginUser>("VotePartyVotesCurrent") {
|
||||
|
||||
@Override
|
||||
public String placeholderRequest(OfflinePlayer p, VotingPluginUser user, String identifier) {
|
||||
return Integer.toString(plugin.getVoteParty().getTotalVotes());
|
||||
}
|
||||
}.withDescription("Current amount of voteparty votes"));
|
||||
|
||||
nonPlayerPlaceholders.add(new PlaceHolder<VotingPluginUser>("VotePartyVotesNeeded") {
|
||||
|
||||
@Override
|
||||
public String placeholderRequest(OfflinePlayer p, VotingPluginUser user, String identifier) {
|
||||
return Integer.toString(plugin.getVoteParty().getNeededVotes());
|
||||
}
|
||||
}.withDescription("Voteparty votes needed"));
|
||||
|
||||
nonPlayerPlaceholders.add(new PlaceHolder<VotingPluginUser>("VotePartyVotesRequired") {
|
||||
|
||||
@Override
|
||||
public String placeholderRequest(OfflinePlayer p, VotingPluginUser user, String identifier) {
|
||||
return Integer.toString(plugin.getVoteParty().getVotesRequired());
|
||||
}
|
||||
}.withDescription("Amount of votes needed for voteparty"));
|
||||
|
||||
nonPlayerPlaceholders.add(new PlaceHolder<VotingPluginUser>("GlobalMonthTotal") {
|
||||
|
||||
@Override
|
||||
public String placeholderRequest(OfflinePlayer p, VotingPluginUser user, String identifier) {
|
||||
int total = 0;
|
||||
for (int num : VotingPluginMain.plugin.getTopVoter(TopVoter.Monthly).values()) {
|
||||
total += num;
|
||||
}
|
||||
return Integer.toString(total);
|
||||
}
|
||||
}.withDescription("Global month total"));
|
||||
|
||||
nonPlayerPlaceholders.add(new PlaceHolder<VotingPluginUser>("GlobalAllTimeTotal") {
|
||||
|
||||
@Override
|
||||
public String placeholderRequest(OfflinePlayer p, VotingPluginUser user, String identifier) {
|
||||
int total = 0;
|
||||
for (int num : VotingPluginMain.plugin.getTopVoter(TopVoter.AllTime).values()) {
|
||||
total += num;
|
||||
}
|
||||
return Integer.toString(total);
|
||||
}
|
||||
}.withDescription("Global alltime total"));
|
||||
|
||||
nonPlayerPlaceholders.add(new PlaceHolder<VotingPluginUser>("GlobalWeeklyTotal") {
|
||||
|
||||
@Override
|
||||
public String placeholderRequest(OfflinePlayer p, VotingPluginUser user, String identifier) {
|
||||
int total = 0;
|
||||
for (int num : VotingPluginMain.plugin.getTopVoter(TopVoter.Weekly).values()) {
|
||||
total += num;
|
||||
}
|
||||
return Integer.toString(total);
|
||||
}
|
||||
}.withDescription("Global weekly total"));
|
||||
|
||||
nonPlayerPlaceholders.add(new PlaceHolder<VotingPluginUser>("GlobalDailyTotal") {
|
||||
|
||||
@Override
|
||||
public String placeholderRequest(OfflinePlayer p, VotingPluginUser user, String identifier) {
|
||||
int total = 0;
|
||||
for (int num : VotingPluginMain.plugin.getTopVoter(TopVoter.Daily).values()) {
|
||||
total += num;
|
||||
}
|
||||
return Integer.toString(total);
|
||||
}
|
||||
}.withDescription("Global daily total"));
|
||||
}
|
||||
}
|
||||
+40
-42
@@ -1,4 +1,4 @@
|
||||
package com.Ben12345rocks.VotingPlugin.Signs;
|
||||
package com.bencodez.votingplugin.signs;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
@@ -11,14 +11,12 @@ import org.bukkit.block.Sign;
|
||||
import org.bukkit.block.Skull;
|
||||
import org.bukkit.block.data.Directional;
|
||||
|
||||
import com.Ben12345rocks.AdvancedCore.NMSManager.NMSManager;
|
||||
import com.Ben12345rocks.AdvancedCore.Util.Misc.ArrayUtils;
|
||||
import com.Ben12345rocks.AdvancedCore.Util.Misc.MiscUtils;
|
||||
import com.Ben12345rocks.VotingPlugin.Main;
|
||||
import com.Ben12345rocks.VotingPlugin.Config.Config;
|
||||
import com.Ben12345rocks.VotingPlugin.Data.ServerData;
|
||||
import com.Ben12345rocks.VotingPlugin.Objects.User;
|
||||
import com.Ben12345rocks.VotingPlugin.TopVoter.TopVoter;
|
||||
import com.bencodez.advancedcore.api.misc.ArrayUtils;
|
||||
import com.bencodez.advancedcore.api.misc.MiscUtils;
|
||||
import com.bencodez.advancedcore.nms.NMSManager;
|
||||
import com.bencodez.votingplugin.VotingPluginMain;
|
||||
import com.bencodez.votingplugin.topvoter.TopVoter;
|
||||
import com.bencodez.votingplugin.user.VotingPluginUser;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
@@ -31,40 +29,42 @@ public class SignHandler {
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
private String sign;
|
||||
private String data;
|
||||
|
||||
/** The lines. */
|
||||
private ArrayList<String> lines;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
private Location location;
|
||||
|
||||
/** The player name. */
|
||||
private String playerName;
|
||||
|
||||
/** The plugin. */
|
||||
private VotingPluginMain plugin;
|
||||
|
||||
/** The position. */
|
||||
private int position;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
private String sign;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
private Location skullLocation;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
private String data;
|
||||
|
||||
/** The lines. */
|
||||
private ArrayList<String> lines;
|
||||
|
||||
/** The position. */
|
||||
private int position;
|
||||
|
||||
/** The plugin. */
|
||||
public Main plugin = Main.plugin;
|
||||
|
||||
/** The player name. */
|
||||
private String playerName;
|
||||
private boolean valid;
|
||||
|
||||
/** The votes. */
|
||||
private int votes;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
private boolean valid;
|
||||
|
||||
public SignHandler(String sign, Location location, Location skullLocation, String data, int position) {
|
||||
public SignHandler(VotingPluginMain plugin, String sign, Location location, Location skullLocation, String data,
|
||||
int position) {
|
||||
this.plugin = plugin;
|
||||
setSign(sign);
|
||||
setLocation(location);
|
||||
setSkullLocation(skullLocation);
|
||||
@@ -129,7 +129,7 @@ public class SignHandler {
|
||||
* @return the right click message
|
||||
*/
|
||||
public String getRightClickMessage() {
|
||||
String msg = Config.getInstance().getFormatSignTopVoterSignRightClickMessage();
|
||||
String msg = plugin.getConfigFile().getFormatSignTopVoterSignRightClickMessage();
|
||||
msg = msg.replace("%player%", playerName);
|
||||
msg = msg.replace("%position%", "" + position);
|
||||
msg = msg.replace("%votes%", "" + votes);
|
||||
@@ -140,8 +140,7 @@ public class SignHandler {
|
||||
/**
|
||||
* Checks if is location same.
|
||||
*
|
||||
* @param loc
|
||||
* the loc
|
||||
* @param loc the loc
|
||||
* @return true, if is location same
|
||||
*/
|
||||
public boolean isLocationSame(Location loc) {
|
||||
@@ -156,14 +155,14 @@ public class SignHandler {
|
||||
* Removes the sign.
|
||||
*/
|
||||
public void removeSign() {
|
||||
ServerData.getInstance().removeSign(sign);
|
||||
plugin.getServerData().removeSign(sign);
|
||||
}
|
||||
|
||||
/**
|
||||
* Store sign.
|
||||
*/
|
||||
public void storeSign() {
|
||||
ServerData.getInstance().setSign(sign, location, skullLocation, data, position);
|
||||
plugin.getServerData().setSign(sign, location, skullLocation, data, position);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -173,16 +172,16 @@ public class SignHandler {
|
||||
lines = new ArrayList<String>();
|
||||
checkValidSign();
|
||||
if (position != 0) {
|
||||
String line1 = Config.getInstance().getFormatSignTopVoterSignLine1();
|
||||
String line2 = Config.getInstance().getFormatSignTopVoterSignLine2();
|
||||
String line3 = Config.getInstance().getFormatSignTopVoterSignLine3();
|
||||
String line4 = Config.getInstance().getFormatSignTopVoterSignLine4();
|
||||
String line1 = plugin.getConfigFile().getFormatSignTopVoterSignLine1();
|
||||
String line2 = plugin.getConfigFile().getFormatSignTopVoterSignLine2();
|
||||
String line3 = plugin.getConfigFile().getFormatSignTopVoterSignLine3();
|
||||
String line4 = plugin.getConfigFile().getFormatSignTopVoterSignLine4();
|
||||
lines.add(line1);
|
||||
lines.add(line2);
|
||||
lines.add(line3);
|
||||
lines.add(line4);
|
||||
|
||||
ArrayList<User> users = null;
|
||||
ArrayList<VotingPluginUser> users = null;
|
||||
if (data.equalsIgnoreCase("all")) {
|
||||
users = plugin.convertSet(plugin.getTopVoter(TopVoter.AllTime).keySet());
|
||||
} else if (data.equalsIgnoreCase("monthly")) {
|
||||
@@ -194,7 +193,7 @@ public class SignHandler {
|
||||
}
|
||||
|
||||
if (users != null && users.size() >= position) {
|
||||
User user = users.get(position - 1);
|
||||
VotingPluginUser user = users.get(position - 1);
|
||||
playerName = user.getPlayerName();
|
||||
|
||||
votes = 0;
|
||||
@@ -232,8 +231,7 @@ public class SignHandler {
|
||||
/**
|
||||
* Update sign.
|
||||
*
|
||||
* @param delay
|
||||
* the delay
|
||||
* @param delay the delay
|
||||
*/
|
||||
public void updateSign(int delay) {
|
||||
Bukkit.getScheduler().runTaskLater(plugin, new Runnable() {
|
||||
@@ -253,7 +251,7 @@ public class SignHandler {
|
||||
}
|
||||
|
||||
} catch (Exception ex) {
|
||||
Main.plugin.debug(ex);
|
||||
VotingPluginMain.plugin.debug(ex);
|
||||
}
|
||||
}
|
||||
}, delay);
|
||||
@@ -0,0 +1,87 @@
|
||||
package com.bencodez.votingplugin.signs;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import org.bukkit.Location;
|
||||
|
||||
import com.bencodez.votingplugin.VotingPluginMain;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
// TODO: Auto-generated Javadoc
|
||||
/**
|
||||
* The Class Signs.
|
||||
*/
|
||||
public class Signs {
|
||||
private VotingPluginMain plugin;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
private ArrayList<SignHandler> signs;
|
||||
|
||||
public Signs(VotingPluginMain plugin) {
|
||||
this.plugin = plugin;
|
||||
this.signs = new ArrayList<SignHandler>();
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the sign from location.
|
||||
*
|
||||
* @param loc the loc
|
||||
* @return the sign from location
|
||||
*/
|
||||
public String getSignFromLocation(Location loc) {
|
||||
for (String sign : plugin.getServerData().getSigns()) {
|
||||
if (plugin.getServerData().getSignLocation(sign).equals(loc)) {
|
||||
return sign;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Load signs.
|
||||
*/
|
||||
public void loadSigns() {
|
||||
setSigns(new ArrayList<SignHandler>());
|
||||
for (String sign : plugin.getServerData().getSigns()) {
|
||||
// plugin.getLogger().info("Loading sign " + sign);
|
||||
getSigns().add(new SignHandler(plugin, sign, plugin.getServerData().getSignLocation(sign),
|
||||
plugin.getServerData().getSignSkullLocation(sign), plugin.getServerData().getSignData(sign),
|
||||
plugin.getServerData().getSignPosition(sign)));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Store signs.
|
||||
*/
|
||||
public void storeSigns() {
|
||||
for (SignHandler sign : getSigns()) {
|
||||
sign.storeSign();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Update signs.
|
||||
*/
|
||||
public void updateSigns() {
|
||||
int time = 0;
|
||||
for (int i = getSigns().size() - 1; i >= 0; i--) {
|
||||
if (!getSigns().get(i).isValid()) {
|
||||
plugin.debug(
|
||||
"Sign " + i + " invalid, removing from data: " + getSigns().get(i).getLocation().toString());
|
||||
getSigns().get(i).removeSign();
|
||||
getSigns().remove(i);
|
||||
} else {
|
||||
getSigns().get(i).updateLines();
|
||||
getSigns().get(i).updateSign(time);
|
||||
time += 5;
|
||||
}
|
||||
}
|
||||
|
||||
plugin.debug("Signs updated");
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,330 @@
|
||||
package com.bencodez.votingplugin.specialrewards;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Set;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
|
||||
import com.bencodez.advancedcore.api.messages.StringParser;
|
||||
import com.bencodez.advancedcore.api.rewards.RewardBuilder;
|
||||
import com.bencodez.advancedcore.api.rewards.RewardHandler;
|
||||
import com.bencodez.advancedcore.api.rewards.RewardOptions;
|
||||
import com.bencodez.votingplugin.VotingPluginMain;
|
||||
import com.bencodez.votingplugin.events.PlayerSpecialRewardEvent;
|
||||
import com.bencodez.votingplugin.events.SpecialRewardType;
|
||||
import com.bencodez.votingplugin.topvoter.TopVoter;
|
||||
import com.bencodez.votingplugin.user.VotingPluginUser;
|
||||
|
||||
// TODO: Auto-generated Javadoc
|
||||
/**
|
||||
* The Class OtherVoteReward.
|
||||
*/
|
||||
public class SpecialRewards {
|
||||
|
||||
private VotingPluginMain plugin;
|
||||
|
||||
public SpecialRewards(VotingPluginMain plugin) {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check all sites.
|
||||
*
|
||||
* @param user the user
|
||||
* @return true, if successful
|
||||
*/
|
||||
public boolean checkAllSites(VotingPluginUser user) {
|
||||
boolean checkAllVotes = user.checkAllVotes();
|
||||
if (checkAllVotes) {
|
||||
giveAllSitesRewards(user, user.isOnline());
|
||||
}
|
||||
return checkAllVotes;
|
||||
}
|
||||
|
||||
public boolean checkCumualativeVotes(VotingPluginUser user, String bungeeTextTotals) {
|
||||
boolean gotCumulativeAny = false;
|
||||
Set<String> votes = plugin.getSpecialRewardsConfig().getCumulativeVotes();
|
||||
for (String vote : votes) {
|
||||
if (StringParser.getInstance().isInt(vote)) {
|
||||
int votesRequired = Integer.parseInt(vote);
|
||||
if (votesRequired != 0) {
|
||||
if (plugin.getSpecialRewardsConfig().getCumulativeRewardEnabled(votesRequired)
|
||||
&& RewardHandler.getInstance().hasRewards(plugin.getSpecialRewardsConfig().getData(),
|
||||
plugin.getSpecialRewardsConfig().getCumulativeRewardsPath(votesRequired))) {
|
||||
boolean gotCumulative = false;
|
||||
int total = 0;
|
||||
boolean useBungeeTotalNum = false;
|
||||
String[] data = new String[] { "0", "0", "0", "0" };
|
||||
if (bungeeTextTotals != null) {
|
||||
data = bungeeTextTotals.split("//");
|
||||
useBungeeTotalNum = true;
|
||||
}
|
||||
if (plugin.getSpecialRewardsConfig().getCumulativeVotesInSameDay(votesRequired)) {
|
||||
if (!useBungeeTotalNum) {
|
||||
total = user.getTotal(TopVoter.Daily);
|
||||
} else {
|
||||
total = Integer.parseInt(data[3]);
|
||||
}
|
||||
} else if (plugin.getSpecialRewardsConfig().getCumulativeVotesInSameWeek(votesRequired)) {
|
||||
if (!useBungeeTotalNum) {
|
||||
total = user.getTotal(TopVoter.Weekly);
|
||||
} else {
|
||||
total = Integer.parseInt(data[2]);
|
||||
}
|
||||
} else if (plugin.getSpecialRewardsConfig().getCumulativeVotesInSameMonth(votesRequired)) {
|
||||
if (!useBungeeTotalNum) {
|
||||
total = user.getTotal(TopVoter.Monthly);
|
||||
} else {
|
||||
total = Integer.parseInt(data[1]);
|
||||
}
|
||||
} else {
|
||||
if (!useBungeeTotalNum) {
|
||||
total = user.getTotal(TopVoter.AllTime);
|
||||
} else {
|
||||
total = Integer.parseInt(data[0]);
|
||||
}
|
||||
}
|
||||
|
||||
if (total != 0 && total >= votesRequired) {
|
||||
if ((total % votesRequired) == 0) {
|
||||
gotCumulative = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (gotCumulative) {
|
||||
gotCumulativeAny = true;
|
||||
giveCumulativeVoteReward(user, user.isOnline(), votesRequired);
|
||||
plugin.debug(user.getPlayerName() + " got cumulative " + votesRequired);
|
||||
} else {
|
||||
plugin.devDebug(user.getPlayerName() + " not able to get cumulative " + votesRequired);
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
plugin.debug("Invalid cumulative number: " + vote);
|
||||
}
|
||||
}
|
||||
return gotCumulativeAny;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check first vote.
|
||||
*
|
||||
* @param user the user
|
||||
* @return true, if successful
|
||||
*/
|
||||
public boolean checkFirstVote(VotingPluginUser user) {
|
||||
if (RewardHandler.getInstance().hasRewards(plugin.getSpecialRewardsConfig().getData(),
|
||||
plugin.getSpecialRewardsConfig().getFirstVoteRewardsPath())) {
|
||||
if (!user.hasGottenFirstVote()) {
|
||||
giveFirstVoteRewards(user, user.isOnline());
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean checkMilestone(VotingPluginUser user, String bungeeTextTotals) {
|
||||
int milestoneCount = user.getMilestoneCount();
|
||||
if (bungeeTextTotals != null) {
|
||||
String[] data = bungeeTextTotals.split("//");
|
||||
if (data.length > 4) {
|
||||
try {
|
||||
milestoneCount = Integer.parseInt(data[5]);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
milestoneCount = user.getMilestoneCount();
|
||||
}
|
||||
}
|
||||
}
|
||||
if (plugin.getConfigFile().isPreventRepeatMilestones()) {
|
||||
ArrayList<Integer> nums = new ArrayList<Integer>();
|
||||
|
||||
for (String str : plugin.getSpecialRewardsConfig().getMilestoneVotes()) {
|
||||
try {
|
||||
nums.add(Integer.parseInt(str));
|
||||
} catch (Exception e) {
|
||||
plugin.getLogger().warning("Failed to get number from " + str);
|
||||
}
|
||||
}
|
||||
|
||||
for (int num : nums) {
|
||||
if (milestoneCount > num) {
|
||||
if (!user.hasGottenMilestone(num)) {
|
||||
plugin.getLogger()
|
||||
.info("Milestone " + num + " for " + user.getPlayerName()
|
||||
+ " not already given when it should be, Current AllTimeTotal: "
|
||||
+ user.getTotal(TopVoter.AllTime) + ", Current MileStoneCount: "
|
||||
+ user.getMilestoneCount());
|
||||
user.setHasGotteMilestone(num, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
boolean gotMilestone = false;
|
||||
Set<String> votes = plugin.getSpecialRewardsConfig().getMilestoneVotes();
|
||||
for (String vote : votes) {
|
||||
if (StringParser.getInstance().isInt(vote)) {
|
||||
int votesRequired = Integer.parseInt(vote);
|
||||
if (votesRequired != 0) {
|
||||
if (plugin.getSpecialRewardsConfig().getMilestoneRewardEnabled(votesRequired)
|
||||
&& RewardHandler.getInstance().hasRewards(plugin.getSpecialRewardsConfig().getData(),
|
||||
plugin.getSpecialRewardsConfig().getMilestoneRewardsPath(votesRequired))) {
|
||||
|
||||
int userVotesTotal = milestoneCount;
|
||||
if (userVotesTotal >= votesRequired && !user.hasGottenMilestone(votesRequired)) {
|
||||
giveMilestoneVoteReward(user, user.isOnline(), votesRequired);
|
||||
user.setHasGotteMilestone(votesRequired, true);
|
||||
plugin.debug(user.getPlayerName() + " got milestone " + votesRequired);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
plugin.debug("Invalid milestone number: " + vote);
|
||||
}
|
||||
}
|
||||
return gotMilestone;
|
||||
}
|
||||
|
||||
public boolean checkVoteStreak(VotingPluginUser user, String type) {
|
||||
boolean gotReward = false;
|
||||
|
||||
Set<String> streaks = plugin.getSpecialRewardsConfig().getVoteStreakVotes(type);
|
||||
for (String streak : streaks) {
|
||||
String s = streak.replaceAll("-", "");
|
||||
boolean multiple = false;
|
||||
if (streak.contains("-")) {
|
||||
// multiple
|
||||
multiple = true;
|
||||
}
|
||||
if (StringParser.getInstance().isInt(s)) {
|
||||
int streakRequired = Integer.parseInt(s);
|
||||
if (streakRequired != 0) {
|
||||
if (plugin.getSpecialRewardsConfig().getVoteStreakRewardEnabled(type, streak)
|
||||
&& RewardHandler.getInstance().hasRewards(plugin.getSpecialRewardsConfig().getData(),
|
||||
plugin.getSpecialRewardsConfig().getVoteStreakRewardsPath(type, "" + streak))) {
|
||||
int curStreak = 0;
|
||||
if (type.equalsIgnoreCase("day")) {
|
||||
curStreak = user.getDayVoteStreak();
|
||||
} else if (type.equalsIgnoreCase("week")) {
|
||||
curStreak = user.getWeekVoteStreak();
|
||||
} else if (type.equalsIgnoreCase("month")) {
|
||||
curStreak = user.getMonthVoteStreak();
|
||||
}
|
||||
if (!multiple) {
|
||||
if (curStreak == streakRequired) {
|
||||
giveVoteStreakReward(user, user.isOnline(), type, "" + streakRequired, curStreak);
|
||||
gotReward = true;
|
||||
plugin.debug(
|
||||
user.getPlayerName() + " got VoteStreak " + streakRequired + " for " + type);
|
||||
}
|
||||
} else {
|
||||
if (curStreak != 0 && curStreak % streakRequired == 0) {
|
||||
giveVoteStreakReward(user, user.isOnline(), type, streakRequired + "-", curStreak);
|
||||
gotReward = true;
|
||||
plugin.debug(
|
||||
user.getPlayerName() + " got VoteStreak " + streakRequired + "* for " + type);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return gotReward;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Give all sites rewards.
|
||||
*
|
||||
* @param user the user
|
||||
* @param online the online
|
||||
*/
|
||||
public void giveAllSitesRewards(VotingPluginUser user, boolean online) {
|
||||
PlayerSpecialRewardEvent event = new PlayerSpecialRewardEvent(user, SpecialRewardType.ALLSITE);
|
||||
Bukkit.getPluginManager().callEvent(event);
|
||||
|
||||
if (event.isCancelled()) {
|
||||
return;
|
||||
}
|
||||
RewardHandler.getInstance().giveReward(user, plugin.getSpecialRewardsConfig().getData(),
|
||||
plugin.getSpecialRewardsConfig().getAllSitesRewardPath(), new RewardOptions().setOnline(online));
|
||||
}
|
||||
|
||||
/**
|
||||
* Give cumulative vote reward.
|
||||
*
|
||||
* @param user the user
|
||||
* @param online the online
|
||||
* @param cumulative the cumulative
|
||||
*/
|
||||
public void giveCumulativeVoteReward(VotingPluginUser user, boolean online, int cumulative) {
|
||||
PlayerSpecialRewardEvent event = new PlayerSpecialRewardEvent(user,
|
||||
SpecialRewardType.CUMMULATIVE.setAmount(cumulative));
|
||||
Bukkit.getPluginManager().callEvent(event);
|
||||
|
||||
if (event.isCancelled()) {
|
||||
return;
|
||||
}
|
||||
|
||||
new RewardBuilder(plugin.getSpecialRewardsConfig().getData(),
|
||||
plugin.getSpecialRewardsConfig().getCumulativeRewardsPath(cumulative)).setOnline(online)
|
||||
.withPlaceHolder("Cumulative", "" + cumulative).send(user);
|
||||
}
|
||||
|
||||
/**
|
||||
* Give first vote rewards.
|
||||
*
|
||||
* @param user the user
|
||||
* @param online the online
|
||||
*/
|
||||
public void giveFirstVoteRewards(VotingPluginUser user, boolean online) {
|
||||
PlayerSpecialRewardEvent event = new PlayerSpecialRewardEvent(user, SpecialRewardType.FIRSTVOTE);
|
||||
Bukkit.getPluginManager().callEvent(event);
|
||||
|
||||
if (event.isCancelled()) {
|
||||
return;
|
||||
}
|
||||
RewardHandler.getInstance().giveReward(user, plugin.getSpecialRewardsConfig().getData(),
|
||||
plugin.getSpecialRewardsConfig().getFirstVoteRewardsPath(), new RewardOptions().setOnline(online));
|
||||
}
|
||||
|
||||
/**
|
||||
* Give milestone vote reward.
|
||||
*
|
||||
* @param user the user
|
||||
* @param online the online
|
||||
* @param milestone the milestone
|
||||
*/
|
||||
public void giveMilestoneVoteReward(VotingPluginUser user, boolean online, int milestone) {
|
||||
PlayerSpecialRewardEvent event = new PlayerSpecialRewardEvent(user,
|
||||
SpecialRewardType.MILESTONE.setAmount(milestone));
|
||||
Bukkit.getPluginManager().callEvent(event);
|
||||
|
||||
if (event.isCancelled()) {
|
||||
return;
|
||||
}
|
||||
new RewardBuilder(plugin.getSpecialRewardsConfig().getData(),
|
||||
plugin.getSpecialRewardsConfig().getMilestoneRewardsPath(milestone)).setOnline(online)
|
||||
.withPlaceHolder("Milestone", "" + milestone).send(user);
|
||||
}
|
||||
|
||||
public void giveVoteStreakReward(VotingPluginUser user, boolean online, String type, String string, int votes) {
|
||||
PlayerSpecialRewardEvent event = new PlayerSpecialRewardEvent(user,
|
||||
SpecialRewardType.VOTESTREAK.setType(type).setAmount(votes));
|
||||
Bukkit.getPluginManager().callEvent(event);
|
||||
|
||||
if (event.isCancelled()) {
|
||||
return;
|
||||
}
|
||||
new RewardBuilder(plugin.getSpecialRewardsConfig().getData(),
|
||||
plugin.getSpecialRewardsConfig().getVoteStreakRewardsPath(type, string)).setOnline(online)
|
||||
.withPlaceHolder("Type", type).withPlaceHolder("Streak", "" + votes).send(user);
|
||||
}
|
||||
|
||||
}
|
||||
+17
-16
@@ -1,14 +1,14 @@
|
||||
package com.Ben12345rocks.VotingPlugin.Test;
|
||||
package com.bencodez.votingplugin.test;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import com.Ben12345rocks.AdvancedCore.Rewards.Reward;
|
||||
import com.Ben12345rocks.AdvancedCore.Rewards.RewardHandler;
|
||||
import com.Ben12345rocks.AdvancedCore.Rewards.RewardOptions;
|
||||
import com.Ben12345rocks.VotingPlugin.Main;
|
||||
import com.Ben12345rocks.VotingPlugin.Events.PlayerVoteEvent;
|
||||
import com.Ben12345rocks.VotingPlugin.Objects.User;
|
||||
import com.Ben12345rocks.VotingPlugin.UserManager.UserManager;
|
||||
import com.bencodez.advancedcore.api.rewards.Reward;
|
||||
import com.bencodez.advancedcore.api.rewards.RewardHandler;
|
||||
import com.bencodez.advancedcore.api.rewards.RewardOptions;
|
||||
import com.bencodez.votingplugin.VotingPluginMain;
|
||||
import com.bencodez.votingplugin.events.PlayerVoteEvent;
|
||||
import com.bencodez.votingplugin.user.UserManager;
|
||||
import com.bencodez.votingplugin.user.VotingPluginUser;
|
||||
|
||||
public class VoteTester {
|
||||
|
||||
@@ -18,12 +18,12 @@ public class VoteTester {
|
||||
return instance;
|
||||
}
|
||||
|
||||
private Main plugin = Main.plugin;
|
||||
private VotingPluginMain plugin = VotingPluginMain.plugin;
|
||||
|
||||
public void testRewards(int amount, String name, String rewardName) {
|
||||
long time1 = System.currentTimeMillis();
|
||||
ArrayList<Long> timesPerReward = new ArrayList<Long>();
|
||||
User user = UserManager.getInstance().getVotingPluginUser(name);
|
||||
VotingPluginUser user = UserManager.getInstance().getVotingPluginUser(name);
|
||||
Reward reward = RewardHandler.getInstance().getReward(rewardName);
|
||||
int rewardsGiven = 0;
|
||||
for (int i = 0; i < amount; i++) {
|
||||
@@ -42,9 +42,9 @@ public class VoteTester {
|
||||
timeTotal += t.longValue();
|
||||
}
|
||||
long timePerRewardAvg = timeTotal / timesPerReward.size();
|
||||
Main.plugin.getLogger().info("Time to process rewards (" + amount + "): " + time + " ms, average per reward "
|
||||
+ timePerRewardAvg + " ms. " + Main.plugin.getStorageType() + ", "
|
||||
+ UserManager.getInstance().getAllUUIDs().size() + " users. " + rewardsGiven + " rewards given");
|
||||
VotingPluginMain.plugin.getLogger().info("Time to process rewards (" + amount + "): " + time
|
||||
+ " ms, average per reward " + timePerRewardAvg + " ms. " + VotingPluginMain.plugin.getStorageType()
|
||||
+ ", " + UserManager.getInstance().getAllUUIDs().size() + " users. " + rewardsGiven + " rewards given");
|
||||
}
|
||||
|
||||
public void testVotes(int amount, String name, String site) {
|
||||
@@ -65,10 +65,11 @@ public class VoteTester {
|
||||
timeTotal += t.longValue();
|
||||
}
|
||||
long timePerVoteAvg = timeTotal / timesPerVote.size();
|
||||
Main.plugin.getLogger()
|
||||
VotingPluginMain.plugin.getLogger()
|
||||
.info("Time to process votes (" + amount + "): " + time + " ms, average per vote " + timePerVoteAvg
|
||||
+ " ms. " + Main.plugin.getStorageType() + ", " + UserManager.getInstance().getAllUUIDs().size()
|
||||
+ " users. " + Main.plugin.getVoteSites().size() + " votesites");
|
||||
+ " ms. " + VotingPluginMain.plugin.getStorageType() + ", "
|
||||
+ UserManager.getInstance().getAllUUIDs().size() + " users. "
|
||||
+ VotingPluginMain.plugin.getVoteSites().size() + " votesites");
|
||||
}
|
||||
|
||||
}
|
||||
+20
-20
@@ -1,24 +1,20 @@
|
||||
package com.Ben12345rocks.VotingPlugin.TopVoter;
|
||||
package com.bencodez.votingplugin.topvoter;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import com.Ben12345rocks.VotingPlugin.Config.Config;
|
||||
import com.bencodez.votingplugin.VotingPluginMain;
|
||||
|
||||
public enum TopVoter {
|
||||
AllTime, Monthly, Weekly, Daily;
|
||||
AllTime, Daily, Monthly, Weekly;
|
||||
|
||||
public static TopVoter getDefault() {
|
||||
TopVoter top = getTopVoter(Config.getInstance().getVoteTopDefault());
|
||||
TopVoter top = getTopVoter(VotingPluginMain.plugin.getConfigFile().getVoteTopDefault());
|
||||
if (top != null) {
|
||||
return top;
|
||||
}
|
||||
return AllTime;
|
||||
}
|
||||
|
||||
public static TopVoter[] valuesMinusAllTime() {
|
||||
return new TopVoter[] { TopVoter.Daily, TopVoter.Weekly, TopVoter.Monthly };
|
||||
}
|
||||
|
||||
public static TopVoter getTopVoter(String str) {
|
||||
for (TopVoter value : values()) {
|
||||
if (value.toString().equalsIgnoreCase(str)) {
|
||||
@@ -28,30 +24,34 @@ public enum TopVoter {
|
||||
return AllTime;
|
||||
}
|
||||
|
||||
public static TopVoter[] valuesMinusAllTime() {
|
||||
return new TopVoter[] { TopVoter.Daily, TopVoter.Weekly, TopVoter.Monthly };
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
if (this.equals(TopVoter.Monthly)) {
|
||||
return Config.getInstance().getFormatTopVoterMonthly();
|
||||
return VotingPluginMain.plugin.getConfigFile().getFormatTopVoterMonthly();
|
||||
} else if (this.equals(TopVoter.Weekly)) {
|
||||
return Config.getInstance().getFormatTopVoterWeekly();
|
||||
return VotingPluginMain.plugin.getConfigFile().getFormatTopVoterWeekly();
|
||||
} else if (this.equals(TopVoter.Daily)) {
|
||||
return Config.getInstance().getFormatTopVoterDaily();
|
||||
return VotingPluginMain.plugin.getConfigFile().getFormatTopVoterDaily();
|
||||
} else {
|
||||
return Config.getInstance().getFormatTopVoterAllTime();
|
||||
return VotingPluginMain.plugin.getConfigFile().getFormatTopVoterAllTime();
|
||||
}
|
||||
}
|
||||
|
||||
public TopVoter next() {
|
||||
ArrayList<TopVoter> list = new ArrayList<TopVoter>();
|
||||
if (Config.getInstance().getLoadTopVoterAllTime()) {
|
||||
if (VotingPluginMain.plugin.getConfigFile().getLoadTopVoterAllTime()) {
|
||||
list.add(TopVoter.AllTime);
|
||||
}
|
||||
if (Config.getInstance().getLoadTopVoterMonthly()) {
|
||||
if (VotingPluginMain.plugin.getConfigFile().getLoadTopVoterMonthly()) {
|
||||
list.add(TopVoter.Monthly);
|
||||
}
|
||||
if (Config.getInstance().getLoadTopVoterWeekly()) {
|
||||
if (VotingPluginMain.plugin.getConfigFile().getLoadTopVoterWeekly()) {
|
||||
list.add(TopVoter.Weekly);
|
||||
}
|
||||
if (Config.getInstance().getLoadTopVoterDaily()) {
|
||||
if (VotingPluginMain.plugin.getConfigFile().getLoadTopVoterDaily()) {
|
||||
list.add(TopVoter.Daily);
|
||||
}
|
||||
for (int i = 0; i < list.size(); i++) {
|
||||
@@ -68,16 +68,16 @@ public enum TopVoter {
|
||||
|
||||
public TopVoter prev() {
|
||||
ArrayList<TopVoter> list = new ArrayList<TopVoter>();
|
||||
if (Config.getInstance().getLoadTopVoterAllTime()) {
|
||||
if (VotingPluginMain.plugin.getConfigFile().getLoadTopVoterAllTime()) {
|
||||
list.add(TopVoter.AllTime);
|
||||
}
|
||||
if (Config.getInstance().getLoadTopVoterMonthly()) {
|
||||
if (VotingPluginMain.plugin.getConfigFile().getLoadTopVoterMonthly()) {
|
||||
list.add(TopVoter.Monthly);
|
||||
}
|
||||
if (Config.getInstance().getLoadTopVoterWeekly()) {
|
||||
if (VotingPluginMain.plugin.getConfigFile().getLoadTopVoterWeekly()) {
|
||||
list.add(TopVoter.Weekly);
|
||||
}
|
||||
if (Config.getInstance().getLoadTopVoterDaily()) {
|
||||
if (VotingPluginMain.plugin.getConfigFile().getLoadTopVoterDaily()) {
|
||||
list.add(TopVoter.Daily);
|
||||
}
|
||||
for (int i = list.size() - 1; i >= 0; i--) {
|
||||
+111
-131
@@ -1,4 +1,4 @@
|
||||
package com.Ben12345rocks.VotingPlugin.TopVoter;
|
||||
package com.bencodez.votingplugin.topvoter;
|
||||
|
||||
import java.io.File;
|
||||
import java.time.LocalDateTime;
|
||||
@@ -16,46 +16,29 @@ import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
|
||||
import com.Ben12345rocks.AdvancedCore.TimeChecker.Events.DateChangedEvent;
|
||||
import com.Ben12345rocks.AdvancedCore.TimeChecker.Events.DayChangeEvent;
|
||||
import com.Ben12345rocks.AdvancedCore.TimeChecker.Events.MonthChangeEvent;
|
||||
import com.Ben12345rocks.AdvancedCore.TimeChecker.Events.PreDateChangedEvent;
|
||||
import com.Ben12345rocks.AdvancedCore.TimeChecker.Events.WeekChangeEvent;
|
||||
import com.Ben12345rocks.AdvancedCore.UserManager.UUID;
|
||||
import com.Ben12345rocks.AdvancedCore.Util.Messages.StringParser;
|
||||
import com.Ben12345rocks.AdvancedCore.Util.Misc.ArrayUtils;
|
||||
import com.Ben12345rocks.AdvancedCore.YML.YMLFileHandler;
|
||||
import com.Ben12345rocks.VotingPlugin.Main;
|
||||
import com.Ben12345rocks.VotingPlugin.Config.Config;
|
||||
import com.Ben12345rocks.VotingPlugin.Config.SpecialRewardsConfig;
|
||||
import com.Ben12345rocks.VotingPlugin.Objects.User;
|
||||
import com.Ben12345rocks.VotingPlugin.SpecialRewards.SpecialRewards;
|
||||
import com.Ben12345rocks.VotingPlugin.UserManager.UserManager;
|
||||
import com.bencodez.advancedcore.api.messages.StringParser;
|
||||
import com.bencodez.advancedcore.api.misc.ArrayUtils;
|
||||
import com.bencodez.advancedcore.api.time.events.DateChangedEvent;
|
||||
import com.bencodez.advancedcore.api.time.events.DayChangeEvent;
|
||||
import com.bencodez.advancedcore.api.time.events.MonthChangeEvent;
|
||||
import com.bencodez.advancedcore.api.time.events.PreDateChangedEvent;
|
||||
import com.bencodez.advancedcore.api.time.events.WeekChangeEvent;
|
||||
import com.bencodez.advancedcore.api.user.UUID;
|
||||
import com.bencodez.advancedcore.api.yml.YMLFileHandler;
|
||||
import com.bencodez.votingplugin.VotingPluginMain;
|
||||
import com.bencodez.votingplugin.user.UserManager;
|
||||
import com.bencodez.votingplugin.user.VotingPluginUser;
|
||||
|
||||
public class TopVoterHandler implements Listener {
|
||||
/** The instance. */
|
||||
static TopVoterHandler instance = new TopVoterHandler();
|
||||
|
||||
/** The plugin. */
|
||||
static Main plugin = Main.plugin;
|
||||
private VotingPluginMain plugin;
|
||||
|
||||
/**
|
||||
* Gets the single instance of TopVoter.
|
||||
*
|
||||
* @return single instance of TopVoter
|
||||
*/
|
||||
public static TopVoterHandler getInstance() {
|
||||
return instance;
|
||||
}
|
||||
|
||||
/**
|
||||
* Instantiates a new top voter.
|
||||
*/
|
||||
private TopVoterHandler() {
|
||||
public TopVoterHandler(VotingPluginMain plugin) {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
public ArrayList<String> getTopVoterBlackList() {
|
||||
return Config.getInstance().getBlackList();
|
||||
return plugin.getConfigFile().getBlackList();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -66,9 +49,9 @@ public class TopVoterHandler implements Listener {
|
||||
|
||||
public String[] getTopVotersWeekly() {
|
||||
ArrayList<String> msg = new ArrayList<String>();
|
||||
ArrayList<User> users = plugin.convertSet(plugin.getTopVoter(TopVoter.Weekly).keySet());
|
||||
ArrayList<VotingPluginUser> users = plugin.convertSet(plugin.getTopVoter(TopVoter.Weekly).keySet());
|
||||
for (int i = 0; i < users.size(); i++) {
|
||||
String line = Config.getInstance().getFormatCommandVoteTopLine().replace("%num%", "" + (i + 1))
|
||||
String line = plugin.getConfigFile().getFormatCommandVoteTopLine().replace("%num%", "" + (i + 1))
|
||||
.replace("%player%", users.get(i).getPlayerName())
|
||||
.replace("%votes%", "" + plugin.getTopVoter(TopVoter.Weekly).get(users.get(i)));
|
||||
msg.add(line);
|
||||
@@ -98,12 +81,12 @@ public class TopVoterHandler implements Listener {
|
||||
}
|
||||
|
||||
public void loadLastMonth() {
|
||||
if (Config.getInstance().isLastMonthGUI()) {
|
||||
if (plugin.getGui().isLastMonthGUI()) {
|
||||
plugin.getLastMonthTopVoter().clear();
|
||||
|
||||
LinkedHashMap<User, Integer> totals = new LinkedHashMap<User, Integer>();
|
||||
LinkedHashMap<VotingPluginUser, Integer> totals = new LinkedHashMap<VotingPluginUser, Integer>();
|
||||
for (String uuid : UserManager.getInstance().getAllUUIDs()) {
|
||||
User user = UserManager.getInstance().getVotingPluginUser(new UUID(uuid));
|
||||
VotingPluginUser user = UserManager.getInstance().getVotingPluginUser(new UUID(uuid));
|
||||
int total = user.getLastMonthTotal();
|
||||
if (total > 0) {
|
||||
totals.put(user, total);
|
||||
@@ -126,9 +109,9 @@ public class TopVoterHandler implements Listener {
|
||||
|
||||
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
|
||||
public void onDayChange(DayChangeEvent event) {
|
||||
synchronized (Main.plugin) {
|
||||
synchronized (VotingPluginMain.plugin) {
|
||||
for (String uuid : UserManager.getInstance().getAllUUIDs()) {
|
||||
User user = UserManager.getInstance().getVotingPluginUser(new UUID(uuid));
|
||||
VotingPluginUser user = UserManager.getInstance().getVotingPluginUser(new UUID(uuid));
|
||||
if (!user.voteStreakUpdatedToday(LocalDateTime.now().minusDays(1))) {
|
||||
if (user.getDayVoteStreak() != 0) {
|
||||
user.setDayVoteStreak(0);
|
||||
@@ -138,30 +121,30 @@ public class TopVoterHandler implements Listener {
|
||||
if (user.getHighestDailyTotal() < user.getTotal(TopVoter.Daily)) {
|
||||
user.setHighestDailyTotal(user.getTotal(TopVoter.Daily));
|
||||
}
|
||||
for (String shopIdent : Config.getInstance().getIdentifiers()) {
|
||||
if (Config.getInstance().getVoteShopResetDaily(shopIdent)) {
|
||||
for (String shopIdent : plugin.getGui().getChestShopIdentifiers()) {
|
||||
if (plugin.getGui().getChestVoteShopResetDaily(shopIdent)) {
|
||||
user.setVoteShopIdentifierLimit(shopIdent, 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (Config.getInstance().getStoreTopVotersDaily()) {
|
||||
if (plugin.getConfigFile().getStoreTopVotersDaily()) {
|
||||
plugin.getLogger().info("Saving TopVoters Daily");
|
||||
storeTopVoters(TopVoter.Daily);
|
||||
}
|
||||
|
||||
try {
|
||||
if (SpecialRewardsConfig.getInstance().isEnableDailyRewards()) {
|
||||
if (plugin.getSpecialRewardsConfig().isEnableDailyRewards()) {
|
||||
HashMap<Integer, String> places = handlePlaces(
|
||||
SpecialRewardsConfig.getInstance().getDailyPossibleRewardPlaces());
|
||||
plugin.getSpecialRewardsConfig().getDailyPossibleRewardPlaces());
|
||||
int i = 0;
|
||||
int lastTotal = -1;
|
||||
@SuppressWarnings("unchecked")
|
||||
LinkedHashMap<User, Integer> clone = (LinkedHashMap<User, Integer>) plugin
|
||||
LinkedHashMap<VotingPluginUser, Integer> clone = (LinkedHashMap<VotingPluginUser, Integer>) plugin
|
||||
.getTopVoter(TopVoter.Daily).clone();
|
||||
for (User user : clone.keySet()) {
|
||||
if (!Config.getInstance().getTopVoterIgnorePermission() || !user.isTopVoterIgnore()) {
|
||||
if (Config.getInstance().getTopVoterAwardsTies()) {
|
||||
for (VotingPluginUser user : clone.keySet()) {
|
||||
if (!plugin.getConfigFile().getTopVoterIgnorePermission() || !user.isTopVoterIgnore()) {
|
||||
if (plugin.getConfigFile().getTopVoterAwardsTies()) {
|
||||
if (user.getTotal(TopVoter.Daily) != lastTotal) {
|
||||
i++;
|
||||
}
|
||||
@@ -185,23 +168,23 @@ public class TopVoterHandler implements Listener {
|
||||
|
||||
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
|
||||
public void onMonthChange(MonthChangeEvent event) {
|
||||
synchronized (Main.plugin) {
|
||||
synchronized (VotingPluginMain.plugin) {
|
||||
for (String uuid : UserManager.getInstance().getAllUUIDs()) {
|
||||
User user = UserManager.getInstance().getVotingPluginUser(new UUID(uuid));
|
||||
VotingPluginUser user = UserManager.getInstance().getVotingPluginUser(new UUID(uuid));
|
||||
if (user.getTotal(TopVoter.Monthly) == 0 && user.getMonthVoteStreak() != 0) {
|
||||
user.setMonthVoteStreak(0);
|
||||
} else {
|
||||
if (!SpecialRewardsConfig.getInstance().isVoteStreakRequirementUsePercentage()
|
||||
if (!plugin.getSpecialRewardsConfig().isVoteStreakRequirementUsePercentage()
|
||||
|| user.hasPercentageTotal(TopVoter.Monthly,
|
||||
SpecialRewardsConfig.getInstance().getVoteStreakRequirementMonth(),
|
||||
plugin.getSpecialRewardsConfig().getVoteStreakRequirementMonth(),
|
||||
LocalDateTime.now().minusDays(1))) {
|
||||
user.addMonthVoteStreak();
|
||||
SpecialRewards.getInstance().checkVoteStreak(user, "Month");
|
||||
plugin.getSpecialRewards().checkVoteStreak(user, "Month");
|
||||
}
|
||||
}
|
||||
|
||||
for (String shopIdent : Config.getInstance().getIdentifiers()) {
|
||||
if (Config.getInstance().getVoteShopResetMonthly(shopIdent)) {
|
||||
for (String shopIdent : plugin.getGui().getChestShopIdentifiers()) {
|
||||
if (plugin.getGui().getChestVoteShopResetMonthly(shopIdent)) {
|
||||
user.setVoteShopIdentifierLimit(shopIdent, 0);
|
||||
}
|
||||
}
|
||||
@@ -213,25 +196,25 @@ public class TopVoterHandler implements Listener {
|
||||
}
|
||||
}
|
||||
|
||||
if (Config.getInstance().getStoreTopVotersMonthly()) {
|
||||
if (plugin.getConfigFile().getStoreTopVotersMonthly()) {
|
||||
plugin.getLogger().info("Saving TopVoters Monthly");
|
||||
storeTopVoters(TopVoter.Monthly);
|
||||
}
|
||||
|
||||
try {
|
||||
if (SpecialRewardsConfig.getInstance().isEnableMonthlyAwards()) {
|
||||
if (plugin.getSpecialRewardsConfig().isEnableMonthlyAwards()) {
|
||||
HashMap<Integer, String> places = handlePlaces(
|
||||
SpecialRewardsConfig.getInstance().getMonthlyPossibleRewardPlaces());
|
||||
plugin.getSpecialRewardsConfig().getMonthlyPossibleRewardPlaces());
|
||||
int i = 0;
|
||||
int lastTotal = -1;
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
LinkedHashMap<User, Integer> clone = (LinkedHashMap<User, Integer>) plugin
|
||||
LinkedHashMap<VotingPluginUser, Integer> clone = (LinkedHashMap<VotingPluginUser, Integer>) plugin
|
||||
.getTopVoter(TopVoter.Monthly).clone();
|
||||
for (User user : clone.keySet()) {
|
||||
for (VotingPluginUser user : clone.keySet()) {
|
||||
|
||||
if (!Config.getInstance().getTopVoterIgnorePermission() || !user.isTopVoterIgnore()) {
|
||||
if (Config.getInstance().getTopVoterAwardsTies()) {
|
||||
if (!plugin.getConfigFile().getTopVoterIgnorePermission() || !user.isTopVoterIgnore()) {
|
||||
if (plugin.getConfigFile().getTopVoterAwardsTies()) {
|
||||
if (user.getTotal(TopVoter.Monthly) != lastTotal) {
|
||||
i++;
|
||||
}
|
||||
@@ -252,9 +235,9 @@ public class TopVoterHandler implements Listener {
|
||||
|
||||
resetTotals(TopVoter.Monthly);
|
||||
|
||||
if (SpecialRewardsConfig.getInstance().getResetMilestonesMonthly()) {
|
||||
if (plugin.getSpecialRewardsConfig().getResetMilestonesMonthly()) {
|
||||
for (String uuid : UserManager.getInstance().getAllUUIDs()) {
|
||||
User user = UserManager.getInstance().getVotingPluginUser(new UUID(uuid));
|
||||
VotingPluginUser user = UserManager.getInstance().getVotingPluginUser(new UUID(uuid));
|
||||
user.setMilestoneCount(0);
|
||||
user.setHasGottenMilestone(new HashMap<String, Boolean>());
|
||||
}
|
||||
@@ -271,22 +254,22 @@ public class TopVoterHandler implements Listener {
|
||||
|
||||
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
|
||||
public void onWeekChange(WeekChangeEvent event) {
|
||||
synchronized (Main.plugin) {
|
||||
synchronized (VotingPluginMain.plugin) {
|
||||
for (String uuid : UserManager.getInstance().getAllUUIDs()) {
|
||||
User user = UserManager.getInstance().getVotingPluginUser(new UUID(uuid));
|
||||
VotingPluginUser user = UserManager.getInstance().getVotingPluginUser(new UUID(uuid));
|
||||
if (user.getTotal(TopVoter.Weekly) == 0 && user.getWeekVoteStreak() != 0) {
|
||||
user.setWeekVoteStreak(0);
|
||||
} else {
|
||||
if (!SpecialRewardsConfig.getInstance().isVoteStreakRequirementUsePercentage()
|
||||
if (!plugin.getSpecialRewardsConfig().isVoteStreakRequirementUsePercentage()
|
||||
|| user.hasPercentageTotal(TopVoter.Weekly,
|
||||
SpecialRewardsConfig.getInstance().getVoteStreakRequirementWeek(), null)) {
|
||||
plugin.getSpecialRewardsConfig().getVoteStreakRequirementWeek(), null)) {
|
||||
user.addWeekVoteStreak();
|
||||
SpecialRewards.getInstance().checkVoteStreak(user, "Week");
|
||||
plugin.getSpecialRewards().checkVoteStreak(user, "Week");
|
||||
}
|
||||
}
|
||||
|
||||
for (String shopIdent : Config.getInstance().getIdentifiers()) {
|
||||
if (Config.getInstance().getVoteShopResetWeekly(shopIdent)) {
|
||||
for (String shopIdent : plugin.getGui().getChestShopIdentifiers()) {
|
||||
if (plugin.getGui().getChestVoteShopResetWeekly(shopIdent)) {
|
||||
user.setVoteShopIdentifierLimit(shopIdent, 0);
|
||||
}
|
||||
}
|
||||
@@ -296,23 +279,23 @@ public class TopVoterHandler implements Listener {
|
||||
}
|
||||
}
|
||||
|
||||
if (Config.getInstance().getStoreTopVotersWeekly()) {
|
||||
if (plugin.getConfigFile().getStoreTopVotersWeekly()) {
|
||||
plugin.getLogger().info("Saving TopVoters Weekly");
|
||||
storeTopVoters(TopVoter.Weekly);
|
||||
}
|
||||
|
||||
try {
|
||||
if (SpecialRewardsConfig.getInstance().isEnableWeeklyAwards()) {
|
||||
if (plugin.getSpecialRewardsConfig().isEnableWeeklyAwards()) {
|
||||
HashMap<Integer, String> places = handlePlaces(
|
||||
SpecialRewardsConfig.getInstance().getWeeklyPossibleRewardPlaces());
|
||||
plugin.getSpecialRewardsConfig().getWeeklyPossibleRewardPlaces());
|
||||
int i = 0;
|
||||
int lastTotal = -1;
|
||||
@SuppressWarnings("unchecked")
|
||||
LinkedHashMap<User, Integer> clone = (LinkedHashMap<User, Integer>) plugin
|
||||
LinkedHashMap<VotingPluginUser, Integer> clone = (LinkedHashMap<VotingPluginUser, Integer>) plugin
|
||||
.getTopVoter(TopVoter.Weekly).clone();
|
||||
for (User user : clone.keySet()) {
|
||||
if (!Config.getInstance().getTopVoterIgnorePermission() || !user.isTopVoterIgnore()) {
|
||||
if (Config.getInstance().getTopVoterAwardsTies()) {
|
||||
for (VotingPluginUser user : clone.keySet()) {
|
||||
if (!plugin.getConfigFile().getTopVoterIgnorePermission() || !user.isTopVoterIgnore()) {
|
||||
if (plugin.getConfigFile().getTopVoterAwardsTies()) {
|
||||
if (user.getTotal(TopVoter.Weekly) != lastTotal) {
|
||||
i++;
|
||||
}
|
||||
@@ -339,22 +322,23 @@ public class TopVoterHandler implements Listener {
|
||||
|
||||
public void resetTotals(TopVoter topVoter) {
|
||||
for (String uuid : UserManager.getInstance().getAllUUIDs()) {
|
||||
User user = UserManager.getInstance().getVotingPluginUser(new UUID(uuid));
|
||||
VotingPluginUser user = UserManager.getInstance().getVotingPluginUser(new UUID(uuid));
|
||||
if (user.getTotal(topVoter) != 0) {
|
||||
user.resetTotals(topVoter);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public LinkedHashMap<User, Integer> sortByValues(LinkedHashMap<User, Integer> topVoterAllTime,
|
||||
final boolean order) {
|
||||
public LinkedHashMap<VotingPluginUser, Integer> sortByValues(
|
||||
LinkedHashMap<VotingPluginUser, Integer> topVoterAllTime, final boolean order) {
|
||||
|
||||
List<Entry<User, Integer>> list = new LinkedList<Entry<User, Integer>>(topVoterAllTime.entrySet());
|
||||
List<Entry<VotingPluginUser, Integer>> list = new LinkedList<Entry<VotingPluginUser, Integer>>(
|
||||
topVoterAllTime.entrySet());
|
||||
|
||||
// Sorting the list based on values
|
||||
Collections.sort(list, new Comparator<Entry<User, Integer>>() {
|
||||
Collections.sort(list, new Comparator<Entry<VotingPluginUser, Integer>>() {
|
||||
@Override
|
||||
public int compare(Entry<User, Integer> o1, Entry<User, Integer> o2) {
|
||||
public int compare(Entry<VotingPluginUser, Integer> o1, Entry<VotingPluginUser, Integer> o2) {
|
||||
if (order) {
|
||||
return o1.getValue().compareTo(o2.getValue());
|
||||
} else {
|
||||
@@ -365,8 +349,8 @@ public class TopVoterHandler implements Listener {
|
||||
});
|
||||
|
||||
// Maintaining insertion order with the help of LinkedList
|
||||
LinkedHashMap<User, Integer> sortedMap = new LinkedHashMap<User, Integer>();
|
||||
for (Entry<User, Integer> entry : list) {
|
||||
LinkedHashMap<VotingPluginUser, Integer> sortedMap = new LinkedHashMap<VotingPluginUser, Integer>();
|
||||
for (Entry<VotingPluginUser, Integer> entry : list) {
|
||||
sortedMap.put(entry.getKey(), entry.getValue());
|
||||
}
|
||||
|
||||
@@ -388,11 +372,11 @@ public class TopVoterHandler implements Listener {
|
||||
}
|
||||
fileName += ".yml";
|
||||
|
||||
YMLFileHandler file = new YMLFileHandler(new File(plugin.getDataFolder(), fileName));
|
||||
YMLFileHandler file = new YMLFileHandler(plugin, new File(plugin.getDataFolder(), fileName));
|
||||
file.setup();
|
||||
ArrayList<String> topVoters = new ArrayList<String>();
|
||||
int count = 1;
|
||||
for (Entry<User, Integer> entry : plugin.getTopVoter(top).entrySet()) {
|
||||
for (Entry<VotingPluginUser, Integer> entry : plugin.getTopVoter(top).entrySet()) {
|
||||
topVoters.add(count + ": " + entry.getKey().getPlayerName() + ": " + entry.getValue());
|
||||
count++;
|
||||
}
|
||||
@@ -403,17 +387,16 @@ public class TopVoterHandler implements Listener {
|
||||
/**
|
||||
* Top voter all time
|
||||
*
|
||||
* @param page
|
||||
* the page
|
||||
* @param page the page
|
||||
* @return the string[]
|
||||
*/
|
||||
public String[] topVoterAllTime(int page) {
|
||||
int pagesize = Config.getInstance().getFormatPageSize();
|
||||
int pagesize = plugin.getConfigFile().getFormatPageSize();
|
||||
ArrayList<String> msg = new ArrayList<String>();
|
||||
ArrayList<String> topVoters = new ArrayList<String>();
|
||||
int count = 1;
|
||||
for (Entry<User, Integer> entry : plugin.getTopVoter(TopVoter.AllTime).entrySet()) {
|
||||
String line = Config.getInstance().getFormatCommandVoteTopLine();
|
||||
for (Entry<VotingPluginUser, Integer> entry : plugin.getTopVoter(TopVoter.AllTime).entrySet()) {
|
||||
String line = plugin.getConfigFile().getFormatCommandVoteTopLine();
|
||||
line = line.replace("%num%", "" + count);
|
||||
line = line.replace("%player%", entry.getKey().getPlayerName());
|
||||
line = line.replace("%votes%", "" + entry.getValue());
|
||||
@@ -426,7 +409,7 @@ public class TopVoterHandler implements Listener {
|
||||
pageSize++;
|
||||
}
|
||||
|
||||
String title = Config.getInstance().getFormatCommandVoteTopTitle();
|
||||
String title = plugin.getConfigFile().getFormatCommandVoteTopTitle();
|
||||
title = title.replace("%page%", "" + page);
|
||||
title = title.replace("%maxpages%", "" + pageSize);
|
||||
title = title.replace("%Top%", "All Time");
|
||||
@@ -443,17 +426,16 @@ public class TopVoterHandler implements Listener {
|
||||
/**
|
||||
* Top voter weekly.
|
||||
*
|
||||
* @param page
|
||||
* the page
|
||||
* @param page the page
|
||||
* @return the string[]
|
||||
*/
|
||||
public String[] topVoterDaily(int page) {
|
||||
int pagesize = Config.getInstance().getFormatPageSize();
|
||||
int pagesize = plugin.getConfigFile().getFormatPageSize();
|
||||
ArrayList<String> msg = new ArrayList<String>();
|
||||
ArrayList<String> topVoters = new ArrayList<String>();
|
||||
int count = 1;
|
||||
for (Entry<User, Integer> entry : plugin.getTopVoter(TopVoter.Daily).entrySet()) {
|
||||
String line = Config.getInstance().getFormatCommandVoteTopLine();
|
||||
for (Entry<VotingPluginUser, Integer> entry : plugin.getTopVoter(TopVoter.Daily).entrySet()) {
|
||||
String line = plugin.getConfigFile().getFormatCommandVoteTopLine();
|
||||
line = line.replace("%num%", "" + count);
|
||||
line = line.replace("%player%", entry.getKey().getPlayerName());
|
||||
line = line.replace("%votes%", "" + entry.getValue());
|
||||
@@ -466,7 +448,7 @@ public class TopVoterHandler implements Listener {
|
||||
pageSize++;
|
||||
}
|
||||
|
||||
String title = Config.getInstance().getFormatCommandVoteTopTitle();
|
||||
String title = plugin.getConfigFile().getFormatCommandVoteTopTitle();
|
||||
title = title.replace("%page%", "" + page);
|
||||
title = title.replace("%maxpages%", "" + pageSize);
|
||||
title = title.replace("%Top%", "Daily");
|
||||
@@ -483,17 +465,16 @@ public class TopVoterHandler implements Listener {
|
||||
/**
|
||||
* Top voter monthly
|
||||
*
|
||||
* @param page
|
||||
* the page
|
||||
* @param page the page
|
||||
* @return the string[]
|
||||
*/
|
||||
public String[] topVoterMonthly(int page) {
|
||||
int pagesize = Config.getInstance().getFormatPageSize();
|
||||
int pagesize = plugin.getConfigFile().getFormatPageSize();
|
||||
ArrayList<String> msg = new ArrayList<String>();
|
||||
ArrayList<String> topVoters = new ArrayList<String>();
|
||||
int count = 1;
|
||||
for (Entry<User, Integer> entry : plugin.getTopVoter(TopVoter.Monthly).entrySet()) {
|
||||
String line = Config.getInstance().getFormatCommandVoteTopLine();
|
||||
for (Entry<VotingPluginUser, Integer> entry : plugin.getTopVoter(TopVoter.Monthly).entrySet()) {
|
||||
String line = plugin.getConfigFile().getFormatCommandVoteTopLine();
|
||||
line = line.replace("%num%", "" + count);
|
||||
line = line.replace("%player%", entry.getKey().getPlayerName());
|
||||
line = line.replace("%votes%", "" + entry.getValue());
|
||||
@@ -506,7 +487,7 @@ public class TopVoterHandler implements Listener {
|
||||
pageSize++;
|
||||
}
|
||||
|
||||
String title = Config.getInstance().getFormatCommandVoteTopTitle();
|
||||
String title = plugin.getConfigFile().getFormatCommandVoteTopTitle();
|
||||
title = title.replace("%page%", "" + page);
|
||||
title = title.replace("%maxpages%", "" + pageSize);
|
||||
title = title.replace("%Top%", "Monthly");
|
||||
@@ -527,16 +508,16 @@ public class TopVoterHandler implements Listener {
|
||||
*/
|
||||
public String[] topVotersAllTime() {
|
||||
ArrayList<String> msg = new ArrayList<String>();
|
||||
List<Entry<User, Integer>> list = new LinkedList<Entry<User, Integer>>(
|
||||
List<Entry<VotingPluginUser, Integer>> list = new LinkedList<Entry<VotingPluginUser, Integer>>(
|
||||
plugin.getTopVoter(TopVoter.AllTime).entrySet());
|
||||
int i = 0;
|
||||
for (Entry<User, Integer> entry : list) {
|
||||
for (Entry<VotingPluginUser, Integer> entry : list) {
|
||||
String line = "%num%: %player%, %votes%";
|
||||
line = line.replace("%num%", "" + (i + 1));
|
||||
try {
|
||||
line = line.replace("%player%", entry.getKey().getPlayerName());
|
||||
} catch (Exception ex) {
|
||||
Main.plugin.debug(ex);
|
||||
VotingPluginMain.plugin.debug(ex);
|
||||
}
|
||||
line = line.replace("%votes%", "" + entry.getValue());
|
||||
|
||||
@@ -556,14 +537,14 @@ public class TopVoterHandler implements Listener {
|
||||
|
||||
public String[] topVotersDaily() {
|
||||
ArrayList<String> msg = new ArrayList<String>();
|
||||
ArrayList<User> users = plugin.convertSet(plugin.getTopVoter(TopVoter.Daily).keySet());
|
||||
ArrayList<VotingPluginUser> users = plugin.convertSet(plugin.getTopVoter(TopVoter.Daily).keySet());
|
||||
for (int i = 0; i < users.size(); i++) {
|
||||
String line = "%num%: %player%, %votes%";
|
||||
line = line.replace("%num%", "" + (i + 1));
|
||||
try {
|
||||
line = line.replace("%player%", users.get(i).getPlayerName());
|
||||
} catch (Exception ex) {
|
||||
Main.plugin.debug(ex);
|
||||
VotingPluginMain.plugin.debug(ex);
|
||||
}
|
||||
line = line.replace("%votes%", "" + plugin.getTopVoter(TopVoter.Monthly).get(users.get(i)));
|
||||
msg.add(line);
|
||||
@@ -580,16 +561,16 @@ public class TopVoterHandler implements Listener {
|
||||
*/
|
||||
public String[] topVotersMonthly() {
|
||||
ArrayList<String> msg = new ArrayList<String>();
|
||||
List<Entry<User, Integer>> list = new LinkedList<Entry<User, Integer>>(
|
||||
List<Entry<VotingPluginUser, Integer>> list = new LinkedList<Entry<VotingPluginUser, Integer>>(
|
||||
plugin.getTopVoter(TopVoter.Monthly).entrySet());
|
||||
int i = 0;
|
||||
for (Entry<User, Integer> entry : list) {
|
||||
for (Entry<VotingPluginUser, Integer> entry : list) {
|
||||
String line = "%num%: %player%, %votes%";
|
||||
line = line.replace("%num%", "" + (i + 1));
|
||||
try {
|
||||
line = line.replace("%player%", entry.getKey().getPlayerName());
|
||||
} catch (Exception ex) {
|
||||
Main.plugin.debug(ex);
|
||||
VotingPluginMain.plugin.debug(ex);
|
||||
}
|
||||
line = line.replace("%votes%", "" + entry.getValue());
|
||||
|
||||
@@ -604,17 +585,16 @@ public class TopVoterHandler implements Listener {
|
||||
/**
|
||||
* Top voter weekly.
|
||||
*
|
||||
* @param page
|
||||
* the page
|
||||
* @param page the page
|
||||
* @return the string[]
|
||||
*/
|
||||
public String[] topVoterWeekly(int page) {
|
||||
int pagesize = Config.getInstance().getFormatPageSize();
|
||||
int pagesize = plugin.getConfigFile().getFormatPageSize();
|
||||
ArrayList<String> msg = new ArrayList<String>();
|
||||
ArrayList<String> topVoters = new ArrayList<String>();
|
||||
int count = 1;
|
||||
for (Entry<User, Integer> entry : plugin.getTopVoter(TopVoter.Weekly).entrySet()) {
|
||||
String line = Config.getInstance().getFormatCommandVoteTopLine();
|
||||
for (Entry<VotingPluginUser, Integer> entry : plugin.getTopVoter(TopVoter.Weekly).entrySet()) {
|
||||
String line = plugin.getConfigFile().getFormatCommandVoteTopLine();
|
||||
line = line.replace("%num%", "" + count);
|
||||
line = line.replace("%player%", entry.getKey().getPlayerName());
|
||||
line = line.replace("%votes%", "" + entry.getValue());
|
||||
@@ -627,7 +607,7 @@ public class TopVoterHandler implements Listener {
|
||||
pageSize++;
|
||||
}
|
||||
|
||||
String title = Config.getInstance().getFormatCommandVoteTopTitle();
|
||||
String title = plugin.getConfigFile().getFormatCommandVoteTopTitle();
|
||||
title = title.replace("%page%", "" + page);
|
||||
title = title.replace("%maxpages%", "" + pageSize);
|
||||
title = title.replace("%Top%", "Weekly");
|
||||
@@ -641,12 +621,12 @@ public class TopVoterHandler implements Listener {
|
||||
return ArrayUtils.getInstance().convert(msg);
|
||||
}
|
||||
|
||||
public synchronized void updateTopVoters(ArrayList<User> users1) {
|
||||
ArrayList<User> users = new ArrayList<User>();
|
||||
public synchronized void updateTopVoters(ArrayList<VotingPluginUser> users1) {
|
||||
ArrayList<VotingPluginUser> users = new ArrayList<VotingPluginUser>();
|
||||
ArrayList<String> blackList = getTopVoterBlackList();
|
||||
for (User user : users1) {
|
||||
for (VotingPluginUser user : users1) {
|
||||
if (!blackList.contains(user.getPlayerName())) {
|
||||
if ((!Config.getInstance().getTopVoterIgnorePermission() || !user.isTopVoterIgnore())
|
||||
if ((!plugin.getConfigFile().getTopVoterIgnorePermission() || !user.isTopVoterIgnore())
|
||||
&& !user.isBanned()) {
|
||||
users.add(user);
|
||||
}
|
||||
@@ -656,10 +636,10 @@ public class TopVoterHandler implements Listener {
|
||||
plugin.debug("Number of users to check top voter: " + users.size());
|
||||
|
||||
for (TopVoter top : TopVoter.values()) {
|
||||
if (Config.getInstance().getLoadTopVoter(top)) {
|
||||
LinkedHashMap<User, Integer> map = new LinkedHashMap<User, Integer>();
|
||||
if (plugin.getConfigFile().getLoadTopVoter(top)) {
|
||||
LinkedHashMap<VotingPluginUser, Integer> map = new LinkedHashMap<VotingPluginUser, Integer>();
|
||||
|
||||
for (User user : users) {
|
||||
for (VotingPluginUser user : users) {
|
||||
int total = user.getTotal(top);
|
||||
if (total > 0) {
|
||||
map.put(user, total);
|
||||
@@ -667,9 +647,9 @@ public class TopVoterHandler implements Listener {
|
||||
}
|
||||
|
||||
map = sortByValues(map, false);
|
||||
int limitSize = Config.getInstance().getMaxiumNumberOfTopVotersToLoad();
|
||||
int limitSize = plugin.getConfigFile().getMaxiumNumberOfTopVotersToLoad();
|
||||
if (limitSize > 0) {
|
||||
ArrayList<User> listKeys = new ArrayList<User>(map.keySet());
|
||||
ArrayList<VotingPluginUser> listKeys = new ArrayList<VotingPluginUser>(map.keySet());
|
||||
if (listKeys.size() > limitSize) {
|
||||
for (int i = listKeys.size() - 1; i >= 0 && i >= limitSize; i--) {
|
||||
map.remove(listKeys.get(i));
|
||||
@@ -0,0 +1,98 @@
|
||||
package com.bencodez.votingplugin.updater;
|
||||
|
||||
import java.util.Timer;
|
||||
import java.util.TimerTask;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
|
||||
import com.bencodez.advancedcore.api.updater.Updater;
|
||||
import com.bencodez.votingplugin.VotingPluginMain;
|
||||
|
||||
// TODO: Auto-generated Javadoc
|
||||
/**
|
||||
* The Class CheckUpdate.
|
||||
*/
|
||||
public class CheckUpdate {
|
||||
|
||||
private VotingPluginMain plugin;
|
||||
|
||||
public CheckUpdate(VotingPluginMain plugin) {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check update.
|
||||
*/
|
||||
public void checkUpdate() {
|
||||
if (plugin.getConfigFile().isDisableUpdateChecking()) {
|
||||
return;
|
||||
}
|
||||
plugin.setUpdater(new Updater(plugin, 15358, false));
|
||||
final Updater.UpdateResult result = plugin.getUpdater().getResult();
|
||||
switch (result) {
|
||||
case FAIL_SPIGOT: {
|
||||
plugin.getLogger().info("Failed to check for update for " + plugin.getName() + "!");
|
||||
break;
|
||||
}
|
||||
case NO_UPDATE: {
|
||||
plugin.getLogger().info(plugin.getName() + " is up to date! Version: " + plugin.getUpdater().getVersion());
|
||||
break;
|
||||
}
|
||||
case UPDATE_AVAILABLE: {
|
||||
plugin.getLogger()
|
||||
.info(plugin.getName() + " has an update available! Your Version: "
|
||||
+ plugin.getDescription().getVersion() + " New Version: " + plugin.getUpdater().getVersion()
|
||||
+ " Use /av download to get the latest update!");
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void checkUpdateBasic() {
|
||||
if (plugin.getConfigFile().isDisableUpdateChecking()) {
|
||||
return;
|
||||
}
|
||||
plugin.setUpdater(new Updater(plugin, 15358, false));
|
||||
final Updater.UpdateResult result = plugin.getUpdater().getResult();
|
||||
switch (result) {
|
||||
case UPDATE_AVAILABLE: {
|
||||
plugin.getLogger()
|
||||
.info(plugin.getName() + " has an update available! Your Version: "
|
||||
+ plugin.getDescription().getVersion() + " New Version: " + plugin.getUpdater().getVersion()
|
||||
+ " Use /av download to get the latest update!");
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Start up.
|
||||
*/
|
||||
public void startUp() {
|
||||
if (plugin.getConfigFile().isDisableUpdateChecking()) {
|
||||
return;
|
||||
}
|
||||
Bukkit.getScheduler().runTaskLaterAsynchronously(plugin, new Runnable() {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
checkUpdate();
|
||||
new Timer().schedule(new TimerTask() {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
checkUpdateBasic();
|
||||
}
|
||||
}, 1000 * 60 * 1200, 1000 * 60 * 1200);
|
||||
|
||||
}
|
||||
}, 10l);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
package com.bencodez.votingplugin.user;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import com.bencodez.advancedcore.api.user.UUID;
|
||||
import com.bencodez.votingplugin.VotingPluginMain;
|
||||
|
||||
public class UserManager {
|
||||
/** The instance. */
|
||||
static UserManager instance = new UserManager();
|
||||
/** The plugin. */
|
||||
static VotingPluginMain plugin = VotingPluginMain.plugin;
|
||||
|
||||
/**
|
||||
* Gets the single instance of UserManager.
|
||||
*
|
||||
* @return single instance of UserManager
|
||||
*/
|
||||
public static UserManager getInstance() {
|
||||
return instance;
|
||||
}
|
||||
|
||||
public UserManager() {
|
||||
super();
|
||||
}
|
||||
|
||||
public ArrayList<String> getAllUUIDs() {
|
||||
return com.bencodez.advancedcore.api.user.UserManager.getInstance().getAllUUIDs();
|
||||
}
|
||||
|
||||
public VotingPluginUser getVotingPluginUser(com.bencodez.advancedcore.api.user.AdvancedCoreUser user) {
|
||||
return getVotingPluginUser(java.util.UUID.fromString(user.getUUID()));
|
||||
}
|
||||
|
||||
public VotingPluginUser getVotingPluginUser(java.util.UUID uuid) {
|
||||
return getVotingPluginUser(new UUID(uuid.toString()));
|
||||
}
|
||||
|
||||
public VotingPluginUser getVotingPluginUser(OfflinePlayer player) {
|
||||
return getVotingPluginUser(player.getName());
|
||||
}
|
||||
|
||||
public VotingPluginUser getVotingPluginUser(Player player) {
|
||||
return getVotingPluginUser(player.getName());
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
public VotingPluginUser getVotingPluginUser(String playerName) {
|
||||
return new VotingPluginUser(plugin,
|
||||
com.bencodez.advancedcore.api.user.UserManager.getInstance().getProperName(playerName));
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
public VotingPluginUser getVotingPluginUser(UUID uuid) {
|
||||
return new VotingPluginUser(plugin, uuid);
|
||||
}
|
||||
}
|
||||
+427
-164
@@ -1,11 +1,14 @@
|
||||
package com.Ben12345rocks.VotingPlugin.Objects;
|
||||
package com.bencodez.votingplugin.user;
|
||||
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.time.Duration;
|
||||
import java.time.Instant;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.YearMonth;
|
||||
import java.time.ZoneId;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
@@ -15,80 +18,51 @@ import java.util.stream.Collectors;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import com.Ben12345rocks.AdvancedCore.Rewards.RewardBuilder;
|
||||
import com.Ben12345rocks.AdvancedCore.Rewards.RewardHandler;
|
||||
import com.Ben12345rocks.AdvancedCore.Rewards.RewardOptions;
|
||||
import com.Ben12345rocks.AdvancedCore.TimeChecker.TimeChecker;
|
||||
import com.Ben12345rocks.AdvancedCore.UserManager.UUID;
|
||||
import com.Ben12345rocks.AdvancedCore.Util.Messages.StringParser;
|
||||
import com.Ben12345rocks.AdvancedCore.Util.Misc.MiscUtils;
|
||||
import com.Ben12345rocks.VotingPlugin.BungeeHandler;
|
||||
import com.Ben12345rocks.VotingPlugin.Main;
|
||||
import com.Ben12345rocks.VotingPlugin.Config.BungeeSettings;
|
||||
import com.Ben12345rocks.VotingPlugin.Config.Config;
|
||||
import com.Ben12345rocks.VotingPlugin.Config.SpecialRewardsConfig;
|
||||
import com.Ben12345rocks.VotingPlugin.Events.PlayerReceivePointsEvent;
|
||||
import com.Ben12345rocks.VotingPlugin.Events.PlayerVoteCoolDownEndEvent;
|
||||
import com.Ben12345rocks.VotingPlugin.Events.PlayerVoteEvent;
|
||||
import com.Ben12345rocks.VotingPlugin.SpecialRewards.SpecialRewards;
|
||||
import com.Ben12345rocks.VotingPlugin.TopVoter.TopVoter;
|
||||
import com.Ben12345rocks.VotingPlugin.VoteParty.VoteParty;
|
||||
import com.Ben12345rocks.VotingPlugin.VoteReminding.VoteReminding;
|
||||
import com.Ben12345rocks.VotingPlugin.bungee.BungeeMethod;
|
||||
import com.bencodez.advancedcore.api.messages.StringParser;
|
||||
import com.bencodez.advancedcore.api.misc.MiscUtils;
|
||||
import com.bencodez.advancedcore.api.rewards.RewardBuilder;
|
||||
import com.bencodez.advancedcore.api.rewards.RewardHandler;
|
||||
import com.bencodez.advancedcore.api.rewards.RewardOptions;
|
||||
import com.bencodez.advancedcore.api.user.UUID;
|
||||
import com.bencodez.votingplugin.VotingPluginMain;
|
||||
import com.bencodez.votingplugin.bungee.BungeeMethod;
|
||||
import com.bencodez.votingplugin.events.PlayerReceivePointsEvent;
|
||||
import com.bencodez.votingplugin.events.PlayerVoteCoolDownEndEvent;
|
||||
import com.bencodez.votingplugin.events.PlayerVoteEvent;
|
||||
import com.bencodez.votingplugin.objects.VoteSite;
|
||||
import com.bencodez.votingplugin.topvoter.TopVoter;
|
||||
|
||||
// TODO: Auto-generated Javadoc
|
||||
/**
|
||||
* The Class User.
|
||||
*/
|
||||
public class User extends com.Ben12345rocks.AdvancedCore.UserManager.User {
|
||||
public class VotingPluginUser extends com.bencodez.advancedcore.api.user.AdvancedCoreUser {
|
||||
|
||||
/** The plugin. */
|
||||
static Main plugin = Main.plugin;
|
||||
private VotingPluginMain plugin;
|
||||
|
||||
/**
|
||||
* Instantiates a new user.
|
||||
*
|
||||
* @param player
|
||||
* the player
|
||||
*/
|
||||
@Deprecated
|
||||
public User(Player player) {
|
||||
public VotingPluginUser(VotingPluginMain plugin, Player player) {
|
||||
super(plugin, player);
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
/**
|
||||
* Instantiates a new user.
|
||||
*
|
||||
* @param playerName
|
||||
* the player name
|
||||
*/
|
||||
@Deprecated
|
||||
public User(String playerName) {
|
||||
public VotingPluginUser(VotingPluginMain plugin, String playerName) {
|
||||
super(plugin, playerName);
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
/**
|
||||
* Instantiates a new user.
|
||||
*
|
||||
* @param uuid
|
||||
* the uuid
|
||||
*/
|
||||
@Deprecated
|
||||
public User(UUID uuid) {
|
||||
public VotingPluginUser(VotingPluginMain plugin, UUID uuid) {
|
||||
super(plugin, uuid);
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
/**
|
||||
* Instantiates a new user.
|
||||
*
|
||||
* @param uuid
|
||||
* the uuid
|
||||
* @param loadName
|
||||
* the load name
|
||||
*/
|
||||
@Deprecated
|
||||
public User(UUID uuid, boolean loadName) {
|
||||
public VotingPluginUser(VotingPluginMain plugin, UUID uuid, boolean loadName) {
|
||||
super(plugin, uuid, loadName);
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
public void addAllTimeTotal() {
|
||||
@@ -123,7 +97,7 @@ public class User extends com.Ben12345rocks.AdvancedCore.UserManager.User {
|
||||
* Adds the points.
|
||||
*/
|
||||
public void addPoints() {
|
||||
int points = Config.getInstance().getPointsOnVote();
|
||||
int points = plugin.getConfigFile().getPointsOnVote();
|
||||
if (points != 0) {
|
||||
addPoints(points);
|
||||
}
|
||||
@@ -132,8 +106,7 @@ public class User extends com.Ben12345rocks.AdvancedCore.UserManager.User {
|
||||
/**
|
||||
* Adds the points.
|
||||
*
|
||||
* @param value
|
||||
* the value
|
||||
* @param value the value
|
||||
*/
|
||||
public void addPoints(int value) {
|
||||
PlayerReceivePointsEvent event = new PlayerReceivePointsEvent(this, value);
|
||||
@@ -178,8 +151,8 @@ public class User extends com.Ben12345rocks.AdvancedCore.UserManager.User {
|
||||
}
|
||||
|
||||
public void bungeeVote(String service) {
|
||||
if (BungeeSettings.getInstance().isUseBungeecoord()) {
|
||||
Main.plugin.debug("Bungee vote for " + getPlayerName() + " on " + service);
|
||||
if (plugin.getBungeeSettings().isUseBungeecoord()) {
|
||||
VotingPluginMain.plugin.debug("Bungee vote for " + getPlayerName() + " on " + service);
|
||||
|
||||
PlayerVoteEvent voteEvent = new PlayerVoteEvent(plugin.getVoteSite(service), getPlayerName(), service,
|
||||
true);
|
||||
@@ -196,8 +169,8 @@ public class User extends com.Ben12345rocks.AdvancedCore.UserManager.User {
|
||||
}
|
||||
|
||||
public void bungeeVoteOnline(String service) {
|
||||
if (BungeeSettings.getInstance().isUseBungeecoord()) {
|
||||
Main.plugin.debug("Bungee online vote for " + getPlayerName() + " on " + service);
|
||||
if (plugin.getBungeeSettings().isUseBungeecoord()) {
|
||||
VotingPluginMain.plugin.debug("Bungee online vote for " + getPlayerName() + " on " + service);
|
||||
|
||||
PlayerVoteEvent voteEvent = new PlayerVoteEvent(plugin.getVoteSite(service), getPlayerName(), service,
|
||||
true);
|
||||
@@ -213,9 +186,9 @@ public class User extends com.Ben12345rocks.AdvancedCore.UserManager.User {
|
||||
}
|
||||
}
|
||||
|
||||
public void bungeeVotePluginMessaging(String service, long time) {
|
||||
if (BungeeSettings.getInstance().isUseBungeecoord()) {
|
||||
Main.plugin.debug("Pluginmessaging vote for " + getPlayerName() + " on " + service);
|
||||
public void bungeeVotePluginMessaging(String service, long time, String bungeeTextTotals) {
|
||||
if (plugin.getBungeeSettings().isUseBungeecoord()) {
|
||||
VotingPluginMain.plugin.debug("Pluginmessaging vote for " + getPlayerName() + " on " + service);
|
||||
|
||||
PlayerVoteEvent voteEvent = new PlayerVoteEvent(plugin.getVoteSite(service), getPlayerName(), service,
|
||||
true);
|
||||
@@ -223,6 +196,7 @@ public class User extends com.Ben12345rocks.AdvancedCore.UserManager.User {
|
||||
voteEvent.setForceBungee(true);
|
||||
voteEvent.setTime(time);
|
||||
voteEvent.setAddTotals(false);
|
||||
voteEvent.setBungeeTextTotals(bungeeTextTotals);
|
||||
Bukkit.getScheduler().runTaskAsynchronously(plugin, new Runnable() {
|
||||
|
||||
@Override
|
||||
@@ -261,8 +235,7 @@ public class User extends com.Ben12345rocks.AdvancedCore.UserManager.User {
|
||||
/**
|
||||
* Can vote site.
|
||||
*
|
||||
* @param voteSite
|
||||
* the vote site
|
||||
* @param voteSite the vote site
|
||||
* @return true, if successful
|
||||
*/
|
||||
public boolean canVoteSite(VoteSite voteSite) {
|
||||
@@ -272,9 +245,9 @@ public class User extends com.Ben12345rocks.AdvancedCore.UserManager.User {
|
||||
return true;
|
||||
}
|
||||
try {
|
||||
LocalDateTime now = TimeChecker.getInstance().getTime();
|
||||
LocalDateTime now = plugin.getTimeChecker().getTime();
|
||||
LocalDateTime lastVote = LocalDateTime.ofInstant(Instant.ofEpochMilli(time), ZoneId.systemDefault())
|
||||
.plusHours(Main.plugin.getOptions().getTimeHourOffSet());
|
||||
.plusHours(VotingPluginMain.plugin.getOptions().getTimeHourOffSet());
|
||||
|
||||
if (!voteSite.isVoteDelayDaily()) {
|
||||
double votedelay = voteSite.getVoteDelay();
|
||||
@@ -306,7 +279,7 @@ public class User extends com.Ben12345rocks.AdvancedCore.UserManager.User {
|
||||
* @return true, if successful
|
||||
*/
|
||||
public boolean checkAllVotes() {
|
||||
User user = this;
|
||||
VotingPluginUser user = this;
|
||||
|
||||
ArrayList<Integer> months = new ArrayList<Integer>();
|
||||
ArrayList<Integer> days = new ArrayList<Integer>();
|
||||
@@ -351,10 +324,10 @@ public class User extends com.Ben12345rocks.AdvancedCore.UserManager.User {
|
||||
|
||||
public void checkDayVoteStreak() {
|
||||
if (!voteStreakUpdatedToday(LocalDateTime.now())) {
|
||||
if (!SpecialRewardsConfig.getInstance().isVoteStreakRequirementUsePercentage() || hasPercentageTotal(
|
||||
TopVoter.Daily, SpecialRewardsConfig.getInstance().getVoteStreakRequirementDay(), null)) {
|
||||
if (!plugin.getSpecialRewardsConfig().isVoteStreakRequirementUsePercentage() || hasPercentageTotal(
|
||||
TopVoter.Daily, plugin.getSpecialRewardsConfig().getVoteStreakRequirementDay(), null)) {
|
||||
addDayVoteStreak();
|
||||
SpecialRewards.getInstance().checkVoteStreak(this, "Day");
|
||||
plugin.getSpecialRewards().checkVoteStreak(this, "Day");
|
||||
setDayVoteStreakLastUpdate(System.currentTimeMillis());
|
||||
}
|
||||
}
|
||||
@@ -378,28 +351,28 @@ public class User extends com.Ben12345rocks.AdvancedCore.UserManager.User {
|
||||
}
|
||||
|
||||
public int getBestDayVoteStreak() {
|
||||
return getData().getInt("BestDayVoteStreak");
|
||||
return getData().getInt("BestDayVoteStreak", isWaitForCache());
|
||||
}
|
||||
|
||||
public int getBestMonthVoteStreak() {
|
||||
return getData().getInt("BestMonthVoteStreak");
|
||||
return getData().getInt("BestMonthVoteStreak", isWaitForCache());
|
||||
}
|
||||
|
||||
public int getBestWeekVoteStreak() {
|
||||
return getData().getInt("BestWeekVoteStreak");
|
||||
return getData().getInt("BestWeekVoteStreak", isWaitForCache());
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public int getDailyTotal() {
|
||||
return getUserData().getInt("DailyTotal");
|
||||
return getUserData().getInt("DailyTotal", isWaitForCache());
|
||||
}
|
||||
|
||||
public int getDayVoteStreak() {
|
||||
return getData().getInt("DayVoteStreak");
|
||||
return getData().getInt("DayVoteStreak", isWaitForCache());
|
||||
}
|
||||
|
||||
public long getDayVoteStreakLastUpdate() {
|
||||
String str = getData().getString("DayVoteStreakLastUpdate");
|
||||
String str = getData().getString("DayVoteStreakLastUpdate", isWaitForCache());
|
||||
if (str.isEmpty()) {
|
||||
return 0;
|
||||
}
|
||||
@@ -424,15 +397,15 @@ public class User extends com.Ben12345rocks.AdvancedCore.UserManager.User {
|
||||
}
|
||||
|
||||
public int getHighestDailyTotal() {
|
||||
return getData().getInt("HighestDailyTotal");
|
||||
return getData().getInt("HighestDailyTotal", isWaitForCache());
|
||||
}
|
||||
|
||||
public int getHighestMonthlyTotal() {
|
||||
return getData().getInt("HighestMonthlyTotal");
|
||||
return getData().getInt("HighestMonthlyTotal", isWaitForCache());
|
||||
}
|
||||
|
||||
public int getHighestWeeklyTotal() {
|
||||
return getData().getInt("HighestWeeklyTotal");
|
||||
return getData().getInt("HighestWeeklyTotal", isWaitForCache());
|
||||
}
|
||||
|
||||
public boolean getLastCoolDownCheck(VoteSite site) {
|
||||
@@ -465,7 +438,7 @@ public class User extends com.Ben12345rocks.AdvancedCore.UserManager.User {
|
||||
}
|
||||
|
||||
public int getLastMonthTotal() {
|
||||
return getData().getInt("LastMonthTotal");
|
||||
return getData().getInt("LastMonthTotal", isWaitForCache());
|
||||
}
|
||||
|
||||
public HashMap<VoteSite, Long> getLastVotes() {
|
||||
@@ -508,7 +481,7 @@ public class User extends com.Ben12345rocks.AdvancedCore.UserManager.User {
|
||||
}
|
||||
|
||||
public int getMilestoneCount() {
|
||||
return getData().getInt("MilestoneCount", getAllTimeTotal());
|
||||
return getData().getInt("MilestoneCount", getAllTimeTotal(), isWaitForCache());
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
@@ -517,7 +490,7 @@ public class User extends com.Ben12345rocks.AdvancedCore.UserManager.User {
|
||||
}
|
||||
|
||||
public int getMonthVoteStreak() {
|
||||
return getData().getInt("MonthVoteStreak");
|
||||
return getData().getInt("MonthVoteStreak", isWaitForCache());
|
||||
}
|
||||
|
||||
public ArrayList<String> getOfflineOtherRewards() {
|
||||
@@ -534,7 +507,15 @@ public class User extends com.Ben12345rocks.AdvancedCore.UserManager.User {
|
||||
* @return the points
|
||||
*/
|
||||
public int getPoints() {
|
||||
return getUserData().getInt("Points");
|
||||
return getUserData().getInt("Points", isWaitForCache());
|
||||
}
|
||||
|
||||
public java.util.UUID getPrimaryAccount() {
|
||||
String s = getData().getString("PrimaryAccount", true);
|
||||
if (s != null && !s.isEmpty()) {
|
||||
return java.util.UUID.fromString(s);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public int getSitesVotedOn() {
|
||||
@@ -550,8 +531,7 @@ public class User extends com.Ben12345rocks.AdvancedCore.UserManager.User {
|
||||
/**
|
||||
* Gets the time.
|
||||
*
|
||||
* @param voteSite
|
||||
* the vote site
|
||||
* @param voteSite the vote site
|
||||
* @return the time
|
||||
*/
|
||||
public long getTime(VoteSite voteSite) {
|
||||
@@ -564,26 +544,26 @@ public class User extends com.Ben12345rocks.AdvancedCore.UserManager.User {
|
||||
|
||||
public int getTotal(TopVoter top) {
|
||||
switch (top) {
|
||||
case AllTime:
|
||||
return getUserData().getInt("AllTimeTotal");
|
||||
case Daily:
|
||||
return getUserData().getInt("DailyTotal");
|
||||
case Monthly:
|
||||
return getData().getInt("MonthTotal");
|
||||
case Weekly:
|
||||
return getUserData().getInt("WeeklyTotal");
|
||||
default:
|
||||
break;
|
||||
case AllTime:
|
||||
return getUserData().getInt("AllTimeTotal", isWaitForCache());
|
||||
case Daily:
|
||||
return getUserData().getInt("DailyTotal", isWaitForCache());
|
||||
case Monthly:
|
||||
return getData().getInt("MonthTotal", isWaitForCache());
|
||||
case Weekly:
|
||||
return getUserData().getInt("WeeklyTotal", isWaitForCache());
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
public int getVotePartyVotes() {
|
||||
return getUserData().getInt("VotePartyVotes");
|
||||
return getUserData().getInt("VotePartyVotes", isWaitForCache());
|
||||
}
|
||||
|
||||
public int getVoteShopIdentifierLimit(String identifier) {
|
||||
return getData().getInt("VoteShopLimit" + identifier);
|
||||
return getData().getInt("VoteShopLimit" + identifier, isWaitForCache());
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
@@ -592,20 +572,41 @@ public class User extends com.Ben12345rocks.AdvancedCore.UserManager.User {
|
||||
}
|
||||
|
||||
public int getWeekVoteStreak() {
|
||||
return getData().getInt("WeekVoteStreak");
|
||||
return getData().getInt("WeekVoteStreak", isWaitForCache());
|
||||
}
|
||||
|
||||
public void giveDailyTopVoterAward(int place, String path) {
|
||||
new RewardBuilder(SpecialRewardsConfig.getInstance().getData(),
|
||||
SpecialRewardsConfig.getInstance().getDailyAwardRewardsPath(path)).withPlaceHolder("place", "" + place)
|
||||
new RewardBuilder(plugin.getSpecialRewardsConfig().getData(),
|
||||
plugin.getSpecialRewardsConfig().getDailyAwardRewardsPath(path)).withPlaceHolder("place", "" + place)
|
||||
.withPlaceHolder("topvoter", "Daily").withPlaceHolder("votes", "" + getTotal(TopVoter.Daily))
|
||||
.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(SpecialRewardsConfig.getInstance().getData(),
|
||||
SpecialRewardsConfig.getInstance().getMonthlyAwardRewardsPath(path))
|
||||
.withPlaceHolder("place", "" + place).withPlaceHolder("topvoter", "Monthly")
|
||||
new RewardBuilder(plugin.getSpecialRewardsConfig().getData(),
|
||||
plugin.getSpecialRewardsConfig().getMonthlyAwardRewardsPath(path)).withPlaceHolder("place", "" + place)
|
||||
.withPlaceHolder("topvoter", "Monthly")
|
||||
.withPlaceHolder("votes", "" + getTotal(TopVoter.Monthly)).setOnline(isOnline()).send(this);
|
||||
}
|
||||
|
||||
@@ -614,18 +615,18 @@ public class User extends com.Ben12345rocks.AdvancedCore.UserManager.User {
|
||||
ArrayList<String> offlineRewards = getOfflineOtherRewards();
|
||||
for (String str : offlineRewards) {
|
||||
if (str.equalsIgnoreCase("FirstVote")) {
|
||||
SpecialRewards.getInstance().giveFirstVoteRewards(this, false);
|
||||
plugin.getSpecialRewards().giveFirstVoteRewards(this, false);
|
||||
} else if (str.equalsIgnoreCase("AllSites")) {
|
||||
SpecialRewards.getInstance().giveAllSitesRewards(this, false);
|
||||
plugin.getSpecialRewards().giveAllSitesRewards(this, false);
|
||||
} else if (str.equalsIgnoreCase("VoteParty")) {
|
||||
VoteParty.getInstance().giveReward(this, false);
|
||||
plugin.getVoteParty().giveReward(this, false);
|
||||
} else if (str.contains("Cumulative")) {
|
||||
String st = str.substring("Cumulative".length());
|
||||
if (StringParser.getInstance().isInt(st)) {
|
||||
int votesRequired = Integer.parseInt(st);
|
||||
if (votesRequired != 0) {
|
||||
if (SpecialRewardsConfig.getInstance().getCumulativeRewardEnabled(votesRequired)) {
|
||||
SpecialRewards.getInstance().giveCumulativeVoteReward(this, false, votesRequired);
|
||||
if (plugin.getSpecialRewardsConfig().getCumulativeRewardEnabled(votesRequired)) {
|
||||
plugin.getSpecialRewards().giveCumulativeVoteReward(this, false, votesRequired);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -634,8 +635,8 @@ public class User extends com.Ben12345rocks.AdvancedCore.UserManager.User {
|
||||
if (StringParser.getInstance().isInt(st)) {
|
||||
int votesRequired = Integer.parseInt(st);
|
||||
if (votesRequired > 0) {
|
||||
if (SpecialRewardsConfig.getInstance().getMilestoneRewardEnabled(votesRequired)) {
|
||||
SpecialRewards.getInstance().giveMilestoneVoteReward(this, true, votesRequired);
|
||||
if (plugin.getSpecialRewardsConfig().getMilestoneRewardEnabled(votesRequired)) {
|
||||
plugin.getSpecialRewards().giveMilestoneVoteReward(this, true, votesRequired);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -645,8 +646,8 @@ public class User extends com.Ben12345rocks.AdvancedCore.UserManager.User {
|
||||
String type = args[1];
|
||||
String st = args[2];
|
||||
|
||||
if (SpecialRewardsConfig.getInstance().getVoteStreakRewardEnabled(type, st)) {
|
||||
SpecialRewards.getInstance().giveVoteStreakReward(this, false, type, "" + st, -1);
|
||||
if (plugin.getSpecialRewardsConfig().getVoteStreakRewardEnabled(type, st)) {
|
||||
plugin.getSpecialRewards().giveVoteStreakReward(this, false, type, "" + st, -1);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -661,8 +662,8 @@ public class User extends com.Ben12345rocks.AdvancedCore.UserManager.User {
|
||||
}
|
||||
|
||||
public void giveWeeklyTopVoterAward(int place, String path) {
|
||||
new RewardBuilder(SpecialRewardsConfig.getInstance().getData(),
|
||||
SpecialRewardsConfig.getInstance().getWeeklyAwardRewardsPath(path)).withPlaceHolder("place", "" + place)
|
||||
new RewardBuilder(plugin.getSpecialRewardsConfig().getData(),
|
||||
plugin.getSpecialRewardsConfig().getWeeklyAwardRewardsPath(path)).withPlaceHolder("place", "" + place)
|
||||
.withPlaceHolder("topvoter", "Weekly").withPlaceHolder("votes", "" + getTotal(TopVoter.Weekly))
|
||||
.setOnline(isOnline()).send(this);
|
||||
}
|
||||
@@ -673,8 +674,8 @@ public class User extends com.Ben12345rocks.AdvancedCore.UserManager.User {
|
||||
* @return true if user got the first vote reward
|
||||
*/
|
||||
public boolean hasGottenFirstVote() {
|
||||
if (BungeeSettings.getInstance().isUseBungeecoord()
|
||||
&& BungeeHandler.getInstance().getMethod().equals(BungeeMethod.PLUGINMESSAGING)) {
|
||||
if (plugin.getBungeeSettings().isUseBungeecoord()
|
||||
&& plugin.getBungeeHandler().getMethod().equals(BungeeMethod.PLUGINMESSAGING)) {
|
||||
return getTotal(TopVoter.AllTime) > 1;
|
||||
}
|
||||
return getTotal(TopVoter.AllTime) != 0;
|
||||
@@ -683,8 +684,7 @@ public class User extends com.Ben12345rocks.AdvancedCore.UserManager.User {
|
||||
/**
|
||||
* Checks for gotten milestone.
|
||||
*
|
||||
* @param votesRequired
|
||||
* the votes required
|
||||
* @param votesRequired the votes required
|
||||
* @return true, if successful
|
||||
*/
|
||||
public boolean hasGottenMilestone(int votesRequired) {
|
||||
@@ -698,17 +698,21 @@ public class User extends com.Ben12345rocks.AdvancedCore.UserManager.User {
|
||||
public boolean hasPercentageTotal(TopVoter top, double percentage, LocalDateTime time) {
|
||||
int total = getTotal(top);
|
||||
switch (top) {
|
||||
case Daily:
|
||||
return total / plugin.getVoteSites().size() * 100 > percentage;
|
||||
case Monthly:
|
||||
return total / (plugin.getVoteSites().size() * time.getMonth().length(false)) * 100 > percentage;
|
||||
case Weekly:
|
||||
return total / (plugin.getVoteSites().size() * 7) * 100 > percentage;
|
||||
default:
|
||||
return false;
|
||||
case Daily:
|
||||
return total / plugin.getVoteSites().size() * 100 > percentage;
|
||||
case Monthly:
|
||||
return total / (plugin.getVoteSites().size() * time.getMonth().length(false)) * 100 > percentage;
|
||||
case Weekly:
|
||||
return total / (plugin.getVoteSites().size() * 7) * 100 > percentage;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public boolean hasPrimaryAccount() {
|
||||
return getPrimaryAccount() != null;
|
||||
}
|
||||
|
||||
public boolean isReminded() {
|
||||
return getUserData().getBoolean("Reminded");
|
||||
}
|
||||
@@ -721,21 +725,29 @@ public class User extends com.Ben12345rocks.AdvancedCore.UserManager.User {
|
||||
* Login message.
|
||||
*/
|
||||
public void loginMessage() {
|
||||
if (Config.getInstance().getVoteRemindingRemindOnLogin()) {
|
||||
VoteReminding.getInstance().runRemindLogin(this);
|
||||
if (plugin.getConfigFile().getVoteRemindingRemindOnLogin()) {
|
||||
plugin.getVoteReminding().runRemindLogin(this);
|
||||
}
|
||||
}
|
||||
|
||||
public void loginRewards() {
|
||||
new RewardBuilder(plugin.getSpecialRewardsConfig().getData(), "LoginRewards").send(this);
|
||||
}
|
||||
|
||||
public void logoutRewards() {
|
||||
new RewardBuilder(plugin.getSpecialRewardsConfig().getData(), "LogoutRewards").send(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Off vote.
|
||||
*/
|
||||
public void offVote() {
|
||||
if (!Main.plugin.getOptions().isProcessRewards()) {
|
||||
Main.plugin.debug("Processing rewards is disabled");
|
||||
if (!VotingPluginMain.plugin.getOptions().isProcessRewards()) {
|
||||
VotingPluginMain.plugin.debug("Processing rewards is disabled");
|
||||
return;
|
||||
}
|
||||
|
||||
Main.plugin.extraDebug("Checking offline vote site votes");
|
||||
VotingPluginMain.plugin.extraDebug("Checking offline vote site votes");
|
||||
Player player = getPlayer();
|
||||
if (player != null) {
|
||||
boolean topVoterIngorePerm = player.hasPermission("VotingPlugin.TopVoter.Ignore");
|
||||
@@ -746,10 +758,9 @@ public class User extends com.Ben12345rocks.AdvancedCore.UserManager.User {
|
||||
// plugin.debug(ArrayUtils.getInstance().makeStringList(offlineVotes));
|
||||
if (offlineVotes.size() > 0) {
|
||||
sendVoteEffects(true);
|
||||
setOfflineVotes(new ArrayList<String>());
|
||||
}
|
||||
|
||||
setOfflineVotes(new ArrayList<String>());
|
||||
|
||||
for (int i = 0; i < offlineVotes.size(); i++) {
|
||||
if (plugin.hasVoteSite(offlineVotes.get(i))) {
|
||||
plugin.debug("Giving offline site reward: " + offlineVotes.get(i));
|
||||
@@ -764,7 +775,7 @@ public class User extends com.Ben12345rocks.AdvancedCore.UserManager.User {
|
||||
}
|
||||
|
||||
public void playerVote(VoteSite voteSite, boolean online, boolean broadcast, boolean bungee) {
|
||||
if (Config.getInstance().getFormatBroadcastWhenOnline() && Config.getInstance().isBroadcastVotesEnabled()
|
||||
if (plugin.getConfigFile().getFormatBroadcastWhenOnline() && plugin.getConfigFile().isBroadcastVotesEnabled()
|
||||
&& broadcast) {
|
||||
voteSite.broadcastVote(this);
|
||||
}
|
||||
@@ -774,8 +785,7 @@ public class User extends com.Ben12345rocks.AdvancedCore.UserManager.User {
|
||||
/**
|
||||
* Removes the points.
|
||||
*
|
||||
* @param points
|
||||
* the points
|
||||
* @param points the points
|
||||
* @return true, if successful
|
||||
*/
|
||||
public boolean removePoints(int points) {
|
||||
@@ -793,12 +803,11 @@ public class User extends com.Ben12345rocks.AdvancedCore.UserManager.User {
|
||||
/**
|
||||
* Send vote effects.
|
||||
*
|
||||
* @param online
|
||||
* the online
|
||||
* @param online the online
|
||||
*/
|
||||
public void sendVoteEffects(boolean online) {
|
||||
RewardHandler.getInstance().giveReward(this, SpecialRewardsConfig.getInstance().getData(),
|
||||
SpecialRewardsConfig.getInstance().getAnySiteRewardsPath(), new RewardOptions().setOnline(online));
|
||||
RewardHandler.getInstance().giveReward(this, plugin.getSpecialRewardsConfig().getData(),
|
||||
plugin.getSpecialRewardsConfig().getAnySiteRewardsPath(), new RewardOptions().setOnline(online));
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
@@ -920,11 +929,18 @@ public class User extends com.Ben12345rocks.AdvancedCore.UserManager.User {
|
||||
/**
|
||||
* Sets the points.
|
||||
*
|
||||
* @param value
|
||||
* the new points
|
||||
* @param value the new points
|
||||
*/
|
||||
public void setPoints(int value) {
|
||||
getUserData().setInt("Points", value, !BungeeSettings.getInstance().isUseBungeecoord());
|
||||
getUserData().setInt("Points", value, !plugin.getBungeeSettings().isUseBungeecoord());
|
||||
}
|
||||
|
||||
public void setPrimaryAccount(java.util.UUID uuid) {
|
||||
if (uuid != null) {
|
||||
getData().setString("PrimaryAccount", uuid.toString());
|
||||
} else {
|
||||
getData().setString("PrimaryAccount", "");
|
||||
}
|
||||
}
|
||||
|
||||
public void setReminded(boolean reminded) {
|
||||
@@ -947,27 +963,27 @@ public class User extends com.Ben12345rocks.AdvancedCore.UserManager.User {
|
||||
|
||||
public void setTotal(TopVoter top, int value) {
|
||||
switch (top) {
|
||||
case AllTime:
|
||||
getUserData().setInt("AllTimeTotal", value);
|
||||
break;
|
||||
case Daily:
|
||||
getUserData().setInt("DailyTotal", value);
|
||||
break;
|
||||
case Monthly:
|
||||
if (Config.getInstance().isLimitMonthlyVotes()) {
|
||||
LocalDateTime time = TimeChecker.getInstance().getTime();
|
||||
int days = YearMonth.of(time.getYear(), time.getMonth()).lengthOfMonth();
|
||||
if (value >= days * plugin.getVoteSites().size()) {
|
||||
value = days * plugin.getVoteSites().size();
|
||||
}
|
||||
case AllTime:
|
||||
getUserData().setInt("AllTimeTotal", value);
|
||||
break;
|
||||
case Daily:
|
||||
getUserData().setInt("DailyTotal", value);
|
||||
break;
|
||||
case Monthly:
|
||||
if (plugin.getConfigFile().isLimitMonthlyVotes()) {
|
||||
LocalDateTime time = plugin.getTimeChecker().getTime();
|
||||
int days = YearMonth.of(time.getYear(), time.getMonth()).lengthOfMonth();
|
||||
if (value >= days * plugin.getVoteSites().size()) {
|
||||
value = days * plugin.getVoteSites().size();
|
||||
}
|
||||
getData().setInt("MonthTotal", value);
|
||||
break;
|
||||
case Weekly:
|
||||
getUserData().setInt("WeeklyTotal", value);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
getData().setInt("MonthTotal", value);
|
||||
break;
|
||||
case Weekly:
|
||||
getUserData().setInt("WeeklyTotal", value);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1002,6 +1018,253 @@ public class User extends com.Ben12345rocks.AdvancedCore.UserManager.User {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public String voteCommandLastDate(VoteSite voteSite) {
|
||||
long time = getTime(voteSite);
|
||||
if (time > 0) {
|
||||
Date date = new Date(time);
|
||||
String timeString = new SimpleDateFormat(plugin.getConfigFile().getFormatTimeFormat()).format(date);
|
||||
if (StringParser.getInstance().containsIgnorecase(timeString, "YamlConfiguration")) {
|
||||
plugin.getLogger().warning("Detected issue parsing time, check time format");
|
||||
}
|
||||
return timeString;
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
public String voteCommandLastDuration(VoteSite voteSite) {
|
||||
long time = getTime(voteSite);
|
||||
if (time > 0) {
|
||||
LocalDateTime now = LocalDateTime.now();
|
||||
LocalDateTime lastVote = LocalDateTime.ofInstant(Instant.ofEpochMilli(time), ZoneId.systemDefault());
|
||||
|
||||
Duration dur = Duration.between(lastVote, now);
|
||||
|
||||
long diffSecond = dur.getSeconds();
|
||||
int diffDays = (int) (diffSecond / 60 / 60 / 24);
|
||||
int diffHours = (int) (diffSecond / 60 / 60 - diffDays * 24);
|
||||
int diffMinutes = (int) (diffSecond / 60 - diffHours * 60 - diffDays * 24 * 60);
|
||||
int diffSeconds = (int) (diffSecond - diffMinutes * 60 - diffHours * 60 * 60 - diffDays * 24 * 60 * 60);
|
||||
|
||||
String info = "";
|
||||
if (diffDays == 1) {
|
||||
info += StringParser.getInstance()
|
||||
.replacePlaceHolder(StringParser.getInstance().replacePlaceHolder(
|
||||
plugin.getConfigFile().getFormatCommandsVoteLastTimeFormat(), "TimeType",
|
||||
plugin.getConfigFile().getFormatTimeFormatsDay()), "amount", "" + diffDays);
|
||||
info += " ";
|
||||
} else if (diffDays > 1) {
|
||||
info += StringParser.getInstance()
|
||||
.replacePlaceHolder(StringParser.getInstance().replacePlaceHolder(
|
||||
plugin.getConfigFile().getFormatCommandsVoteLastTimeFormat(), "TimeType",
|
||||
plugin.getConfigFile().getFormatTimeFormatsDays()), "amount", "" + diffDays);
|
||||
info += " ";
|
||||
}
|
||||
|
||||
if (diffHours == 1) {
|
||||
info += StringParser.getInstance()
|
||||
.replacePlaceHolder(StringParser.getInstance().replacePlaceHolder(
|
||||
plugin.getConfigFile().getFormatCommandsVoteLastTimeFormat(), "TimeType",
|
||||
plugin.getConfigFile().getFormatTimeFormatsHour()), "amount", "" + diffHours);
|
||||
info += " ";
|
||||
} else if (diffHours > 1) {
|
||||
info += StringParser.getInstance()
|
||||
.replacePlaceHolder(StringParser.getInstance().replacePlaceHolder(
|
||||
plugin.getConfigFile().getFormatCommandsVoteLastTimeFormat(), "TimeType",
|
||||
plugin.getConfigFile().getFormatTimeFormatsHours()), "amount", "" + diffHours);
|
||||
info += " ";
|
||||
}
|
||||
|
||||
if (diffMinutes == 1) {
|
||||
info += StringParser.getInstance().replacePlaceHolder(StringParser.getInstance().replacePlaceHolder(
|
||||
plugin.getConfigFile().getFormatCommandsVoteLastTimeFormat(), "TimeType",
|
||||
plugin.getConfigFile().getFormatTimeFormatsMinute()), "amount", "" + diffMinutes);
|
||||
info += " ";
|
||||
} else if (diffMinutes > 1) {
|
||||
info += StringParser.getInstance().replacePlaceHolder(StringParser.getInstance().replacePlaceHolder(
|
||||
plugin.getConfigFile().getFormatCommandsVoteLastTimeFormat(), "TimeType",
|
||||
plugin.getConfigFile().getFormatTimeFormatsMinutes()), "amount", "" + diffMinutes);
|
||||
info += " ";
|
||||
}
|
||||
|
||||
if (diffSeconds == 1) {
|
||||
info += StringParser.getInstance().replacePlaceHolder(StringParser.getInstance().replacePlaceHolder(
|
||||
plugin.getConfigFile().getFormatCommandsVoteLastTimeFormat(), "TimeType",
|
||||
plugin.getConfigFile().getFormatTimeFormatsSecond()), "amount", "" + diffSeconds);
|
||||
} else {
|
||||
info += StringParser.getInstance().replacePlaceHolder(StringParser.getInstance().replacePlaceHolder(
|
||||
plugin.getConfigFile().getFormatCommandsVoteLastTimeFormat(), "TimeType",
|
||||
plugin.getConfigFile().getFormatTimeFormatsSeconds()), "amount", "" + diffSeconds);
|
||||
}
|
||||
|
||||
info = StringParser.getInstance()
|
||||
.replacePlaceHolder(plugin.getConfigFile().getFormatCommandsVoteLastLastVoted(), "times", info);
|
||||
|
||||
return info;
|
||||
}
|
||||
return plugin.getConfigFile().getFormatCommandsVoteLastNeverVoted();
|
||||
}
|
||||
|
||||
public String voteCommandLastLine(VoteSite voteSite) {
|
||||
String timeString = voteCommandLastDate(voteSite);
|
||||
String timeSince = voteCommandLastDuration(voteSite);
|
||||
|
||||
HashMap<String, String> placeholders = new HashMap<String, String>();
|
||||
placeholders.put("time", timeString);
|
||||
placeholders.put("SiteName", voteSite.getDisplayName());
|
||||
placeholders.put("timesince", timeSince);
|
||||
|
||||
return StringParser.getInstance().replacePlaceHolder(plugin.getConfigFile().getFormatCommandsVoteLastLine(),
|
||||
placeholders);
|
||||
}
|
||||
|
||||
public String voteCommandNextInfo(VoteSite voteSite) {
|
||||
String info = new String();
|
||||
|
||||
long time = getTime(voteSite);
|
||||
LocalDateTime now = plugin.getTimeChecker().getTime();
|
||||
;
|
||||
LocalDateTime lastVote = LocalDateTime.ofInstant(Instant.ofEpochMilli(time), ZoneId.systemDefault())
|
||||
.plusHours(VotingPluginMain.plugin.getOptions().getTimeHourOffSet());
|
||||
|
||||
if (!voteSite.isVoteDelayDaily()) {
|
||||
double votedelay = voteSite.getVoteDelay();
|
||||
if (votedelay == 0 && voteSite.getVoteDelayMin() == 0) {
|
||||
String errorMsg = plugin.getConfigFile().getFormatCommandsVoteNextInfoError();
|
||||
info = errorMsg;
|
||||
} else {
|
||||
|
||||
LocalDateTime nextvote = lastVote.plusHours((long) votedelay)
|
||||
.plusMinutes((long) voteSite.getVoteDelayMin());
|
||||
|
||||
if (time == 0 || now.isAfter(nextvote)) {
|
||||
info = plugin.getConfigFile().getFormatCommandsVoteNextInfoCanVote();
|
||||
} else {
|
||||
Duration dur = Duration.between(now, nextvote);
|
||||
|
||||
long diffHours = dur.getSeconds() / (60 * 60);
|
||||
long diffMinutes = dur.getSeconds() / 60 - diffHours * 60;
|
||||
|
||||
String timeMsg = plugin.getConfigFile().getFormatCommandsVoteNextInfoTime();
|
||||
timeMsg = StringParser.getInstance().replaceIgnoreCase(timeMsg, "%hours%",
|
||||
Long.toString(diffHours));
|
||||
timeMsg = StringParser.getInstance().replaceIgnoreCase(timeMsg, "%minutes%",
|
||||
Long.toString(diffMinutes));
|
||||
info = timeMsg;
|
||||
|
||||
}
|
||||
}
|
||||
} else {
|
||||
LocalDateTime offsetoclockyesterday = plugin.getTimeChecker().getTime().plusDays(-1).withHour(0)
|
||||
.withMinute(0).plusHours((long) voteSite.getTimeOffSet());
|
||||
LocalDateTime offsetoclocktoday = plugin.getTimeChecker().getTime().withHour(0).withMinute(0)
|
||||
.plusHours((long) voteSite.getTimeOffSet());
|
||||
LocalDateTime offsetoclocktomorrow = plugin.getTimeChecker().getTime().plusDays(1).withHour(0).withMinute(0)
|
||||
.plusHours((long) voteSite.getTimeOffSet());
|
||||
|
||||
if (!now.isBefore(offsetoclocktoday)) {
|
||||
if (!lastVote.isBefore(offsetoclocktoday)) {
|
||||
Duration dur = Duration.between(now, offsetoclocktomorrow);
|
||||
int diffHours = (int) (dur.getSeconds() / (60 * 60));
|
||||
long diffMinutes = dur.getSeconds() / 60 - diffHours * 60;
|
||||
|
||||
if (diffHours < 0) {
|
||||
diffHours = diffHours * -1;
|
||||
}
|
||||
if (diffHours >= 24) {
|
||||
diffHours = diffHours - 24;
|
||||
}
|
||||
if (diffMinutes < 0) {
|
||||
diffMinutes = diffMinutes * -1;
|
||||
}
|
||||
|
||||
String timeMsg = plugin.getConfigFile().getFormatCommandsVoteNextInfoVoteDelayDaily();
|
||||
timeMsg = StringParser.getInstance().replaceIgnoreCase(timeMsg, "%hours%",
|
||||
Integer.toString(diffHours));
|
||||
timeMsg = StringParser.getInstance().replaceIgnoreCase(timeMsg, "%minutes%",
|
||||
Long.toString(diffMinutes));
|
||||
info = timeMsg;
|
||||
} else {
|
||||
info = plugin.getConfigFile().getFormatCommandsVoteNextInfoCanVote();
|
||||
}
|
||||
} else {
|
||||
if (!lastVote.isBefore(offsetoclockyesterday)) {
|
||||
Duration dur = Duration.between(now, offsetoclocktoday);
|
||||
int diffHours = (int) (dur.getSeconds() / (60 * 60));
|
||||
long diffMinutes = dur.getSeconds() / 60 - diffHours * 60;
|
||||
|
||||
if (diffHours < 0) {
|
||||
diffHours = diffHours * -1;
|
||||
}
|
||||
if (diffHours >= 24) {
|
||||
diffHours = diffHours - 24;
|
||||
}
|
||||
if (diffMinutes < 0) {
|
||||
diffMinutes = diffMinutes * -1;
|
||||
}
|
||||
|
||||
String timeMsg = plugin.getConfigFile().getFormatCommandsVoteNextInfoVoteDelayDaily();
|
||||
timeMsg = StringParser.getInstance().replaceIgnoreCase(timeMsg, "%hours%",
|
||||
Integer.toString(diffHours));
|
||||
timeMsg = StringParser.getInstance().replaceIgnoreCase(timeMsg, "%minutes%",
|
||||
Long.toString(diffMinutes));
|
||||
info = timeMsg;
|
||||
} else {
|
||||
info = plugin.getConfigFile().getFormatCommandsVoteNextInfoCanVote();
|
||||
}
|
||||
}
|
||||
}
|
||||
return info;
|
||||
}
|
||||
|
||||
public long voteNextDurationTime(VoteSite voteSite) {
|
||||
long time = getTime(voteSite);
|
||||
LocalDateTime now = plugin.getTimeChecker().getTime();
|
||||
;
|
||||
LocalDateTime lastVote = LocalDateTime.ofInstant(Instant.ofEpochMilli(time), ZoneId.systemDefault())
|
||||
.plusHours(VotingPluginMain.plugin.getOptions().getTimeHourOffSet());
|
||||
|
||||
if (!voteSite.isVoteDelayDaily()) {
|
||||
double votedelay = voteSite.getVoteDelay();
|
||||
if (votedelay == 0 && voteSite.getVoteDelayMin() == 0) {
|
||||
return 0;
|
||||
} else {
|
||||
LocalDateTime nextvote = lastVote.plusHours((long) votedelay)
|
||||
.plusMinutes((long) voteSite.getVoteDelayMin());
|
||||
|
||||
if (time == 0 || now.isAfter(nextvote)) {
|
||||
return 0;
|
||||
} else {
|
||||
Duration dur = Duration.between(now, nextvote);
|
||||
return dur.getSeconds();
|
||||
}
|
||||
}
|
||||
} else {
|
||||
LocalDateTime offsetoclockyesterday = plugin.getTimeChecker().getTime().plusDays(-1).withHour(0)
|
||||
.withMinute(0).plusHours((long) voteSite.getTimeOffSet());
|
||||
LocalDateTime offsetoclocktoday = plugin.getTimeChecker().getTime().withHour(0).withMinute(0)
|
||||
.plusHours((long) voteSite.getTimeOffSet());
|
||||
LocalDateTime offsetoclocktomorrow = plugin.getTimeChecker().getTime().plusDays(1).withHour(0).withMinute(0)
|
||||
.plusHours((long) voteSite.getTimeOffSet());
|
||||
|
||||
if (!now.isBefore(offsetoclocktoday)) {
|
||||
if (!lastVote.isBefore(offsetoclocktoday)) {
|
||||
Duration dur = Duration.between(now, offsetoclocktomorrow);
|
||||
return dur.getSeconds();
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
} else {
|
||||
if (!lastVote.isBefore(offsetoclockyesterday)) {
|
||||
Duration dur = Duration.between(now, offsetoclocktoday);
|
||||
return dur.getSeconds();
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public boolean voteStreakUpdatedToday(LocalDateTime time) {
|
||||
return MiscUtils.getInstance().getTime(getDayVoteStreakLastUpdate()).getDayOfYear() == time.getDayOfYear();
|
||||
}
|
||||
Loaded 100 of 102 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user