Compare commits

...
18 Commits
Author SHA1 Message Date
Ben12345rocks 4ccc5def2b Update version number 2018-05-06 12:55:22 -04:00
Ben12345rocks 5378d4e372 Slight bug fix 2018-05-04 16:57:37 -04:00
Ben12345rocks 8d37d39b1c Update version number 2018-04-21 20:54:13 -04:00
Ben12345rocks 473a83604c Add config option for delay 2018-04-16 19:19:08 -04:00
Ben12345rocks 4f72fbab78 Bug fix 2018-04-15 21:14:38 -04:00
Ben12345rocks 1f62d68aed Add a delay 2018-04-15 20:53:35 -04:00
Ben12345rocks 7c063bbe68 Only convert 500 users at a time 2018-04-15 20:23:54 -04:00
Ben12345rocks 4c11df4b37 Bug fix 2018-04-14 21:27:11 -04:00
Ben12345rocks f859caf1ee Bug fix 2018-04-14 10:29:03 -04:00
Ben12345rocks 566d688b57 Javadoc fixes 2018-03-30 09:09:34 -04:00
Ben12345rocks e4209b15c3 Update version number 2018-03-30 08:37:17 -04:00
Ben12345rocks bd5b26805a Update config 2018-03-25 13:05:22 -04:00
Ben12345rocks 27c43b8e8e New way to do multiple places for top voter 2018-03-25 12:55:41 -04:00
Ben12345rocks 5b719141fe Change default config 2018-03-22 16:52:57 -04:00
Ben12345rocks f8ee0bba17 Bug fixes 2018-03-22 16:52:05 -04:00
Ben12345rocks d5ea3c60a9 Implement new vote party system type 2018-03-22 16:50:46 -04:00
Ben12345rocks 3be9eaf47a Slight performance improvement 2018-03-21 19:12:07 -04:00
Ben12345rocks f385927958 implement config option for backups 2018-03-18 21:00:51 -04:00
10 changed files with 147 additions and 123 deletions

No files matched your search

