Abort the installation wizard if a runtime exception happens

This commit is contained in:
snowleo 2011-10-26 19:46:40 +02:00
parent 48f8eb9788
commit 5641b1173c
2 changed files with 43 additions and 23 deletions

View File

@ -71,14 +71,22 @@ 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;
}
}

View File

@ -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())
{
current.askQuestion(player);
}
result = MachineResult.WAIT;
}
}
if (current != null)
catch (RuntimeException ex)
{
if (player.isOnline())
{
current.askQuestion(player);
}
result = MachineResult.WAIT;
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());