From 304c4f73715ad603866f423692ad3302cf547d27 Mon Sep 17 00:00:00 2001 From: Sotr Date: Sun, 28 Apr 2019 23:47:54 +0800 Subject: [PATCH] Notify operators when there is a new release Former-commit-id: 71fe40169cac52936d7922b877b519498d332992 [formerly ebfc6b4a3ff5bc0ec66459d611a2d29d194805be] Former-commit-id: 165b4ef5060d25e68de5c51ab9cba99d29ee0134 --- .../quickshop/Watcher/UpdateWatcher.java | 130 ++++++++++-------- 1 file changed, 69 insertions(+), 61 deletions(-) diff --git a/src/main/java/org/maxgamer/quickshop/Watcher/UpdateWatcher.java b/src/main/java/org/maxgamer/quickshop/Watcher/UpdateWatcher.java index ca4c49d04..1cbb9274f 100644 --- a/src/main/java/org/maxgamer/quickshop/Watcher/UpdateWatcher.java +++ b/src/main/java/org/maxgamer/quickshop/Watcher/UpdateWatcher.java @@ -1,5 +1,6 @@ package org.maxgamer.quickshop.Watcher; +import org.bukkit.Bukkit; import org.bukkit.ChatColor; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; @@ -11,65 +12,72 @@ import org.maxgamer.quickshop.Util.UpdateInfomation; import org.maxgamer.quickshop.Util.Updater; public class UpdateWatcher implements Listener { - static BukkitTask cronTask = null; - static volatile boolean hasNewUpdate = false; - static boolean isBeta = false; - static UpdateInfomation info = null; - - public static void init() { - cronTask = new BukkitRunnable() { - - @Override - public void run() { - info = Updater.checkUpdate(); - if (!info.getIsNewUpdate()) { - hasNewUpdate = false; - return; - } - - if(!info.getIsBeta()) { - QuickShop.instance.getLogger().info("A new version of QuickShop has been released!"); - QuickShop.instance.getLogger().info("Update here: https://www.spigotmc.org/resources/62575/"); - hasNewUpdate = true; - }else { - QuickShop.instance.getLogger().info("A new BETA version of QuickShop is available!"); - QuickShop.instance.getLogger().info("Update here: https://www.spigotmc.org/resources/62575/"); - QuickShop.instance.getLogger().info("This is a BETA version, which means you should use with caution."); - hasNewUpdate = true; - } - - - - } - }.runTaskTimerAsynchronously(QuickShop.instance, 1, 20 * 60 * 60); - } - - public static void uninit() { - hasNewUpdate = false; - if (cronTask == null) { - return; - } - cronTask.cancel(); - } - - @EventHandler - public void PlayerJoin(PlayerJoinEvent e) { - new BukkitRunnable() { - @Override - public void run() { - if (hasNewUpdate && e.getPlayer().hasPermission("quickshop.alert")) { - if(!info.getIsBeta()) { - e.getPlayer().sendMessage(ChatColor.GREEN+"A new version of QuickShop has been released!"); - e.getPlayer().sendMessage(ChatColor.GREEN+"Update here: https://www.spigotmc.org/resources/62575/"); - }else { - e.getPlayer().sendMessage(ChatColor.GRAY+"A new BETA version of QuickShop has been released!"); - e.getPlayer().sendMessage(ChatColor.GRAY+"Update here: https://www.spigotmc.org/resources/62575/"); - e.getPlayer().sendMessage(ChatColor.GRAY+"This is a BETA version, which means you should use with caution."); - } - } - - } - }.runTaskLater(QuickShop.instance, 80); - } - + static BukkitTask cronTask = null; + static volatile boolean hasNewUpdate = false; + static boolean isBeta = false; + static UpdateInfomation info = null; + + public static void init() { + cronTask = new BukkitRunnable() { + + @Override + public void run() { + info = Updater.checkUpdate(); + if (!info.getIsNewUpdate()) { + hasNewUpdate = false; + return; + } + + hasNewUpdate = true; + + if (!info.getIsBeta()) { + QuickShop.instance.getLogger().warning("A new version of QuickShop has been released!"); + QuickShop.instance.getLogger().warning("Update here: https://www.spigotmc.org/resources/62575/"); + + Bukkit.getOnlinePlayers().forEach(player -> { + if (player.isOp()) { + player.sendMessage(ChatColor.GREEN + "---------------------------------------------------"); + player.sendMessage(ChatColor.GREEN + "A new version of QuickShop has been released!"); + player.sendMessage(ChatColor.GREEN + "Update here: https://www.spigotmc.org/resources/62575/"); + player.sendMessage(ChatColor.GREEN + "---------------------------------------------------"); + } + }); + } else { + QuickShop.instance.getLogger().warning("A new BETA version of QuickShop is available!"); + QuickShop.instance.getLogger().warning("Update here: https://www.spigotmc.org/resources/62575/"); + QuickShop.instance.getLogger().warning("This is a BETA version, which means you should use with caution."); + } + + } + }.runTaskTimerAsynchronously(QuickShop.instance, 1, 20 * 60 * 60); + } + + public static void uninit() { + hasNewUpdate = false; + if (cronTask == null) { + return; + } + cronTask.cancel(); + } + + @EventHandler + public void PlayerJoin(PlayerJoinEvent e) { + new BukkitRunnable() { + @Override + public void run() { + if (hasNewUpdate && e.getPlayer().hasPermission("quickshop.alert")) { + if(!info.getIsBeta()) { + e.getPlayer().sendMessage(ChatColor.GREEN+"A new version of QuickShop has been released!"); + e.getPlayer().sendMessage(ChatColor.GREEN+"Update here: https://www.spigotmc.org/resources/62575/"); + }else { + e.getPlayer().sendMessage(ChatColor.GRAY+"A new BETA version of QuickShop has been released!"); + e.getPlayer().sendMessage(ChatColor.GRAY+"Update here: https://www.spigotmc.org/resources/62575/"); + e.getPlayer().sendMessage(ChatColor.GRAY+"This is a BETA version, which means you should use with caution."); + } + } + + } + }.runTaskLater(QuickShop.instance, 80); + } + }