diff --git a/src/main/java/io/github/dre2n/dungeonsxl/command/PlayCommand.java b/src/main/java/io/github/dre2n/dungeonsxl/command/PlayCommand.java index 68b57359..8ffef004 100644 --- a/src/main/java/io/github/dre2n/dungeonsxl/command/PlayCommand.java +++ b/src/main/java/io/github/dre2n/dungeonsxl/command/PlayCommand.java @@ -156,7 +156,7 @@ public class PlayCommand extends BRCommand { } if (dGroup.getGameWorld() == null) { - dGroup.setGameWorld(GameWorld.load(DGroup.getByPlayer(player).getMapName())); + new Game(dGroup, dGroup.getMapName()); } if (dGroup.getGameWorld() == null) { @@ -165,7 +165,6 @@ public class PlayCommand extends BRCommand { return; } - new Game(dGroup, dGroup.getGameWorld()); if (dGroup.getGameWorld().getLobbyLocation() == null) { for (Player groupPlayer : dGroup.getPlayers()) { new DGamePlayer(groupPlayer, dGroup.getGameWorld()); 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 abb97ef3..31daddfa 100644 --- a/src/main/java/io/github/dre2n/dungeonsxl/game/Game.java +++ b/src/main/java/io/github/dre2n/dungeonsxl/game/Game.java @@ -64,8 +64,23 @@ public class Game { } public Game(DGroup dGroup, GameWorld world) { - this(dGroup); + dGroups.add(dGroup); + started = false; this.world = world; + fetchRules(); + + plugin.getGames().add(this); + } + + public Game(DGroup dGroup, String worldName) { + plugin.getGames().add(this); + + dGroups.add(dGroup); + started = false; + world = new GameWorld(); + dGroup.setGameWorld(world); + fetchRules(); + world.load(worldName); } public Game(DGroup dGroup, GameType type, GameWorld world) { diff --git a/src/main/java/io/github/dre2n/dungeonsxl/global/DPortal.java b/src/main/java/io/github/dre2n/dungeonsxl/global/DPortal.java index a668565c..43d3d6fe 100644 --- a/src/main/java/io/github/dre2n/dungeonsxl/global/DPortal.java +++ b/src/main/java/io/github/dre2n/dungeonsxl/global/DPortal.java @@ -186,7 +186,7 @@ public class DPortal extends GlobalProtection { } if (target == null) { - target = GameWorld.load(dGroup.getMapName()); + target = new GameWorld(dGroup.getMapName()); dGroup.setGameWorld(target); } diff --git a/src/main/java/io/github/dre2n/dungeonsxl/listener/PlayerListener.java b/src/main/java/io/github/dre2n/dungeonsxl/listener/PlayerListener.java index 0bb5b80c..8683ec54 100644 --- a/src/main/java/io/github/dre2n/dungeonsxl/listener/PlayerListener.java +++ b/src/main/java/io/github/dre2n/dungeonsxl/listener/PlayerListener.java @@ -560,7 +560,7 @@ public class PlayerListener implements Listener { } if (dGroup.getGameWorld() == null) { - dGroup.setGameWorld(GameWorld.load(DGroup.getByPlayer(player).getMapName())); + dGroup.setGameWorld(new GameWorld(DGroup.getByPlayer(player).getMapName())); dGroup.getGameWorld().setTutorial(true); } diff --git a/src/main/java/io/github/dre2n/dungeonsxl/mob/DMobType.java b/src/main/java/io/github/dre2n/dungeonsxl/mob/DMobType.java index a36c0419..3cc21341 100644 --- a/src/main/java/io/github/dre2n/dungeonsxl/mob/DMobType.java +++ b/src/main/java/io/github/dre2n/dungeonsxl/mob/DMobType.java @@ -83,7 +83,7 @@ public class DMobType { this.name = name; // Read Mobs - EntityType type = EntityType.fromName(config.getString("type")); + type = EntityType.fromName(config.getString("type")); // Load MaxHealth if (config.contains("maxHealth")) { diff --git a/src/main/java/io/github/dre2n/dungeonsxl/player/DGamePlayer.java b/src/main/java/io/github/dre2n/dungeonsxl/player/DGamePlayer.java index b5e70ebe..58c22a37 100644 --- a/src/main/java/io/github/dre2n/dungeonsxl/player/DGamePlayer.java +++ b/src/main/java/io/github/dre2n/dungeonsxl/player/DGamePlayer.java @@ -589,7 +589,7 @@ public class DGamePlayer extends DInstancePlayer { dGroup.removeUnplayedFloor(dGroup.getMapName()); dGroup.setMapName(newFloor); - GameWorld gameWorld = GameWorld.load(newFloor); + GameWorld gameWorld = new GameWorld(newFloor); dGroup.setGameWorld(gameWorld); for (Player player : dGroup.getPlayers()) { DGamePlayer dPlayer = getByPlayer(player); diff --git a/src/main/java/io/github/dre2n/dungeonsxl/sign/ClassesSign.java b/src/main/java/io/github/dre2n/dungeonsxl/sign/ClassesSign.java index 9174a789..34d4b747 100644 --- a/src/main/java/io/github/dre2n/dungeonsxl/sign/ClassesSign.java +++ b/src/main/java/io/github/dre2n/dungeonsxl/sign/ClassesSign.java @@ -33,6 +33,7 @@ public class ClassesSign extends DSign { public ClassesSign(Sign sign, GameWorld gameWorld) { super(sign, gameWorld); + dClass = plugin.getDClasses().getByName(sign.getLine(1)); } /* Getters and setters */ @@ -55,8 +56,7 @@ public class ClassesSign extends DSign { @Override public boolean check() { String[] lines = getSign().getLines(); - dClass = plugin.getDClasses().getByName(lines[1]); - return dClass != null; + return plugin.getDClasses().getByName(lines[1]) != null; } @Override @@ -73,7 +73,6 @@ public class ClassesSign extends DSign { getSign().update(); getGameWorld().getSignClass().add(getSign()); - } @Override diff --git a/src/main/java/io/github/dre2n/dungeonsxl/task/MobSpawnTask.java b/src/main/java/io/github/dre2n/dungeonsxl/task/MobSpawnTask.java index 82684916..3e89bdc3 100644 --- a/src/main/java/io/github/dre2n/dungeonsxl/task/MobSpawnTask.java +++ b/src/main/java/io/github/dre2n/dungeonsxl/task/MobSpawnTask.java @@ -75,7 +75,7 @@ public class MobSpawnTask extends BukkitRunnable { DMobType mobType = DungeonsXL.getInstance().getDMobTypes().getByName(sign.getMob()); if (mobType != null) { - mobType.spawn(GameWorld.getByWorld(world), spawnLoc); + mobType.spawn(gameWorld, spawnLoc); } // Set the amount diff --git a/src/main/java/io/github/dre2n/dungeonsxl/world/GameWorld.java b/src/main/java/io/github/dre2n/dungeonsxl/world/GameWorld.java index 2bdba9eb..5971b827 100644 --- a/src/main/java/io/github/dre2n/dungeonsxl/world/GameWorld.java +++ b/src/main/java/io/github/dre2n/dungeonsxl/world/GameWorld.java @@ -109,6 +109,11 @@ public class GameWorld { } } + public GameWorld(String name) { + this(); + load(name); + } + /** * @return * the Game connected to the GameWorld @@ -472,20 +477,18 @@ public class GameWorld { } } - /* Statics */ - public static GameWorld load(String name) { + public void load(String name) { GameWorldLoadEvent event = new GameWorldLoadEvent(name); plugin.getServer().getPluginManager().callEvent(event); if (event.isCancelled()) { - return null; + return; } File file = new File(plugin.getDataFolder(), "/maps/" + name); if (file.exists()) { - GameWorld gameWorld = new GameWorld(); - gameWorld.mapName = name; + mapName = name; // Unload empty editWorlds for (EditWorld editWorld : plugin.getEditWorlds()) { @@ -495,55 +498,52 @@ public class GameWorld { } // Config einlesen - gameWorld.worldConfig = new WorldConfig(new File(plugin.getDataFolder() + "/maps/" + gameWorld.mapName, "config.yml")); + worldConfig = new WorldConfig(new File(plugin.getDataFolder() + "/maps/" + mapName, "config.yml")); // Secure Objects - gameWorld.secureObjects = gameWorld.worldConfig.getSecureObjects(); + secureObjects = worldConfig.getSecureObjects(); - if (Bukkit.getWorld("DXL_Game_" + gameWorld.id) == null) { + if (Bukkit.getWorld("DXL_Game_" + id) == null) { // World - FileUtil.copyDirectory(file, new File("DXL_Game_" + gameWorld.id), DungeonsXL.EXCLUDED_FILES); + FileUtil.copyDirectory(file, new File("DXL_Game_" + id), DungeonsXL.EXCLUDED_FILES); // Id File - File idFile = new File("DXL_Game_" + gameWorld.id + "/.id_" + name); + File idFile = new File("DXL_Game_" + id + "/.id_" + name); try { idFile.createNewFile(); } catch (IOException e) { e.printStackTrace(); } - gameWorld.world = plugin.getServer().createWorld(WorldCreator.name("DXL_Game_" + gameWorld.id)); + world = plugin.getServer().createWorld(WorldCreator.name("DXL_Game_" + id)); ObjectInputStream os; try { - os = new ObjectInputStream(new FileInputStream(new File(plugin.getDataFolder() + "/maps/" + gameWorld.mapName + "/DXLData.data"))); + os = new ObjectInputStream(new FileInputStream(new File(plugin.getDataFolder() + "/maps/" + mapName + "/DXLData.data"))); int length = os.readInt(); for (int i = 0; i < length; i++) { int x = os.readInt(); int y = os.readInt(); int z = os.readInt(); - Block block = gameWorld.world.getBlockAt(x, y, z); - gameWorld.checkSign(block); + Block block = world.getBlockAt(x, y, z); + checkSign(block); } os.close(); } catch (FileNotFoundException exception) { - plugin.getLogger().info("Could not find any sign data for the world \"" + name + "\"!"); + MessageUtil.log(plugin, "Could not find any sign data for the world \"" + name + "\"!"); } catch (IOException exception) { exception.printStackTrace(); } } - - return gameWorld; } - - return null; } + /* Statics */ public static GameWorld getByWorld(World world) { for (GameWorld gameWorld : plugin.getGameWorlds()) { if (gameWorld.getWorld() == null) {