summaryrefslogtreewikicommitdiff
path: root/src/main/java/net/tylermurphy/hideAndSeek/configuration
diff options
context:
space:
mode:
authorTyler Murphy <tylermurphy534@gmail.com>2022-10-30 15:39:34 -0400
committerTyler Murphy <tylermurphy534@gmail.com>2022-10-30 15:39:34 -0400
commit667a365e7b406063617e336798ec95a0e524e2b1 (patch)
tree6c0e9c96474801be2c41ab6bb201b53ef4e2fe97 /src/main/java/net/tylermurphy/hideAndSeek/configuration
parentUpdate 'README.md' (diff)
downloadkenshinshideandseek-667a365e7b406063617e336798ec95a0e524e2b1.tar.gz
kenshinshideandseek-667a365e7b406063617e336798ec95a0e524e2b1.tar.bz2
kenshinshideandseek-667a365e7b406063617e336798ec95a0e524e2b1.zip
start adding multi map support
Diffstat (limited to '')
-rw-r--r--src/main/java/net/tylermurphy/hideAndSeek/configuration/Config.java100
-rw-r--r--src/main/java/net/tylermurphy/hideAndSeek/configuration/ConfigManager.java18
-rw-r--r--src/main/java/net/tylermurphy/hideAndSeek/configuration/Map.java196
-rw-r--r--src/main/java/net/tylermurphy/hideAndSeek/configuration/Maps.java136
4 files changed, 362 insertions, 88 deletions
diff --git a/src/main/java/net/tylermurphy/hideAndSeek/configuration/Config.java b/src/main/java/net/tylermurphy/hideAndSeek/configuration/Config.java
index a71369f..3a43e15 100644
--- a/src/main/java/net/tylermurphy/hideAndSeek/configuration/Config.java
+++ b/src/main/java/net/tylermurphy/hideAndSeek/configuration/Config.java
@@ -24,12 +24,13 @@ 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 org.bukkit.ChatColor;
+import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.inventory.ItemStack;
-import org.bukkit.util.Vector;
import org.jetbrains.annotations.Nullable;
import java.util.ArrayList;
@@ -49,10 +50,6 @@ public class Config {
abortPrefix,
gameOverPrefix,
warningPrefix,
- spawnWorld,
- seekerLobbyWorld,
- exitWorld,
- lobbyWorld,
locale,
leaveServer,
placeholderError,
@@ -62,20 +59,13 @@ public class Config {
databasePort,
databaseUser,
databasePass,
- databaseName;
-
- public static Vector
- spawnPosition,
- lobbyPosition,
- exitPosition,
- seekerLobbyPosition,
- worldBorderPosition;
+ databaseName,
+ exitWorld;
public static boolean
nameTagsVisible,
permissionsRequired,
announceMessagesToNonPlayers,
- worldBorderEnabled,
tauntEnabled,
tauntCountdown,
tauntLast,
@@ -93,20 +83,11 @@ public class Config {
mapSaveEnabled,
allowNaturalCauses,
saveInventory,
- blockhuntEnabled,
delayedRespawn;
public static int
minPlayers,
- worldBorderSize,
- worldBorderDelay,
- currentWorldborderSize,
- worldBorderChange,
gameLength,
- saveMinX,
- saveMinZ,
- saveMaxX,
- saveMaxZ,
tauntDelay,
glowLength,
countdown,
@@ -132,9 +113,6 @@ public class Config {
blockedCommands,
blockedInteracts;
- public static List<Material>
- blockhuntBlocks;
-
public static String
LOBBY_TITLE,
GAME_TITLE,
@@ -166,6 +144,9 @@ public class Config {
public static CountdownDisplay
countdownDisplay;
+
+ public static Location
+ exitPosition;
public static void loadConfig() {
@@ -173,50 +154,8 @@ public class Config {
config.saveConfig();
ConfigManager leaderboard = ConfigManager.create("leaderboard.yml");
- //Spawn
- spawnPosition = new Vector(
- config.getDouble("spawns.game.x"),
- Math.max(Main.getInstance().supports(18) ? -64 : 0, Math.min(255, config.getDouble("spawns.game.y"))),
- config.getDouble("spawns.game.z")
- );
- spawnWorld = config.getString("spawns.game.world");
-
- ///Lobby
- lobbyPosition = new Vector(
- config.getDouble("spawns.lobby.x"),
- Math.max(Main.getInstance().supports(18) ? -64 : 0, Math.min(255, config.getDouble("spawns.lobby.y"))),
- config.getDouble("spawns.lobby.z")
- );
- lobbyWorld = config.getString("spawns.lobby.world");
-
- ///Seeker Lobby
- seekerLobbyPosition = new Vector(
- config.getDouble("spawns.seeker.x"),
- Math.max(Main.getInstance().supports(18) ? -64 : 0, Math.min(255, config.getDouble("spawns.seeker.y"))),
- config.getDouble("spawns.seeker.z")
- );
- seekerLobbyWorld = config.getString("spawns.seeker.world");
-
announceMessagesToNonPlayers = config.getBoolean("announceMessagesToNonPlayers");
- exitPosition = new Vector(
- config.getDouble("spawns.exit.x"),
- Math.max(Main.getInstance().supports(18) ? -64 : 0, Math.min(255, config.getDouble("spawns.exit.y"))),
- config.getDouble("spawns.exit.z")
- );
- exitWorld = config.getString("spawns.exit.world");
-
- //World border
- worldBorderPosition = new Vector(
- config.getInt("worldBorder.x"),
- 0,
- config.getInt("worldBorder.z")
- );
- worldBorderSize = Math.max(100, config.getInt("worldBorder.size"));
- worldBorderDelay = Math.max(1, config.getInt("worldBorder.delay"));
- worldBorderEnabled = config.getBoolean("worldBorder.enabled");
- worldBorderChange = config.getInt("worldBorder.moveAmount");
-
//Prefix
char SYMBOLE = '\u00A7';
String SYMBOLE_STRING = String.valueOf(SYMBOLE);
@@ -229,11 +168,14 @@ public class Config {
gameOverPrefix = config.getString("prefix.gameover").replace("&", SYMBOLE_STRING);
warningPrefix = config.getString("prefix.warning").replace("&", SYMBOLE_STRING);
- //Map Bounds
- saveMinX = config.getInt("bounds.min.x");
- saveMinZ = config.getInt("bounds.min.z");
- saveMaxX = config.getInt("bounds.max.x");
- saveMaxZ = config.getInt("bounds.max.z");
+ // Locations
+ exitPosition = new Location(
+ Bukkit.getWorld(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
@@ -305,18 +247,6 @@ public class Config {
}
bungeeLeave = config.getString("leaveType") == null || config.getString("leaveType").equalsIgnoreCase("proxy");
leaveServer = config.getString("leaveServer");
- blockhuntEnabled = config.getBoolean("blockhunt.enabled") && Main.getInstance().supports(9);
- blockhuntBlocks = new ArrayList<>();
- tempInteracts = config.getStringList("blockhunt.blocks");
- for(String id : tempInteracts) {
- Optional<XMaterial> optional_mat = XMaterial.matchXMaterial(id);
- if (optional_mat.isPresent()) {
- Material mat = optional_mat.get().parseMaterial();
- if (mat != null) {
- blockhuntBlocks.add(mat);
- }
- }
- }
solidifyTime = Math.max(20,config.getInt("blockhunt.solidifyTime"));
//Leaderboard
diff --git a/src/main/java/net/tylermurphy/hideAndSeek/configuration/ConfigManager.java b/src/main/java/net/tylermurphy/hideAndSeek/configuration/ConfigManager.java
index 5e28258..e09001e 100644
--- a/src/main/java/net/tylermurphy/hideAndSeek/configuration/ConfigManager.java
+++ b/src/main/java/net/tylermurphy/hideAndSeek/configuration/ConfigManager.java
@@ -25,8 +25,8 @@ import org.bukkit.configuration.InvalidConfigurationException;
import org.bukkit.configuration.file.YamlConfiguration;
import java.io.*;
-import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
+import java.nio.file.Files;
import java.util.List;
import java.util.Map;
@@ -188,6 +188,10 @@ public class ConfigManager {
config.set(path, defaultConfig.get(path));
}
+ public void resetAll() {
+ config = new YamlConfiguration();
+ }
+
public void resetFile(String newDefaultFilename) {
this.defaultFilename = newDefaultFilename;
@@ -226,6 +230,14 @@ public class ConfigManager {
config.set(path, value);
}
+ public void overwriteConfig() {
+ try {
+ this.config.save(file);
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ }
+
public void saveConfig() {
try {
InputStream is = Main.getInstance().getResource(defaultFilename);
@@ -233,7 +245,7 @@ public class ConfigManager {
throw new RuntimeException("Could not create input stream for "+defaultFilename);
}
StringBuilder textBuilder = new StringBuilder(new String("".getBytes(), StandardCharsets.UTF_8));
- Reader reader = new BufferedReader(new InputStreamReader(is, Charset.forName(StandardCharsets.UTF_8.name())));
+ Reader reader = new BufferedReader(new InputStreamReader(is, StandardCharsets.UTF_8));
int c;
while((c = reader.read()) != -1) {
textBuilder.append((char) c);
@@ -285,7 +297,7 @@ public class ConfigManager {
yamlString = builder.toString();
}
}
- Writer fileWriter = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(file), StandardCharsets.UTF_8));
+ Writer fileWriter = new BufferedWriter(new OutputStreamWriter(Files.newOutputStream(file.toPath()), StandardCharsets.UTF_8));
fileWriter.write(yamlString);
fileWriter.close();
} catch (IOException e) {
diff --git a/src/main/java/net/tylermurphy/hideAndSeek/configuration/Map.java b/src/main/java/net/tylermurphy/hideAndSeek/configuration/Map.java
new file mode 100644
index 0000000..b18a0b0
--- /dev/null
+++ b/src/main/java/net/tylermurphy/hideAndSeek/configuration/Map.java
@@ -0,0 +1,196 @@
+package net.tylermurphy.hideAndSeek.configuration;
+
+import java.io.File;
+import java.util.List;
+
+import net.tylermurphy.hideAndSeek.Main;
+import net.tylermurphy.hideAndSeek.game.events.Border;
+import net.tylermurphy.hideAndSeek.world.VoidGenerator;
+import net.tylermurphy.hideAndSeek.world.WorldLoader;
+import org.bukkit.*;
+import org.bukkit.util.Vector;
+
+import static net.tylermurphy.hideAndSeek.configuration.Config.*;
+
+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
+ gameWorldName;
+
+ private int
+ xBoundMin = 0,
+ zBoundMin = 0,
+ xBoundMax = 0,
+ zBoundMax = 0,
+ xWorldBorder = 0,
+ zWorldBorder = 0,
+ worldBorderSize = 0,
+ worldBorderDelay = 0,
+ worldBorderChange = 0;
+
+ private boolean
+ blockhunt;
+
+ private List<Material>
+ blockhuntBlocks;
+
+ private final Border
+ worldBorder;
+
+ private final WorldLoader
+ worldLoader;
+
+ public Map(String name) {
+ this.name = name;
+ this.worldBorder = new Border(this);
+ this.worldLoader = new WorldLoader(this);
+ }
+
+ public void setSpawn(Location pos) {
+ this.spawnPosition = pos;
+ this.gameWorldName = pos.getWorld().getName();
+ }
+
+ public void setLobby(Location pos) {
+ this.lobbyPosition = pos;
+ }
+
+ public void setSeekerLobby(Location pos) {
+ this.seekerLobbyPosition = pos;
+ }
+
+ public void setWorldBorderData(int x, int z, int size, int delay, int move) {
+ if(size < 1) {
+ this.worldBorderSize = 0;
+ this.worldBorderDelay = 0;
+ this.worldBorderChange = 0;
+ this.xWorldBorder = 0;
+ this.zWorldBorder = 0;
+ this.worldBorder.resetWorldBorder();
+ } else {
+ this.worldBorderSize = size;
+ this.worldBorderDelay = delay;
+ this.worldBorderChange = move;
+ this.xWorldBorder = x;
+ this.zWorldBorder = z;
+ }
+ }
+
+ public void setBlockhunt(boolean enabled, List<Material> blocks) {
+ this.blockhunt = enabled;
+ this.blockhuntBlocks = blocks;
+ }
+
+ public void setBoundMin(int x, int z) {
+ this.xBoundMin = x;
+ this.zBoundMin = z;
+ }
+
+ public void setBoundMax(int x, int z) {
+ this.xBoundMax = x;
+ this.zBoundMax = z;
+ }
+
+ public Location getSpawn() {
+ if(mapSaveEnabled)
+ spawnPosition.setWorld(Bukkit.getWorld("hs_"+gameWorldName));
+ else
+ spawnPosition.setWorld(Bukkit.getWorld(gameWorldName));
+ return spawnPosition;
+ }
+
+ public Location getLobby() {
+ return lobbyPosition;
+ }
+
+ public Location getSeekerLobby() {
+ return seekerLobbyPosition;
+ }
+
+ public boolean isWorldBorderEnabled() {
+ return worldBorderSize > 0;
+ }
+
+ public Vector getWorldBorderPos() {
+ return new Vector(
+ xWorldBorder,
+ 0,
+ zWorldBorder
+ );
+ }
+
+ public Vector getWorldBorderData() {
+ return new Vector(
+ worldBorderSize,
+ worldBorderDelay,
+ worldBorderChange
+ );
+ }
+
+ public Border getWorldBorder() {
+ return worldBorder;
+ }
+
+ public boolean isBlockHuntEnabled() {
+ return blockhunt;
+ }
+
+ public List<Material> getBlockHunt() {
+ return blockhuntBlocks;
+ }
+
+ public Vector getBoundsMin() {
+ return new Vector(
+ xBoundMin,
+ 0,
+ zBoundMin
+ );
+ }
+
+ public Vector getBoundsMax() {
+ return new Vector(
+ xBoundMax,
+ 0,
+ zBoundMin
+ );
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public WorldLoader getWorldLoader() {
+ return worldLoader;
+ }
+
+ 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(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;
+ }
+
+ public boolean isSpawnNotSetup() {
+ return spawnPosition.getBlockX() == 0 && spawnPosition.getBlockY() == 0 && spawnPosition.getBlockZ() == 0;
+ }
+
+}
diff --git a/src/main/java/net/tylermurphy/hideAndSeek/configuration/Maps.java b/src/main/java/net/tylermurphy/hideAndSeek/configuration/Maps.java
new file mode 100644
index 0000000..736fec2
--- /dev/null
+++ b/src/main/java/net/tylermurphy/hideAndSeek/configuration/Maps.java
@@ -0,0 +1,136 @@
+package net.tylermurphy.hideAndSeek.configuration;
+
+import java.util.*;
+import java.util.stream.Collectors;
+
+import org.bukkit.Bukkit;
+import org.bukkit.Location;
+import org.bukkit.Material;
+import org.bukkit.World;
+import org.bukkit.configuration.ConfigurationSection;
+import org.bukkit.configuration.file.YamlConfiguration;
+
+import com.cryptomorin.xseries.XMaterial;
+
+public class Maps {
+
+ private static final HashMap<String, Map> MAPS = new HashMap<>();
+
+ public static Map getMap(String name) {
+ return MAPS.get(name);
+ }
+
+ public static Map getRandomMap() {
+ Optional<Map> map = MAPS.values().stream().skip(new Random().nextInt(MAPS.values().size())).findFirst();
+ if(map.isPresent()) return map.get();
+ setMap("default", new Map("default"));
+ return MAPS.get("default");
+ }
+
+ public static void setMap(String name, Map map) {
+ MAPS.put(name, map);
+ saveMaps();
+ }
+
+ public static Collection<Map> getAllMaps() {
+ return MAPS.values();
+ }
+
+ public static void loadMaps() {
+
+ ConfigManager manager = ConfigManager.create("maps.yml");
+
+ ConfigurationSection maps = manager.getConfigurationSection("maps");
+ if(maps == null) return;
+ Set<String> keys = maps.getKeys(false);
+ if(keys == null) return;
+
+ MAPS.clear();
+ for(String key : keys) {
+ System.out.println(key);
+ MAPS.put(key, parseMap(maps, key));
+ }
+
+ }
+
+ private static Map parseMap(ConfigurationSection maps, String name) {
+ ConfigurationSection data = maps.getConfigurationSection(name);
+ if(data == null) return null;
+ Map map = new Map(name);
+ map.setSpawn(setSpawn(data, "game"));
+ map.setLobby(setSpawn(data, "lobby"));
+ map.setSeekerLobby(setSpawn(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(
+ data.getInt("worldborder.pos.x"),
+ data.getInt("worldborder.pos.z"),
+ data.getInt("worldborder.size"),
+ data.getInt("worldborder.delay"),
+ data.getInt("worldborder.change")
+ );
+ map.setBlockhunt(
+ data.getBoolean("blockhunt.enabled"),
+ data.getStringList("blockhunt.blocks")
+ .stream()
+ .map(XMaterial::matchXMaterial)
+ .filter(Optional::isPresent)
+ .map(e -> e.get().parseMaterial())
+ .filter(Objects::nonNull)
+ .collect(Collectors.toList())
+ );
+ 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);
+ 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");
+ return new Location(world, x, y, z);
+ }
+
+ private static void saveMaps() {
+
+ ConfigManager manager = ConfigManager.create("maps.yml");
+ ConfigurationSection maps = new YamlConfiguration();
+
+ for(Map map : MAPS.values()) {
+ ConfigurationSection data = new YamlConfiguration();
+ saveSpawn(data, map.getSpawn(), "game");
+ saveSpawn(data, map.getLobby(), "lobby");
+ saveSpawn(data, map.getSeekerLobby(), "seeker");
+ data.set("bounds.min.x", map.getBoundsMin().getX());
+ data.set("bounds.min.z", map.getBoundsMin().getZ());
+ data.set("bounds.max.x", map.getBoundsMax().getX());
+ data.set("bounds.max.z", map.getBoundsMax().getZ());
+ data.set("worldborder.pos.x", map.getWorldBorderPos().getX());
+ data.set("worldborder.pos.z", map.getWorldBorderPos().getZ());
+ data.set("worldborder.pos.size", map.getWorldBorderData().getX());
+ data.set("worldborder.pos.delay", map.getWorldBorderData().getY());
+ data.set("worldborder.pos.change", map.getWorldBorderData().getZ());
+ data.set("blockhunt.enabled", map.isBlockHuntEnabled());
+ data.set("blockhunt.blocks", map.getBlockHunt().stream().map(Material::name));
+ maps.set(map.getName(), map);
+ }
+
+ manager.set("maps", maps);
+ manager.overwriteConfig();
+
+ }
+
+ private static void saveSpawn(ConfigurationSection data, Location spawn, String name) {
+ if(spawn.getWorld() != null) {
+ data.set("spawns." + name + ".world", spawn.getWorld().getName());
+ } else {
+ data.set("spawns." + name + ".world", "world");
+ }
+ data.set("spawns.." + name + ".x", spawn.getX());
+ data.set("spawns.." + name + ".y", spawn.getY());
+ data.set("spawns.." + name + ".z", spawn.getZ());
+ }
+
+}