summaryrefslogtreewikicommitdiff
path: root/src/main/java/net/tylermurphy/hideAndSeek/configuration
diff options
context:
space:
mode:
authorTyler Murphy <tylermurphy534@gmail.com>2021-12-30 12:17:32 -0500
committerGitHub <noreply@github.com>2021-12-30 12:17:32 -0500
commit31d60d7d23715aa3f063241c0c420ea0b0bf003b (patch)
treeca43ffa540d9629f6f0faf2ab3d5e5941db0f352 /src/main/java/net/tylermurphy/hideAndSeek/configuration
parentMerge pull request #16 from tylermurphy534/1.3.2 (diff)
parent1.3.3 rc5 (diff)
downloadkenshinshideandseek-31d60d7d23715aa3f063241c0c420ea0b0bf003b.tar.gz
kenshinshideandseek-31d60d7d23715aa3f063241c0c420ea0b0bf003b.tar.bz2
kenshinshideandseek-31d60d7d23715aa3f063241c0c420ea0b0bf003b.zip
Merge pull request #20 from tylermurphy534/1.3.3
1.3.3
Diffstat (limited to 'src/main/java/net/tylermurphy/hideAndSeek/configuration')
-rw-r--r--src/main/java/net/tylermurphy/hideAndSeek/configuration/Config.java37
-rw-r--r--src/main/java/net/tylermurphy/hideAndSeek/configuration/ConfigManager.java62
-rw-r--r--src/main/java/net/tylermurphy/hideAndSeek/configuration/Items.java20
-rw-r--r--src/main/java/net/tylermurphy/hideAndSeek/configuration/Localization.java23
-rw-r--r--src/main/java/net/tylermurphy/hideAndSeek/configuration/LocalizationString.java94
5 files changed, 173 insertions, 63 deletions
diff --git a/src/main/java/net/tylermurphy/hideAndSeek/configuration/Config.java b/src/main/java/net/tylermurphy/hideAndSeek/configuration/Config.java
index ee9d88d..524eeac 100644
--- a/src/main/java/net/tylermurphy/hideAndSeek/configuration/Config.java
+++ b/src/main/java/net/tylermurphy/hideAndSeek/configuration/Config.java
@@ -1,3 +1,22 @@
+/*
+ * 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.util.Vector;
@@ -37,7 +56,8 @@ public class Config {
glowStackable,
pvpEnabled,
autoJoin,
- teleportToExit;
+ teleportToExit,
+ lobbyCountdownEnabled;
public static int
minPlayers,
@@ -50,7 +70,11 @@ public class Config {
saveMaxX,
saveMaxZ,
tauntDelay,
- glowLength;
+ glowLength,
+ countdown,
+ changeCountdown,
+ lobbyMin,
+ lobbyMax;
public static void loadConfig() {
@@ -121,10 +145,17 @@ public class Config {
glowStackable = manager.getBoolean("glow.stackable");
glowEnabled = manager.getBoolean("glow.enabled");
+ //Lobby
+ minPlayers = Math.max(2, manager.getInt("minPlayers"));
+ countdown = Math.max(10,manager.getInt("lobby.countdown"));
+ changeCountdown = Math.max(minPlayers,manager.getInt("lobby.changeCountdown"));
+ lobbyMin = Math.max(minPlayers,manager.getInt("lobby.min"));
+ lobbyMax = manager.getInt("lobby.max");
+ lobbyCountdownEnabled = manager.getBoolean("lobby.enabled");
+
//Other
nametagsVisible = manager.getBoolean("nametagsVisible");
permissionsRequired = manager.getBoolean("permissionsRequired");
- minPlayers = Math.max(2, manager.getInt("minPlayers"));
gameLength = manager.getInt("gameLength");
pvpEnabled = manager.getBoolean("pvp");
autoJoin = manager.getBoolean("autoJoin");
diff --git a/src/main/java/net/tylermurphy/hideAndSeek/configuration/ConfigManager.java b/src/main/java/net/tylermurphy/hideAndSeek/configuration/ConfigManager.java
index c1757d1..84ad5b4 100644
--- a/src/main/java/net/tylermurphy/hideAndSeek/configuration/ConfigManager.java
+++ b/src/main/java/net/tylermurphy/hideAndSeek/configuration/ConfigManager.java
@@ -1,3 +1,22 @@
+/*
+ * 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;
@@ -11,17 +30,20 @@ import java.util.Map;
public class ConfigManager {
- private File file;
+ private final File file;
private YamlConfiguration config,defaultConfig;
private String defaultFilename;
public ConfigManager(String filename){
- this.file = new File(Main.plugin.getDataFolder(), filename);
+ this.file = new File(Main.data, filename);
this.defaultFilename = file.getName();
- File folder = Main.plugin.getDataFolder();
- if(!folder.exists())
- folder.mkdirs();
+ File folder = Main.data;
+ if(!folder.exists()){
+ if(!folder.mkdirs()){
+ throw new RuntimeException("Failed to make directory: " + file.getPath());
+ }
+ }
if(!file.exists()){
saveDefaultConfiguration();
@@ -30,18 +52,21 @@ public class ConfigManager {
this.config = YamlConfiguration.loadConfiguration(file);
InputStream input = Main.plugin.getResource(file.getName());
+ if(input == null){
+ throw new RuntimeException("Could not create input stream for "+file.getPath());
+ }
InputStreamReader reader = new InputStreamReader(input);
this.defaultConfig = YamlConfiguration.loadConfiguration(reader);
try{
input.close();
reader.close();
- } catch (IOException e){}
+ } catch (IOException ignored){}
}
public ConfigManager(String filename, String defaultFilename){
this.defaultFilename = defaultFilename;
- this.file = new File(Main.plugin.getDataFolder(), filename);
+ this.file = new File(Main.data, filename);
if(!file.exists()){
saveDefaultConfiguration();
@@ -50,6 +75,9 @@ public class ConfigManager {
this.config = YamlConfiguration.loadConfiguration(file);
InputStream input = Main.plugin.getResource(defaultFilename);
+ if(input == null){
+ throw new RuntimeException("Could not create input stream for "+defaultFilename);
+ }
InputStreamReader reader = new InputStreamReader(input);
this.defaultConfig = YamlConfiguration.loadConfiguration(reader);
try{
@@ -65,6 +93,9 @@ public class ConfigManager {
private void saveDefaultConfiguration(){
try{
InputStream input = Main.plugin.getResource(defaultFilename);
+ if(input == null){
+ throw new RuntimeException("Could not create input stream for "+defaultFilename);
+ }
java.nio.file.Files.copy(input, file.toPath());
input.close();
} catch(IOException e){
@@ -72,10 +103,6 @@ public class ConfigManager {
}
}
- public void addToConfig(String path, Object value) {
- config.set(path, value);
- }
-
public double getDouble(String path){
double value = config.getDouble(path);
if(value == 0.0D){
@@ -111,6 +138,9 @@ public class ConfigManager {
this.defaultFilename = newDefaultFilename;
InputStream input = Main.plugin.getResource(defaultFilename);
+ if(input == null){
+ throw new RuntimeException("Could not create input stream for "+defaultFilename);
+ }
InputStreamReader reader = new InputStreamReader(input);
this.config = YamlConfiguration.loadConfiguration(reader);
this.defaultConfig = YamlConfiguration.loadConfiguration(reader);
@@ -119,7 +149,7 @@ public class ConfigManager {
public boolean getBoolean(String path){
boolean value = config.getBoolean(path);
- if(value == false){
+ if(!value){
return defaultConfig.getBoolean(path);
} else {
return true;
@@ -142,9 +172,12 @@ public class ConfigManager {
public void saveConfig(){
try {
InputStream is = Main.plugin.getResource(defaultFilename);
+ if(is == null){
+ throw new RuntimeException("Could not create input stream for "+defaultFilename);
+ }
StringBuilder textBuilder = new StringBuilder();
Reader reader = new BufferedReader(new InputStreamReader(is, Charset.forName(StandardCharsets.UTF_8.name())));
- int c = 0;
+ int c;
while((c = reader.read()) != -1){
textBuilder.append((char) c);
}
@@ -165,7 +198,7 @@ public class ConfigManager {
i++;
if(index == -1) break;
}
- if(index < 10) continue;;
+ if(index < 10) continue;
int start = yamlString.indexOf(' ', index);
int end = yamlString.indexOf('\n', index);
if(end == -1) end = yamlString.length();
@@ -173,7 +206,6 @@ public class ConfigManager {
if(entry.getValue() instanceof String){
replace = "\"" + replace + "\"";
}
- System.out.println(entry.getKey() + " " + index + " " + start + " " + end);
StringBuilder builder = new StringBuilder(yamlString);
builder.replace(start+1, end, replace);
yamlString = builder.toString();
diff --git a/src/main/java/net/tylermurphy/hideAndSeek/configuration/Items.java b/src/main/java/net/tylermurphy/hideAndSeek/configuration/Items.java
index e5470af..569cae6 100644
--- a/src/main/java/net/tylermurphy/hideAndSeek/configuration/Items.java
+++ b/src/main/java/net/tylermurphy/hideAndSeek/configuration/Items.java
@@ -1,3 +1,22 @@
+/*
+ * 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.ChatColor;
@@ -78,6 +97,7 @@ public class Items {
if(material == Material.POTION || material == Material.SPLASH_POTION || material == Material.LINGERING_POTION){
PotionMeta meta = getPotionMeta(stack, item);
stack.setItemMeta(meta);
+
} else {
ConfigurationSection enchantments = item.getConfigurationSection("enchantments");
if (enchantments != null)
diff --git a/src/main/java/net/tylermurphy/hideAndSeek/configuration/Localization.java b/src/main/java/net/tylermurphy/hideAndSeek/configuration/Localization.java
index 61dc5a4..d5ae01d 100644
--- a/src/main/java/net/tylermurphy/hideAndSeek/configuration/Localization.java
+++ b/src/main/java/net/tylermurphy/hideAndSeek/configuration/Localization.java
@@ -1,3 +1,22 @@
+/*
+ * 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 java.io.File;
@@ -10,7 +29,7 @@ public class Localization {
public static final Map<String,LocalizationString> LOCAL = new HashMap<>();
- private static String[][] CHANGES = {{"WORLDBORDER_DECREASING"}};
+ private static final String[][] CHANGES = {{"WORLDBORDER_DECREASING"}};
public static void loadLocalization() {
@@ -48,7 +67,7 @@ public class Localization {
public static LocalizationString message(String key) {
LocalizationString temp = LOCAL.get(key);
if(temp == null) {
- return new LocalizationString(ChatColor.RED + "" + ChatColor.ITALIC + key + "is not found in localization.yml. This is a plugin issue, please report it.");
+ return new LocalizationString(ChatColor.RED + "" + ChatColor.ITALIC + key + " is not found in localization.yml. This is a plugin issue, please report it.");
}
return new LocalizationString(temp.toString());
}
diff --git a/src/main/java/net/tylermurphy/hideAndSeek/configuration/LocalizationString.java b/src/main/java/net/tylermurphy/hideAndSeek/configuration/LocalizationString.java
index fd0e020..3d8bc0f 100644
--- a/src/main/java/net/tylermurphy/hideAndSeek/configuration/LocalizationString.java
+++ b/src/main/java/net/tylermurphy/hideAndSeek/configuration/LocalizationString.java
@@ -1,48 +1,56 @@
+/*
+ * 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.command.CommandSender;
import org.bukkit.entity.Entity;
public class LocalizationString {
-
- String message;
-
- public LocalizationString(String message) {
- this.message = message;
- }
-
- public LocalizationString addPlayer(Entity player) {
- this.message = message.replaceFirst("\\{PLAYER\\}", player.getName());
- return this;
- }
-
- public LocalizationString addPlayer(CommandSender player) {
- this.message = message.replaceFirst("\\{PLAYER\\}", player.getName());
- return this;
- }
-
- public LocalizationString addPlayer(String player) {
- this.message = message.replaceFirst("\\{PLAYER\\}", player);
- return this;
- }
-
- public LocalizationString addAmount(Integer value) {
- this.message = message.replaceFirst("\\{AMOUNT\\}", value.toString());
- return this;
- }
-
- public LocalizationString addAmount(String value) {
- this.message = message.replaceFirst("\\{AMOUNT\\}", value.toString());
- return this;
- }
-
- public LocalizationString addAmount(Float value) {
- this.message = message.replaceFirst("\\{AMOUNT\\}", value.toString());
- return this;
- }
-
- public String toString() {
- return message;
- }
-
-}
+
+ String message;
+
+ public LocalizationString(String message) {
+ this.message = message;
+ }
+
+ public LocalizationString addPlayer(Entity player) {
+ this.message = message.replaceFirst("\\{PLAYER}", player.getName());
+ return this;
+ }
+
+ public LocalizationString addPlayer(String player) {
+ this.message = message.replaceFirst("\\{PLAYER}", player);
+ return this;
+ }
+
+ public LocalizationString addAmount(Integer value) {
+ this.message = message.replaceFirst("\\{AMOUNT}", value.toString());
+ return this;
+ }
+
+ public LocalizationString addAmount(String value) {
+ this.message = message.replaceFirst("\\{AMOUNT}", value);
+ return this;
+ }
+
+ public String toString() {
+ return message;
+ }
+
+} \ No newline at end of file