mirror of
https://github.com/EarthMC/QuickShop-Reremake.git
synced 2026-11-24 17:39:52 -05:00
Merge pull request #65 from cakoyo/patch-new
Notify operators when there is a new release Former-commit-id: 4b808d9aca7de905cd9e40210efabd5cc5085e9b [formerly eb98c82a09d5331e9420e0dd1ef312e44341cba7] Former-commit-id: 0885582bd58e2e213c8b90bc703ad2372a706650
This commit is contained in:
commit
e901458400
1 file changed
+69
-61
@@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user