diff --git a/jme3-core/src/main/java/com/jme3/app/state/AppStateManager.java b/jme3-core/src/main/java/com/jme3/app/state/AppStateManager.java index 177fcb22f..df7eeb4b2 100644 --- a/jme3-core/src/main/java/com/jme3/app/state/AppStateManager.java +++ b/jme3-core/src/main/java/com/jme3/app/state/AppStateManager.java @@ -210,6 +210,18 @@ public class AppStateManager { * @return First attached state that is an instance of stateClass */ public T getState(Class stateClass){ + return getState(stateClass, false); + } + + /** + * Returns the first state that is an instance of subclass of the specified class. + * @param + * @param stateClass + * @param failOnMiss + * @return First attached state that is an instance of stateClass. If failOnMiss is true + * then an IllegalArgumentException is thrown if the state is not attached. + */ + public T getState(Class stateClass, boolean failOnMiss){ synchronized (states){ AppState[] array = getStates(); for (AppState state : array) { @@ -229,6 +241,10 @@ public class AppStateManager { } } } + + if(failOnMiss) { + throw new IllegalArgumentException("State not found for:" + stateClass); + } return null; } diff --git a/jme3-core/src/main/java/com/jme3/app/state/BaseAppState.java b/jme3-core/src/main/java/com/jme3/app/state/BaseAppState.java index a8a80f19e..cee045355 100644 --- a/jme3-core/src/main/java/com/jme3/app/state/BaseAppState.java +++ b/jme3-core/src/main/java/com/jme3/app/state/BaseAppState.java @@ -142,7 +142,11 @@ public abstract class BaseAppState implements AppState { } public final T getState( Class type ) { - return getStateManager().getState(type); + return getState( type, false ); + } + + public final T getState( Class type, boolean failOnMiss ) { + return getStateManager().getState( type, failOnMiss ); } @Override