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.java178
-rw-r--r--src/main/java/net/tylermurphy/hideAndSeek/configuration/ConfigManager.java175
-rw-r--r--src/main/java/net/tylermurphy/hideAndSeek/configuration/Items.java19
-rw-r--r--src/main/java/net/tylermurphy/hideAndSeek/configuration/Leaderboard.java51
-rw-r--r--src/main/java/net/tylermurphy/hideAndSeek/configuration/Localization.java31
-rw-r--r--src/main/java/net/tylermurphy/hideAndSeek/configuration/LocalizationString.java19
-rw-r--r--src/main/java/net/tylermurphy/hideAndSeek/configuration/Map.java238
-rw-r--r--src/main/java/net/tylermurphy/hideAndSeek/configuration/Maps.java158
8 files changed, 584 insertions, 285 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..5881d19 100644
--- a/src/main/java/net/tylermurphy/hideAndSeek/configuration/Config.java
+++ b/src/main/java/net/tylermurphy/hideAndSeek/configuration/Config.java
@@ -1,22 +1,3 @@
-/*
- * This file is part of Kenshins Hide and Seek
- *
- * Copyright (c) 2021 Tyler Murphy.
- *
- * Kenshins Hide and Seek free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * he Free Software Foundation version 3.
- *
- * Kenshins Hide and Seek is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- *
- */
-
package net.tylermurphy.hideAndSeek.configuration;
import com.cryptomorin.xseries.XItemStack;
@@ -24,16 +5,15 @@ import com.cryptomorin.xseries.XMaterial;
import com.cryptomorin.xseries.XSound;
import net.tylermurphy.hideAndSeek.Main;
import net.tylermurphy.hideAndSeek.game.util.CountdownDisplay;
+import net.tylermurphy.hideAndSeek.util.Location;
import org.bukkit.ChatColor;
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;
-import java.util.Collections;
import java.util.List;
import java.util.Optional;
@@ -49,10 +29,6 @@ public class Config {
abortPrefix,
gameOverPrefix,
warningPrefix,
- spawnWorld,
- seekerLobbyWorld,
- exitWorld,
- lobbyWorld,
locale,
leaveServer,
placeholderError,
@@ -64,18 +40,10 @@ public class Config {
databasePass,
databaseName;
- public static Vector
- spawnPosition,
- lobbyPosition,
- exitPosition,
- seekerLobbyPosition,
- worldBorderPosition;
-
public static boolean
nameTagsVisible,
permissionsRequired,
announceMessagesToNonPlayers,
- worldBorderEnabled,
tauntEnabled,
tauntCountdown,
tauntLast,
@@ -93,20 +61,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,
@@ -120,7 +79,6 @@ public class Config {
lobbyItemStartPosition,
flightToggleItemPosition,
teleportItemPosition,
- solidifyTime,
delayedRespawnDelay;
public static float
@@ -132,27 +90,6 @@ public class Config {
blockedCommands,
blockedInteracts;
- public static List<Material>
- blockhuntBlocks;
-
- public static String
- LOBBY_TITLE,
- GAME_TITLE,
- COUNTDOWN_WAITING,
- COUNTDOWN_COUNTING,
- COUNTDOWN_ADMINSTART,
- TAUNT_COUNTING,
- TAUNT_ACTIVE,
- TAUNT_EXPIRED,
- GLOW_ACTIVE,
- GLOW_INACTIVE,
- BORDER_COUNTING,
- BORDER_DECREASING;
-
- public static List<String>
- LOBBY_CONTENTS,
- GAME_CONTENTS;
-
public static ItemStack
lobbyLeaveItem,
lobbyStartItem,
@@ -166,74 +103,36 @@ public class Config {
public static CountdownDisplay
countdownDisplay;
+
+ public static Location
+ exitPosition;
public static void loadConfig() {
config = ConfigManager.create("config.yml");
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);
+ char SYMBOL = '\u00A7';
+ String SYMBOL_STRING = String.valueOf(SYMBOL);
- messagePrefix = config.getString("prefix.default").replace("&", SYMBOLE_STRING);
- errorPrefix = config.getString("prefix.error").replace("&", SYMBOLE_STRING);
- tauntPrefix = config.getString("prefix.taunt").replace("&", SYMBOLE_STRING);
- worldBorderPrefix = config.getString("prefix.border").replace("&", SYMBOLE_STRING);
- abortPrefix = config.getString("prefix.abort").replace("&", SYMBOLE_STRING);
- gameOverPrefix = config.getString("prefix.gameover").replace("&", SYMBOLE_STRING);
- warningPrefix = config.getString("prefix.warning").replace("&", SYMBOLE_STRING);
+ messagePrefix = config.getString("prefix.default").replace("&", SYMBOL_STRING);
+ errorPrefix = config.getString("prefix.error").replace("&", SYMBOL_STRING);
+ tauntPrefix = config.getString("prefix.taunt").replace("&", SYMBOL_STRING);
+ worldBorderPrefix = config.getString("prefix.border").replace("&", SYMBOL_STRING);
+ abortPrefix = config.getString("prefix.abort").replace("&", SYMBOL_STRING);
+ gameOverPrefix = config.getString("prefix.gameover").replace("&", SYMBOL_STRING);
+ warningPrefix = config.getString("prefix.warning").replace("&", SYMBOL_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(
+ config.getString("exit.world"),
+ config.getInt("exit.x"),
+ config.getInt("exit.y"),
+ config.getInt("exit.z")
+ );
mapSaveEnabled = config.getBoolean("mapSaveEnabled");
//Taunt
@@ -289,8 +188,7 @@ public class Config {
try {
countdownDisplay = CountdownDisplay.valueOf(config.getString("hideCountdownDisplay"));
} catch (IllegalArgumentException e) {
- countdownDisplay = CountdownDisplay.CHAT;
- Main.getInstance().getLogger().warning("hideCountdownDisplay: "+config.getString("hideCountdownDisplay")+" is not a valid configuration option!");
+ throw new RuntimeException("hideCountdownDisplay: "+config.getString("hideCountdownDisplay")+", is not a valid configuration option!");
}
blockedInteracts = new ArrayList<>();
List<String> tempInteracts = config.getStringList("blockedInteracts");
@@ -305,37 +203,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
- LOBBY_TITLE = leaderboard.getString("lobby.title");
- GAME_TITLE = leaderboard.getString("game.title");
- LOBBY_CONTENTS = leaderboard.getStringList("lobby.content");
- Collections.reverse(LOBBY_CONTENTS);
- GAME_CONTENTS = leaderboard.getStringList("game.content");
- Collections.reverse(GAME_CONTENTS);
- COUNTDOWN_WAITING = leaderboard.getString("countdown.waiting");
- COUNTDOWN_COUNTING = leaderboard.getString("countdown.counting");
- COUNTDOWN_ADMINSTART = leaderboard.getString("countdown.adminStart");
- TAUNT_COUNTING = leaderboard.getString("taunt.counting");
- TAUNT_ACTIVE = leaderboard.getString("taunt.active");
- TAUNT_EXPIRED = leaderboard.getString("taunt.expired");
- GLOW_ACTIVE = leaderboard.getString("glow.active");
- GLOW_INACTIVE = leaderboard.getString("glow.inactive");
- BORDER_COUNTING = leaderboard.getString("border.counting");
- BORDER_DECREASING = leaderboard.getString("border.decreasing");
//Lobby Items
if (config.getBoolean("lobbyItems.leave.enabled")) {
@@ -364,8 +231,7 @@ public class Config {
databaseType = config.getString("databaseType").toUpperCase();
if(!databaseType.equals("SQLITE") && !databaseType.equals("MYSQL")){
- Main.getInstance().getLogger().warning("databaseType: "+databaseType+" is not a valid configuration option!");
- databaseType = "SQLITE";
+ throw new RuntimeException("databaseType: "+databaseType+" is not a valid configuration option!");
}
delayedRespawn = config.getBoolean("delayedRespawn.enabled");
diff --git a/src/main/java/net/tylermurphy/hideAndSeek/configuration/ConfigManager.java b/src/main/java/net/tylermurphy/hideAndSeek/configuration/ConfigManager.java
index 5e28258..92fa4ce 100644
--- a/src/main/java/net/tylermurphy/hideAndSeek/configuration/ConfigManager.java
+++ b/src/main/java/net/tylermurphy/hideAndSeek/configuration/ConfigManager.java
@@ -1,22 +1,3 @@
-/*
- * This file is part of Kenshins Hide and Seek
- *
- * Copyright (c) 2021 Tyler Murphy.
- *
- * Kenshins Hide and Seek free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * he Free Software Foundation version 3.
- *
- * Kenshins Hide and Seek is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- *
- */
-
package net.tylermurphy.hideAndSeek.configuration;
import net.tylermurphy.hideAndSeek.Main;
@@ -25,8 +6,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;
@@ -93,6 +74,7 @@ public class ConfigManager {
try {
this.config.load(reader);
} catch(InvalidConfigurationException e) {
+ Main.getInstance().getLogger().severe(e.getMessage());
throw new RuntimeException("Invalid configuration in config file: "+file.getPath());
} catch(IOException e) {
throw new RuntimeException("Could not access file: "+file.getPath());
@@ -107,9 +89,10 @@ public class ConfigManager {
try {
this.defaultConfig.load(default_reader);
} catch(InvalidConfigurationException e) {
- throw new RuntimeException("Invalid configuration in config file: "+file.getPath());
+ Main.getInstance().getLogger().severe(e.getMessage());
+ throw new RuntimeException("Invalid configuration in internal config file: "+defaultFilename);
} catch(IOException e) {
- throw new RuntimeException("Could not access file: "+file.getPath());
+ throw new RuntimeException("Could not access internal file: "+defaultFilename);
}
try{
@@ -124,6 +107,7 @@ public class ConfigManager {
return config.contains(path);
}
+ @SuppressWarnings("unused")
public double getDouble(String path) {
if (!config.contains(path)) {
return defaultConfig.getDouble(path);
@@ -226,71 +210,122 @@ public class ConfigManager {
config.set(path, value);
}
+ public void overwriteConfig() {
+ try {
+ this.config.save(file);
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ }
+
public void saveConfig() {
try {
+ // open config file
InputStream is = Main.getInstance().getResource(defaultFilename);
+ // if failed error
if (is == null) {
throw new RuntimeException("Could not create input stream for "+defaultFilename);
}
+ // manually read in each character to preserve string data
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) {
+ while((c = reader.read()) != -1)
textBuilder.append((char) c);
- }
- String yamlString = new String(textBuilder.toString().getBytes(), StandardCharsets.UTF_8);
- Map<String, Object> temp = config.getValues(true);
- for(Map.Entry<String, Object> entry: temp.entrySet()) {
- if (entry.getValue() instanceof Integer || entry.getValue() instanceof Double || entry.getValue() instanceof String || entry.getValue() instanceof Boolean || entry.getValue() instanceof List) {
- String[] parts = entry.getKey().split("\\.");
- int index = 0;
- int i = 0;
- for(String part : parts) {
- if (i == 0) {
- index = yamlString.indexOf(part+":", index);
- } else {
- index = yamlString.indexOf(" " + part+":", index);
- index++;
- }
- i++;
- if (index == -1) break;
- }
- if (index < 10) continue;
- int start = yamlString.indexOf(' ', index);
- int end = yamlString.indexOf('\n', index);
- if (end == -1) end = yamlString.length();
- StringBuilder replace = new StringBuilder(new String("".getBytes(), StandardCharsets.UTF_8));
- if (entry.getValue() instanceof List) {
- if (((List<?>) entry.getValue()).isEmpty()) {
- replace.append("[]");
- } else {
- replace.append("[");
- for (Object o : (List<?>) entry.getValue()) {
- replace.append(o.toString()).append(", ");
- }
- replace = new StringBuilder(replace.substring(0, replace.length() - 2));
- replace.append("]");
- }
+ // store yaml file into a string
+ String yaml = new String(textBuilder.toString().getBytes(), StandardCharsets.UTF_8);
+ // get config values
+ Map<String, Object> data = config.getValues(true);
+ // write each stored config value into the yaml string
+ for(Map.Entry<String, Object> entry: data.entrySet()) {
+ // if type isn't supported, skip
+ if(!isSupported(entry.getValue())) continue;
+ // get index of key in yaml string
+ int index = getIndex(yaml, entry.getKey());
+ // if index not found, skip
+ if (index < 10) continue;
+ // get start and end of the value
+ int start = yaml.indexOf(' ', index) + 1;
+ int end = yaml.indexOf('\n', index);
+ // if end not found, set it to the end of the file
+ if (end == -1) end = yaml.length();
+ // create new replace sting
+ StringBuilder replace = new StringBuilder(new String("".getBytes(), StandardCharsets.UTF_8));
+ // get value
+ Object value = entry.getValue();
+ // if the value is a list,
+ if (value instanceof List) {
+ end = yaml.indexOf(']', start) + 1;
+ List<?> list = (List<?>) entry.getValue();
+ if (list.isEmpty()) {
+ // if list is empty, put an empty list
+ replace.append("[]");
} else {
- replace.append(entry.getValue());
- }
- if (entry.getValue() instanceof String) {
- replace.append("\"");
- replace.reverse();
- replace.append("\"");
- replace.reverse();
+ // if list has values, populate values into the string
+ // get gap before key
+ int gap = whitespaceBefore(yaml, index);
+ String space = new String(new char[gap]).replace('\0', ' ');
+ replace.append("[\n");
+ for (int i = 0; i < list.size(); i++) {
+ replace.append(space).append(" ").append(convert(list.get(i)));
+ if(i != list.size() -1) replace.append(",\n");
+ }
+ replace.append('\n').append(space).append("]");
}
- StringBuilder builder = new StringBuilder(yamlString);
- builder.replace(start+1, end, replace.toString());
- yamlString = builder.toString();
+ // otherwise just put the value directly
+ } else {
+ replace.append(convert(value));
}
+ // replace the new value in the yaml string
+ StringBuilder builder = new StringBuilder(yaml);
+ builder.replace(start, end, replace.toString());
+ yaml = builder.toString();
}
- Writer fileWriter = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(file), StandardCharsets.UTF_8));
- fileWriter.write(yamlString);
+
+ // write yaml string to file
+ Writer fileWriter = new BufferedWriter(new OutputStreamWriter(Files.newOutputStream(file.toPath()), StandardCharsets.UTF_8));
+ fileWriter.write(yaml);
fileWriter.close();
} catch (IOException e) {
e.printStackTrace();
}
}
+ private int getIndex(String yaml, String key) {
+ String[] parts = key.split("\\.");
+ int index = 0;
+ for(String part : parts) {
+ if (index == 0) {
+ index = yaml.indexOf("\n" + part + ":", index) + 1;
+ } else {
+ index = yaml.indexOf(" " + part + ":", index) + 1;
+ }
+ if (index == 0) break;
+ }
+ return index;
+ }
+
+ public boolean isSupported(Object o) {
+ return o instanceof Integer ||
+ o instanceof Double ||
+ o instanceof String ||
+ o instanceof Boolean ||
+ o instanceof List;
+ }
+
+ public int whitespaceBefore(String yaml, int index) {
+ int count = 0;
+ for(int i = index - 1; yaml.charAt(i) == ' '; i--) count++;
+ return count;
+ }
+
+ private String convert(Object o) {
+ if(o instanceof String) {
+ return "\"" + o + "\"";
+ } else if (o instanceof Boolean) {
+ return (boolean)o ? "true" : "false";
+ }
+ return o.toString();
+ }
+
}
diff --git a/src/main/java/net/tylermurphy/hideAndSeek/configuration/Items.java b/src/main/java/net/tylermurphy/hideAndSeek/configuration/Items.java
index 06dbb99..e5f970b 100644
--- a/src/main/java/net/tylermurphy/hideAndSeek/configuration/Items.java
+++ b/src/main/java/net/tylermurphy/hideAndSeek/configuration/Items.java
@@ -1,22 +1,3 @@
-/*
- * This file is part of Kenshins Hide and Seek
- *
- * Copyright (c) 2021 Tyler Murphy.
- *
- * Kenshins Hide and Seek free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * he Free Software Foundation version 3.
- *
- * Kenshins Hide and Seek is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- *
- */
-
package net.tylermurphy.hideAndSeek.configuration;
import com.cryptomorin.xseries.XItemStack;
diff --git a/src/main/java/net/tylermurphy/hideAndSeek/configuration/Leaderboard.java b/src/main/java/net/tylermurphy/hideAndSeek/configuration/Leaderboard.java
new file mode 100644
index 0000000..63dc850
--- /dev/null
+++ b/src/main/java/net/tylermurphy/hideAndSeek/configuration/Leaderboard.java
@@ -0,0 +1,51 @@
+package net.tylermurphy.hideAndSeek.configuration;
+
+import java.util.Collections;
+import java.util.List;
+
+public class Leaderboard {
+
+ public static String
+ LOBBY_TITLE,
+ GAME_TITLE,
+ COUNTDOWN_WAITING,
+ COUNTDOWN_COUNTING,
+ COUNTDOWN_ADMINSTART,
+ TAUNT_COUNTING,
+ TAUNT_ACTIVE,
+ TAUNT_EXPIRED,
+ GLOW_ACTIVE,
+ GLOW_INACTIVE,
+ BORDER_COUNTING,
+ BORDER_DECREASING;
+
+ public static List<String>
+ LOBBY_CONTENTS,
+ GAME_CONTENTS;
+
+ public static void loadLeaderboard() {
+
+ ConfigManager leaderboard = ConfigManager.create("leaderboard.yml");
+
+ LOBBY_TITLE = leaderboard.getString("lobby.title");
+ GAME_TITLE = leaderboard.getString("game.title");
+ LOBBY_CONTENTS = leaderboard.getStringList("lobby.content");
+ Collections.reverse(LOBBY_CONTENTS);
+ GAME_CONTENTS = leaderboard.getStringList("game.content");
+ Collections.reverse(GAME_CONTENTS);
+ COUNTDOWN_WAITING = leaderboard.getString("countdown.waiting");
+ COUNTDOWN_COUNTING = leaderboard.getString("countdown.counting");
+ COUNTDOWN_ADMINSTART = leaderboard.getString("countdown.adminStart");
+ TAUNT_COUNTING = leaderboard.getString("taunt.counting");
+ TAUNT_ACTIVE = leaderboard.getString("taunt.active");
+ TAUNT_EXPIRED = leaderboard.getString("taunt.expired");
+ GLOW_ACTIVE = leaderboard.getString("glow.active");
+ GLOW_INACTIVE = leaderboard.getString("glow.inactive");
+ BORDER_COUNTING = leaderboard.getString("border.counting");
+ BORDER_DECREASING = leaderboard.getString("border.decreasing");
+
+ leaderboard.saveConfig();
+
+ }
+
+}
diff --git a/src/main/java/net/tylermurphy/hideAndSeek/configuration/Localization.java b/src/main/java/net/tylermurphy/hideAndSeek/configuration/Localization.java
index 9418414..b9f9b69 100644
--- a/src/main/java/net/tylermurphy/hideAndSeek/configuration/Localization.java
+++ b/src/main/java/net/tylermurphy/hideAndSeek/configuration/Localization.java
@@ -1,22 +1,3 @@
-/*
- * This file is part of Kenshins Hide and Seek
- *
- * Copyright (c) 2021 Tyler Murphy.
- *
- * Kenshins Hide and Seek free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * he Free Software Foundation version 3.
- *
- * Kenshins Hide and Seek is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- *
- */
-
package net.tylermurphy.hideAndSeek.configuration;
import net.md_5.bungee.api.ChatColor;
@@ -31,8 +12,16 @@ public class Localization {
public static final Map<String,LocalizationString> DEFAULT_LOCAL = new HashMap<>();
private static final Map<String,String[][]> CHANGES = new HashMap<String,String[][]>() {{
- put("en-US", new String[][]{{"WORLDBORDER_DECREASING"},{"START","TAUNTED"}});
- put("de-DE", new String[][]{{},{"TAUNTED"}});
+ put("en-US", new String[][]{
+ {"WORLDBORDER_DECREASING"},
+ {"START","TAUNTED"},
+ {"GAME_SETUP", "SETUP_GAME", "SETUP_LOBBY", "SETUP_SEEKER_LOBBY", "SETUP_EXIT", "SETUP_SAVEMAP", "SETUP_BOUNDS"}
+ });
+ put("de-DE", new String[][]{
+ {},
+ {"TAUNTED"},
+ {"GAME_SETUP", "SETUP_GAME", "SETUP_LOBBY", "SETUP_SEEKER_LOBBY", "SETUP_EXIT", "SETUP_SAVEMAP", "SETUP_BOUNDS"}
+ });
}};
public static void loadLocalization() {
diff --git a/src/main/java/net/tylermurphy/hideAndSeek/configuration/LocalizationString.java b/src/main/java/net/tylermurphy/hideAndSeek/configuration/LocalizationString.java
index 3d8bc0f..b457622 100644
--- a/src/main/java/net/tylermurphy/hideAndSeek/configuration/LocalizationString.java
+++ b/src/main/java/net/tylermurphy/hideAndSeek/configuration/LocalizationString.java
@@ -1,22 +1,3 @@
-/*
- * This file is part of Kenshins Hide and Seek
- *
- * Copyright (c) 2021 Tyler Murphy.
- *
- * Kenshins Hide and Seek free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * he Free Software Foundation version 3.
- *
- * Kenshins Hide and Seek is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- *
- */
-
package net.tylermurphy.hideAndSeek.configuration;
import org.bukkit.entity.Entity;
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..a23a1f7
--- /dev/null
+++ b/src/main/java/net/tylermurphy/hideAndSeek/configuration/Map.java
@@ -0,0 +1,238 @@
+package net.tylermurphy.hideAndSeek.configuration;
+
+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;
+
+import static net.tylermurphy.hideAndSeek.configuration.Config.*;
+
+public class Map {
+
+ private final String name;
+
+ private Location
+ spawnPosition = Location.getDefault(),
+ lobbyPosition = Location.getDefault(),
+ seekerLobbyPosition = Location.getDefault();
+
+ private int
+ xBoundMin = 0,
+ zBoundMin = 0,
+ xBoundMax = 0,
+ zBoundMax = 0,
+ xWorldBorder = 0,
+ zWorldBorder = 0,
+ worldBorderSize = 0,
+ worldBorderDelay = 0,
+ worldBorderChange = 0;
+
+ private boolean
+ blockhunt = false;
+
+ private List<Material>
+ blockhuntBlocks = new ArrayList<>();
+
+ 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;
+ }
+
+ 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;
+ } else {
+ this.worldBorderSize = size;
+ this.worldBorderDelay = delay;
+ this.worldBorderChange = move;
+ this.xWorldBorder = x;
+ this.zWorldBorder = z;
+ }
+ this.worldBorder.resetWorldBorder();
+ }
+
+ public void setBlockhunt(boolean enabled, List<Material> blocks) {
+ if (Main.getInstance().supports(9)) {
+ this.blockhunt = enabled;
+ } else {
+ this.blockhunt = false;
+ }
+ 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;
+ }
+
+ @NotNull
+ public Location getGameSpawn() {
+ if(mapSaveEnabled) {
+ return spawnPosition.changeWorld("hs_"+name);
+ } else {
+ return spawnPosition;
+ }
+ }
+
+ @NotNull
+ public String getGameSpawnName() {
+ if(mapSaveEnabled)
+ return getGameSpawn().getWorld();
+ else
+ return getSpawn().getWorld();
+ }
+
+ @NotNull
+ public Location getSpawn() {
+ return spawnPosition;
+ }
+
+ @NotNull
+ public String getSpawnName() {
+ return getSpawn().getWorld();
+ }
+
+ @NotNull
+ public Location getLobby() {
+ return lobbyPosition;
+ }
+
+ @NotNull
+ public String getLobbyName() {
+ return getLobby().getWorld();
+ }
+
+ @NotNull
+ public Location getSeekerLobby() {
+ return seekerLobbyPosition;
+ }
+
+ @NotNull
+ public String getSeekerLobbyName() {
+ return getSeekerLobby().getWorld();
+ }
+
+ @NotNull
+ public Location getGameSeekerLobby() {
+ if(mapSaveEnabled) {
+ return seekerLobbyPosition.changeWorld("hs_"+name);
+ } else {
+ return seekerLobbyPosition;
+ }
+ }
+
+ public boolean isWorldBorderEnabled() {
+ return worldBorderSize > 0;
+ }
+
+ @NotNull
+ public Vector getWorldBorderPos() {
+ return new Vector(
+ xWorldBorder,
+ 0,
+ zWorldBorder
+ );
+ }
+
+ @NotNull
+ public Vector getWorldBorderData() {
+ return new Vector(
+ worldBorderSize,
+ worldBorderDelay,
+ worldBorderChange
+ );
+ }
+
+ @NotNull
+ public Border getWorldBorder() {
+ return worldBorder;
+ }
+
+ public boolean isBlockHuntEnabled() {
+ return blockhunt;
+ }
+
+ @NotNull
+ public List<Material> getBlockHunt() {
+ return blockhuntBlocks;
+ }
+
+ @NotNull
+ public Vector getBoundsMin() {
+ return new Vector(
+ xBoundMin,
+ 0,
+ zBoundMin
+ );
+ }
+
+ @NotNull
+ public Vector getBoundsMax() {
+ return new Vector(
+ xBoundMax,
+ 0,
+ zBoundMax
+ );
+ }
+
+ @NotNull
+ public String getName() {
+ return name;
+ }
+
+ @NotNull
+ public WorldLoader getWorldLoader() {
+ return worldLoader;
+ }
+
+ public boolean isNotSetup() {
+ 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;
+ return xBoundMin == 0 || zBoundMin == 0 || xBoundMax == 0 || zBoundMax == 0;
+ }
+
+ public boolean isBoundsNotSetup() {
+ return xBoundMin == 0 || zBoundMin == 0 || xBoundMax == 0 || zBoundMax == 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..d691fa9
--- /dev/null
+++ b/src/main/java/net/tylermurphy/hideAndSeek/configuration/Maps.java
@@ -0,0 +1,158 @@
+package net.tylermurphy.hideAndSeek.configuration;
+
+import java.util.*;
+import java.util.stream.Collectors;
+
+import net.tylermurphy.hideAndSeek.Main;
+import net.tylermurphy.hideAndSeek.util.Location;
+import org.bukkit.Material;
+import org.bukkit.configuration.ConfigurationSection;
+import org.bukkit.configuration.file.YamlConfiguration;
+
+import com.cryptomorin.xseries.XMaterial;
+import org.jetbrains.annotations.NotNull;
+import org.jetbrains.annotations.Nullable;
+
+public class Maps {
+
+ private static final HashMap<String, Map> MAPS = new HashMap<>();
+
+ @Nullable
+ public static Map getMap(String name) {
+ return MAPS.get(name);
+ }
+
+ @Nullable
+ public static Map getRandomMap() {
+ Optional<Map> map;
+ if(MAPS.values().size() > 0) {
+ Collection<Map> setupMaps = MAPS.values().stream().filter(m -> !m.isNotSetup()).collect(Collectors.toList());
+ if(setupMaps.size() < 1) {
+ return null;
+ }
+ map = setupMaps.stream().skip(new Random().nextInt(setupMaps.size())).findFirst();
+ } else {
+ map = Optional.empty();
+ }
+ return map.orElse(null);
+ }
+
+ public static void setMap(String name, Map map) {
+ MAPS.put(name, map);
+ saveMaps();
+ }
+
+ public static boolean removeMap(String name) {
+ boolean status = MAPS.remove(name) != null;
+ saveMaps();
+ return status;
+ }
+
+ @NotNull
+ 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) {
+ 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);
+ Main.getInstance().getLogger().info("Loading map: " + name + "...");
+ 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(
+ data.getInt("worldborder.pos.x"),
+ data.getInt("worldborder.pos.z"),
+ data.getInt("worldborder.size"),
+ data.getInt("worldborder.delay"),
+ data.getInt("worldborder.change")
+ );
+ List<String> blockhunt = data.getStringList("blockhunt.blocks");
+ if(blockhunt == null) blockhunt = new ArrayList<>();
+ map.setBlockhunt(
+ data.getBoolean("blockhunt.enabled"),
+ blockhunt
+ .stream()
+ .map(XMaterial::matchXMaterial)
+ .filter(Optional::isPresent)
+ .map(e -> e.get().parseMaterial())
+ .filter(Objects::nonNull)
+ .collect(Collectors.toList())
+ );
+ return map;
+ }
+
+ 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");
+ 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", 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());
+ 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).collect(Collectors.toList()));
+ maps.set(map.getName(), data);
+ }
+
+ manager.set("maps", maps);
+ manager.overwriteConfig();
+
+ }
+
+ private static void saveSpawn(ConfigurationSection data, Location spawn, String name, Map map) {
+ String worldName = getWorldName(name, map);
+ 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;
+ }
+ }
+
+}