From e8b8d26bdbe935fff57ab3ded6902e576355f995 Mon Sep 17 00:00:00 2001 From: snowleo Date: Wed, 26 Oct 2011 20:25:09 +0200 Subject: Basic automatic updates downloader --- .../essentials/update/UpdatesDownloader.java | 36 +++++++++++++++++++--- 1 file changed, 31 insertions(+), 5 deletions(-) (limited to 'EssentialsUpdate/src/com/earth2me/essentials/update/UpdatesDownloader.java') diff --git a/EssentialsUpdate/src/com/earth2me/essentials/update/UpdatesDownloader.java b/EssentialsUpdate/src/com/earth2me/essentials/update/UpdatesDownloader.java index 717163726..d13d0d41b 100644 --- a/EssentialsUpdate/src/com/earth2me/essentials/update/UpdatesDownloader.java +++ b/EssentialsUpdate/src/com/earth2me/essentials/update/UpdatesDownloader.java @@ -1,9 +1,14 @@ package com.earth2me.essentials.update; +import com.earth2me.essentials.update.tasks.InstallModule; +import java.util.Iterator; +import java.util.Map.Entry; +import java.util.logging.Level; +import org.bukkit.Bukkit; import org.bukkit.plugin.Plugin; -public class UpdatesDownloader extends WorkListener +public class UpdatesDownloader extends WorkListener implements Runnable { public UpdatesDownloader(final Plugin plugin, final VersionInfo newVersionInfo) { @@ -12,17 +17,38 @@ public class UpdatesDownloader extends WorkListener public void start() { + iterator = getNewVersionInfo().getModules().entrySet().iterator(); + Bukkit.getScheduler().scheduleAsyncDelayedTask(getPlugin(), this); } + private transient Iterator> iterator; @Override - public void onWorkAbort(String message) + public void run() { - throw new UnsupportedOperationException("Not supported yet."); + if (iterator.hasNext()) + { + final Entry entry = iterator.next(); + if (Bukkit.getPluginManager().getPlugin(entry.getKey()) == null) + { + run(); + } + else + { + new InstallModule(this, entry.getKey()).start(); + } + } } @Override - public void onWorkDone(String message) + public void onWorkAbort(final String message) { - throw new UnsupportedOperationException("Not supported yet."); + Bukkit.getLogger().log(Level.SEVERE, message); + } + + @Override + public void onWorkDone(final String message) + { + Bukkit.getLogger().log(Level.INFO, message); + Bukkit.getScheduler().scheduleAsyncDelayedTask(getPlugin(), this); } } -- cgit v1.2.3 From 72596decbae18e2f59fdd5f1fff78b304ca2e114 Mon Sep 17 00:00:00 2001 From: snowleo Date: Wed, 26 Oct 2011 22:14:24 +0200 Subject: The state machine now handles both manual updating and installation. --- .../src/com/earth2me/essentials/update/UpdatesDownloader.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'EssentialsUpdate/src/com/earth2me/essentials/update/UpdatesDownloader.java') diff --git a/EssentialsUpdate/src/com/earth2me/essentials/update/UpdatesDownloader.java b/EssentialsUpdate/src/com/earth2me/essentials/update/UpdatesDownloader.java index d13d0d41b..95fdb2932 100644 --- a/EssentialsUpdate/src/com/earth2me/essentials/update/UpdatesDownloader.java +++ b/EssentialsUpdate/src/com/earth2me/essentials/update/UpdatesDownloader.java @@ -28,7 +28,8 @@ public class UpdatesDownloader extends WorkListener implements Runnable if (iterator.hasNext()) { final Entry entry = iterator.next(); - if (Bukkit.getPluginManager().getPlugin(entry.getKey()) == null) + final Plugin plugin = Bukkit.getPluginManager().getPlugin(entry.getKey()); + if (plugin == null) { run(); } -- cgit v1.2.3 From f6e56ce0f4e01d5533883e7afcec159cbbbde771 Mon Sep 17 00:00:00 2001 From: snowleo Date: Wed, 26 Oct 2011 22:17:27 +0200 Subject: Removing automatic updates It's a bad idea to automatically overwrite files, without asking the player first. This would be triggered by the selfupdate after the reload. --- .../essentials/update/UpdatesDownloader.java | 55 ---------------------- 1 file changed, 55 deletions(-) delete mode 100644 EssentialsUpdate/src/com/earth2me/essentials/update/UpdatesDownloader.java (limited to 'EssentialsUpdate/src/com/earth2me/essentials/update/UpdatesDownloader.java') diff --git a/EssentialsUpdate/src/com/earth2me/essentials/update/UpdatesDownloader.java b/EssentialsUpdate/src/com/earth2me/essentials/update/UpdatesDownloader.java deleted file mode 100644 index 95fdb2932..000000000 --- a/EssentialsUpdate/src/com/earth2me/essentials/update/UpdatesDownloader.java +++ /dev/null @@ -1,55 +0,0 @@ -package com.earth2me.essentials.update; - -import com.earth2me.essentials.update.tasks.InstallModule; -import java.util.Iterator; -import java.util.Map.Entry; -import java.util.logging.Level; -import org.bukkit.Bukkit; -import org.bukkit.plugin.Plugin; - - -public class UpdatesDownloader extends WorkListener implements Runnable -{ - public UpdatesDownloader(final Plugin plugin, final VersionInfo newVersionInfo) - { - super(plugin, newVersionInfo); - } - - public void start() - { - iterator = getNewVersionInfo().getModules().entrySet().iterator(); - Bukkit.getScheduler().scheduleAsyncDelayedTask(getPlugin(), this); - } - private transient Iterator> iterator; - - @Override - public void run() - { - if (iterator.hasNext()) - { - final Entry entry = iterator.next(); - final Plugin plugin = Bukkit.getPluginManager().getPlugin(entry.getKey()); - if (plugin == null) - { - run(); - } - else - { - new InstallModule(this, entry.getKey()).start(); - } - } - } - - @Override - public void onWorkAbort(final String message) - { - Bukkit.getLogger().log(Level.SEVERE, message); - } - - @Override - public void onWorkDone(final String message) - { - Bukkit.getLogger().log(Level.INFO, message); - Bukkit.getScheduler().scheduleAsyncDelayedTask(getPlugin(), this); - } -} -- cgit v1.2.3