64 lines
2.0 KiB
Java
64 lines
2.0 KiB
Java
|
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<ReminderList> reminderLists;
|
||
|
|
||
|
public Reminder(int frequency, List<ReminderList> reminderLists) {
|
||
|
this.frequency = frequency;
|
||
|
this.reminderLists = reminderLists;
|
||
|
Collections.sort(reminderLists);
|
||
|
}
|
||
|
|
||
|
public static Reminder fromConfig(ConfigurationSection config) {
|
||
|
int frequency = config.getInt("frequency");
|
||
|
List<ReminderList> 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<String> 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;
|
||
|
}
|
||
|
}
|