+7 -1
View File
@@ -597,6 +597,8 @@ VoteParty:
Enabled: false
# Number of votes required to give rewards
VotesRequired: 20
# Increase the amount of votes required on each vote party reached
#IncreaseVotesRquired: 10
# If true, players who did not vote to reach the votes required will
# recieve the reward
GiveAllPlayers: false
@@ -710,6 +712,7 @@ EnableMonthlyAwards: true
# Rewards to give
MonthlyAwards:
# Position. 1 is first in top voter, 2 is second, etc...
# Using 1-10 will reward players in first to tenth place with the same reward
1:
Rewards:
Messages:
@@ -836,4 +839,7 @@ PurgeMin: 90
# Whether or not to disable checking names on mojang, disable if you hit the rate limit
# Shouldn't make a noticeable impact if set to false
CheckNameMojang: true
CheckNameMojang: true
# Whether or not to create daily backups. (Only the most recent ones get saved)
CreateBackups: true
+1 -1
View File
@@ -3,7 +3,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>com.Ben12345rocks</groupId>
<artifactId>VotingPlugin</artifactId>
<version>5.12.7</version>
<version>5.13</version>
<packaging>jar</packaging>
<name>VotingPlugin</name>
<properties>
@@ -216,15 +216,8 @@ public class Config extends YMLFile {
return getData().getBoolean("Cumulative." + cumulative + ".VotesInSameWeek");
}
/**
* Gets the daily award rewards path
*
* @param pos
* the pos
* @return the daily award rewards
*/
public String getDailyAwardRewardsPath(int pos) {
return "DailyAwards." + pos + ".Rewards";
public String getDailyAwardRewardsPath(String path) {
return "DailyAwards." + path + ".Rewards";
}
/**
@@ -946,15 +939,8 @@ public class Config extends YMLFile {
}
}
/**
* Gets the monthly award rewards.
*
* @param pos
* the pos
* @return the monthly award rewards
*/
public String getMonthlyAwardRewardsPath(int pos) {
return "MonthlyAwards." + pos + ".Rewards";
public String getMonthlyAwardRewardsPath(String path) {
return "MonthlyAwards." + path + ".Rewards";
}
/**
@@ -1066,6 +1052,10 @@ public class Config extends YMLFile {
return getData().getInt("VoteParty.UserVotesRequired");
}
public int getVotePartyIncreaseVotesRquired() {
return getData().getInt("VoteParty.IncreaseVotesRquired", 0);
}
/**
* Gets the vote GUI slot command.
*
@@ -1357,15 +1347,8 @@ public class Config extends YMLFile {
return getData().getBoolean("GUI.VoteURL.ViewAllUrlsButtonEnabled");
}
/**
* Gets the weekly award rewards.
*
* @param pos
* the pos
* @return the weekly award rewards
*/
public String getWeeklyAwardRewardsPath(int pos) {
return "WeeklyAwards." + pos + ".Rewards";
public String getWeeklyAwardRewardsPath(String path) {
return "WeeklyAwards." + path + ".Rewards";
}
/**
@@ -1439,6 +1422,10 @@ public class Config extends YMLFile {
saveData();
}
public int getConvertDelay() {
return getData().getInt("ConvertDelay", 10000);
}
/**
* Sets the debug info ingame.
*
@@ -103,6 +103,15 @@ public class ServerData {
return (ArrayList<String>) getData().getList("ServiceSites", new ArrayList<String>());
}
public int getVotePartyExtraRequired() {
return getData().getInt("VotePartyExtraRequired", 0);
}
public void setVotePartyExtraRequired(int value) {
getData().set("VotePartyExtraRequired", value);
saveData();
}
/**
* Gets the sign data.
*
@@ -46,7 +46,7 @@ public class VotiferEvent implements Listener {
public static void playerVote(final String playerName, final String voteSiteURL, final boolean realVote) {
if (!PlayerUtils.getInstance().isValidUser(playerName) && !config.allowUnJoined()) {
if (!config.allowUnJoined() && !PlayerUtils.getInstance().isValidUser(playerName)) {
plugin.getLogger().warning("Player " + playerName
+ " has not joined before, disregarding vote, set AllowUnjoined to true to prevent this");
return;
@@ -129,30 +129,72 @@ public class Main extends JavaPlugin {
}
UserStorage cur = AdvancedCoreHook.getInstance().getStorageType();
AdvancedCoreHook.getInstance().setStorageType(from);
AdvancedCoreHook.getInstance().reload();
HashMap<User, HashMap<String, String>> data = new HashMap<User, HashMap<String, String>>();
for (String uuid : UserManager.getInstance().getAllUUIDs()) {
try {
User user = UserManager.getInstance().getVotingPluginUser(new UUID(uuid));
if (AdvancedCoreHook.getInstance().getStorageType().equals(UserStorage.MYSQL)
&& AdvancedCoreHook.getInstance().getMysql() != null) {
AdvancedCoreHook.getInstance().getMysql().clearCache();
}
ArrayList<String> uuids = new ArrayList<String>(UserManager.getInstance().getAllUUIDs());
HashMap<String, String> values = new HashMap<String, String>();
for (String key : user.getData().getKeys()) {
values.put(key, user.getData().getString(key));
}
data.put(user, values);
debug("[Convert] Added " + uuid);
} catch (Exception e) {
AdvancedCoreHook.getInstance().debug(e);
plugin.getLogger().warning("Exception occoured for '" + uuid + "': " + e.getMessage()
+ ", turn debug on to see full stack traces");
while (uuids.size() > 0) {
HashMap<User, HashMap<String, String>> data = new HashMap<User, HashMap<String, String>>();
AdvancedCoreHook.getInstance().setStorageType(from);
if (AdvancedCoreHook.getInstance().getStorageType().equals(UserStorage.MYSQL)
&& AdvancedCoreHook.getInstance().getMysql() != null)
{
AdvancedCoreHook.getInstance().getMysql().clearCache();
}
ArrayList<String> converted = new ArrayList<String>();
int i = 0;
while (i < 500 && i < uuids.size()) {
String uuid = uuids.get(i);
try {
User user = UserManager.getInstance().getVotingPluginUser(new UUID(uuid));
HashMap<String, String> values = new HashMap<String, String>();
for (String key : user.getData().getKeys()) {
values.put(key, user.getData().getString(key));
}
i++;
converted.add(uuid);
data.put(user, values);
debug("[Convert] Added " + uuid);
} catch (Exception e) {
AdvancedCoreHook.getInstance().debug(e);
plugin.getLogger().warning("Exception occoured for '" + uuid + "': " + e.getMessage()
+ ", turn debug on to see full stack traces");
}
}
try {
wait(Config.getInstance().getConvertDelay());
} catch (Exception e) {
e.printStackTrace();
}
uuids.removeAll(converted);
plugin.getLogger()
.info("Finished getting data from " + from.toString() + " Converting " + data.size() + " users");
AdvancedCoreHook.getInstance().setStorageType(to);
if (AdvancedCoreHook.getInstance().getStorageType().equals(UserStorage.MYSQL)
&& AdvancedCoreHook.getInstance().getMysql() != null)
{
AdvancedCoreHook.getInstance().getMysql().clearCache();
}
writeConvertData(data);
}
plugin.getLogger().info("Finished getting data from " + from.toString());
AdvancedCoreHook.getInstance().setStorageType(to);
AdvancedCoreHook.getInstance().setStorageType(cur);
AdvancedCoreHook.getInstance().reload();
plugin.getLogger().info("Finished convertting");
}
private void writeConvertData(HashMap<User, HashMap<String, String>> data) {
for (Entry<User, HashMap<String, String>> entry : data.entrySet()) {
try {
for (Entry<String, String> values : entry.getValue().entrySet()) {
@@ -164,10 +206,6 @@ public class Main extends JavaPlugin {
+ e.getMessage() + ", turn debug on to see full stack traces");
}
}
AdvancedCoreHook.getInstance().setStorageType(cur);
AdvancedCoreHook.getInstance().reload();
plugin.getLogger().info("Finished convertting");
}
public ArrayList<User> convertSet(Set<User> set) {
@@ -776,8 +814,8 @@ public class Main extends JavaPlugin {
@Override
public void run() {
plugin.getLogger()
.warning("Detected an issue with voting sites, check the plugin startup log for more details");
plugin.getLogger().warning(
"Detected an issue with voting sites, check the plugin startup log for more details");
}
}, 30l);
}
@@ -204,7 +204,7 @@ public class User extends com.Ben12345rocks.AdvancedCore.Objects.User {
return now.isAfter(nextvote);
} else {
if (now.getDayOfYear() != lastVote.getDayOfYear() && now.getYear() != lastVote.getYear()) {
if (now.getDayOfYear() != lastVote.getDayOfYear() || now.getYear() != lastVote.getYear()) {
return true;
}
return false;
@@ -411,25 +411,13 @@ public class User extends com.Ben12345rocks.AdvancedCore.Objects.User {
return getData().getInt("WeekVoteStreak");
}
/**
* Give daily top voter award.
*
* @param place
* the place
*/
public void giveDailyTopVoterAward(int place) {
new RewardBuilder(Config.getInstance().getData(), Config.getInstance().getDailyAwardRewardsPath(place))
public void giveDailyTopVoterAward(int place, String path) {
new RewardBuilder(Config.getInstance().getData(), Config.getInstance().getDailyAwardRewardsPath(path))
.withPlaceHolder("place", "" + place).withPlaceHolder("topvoter", "Daily").send(this);
}
/**
* Give monthly top voter award.
*
* @param place
* the place
*/
public void giveMonthlyTopVoterAward(int place) {
new RewardBuilder(Config.getInstance().getData(), Config.getInstance().getMonthlyAwardRewardsPath(place))
public void giveMonthlyTopVoterAward(int place, String path) {
new RewardBuilder(Config.getInstance().getData(), Config.getInstance().getMonthlyAwardRewardsPath(path))
.withPlaceHolder("place", "" + place).withPlaceHolder("topvoter", "Monthly").send(this);
}
@@ -462,36 +450,6 @@ public class User extends com.Ben12345rocks.AdvancedCore.Objects.User {
}
}
}
} else if (str.contains("MonthlyTopVoter")) {
String st = str.substring("MontlyTopVoter".length());
if (StringUtils.getInstance().isInt(st)) {
int place = Integer.parseInt(st);
if (place > 0) {
if (Config.getInstance().getMonthlyAwardsEnabled()) {
giveMonthlyTopVoterAward(place);
}
}
}
} else if (str.contains("WeeklyTopVoter")) {
String st = str.substring("WeeklyTopVoter".length());
if (StringUtils.getInstance().isInt(st)) {
int place = Integer.parseInt(st);
if (place > 0) {
if (Config.getInstance().getWeeklyAwardsEnabled()) {
giveWeeklyTopVoterAward(place);
}
}
}
} else if (str.contains("DailyTopVoter")) {
String st = str.substring("DailyTopVoter".length());
if (StringUtils.getInstance().isInt(st)) {
int place = Integer.parseInt(st);
if (place > 0) {
if (Config.getInstance().getDailyAwardsEnabled()) {
giveDailyTopVoterAward(place);
}
}
}
} else if (str.contains("VoteStreak")) {
String[] args = str.split("_");
if (args.length > 2) {
@@ -513,14 +471,8 @@ public class User extends com.Ben12345rocks.AdvancedCore.Objects.User {
}
}
/**
* Give weekly top voter award.
*
* @param place
* the place
*/
public void giveWeeklyTopVoterAward(int place) {
new RewardBuilder(Config.getInstance().getData(), Config.getInstance().getWeeklyAwardRewardsPath(place))
public void giveWeeklyTopVoterAward(int place, String path) {
new RewardBuilder(Config.getInstance().getData(), Config.getInstance().getWeeklyAwardRewardsPath(path))
.withPlaceHolder("place", "" + place).withPlaceHolder("topvoter", "Weekly").send(this);
}
@@ -105,7 +105,7 @@ public class TopVoterHandler implements Listener {
}
if (Config.getInstance().getDailyAwardsEnabled()) {
Set<String> places = Config.getInstance().getDailyPossibleRewardPlaces();
HashMap<Integer, String> places = handlePlaces(Config.getInstance().getDailyPossibleRewardPlaces());
int i = 0;
int lastTotal = -1;
for (User user : plugin.topVoterDaily.keySet()) {
@@ -117,8 +117,8 @@ public class TopVoterHandler implements Listener {
} else {
i++;
}
if (places.contains(Integer.toString(i))) {
user.giveDailyTopVoterAward(i);
if (places.containsKey(i)) {
user.giveDailyTopVoterAward(i, places.get(i));
}
}
lastTotal = user.getDailyTotal();
@@ -150,7 +150,7 @@ public class TopVoterHandler implements Listener {
}
if (Config.getInstance().getMonthlyAwardsEnabled()) {
Set<String> places = Config.getInstance().getMonthlyPossibleRewardPlaces();
HashMap<Integer, String> places = handlePlaces(Config.getInstance().getMonthlyPossibleRewardPlaces());
int i = 0;
int lastTotal = -1;
for (User user : plugin.topVoterMonthly.keySet()) {
@@ -163,8 +163,8 @@ public class TopVoterHandler implements Listener {
} else {
i++;
}
if (places.contains(Integer.toString(i))) {
user.giveMonthlyTopVoterAward(i);
if (places.containsKey(i)) {
user.giveMonthlyTopVoterAward(i, places.get(i));
}
}
lastTotal = user.getMonthTotal();
@@ -180,7 +180,26 @@ public class TopVoterHandler implements Listener {
}
}
}
private HashMap<Integer, String> handlePlaces(Set<String> places) {
HashMap<Integer, String> place = new HashMap<Integer, String>();
for (String p : places) {
String[] data = p.split("-");
try {
if (data.length > 1) {
for (int i = Integer.parseInt(data[0]); i < Integer.parseInt(data[1]); i++) {
place.put(i, p);
}
} else {
place.put(Integer.parseInt(data[0]), p);
}
} catch (Exception e) {
e.printStackTrace();
}
}
return place;
}
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
@@ -211,7 +230,7 @@ public class TopVoterHandler implements Listener {
}
if (Config.getInstance().getWeeklyAwardsEnabled()) {
Set<String> places = Config.getInstance().getWeeklyPossibleRewardPlaces();
HashMap<Integer, String> places = handlePlaces(Config.getInstance().getWeeklyPossibleRewardPlaces());
int i = 0;
int lastTotal = -1;
for (User user : plugin.topVoterWeekly.keySet()) {
@@ -223,8 +242,8 @@ public class TopVoterHandler implements Listener {
} else {
i++;
}
if (places.contains(Integer.toString(i))) {
user.giveWeeklyTopVoterAward(i);
if (places.containsKey(i)) {
user.giveWeeklyTopVoterAward(i, places.get(i));
}
}
lastTotal = user.getWeeklyTotal();
@@ -7,7 +7,6 @@ import org.bukkit.entity.Player;
import com.Ben12345rocks.AdvancedCore.Util.Misc.StringUtils;
import com.Ben12345rocks.VotingPlugin.Main;
import com.Ben12345rocks.VotingPlugin.Commands.Commands;
import com.Ben12345rocks.VotingPlugin.Config.Config;
import com.Ben12345rocks.VotingPlugin.Config.ConfigVoteSites;
import com.Ben12345rocks.VotingPlugin.Objects.User;
import com.Ben12345rocks.VotingPlugin.Objects.VoteSite;
@@ -110,7 +109,7 @@ public class PlaceHolders {
} else if (identifier.equalsIgnoreCase("VotePartyVotesCurrent")) {
return Integer.toString(VoteParty.getInstance().getTotalVotes());
} else if (identifier.equalsIgnoreCase("VotePartyVotesRequired")) {
return Integer.toString(Config.getInstance().getVotePartyVotesRequired());
return Integer.toString(VoteParty.getInstance().getVotesRequired());
}
// %VotingPlugin_canvote% - Whether or not a player can vote on all
@@ -86,8 +86,8 @@ public class VoteParty implements Listener {
* Check.
*/
public void check() {
if (getTotalVotes() >= Config.getInstance().getVotePartyVotesRequired()) {
setTotalVotes(getTotalVotes() - Config.getInstance().getVotePartyVotesRequired());
if (getTotalVotes() >= getVotesRequired()) {
setTotalVotes(getTotalVotes() - getVotesRequired());
VotePartyEvent event = new VotePartyEvent();
Bukkit.getPluginManager().callEvent(event);
@@ -96,6 +96,11 @@ public class VoteParty implements Listener {
}
giveRewards();
MiscUtils.getInstance().broadcast(Config.getInstance().getVotePartyBroadcast());
if (Config.getInstance().getVotePartyIncreaseVotesRquired() > 0) {
ServerData.getInstance().setVotePartyExtraRequired(ServerData.getInstance().getVotePartyExtraRequired()
+ Config.getInstance().getVotePartyIncreaseVotesRquired());
}
}
}
@@ -123,13 +128,22 @@ public class VoteParty implements Listener {
}
}
public int getVotesRequired() {
int required = Config.getInstance().getVotePartyVotesRequired();
int extra = ServerData.getInstance().getVotePartyExtraRequired();
if (extra > 0) {
return required + extra;
}
return required;
}
/**
* Gets the needed votes.
*
* @return the needed votes
*/
public int getNeededVotes() {
int votesRequired = Config.getInstance().getVotePartyVotesRequired();
int votesRequired = getVotesRequired();
int votes = getTotalVotes();
int neededVotes = votesRequired - votes;
return neededVotes;