mirror of
https://github.com/TotalFreedomMC/TF-EssentialsX.git
synced 2025-02-14 05:01:28 +00:00
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.
This commit is contained in:
parent
38b6d79f49
commit
102570958e
1 changed files with 17 additions and 0 deletions
|
@ -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);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue