diff --git a/src/main/java/io/github/dre2n/dungeonsxl/DungeonsXL.java b/src/main/java/io/github/dre2n/dungeonsxl/DungeonsXL.java index 658eba8a..7a669833 100644 --- a/src/main/java/io/github/dre2n/dungeonsxl/DungeonsXL.java +++ b/src/main/java/io/github/dre2n/dungeonsxl/DungeonsXL.java @@ -146,7 +146,6 @@ public class DungeonsXL extends BRPlugin { loadMainConfig(new File(getDataFolder(), "config.yml")); // Load Language 2 loadMessageConfig(new File(LANGUAGES, mainConfig.getLanguage() + ".yml")); - loadDCommands(); DPermissions.register(); loadGameTypes(); loadRequirementTypes(); @@ -161,6 +160,8 @@ public class DungeonsXL extends BRPlugin { loadDClasses(CLASSES); loadDMobTypes(MOBS); loadSignScripts(SIGNS); + loadDWorlds(MAPS); + loadDCommands(); manager.registerEvents(new EntityListener(), this); manager.registerEvents(new GUIListener(), this); @@ -582,7 +583,7 @@ public class DungeonsXL extends BRPlugin { /** * load / reload a new instance of DWorlds */ - public void loadWorlds(File folder) { + public void loadDWorlds(File folder) { dWorlds = new DWorlds(MAPS); } diff --git a/src/main/java/io/github/dre2n/dungeonsxl/command/CreateCommand.java b/src/main/java/io/github/dre2n/dungeonsxl/command/CreateCommand.java index ff2a31cd..10b14973 100644 --- a/src/main/java/io/github/dre2n/dungeonsxl/command/CreateCommand.java +++ b/src/main/java/io/github/dre2n/dungeonsxl/command/CreateCommand.java @@ -51,7 +51,7 @@ public class CreateCommand extends BRCommand { public void onExecute(String[] args, CommandSender sender) { String name = args[1]; - if (new File(plugin.getDataFolder(), "/maps/" + name).exists()) { + if (new File(DungeonsXL.MAPS, name).exists()) { MessageUtil.sendMessage(sender, DMessages.ERROR_NAME_IN_USE.getMessage(name)); return; } @@ -67,7 +67,8 @@ public class CreateCommand extends BRCommand { MessageUtil.log(plugin, DMessages.LOG_GENERATE_NEW_WORLD.getMessage()); // Create World - DResourceWorld resource = new DResourceWorld(name); + DResourceWorld resource = new DResourceWorld(plugin.getDWorlds(), name); + plugin.getDWorlds().addResource(resource); DEditWorld editWorld = resource.generate(); editWorld.save(); editWorld.delete(); @@ -88,7 +89,8 @@ public class CreateCommand extends BRCommand { MessageUtil.log(plugin, DMessages.LOG_GENERATE_NEW_WORLD.getMessage()); // Create World - DResourceWorld resource = new DResourceWorld(name); + DResourceWorld resource = new DResourceWorld(plugin.getDWorlds(), name); + plugin.getDWorlds().addResource(resource); DEditWorld editWorld = resource.generate(); // MSG Done diff --git a/src/main/java/io/github/dre2n/dungeonsxl/game/Game.java b/src/main/java/io/github/dre2n/dungeonsxl/game/Game.java index 4c150b4a..b62874f7 100644 --- a/src/main/java/io/github/dre2n/dungeonsxl/game/Game.java +++ b/src/main/java/io/github/dre2n/dungeonsxl/game/Game.java @@ -78,10 +78,9 @@ public class Game { dGroups.add(dGroup); started = false; - // TO DO world = new DGameWorld(); DResourceWorld resource = plugin.getDWorlds().getResourceByName(worldName); + world = resource.instantiateAsGameWorld(); dGroup.setGameWorld(world); - resource.instantiateAsGameWorld(); fetchRules(); } diff --git a/src/main/java/io/github/dre2n/dungeonsxl/world/DResourceWorld.java b/src/main/java/io/github/dre2n/dungeonsxl/world/DResourceWorld.java index ab637eef..3e3e9a5a 100644 --- a/src/main/java/io/github/dre2n/dungeonsxl/world/DResourceWorld.java +++ b/src/main/java/io/github/dre2n/dungeonsxl/world/DResourceWorld.java @@ -37,13 +37,15 @@ import org.bukkit.WorldType; public class DResourceWorld { DungeonsXL plugin = DungeonsXL.getInstance(); - DWorlds worlds = plugin.getDWorlds(); + DWorlds worlds; private File folder; private WorldConfig config; private SignData signData; - public DResourceWorld(String name) { + public DResourceWorld(DWorlds worlds, String name) { + this.worlds = worlds; + folder = new File(DungeonsXL.MAPS, name); if (!folder.exists()) { folder.mkdir(); @@ -60,11 +62,11 @@ public class DResourceWorld { } signData = new SignData(signDataFile); - - worlds.addResource(this); } - public DResourceWorld(File folder) { + public DResourceWorld(DWorlds worlds, File folder) { + this.worlds = worlds; + this.folder = folder; File configFile = new File(folder, "config.yml"); @@ -76,8 +78,6 @@ public class DResourceWorld { if (signData.exists()) { this.signData = new SignData(signData); } - - worlds.addResource(this); } /* Getters and setters */ @@ -185,11 +185,11 @@ public class DResourceWorld { DInstanceWorld instance = null; try { if (game) { - new DGameWorld(this, instanceFolder, world, id); + instance = new DGameWorld(this, instanceFolder, world, id); signData.deserializeSigns((DGameWorld) instance); } else { - new DEditWorld(this, instanceFolder, world, id); + instance = new DEditWorld(this, instanceFolder, world, id); signData.deserializeSigns((DEditWorld) instance); } diff --git a/src/main/java/io/github/dre2n/dungeonsxl/world/DWorlds.java b/src/main/java/io/github/dre2n/dungeonsxl/world/DWorlds.java index 62488a1d..de509047 100644 --- a/src/main/java/io/github/dre2n/dungeonsxl/world/DWorlds.java +++ b/src/main/java/io/github/dre2n/dungeonsxl/world/DWorlds.java @@ -29,13 +29,13 @@ import org.bukkit.Bukkit; */ public class DWorlds { - private Set resources; - private Set instances; + private Set resources = new HashSet<>(); + private Set instances = new HashSet<>(); public DWorlds(File folder) { for (File file : folder.listFiles()) { if (file.isDirectory()) { - new DResourceWorld(file); + resources.add(new DResourceWorld(this, file)); } } }