forked from Minecraft/QoL
Added reminder groups (#3)
Added reminder groups + Multiple reminder groups can be define + Reminders still occur as set by the frequency + Each group can be configured with its own chat color and period + The period config defines how many reminder cycles it takes before that group's next message is used Co-authored-by: Joey Hines <joey@ahines.net> Reviewed-on: https://git.birbmc.com/Canopy/QoL/pulls/3 Reviewed-by: Etzelia <etzelia@hotmail.com> Co-Authored-By: ZeroHD <joey@ahines.net> Co-Committed-By: ZeroHD <joey@ahines.net>benamaurer-chatchatDiscod
parent
fc163baf51
commit
684b269039
6
pom.xml
6
pom.xml
|
@ -37,7 +37,7 @@
|
|||
<dependency>
|
||||
<groupId>xyz.etztech</groupId>
|
||||
<artifactId>plugin-api</artifactId>
|
||||
<version>1.0.8</version>
|
||||
<version>1.0.7</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>net.ess3</groupId>
|
||||
|
@ -72,8 +72,8 @@
|
|||
<url>https://nexus.scarsz.me/content/groups/public/</url>
|
||||
</repository>
|
||||
<repository>
|
||||
<id>etztech-repo</id>
|
||||
<url>http://repo.etztech.xyz</url>
|
||||
<id>birbmc-repo</id>
|
||||
<url>https://mvn.birbmc.com</url>
|
||||
</repository>
|
||||
<repository>
|
||||
<id>dynmap-repo</id>
|
||||
|
|
|
@ -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<String> audits = new ArrayList<>();
|
||||
private static List<LinkCommand> 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<String> 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"));
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -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<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;
|
||||
}
|
||||
}
|
|
@ -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<ReminderList>{
|
||||
private final List<String> reminders;
|
||||
private final int period;
|
||||
private final ChatColor color;
|
||||
private int ndx;
|
||||
private int count;
|
||||
|
||||
public ReminderList(List<String> 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;
|
||||
}
|
||||
}
|
|
@ -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:
|
||||
|
|
Loading…
Reference in New Issue