summaryrefslogtreecommitdiffstats
path: root/EssentialsUpdate/src/com/earth2me
diff options
context:
space:
mode:
authorsnowleo <schneeleo@gmail.com>2011-10-26 17:42:39 +0200
committersnowleo <schneeleo@gmail.com>2011-10-26 17:42:39 +0200
commit102570958eedece667c1efec8b387be0aec8231a (patch)
tree48880dc9b869b4f739b2560be270c04e6f5b948d /EssentialsUpdate/src/com/earth2me
parent38b6d79f49e5d62cdb304b4e7c1dfac027d5f5e8 (diff)
downloadEssentials-102570958eedece667c1efec8b387be0aec8231a.tar
Essentials-102570958eedece667c1efec8b387be0aec8231a.tar.gz
Essentials-102570958eedece667c1efec8b387be0aec8231a.tar.lz
Essentials-102570958eedece667c1efec8b387be0aec8231a.tar.xz
Essentials-102570958eedece667c1efec8b387be0aec8231a.zip
Allow states to be automatically added to the state map.
They have to have a Constructor that accept the StateMap as argument, otherwise a RuntimeException is thrown.
Diffstat (limited to 'EssentialsUpdate/src/com/earth2me')
-rw-r--r--EssentialsUpdate/src/com/earth2me/essentials/update/states/AbstractState.java17
1 files changed, 17 insertions, 0 deletions
diff --git a/EssentialsUpdate/src/com/earth2me/essentials/update/states/AbstractState.java b/EssentialsUpdate/src/com/earth2me/essentials/update/states/AbstractState.java
index 22fadc0de..5f2ff42ea 100644
--- a/EssentialsUpdate/src/com/earth2me/essentials/update/states/AbstractState.java
+++ b/EssentialsUpdate/src/com/earth2me/essentials/update/states/AbstractState.java
@@ -16,6 +16,23 @@ public abstract class AbstractState
public AbstractState getState(final Class<? extends AbstractState> stateClass)
{
+ if (!stateMap.containsKey(stateClass))
+ {
+ try
+ {
+ final AbstractState state = stateClass.getConstructor(StateMap.class).newInstance(stateMap);
+ stateMap.put(stateClass, state);
+ }
+ catch (Exception ex)
+ {
+ /*
+ * This should never happen.
+ * All states that are added to the map automatically,
+ * have to have a Constructor that accepts the StateMap.
+ */
+ throw new RuntimeException(ex);
+ }
+ }
return stateMap.get(stateClass);
}