From 30960acffa3fa8c33a2ae20750702d4ac87eefc4 Mon Sep 17 00:00:00 2001 From: SenseiKiwi Date: Mon, 17 Jun 2013 06:31:53 -0400 Subject: [PATCH] Fixed Tutorial Listing Bug and Improved Listing Fixed the bug that caused the dungeon creation tutorial to be listed as a schematic. We were listing all files in the custom schematic directory as a schematic, even though that file wasn't. I added filtering so that we only look at files that end with ".schematic". Also improved dungeon listing by sorting the name list in alphabetical order. That makes the list much easier to read through. --- .../mod_pocketDim/helpers/DungeonHelper.java | 23 +++++++++++++------ 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/StevenDimDoors/mod_pocketDim/helpers/DungeonHelper.java b/StevenDimDoors/mod_pocketDim/helpers/DungeonHelper.java index ea8074b..ad97297 100644 --- a/StevenDimDoors/mod_pocketDim/helpers/DungeonHelper.java +++ b/StevenDimDoors/mod_pocketDim/helpers/DungeonHelper.java @@ -4,6 +4,7 @@ import java.io.File; import java.io.FileOutputStream; import java.util.ArrayList; import java.util.Collection; +import java.util.Collections; import java.util.HashMap; import java.util.HashSet; import java.util.Random; @@ -217,16 +218,19 @@ public class DungeonHelper } } - public void importCustomDungeons(String dir) + public void importCustomDungeons(String path) { - File file = new File(dir); - File[] schematicNames = file.listFiles(); + File directory = new File(path); + File[] schematicNames = directory.listFiles(); - if (schematicNames!=null) + if (schematicNames != null) { - for(File schematicFile: schematicNames) + for (File schematicFile: schematicNames) { - this.registerCustomDungeon(schematicFile); + if (schematicFile.getName().endsWith(SCHEMATIC_FILE_EXTENSION)) + { + registerCustomDungeon(schematicFile); + } } } } @@ -660,13 +664,18 @@ public class DungeonHelper } public Collection getDungeonNames() { + //Use a HashSet to guarantee that all dungeon names will be distinct. //This shouldn't be necessary if we keep proper lists without repetitions, //but it's a fool-proof workaround. HashSet dungeonNames = new HashSet(); dungeonNames.addAll( parseDungeonNames(registeredDungeons) ); dungeonNames.addAll( parseDungeonNames(customDungeons) ); - return dungeonNames; + + //Sort dungeon names alphabetically + ArrayList sortedNames = new ArrayList(dungeonNames); + Collections.sort(sortedNames); + return sortedNames; } private static ArrayList parseDungeonNames(ArrayList dungeons)