summaryrefslogtreecommitdiffstats
path: root/EssentialsUpdate/src/com/earth2me/essentials/update/UpdateProcess.java
diff options
context:
space:
mode:
Diffstat (limited to 'EssentialsUpdate/src/com/earth2me/essentials/update/UpdateProcess.java')
-rw-r--r--EssentialsUpdate/src/com/earth2me/essentials/update/UpdateProcess.java62
1 files changed, 43 insertions, 19 deletions
diff --git a/EssentialsUpdate/src/com/earth2me/essentials/update/UpdateProcess.java b/EssentialsUpdate/src/com/earth2me/essentials/update/UpdateProcess.java
index 95898bcb6..80434480f 100644
--- a/EssentialsUpdate/src/com/earth2me/essentials/update/UpdateProcess.java
+++ b/EssentialsUpdate/src/com/earth2me/essentials/update/UpdateProcess.java
@@ -1,5 +1,6 @@
package com.earth2me.essentials.update;
+import com.earth2me.essentials.update.states.StateMachine;
import java.util.List;
import org.bukkit.Bukkit;
import org.bukkit.command.CommandSender;
@@ -18,31 +19,41 @@ public class UpdateProcess extends PlayerListener
private transient Player currentPlayer;
private final transient Plugin plugin;
private final transient UpdateCheck updateCheck;
-
+ private transient StateMachine stateMachine;
+
public UpdateProcess(final Plugin plugin, final UpdateCheck updateCheck)
{
this.plugin = plugin;
this.updateCheck = updateCheck;
}
-
+
public void registerEvents()
{
final PluginManager pluginManager = plugin.getServer().getPluginManager();
pluginManager.registerEvent(Type.PLAYER_QUIT, this, Priority.Low, plugin);
pluginManager.registerEvent(Type.PLAYER_CHAT, this, Priority.Lowest, plugin);
}
-
+
@Override
public void onPlayerChat(final PlayerChatEvent event)
{
if (event.getPlayer() == currentPlayer)
{
- reactOnMessage(event.getMessage());
+ final StateMachine.MachineResult result = stateMachine.reactOnMessage(event.getMessage());
+ if (result == StateMachine.MachineResult.ABORT)
+ {
+ currentPlayer.sendMessage("Installation wizard aborted. You can restart it using /essentialsupdate.");
+ currentPlayer = null;
+ }
+ if (result == StateMachine.MachineResult.DONE)
+ {
+ startWork();
+ }
event.setCancelled(true);
return;
}
}
-
+
@Override
public void onPlayerJoin(final PlayerJoinEvent event)
{
@@ -70,26 +81,26 @@ public class UpdateProcess extends PlayerListener
}
}
}
-
- void doAutomaticUpdate()
+
+ public void doAutomaticUpdate()
{
- final UpdatesDownloader downloader = new UpdatesDownloader();
+
final VersionInfo info = updateCheck.getNewVersionInfo();
final List<String> changelog = info.getChangelog();
Bukkit.getLogger().info("Essentials changelog " + updateCheck.getNewVersion().toString());
for (String line : changelog)
{
- Bukkit.getLogger().info(" - "+line);
+ Bukkit.getLogger().info(" - " + line);
}
- downloader.start(plugin.getServer().getUpdateFolderFile(), info);
+ final UpdatesDownloader downloader = new UpdatesDownloader(plugin, info);
+ downloader.start();
}
-
- void doManualUpdate()
+
+ public void doManualUpdate()
{
-
}
-
- void onCommand(CommandSender sender)
+
+ public void onCommand(final CommandSender sender)
{
if (sender instanceof Player && sender.hasPermission("essentials.install"))
{
@@ -107,7 +118,12 @@ public class UpdateProcess extends PlayerListener
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();
+ }
}
}
if (!currentPlayer.equals(sender))
@@ -120,9 +136,17 @@ public class UpdateProcess extends PlayerListener
sender.sendMessage("Please run the command as op from in game.");
}
}
-
- private void reactOnMessage(String message)
+
+ private void startWork()
{
- throw new UnsupportedOperationException("Not yet implemented");
+ currentPlayer.sendMessage("Installation wizard done. Starting installation.");
+ Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable()
+ {
+ @Override
+ public void run()
+ {
+ stateMachine.startWork();
+ }
+ });
}
}