diff options
author | snowleo <schneeleo@gmail.com> | 2011-10-23 21:45:01 +0200 |
---|---|---|
committer | snowleo <schneeleo@gmail.com> | 2011-10-23 21:45:01 +0200 |
commit | 9433acf6896eeea49e4c72a4acdf11cc619f8d44 (patch) | |
tree | 3620736ed675382e7dd1e7a2c7f25ec41574a00d /EssentialsUpdate/src/com/earth2me/essentials/update/tasks | |
parent | aa922c5b67dc6d9fc5ef865edb9269397a687e13 (diff) | |
download | Essentials-9433acf6896eeea49e4c72a4acdf11cc619f8d44.tar Essentials-9433acf6896eeea49e4c72a4acdf11cc619f8d44.tar.gz Essentials-9433acf6896eeea49e4c72a4acdf11cc619f8d44.tar.lz Essentials-9433acf6896eeea49e4c72a4acdf11cc619f8d44.tar.xz Essentials-9433acf6896eeea49e4c72a4acdf11cc619f8d44.zip |
Statemachine for installation wizard (WIP)
Diffstat (limited to 'EssentialsUpdate/src/com/earth2me/essentials/update/tasks')
3 files changed, 80 insertions, 0 deletions
diff --git a/EssentialsUpdate/src/com/earth2me/essentials/update/tasks/InstallChat.java b/EssentialsUpdate/src/com/earth2me/essentials/update/tasks/InstallChat.java new file mode 100644 index 000000000..44b4e245d --- /dev/null +++ b/EssentialsUpdate/src/com/earth2me/essentials/update/tasks/InstallChat.java @@ -0,0 +1,12 @@ +package com.earth2me.essentials.update.tasks; + +import com.earth2me.essentials.update.WorkListener; + + +public class InstallChat extends InstallModule +{ + public InstallChat(final WorkListener listener) + { + super(listener, "EssentialsChat"); + } +} diff --git a/EssentialsUpdate/src/com/earth2me/essentials/update/tasks/InstallModule.java b/EssentialsUpdate/src/com/earth2me/essentials/update/tasks/InstallModule.java new file mode 100644 index 000000000..b97991a04 --- /dev/null +++ b/EssentialsUpdate/src/com/earth2me/essentials/update/tasks/InstallModule.java @@ -0,0 +1,61 @@ +package com.earth2me.essentials.update.tasks; + +import com.earth2me.essentials.update.GetFile; +import com.earth2me.essentials.update.ModuleInfo; +import com.earth2me.essentials.update.VersionInfo; +import com.earth2me.essentials.update.WorkListener; +import java.io.File; +import java.net.URL; +import java.util.logging.Level; +import org.bukkit.Bukkit; + + +public class InstallModule implements Runnable, Task +{ + protected final transient WorkListener listener; + private final transient String moduleName; + private final transient String fileName; + + public InstallModule(final WorkListener listener, final String moduleName) + { + this(listener, moduleName, moduleName + ".jar"); + } + + public InstallModule(final WorkListener listener, final String moduleName, final String fileName) + { + this.listener = listener; + this.moduleName = moduleName; + this.fileName = fileName; + } + + @Override + public void start() + { + Bukkit.getScheduler().scheduleAsyncDelayedTask(listener.getPlugin(), this); + } + + @Override + public void run() + { + final VersionInfo info = listener.getNewVersionInfo(); + final ModuleInfo module = info.getModules().get(moduleName); + if (module == null) + { + listener.onWorkAbort("Module " + moduleName + " not found in VersionInfo."); + return; + } + try + { + final URL downloadUrl = module.getUrl(); + final GetFile getFile = new GetFile(downloadUrl); + getFile.saveTo(new File(listener.getPlugin().getServer().getUpdateFolderFile(), fileName), module.getHash()); + listener.onWorkDone("Module " + moduleName + " downloaded."); + } + catch (Exception ex) + { + Bukkit.getLogger().log(Level.SEVERE, "Failed to download module " + moduleName + " to " + fileName, ex); + listener.onWorkAbort("An error occured, please check your server log."); + return; + } + } +} diff --git a/EssentialsUpdate/src/com/earth2me/essentials/update/tasks/Task.java b/EssentialsUpdate/src/com/earth2me/essentials/update/tasks/Task.java new file mode 100644 index 000000000..3f1d572ed --- /dev/null +++ b/EssentialsUpdate/src/com/earth2me/essentials/update/tasks/Task.java @@ -0,0 +1,7 @@ +package com.earth2me.essentials.update.tasks; + + +public interface Task +{ + void start(); +} |