mirror of
https://github.com/NLthijs48/AreaShop.git
synced 2024-11-16 15:25:11 +01:00
Make the updatechecker check async
If the updatechecker cannot reach BukkitDev it would slow down the startup of the server up to 30 seconds (and also if you use /reload), this will not happen anymore.
This commit is contained in:
parent
684add89cd
commit
d9405a9f49
@ -172,18 +172,33 @@ public final class AreaShop extends JavaPlugin {
|
|||||||
|
|
||||||
// Dont initialize the updatechecker if disabled in the config
|
// Dont initialize the updatechecker if disabled in the config
|
||||||
if(this.getConfig().getBoolean("checkForUpdates")) {
|
if(this.getConfig().getBoolean("checkForUpdates")) {
|
||||||
try {
|
new BukkitRunnable() {
|
||||||
updater = new Updater(this, 76518, null, UpdateType.NO_DOWNLOAD, false);
|
@Override
|
||||||
AreaShop.debug("Result=" + updater.getResult().toString() + ", Latest=" + updater.getLatestName() + ", Type=" + updater.getLatestType());
|
public void run() {
|
||||||
updateAvailable = updater.getResult() == UpdateResult.UPDATE_AVAILABLE;
|
try {
|
||||||
if(updateAvailable) {
|
updater = new Updater(AreaShop.getInstance(), 76518, null, UpdateType.NO_DOWNLOAD, false);
|
||||||
this.getLogger().info("Update from AreaShop V" + this.getDescription().getVersion() + " to " + updater.getLatestName() + " available, get the latest version at http://dev.bukkit.org/bukkit-plugins/regionbuyandrent/");
|
AreaShop.debug("Result=" + updater.getResult().toString() + ", Latest=" + updater.getLatestName() + ", Type=" + updater.getLatestType());
|
||||||
|
updateAvailable = updater.getResult() == UpdateResult.UPDATE_AVAILABLE;
|
||||||
|
if(updateAvailable) {
|
||||||
|
AreaShop.getInstance().getLogger().info("Update from AreaShop V" + AreaShop.getInstance().getDescription().getVersion() + " to " + updater.getLatestName() + " available, get the latest version at http://dev.bukkit.org/bukkit-plugins/regionbuyandrent/");
|
||||||
|
new BukkitRunnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
for(Player player : Bukkit.getOnlinePlayers()) {
|
||||||
|
if(player.hasPermission("areashop.notifyupdate")) {
|
||||||
|
AreaShop.getInstance().message(player, "update-playerNotify", AreaShop.getInstance().getDescription().getVersion(), AreaShop.getInstance().getUpdater().getLatestName());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}.runTask(AreaShop.getInstance());
|
||||||
|
}
|
||||||
|
} catch(Exception e) {
|
||||||
|
AreaShop.debug("Something went wrong with the Updater:");
|
||||||
|
AreaShop.debug(e.getMessage());
|
||||||
|
updateAvailable = false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} catch(Exception e) {
|
}.runTaskAsynchronously(this);
|
||||||
AreaShop.debug("Something went wrong with the Updater:");
|
|
||||||
AreaShop.debug(e.getMessage());
|
|
||||||
updateAvailable = false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -40,6 +40,10 @@ public final class PlayerLoginListener implements Listener {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
final Player player = event.getPlayer();
|
final Player player = event.getPlayer();
|
||||||
|
// Notify admins for plugin updates
|
||||||
|
if(plugin.updateAvailable() && player.hasPermission("areashop.notifyupdate")) {
|
||||||
|
AreaShop.getInstance().message(player, "update-playerNotify", AreaShop.getInstance().getDescription().getVersion(), AreaShop.getInstance().getUpdater().getLatestName());
|
||||||
|
}
|
||||||
// Schedule task to check for notifications, prevents a lag spike at login
|
// Schedule task to check for notifications, prevents a lag spike at login
|
||||||
new BukkitRunnable() {
|
new BukkitRunnable() {
|
||||||
@Override
|
@Override
|
||||||
@ -66,10 +70,6 @@ public final class PlayerLoginListener implements Listener {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Notify admins for plugin updates
|
|
||||||
if(plugin.updateAvailable() && player.hasPermission("areashop.notifyupdate")) {
|
|
||||||
AreaShop.getInstance().message(player, "update-playerNotify", AreaShop.getInstance().getDescription().getVersion(), AreaShop.getInstance().getUpdater().getLatestName());
|
|
||||||
}
|
|
||||||
this.cancel();
|
this.cancel();
|
||||||
}
|
}
|
||||||
}.runTaskTimer(plugin, 25, 25);
|
}.runTaskTimer(plugin, 25, 25);
|
||||||
|
Loading…
Reference in New Issue
Block a user