diff --git a/pom.xml b/pom.xml index 6f2a341..88326e3 100644 --- a/pom.xml +++ b/pom.xml @@ -37,7 +37,7 @@ xyz.etztech plugin-api - 1.0.8 + 1.0.7 net.ess3 @@ -72,8 +72,8 @@ https://nexus.scarsz.me/content/groups/public/ - etztech-repo - http://repo.etztech.xyz + birbmc-repo + https://mvn.birbmc.com dynmap-repo diff --git a/src/main/java/xyz/etztech/qol/QoL.java b/src/main/java/xyz/etztech/qol/QoL.java index 8d26c61..469932a 100644 --- a/src/main/java/xyz/etztech/qol/QoL.java +++ b/src/main/java/xyz/etztech/qol/QoL.java @@ -2,7 +2,6 @@ package xyz.etztech.qol; import net.ess3.api.IEssentials; import org.bukkit.Bukkit; -import org.bukkit.ChatColor; import org.bukkit.Location; import org.bukkit.configuration.file.FileConfiguration; import org.bukkit.entity.Player; @@ -15,6 +14,7 @@ import org.dynmap.markers.MarkerSet; import xyz.etztech.qol.commands.*; import xyz.etztech.qol.listeners.*; import xyz.etztech.qol.other.LinkCommand; +import xyz.etztech.qol.other.Reminder; import xyz.etztech.qol.other.TPSRunnable; import java.util.ArrayList; @@ -45,6 +45,8 @@ public class QoL extends JavaPlugin { private static List audits = new ArrayList<>(); private static List links = new ArrayList<>(); + private Reminder reminder = null; + public void onEnable() { instance = this; saveDefaultConfig(); @@ -136,25 +138,15 @@ public class QoL extends JavaPlugin { }, 0, EtzTechUtil.minutesToTicks(schedule)); } - // Reminders - int frequency = config.getInt("reminders.frequency"); - if (frequency > 0) { + if (reminder != null && reminder.getFrequency() != 0) { Bukkit.getScheduler().scheduleSyncRepeatingTask(QoL.getInstance(), new Runnable() { - int idx = 0; - @Override public void run() { - List reminders = config.getStringList("reminders.messages"); - ChatColor color = ChatColor.getByChar(config.getString("reminders.color").replace("&", "")); - if (idx >= reminders.size()) { - idx = 0; - } for (Player player : Bukkit.getOnlinePlayers()) { - EtzTechUtil.sms(player, color + reminders.get(idx)); + player.spigot().sendMessage(reminder.nextReminder()); } - idx++; } - }, 0, EtzTechUtil.minutesToTicks(frequency)); + }, 0, EtzTechUtil.minutesToTicks(reminder.getFrequency())); } // TPS Check @@ -186,6 +178,8 @@ public class QoL extends JavaPlugin { qolMarkerIcon = config.getString("dynmap.marker_icon", "blueflag"); qolMarkerLayerShow = config.getBoolean("dynmap.marker_set_show", false); qolMarkerSetLabel = config.getString("dynmap.marker_set_label", "QoL Markers"); + + reminder = Reminder.fromConfig(config.getConfigurationSection("reminders")); } diff --git a/src/main/java/xyz/etztech/qol/other/Reminder.java b/src/main/java/xyz/etztech/qol/other/Reminder.java new file mode 100644 index 0000000..3f39830 --- /dev/null +++ b/src/main/java/xyz/etztech/qol/other/Reminder.java @@ -0,0 +1,63 @@ +package xyz.etztech.qol.other; + +import net.md_5.bungee.api.chat.BaseComponent; +import net.md_5.bungee.api.chat.ComponentBuilder; +import org.bukkit.configuration.ConfigurationSection; +import net.md_5.bungee.api.ChatColor; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; + +public class Reminder { + private final int frequency; + private final List reminderLists; + + public Reminder(int frequency, List reminderLists) { + this.frequency = frequency; + this.reminderLists = reminderLists; + Collections.sort(reminderLists); + } + + public static Reminder fromConfig(ConfigurationSection config) { + int frequency = config.getInt("frequency"); + List reminderLists = new ArrayList(); + ConfigurationSection reminderGroups = config.getConfigurationSection("reminder_groups"); + + for (String groupName: reminderGroups.getKeys(false)) { + ConfigurationSection group = reminderGroups.getConfigurationSection(groupName); + + int period = group.getInt("period", 0); + ChatColor color = ChatColor.of(group.getString("color", "#3273DC")); + List reminders = group.getStringList("reminders"); + + reminderLists.add(new ReminderList(reminders, period, color)); + } + + return new Reminder(frequency, reminderLists); + } + + public BaseComponent[] nextReminder() { + BaseComponent[] msg = null; + boolean reminderFound = false; + for (ReminderList reminderList: reminderLists) { + if (!reminderFound && reminderList.isReady()) { + msg = new ComponentBuilder(). + color(reminderList.getColor()) + .append(reminderList.nextReminder()) + .create(); + + reminderFound = true; + + } + + reminderList.incCount(); + } + + return msg; + } + + public int getFrequency() { + return frequency; + } +} diff --git a/src/main/java/xyz/etztech/qol/other/ReminderList.java b/src/main/java/xyz/etztech/qol/other/ReminderList.java new file mode 100644 index 0000000..c44c07d --- /dev/null +++ b/src/main/java/xyz/etztech/qol/other/ReminderList.java @@ -0,0 +1,46 @@ +package xyz.etztech.qol.other; + +import net.md_5.bungee.api.ChatColor; +import org.jetbrains.annotations.NotNull; + +import java.util.List; + +public class ReminderList implements Comparable{ + private final List reminders; + private final int period; + private final ChatColor color; + private int ndx; + private int count; + + public ReminderList(List reminders, int period, ChatColor color) { + this.reminders = reminders; + this.period = period; + this.color = color; + this.ndx = 0; + this.count = 0; + } + + public void incCount() { + count = (count + 1) % (period + 1); + } + + public boolean isReady() { + return count == period; + } + + public String nextReminder() { + String nextReminder = reminders.get(ndx); + ndx = (ndx + 1) % reminders.size(); + + return nextReminder; + } + + @Override + public int compareTo(@NotNull ReminderList o) { + return Integer.compare(o.period, this.period); + } + + public ChatColor getColor() { + return color; + } +} diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index 17b14b4..102a360 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -60,10 +60,19 @@ schedule: # To disable, set minutes to 0 reminders: - frequency: 5 # In minutes - color: '&a' - messages: - - 'Check out the Discord!' + frequency: 1 # In minutes + reminder_groups: + standard: + color: '#3273DC' + reminders: + - '1st Standard Reminder' + - '2nd Standard Reminder' + event: + color: '#3273DC' + period: 2 + reminders: + - '1st Event Reminder' + - '2nd Event Reminder' # A list of links for link command aliases, separated by a comma between name and URL links: