Compare commits

..
50 Commits
Author SHA1 Message Date
BenCodez 0f50998519 Update version number to 6.1 2021-01-23 18:01:37 -05:00
BenCodez 1768d4490f Command changes 2021-01-23 17:42:21 -05:00
BenCodez 2a3635b805 Add option to main vote gui run on /vote 2021-01-23 16:41:59 -05:00
BenCodez a5be973fd4 Fix back to main GUI button 2021-01-22 21:04:02 -05:00
BenCodez c8a76f38f9 Votetoday back button to votegui bug fix 2021-01-22 20:30:20 -05:00
BenCodez 273edaf101 Little bug fix 2021-01-22 19:12:54 -05:00
BenCodez d1a90676fc Changes to /av perms 2021-01-19 19:40:43 -05:00
BenCodez ff6119050d Add nonvotedplayerscache, allows allowunjoined option on bungee 2021-01-18 17:44:00 -05:00
BenCodez 0a0b95097d Changes to month/week/day changes to reduce impact of server restarts 2021-01-17 16:21:13 -05:00
BenCodez ace42a5a1f Little fixes 2021-01-13 17:11:25 -05:00
BenCodez 1a23648b91 Add package relocation to prevent conflicts 2021-01-09 14:50:00 -05:00
BenCodez 65b5a46525 Changes to permission handling, advanced tab is disabled 2021-01-08 17:34:54 -05:00
BenCodez 462d99c0e5 Little change 2021-01-04 18:57:23 -05:00
BenCodez 04636dd5af Little change 2021-01-03 12:29:38 -05:00
BenCodez d5b5b6cec0 Command changes 2021-01-02 16:47:08 -05:00
BenCodez 921fdac8bb Little change 2020-12-27 17:09:34 -05:00
BenCodez 6b9bc60785 Bug fix 2020-12-27 16:51:25 -05:00
BenCodez ff01c73193 Little changes 2020-12-26 09:14:59 -05:00
BenCodez a6cb4c3a8c Bug fix 2020-12-25 12:43:32 -05:00
BenCodez 43d33277ba Little fix 2020-12-25 11:41:12 -05:00
BenCodez 9badb50075 Little change 2020-12-22 19:44:29 -05:00
BenCodez ad6a09ba85 Bug fix 2020-12-22 16:58:55 -05:00
BenCodez 1791ec5e46 Merge branch 'master' of https://github.com/BenCodez/VotingPlugin 2020-12-22 16:57:24 -05:00
BenCodez 46457a9e61 Update version number 2020-12-22 16:56:23 -05:00
Ben 38ab221fd8 Little bug fix 2020-12-22 05:39:59 -05:00
BenCodez fc2317655e Change default option 2020-12-21 20:12:52 -05:00
BenCodez fb183b9f1f Add option 2020-12-21 18:40:49 -05:00
BenCodez 64057723b6 Update version number 2020-12-19 17:51:20 -05:00
BenCodez 703662c0c0 Bug fix 2020-12-19 17:51:01 -05:00
BenCodez ac72b47362 Update version number 2020-12-19 16:57:43 -05:00
BenCodez 6ca0e26e9c Add per shop message for purchases 2020-12-19 16:45:59 -05:00
BenCodez 168f2fbce2 Improvements 2020-12-17 19:21:51 -05:00
BenCodez a45370011e Little change 2020-12-14 16:58:21 -05:00
BenCodez f85c97f50a Bug fix 2020-12-09 17:14:01 -05:00
BenCodez 1651f8b626 Add option 2020-12-08 21:27:31 -05:00
BenCodez ad08e4cfcf Little fix 2020-12-06 12:08:17 -05:00
BenCodez 91ec3456f5 Little change 2020-12-06 12:02:36 -05:00
BenCodez 4c4f0ef6ae Add per vote shop purchase confirmations 2020-11-30 19:04:51 -05:00
BenCodez 17a899407d Update version number 2020-11-27 20:46:01 -05:00
BenCodez 1a194c684d Little change 2020-11-27 17:03:01 -05:00
BenCodez 93e06e431d Bug fix 2020-11-26 16:47:06 -05:00
BenCodez 8fede65b79 Little change 2020-11-25 21:23:44 -05:00
BenCodez 601d23d5cc Undo 2020-11-25 20:50:38 -05:00
BenCodez 536bacb96a Deprecate class 2020-11-25 19:55:39 -05:00
BenCodez 07b4c36490 Temp change to support plugins until update 2020-11-25 19:51:08 -05:00
BenCodez 39a86b824e Change default option 2020-11-24 19:01:04 -05:00
BenCodez 204c17affc Bug fix 2020-11-24 18:58:54 -05:00
BenCodez ff92dccf47 Bug fix 2020-11-24 18:54:50 -05:00
BenCodez ec69a4db70 Bug fix 2020-11-24 17:08:48 -05:00
Ben c9e0880ce9 Update README.md 2020-11-23 17:48:28 -05:00
34 changed files with 705 additions and 172 deletions

No files matched your search

