diff --git a/core/src/main/java/de/erethon/dungeonsxl/DungeonsXL.java b/core/src/main/java/de/erethon/dungeonsxl/DungeonsXL.java index e7942a4c..0e0ac809 100644 --- a/core/src/main/java/de/erethon/dungeonsxl/DungeonsXL.java +++ b/core/src/main/java/de/erethon/dungeonsxl/DungeonsXL.java @@ -341,9 +341,9 @@ public class DungeonsXL extends DREPlugin implements DungeonsAPI { // Dungeons - Linked dungeons for (File file : DUNGEONS.listFiles()) { - Dungeon dungeon = new DDungeon(this, file); + Dungeon dungeon = DDungeon.create(this, file); - if (dungeon.isSetupCorrect()) { + if (dungeon != null) { dungeonRegistry.add(dungeon.getName(), dungeon); } else { MessageUtil.log(this, "&4The setup of dungeon &6" + file.getName() diff --git a/core/src/main/java/de/erethon/dungeonsxl/dungeon/DDungeon.java b/core/src/main/java/de/erethon/dungeonsxl/dungeon/DDungeon.java index 4e8282c9..51f03daf 100644 --- a/core/src/main/java/de/erethon/dungeonsxl/dungeon/DDungeon.java +++ b/core/src/main/java/de/erethon/dungeonsxl/dungeon/DDungeon.java @@ -37,21 +37,6 @@ public class DDungeon implements Dungeon { private ResourceWorld map; private GameRuleContainer rules; - /** - * Real dungeon - * - * @param plugin the plugin instance - * @param file the file to load from - */ - public DDungeon(DungeonsXL plugin, File file) { - this.plugin = plugin; - - name = file.getName().replaceAll(".yml", ""); - config = new DungeonConfig(plugin, file); - map = config.getStartFloor(); - setupRules(); - } - /** * Artificial dungeon * @@ -66,6 +51,35 @@ public class DDungeon implements Dungeon { setupRules(); } + private DDungeon() { + } + + /** + * Real dungeon + * + * @param plugin the plugin instance + * @param file the file to load from + * @return the dungeon or null if the config is erroneous + */ + public static Dungeon create(DungeonsXL plugin, File file) { + DungeonConfig config = new DungeonConfig(plugin, file); + if (config.getStartFloor() == null || config.getEndFloor() == null) { + return null; + } + + DDungeon dungeon = new DDungeon(); + dungeon.plugin = plugin; + dungeon.name = file.getName().replaceAll(".yml", ""); + dungeon.config = config; + dungeon.map = config.getStartFloor(); + if (dungeon.isSetupCorrect()) { + dungeon.setupRules(); + return dungeon; + } else { + return null; + } + } + public DungeonConfig getConfig() { if (!isMultiFloor()) { throw new IllegalStateException("Tried to access the dungeon config of a single floor dungeon"); @@ -194,7 +208,7 @@ public class DDungeon implements Dungeon { return false; } } - return getConfig().getStartFloor() != null && getConfig().getEndFloor() != null; + return getConfig() == null || (getConfig().getStartFloor() != null && getConfig().getEndFloor() != null); } /* Statics */