diff options
Diffstat (limited to '')
4 files changed, 96 insertions, 95 deletions
diff --git a/src/main/java/net/tylermurphy/hideAndSeek/configuration/Config.java b/src/main/java/net/tylermurphy/hideAndSeek/configuration/Config.java index 22f4480..793e773 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/configuration/Config.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/configuration/Config.java @@ -39,8 +39,8 @@ import java.util.Optional; public class Config { - private static ConfigManager config, leaderboard; - + private static ConfigManager config; + public static String messagePrefix, errorPrefix, @@ -150,7 +150,7 @@ public class Config { config = ConfigManager.create("config.yml"); config.saveConfig(); - leaderboard = ConfigManager.create("leaderboard.yml"); + ConfigManager leaderboard = ConfigManager.create("leaderboard.yml"); //Spawn spawnPosition = new Vector( @@ -217,14 +217,14 @@ public class Config { glowLength = Math.max(1, config.getInt("glow.time")); glowStackable = config.getBoolean("glow.stackable"); glowEnabled = config.getBoolean("glow.enabled") && Version.atLeast("1.9"); - if(glowEnabled) { + if (glowEnabled) { ConfigurationSection item = new YamlConfiguration().createSection("temp"); item.set("name", ChatColor.translateAlternateColorCodes('&',config.getString("glow.name"))); item.set("material", config.getString("glow.material")); List<String> lore = config.getStringList("glow.lore"); if (lore != null && !lore.isEmpty()) item.set("lore", lore); ItemStack temp = null; - try{ temp = XItemStack.deserialize(item); } catch(Exception ignored){} + try{ temp = XItemStack.deserialize(item); } catch(Exception ignored) {} glowPowerupItem = temp; } @@ -264,17 +264,17 @@ public class Config { placeholderNoData = config.getString("placeholder.noData"); try { countdownDisplay = CountdownDisplay.valueOf(config.getString("hideCountdownDisplay")); - } catch (IllegalArgumentException e){ + } catch (IllegalArgumentException e) { countdownDisplay = CountdownDisplay.CHAT; Main.plugin.getLogger().warning("hideCountdownDisplay: "+config.getString("hideCountdownDisplay")+" is not a valid configuration option!"); } blockedInteracts = new ArrayList<>(); List<String> tempInteracts = config.getStringList("blockedInteracts"); - for(String id : tempInteracts){ + for(String id : tempInteracts) { Optional<XMaterial> optional_mat = XMaterial.matchXMaterial(id); - if(optional_mat.isPresent()){ + if (optional_mat.isPresent()) { Material mat = optional_mat.get().parseMaterial(); - if(mat != null){ + if (mat != null) { blockedInteracts.add(mat.name()); } } @@ -301,35 +301,35 @@ public class Config { BORDER_DECREASING = leaderboard.getString("border.decreasing"); //Lobby Items - if(config.getBoolean("lobbyItems.leave.enabled")) { + if (config.getBoolean("lobbyItems.leave.enabled")) { ConfigurationSection item = new YamlConfiguration().createSection("temp"); item.set("name", ChatColor.translateAlternateColorCodes('&',config.getString("lobbyItems.leave.name"))); item.set("material", config.getString("lobbyItems.leave.material")); - if(Version.atLeast("1.14")){ - if(config.contains("lobbyItems.leave.model-data") && config.getInt("lobbyItems.leave.model-data") != 0){ + if (Version.atLeast("1.14")) { + if (config.contains("lobbyItems.leave.model-data") && config.getInt("lobbyItems.leave.model-data") != 0) { item.set("model-data", config.getInt("lobbyItems.leave.model-data")); } } List<String> lore = config.getStringList("lobbyItems.leave.lore"); if (lore != null && !lore.isEmpty()) item.set("lore", lore); ItemStack temp = null; - try{ temp = XItemStack.deserialize(item); } catch(Exception ignored){} + try{ temp = XItemStack.deserialize(item); } catch(Exception ignored) {} lobbyLeaveItem = temp; lobbyItemLeavePosition = config.getInt("lobbyItems.leave.position"); } - if(config.getBoolean("lobbyItems.start.enabled")) { + if (config.getBoolean("lobbyItems.start.enabled")) { ConfigurationSection item = new YamlConfiguration().createSection("temp"); item.set("name", ChatColor.translateAlternateColorCodes('&',config.getString("lobbyItems.start.name"))); item.set("material", config.getString("lobbyItems.start.material")); List<String> lore = config.getStringList("lobbyItems.start.lore"); if (lore != null && !lore.isEmpty()) item.set("lore", lore); ItemStack temp = null; - try{ temp = XItemStack.deserialize(item); } catch(Exception ignored){} + try{ temp = XItemStack.deserialize(item); } catch(Exception ignored) {} lobbyStartItem = temp; lobbyItemStartAdmin = config.getBoolean("lobbyItems.start.adminOnly"); lobbyItemStartPosition = config.getInt("lobbyItems.start.position"); - if(Version.atLeast("1.14")){ - if(config.contains("lobbyItems.start.model-data") && config.getInt("lobbyItems.start.model-data") != 0){ + if (Version.atLeast("1.14")) { + if (config.contains("lobbyItems.start.model-data") && config.getInt("lobbyItems.start.model-data") != 0) { item.set("model-data", config.getInt("lobbyItems.start.model-data")); } } diff --git a/src/main/java/net/tylermurphy/hideAndSeek/configuration/ConfigManager.java b/src/main/java/net/tylermurphy/hideAndSeek/configuration/ConfigManager.java index 4bb1a83..5954d05 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/configuration/ConfigManager.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/configuration/ConfigManager.java @@ -36,35 +36,35 @@ public class ConfigManager { private YamlConfiguration config,defaultConfig; private String defaultFilename; - public static ConfigManager create(String filename){ + public static ConfigManager create(String filename) { return new ConfigManager(filename, filename); } - public static ConfigManager create(String filename, String defaultFilename){ + public static ConfigManager create(String filename, String defaultFilename) { return new ConfigManager(filename, defaultFilename); } - private ConfigManager(String filename, String defaultFilename){ + private ConfigManager(String filename, String defaultFilename) { this.defaultFilename = defaultFilename; this.file = new File(Main.data, filename); File folder = Main.data; - if(!folder.exists()){ - if(!folder.mkdirs()){ + if (!folder.exists()) { + if (!folder.mkdirs()) { throw new RuntimeException("Failed to make directory: " + file.getPath()); } } - if(!file.exists()){ + if (!file.exists()) { try{ InputStream input = Main.plugin.getResource(defaultFilename); - if(input == null){ + 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){ + } catch(IOException e) { e.printStackTrace(); } } @@ -72,90 +72,90 @@ public class ConfigManager { FileInputStream fileInputStream; try { fileInputStream = new FileInputStream(file); - } catch (FileNotFoundException e){ + } catch (FileNotFoundException e) { throw new RuntimeException("Could not create input stream for "+file.getPath()); } InputStreamReader reader = new InputStreamReader(fileInputStream, StandardCharsets.UTF_8); this.config = new YamlConfiguration(); try { this.config.load(reader); - } catch(InvalidConfigurationException e){ + } catch(InvalidConfigurationException e) { throw new RuntimeException("Invalid configuration in config file: "+file.getPath()); - } catch(IOException e){ + } catch(IOException e) { throw new RuntimeException("Could not access file: "+file.getPath()); } InputStream input = this.getClass().getClassLoader().getResourceAsStream(defaultFilename); - if(input == null){ + if (input == null) { throw new RuntimeException("Could not create input stream for "+defaultFilename); } InputStreamReader default_reader = new InputStreamReader(input, StandardCharsets.UTF_8); this.defaultConfig = new YamlConfiguration(); try { this.defaultConfig.load(default_reader); - } catch(InvalidConfigurationException e){ + } catch(InvalidConfigurationException e) { throw new RuntimeException("Invalid configuration in config file: "+file.getPath()); - } catch(IOException e){ + } catch(IOException e) { throw new RuntimeException("Could not access file: "+file.getPath()); } try{ fileInputStream.close(); default_reader.close(); - } catch (IOException e){ + } catch (IOException e) { throw new RuntimeException("Unable to finalize loading of config files."); } } - public boolean contains(String path){ + public boolean contains(String path) { return config.contains(path); } - public double getDouble(String path){ + public double getDouble(String path) { double value = config.getDouble(path); - if(value == 0.0D){ + if (value == 0.0D) { return defaultConfig.getDouble(path); } else { return value; } } - public int getInt(String path){ + public int getInt(String path) { int value = config.getInt(path); - if(value == 0){ + if (value == 0) { return defaultConfig.getInt(path); } else { return value; } } - public int getDefaultInt(String path){ + public int getDefaultInt(String path) { return defaultConfig.getInt(path); } - public float getFloat(String path){ + public float getFloat(String path) { float value = (float) config.getDouble(path); - if(value == 0.0F){ + if (value == 0.0F) { return (float) defaultConfig.getDouble(path); } else { return value; } } - public String getString(String path){ + public String getString(String path) { String value = config.getString(path); - if(value == null){ + if (value == null) { return defaultConfig.getString(path); } else { return value; } } - public String getString(String path, String oldPath){ + public String getString(String path, String oldPath) { String value = config.getString(path); - if(value == null){ + if (value == null) { String oldValue = config.getString(oldPath); - if(oldValue == null){ + if (oldValue == null) { return defaultConfig.getString(path); } else { return oldValue; @@ -165,24 +165,24 @@ public class ConfigManager { } } - public List<String> getStringList(String path){ + public List<String> getStringList(String path) { List<String> value = config.getStringList(path); - if(value == null){ + if (value == null) { return defaultConfig.getStringList(path); } else { return value; } } - public void reset(String path){ + public void reset(String path) { config.set(path, defaultConfig.get(path)); } - public void resetFile(String newDefaultFilename){ + public void resetFile(String newDefaultFilename) { this.defaultFilename = newDefaultFilename; InputStream input = Main.plugin.getResource(defaultFilename); - if(input == null){ + if (input == null) { throw new RuntimeException("Could not create input stream for "+defaultFilename); } InputStreamReader reader = new InputStreamReader(input); @@ -191,63 +191,63 @@ public class ConfigManager { } - public boolean getBoolean(String path){ - if(!config.contains(path)){ + public boolean getBoolean(String path) { + if (!config.contains(path)) { return defaultConfig.getBoolean(path); } else { return config.getBoolean(path); } } - public ConfigurationSection getConfigurationSection(String path){ + public ConfigurationSection getConfigurationSection(String path) { ConfigurationSection section = config.getConfigurationSection(path); - if(section == null){ + if (section == null) { return defaultConfig.getConfigurationSection(path); } else { return section; } } - public void set(String path, Object value){ + public void set(String path, Object value) { config.set(path, value); } - public void saveConfig(){ + public void saveConfig() { try { InputStream is = Main.plugin.getResource(defaultFilename); - if(is == null){ + if (is == null) { 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()))); 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){ + 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) { + if (i == 0) { index = yamlString.indexOf(part+":", index); } else { index = yamlString.indexOf(" " + part+":", index); index++; } i++; - if(index == -1) break; + 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(); + 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()){ + if (entry.getValue() instanceof List) { + if (((List<?>) entry.getValue()).isEmpty()) { replace.append("[]"); } else { replace.append("["); @@ -260,7 +260,7 @@ public class ConfigManager { } else { replace.append(entry.getValue()); } - if(entry.getValue() instanceof String){ + if (entry.getValue() instanceof String) { replace.append("\""); replace.reverse(); replace.append("\""); @@ -274,7 +274,7 @@ public class ConfigManager { Writer fileWriter = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(file), StandardCharsets.UTF_8)); fileWriter.write(yamlString); fileWriter.close(); - } catch (IOException e){ + } catch (IOException e) { e.printStackTrace(); } } diff --git a/src/main/java/net/tylermurphy/hideAndSeek/configuration/Items.java b/src/main/java/net/tylermurphy/hideAndSeek/configuration/Items.java index 22ec84b..c2d7bed 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/configuration/Items.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/configuration/Items.java @@ -25,7 +25,8 @@ import org.bukkit.Material; import org.bukkit.configuration.ConfigurationSection; import org.bukkit.configuration.file.YamlConfiguration; import org.bukkit.inventory.ItemStack; -import org.bukkit.potion.*; +import org.bukkit.potion.PotionEffect; +import org.bukkit.potion.PotionEffectType; import java.util.ArrayList; import java.util.List; @@ -45,9 +46,9 @@ public class Items { int i = 1; while (true) { ConfigurationSection section = SeekerItems.getConfigurationSection(String.valueOf(i)); - if(section == null) break; + if (section == null) break; ItemStack item = createItem(section); - if(item != null) SEEKER_ITEMS.add(item); + if (item != null) SEEKER_ITEMS.add(item); i++; } @@ -56,9 +57,9 @@ public class Items { i = 1; while (true) { ConfigurationSection section = HiderItems.getConfigurationSection(String.valueOf(i)); - if(section == null) break; + if (section == null) break; ItemStack item = createItem(section); - if(item != null) HIDER_ITEMS.add(item); + if (item != null) HIDER_ITEMS.add(item); i++; } SEEKER_EFFECTS = new ArrayList<>(); @@ -66,9 +67,9 @@ public class Items { i = 1; while (true) { ConfigurationSection section = SeekerEffects.getConfigurationSection(String.valueOf(i)); - if(section == null) break; + if (section == null) break; PotionEffect effect = getPotionEffect(section); - if(effect != null) SEEKER_EFFECTS.add(effect); + if (effect != null) SEEKER_EFFECTS.add(effect); i++; } @@ -77,9 +78,9 @@ public class Items { i = 1; while (true) { ConfigurationSection section = HiderEffects.getConfigurationSection(String.valueOf(i)); - if(section == null) break; + if (section == null) break; PotionEffect effect = getPotionEffect(section); - if(effect != null) HIDER_EFFECTS.add(effect); + if (effect != null) HIDER_EFFECTS.add(effect); i++; } @@ -89,11 +90,11 @@ public class Items { ConfigurationSection config = new YamlConfiguration().createSection("temp"); String material = item.getString("material").toUpperCase(); boolean splash = false; - if(!Version.atLeast("1.9")){ - if(material.contains("POTION")){ + if (!Version.atLeast("1.9")) { + if (material.contains("POTION")) { config.set("level", 1); } - if(material.equalsIgnoreCase("SPLASH_POTION") || material.equalsIgnoreCase("LINGERING_POTION")){ + if (material.equalsIgnoreCase("SPLASH_POTION") || material.equalsIgnoreCase("LINGERING_POTION")) { material = "POTION"; splash = true; } @@ -102,25 +103,25 @@ public class Items { config.set("material", material); config.set("enchants", item.getConfigurationSection("enchantments")); config.set("unbreakable", item.getBoolean("unbreakable")); - if(Version.atLeast("1.14")){ - if(item.contains("model-data")){ + if (Version.atLeast("1.14")) { + if (item.contains("model-data")) { config.set("model-data", item.getInt("model-data")); } } - if(item.isSet("lore")) + if (item.isSet("lore")) config.set("lore", item.getStringList("lore")); if (material.equalsIgnoreCase("POTION") || material.equalsIgnoreCase("SPLASH_POTION") || material.equalsIgnoreCase("LINGERING_POTION")) config.set("base-effect", String.format("%s,%s,%s", item.getString("type"), false, splash)); ItemStack stack = XItemStack.deserialize(config); stack.setAmount(item.getInt("amount")); - if(stack.getData().getItemType() == Material.AIR) return null; + if (stack.getData().getItemType() == Material.AIR) return null; return stack; } - private static PotionEffect getPotionEffect(ConfigurationSection item){ + private static PotionEffect getPotionEffect(ConfigurationSection item) { String type = item.getString("type"); - if(type == null) return null; - if(PotionEffectType.getByName(type.toUpperCase()) == null) return null; + if (type == null) return null; + if (PotionEffectType.getByName(type.toUpperCase()) == null) return null; return new PotionEffect( Objects.requireNonNull(PotionEffectType.getByName(type.toUpperCase())), item.getInt("duration"), diff --git a/src/main/java/net/tylermurphy/hideAndSeek/configuration/Localization.java b/src/main/java/net/tylermurphy/hideAndSeek/configuration/Localization.java index d477117..be60b61 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/configuration/Localization.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/configuration/Localization.java @@ -19,12 +19,12 @@ package net.tylermurphy.hideAndSeek.configuration; +import net.md_5.bungee.api.ChatColor; + import java.io.File; import java.util.HashMap; import java.util.Map; -import net.md_5.bungee.api.ChatColor; - public class Localization { public static final Map<String,LocalizationString> LOCAL = new HashMap<>(); @@ -40,9 +40,9 @@ public class Localization { int PLUGIN_VERSION = manager.getDefaultInt("version"); int VERSION = manager.getInt("version"); - if(VERSION < PLUGIN_VERSION){ - for(int i = VERSION; i < PLUGIN_VERSION; i++){ - if(i < 1) continue; + if (VERSION < PLUGIN_VERSION) { + for(int i = VERSION; i < PLUGIN_VERSION; i++) { + if (i < 1) continue; String[] changeList = CHANGES.get(Config.locale)[i-1]; for(String change : changeList) manager.reset("Localization." + change); @@ -51,9 +51,9 @@ public class Localization { } String SELECTED_LOCAL = manager.getString("type"); - if(SELECTED_LOCAL == null){ + if (SELECTED_LOCAL == null) { manager.reset("type"); - } else if(!SELECTED_LOCAL.equals(Config.locale)){ + } else if (!SELECTED_LOCAL.equals(Config.locale)) { manager.resetFile("lang"+File.separator+"localization_"+Config.locale +".yml"); } @@ -69,7 +69,7 @@ public class Localization { public static LocalizationString message(String key) { LocalizationString temp = LOCAL.get(key); - if(temp == null) { + 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(temp.toString()); |