Changed DungeonHelper into a singleton

Changed DungeonHelper into a singleton. Changed code in other classes to
interface with it properly.
This commit is contained in:
SenseiKiwi
2013-06-16 01:00:05 -04:00
parent a5159055a4
commit f56893018d
7 changed files with 40 additions and 29 deletions

View File

@@ -25,6 +25,7 @@ import StevenDimDoors.mod_pocketDim.helpers.jnbt.Tag;
public class DungeonHelper
{
private static DungeonHelper instance = null;
private static DDProperties properties = null;
public static final Pattern NamePattern = Pattern.compile("[A-Za-z0-9_]+");
@@ -76,7 +77,7 @@ public class DungeonHelper
private HashSet<String> dungeonTypeChecker;
private Hashtable<String, ArrayList<DungeonGenerator>> dungeonTypeMapping;
public DungeonHelper()
private DungeonHelper()
{
//Load the dungeon type checker with the list of all types in lowercase.
//Capitalization matters for matching in a hash set.
@@ -100,6 +101,27 @@ public class DungeonHelper
properties = DDProperties.instance();
}
public static DungeonHelper create()
{
if (instance == null)
instance = new DungeonHelper();
else
throw new IllegalStateException("Cannot create DungeonHelper twice");
return instance;
}
public static DungeonHelper instance()
{
if (instance == null)
{
//This is to prevent some frustrating bugs that could arise when classes
//are loaded in the wrong order. Trust me, I had to squash a few...
throw new IllegalStateException("Instance of DungeonHelper requested before creation");
}
return instance;
}
public boolean validateSchematicName(String name)
{
String[] dungeonData = name.split("_");

View File

@@ -978,7 +978,7 @@ public class dimHelper extends DimensionManager
if(isRandomRift)
{
mod_pocketDim.dungeonHelper.generateDungeonlink(link);
DungeonHelper.instance().generateDungeonlink(link);
}