+1 -1
View File
@@ -18,7 +18,7 @@ https://github.com/Ben12345rocks/VotingPlugin/blob/master/VotingPlugin/Resources
</repository>
<dependency>
<groupId>com.github.Ben12345rocks</groupId>
<groupId>com.github.BenCodez</groupId>
<artifactId>VotingPlugin</artifactId>
<version>LATEST</version>
<scope>provided</scope>
@@ -28,6 +28,10 @@ BungeeDebug: false
# If false you need to enable
BungeeBroadcast: false
# If true & AllowUnJoined is false (Config.yml) it will remove any invalid players
# Not fully tested, could cause some trouble in some cases
RemoveInvalidUsers: false
# What server this is in bungee (must match)
# Also can be applied to rewards
Server: PleaseSet
+17 -4
View File
@@ -288,7 +288,7 @@ Format:
Amount: 1
Name: '&aNext Page'
InvFull: '&cInventory full, dropping items on ground'
InvFull: '&cInventory full'
# Display text
# Used in /vote top (GUI)
@@ -343,6 +343,15 @@ StoreTopVoters:
# Most of these values can be left untouched for most setups
# ------------------------------------------------
# If false, votestreaks will be disabled
UseVoteStreaks: true
# If false, storing best totals will be disabled
UseHighestTotals: true
# If true, /vote will open /vote gui by default
UseVoteGUIMainCommand: false
# Number of points to give on vote
# Set to 0 to give no points
PointsOnVote: 1
@@ -351,6 +360,10 @@ PointsOnVote: 1
# Not really recommended
AddTotals: true
# If true, items given for rewards are dropped on the ground
# If false, items will be given when there is space
DropOnFullInv: true
# Click sound when using gui
# Set to none for no sound
ClickSound:
@@ -362,9 +375,9 @@ ClickSound:
# case sensitive
VotingBroadcastBlacklist: []
# Set to false to prevent javascript
# parsing on placeholderapi placeholders
UseJavascriptPlaceholders: true
# When enabled, javascript will be parsed on placeholders (from placeholderapi)
# allows more fancy placeholders with math for example
UseJavascriptPlaceholders: false
# Limit monthly votes to number of days of a month multipled by the number of sites
LimitMonthlyVotes: false
+5 -1
View File
@@ -4,7 +4,7 @@
#
# GUI Methods:
# - BOOK
# - GUI
# - CHEST
# - CHAT (Disables GUI)
GUIMethod:
Today: CHEST #BOOK not available (future update?)
@@ -276,6 +276,10 @@ CHEST:
Permission: ''
# Whether or not to keep GUI open after purchase
CloseGUI: true
# Require confirmation on purchase, overrides global option above
RequireConfirmation: false
# Overrides other purchase message
#PurchaseMessage: 'Thanks for the purchase'
# Limit how many times you can buy this
#Limit: 3
# Reset limit daily/weekly/monthly
@@ -15,6 +15,9 @@ AllSites:
Messages:
Player: '&aYou voted on all sites in 1 day!'
# NOTE: This is not a 1 time reward, that's what milestones are for!
# If total votes (Can be changed) divided by cumulative amount
# and as no remainder (So divides perfectly)then a reward is given
Cumulative:
# Number of votes required
# Allows multiple cumulative rewards
@@ -42,6 +45,7 @@ VoteParty:
#IncreaseVotesRquired: 10
# If true, players who did not vote to reach the votes required will
# recieve the reward
# If false, only players who voted get rewards
GiveAllPlayers: false
# If true, the vote count will reset each day
ResetEachDay: false
@@ -62,6 +66,8 @@ VoteParty:
Commands: []
# Rewards to give per player
Rewards:
# Uncomment below for online player rewards only
#RewardType: ONLINE
Commands:
- say %player%
Items:
@@ -72,6 +78,7 @@ VoteParty:
# Reset milestones at end of the month
ResetMilestonesMonthly: false
# One time reward to be given (unless you reset it somehow)
MileStones:
# Number of votes required
# Allows multiple milestones
@@ -143,6 +150,8 @@ LoginRewards: []
# Will queue until player logs in unless forceoffline is enabled
LogoutRewards: []
EnableMonthlyAwards: true
# Rewards to give
MonthlyAwards:
# Position. 1 is first in top voter, 2 is second, etc...
+6
View File
@@ -101,6 +101,12 @@ VoteSites:
Fallback:
Messages:
Player: 'You got unlucky'
# Give 1 diamond
Items:
item1:
Material: DIAMOND
Amount: 1
Messages:
Player: 'You voted'
+2
View File
@@ -40,6 +40,8 @@ BungeeMethod: PLUGINMESSAGING
FallBackServer: factions
AllowUnJoined: false
# ----------------------------
# SOCKET METHOD Settings
# ----------------------------
+19 -11
View File
@@ -112,9 +112,6 @@ commands:
adminvoteconfig:
description: Command Alias
aliases: avconfig
adminvotesettotal:
description: Command Alias
aliases: avsettotal
adminvoteupdatecheck:
description: Command Alias
aliases: avupdatecheck
@@ -127,9 +124,6 @@ commands:
adminvotegivereward:
description: Command Alias
aliases: avgivereward
adminvoteusers:
description: Command Alias
aliases: avusers
adminvoteConvertFromData:
description: Command Alias
aliases: avConvertFromData
@@ -141,15 +135,26 @@ commands:
adminvoteClearCache:
description: Command Alias
aliases: avClearCache
adminvoteConvertFrom:
description: Command Alias
aliases: avConvertFrom
adminvoteServiceSites:
description: Command Alias
aliases: avServiceSites
adminvoteSetVotePartyCount:
description: Command Alias
aliases: avSetVotePartyCount
adminvoteChoices:
description: Command Alias
aliases: avChoices
adminvoteReloadAll:
description: Command Alias
aliases: avReloadAll
adminvotePermsPlayer:
description: Command Alias
aliases: avPermsPlayer
adminvoteResyncMilestonesAlreadyGiven:
description: Command Alias
aliases: avResyncMilestonesAlreadyGiven
voteSetPrimaryAccount:
description: Command Alias
adminvoteClearOfflineVotes:
description: Command Alias
aliases: avClearOfflineVotes
@@ -218,9 +223,9 @@ permissions:
VotingPlugin.Player:
description: Allows basic access player commands
VotingPlugin.Mod:
description: Allows mod access player commands
description: Allows mod commands
VotingPlugin.Admin:
description: Allows admin access player commands
description: Allows admincommands
VotingPlugin.Login.RemindVotes:
description: Allows players to get remined on login if they can vote
default: true
@@ -237,4 +242,7 @@ permissions:
description: Permission to create sign
VotingPlugin.Admin.GenerateServiceSite:
description: Permission for generating votesite message
VotingPlugin.Login.RemindVotes.Any:
description: Remind if player can vote on any website, rather than all
default: false
+9 -9
View File
@@ -3,8 +3,8 @@
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.bencodez</groupId>
<artifactId>votingplugin</artifactId>
<version>6.0</version>
<artifactId>VotingPlugin</artifactId>
<version>6.1</version>
<packaging>jar</packaging>
<name>VotingPlugin</name>
<properties>
@@ -106,29 +106,29 @@
other plugins -->
<relocation>
<pattern>com.bencodez.advancedcore</pattern>
<shadedPattern>${project.groupId}.${project.artifactId}.advancedcore</shadedPattern>
<shadedPattern>${project.groupId}.votingplugin.advancedcore</shadedPattern>
</relocation>
<!-- Lets relocate the shaded API so we dont cause any conflicts with
other plugins -->
<relocation>
<pattern>net.pl3x.bukkit.chatapi</pattern>
<shadedPattern>${project.groupId}.${project.artifactId}</shadedPattern>
<shadedPattern>${project.groupId}.votingplugin</shadedPattern>
</relocation>
<relocation>
<pattern>me.mrten.mysqlapi</pattern>
<shadedPattern>${project.groupId}.${project.artifactId}.mysqlapi</shadedPattern>
<shadedPattern>${project.groupId}.votingplugin.mysqlapi</shadedPattern>
</relocation>
<relocation>
<pattern>com.zaxxer.HikariCP</pattern>
<shadedPattern>${project.groupId}.${project.artifactId}.HikariCP</shadedPattern>
<shadedPattern>${project.groupId}.votingplugin.HikariCP</shadedPattern>
</relocation>
<relocation>
<pattern>com.zaxxer.hikari</pattern>
<shadedPattern>${project.groupId}.${project.artifactId}.hikari</shadedPattern>
<shadedPattern>${project.groupId}.votingplugin.hikari</shadedPattern>
</relocation>
<relocation>
<pattern>org.slf4j.slf4j-simple</pattern>
<shadedPattern>${project.groupId}.${project.artifactId}.slf4j-simple</shadedPattern>
<pattern>xyz.upperlevel.spigot.book</pattern>
<shadedPattern>${project.groupId}.votingplugin.upperlevel.book</shadedPattern>
</relocation>
</relocations>
</configuration>
@@ -0,0 +1,30 @@
package com.Ben12345rocks.VotingPlugin.Objects;
import org.bukkit.entity.Player;
import com.bencodez.votingplugin.user.UserManager;
import com.bencodez.votingplugin.user.VotingPluginUser;
@Deprecated
public class User {
private VotingPluginUser user;
public User(Player p) {
user = UserManager.getInstance().getVotingPluginUser(p);
}
public int getPoints() {
return user.getPoints();
}
public void setPoints(int points) {
user.setPoints(points);
}
public void addPoints(int points) {
user.addPoints(points);
}
public boolean removePoints(int points) {
return user.removePoints(points);
}
}
@@ -47,9 +47,9 @@ public class BungeeHandler {
plugin.getLogger().info("Using BungeeMethod: " + method.toString());
if (method.equals(BungeeMethod.MYSQL)) {
plugin.registerBungeeChannels();
plugin.registerBungeeChannels("vp:vp");
} else if (method.equals(BungeeMethod.PLUGINMESSAGING)) {
plugin.registerBungeeChannels();
plugin.registerBungeeChannels("vp:vp");
plugin.getPluginMessaging().add(new PluginMessageHandler("Vote") {
@Override
@@ -66,7 +66,6 @@ import com.bencodez.votingplugin.config.SpecialRewardsConfig;
import com.bencodez.votingplugin.cooldown.CoolDownCheck;
import com.bencodez.votingplugin.data.ServerData;
import com.bencodez.votingplugin.listeners.BlockBreak;
import com.bencodez.votingplugin.listeners.PlayerCommandSendListener;
import com.bencodez.votingplugin.listeners.PlayerInteract;
import com.bencodez.votingplugin.listeners.PlayerJoinEvent;
import com.bencodez.votingplugin.listeners.PlayerVoteListener;
@@ -899,9 +898,9 @@ public class VotingPluginMain extends AdvancedCorePlugin {
pm.registerEvents(new BlockBreak(this), this);
pm.registerEvents(new PlayerInteract(this), this);
pm.registerEvents(new VotingPluginUpdateEvent(this), this);
if (!NMSManager.getInstance().isVersion("1.12")) {
/*if (!NMSManager.getInstance().isVersion("1.12")) {
pm.registerEvents(new PlayerCommandSendListener(this), this);
}
}*/
coolDownCheck = new CoolDownCheck(this);
pm.registerEvents(coolDownCheck, this);
@@ -28,6 +28,10 @@ public class Config {
public boolean getBroadcast() {
return getData().getBoolean("Broadcast", false);
}
public boolean getAllowUnJoined() {
return getData().getBoolean("AllowUnJoined",false);
}
public String getBungeeHost() {
return getData().getString("BungeeServer.Host", "");
@@ -0,0 +1,94 @@
package com.bencodez.votingplugin.bungee;
import java.io.File;
import java.io.IOException;
import lombok.Getter;
import net.md_5.bungee.api.connection.ProxiedPlayer;
import net.md_5.bungee.config.Configuration;
import net.md_5.bungee.config.ConfigurationProvider;
import net.md_5.bungee.config.YamlConfiguration;
public class NonVotedPlayersCache {
private VotingPluginBungee bungee;
@Getter
private Configuration data;
public NonVotedPlayersCache(VotingPluginBungee bungee) {
this.bungee = bungee;
}
public void addPlayer(ProxiedPlayer proxiedPlayer) {
if (!bungee.getMysql().containsKeyQuery(proxiedPlayer.getUniqueId().toString())) {
addPlayer(proxiedPlayer.getUniqueId().toString(), proxiedPlayer.getName());
}
}
private void addPlayer(String uuid, String playerName) {
getData().set("NonVotedPlayers." + playerName + ".UUID", uuid);
getData().set("NonVotedPlayers." + playerName + ".LastTime", System.currentTimeMillis());
}
public String playerExists(String playerName) {
if (getData().getSection("NonVotedPlayers").getKeys().contains(playerName)) {
return getData().getString("NonVotedPlayers." + playerName + ".UUID", "");
}
return "";
}
private void remove(String player) {
bungee.debug("Removing nonvotedplayer: " + player);
getData().set("NonVotedPlayers." + player, null);
}
public void check() {
for (String player : getData().getSection("NonVotedPlayers").getKeys()) {
long time = getData().getLong("NonVotedPlayers." + player + ".LastTime", 0);
if ((System.currentTimeMillis() - time) > 1000 * 60 * 60 * 24 * 5) {
remove(player);
} else {
String uuid = getData().getString("NonVotedPlayers." + player + ".UUID", "");
if (!uuid.isEmpty()) {
if (bungee.getMysql().containsKeyQuery(uuid)) {
remove(player);
}
} else {
remove(player);
}
}
}
save();
}
public void load() {
if (!bungee.getDataFolder().exists()) {
bungee.getDataFolder().mkdir();
}
File file = new File(bungee.getDataFolder(), "nonvotedplayerscache.yml");
if (!file.exists()) {
try {
file.createNewFile();
} catch (IOException e) {
e.printStackTrace();
}
}
try {
data = ConfigurationProvider.getProvider(YamlConfiguration.class)
.load(new File(bungee.getDataFolder(), "nonvotedplayerscache.yml"));
} catch (IOException e) {
e.printStackTrace();
}
}
public void save() {
try {
ConfigurationProvider.getProvider(YamlConfiguration.class).save(data,
new File(bungee.getDataFolder(), "nonvotedplayerscache.yml"));
} catch (IOException e) {
e.printStackTrace();
}
}
}
@@ -37,6 +37,7 @@ import net.md_5.bungee.api.CommandSender;
import net.md_5.bungee.api.config.ServerInfo;
import net.md_5.bungee.api.connection.ProxiedPlayer;
import net.md_5.bungee.api.event.PluginMessageEvent;
import net.md_5.bungee.api.event.PostLoginEvent;
import net.md_5.bungee.api.event.ServerConnectedEvent;
import net.md_5.bungee.api.plugin.Plugin;
import net.md_5.bungee.config.Configuration;
@@ -65,6 +66,8 @@ public class VotingPluginBungee extends Plugin implements net.md_5.bungee.api.pl
private VoteCache voteCacheFile;
private NonVotedPlayersCache nonVotedPlayersCache;
public void checkCachedVotes(String server) {
if (getProxy().getServerInfo(server) != null) {
if (!getProxy().getServerInfo(server).getPlayers().isEmpty()) {
@@ -147,6 +150,9 @@ public class VotingPluginBungee extends Plugin implements net.md_5.bungee.api.pl
if (str != null) {
return str;
}
if (nonVotedPlayersCache != null) {
return nonVotedPlayersCache.playerExists(playerName);
}
return "";
}
@@ -170,7 +176,7 @@ public class VotingPluginBungee extends Plugin implements net.md_5.bungee.api.pl
return num;
}
}
return -1;
return 0;
}
private int mysqlUpdate(ArrayList<Column> cols, String uuid, String column, int toAdd) {
@@ -199,6 +205,7 @@ public class VotingPluginBungee extends Plugin implements net.md_5.bungee.api.pl
num++;
}
}
nonVotedPlayersCache.save();
}
}
@@ -240,12 +247,15 @@ public class VotingPluginBungee extends Plugin implements net.md_5.bungee.api.pl
method = BungeeMethod.getByName(config.getBungeeMethod());
if (method.equals(BungeeMethod.MYSQL)) {
this.getProxy().registerChannel("VotingPlugin:VotingPlugin".toLowerCase());
this.getProxy().registerChannel("vp:vp");
} else if (method.equals(BungeeMethod.PLUGINMESSAGING)) {
voteCacheFile = new VoteCache(this);
voteCacheFile.load();
nonVotedPlayersCache = new NonVotedPlayersCache(this);
nonVotedPlayersCache.load();
try {
for (String server : voteCacheFile.getServers()) {
ArrayList<OfflineBungeeVote> vote = new ArrayList<OfflineBungeeVote>();
@@ -292,7 +302,18 @@ public class VotingPluginBungee extends Plugin implements net.md_5.bungee.api.pl
}
}, 15l, TimeUnit.SECONDS);
this.getProxy().registerChannel("VotingPlugin:VotingPlugin".toLowerCase());
getProxy().getScheduler().schedule(this, new Runnable() {
@Override
public void run() {
if (nonVotedPlayersCache != null) {
debug("Checking nonvotedplayers.yml...");
nonVotedPlayersCache.check();
}
}
}, 1l, 60l, TimeUnit.MINUTES);
this.getProxy().registerChannel("vp:vp");
} else if (method.equals(BungeeMethod.SOCKETS)) {
encryptionHandler = new EncryptionHandler(new File(getDataFolder(), "secretkey.key"));
@@ -352,7 +373,7 @@ public class VotingPluginBungee extends Plugin implements net.md_5.bungee.api.pl
@EventHandler
public void onPluginMessage(PluginMessageEvent ev) {
if (!ev.getTag().equals("VotingPlugin:VotingPlugin".toLowerCase())) {
if (!ev.getTag().equals("vp:vp".toLowerCase())) {
return;
}
ByteArrayInputStream instream = new ByteArrayInputStream(ev.getData());
@@ -369,8 +390,7 @@ public class VotingPluginBungee extends Plugin implements net.md_5.bungee.api.pl
}
for (String send : getProxy().getServers().keySet()) {
if (getProxy().getServers().get(send).getPlayers().size() > 0) {
getProxy().getServers().get(send).sendData("VotingPlugin:VotingPlugin".toLowerCase(),
outstream.toByteArray());
getProxy().getServers().get(send).sendData("vp:vp".toLowerCase(), outstream.toByteArray());
}
}
} catch (Exception e) {
@@ -378,6 +398,13 @@ public class VotingPluginBungee extends Plugin implements net.md_5.bungee.api.pl
}
}
@EventHandler
public void onLogin(PostLoginEvent event) {
if (nonVotedPlayersCache != null) {
nonVotedPlayersCache.addPlayer(event.getPlayer());
}
}
@EventHandler
public void onServerConnected(ServerConnectedEvent event) {
final String server = event.getServer().getInfo().getName();
@@ -434,8 +461,7 @@ public class VotingPluginBungee extends Plugin implements net.md_5.bungee.api.pl
out.writeUTF(message);
}
if (getProxy().getServers().get(server).getPlayers().size() > 0) {
getProxy().getServers().get(server).sendData("VotingPlugin:VotingPlugin".toLowerCase(),
byteOutStream.toByteArray(), false);
getProxy().getServers().get(server).sendData("vp:vp".toLowerCase(), byteOutStream.toByteArray(), false);
}
out.close();
} catch (Exception e) {
@@ -503,17 +529,24 @@ public class VotingPluginBungee extends Plugin implements net.md_5.bungee.api.pl
} else if (method.equals(BungeeMethod.PLUGINMESSAGING)) {
String uuid = getUUID(player);
if (uuid.isEmpty()) {
UUID u = null;
try {
u = fetchUUID(player);
} catch (Exception e) {
e.printStackTrace();
}
if (u == null) {
debug("Failed to get uuid for " + player);
if (config.getAllowUnJoined()) {
UUID u = null;
try {
u = fetchUUID(player);
} catch (Exception e) {
if (getConfig().getDebug()) {
e.printStackTrace();
}
}
if (u == null) {
debug("Failed to get uuid for " + player);
return;
}
uuid = u.toString();
} else {
getLogger().info("Ignoring vote from " + player);
return;
}
uuid = u.toString();
}
player = getProperName(uuid, player);
@@ -6,6 +6,7 @@ import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Set;
import java.util.regex.Pattern;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
@@ -14,6 +15,7 @@ import org.bukkit.command.CommandSender;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.bukkit.permissions.Permission;
import com.bencodez.advancedcore.DebugLevel;
import com.bencodez.advancedcore.api.command.CommandHandler;
@@ -401,12 +403,21 @@ public class CommandLoader {
@Override
public void execute(CommandSender sender, String[] args) {
new AdminVotePerms(plugin, sender).open();
new AdminVotePerms(plugin, sender, 1).open();
}
});
plugin.getAdminVoteCommand().add(new CommandHandler(new String[] { "Perms", "(Number)" },
"VotingPlugin.Commands.AdminVote.Perms|" + adminPerm, "List permissions") {
@Override
public void execute(CommandSender sender, String[] args) {
new AdminVotePerms(plugin, sender, Integer.parseInt(args[1])).open();
}
});
plugin.getAdminVoteCommand()
.add(new CommandHandler(new String[] { "Perms", "(Player)" },
.add(new CommandHandler(new String[] { "PermsPlayer", "(Player)" },
"VotingPlugin.Commands.AdminVote.Perms.Other|" + adminPerm,
"List permissions from the plugin the player has") {
@@ -417,7 +428,7 @@ public class CommandLoader {
});
plugin.getAdminVoteCommand()
.add(new CommandHandler(new String[] { "Perms", "(Player)", "(Number)" },
.add(new CommandHandler(new String[] { "PermsPlayer", "(Player)", "(Number)" },
"VotingPlugin.Commands.AdminVote.Perms.Other|" + adminPerm,
"List permissions from the plugin the player has") {
@@ -427,6 +438,29 @@ public class CommandLoader {
}
});
plugin.getAdminVoteCommand()
.add(new CommandHandler(new String[] { "Perms", "(Number)", "(Player)" },
"VotingPlugin.Commands.AdminVote.Perms.Other|" + adminPerm,
"List permissions from the plugin the specificed player has") {
@Override
public void execute(CommandSender sender, String[] args) {
new AdminVotePerms(plugin, sender, Integer.parseInt(args[1]), args[2]).open();
}
});
if (plugin.getOptions().getDebug().equals(DebugLevel.DEV)) {
plugin.getAdminVoteCommand().add(new CommandHandler(new String[] { "PermsDebug" },
"VotingPlugin.Commands.AdminVote.PermsDebug", "Dev permission list, generate this list, requires dev debug") {
@Override
public void execute(CommandSender sender, String[] args) {
sendMessage(sender, ArrayUtils.getInstance()
.convert(new AdminVotePerms(plugin, sender, 0).listPermsDev(sender)));
}
});
}
plugin.getAdminVoteCommand().add(new CommandHandler(new String[] { "Reload" },
"VotingPlugin.Commands.AdminVote.Reload|" + adminPerm, "Reload plugin, will not reload user storage") {
@@ -507,6 +541,7 @@ public class CommandLoader {
});
}
sendMessage(sender,
"Using AdvancedCore " + plugin.getVersion() + "' built on '" + plugin.getBuildTime());
}
@@ -1200,11 +1235,29 @@ public class CommandLoader {
String[] args = cmdHandle.getArgs()[0].split("&");
for (String arg : args) {
commands.put("vote" + arg, cmdHandle);
try {
String[] perms = cmdHandle.getPerm().split(Pattern.quote("|"));
if (perms.length > 1) {
// has another perm
plugin.devDebug("Adding child perm " + perms[0] + " to " + perms[1]);
Permission p = Bukkit.getPluginManager().getPermission(perms[1]);
p.getChildren().put(perms[0], true);
p.recalculatePermissibles();
}
} catch (Exception e) {
plugin.devDebug("Failed to set permission for /vote" + arg);
}
try {
plugin.getCommand("vote" + arg).setExecutor(new CommandAliases(cmdHandle, false));
plugin.getCommand("vote" + arg)
.setTabCompleter(new AliasesTabCompleter().setCMDHandle(cmdHandle, false));
plugin.getCommand("vote" + arg).setPermission(cmdHandle.getPerm().split(Pattern.quote("|"))[0]);
for (String str : plugin.getCommand("vote" + arg).getAliases()) {
commands.put(str, cmdHandle);
}
@@ -1213,6 +1266,20 @@ public class CommandLoader {
}
}
} else {
try {
String[] perms = cmdHandle.getPerm().split(Pattern.quote("|"));
if (perms.length > 1) {
// has another perm
plugin.devDebug("Adding child perm " + perms[0] + " to " + perms[1]);
Permission p = Bukkit.getPluginManager().getPermission(perms[1]);
p.getChildren().put(perms[0], true);
p.recalculatePermissibles();
}
} catch (Exception e) {
plugin.devDebug("Failed to set permission for /vote");
}
}
}
@@ -1221,11 +1288,28 @@ public class CommandLoader {
String[] args = cmdHandle.getArgs()[0].split("&");
for (String arg : args) {
commands.put("adminvote" + arg, cmdHandle);
try {
String[] perms = cmdHandle.getPerm().split(Pattern.quote("|"));
if (perms.length > 1) {
// has another perm
plugin.devDebug("Adding child perm " + perms[0] + " to " + perms[1]);
Permission p = Bukkit.getPluginManager().getPermission(perms[1]);
p.getChildren().put(perms[0], true);
p.recalculatePermissibles();
}
} catch (Exception e) {
plugin.devDebug("Failed to set permission for /adminvote" + arg);
}
try {
plugin.getCommand("adminvote" + arg).setExecutor(new CommandAliases(cmdHandle, true));
plugin.getCommand("adminvote" + arg)
.setTabCompleter(new AliasesTabCompleter().setCMDHandle(cmdHandle, true));
plugin.getCommand("adminvote" + arg)
.setPermission(cmdHandle.getPerm().split(Pattern.quote("|"))[0]);
for (String str : plugin.getCommand("adminvote" + arg).getAliases()) {
commands.put(str, cmdHandle);
}
@@ -1236,6 +1320,20 @@ public class CommandLoader {
}
}
} else {
try {
String[] perms = cmdHandle.getPerm().split(Pattern.quote("|"));
if (perms.length > 1) {
// has another perm
plugin.devDebug("Adding child perm " + perms[0] + " to " + perms[1]);
Permission p = Bukkit.getPluginManager().getPermission(perms[1]);
p.getChildren().put(perms[0], true);
p.recalculatePermissibles();
}
} catch (Exception e) {
plugin.devDebug("Failed to set permission for /vote");
}
}
}
}
@@ -1385,6 +1483,28 @@ public class CommandLoader {
}
});
ArrayList<String> topVoter = new ArrayList<String>();
for (TopVoter top : TopVoter.values()) {
topVoter.add(top.toString());
}
TabCompleteHandler.getInstance().addTabCompleteOption(new TabCompleteHandle("(topvoter)", topVoter) {
@Override
public void reload() {
ArrayList<String> topVoter = new ArrayList<String>();
for (TopVoter top : TopVoter.values()) {
topVoter.add(top.toString());
}
setReplace(topVoter);
}
@Override
public void updateReplacements() {
}
});
TabCompleteHandler.getInstance().addTabCompleteOption(new TabCompleteHandle("(VoteShop)", sites) {
@Override
@@ -1704,6 +1824,34 @@ public class CommandLoader {
}
});
for (final TopVoter top : TopVoter.values()) {
String argName = top.toString();
String perm = top.toString();
if (argName.equals(TopVoter.AllTime.toString())) {
argName = "All";
perm = "All";
}
plugin.getVoteCommand().add(new CommandHandler(new String[] { "Top", argName },
"VotingPlugin.Commands.Vote.Top." + perm + "|" + playerPerm, "Open page of Top Voters") {
@Override
public void execute(CommandSender sender, String[] args) {
new VoteTopVoter(plugin, sender, null, top, 1).open(GUIMethod.CHAT);
}
});
plugin.getVoteCommand().add(new CommandHandler(new String[] { "Top", argName, "(number)" },
"VotingPlugin.Commands.Vote.Top." + perm + "|" + playerPerm, "Open page of Top Voters") {
@Override
public void execute(CommandSender sender, String[] args) {
int page = Integer.parseInt(args[2]);
new VoteTopVoter(plugin, sender, null, top, page).open(GUIMethod.CHAT);
}
});
}
plugin.getVoteCommand().add(new CommandHandler(new String[] { "Top", "(number)" },
"VotingPlugin.Commands.Vote.Top|" + playerPerm, "Open page of Top Voters") {
@@ -1715,47 +1863,6 @@ public class CommandLoader {
}
});
plugin.getVoteCommand().add(new CommandHandler(new String[] { "Top", "(number)", "Monthly" },
"VotingPlugin.Commands.Vote.Top.Monthly|" + playerPerm, "Open page of Top Voters") {
@Override
public void execute(CommandSender sender, String[] args) {
int page = Integer.parseInt(args[1]);
new VoteTopVoter(plugin, sender, null, TopVoter.Monthly, page).open(GUIMethod.CHAT);
}
});
plugin.getVoteCommand().add(new CommandHandler(new String[] { "Top", "(number)", "All" },
"VotingPlugin.Commands.Vote.Top.All|" + playerPerm, "Open page of Top Voters All Time") {
@Override
public void execute(CommandSender sender, String[] args) {
int page = Integer.parseInt(args[1]);
new VoteTopVoter(plugin, sender, null, TopVoter.AllTime, page).open(GUIMethod.CHAT);
}
});
plugin.getVoteCommand().add(new CommandHandler(new String[] { "Top", "(number)", "Weekly" },
"VotingPlugin.Commands.Vote.Top.Weekly|" + playerPerm, "Open page of Top Voters") {
@Override
public void execute(CommandSender sender, String[] args) {
int page = Integer.parseInt(args[1]);
new VoteTopVoter(plugin, sender, null, TopVoter.Weekly, page).open(GUIMethod.CHAT);
}
});
plugin.getVoteCommand().add(new CommandHandler(new String[] { "Top", "(number)", "Daily" },
"VotingPlugin.Commands.Vote.Top.Daily|" + playerPerm, "Open page of Top Voters") {
@Override
public void execute(CommandSender sender, String[] args) {
int page = Integer.parseInt(args[1]);
new VoteTopVoter(plugin, sender, null, TopVoter.Daily, page).open(GUIMethod.CHAT);
}
});
plugin.getVoteCommand()
.add(new CommandHandler(new String[] { "Party" }, "VotingPlugin.Commands.Vote.Party|" + playerPerm,
"View current amount of votes and how many more needed") {
@@ -1929,7 +2036,13 @@ public class CommandLoader {
if (sender instanceof Player) {
user = UserManager.getInstance().getVotingPluginUser((Player) sender);
}
new VoteURL(plugin, sender, user, true).open();
if (plugin.getConfigFile().isUseVoteGUIMainCommand() && sender instanceof Player) {
// vote gui command
new VoteGUI(plugin, sender, user).open();
} else {
new VoteURL(plugin, sender, user, true).open();
}
}
});
@@ -1938,7 +2051,7 @@ public class CommandLoader {
@Override
public void execute(CommandSender sender, String[] args) {
new VoteURL(plugin, sender, null, true).open();
new VoteURL(plugin, sender, null, true).open(GUIMethod.CHAT);
}
});
@@ -1,6 +1,8 @@
package com.bencodez.votingplugin.commands.gui.admin;
import java.util.ArrayList;
import java.util.Set;
import java.util.regex.Pattern;
import org.bukkit.Bukkit;
import org.bukkit.command.CommandSender;
@@ -19,9 +21,10 @@ public class AdminVotePerms extends GUIHandler {
private String playerName;
private VotingPluginMain plugin;
public AdminVotePerms(VotingPluginMain plugin, CommandSender player) {
public AdminVotePerms(VotingPluginMain plugin, CommandSender player, int page) {
super(player);
this.plugin = plugin;
this.page = page;
}
public AdminVotePerms(VotingPluginMain plugin, CommandSender player, int page, String playerName) {
@@ -38,17 +41,18 @@ public class AdminVotePerms extends GUIHandler {
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");
msg.add("&6" + handle.getHelpLineCommand("/vote") + " : "
+ handle.getPerm().split(Pattern.quote("|"))[0] + " : &atrue");
} else {
msg.add("&c" + handle.getHelpLineCommand("/vote") + " : " + handle.getPerm() + " : false");
msg.add("&6" + handle.getHelpLineCommand("/vote") + " : "
+ handle.getPerm().split(Pattern.quote("|"))[0] + " : &cfalse");
}
} else {
msg.add(handle.getHelpLineCommand("/vote") + " : " + handle.getPerm());
msg.add(handle.getHelpLineCommand("/vote") + " : " + handle.getPerm().split(Pattern.quote("|"))[0]);
}
}
@@ -56,30 +60,57 @@ public class AdminVotePerms extends GUIHandler {
for (CommandHandler handle : plugin.getAdminVoteCommand()) {
if (sender instanceof Player) {
if (handle.hasPerm(sender)) {
msg.add("&a" + handle.getHelpLineCommand("/av") + " : " + handle.getPerm() + " : true");
msg.add("&6" + handle.getHelpLineCommand("/av") + " : "
+ handle.getPerm().split(Pattern.quote("|"))[0] + " : &atrue");
} else {
msg.add("&c" + handle.getHelpLineCommand("/av") + " : " + handle.getPerm() + " : false");
msg.add("&6" + handle.getHelpLineCommand("/av") + " : "
+ handle.getPerm().split(Pattern.quote("|"))[0] + " : &cfalse");
}
} else {
msg.add(handle.getHelpLineCommand("/av") + " : " + handle.getPerm());
msg.add(handle.getHelpLineCommand("/av") + " : " + handle.getPerm().split(Pattern.quote("|"))[0]);
}
}
for (Permission perm : plugin.getDescription().getPermissions()) {
if (sender instanceof Player) {
if (sender.hasPermission(perm)) {
msg.add("&a" + perm.getName() + " : true");
Set<String> child = perm.getChildren().keySet();
if (child.size() > 0) {
if (sender.hasPermission(perm)) {
msg.add("&6" + perm.getName() + " : &atrue");
} else {
msg.add("&6" + perm.getName() + " : &cfalse");
}
} else {
msg.add("&c" + perm.getName() + " : false");
if (sender.hasPermission(perm)) {
msg.add("&6" + perm.getName() + " : &atrue");
} else {
msg.add("&6" + perm.getName() + " : &cfalse");
}
}
} else {
msg.add(perm.getName());
}
}
msg = ArrayUtils.getInstance().colorize(msg);
int pagesize = plugin.getConfigFile().getFormatPageSize();
return ArrayUtils.getInstance().convert(msg);
int maxPage = msg.size() / pagesize;
if ((msg.size() % pagesize) != 0) {
maxPage++;
}
ArrayList<String> text = new ArrayList<String>();
text.add("&c&lCommand : Permissions " + page + "/" + maxPage);
for (int i = pagesize * page - pagesize; i < msg.size() && i < pagesize * page; i++) {
text.add(msg.get(i));
}
text = ArrayUtils.getInstance().colorize(text);
return ArrayUtils.getInstance().convert(text);
}
public ArrayList<String> listPerms(CommandSender sender, String player, int page) {
@@ -91,26 +122,39 @@ public class AdminVotePerms extends GUIHandler {
for (CommandHandler handle : plugin.getVoteCommand()) {
if (handle.hasPerm(p)) {
msg.add("&a" + handle.getHelpLineCommand("/vote") + " : " + handle.getPerm() + " : true");
msg.add("&6" + handle.getHelpLineCommand("/vote") + " : "
+ handle.getPerm().split(Pattern.quote("|"))[0] + " : &atrue");
} else {
msg.add("&c" + handle.getHelpLineCommand("/vote") + " : " + handle.getPerm() + " : false");
msg.add("&6" + handle.getHelpLineCommand("/vote") + " : "
+ handle.getPerm().split(Pattern.quote("|"))[0] + " : &cfalse");
}
}
for (CommandHandler handle : plugin.getAdminVoteCommand()) {
if (handle.hasPerm(p)) {
msg.add("&a" + handle.getHelpLineCommand("/av") + " : " + handle.getPerm() + " : true");
msg.add("&6" + handle.getHelpLineCommand("/av") + " : "
+ handle.getPerm().split(Pattern.quote("|"))[0] + " : &atrue");
} else {
msg.add("&c" + handle.getHelpLineCommand("/av") + " : " + handle.getPerm() + " : false");
msg.add("&6" + handle.getHelpLineCommand("/av") + " : "
+ handle.getPerm().split(Pattern.quote("|"))[0] + " : &cfalse");
}
}
for (Permission perm : plugin.getDescription().getPermissions()) {
if (p.hasPermission(perm)) {
msg.add("&a" + perm.getName() + " : true");
Set<String> child = perm.getChildren().keySet();
if (child.size() > 0) {
if (p.hasPermission(perm)) {
msg.add("&6" + perm.getName() + " : &atrue");
} else {
msg.add("&6" + perm.getName() + " : &cfalse");
}
} else {
msg.add("&c" + perm.getName() + " : false");
if (p.hasPermission(perm)) {
msg.add("&6" + perm.getName() + " : &atrue");
} else {
msg.add("&6" + perm.getName() + " : &cfalse");
}
}
}
@@ -123,7 +167,7 @@ public class AdminVotePerms extends GUIHandler {
maxPage++;
}
text.add("&c&lCommand : Permissions (seperated by |) " + page + "/" + maxPage);
text.add("&c&lCommand : Permissions for " + player + " " + page + "/" + maxPage);
for (int i = pagesize * page - pagesize; i < msg.size() && i < pagesize * page; i++) {
text.add(msg.get(i));
@@ -135,6 +179,34 @@ public class AdminVotePerms extends GUIHandler {
}
public String[] listPermsDev(CommandSender sender) {
ArrayList<String> msg = new ArrayList<String>();
msg.add("Command");
msg.add(" Permissions (seperated by |");
msg.add(" Help messasge");
msg.add(" ");
for (CommandHandler handle : plugin.getVoteCommand()) {
msg.add(handle.getHelpLineCommand("/vote"));
msg.add(" " + handle.getPerm());
msg.add(" " + handle.getHelpMessage());
}
for (CommandHandler handle : plugin.getAdminVoteCommand()) {
msg.add(handle.getHelpLineCommand("/av"));
msg.add(" " + handle.getPerm());
msg.add(" " + handle.getHelpMessage());
}
for (Permission perm : plugin.getDescription().getPermissions()) {
msg.add(perm.getName() + " : " + perm.getDescription());
}
msg = ArrayUtils.getInstance().colorize(msg);
return ArrayUtils.getInstance().convert(msg);
}
@Override
public void onBook(Player player) {
}
@@ -62,7 +62,14 @@ public class VoteGUI extends GUIHandler {
lore = plugin.getTopVoterHandler().topVoterAllTime(1);
}
} else if (slot.equalsIgnoreCase("today")) {
lore = new VoteToday(plugin, player, user, 1).voteToday();
String[] today = new VoteToday(plugin, player, user, 1).voteTodayGUI();
ArrayList<String> list = new ArrayList<String>();
if (today.length > 0) {
for (int i = today.length - 1; i < today.length && list.size() < 10 && i >= 0; i--) {
list.add(today[i]);
}
}
lore = ArrayUtils.getInstance().convert(list);
} else if (slot.equalsIgnoreCase("help")) {
lore = new String[] { "Click to view help" };
}
@@ -112,6 +119,9 @@ public class VoteGUI extends GUIHandler {
@Override
public void onChest(Player player) {
if (this.user == null) {
user = UserManager.getInstance().getVotingPluginUser((Player) player);
}
if ((!player.getName().equals(user.getPlayerName())
&& !player.hasPermission("VotingPlugin.Commands.Vote.GUI.Other")
&& !player.hasPermission("VotingPlugin.Mod"))
@@ -106,7 +106,7 @@ public class VoteShop extends GUIHandler {
}
if (limitPass) {
if (!plugin.getGui().isChestVoteShopRequireConfirmation()) {
if (!plugin.getGui().isChestVoteShopRequireConfirmation(identifier)) {
HashMap<String, String> placeholders = new HashMap<String, String>();
placeholders.put("identifier",
plugin.getGui().getChestShopIdentifierIdentifierName(identifier));
@@ -119,7 +119,7 @@ public class VoteShop extends GUIHandler {
new RewardOptions().setPlaceholders(placeholders));
user.sendMessage(StringParser.getInstance().replacePlaceHolder(
plugin.getConfigFile().getFormatShopPurchaseMsg(), placeholders));
plugin.getGui().getCHESTVoteShopPurchase(identifier), placeholders));
if (limit > 0) {
user.setVoteShopIdentifierLimit(identifier,
user.getVoteShopIdentifierLimit(identifier) + 1);
@@ -66,7 +66,7 @@ public class VoteShopConfirm extends GUIHandler {
new RewardOptions().setPlaceholders(placeholders));
user.sendMessage(StringParser.getInstance()
.replacePlaceHolder(plugin.getConfigFile().getFormatShopPurchaseMsg(), placeholders));
.replacePlaceHolder(plugin.getGui().getCHESTVoteShopPurchase(identifier), placeholders));
if (limit > 0) {
user.setVoteShopIdentifierLimit(identifier, user.getVoteShopIdentifierLimit(identifier) + 1);
}
@@ -1,13 +1,13 @@
package com.bencodez.votingplugin.commands.gui.player;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map.Entry;
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;
@@ -17,6 +17,7 @@ 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.api.user.UUID;
import com.bencodez.advancedcore.nms.NMSManager;
import com.bencodez.votingplugin.VotingPluginMain;
import com.bencodez.votingplugin.objects.VoteSite;
@@ -89,19 +90,19 @@ public class VoteToday extends GUIHandler {
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);
item = new ItemBuilder(user.getPlayerHead());
} else {
item = new ItemBuilder(plugin.getGui().getChestVoteTodayPlayerItem());
}
item.setName(StringParser.getInstance().replacePlaceHolder(plugin.getGui().getChestVoteTodayIconTitle(),
"player", user.getPlayerName()));
item.setLore(msg);
final String uuid = user.getUUID();
inv.addButton(inv.getNextSlot(), new BInventoryButton(item) {
@Override
public void onClick(ClickEvent clickEvent) {
VotingPluginUser user = UserManager.getInstance()
.getVotingPluginUser(clickEvent.getClickedItem().getItemMeta().getDisplayName());
VotingPluginUser user = UserManager.getInstance().getVotingPluginUser(new UUID(uuid));
new VoteGUI(plugin, player, user)
.open(GUIMethod.valueOf(plugin.getGui().getGuiMethodGUI().toUpperCase()));
}
@@ -141,4 +142,31 @@ public class VoteToday extends GUIHandler {
return ArrayUtils.getInstance().convert(msg);
}
public String[] voteTodayGUI() {
ArrayList<String> msg = new ArrayList<String>();
for (VotingPluginUser user : plugin.getVoteToday().keySet()) {
LocalDateTime mostRecent = null;
VoteSite mostRecentSite = null;
for (Entry<VoteSite, LocalDateTime> entry : plugin.getVoteToday().get(user).entrySet()) {
if (mostRecent == null || entry.getValue().isAfter(mostRecent)) {
mostRecent = entry.getValue();
mostRecentSite = entry.getKey();
}
}
if (mostRecent != null) {
DateTimeFormatter formatter = DateTimeFormatter.ofPattern(plugin.getConfigFile().getFormatTimeFormat());
String timeString = mostRecent.format(formatter);
HashMap<String, String> placeholders = new HashMap<String, String>();
placeholders.put("player", user.getPlayerName());
placeholders.put("votesite", mostRecentSite.getKey());
placeholders.put("time", timeString);
msg.add(StringParser.getInstance()
.replacePlaceHolder(plugin.getConfigFile().getFormatCommandsVoteTodayLine(), placeholders));
}
}
msg = ArrayUtils.getInstance().colorize(msg);
return ArrayUtils.getInstance().convert(msg);
}
}
@@ -41,7 +41,7 @@ public class VoteURL extends GUIHandler {
if (user == null && player instanceof Player) {
this.user = UserManager.getInstance().getVotingPluginUser((Player) player);
}
if (player.getName().equals(user.getPlayerName())) {
if (player != null && user != null && player.getName().equals(user.getPlayerName())) {
if (plugin.getConfigFile().isUsePrimaryAccountForPlaceholders() && user.hasPrimaryAccount()) {
user = UserManager.getInstance().getVotingPluginUser(user.getPrimaryAccount());
}
@@ -27,7 +27,7 @@ public class BungeeSettings extends YMLFile {
@ConfigDataString(path = "BungeeMethod")
@Getter
private String bungeeMethod = "SOCKETS";
private String bungeeMethod = "PLUGINMESSAGING";
@ConfigDataString(path = "BungeeServer.Host")
@Getter
@@ -37,6 +37,10 @@ public class BungeeSettings extends YMLFile {
@Getter
private int bungeeServerPort = 1297;
@ConfigDataBoolean(path = "RemoveInvalidUsers")
@Getter
private boolean removeInvalidUsers = false;
@ConfigDataString(path = "Server")
@Getter
private String server = "PleaseSet";
@@ -36,6 +36,10 @@ public class Config extends YMLFile {
@Getter
private boolean allowUnjoined = false;
@ConfigDataBoolean(path = "UseVoteGUIMainCommand")
@Getter
private boolean useVoteGUIMainCommand = false;
@ConfigDataBoolean(path = "AllowUnJoinedCheckServer")
@Getter
private boolean allowUnJoinedCheckServer = true;
@@ -217,7 +221,7 @@ public class Config extends YMLFile {
@ConfigDataBoolean(path = "UseJavascriptPlaceholders")
@Getter
private boolean useJavascriptPlaceholders = true;
private boolean useJavascriptPlaceholders = false;
@ConfigDataBoolean(path = "UsePrimaryAccountForPlaceholders")
@Getter
@@ -639,8 +643,16 @@ public class Config extends YMLFile {
return getData().getBoolean("LoadTopVoter.AllTime", true);
}
@ConfigDataBoolean(path = "UseVoteStreaks")
@Getter
private boolean useVoteStreaks = true;
@ConfigDataBoolean(path = "UseHighestTotals")
@Getter
private boolean useHighestTotals = true;
public boolean getLoadTopVoterDaily() {
return getData().getBoolean("LoadTopVoter.Daily");
return getData().getBoolean("LoadTopVoter.Daily", false);
}
public boolean getLoadTopVoterMonthly() {
@@ -648,7 +660,7 @@ public class Config extends YMLFile {
}
public boolean getLoadTopVoterWeekly() {
return getData().getBoolean("LoadTopVoter.Weekly");
return getData().getBoolean("LoadTopVoter.Weekly", false);
}
public int getPointsOnVote() {
@@ -143,6 +143,10 @@ public class GUI extends YMLFile {
private boolean lastMonthGUI = false;
private VotingPluginMain plugin;
public String getCHESTVoteShopPurchase(String identifier) {
return getData().getString("CHEST.Shop." + identifier +".PurchaseMessage", plugin.getConfigFile().getFormatShopPurchaseMsg());
}
public GUI(VotingPluginMain plugin) {
super(plugin, new File(plugin.getDataFolder(), "GUI.yml"));
@@ -497,4 +501,9 @@ public class GUI extends YMLFile {
public void onFileCreation() {
plugin.saveResource("GUI.yml", true);
}
public boolean isChestVoteShopRequireConfirmation(String identifier) {
return getData().getBoolean("CHEST.Shop." + identifier + ".RequireConfirmation",
isChestVoteShopRequireConfirmation());
}
}
@@ -27,7 +27,7 @@ public class SpecialRewardsConfig extends YMLFile {
@ConfigDataBoolean(path = "EnableMonthlyAwards")
@Getter
private boolean enableMonthlyAwards = false;
private boolean enableMonthlyAwards = true;
@ConfigDataBoolean(path = "EnableWeeklyAwards")
@Getter
@@ -4,6 +4,7 @@ import org.bukkit.event.Event;
import org.bukkit.event.HandlerList;
import com.bencodez.votingplugin.objects.VoteSite;
import com.bencodez.votingplugin.user.VotingPluginUser;
import lombok.Getter;
import lombok.Setter;
@@ -65,6 +66,10 @@ public class PlayerVoteEvent extends Event {
@Getter
@Setter
private VoteSite voteSite;
@Getter
@Setter
private VotingPluginUser votingPluginUser;
public PlayerVoteEvent(VoteSite voteSite, String voteUsername, String serviceSite, boolean realVote) {
super(true);
@@ -13,6 +13,7 @@ import com.bencodez.votingplugin.VotingPluginMain;
/**
* The Class PlayerJoinEvent.
*/
@Deprecated
public class PlayerCommandSendListener implements Listener {
@SuppressWarnings("unused")
@@ -49,10 +49,18 @@ public class PlayerVoteListener implements Listener {
if (!plugin.getConfigFile().isAllowUnjoined()) {
plugin.getLogger().warning("Player " + playerName
+ " has not joined before, disregarding vote, set AllowUnjoined to true to prevent this");
if (event.isBungee() && plugin.getBungeeSettings().isRemoveInvalidUsers()) {
UserManager.getInstance().getVotingPluginUser(playerName).remove();
}
return;
}
}
if (playerName.isEmpty()) {
plugin.getLogger().warning("Empty player name for vote");
return;
}
if (event.isBungee()) {
plugin.debug("BungeePlayerVote forcebungee: " + event.isForceBungee() + ", bungeetotals: "
+ event.getBungeeTextTotals());
@@ -64,8 +72,6 @@ public class PlayerVoteListener implements Listener {
if (voteSite == null) {
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");
ArrayList<String> services = new ArrayList<String>();
for (VoteSite site : plugin.getVoteSites()) {
@@ -77,7 +83,12 @@ public class PlayerVoteListener implements Listener {
return;
}
VotingPluginUser user = UserManager.getInstance().getVotingPluginUser(playerName);
VotingPluginUser user = null;
if (event.getVotingPluginUser() != null) {
user = event.getVotingPluginUser();
} else {
user = UserManager.getInstance().getVotingPluginUser(playerName);
}
user.updateName(true);
if (plugin.getConfigFile().isClearCacheOnVote() || plugin.getBungeeSettings().isUseBungeecoord()) {
@@ -133,6 +144,7 @@ public class PlayerVoteListener implements Listener {
if (((user.isOnline() || voteSite.isGiveOffline())
&& VotingPluginMain.plugin.getOptions().isProcessRewards()) || event.isBungee()) {
user.playerVote(voteSite, true, false, event.isForceBungee());
user.sendVoteEffects(true);
user.closeInv();
} else {
user.addOfflineVote(voteSite.getKey());
@@ -60,7 +60,7 @@ public enum TopVoter {
if (next > list.size() - 1) {
next = 0;
}
return TopVoter.values()[next];
return list.get(next);
}
}
return TopVoter.AllTime;
@@ -86,9 +86,25 @@ public enum TopVoter {
if (prev < 0) {
prev = list.size() - 1;
}
return TopVoter.values()[prev];
return list.get(prev);
}
}
return TopVoter.AllTime;
}
public String getColumnName() {
switch (this) {
case AllTime:
return "AllTimeTotal";
case Daily:
return "DailyTotal";
case Monthly:
return "MonthTotal";
case Weekly:
return "WeeklyTotal";
default:
return null;
}
}
}
@@ -24,6 +24,7 @@ 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.user.UserStorage;
import com.bencodez.advancedcore.api.yml.YMLFileHandler;
import com.bencodez.votingplugin.VotingPluginMain;
import com.bencodez.votingplugin.user.UserManager;
@@ -105,6 +106,9 @@ public class TopVoterHandler implements Listener {
plugin.setUpdate(true);
plugin.update();
loadLastMonth();
if (plugin.getStorageType().equals(UserStorage.MYSQL)) {
plugin.getMysql().clearCache();
}
}
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
@@ -112,14 +116,18 @@ public class TopVoterHandler implements Listener {
synchronized (VotingPluginMain.plugin) {
for (String uuid : UserManager.getInstance().getAllUUIDs()) {
VotingPluginUser user = UserManager.getInstance().getVotingPluginUser(new UUID(uuid));
if (!user.voteStreakUpdatedToday(LocalDateTime.now().minusDays(1))) {
if (user.getDayVoteStreak() != 0) {
user.setDayVoteStreak(0);
if (plugin.getConfigFile().isUseVoteStreaks()) {
if (!user.voteStreakUpdatedToday(LocalDateTime.now().minusDays(1))) {
if (user.getDayVoteStreak() != 0) {
user.setDayVoteStreak(0);
}
}
}
if (user.getHighestDailyTotal() < user.getTotal(TopVoter.Daily)) {
user.setHighestDailyTotal(user.getTotal(TopVoter.Daily));
if (plugin.getConfigFile().isUseHighestTotals()) {
if (user.getHighestDailyTotal() < user.getTotal(TopVoter.Daily)) {
user.setHighestDailyTotal(user.getTotal(TopVoter.Daily));
}
}
for (String shopIdent : plugin.getGui().getChestShopIdentifiers()) {
if (plugin.getGui().getChestVoteShopResetDaily(shopIdent)) {
@@ -163,6 +171,10 @@ public class TopVoterHandler implements Listener {
}
resetTotals(TopVoter.Daily);
if (plugin.getStorageType().equals(UserStorage.MYSQL)) {
plugin.getMysql().clearCache();
}
}
}
@@ -171,15 +183,17 @@ public class TopVoterHandler implements Listener {
synchronized (VotingPluginMain.plugin) {
for (String uuid : UserManager.getInstance().getAllUUIDs()) {
VotingPluginUser user = UserManager.getInstance().getVotingPluginUser(new UUID(uuid));
if (user.getTotal(TopVoter.Monthly) == 0 && user.getMonthVoteStreak() != 0) {
user.setMonthVoteStreak(0);
} else {
if (!plugin.getSpecialRewardsConfig().isVoteStreakRequirementUsePercentage()
|| user.hasPercentageTotal(TopVoter.Monthly,
plugin.getSpecialRewardsConfig().getVoteStreakRequirementMonth(),
LocalDateTime.now().minusDays(1))) {
user.addMonthVoteStreak();
plugin.getSpecialRewards().checkVoteStreak(user, "Month");
if (plugin.getConfigFile().isUseVoteStreaks()) {
if (user.getTotal(TopVoter.Monthly) == 0 && user.getMonthVoteStreak() != 0) {
user.setMonthVoteStreak(0);
} else {
if (!plugin.getSpecialRewardsConfig().isVoteStreakRequirementUsePercentage()
|| user.hasPercentageTotal(TopVoter.Monthly,
plugin.getSpecialRewardsConfig().getVoteStreakRequirementMonth(),
LocalDateTime.now().minusDays(1))) {
user.addMonthVoteStreak();
plugin.getSpecialRewards().checkVoteStreak(user, "Month");
}
}
}
@@ -191,8 +205,10 @@ public class TopVoterHandler implements Listener {
user.setLastMonthTotal(user.getTotal(TopVoter.Monthly));
if (user.getHighestMonthlyTotal() < user.getTotal(TopVoter.Monthly)) {
user.setHighestMonthlyTotal(user.getTotal(TopVoter.Monthly));
if (plugin.getConfigFile().isUseHighestTotals()) {
if (user.getHighestMonthlyTotal() < user.getTotal(TopVoter.Monthly)) {
user.setHighestMonthlyTotal(user.getTotal(TopVoter.Monthly));
}
}
}
@@ -243,6 +259,10 @@ public class TopVoterHandler implements Listener {
}
}
if (plugin.getStorageType().equals(UserStorage.MYSQL)) {
plugin.getMysql().clearCache();
}
}
}
@@ -257,14 +277,16 @@ public class TopVoterHandler implements Listener {
synchronized (VotingPluginMain.plugin) {
for (String uuid : UserManager.getInstance().getAllUUIDs()) {
VotingPluginUser user = UserManager.getInstance().getVotingPluginUser(new UUID(uuid));
if (user.getTotal(TopVoter.Weekly) == 0 && user.getWeekVoteStreak() != 0) {
user.setWeekVoteStreak(0);
} else {
if (!plugin.getSpecialRewardsConfig().isVoteStreakRequirementUsePercentage()
|| user.hasPercentageTotal(TopVoter.Weekly,
plugin.getSpecialRewardsConfig().getVoteStreakRequirementWeek(), null)) {
user.addWeekVoteStreak();
plugin.getSpecialRewards().checkVoteStreak(user, "Week");
if (plugin.getConfigFile().isUseVoteStreaks()) {
if (user.getTotal(TopVoter.Weekly) == 0 && user.getWeekVoteStreak() != 0) {
user.setWeekVoteStreak(0);
} else {
if (!plugin.getSpecialRewardsConfig().isVoteStreakRequirementUsePercentage()
|| user.hasPercentageTotal(TopVoter.Weekly,
plugin.getSpecialRewardsConfig().getVoteStreakRequirementWeek(), null)) {
user.addWeekVoteStreak();
plugin.getSpecialRewards().checkVoteStreak(user, "Week");
}
}
}
@@ -274,8 +296,10 @@ public class TopVoterHandler implements Listener {
}
}
if (user.getHighestWeeklyTotal() < user.getTotal(TopVoter.Weekly)) {
user.setHighestWeeklyTotal(user.getTotal(TopVoter.Weekly));
if (plugin.getConfigFile().isUseHighestTotals()) {
if (user.getHighestWeeklyTotal() < user.getTotal(TopVoter.Weekly)) {
user.setHighestWeeklyTotal(user.getTotal(TopVoter.Weekly));
}
}
}
@@ -313,6 +337,10 @@ public class TopVoterHandler implements Listener {
e.printStackTrace();
}
resetTotals(TopVoter.Weekly);
if (plugin.getStorageType().equals(UserStorage.MYSQL)) {
plugin.getMysql().clearCache();
}
}
}
@@ -321,11 +349,15 @@ public class TopVoterHandler implements Listener {
}
public void resetTotals(TopVoter topVoter) {
for (String uuid : UserManager.getInstance().getAllUUIDs()) {
VotingPluginUser user = UserManager.getInstance().getVotingPluginUser(new UUID(uuid));
if (user.getTotal(topVoter) != 0) {
user.resetTotals(topVoter);
if (!plugin.getStorageType().equals(UserStorage.MYSQL)) {
for (String uuid : UserManager.getInstance().getAllUUIDs()) {
VotingPluginUser user = UserManager.getInstance().getVotingPluginUser(new UUID(uuid));
if (user.getTotal(topVoter) != 0) {
user.resetTotals(topVoter);
}
}
} else {
plugin.getMysql().wipeColumnData(topVoter.getColumnName());
}
}
@@ -412,7 +444,7 @@ public class TopVoterHandler implements Listener {
String title = plugin.getConfigFile().getFormatCommandVoteTopTitle();
title = title.replace("%page%", "" + page);
title = title.replace("%maxpages%", "" + pageSize);
title = title.replace("%Top%", "All Time");
title = title.replace("%Top%", plugin.getConfigFile().getFormatTopVoterAllTime());
msg.add(StringParser.getInstance().colorize(title));
for (int i = (page - 1) * pagesize; (i < topVoters.size()) && (i < (((page - 1) * pagesize) + 10)); i++) {
@@ -451,7 +483,7 @@ public class TopVoterHandler implements Listener {
String title = plugin.getConfigFile().getFormatCommandVoteTopTitle();
title = title.replace("%page%", "" + page);
title = title.replace("%maxpages%", "" + pageSize);
title = title.replace("%Top%", "Daily");
title = title.replace("%Top%", plugin.getConfigFile().getFormatTopVoterDaily());
msg.add(StringParser.getInstance().colorize(title));
for (int i = (page - 1) * pagesize; (i < topVoters.size()) && (i < (((page - 1) * pagesize) + 10)); i++) {
@@ -490,7 +522,7 @@ public class TopVoterHandler implements Listener {
String title = plugin.getConfigFile().getFormatCommandVoteTopTitle();
title = title.replace("%page%", "" + page);
title = title.replace("%maxpages%", "" + pageSize);
title = title.replace("%Top%", "Monthly");
title = title.replace("%Top%", plugin.getConfigFile().getFormatTopVoterMonthly());
msg.add(StringParser.getInstance().colorize(title));
for (int i = (page - 1) * pagesize; (i < topVoters.size()) && (i < (((page - 1) * pagesize) + 10)); i++) {
@@ -610,7 +642,7 @@ public class TopVoterHandler implements Listener {
String title = plugin.getConfigFile().getFormatCommandVoteTopTitle();
title = title.replace("%page%", "" + page);
title = title.replace("%maxpages%", "" + pageSize);
title = title.replace("%Top%", "Weekly");
title = title.replace("%Top%", plugin.getConfigFile().getFormatTopVoterWeekly());
msg.add(StringParser.getInstance().colorize(title));
for (int i = (page - 1) * pagesize; (i < topVoters.size()) && (i < (((page - 1) * pagesize) + 10)); i++) {
@@ -26,7 +26,7 @@ public class UserManager {
public UserManager() {
super();
}
public ArrayList<String> getAllUUIDs() {
return com.bencodez.advancedcore.api.user.UserManager.getInstance().getAllUUIDs();
}
@@ -39,8 +39,13 @@ public class UserManager {
return getVotingPluginUser(new UUID(uuid.toString()));
}
@SuppressWarnings("deprecation")
public VotingPluginUser getVotingPluginUser(java.util.UUID uuid, String playerName) {
return new VotingPluginUser(plugin, new UUID(uuid.toString()), playerName);
}
public VotingPluginUser getVotingPluginUser(OfflinePlayer player) {
return getVotingPluginUser(player.getName());
return getVotingPluginUser(player.getUniqueId(), player.getName());
}
public VotingPluginUser getVotingPluginUser(Player player) {
@@ -59,6 +59,12 @@ public class VotingPluginUser extends com.bencodez.advancedcore.api.user.Advance
this.plugin = plugin;
}
@Deprecated
public VotingPluginUser(VotingPluginMain plugin, UUID uuid, String playerName) {
super(plugin, uuid, playerName);
this.plugin = plugin;
}
@Deprecated
public VotingPluginUser(VotingPluginMain plugin, UUID uuid, boolean loadName) {
super(plugin, uuid, loadName);
@@ -193,6 +199,7 @@ public class VotingPluginUser extends com.bencodez.advancedcore.api.user.Advance
PlayerVoteEvent voteEvent = new PlayerVoteEvent(plugin.getVoteSite(service), getPlayerName(), service,
true);
voteEvent.setBungee(true);
voteEvent.setVotingPluginUser(this);
voteEvent.setForceBungee(true);
voteEvent.setTime(time);
voteEvent.setAddTotals(false);
@@ -95,7 +95,8 @@ public class VoteReminding {
if (plugin.getConfigFile().isUsePrimaryAccountForPlaceholders() && user.hasPrimaryAccount()) {
user = UserManager.getInstance().getVotingPluginUser(user.getPrimaryAccount());
}
if ((!UserManager.getInstance().getAllUUIDs().contains(user.getUUID()) || user.canVoteAll())
if ((!UserManager.getInstance().getAllUUIDs().contains(user.getUUID()) || (user.canVoteAll()
|| (user.canVoteAny() && user.hasPermission("VotingPlugin.Login.RemindVotes.Any"))))
&& user.shouldBeReminded()) {
giveReward(user);
if (user.getData().hasData()) {