mirror of
https://github.com/EssentialsX/Essentials.git
synced 2024-08-26 15:32:50 +02:00
Abort the installation wizard if a runtime exception happens
This commit is contained in:
parent
48f8eb9788
commit
5641b1173c
|
@ -8,12 +8,12 @@ public abstract class AbstractState
|
||||||
{
|
{
|
||||||
private transient boolean abortion = false;
|
private transient boolean abortion = false;
|
||||||
private final transient StateMap stateMap;
|
private final transient StateMap stateMap;
|
||||||
|
|
||||||
public AbstractState(final StateMap stateMap)
|
public AbstractState(final StateMap stateMap)
|
||||||
{
|
{
|
||||||
this.stateMap = stateMap;
|
this.stateMap = stateMap;
|
||||||
}
|
}
|
||||||
|
|
||||||
public <T extends AbstractState> T getState(final Class<? extends T> stateClass)
|
public <T extends AbstractState> T getState(final Class<? extends T> stateClass)
|
||||||
{
|
{
|
||||||
if (!stateMap.containsKey(stateClass))
|
if (!stateMap.containsKey(stateClass))
|
||||||
|
@ -35,7 +35,7 @@ public abstract class AbstractState
|
||||||
}
|
}
|
||||||
return (T)stateMap.get(stateClass);
|
return (T)stateMap.get(stateClass);
|
||||||
}
|
}
|
||||||
|
|
||||||
public abstract AbstractState getNextState();
|
public abstract AbstractState getNextState();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -60,7 +60,7 @@ public abstract class AbstractState
|
||||||
* @return true, if the answer could be recognized as a valid answer
|
* @return true, if the answer could be recognized as a valid answer
|
||||||
*/
|
*/
|
||||||
public abstract boolean reactOnAnswer(String answer);
|
public abstract boolean reactOnAnswer(String answer);
|
||||||
|
|
||||||
public final AbstractState reactOnAnswer(final Player sender, final String answer)
|
public final AbstractState reactOnAnswer(final Player sender, final String answer)
|
||||||
{
|
{
|
||||||
final String trimmedAnswer = answer.trim();
|
final String trimmedAnswer = answer.trim();
|
||||||
|
@ -71,16 +71,24 @@ public abstract class AbstractState
|
||||||
abort();
|
abort();
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
final boolean found = reactOnAnswer(trimmedAnswer);
|
try
|
||||||
if (found)
|
|
||||||
{
|
{
|
||||||
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;
|
return this;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -90,12 +98,12 @@ public abstract class AbstractState
|
||||||
{
|
{
|
||||||
listener.onWorkDone();
|
listener.onWorkDone();
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isAbortion()
|
public boolean isAbortion()
|
||||||
{
|
{
|
||||||
return abortion;
|
return abortion;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void abort()
|
protected void abort()
|
||||||
{
|
{
|
||||||
abortion = true;
|
abortion = true;
|
||||||
|
|
|
@ -33,22 +33,33 @@ public class StateMachine extends WorkListener
|
||||||
|
|
||||||
public MachineResult askQuestion()
|
public MachineResult askQuestion()
|
||||||
{
|
{
|
||||||
while (current.guessAnswer())
|
try
|
||||||
{
|
{
|
||||||
current = current.getNextState();
|
while (current.guessAnswer())
|
||||||
if (current == null)
|
|
||||||
{
|
{
|
||||||
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())
|
player.sendMessage(ex.getMessage());
|
||||||
{
|
finish();
|
||||||
current.askQuestion(player);
|
result = MachineResult.ABORT;
|
||||||
}
|
|
||||||
result = MachineResult.WAIT;
|
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
@ -135,6 +146,7 @@ public class StateMachine extends WorkListener
|
||||||
|
|
||||||
private void finish()
|
private void finish()
|
||||||
{
|
{
|
||||||
|
current = null;
|
||||||
iterator = null;
|
iterator = null;
|
||||||
states.clear();
|
states.clear();
|
||||||
getPlugin().getServer().getPluginManager().callEvent(new InstallationFinishedEvent());
|
getPlugin().getServer().getPluginManager().callEvent(new InstallationFinishedEvent());
|
||||||
|
|
Loading…
Reference in New Issue
Block a user