From e9daa954737864b124e7b4d0d29f8fa24da70e22 Mon Sep 17 00:00:00 2001 From: Tyler Murphy Date: Mon, 11 Apr 2022 12:36:11 -0400 Subject: 1.4.0 initial --- .../hideAndSeek/configuration/Config.java | 21 +++++++++--- .../hideAndSeek/configuration/ConfigManager.java | 14 ++++++++ .../hideAndSeek/configuration/Items.java | 38 +++++++++++++++++----- .../hideAndSeek/configuration/Localization.java | 6 ++-- 4 files changed, 63 insertions(+), 16 deletions(-) (limited to 'src/main/java/net/tylermurphy/hideAndSeek/configuration') diff --git a/src/main/java/net/tylermurphy/hideAndSeek/configuration/Config.java b/src/main/java/net/tylermurphy/hideAndSeek/configuration/Config.java index 524eeac..98b27b2 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/configuration/Config.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/configuration/Config.java @@ -19,6 +19,7 @@ package net.tylermurphy.hideAndSeek.configuration; +import net.tylermurphy.hideAndSeek.util.Version; import org.bukkit.util.Vector; public class Config { @@ -36,7 +37,7 @@ public class Config { spawnWorld, exitWorld, lobbyWorld, - local; + locale; public static Vector spawnPosition, @@ -57,7 +58,8 @@ public class Config { pvpEnabled, autoJoin, teleportToExit, - lobbyCountdownEnabled; + lobbyCountdownEnabled, + seekerPing; public static int minPlayers, @@ -74,7 +76,10 @@ public class Config { countdown, changeCountdown, lobbyMin, - lobbyMax; + lobbyMax, + seekerPingLevel1, + seekerPingLevel2, + seekerPingLevel3; public static void loadConfig() { @@ -143,7 +148,7 @@ public class Config { //Glow glowLength = Math.max(1,manager.getInt("glow.time")); glowStackable = manager.getBoolean("glow.stackable"); - glowEnabled = manager.getBoolean("glow.enabled"); + glowEnabled = manager.getBoolean("glow.enabled") && Version.atLeast("1.9"); //Lobby minPlayers = Math.max(2, manager.getInt("minPlayers")); @@ -153,6 +158,12 @@ public class Config { lobbyMax = manager.getInt("lobby.max"); lobbyCountdownEnabled = manager.getBoolean("lobby.enabled"); + //SeekerPing + seekerPing = manager.getBoolean("seekerPing.enabled"); + seekerPingLevel1 = manager.getInt("seekerPing.distances.level1"); + seekerPingLevel2 = manager.getInt("seekerPing.distances.level2"); + seekerPingLevel3 = manager.getInt("seekerPing.distances.level3"); + //Other nametagsVisible = manager.getBoolean("nametagsVisible"); permissionsRequired = manager.getBoolean("permissionsRequired"); @@ -160,7 +171,7 @@ public class Config { pvpEnabled = manager.getBoolean("pvp"); autoJoin = manager.getBoolean("autoJoin"); teleportToExit = manager.getBoolean("teleportToExit"); - local = manager.getString("local"); + locale = manager.getString("locale", "local"); } public static void addToConfig(String path, Object value) { diff --git a/src/main/java/net/tylermurphy/hideAndSeek/configuration/ConfigManager.java b/src/main/java/net/tylermurphy/hideAndSeek/configuration/ConfigManager.java index 84ad5b4..2217273 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/configuration/ConfigManager.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/configuration/ConfigManager.java @@ -130,6 +130,20 @@ public class ConfigManager { } } + public String getString(String path, String oldPath){ + String value = config.getString(path); + if(value == null){ + String oldValue = config.getString(oldPath); + if(oldValue == null){ + return defaultConfig.getString(path); + } else { + return oldValue; + } + } else { + return value; + } + } + public void reset(String path){ config.set(path, defaultConfig.get(path)); } diff --git a/src/main/java/net/tylermurphy/hideAndSeek/configuration/Items.java b/src/main/java/net/tylermurphy/hideAndSeek/configuration/Items.java index 569cae6..99bc74c 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/configuration/Items.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/configuration/Items.java @@ -19,9 +19,13 @@ package net.tylermurphy.hideAndSeek.configuration; +import com.cryptomorin.xseries.XEnchantment; +import com.cryptomorin.xseries.XMaterial; +import com.cryptomorin.xseries.XPotion; +import net.tylermurphy.hideAndSeek.util.Version; +import org.bukkit.Bukkit; import org.bukkit.ChatColor; import org.bukkit.Material; -import org.bukkit.NamespacedKey; import org.bukkit.configuration.ConfigurationSection; import org.bukkit.enchantments.Enchantment; import org.bukkit.inventory.ItemStack; @@ -63,7 +67,6 @@ public class Items { if(item != null) HIDER_ITEMS.add(item); i++; } - SEEKER_EFFECTS = new ArrayList<>(); ConfigurationSection SeekerEffects = manager.getConfigurationSection("effects.seeker"); i = 1; @@ -91,18 +94,22 @@ public class Items { private static ItemStack createItem(ConfigurationSection item) { String material_string = item.getString("material"); if(material_string == null) return null; - Material material = Material.valueOf(material_string.toUpperCase()); + if(!XMaterial.matchXMaterial(material_string.toUpperCase()).isPresent()) return null; + Material material = XMaterial.matchXMaterial(material_string.toUpperCase()).get().parseMaterial(); int amount = item.getInt("amount"); + if(material == null) return null; ItemStack stack = new ItemStack(material, amount); - if(material == Material.POTION || material == Material.SPLASH_POTION || material == Material.LINGERING_POTION){ + if(material == XMaterial.POTION.parseMaterial() || material == XMaterial.SPLASH_POTION.parseMaterial() || material == XMaterial.LINGERING_POTION.parseMaterial()){ PotionMeta meta = getPotionMeta(stack, item); + if(meta == null) return null; stack.setItemMeta(meta); } else { ConfigurationSection enchantments = item.getConfigurationSection("enchantments"); if (enchantments != null) for (String enchantment_string : enchantments.getKeys(false)) { - Enchantment enchantment = Enchantment.getByKey(NamespacedKey.minecraft(enchantment_string)); + if(!XEnchantment.matchXEnchantment(enchantment_string).isPresent()) continue; + Enchantment enchantment = XEnchantment.matchXEnchantment(enchantment_string).get().getEnchant(); if (enchantment == null) continue; stack.addUnsafeEnchantment( enchantment, @@ -121,23 +128,38 @@ public class Items { String name = item.getString("name"); if(name != null) meta.setDisplayName(ChatColor.translateAlternateColorCodes('&', name)); - meta.setUnbreakable(item.getBoolean("unbreakable")); + if(Version.atLeast("1.11")){ + meta.setUnbreakable(item.getBoolean("unbreakable")); + } else { + meta.spigot().setUnbreakable(true); + } meta.setLore(item.getStringList("lore")); return meta; } - private static PotionMeta getPotionMeta(ItemStack stack, ConfigurationSection item){ + private static PotionMeta getPotionMeta(ItemStack stack, ConfigurationSection item) { String type = item.getString("type"); PotionMeta meta = (PotionMeta) stack.getItemMeta(); if(type==null) return meta; assert meta != null; - meta.setBasePotionData(new PotionData((PotionType.valueOf(type.toUpperCase())))); + XPotion.Effect potionEffect = XPotion.parseEffect(type.toUpperCase()); + if(potionEffect == null) return null; + XPotion xpotion = potionEffect.getXPotion(); + if(xpotion == null) return null; + PotionEffectType potionType = xpotion.getPotionEffectType(); + if(potionType == null) return null; + if(Version.atLeast("1.9")) { + meta.setBasePotionData(new PotionData(xpotion.getPotionType())); + } else { + meta.setMainEffect(potionType); + } return meta; } private static PotionEffect getPotionEffect(ConfigurationSection item){ String type = item.getString("type"); 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 d5ae01d..5ea9e53 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/configuration/Localization.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/configuration/Localization.java @@ -33,7 +33,7 @@ public class Localization { public static void loadLocalization() { - ConfigManager manager = new ConfigManager("localization.yml", "lang"+File.separator+"localization_"+Config.local+".yml"); + ConfigManager manager = new ConfigManager("localization.yml", "lang"+File.separator+"localization_"+Config.locale +".yml"); int PLUGIN_VERSION = 2; int VERSION = manager.getInt("version"); @@ -50,8 +50,8 @@ public class Localization { String SELECTED_LOCAL = manager.getString("type"); if(SELECTED_LOCAL == null){ manager.reset("type"); - } else if(!SELECTED_LOCAL.equals(Config.local)){ - manager.resetFile("lang"+File.separator+"localization_"+Config.local+".yml"); + } else if(!SELECTED_LOCAL.equals(Config.locale)){ + manager.resetFile("lang"+File.separator+"localization_"+Config.locale +".yml"); } manager.saveConfig(); -- cgit v1.2.3-freya