diff options
Diffstat (limited to 'src/main/java/net/tylermurphy/hideAndSeek/configuration')
-rw-r--r-- | src/main/java/net/tylermurphy/hideAndSeek/configuration/Map.java | 64 | ||||
-rw-r--r-- | src/main/java/net/tylermurphy/hideAndSeek/configuration/Maps.java | 30 |
2 files changed, 66 insertions, 28 deletions
diff --git a/src/main/java/net/tylermurphy/hideAndSeek/configuration/Map.java b/src/main/java/net/tylermurphy/hideAndSeek/configuration/Map.java index 42cab4b..5e9b6ae 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/configuration/Map.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/configuration/Map.java @@ -23,7 +23,9 @@ public class Map { seekerLobbyPosition = new Location(null, 0, 0, 0); private String - gameWorldName = "world"; + spawnWorldName = "world", + lobbyWorldName = "world", + seekerLobbyWorldName = "world"; private int xBoundMin = 0, @@ -57,15 +59,31 @@ public class Map { public void setSpawn(Location pos) { this.spawnPosition = pos; if(pos.getWorld() != null) - this.gameWorldName = pos.getWorld().getName(); + this.spawnWorldName = pos.getWorld().getName(); } public void setLobby(Location pos) { this.lobbyPosition = pos; + if(pos.getWorld() != null) + this.lobbyWorldName = pos.getWorld().getName(); } public void setSeekerLobby(Location pos) { this.seekerLobbyPosition = pos; + if(pos.getWorld() != null) + this.seekerLobbyWorldName = pos.getWorld().getName(); + } + + public void setSpawnName(String name) { + this.spawnWorldName = name; + } + + public void setLobbyName(String name) { + this.lobbyWorldName = name; + } + + public void setSeekerLobbyName(String name) { + this.seekerLobbyWorldName = name; } public void setWorldBorderData(int x, int z, int size, int delay, int move) { @@ -103,7 +121,7 @@ public class Map { public Location getGameSpawn() { if(mapSaveEnabled) { return new Location( - Bukkit.getWorld("hs_" + gameWorldName), + Bukkit.getWorld("hs_" + spawnWorldName), spawnPosition.getX(), spawnPosition.getY(), spawnPosition.getZ() @@ -114,7 +132,10 @@ public class Map { } public String getGameSpawnName() { - return "hs_"+gameWorldName; + if(mapSaveEnabled) + return "hs_"+ spawnWorldName; + else + return spawnWorldName; } public Location getSpawn() { @@ -122,21 +143,29 @@ public class Map { } public String getSpawnName() { - return gameWorldName; + return spawnWorldName; } public Location getLobby() { return lobbyPosition; } + public String getLobbyName() { + return lobbyWorldName; + } + public Location getSeekerLobby() { return seekerLobbyPosition; } + public String getSeekerLobbyName() { + return seekerLobbyWorldName; + } + public Location getGameSeekerLobby() { if(mapSaveEnabled) { return new Location( - Bukkit.getWorld("hs_" + gameWorldName), + Bukkit.getWorld("hs_" + getSeekerLobbyName()), seekerLobbyPosition.getX(), seekerLobbyPosition.getY(), seekerLobbyPosition.getZ() @@ -203,19 +232,11 @@ public class Map { } public boolean isNotSetup() { - if (spawnPosition.getBlockX() == 0 && spawnPosition.getBlockY() == 0 && spawnPosition.getBlockZ() == 0) return true; - if (lobbyPosition.getBlockX() == 0 && lobbyPosition.getBlockY() == 0 && lobbyPosition.getBlockZ() == 0) return true; - if (exitPosition == null || exitPosition.getBlockX() == 0 && exitPosition.getBlockY() == 0 && exitPosition.getBlockZ() == 0) return true; - if (exitPosition.getWorld() == null) { - Bukkit.getServer().createWorld(new WorldCreator(exitWorld).generator(new VoidGenerator())); - World world = Bukkit.getServer().getWorld(exitWorld); - if(world == null) return true; - } - if (seekerLobbyPosition.getBlockX() == 0 && seekerLobbyPosition.getBlockY() == 0 && seekerLobbyPosition.getBlockZ() == 0) return true; - if (mapSaveEnabled) { - File destination = new File(Main.getInstance().getWorldContainer() + File.separator + spawnPosition.getWorld().getName()); - if (!destination.exists()) return true; - } + if (spawnPosition.getBlockX() == 0 && spawnPosition.getBlockY() == 0 && spawnPosition.getBlockZ() == 0 || !Map.worldExists(spawnWorldName)) return true; + if (lobbyPosition.getBlockX() == 0 && lobbyPosition.getBlockY() == 0 && lobbyPosition.getBlockZ() == 0 || !Map.worldExists(lobbyWorldName)) return true; + if (exitPosition == null || exitPosition.getBlockX() == 0 && exitPosition.getBlockY() == 0 && exitPosition.getBlockZ() == 0 || !Map.worldExists(exitWorld) ) return true; + if (seekerLobbyPosition.getBlockX() == 0 && seekerLobbyPosition.getBlockY() == 0 && seekerLobbyPosition.getBlockZ() == 0 || !Map.worldExists(seekerLobbyWorldName)) return true; + if (mapSaveEnabled && !Map.worldExists(getGameSpawnName())) return true; if(isWorldBorderEnabled() && new Vector(spawnPosition.getX(), 0, spawnPosition.getZ()).distance(new Vector(xWorldBorder, 0, zWorldBorder)) > 100) return true; return xBoundMin == 0 || zBoundMin == 0 || xBoundMax == 0 || zBoundMax == 0; @@ -225,4 +246,9 @@ public class Map { return spawnPosition.getBlockX() == 0 && spawnPosition.getBlockY() == 0 && spawnPosition.getBlockZ() == 0; } + public static boolean worldExists(String worldName) { + File destination = new File(Main.getInstance().getWorldContainer()+File.separator+worldName); + return destination.isDirectory(); + } + } diff --git a/src/main/java/net/tylermurphy/hideAndSeek/configuration/Maps.java b/src/main/java/net/tylermurphy/hideAndSeek/configuration/Maps.java index 4f18639..ff1b396 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/configuration/Maps.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/configuration/Maps.java @@ -60,7 +60,6 @@ public class Maps { MAPS.clear(); for(String key : keys) { - System.out.println(key); MAPS.put(key, parseMap(maps, key)); } @@ -71,8 +70,11 @@ public class Maps { if(data == null) return null; Map map = new Map(name); map.setSpawn(setSpawn(data, "game")); + map.setSpawnName(data.getString("spawns.game.world")); map.setLobby(setSpawn(data, "lobby")); + map.setLobbyName(data.getString("spawns.lobby.world")); map.setSeekerLobby(setSpawn(data, "seeker")); + map.setSeekerLobbyName(data.getString("spawns.seeker.world")); map.setBoundMin(data.getInt("bounds.min.x"), data.getInt("bounds.min.z")); map.setBoundMax(data.getInt("bounds.max.x"), data.getInt("bounds.max.z")); map.setWorldBorderData( @@ -100,8 +102,8 @@ public class Maps { private static Location setSpawn(ConfigurationSection data, String spawn) { String worldName = data.getString("spawns."+spawn+".world"); if(worldName == null) return new Location(null, 0, 0, 0); + if(!Map.worldExists(worldName)) return new Location(null, 0, 0, 0); World world = Bukkit.getWorld(worldName); - if(world == null) return new Location(null, 0, 0, 0); double x = data.getDouble("spawns."+spawn+".x"); double y = data.getDouble("spawns."+spawn+".y"); double z = data.getDouble("spawns."+spawn+".z"); @@ -115,9 +117,9 @@ public class Maps { for(Map map : MAPS.values()) { ConfigurationSection data = new YamlConfiguration(); - saveSpawn(data, map.getSpawn(), "game"); - saveSpawn(data, map.getLobby(), "lobby"); - saveSpawn(data, map.getSeekerLobby(), "seeker"); + saveSpawn(data, map.getSpawn(), "game", map); + saveSpawn(data, map.getLobby(), "lobby", map); + saveSpawn(data, map.getSeekerLobby(), "seeker", map); data.set("bounds.min.x", map.getBoundsMin().getX()); data.set("bounds.min.z", map.getBoundsMin().getZ()); data.set("bounds.max.x", map.getBoundsMax().getX()); @@ -137,15 +139,25 @@ public class Maps { } - private static void saveSpawn(ConfigurationSection data, Location spawn, String name) { - if(spawn.getWorld() != null) { - data.set("spawns." + name + ".world", spawn.getWorld().getName()); - } else { + private static void saveSpawn(ConfigurationSection data, Location spawn, String name, Map map) { + String worldName = getWorldName(name, map); + if(worldName == null || !Map.worldExists(worldName)) { data.set("spawns." + name + ".world", "world"); + } else { + data.set("spawns." + name + ".world", worldName); } data.set("spawns." + name + ".x", spawn.getX()); data.set("spawns." + name + ".y", spawn.getY()); data.set("spawns." + name + ".z", spawn.getZ()); } + private static String getWorldName(String name, Map map) { + switch (name) { + case "game": return map.getSpawnName(); + case "lobby": return map.getLobbyName(); + case "seeker": return map.getSeekerLobbyName(); + default: return null; + } + } + } |