From 579844f1935a931bc72bba3a95466066767f90be Mon Sep 17 00:00:00 2001 From: BenCodez Date: Fri, 1 Dec 2023 21:34:06 -0500 Subject: [PATCH] Save vote reminding toggles across restarts --- .../votingplugin/VotingPluginMain.java | 2 ++ .../votingplugin/data/ServerData.java | 14 ++++++++ .../votereminding/VoteReminding.java | 32 +++++++++++++++++++ 3 files changed, 48 insertions(+) diff --git a/VotingPlugin/src/com/bencodez/votingplugin/VotingPluginMain.java b/VotingPlugin/src/com/bencodez/votingplugin/VotingPluginMain.java index 12173d6fe..86e14759e 100644 --- a/VotingPlugin/src/com/bencodez/votingplugin/VotingPluginMain.java +++ b/VotingPlugin/src/com/bencodez/votingplugin/VotingPluginMain.java @@ -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); @@ -1292,6 +1293,7 @@ public void onUnLoad() { if (timeQueueHandler != null) { timeQueueHandler.save(); } + getVoteReminding().saveReminds(); getSigns().storeSigns(); HandlerList.unregisterAll(plugin); plugin = null; diff --git a/VotingPlugin/src/com/bencodez/votingplugin/data/ServerData.java b/VotingPlugin/src/com/bencodez/votingplugin/data/ServerData.java index 1164a71ab..01eea9bbc 100644 --- a/VotingPlugin/src/com/bencodez/votingplugin/data/ServerData.java +++ b/VotingPlugin/src/com/bencodez/votingplugin/data/ServerData.java @@ -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; @@ -72,6 +73,10 @@ public List getAutoCachedPlaceholder() { return getData().getStringList("AutoCachePlaceholders"); } + public List getDisabledReminders() { + return getData().getStringList("DisabledReminders"); + } + public synchronized void addServiceSite(String site) { ArrayList l = getServiceSites(); if (!getServiceSites().contains(site)) { @@ -327,6 +332,15 @@ public void setBungeeVotePartyRequired(int required) { saveData(); } + public void saveDisabledReminders(ArrayList disabledReminders) { + ArrayList uuids = new ArrayList(); + for (UUID uuid : disabledReminders) { + uuids.add(uuid.toString()); + } + getData().set("DisabledReminders", uuids); + saveData(); + } + /** * Update values. */ diff --git a/VotingPlugin/src/com/bencodez/votingplugin/votereminding/VoteReminding.java b/VotingPlugin/src/com/bencodez/votingplugin/votereminding/VoteReminding.java index 5ac119e1c..d04fe3242 100644 --- a/VotingPlugin/src/com/bencodez/votingplugin/votereminding/VoteReminding.java +++ b/VotingPlugin/src/com/bencodez/votingplugin/votereminding/VoteReminding.java @@ -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; @@ -33,6 +36,35 @@ public VoteReminding(VotingPluginMain plugin) { this.plugin = plugin; } + public void loadReminds() { + List 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 remindersDisabled = new ArrayList(); + for (Entry entry : remindersEnabled.entrySet()) { + if (remindersEnabled.containsKey(entry.getKey())) { + if (!remindersEnabled.get(entry.getKey()).booleanValue()) { + remindersDisabled.add(entry.getKey()); + } + } + } + + plugin.getServerData().saveDisabledReminders(remindersDisabled); + } + /** * Check remind. *