Skip to content

Commit 1733aa9

Browse files
committed
notify periodically for unread mail
1 parent 7a3001d commit 1733aa9

1 file changed

Lines changed: 20 additions & 1 deletion

File tree

src/main/java/pro/cloudnode/smp/cloudnodemsg/CloudnodeMSG.java

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
import org.bukkit.entity.Player;
66
import org.bukkit.metadata.MetadataValue;
77
import org.bukkit.plugin.java.JavaPlugin;
8+
import org.bukkit.scheduler.BukkitRunnable;
9+
import org.bukkit.scheduler.BukkitTask;
810
import org.jetbrains.annotations.NotNull;
911
import org.jetbrains.annotations.Nullable;
1012
import pro.cloudnode.smp.cloudnodemsg.command.IgnoreCommand;
@@ -50,11 +52,14 @@ public void onEnable() {
5052

5153
getServer().getPluginManager().registerEvents(new AsyncChatListener(), this);
5254
getServer().getPluginManager().registerEvents(new PlayerJoinListener(), this);
55+
56+
minuteLoop = minuteLoop();
5357
}
5458

5559
@Override
5660
public void onDisable() {
57-
dbSource.close();
61+
if (dbSource != null) dbSource.close();
62+
if (minuteLoop != null) minuteLoop.cancel();
5863
}
5964

6065
public static boolean isVanished(final @NotNull Player player) {
@@ -124,4 +129,18 @@ public void runDDL() {
124129
public static void runAsync(final @NotNull Runnable runnable) {
125130
getInstance().getServer().getScheduler().runTaskAsynchronously(getInstance(), runnable);
126131
}
132+
133+
private @NotNull BukkitTask minuteLoop() {
134+
return getServer().getScheduler().runTaskTimerAsynchronously(this, () -> {
135+
final int mailNotifyInterval = config.mailNotifyInterval();
136+
if (mailNotifyInterval > 0) {
137+
for (final @NotNull Player player : getServer().getOnlinePlayers()) {
138+
if (!player.hasPermission(Permission.MAIL)) continue;
139+
final int unread = Mail.unread(player);
140+
if (unread > 0) player.sendMessage(config.mailNotify(unread));
141+
}
142+
}
143+
}, 0, 20 * 60);
144+
}
145+
private @Nullable BukkitTask minuteLoop;
127146
}

0 commit comments

Comments
 (0)