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. --- .../earth2me/essentials/update/UpdateProcess.java | 59 ++++++++++++++-------- 1 file changed, 39 insertions(+), 20 deletions(-) (limited to 'EssentialsUpdate/src/com/earth2me/essentials/update/UpdateProcess.java') diff --git a/EssentialsUpdate/src/com/earth2me/essentials/update/UpdateProcess.java b/EssentialsUpdate/src/com/earth2me/essentials/update/UpdateProcess.java index 393bf5aef..38fefb111 100644 --- a/EssentialsUpdate/src/com/earth2me/essentials/update/UpdateProcess.java +++ b/EssentialsUpdate/src/com/earth2me/essentials/update/UpdateProcess.java @@ -1,7 +1,11 @@ package com.earth2me.essentials.update; +import com.earth2me.essentials.update.states.Changelog; +import com.earth2me.essentials.update.states.EssentialsChat; import com.earth2me.essentials.update.states.InstallationFinishedEvent; import com.earth2me.essentials.update.states.StateMachine; +import com.earth2me.essentials.update.states.UpdateOrInstallation; +import com.earth2me.essentials.update.tasks.SelfUpdate; import java.util.List; import java.util.logging.Level; import org.bukkit.Bukkit; @@ -51,6 +55,34 @@ public class UpdateProcess extends PlayerListener }, Priority.Normal, plugin); } + public boolean selfUpdate() + { + if (new Version(plugin.getDescription().getVersion()).compareTo(updateCheck.getNewVersion()) < 0) + { + if (currentPlayer != null) + { + currentPlayer.sendMessage("A newer version of EssentialsUpdate is found. Downloading new file and reloading server."); + } + Bukkit.getLogger().log(Level.INFO, "A newer version of EssentialsUpdate is found. Downloading new file and reloading server."); + new SelfUpdate(new WorkListener(plugin, updateCheck.getNewVersionInfo()) + { + @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); + } + }).start(); + return true; + } + return false; + } + @Override public void onPlayerChat(final PlayerChatEvent event) { @@ -109,7 +141,6 @@ public class UpdateProcess extends PlayerListener public void doAutomaticUpdate() { - final VersionInfo info = updateCheck.getNewVersionInfo(); final List changelog = info.getChangelog(); Bukkit.getLogger().log(Level.INFO, "Essentials changelog {0}", updateCheck.getNewVersion().toString()); @@ -121,34 +152,22 @@ public class UpdateProcess extends PlayerListener downloader.start(); } - public void doManualUpdate() - { - } - public void onCommand(final CommandSender sender) { - if (sender instanceof Player && sender.hasPermission("essentials.install")) + if (sender instanceof Player && sender.hasPermission("essentials.update")) { if (currentPlayer == null) { currentPlayer = (Player)sender; - if (updateCheck.isEssentialsInstalled()) + if (selfUpdate()) { - doManualUpdate(); + return; } - else + stateMachine = new StateMachine(plugin, currentPlayer, updateCheck); + final StateMachine.MachineResult result = stateMachine.askQuestion(); + if (result == StateMachine.MachineResult.DONE) { - sender.sendMessage("Thank you for choosing Essentials."); - sender.sendMessage("The following installation wizard will guide you through the installation of Essentials."); - sender.sendMessage("Your answers will be saved for a later update."); - sender.sendMessage("Please answer the messages with yes or no, if not otherwise stated."); - sender.sendMessage("Write bye/exit/quit if you want to exit the wizard at anytime."); - stateMachine = new StateMachine(plugin, currentPlayer, updateCheck.getNewVersionInfo()); - final StateMachine.MachineResult result = stateMachine.askQuestion(); - if (result == StateMachine.MachineResult.DONE) - { - startWork(); - } + startWork(); } } if (!currentPlayer.equals(sender)) -- cgit v1.2.3