From bbb39da8082927d8d0e1c656de3938e9234a940e Mon Sep 17 00:00:00 2001 From: SenseiKiwi Date: Sat, 22 Jun 2013 14:27:59 -0400 Subject: [PATCH] Fixed Bugs in DungeonHelper 1. Added converting dungeon type names to lowercase before adding them to dungeonTypeMapping (a HashMap that associates dungeon type strings with their lists). Keeping the original casing was causing a NullPointerException when the HashMap returned null and we expected to receive a non-null list. 2. Added code to strip out the file extension of a schematic in validateSchematicName(). The extension was getting dragged along with the dungeon's weight, which would cause parsing to fail and the name was considered invalid. This means that none of the custom dungeons were being registered for generation since the system saw them as badly tagged. They also wouldn't generate Monoliths even if tagged as closed because we would ignore the tags. 3. Changed a comparison for the "open" tag to be case insensitive. 4. Minor changes --- .../mod_pocketDim/helpers/DungeonHelper.java | 29 +++++++++++-------- 1 file changed, 17 insertions(+), 12 deletions(-) diff --git a/StevenDimDoors/mod_pocketDim/helpers/DungeonHelper.java b/StevenDimDoors/mod_pocketDim/helpers/DungeonHelper.java index f833e11c..f471e5e8 100644 --- a/StevenDimDoors/mod_pocketDim/helpers/DungeonHelper.java +++ b/StevenDimDoors/mod_pocketDim/helpers/DungeonHelper.java @@ -91,14 +91,15 @@ public class DungeonHelper } //Add all the basic dungeon types to dungeonTypeMapping + //Dungeon type names must be passed in lowercase to make matching easier. dungeonTypeMapping = new HashMap>(); - dungeonTypeMapping.put(SIMPLE_HALL_DUNGEON_TYPE, simpleHalls); - dungeonTypeMapping.put(COMPLEX_HALL_DUNGEON_TYPE, complexHalls); - dungeonTypeMapping.put(HUB_DUNGEON_TYPE, hubs); - dungeonTypeMapping.put(EXIT_DUNGEON_TYPE, exits); - dungeonTypeMapping.put(DEAD_END_DUNGEON_TYPE, deadEnds); - dungeonTypeMapping.put(MAZE_DUNGEON_TYPE, mazes); - dungeonTypeMapping.put(TRAP_DUNGEON_TYPE, pistonTraps); + dungeonTypeMapping.put(SIMPLE_HALL_DUNGEON_TYPE.toLowerCase(), simpleHalls); + dungeonTypeMapping.put(COMPLEX_HALL_DUNGEON_TYPE.toLowerCase(), complexHalls); + dungeonTypeMapping.put(HUB_DUNGEON_TYPE.toLowerCase(), hubs); + dungeonTypeMapping.put(EXIT_DUNGEON_TYPE.toLowerCase(), exits); + dungeonTypeMapping.put(DEAD_END_DUNGEON_TYPE.toLowerCase(), deadEnds); + dungeonTypeMapping.put(MAZE_DUNGEON_TYPE.toLowerCase(), mazes); + dungeonTypeMapping.put(TRAP_DUNGEON_TYPE.toLowerCase(), pistonTraps); //Load our reference to the DDProperties singleton if (properties == null) @@ -162,13 +163,17 @@ public class DungeonHelper public boolean isCustomDungeon(int dimensionID) { - //TODO: Should we simply treat all pocket dimensions as valid custom dungeons? ~SenseiKiwi return customDungeonStatus.containsKey(dimensionID); } public boolean validateSchematicName(String name) { - String[] dungeonData = name.split("_"); + String[] dungeonData; + + if (!name.endsWith(SCHEMATIC_FILE_EXTENSION)) + return false; + + dungeonData = name.substring(0, name.length() - SCHEMATIC_FILE_EXTENSION.length()).split("_"); //Check for a valid number of parts if (dungeonData.length < 3 || dungeonData.length > 4) @@ -210,17 +215,17 @@ public class DungeonHelper String path = schematicFile.getAbsolutePath(); try { - if (name.endsWith(SCHEMATIC_FILE_EXTENSION) && validateSchematicName(name)) + if (validateSchematicName(name)) { //Strip off the file extension while splitting the file name String[] dungeonData = name.substring(0, name.length() - SCHEMATIC_FILE_EXTENSION.length()).split("_"); String dungeonType = dungeonData[0].toLowerCase(); - boolean open = dungeonData[2].equals("open"); + boolean isOpen = dungeonData[2].equalsIgnoreCase("open"); int weight = (dungeonData.length == 4) ? Integer.parseInt(dungeonData[3]) : DEFAULT_DUNGEON_WEIGHT; //Add this custom dungeon to the list corresponding to its type - DungeonGenerator generator = new DungeonGenerator(weight, path, open); + DungeonGenerator generator = new DungeonGenerator(weight, path, isOpen); dungeonTypeMapping.get(dungeonType).add(generator); registeredDungeons.add(generator);