Skip to content

Commit

Permalink
Save vote reminding toggles across restarts
Browse files Browse the repository at this point in the history
  • Loading branch information
BenCodez committed Dec 2, 2023
1 parent 4c6073c commit 579844f
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1057,6 +1057,7 @@ public void onPostLoad() {
checkUpdate.startUp();
voteReminding = new VoteReminding(this);
voteReminding.loadRemindChecking();
voteReminding.loadReminds();
specialRewards = new SpecialRewards(this);
signs = new Signs(this);

Expand Down Expand Up @@ -1292,6 +1293,7 @@ public void onUnLoad() {
if (timeQueueHandler != null) {
timeQueueHandler.save();
}
getVoteReminding().saveReminds();
getSigns().storeSigns();
HandlerList.unregisterAll(plugin);
plugin = null;
Expand Down
14 changes: 14 additions & 0 deletions VotingPlugin/src/com/bencodez/votingplugin/data/ServerData.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import java.util.List;
import java.util.Locale;
import java.util.Set;
import java.util.UUID;

import org.bukkit.Bukkit;
import org.bukkit.Location;
Expand Down Expand Up @@ -72,6 +73,10 @@ public List<String> getAutoCachedPlaceholder() {
return getData().getStringList("AutoCachePlaceholders");
}

public List<String> getDisabledReminders() {
return getData().getStringList("DisabledReminders");
}

public synchronized void addServiceSite(String site) {
ArrayList<String> l = getServiceSites();
if (!getServiceSites().contains(site)) {
Expand Down Expand Up @@ -327,6 +332,15 @@ public void setBungeeVotePartyRequired(int required) {
saveData();
}

public void saveDisabledReminders(ArrayList<UUID> disabledReminders) {
ArrayList<String> uuids = new ArrayList<String>();
for (UUID uuid : disabledReminders) {
uuids.add(uuid.toString());
}
getData().set("DisabledReminders", uuids);
saveData();
}

/**
* Update values.
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package com.bencodez.votingplugin.votereminding;

import java.util.ArrayList;
import java.util.List;
import java.util.Map.Entry;
import java.util.UUID;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.Executors;
Expand Down Expand Up @@ -33,6 +36,35 @@ public VoteReminding(VotingPluginMain plugin) {
this.plugin = plugin;
}

public void loadReminds() {
List<String> uuidsStr = plugin.getServerData().getDisabledReminders();

for (String str : uuidsStr) {
remindersEnabled.put(UUID.fromString(str), Boolean.FALSE);
}

plugin.getTimer().scheduleAtFixedRate(new Runnable() {

@Override
public void run() {
saveReminds();
}
}, 24, 24, TimeUnit.HOURS);
}

public void saveReminds() {
ArrayList<UUID> remindersDisabled = new ArrayList<UUID>();
for (Entry<UUID, Boolean> entry : remindersEnabled.entrySet()) {
if (remindersEnabled.containsKey(entry.getKey())) {
if (!remindersEnabled.get(entry.getKey()).booleanValue()) {
remindersDisabled.add(entry.getKey());
}
}
}

plugin.getServerData().saveDisabledReminders(remindersDisabled);
}

/**
* Check remind.
*
Expand Down

0 comments on commit 579844f

Please sign in to comment.