summaryrefslogtreecommitdiffstats
path: root/EssentialsUpdate
diff options
context:
space:
mode:
authorsnowleo <schneeleo@gmail.com>2011-10-26 19:46:40 +0200
committersnowleo <schneeleo@gmail.com>2011-10-26 19:46:40 +0200
commit5641b1173cafe59f97d3622ec58cace52640d3e3 (patch)
treeda7e5652346aba47b37c6625619f8907d5498a2f /EssentialsUpdate
parent48f8eb9788dd1c49f563d7b5f2d06c27b7ab3201 (diff)
downloadEssentials-5641b1173cafe59f97d3622ec58cace52640d3e3.tar
Essentials-5641b1173cafe59f97d3622ec58cace52640d3e3.tar.gz
Essentials-5641b1173cafe59f97d3622ec58cace52640d3e3.tar.lz
Essentials-5641b1173cafe59f97d3622ec58cace52640d3e3.tar.xz
Essentials-5641b1173cafe59f97d3622ec58cace52640d3e3.zip
Abort the installation wizard if a runtime exception happens
Diffstat (limited to 'EssentialsUpdate')
-rw-r--r--EssentialsUpdate/src/com/earth2me/essentials/update/states/AbstractState.java32
-rw-r--r--EssentialsUpdate/src/com/earth2me/essentials/update/states/StateMachine.java34
2 files changed, 43 insertions, 23 deletions
diff --git a/EssentialsUpdate/src/com/earth2me/essentials/update/states/AbstractState.java b/EssentialsUpdate/src/com/earth2me/essentials/update/states/AbstractState.java
index 3f0c4c233..6d2613a40 100644
--- a/EssentialsUpdate/src/com/earth2me/essentials/update/states/AbstractState.java
+++ b/EssentialsUpdate/src/com/earth2me/essentials/update/states/AbstractState.java
@@ -8,12 +8,12 @@ public abstract class AbstractState
{
private transient boolean abortion = false;
private final transient StateMap stateMap;
-
+
public AbstractState(final StateMap stateMap)
{
this.stateMap = stateMap;
}
-
+
public <T extends AbstractState> T getState(final Class<? extends T> stateClass)
{
if (!stateMap.containsKey(stateClass))
@@ -35,7 +35,7 @@ public abstract class AbstractState
}
return (T)stateMap.get(stateClass);
}
-
+
public abstract AbstractState getNextState();
/**
@@ -60,7 +60,7 @@ public abstract class AbstractState
* @return true, if the answer could be recognized as a valid answer
*/
public abstract boolean reactOnAnswer(String answer);
-
+
public final AbstractState reactOnAnswer(final Player sender, final String answer)
{
final String trimmedAnswer = answer.trim();
@@ -71,16 +71,24 @@ public abstract class AbstractState
abort();
return null;
}
- final boolean found = reactOnAnswer(trimmedAnswer);
- if (found)
+ try
{
- return getNextState();
+ final boolean found = reactOnAnswer(trimmedAnswer);
+ if (found)
+ {
+ return getNextState();
+ }
+ else
+ {
+ sender.sendMessage("Answer not recognized.");
+ return this;
+ }
}
- else
+ catch (RuntimeException ex)
{
- sender.sendMessage("Answer not recognized.");
+ sender.sendMessage(ex.toString());
return this;
- }
+ }
}
/**
@@ -90,12 +98,12 @@ public abstract class AbstractState
{
listener.onWorkDone();
}
-
+
public boolean isAbortion()
{
return abortion;
}
-
+
protected void abort()
{
abortion = true;
diff --git a/EssentialsUpdate/src/com/earth2me/essentials/update/states/StateMachine.java b/EssentialsUpdate/src/com/earth2me/essentials/update/states/StateMachine.java
index 9a9c64134..17f6502fb 100644
--- a/EssentialsUpdate/src/com/earth2me/essentials/update/states/StateMachine.java
+++ b/EssentialsUpdate/src/com/earth2me/essentials/update/states/StateMachine.java
@@ -33,22 +33,33 @@ public class StateMachine extends WorkListener
public MachineResult askQuestion()
{
- while (current.guessAnswer())
+ try
{
- current = current.getNextState();
- if (current == null)
+ while (current.guessAnswer())
{
- result = MachineResult.DONE;
- break;
+
+ current = current.getNextState();
+ if (current == null)
+ {
+ result = MachineResult.DONE;
+ break;
+ }
+
}
- }
- if (current != null)
- {
- if (player.isOnline())
+ if (current != null)
{
- current.askQuestion(player);
+ if (player.isOnline())
+ {
+ current.askQuestion(player);
+ }
+ result = MachineResult.WAIT;
}
- result = MachineResult.WAIT;
+ }
+ catch (RuntimeException ex)
+ {
+ player.sendMessage(ex.getMessage());
+ finish();
+ result = MachineResult.ABORT;
}
return result;
}
@@ -135,6 +146,7 @@ public class StateMachine extends WorkListener
private void finish()
{
+ current = null;
iterator = null;
states.clear();
getPlugin().getServer().getPluginManager().callEvent(new InstallationFinishedEvent());