summaryrefslogtreewikicommitdiff
path: root/src/main/java/net/tylermurphy/hideAndSeek/configuration
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/main/java/net/tylermurphy/hideAndSeek/configuration/Config.java10
-rw-r--r--src/main/java/net/tylermurphy/hideAndSeek/configuration/Map.java71
-rw-r--r--src/main/java/net/tylermurphy/hideAndSeek/configuration/Maps.java26
3 files changed, 26 insertions, 81 deletions
diff --git a/src/main/java/net/tylermurphy/hideAndSeek/configuration/Config.java b/src/main/java/net/tylermurphy/hideAndSeek/configuration/Config.java
index ee7aa18..dbc9e37 100644
--- a/src/main/java/net/tylermurphy/hideAndSeek/configuration/Config.java
+++ b/src/main/java/net/tylermurphy/hideAndSeek/configuration/Config.java
@@ -24,9 +24,8 @@ import com.cryptomorin.xseries.XMaterial;
import com.cryptomorin.xseries.XSound;
import net.tylermurphy.hideAndSeek.Main;
import net.tylermurphy.hideAndSeek.game.util.CountdownDisplay;
-import org.bukkit.Bukkit;
+import net.tylermurphy.hideAndSeek.util.Location;
import org.bukkit.ChatColor;
-import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.configuration.file.YamlConfiguration;
@@ -34,7 +33,6 @@ import org.bukkit.inventory.ItemStack;
import org.jetbrains.annotations.Nullable;
import java.util.ArrayList;
-import java.util.Collections;
import java.util.List;
import java.util.Optional;
@@ -59,8 +57,7 @@ public class Config {
databasePort,
databaseUser,
databasePass,
- databaseName,
- exitWorld;
+ databaseName;
public static boolean
nameTagsVisible,
@@ -150,12 +147,11 @@ public class Config {
// Locations
exitPosition = new Location(
- Bukkit.getWorld(config.getString("exit.world")),
+ config.getString("exit.world"),
config.getInt("exit.x"),
config.getInt("exit.y"),
config.getInt("exit.z")
);
- exitWorld = config.getString("exit.world");
mapSaveEnabled = config.getBoolean("mapSaveEnabled");
//Taunt
diff --git a/src/main/java/net/tylermurphy/hideAndSeek/configuration/Map.java b/src/main/java/net/tylermurphy/hideAndSeek/configuration/Map.java
index 406f161..8c3f8a7 100644
--- a/src/main/java/net/tylermurphy/hideAndSeek/configuration/Map.java
+++ b/src/main/java/net/tylermurphy/hideAndSeek/configuration/Map.java
@@ -1,12 +1,11 @@
package net.tylermurphy.hideAndSeek.configuration;
-import java.io.File;
import java.util.ArrayList;
import java.util.List;
-import net.tylermurphy.hideAndSeek.Main;
import net.tylermurphy.hideAndSeek.game.events.Border;
import net.tylermurphy.hideAndSeek.world.WorldLoader;
+import net.tylermurphy.hideAndSeek.util.Location;
import org.bukkit.*;
import org.bukkit.util.Vector;
import org.jetbrains.annotations.NotNull;
@@ -18,14 +17,9 @@ public class Map {
private final String name;
private Location
- spawnPosition = new Location(null, 0, 0, 0),
- lobbyPosition = new Location(null, 0, 0, 0),
- seekerLobbyPosition = new Location(null, 0, 0, 0);
-
- private String
- spawnWorldName = "world",
- lobbyWorldName = "world",
- seekerLobbyWorldName = "world";
+ spawnPosition = Location.getDefault(),
+ lobbyPosition = Location.getDefault(),
+ seekerLobbyPosition = Location.getDefault();
private int
xBoundMin = 0,
@@ -58,32 +52,14 @@ public class Map {
public void setSpawn(Location pos) {
this.spawnPosition = pos;
- if(pos.getWorld() != null)
- 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) {
@@ -121,12 +97,7 @@ public class Map {
@NotNull
public Location getGameSpawn() {
if(mapSaveEnabled) {
- return new Location(
- Bukkit.getWorld("hs_" + spawnWorldName),
- spawnPosition.getX(),
- spawnPosition.getY(),
- spawnPosition.getZ()
- );
+ return spawnPosition.changeWorld("hs_"+name);
} else {
return spawnPosition;
}
@@ -135,9 +106,9 @@ public class Map {
@NotNull
public String getGameSpawnName() {
if(mapSaveEnabled)
- return "hs_"+ spawnWorldName;
+ return getGameSpawn().getWorld();
else
- return spawnWorldName;
+ return getSpawn().getWorld();
}
@NotNull
@@ -147,7 +118,7 @@ public class Map {
@NotNull
public String getSpawnName() {
- return spawnWorldName;
+ return getSpawn().getWorld();
}
@NotNull
@@ -157,7 +128,7 @@ public class Map {
@NotNull
public String getLobbyName() {
- return lobbyWorldName;
+ return getLobby().getWorld();
}
@NotNull
@@ -167,18 +138,13 @@ public class Map {
@NotNull
public String getSeekerLobbyName() {
- return seekerLobbyWorldName;
+ return getSeekerLobby().getWorld();
}
@NotNull
public Location getGameSeekerLobby() {
if(mapSaveEnabled) {
- return new Location(
- Bukkit.getWorld("hs_" + getSeekerLobbyName()),
- seekerLobbyPosition.getX(),
- seekerLobbyPosition.getY(),
- seekerLobbyPosition.getZ()
- );
+ return seekerLobbyPosition.changeWorld("hs_"+name);
} else {
return seekerLobbyPosition;
}
@@ -249,11 +215,11 @@ public class Map {
}
public boolean isNotSetup() {
- if (spawnPosition.getBlockX() == 0 && spawnPosition.getBlockY() == 0 && spawnPosition.getBlockZ() == 0 || Map.worldDoesntExist(spawnWorldName)) return true;
- if (lobbyPosition.getBlockX() == 0 && lobbyPosition.getBlockY() == 0 && lobbyPosition.getBlockZ() == 0 || Map.worldDoesntExist(lobbyWorldName)) return true;
- if (exitPosition == null || exitPosition.getBlockX() == 0 && exitPosition.getBlockY() == 0 && exitPosition.getBlockZ() == 0 || Map.worldDoesntExist(exitWorld)) return true;
- if (seekerLobbyPosition.getBlockX() == 0 && seekerLobbyPosition.getBlockY() == 0 && seekerLobbyPosition.getBlockZ() == 0 || Map.worldDoesntExist(seekerLobbyWorldName)) return true;
- if (mapSaveEnabled && Map.worldDoesntExist(getGameSpawnName())) return true;
+ if (spawnPosition.getBlockX() == 0 && spawnPosition.getBlockY() == 0 && spawnPosition.getBlockZ() == 0 || !spawnPosition.exists()) return true;
+ if (lobbyPosition.getBlockX() == 0 && lobbyPosition.getBlockY() == 0 && lobbyPosition.getBlockZ() == 0 || !lobbyPosition.exists()) return true;
+ if (exitPosition == null || exitPosition.getBlockX() == 0 && exitPosition.getBlockY() == 0 && exitPosition.getBlockZ() == 0 || !exitPosition.exists()) return true;
+ if (seekerLobbyPosition.getBlockX() == 0 && seekerLobbyPosition.getBlockY() == 0 && seekerLobbyPosition.getBlockZ() == 0 || !seekerLobbyPosition.exists()) return true;
+ if (mapSaveEnabled && !getGameSpawn().exists()) return true;
if (blockhunt && blockhuntBlocks.isEmpty()) return true;
if(isWorldBorderEnabled() &&
new Vector(spawnPosition.getX(), 0, spawnPosition.getZ()).distance(new Vector(xWorldBorder, 0, zWorldBorder)) > 100) return true;
@@ -268,9 +234,4 @@ public class Map {
return xBoundMin == 0 || zBoundMin == 0 || xBoundMax == 0 || zBoundMax == 0;
}
- public static boolean worldDoesntExist(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 a27a542..98ba4a0 100644
--- a/src/main/java/net/tylermurphy/hideAndSeek/configuration/Maps.java
+++ b/src/main/java/net/tylermurphy/hideAndSeek/configuration/Maps.java
@@ -3,10 +3,8 @@ package net.tylermurphy.hideAndSeek.configuration;
import java.util.*;
import java.util.stream.Collectors;
-import org.bukkit.Bukkit;
-import org.bukkit.Location;
+import net.tylermurphy.hideAndSeek.util.Location;
import org.bukkit.Material;
-import org.bukkit.World;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.configuration.file.YamlConfiguration;
@@ -74,12 +72,9 @@ public class Maps {
ConfigurationSection data = maps.getConfigurationSection(name);
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.setSpawn(getSpawn(data, "game"));
+ map.setLobby(getSpawn(data, "lobby"));
+ map.setSeekerLobby(getSpawn(data, "seeker"));
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(
@@ -104,11 +99,8 @@ public class Maps {
return map;
}
- 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.worldDoesntExist(worldName)) return new Location(null, 0, 0, 0);
- World world = Bukkit.getWorld(worldName);
+ private static Location getSpawn(ConfigurationSection data, String spawn) {
+ String world = data.getString("spawns."+spawn+".world");
double x = data.getDouble("spawns."+spawn+".x");
double y = data.getDouble("spawns."+spawn+".y");
double z = data.getDouble("spawns."+spawn+".z");
@@ -146,11 +138,7 @@ public class Maps {
private static void saveSpawn(ConfigurationSection data, Location spawn, String name, Map map) {
String worldName = getWorldName(name, map);
- if(worldName == null || Map.worldDoesntExist(worldName)) {
- data.set("spawns." + name + ".world", "world");
- } else {
- data.set("spawns." + name + ".world", worldName);
- }
+ 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());