diff --git a/src/main/java/org/betonquest/betonquest/conditions/BaseNumberCompareCondition.java b/src/main/java/org/betonquest/betonquest/conditions/BaseNumberCompareCondition.java index fb65ead512..3ae5370f22 100644 --- a/src/main/java/org/betonquest/betonquest/conditions/BaseNumberCompareCondition.java +++ b/src/main/java/org/betonquest/betonquest/conditions/BaseNumberCompareCondition.java @@ -27,8 +27,9 @@ protected BaseNumberCompareCondition(final Instruction instruction) { * @param profile the profile to get the number from * @return the number * @throws QuestRuntimeException when the number cannot be parsed + * @throws IllegalStateException when getting the number fails caused by an invalid state that should cause the condition to be false */ - protected abstract Double getFirst(Profile profile) throws QuestRuntimeException; + protected abstract Double getFirst(Profile profile) throws QuestRuntimeException, IllegalStateException; /** * Get the second number. @@ -36,8 +37,9 @@ protected BaseNumberCompareCondition(final Instruction instruction) { * @param profile the profile to get the number from * @return the number * @throws QuestRuntimeException when the number cannot be parsed + * @throws IllegalStateException when getting the number fails caused by an invalid state that should cause the condition to be false */ - protected abstract Double getSecond(Profile profile) throws QuestRuntimeException; + protected abstract Double getSecond(Profile profile) throws QuestRuntimeException, IllegalStateException; /** * Get the operation. @@ -67,7 +69,11 @@ protected Operation fromSymbol(final String symbol) throws InstructionParseExcep @Override protected Boolean execute(final Profile profile) throws QuestRuntimeException { - return getOperation().compare.check(getFirst(profile), getSecond(profile)); + try { + return getOperation().compare.check(getFirst(profile), getSecond(profile)); + } catch (final IllegalStateException e) { + return false; + } } /** diff --git a/src/main/java/org/betonquest/betonquest/conditions/StageCondition.java b/src/main/java/org/betonquest/betonquest/conditions/StageCondition.java index 7a0e2c8570..55caa73b8a 100644 --- a/src/main/java/org/betonquest/betonquest/conditions/StageCondition.java +++ b/src/main/java/org/betonquest/betonquest/conditions/StageCondition.java @@ -50,13 +50,22 @@ protected Double getFirst(final Profile profile) throws QuestRuntimeException { if (stage.getData(profile) == null) { return -1.0; } - return (double) stage.getStageIndex(stage.getStage(profile)); // TODO return false for invalid stages + try { + return (double) stage.getStageIndex(stage.getStage(profile)); + } catch (final QuestRuntimeException e) { + throw new IllegalStateException(profile + " has an invalid stage"); + } } @Override protected Double getSecond(final Profile profile) throws QuestRuntimeException { final StageObjective stage = getStageObjective(); - return (double) stage.getStageIndex(second.getString(profile)); // TODO return false for invalid stages + final String targetState = second.getString(profile); + try { + return (double) stage.getStageIndex(targetState); + } catch (final QuestRuntimeException e) { + throw new IllegalStateException("The stage " + targetState + "' does not exist"); + } } @Override