Fix erroneous MFD config NPE; resolvse #811

This commit is contained in:
Daniel Saukel 2020-06-17 00:35:03 +02:00
parent 4e2ff51902
commit 4ca4112ee8
2 changed files with 32 additions and 18 deletions

View File

@ -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()

View File

@ -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 */