1
0
mirror of https://github.com/essentials/Essentials.git synced 2025-09-25 13:49:12 +02:00

Statemachine for installation wizard (WIP)

This commit is contained in:
snowleo
2011-10-23 21:45:01 +02:00
parent 1b4b78d6e6
commit 7888471982
14 changed files with 471 additions and 41 deletions

View File

@@ -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();
}
});
}
}