From 6ea3c4987f6e48db53451afc4a6e1c31a3b7fd39 Mon Sep 17 00:00:00 2001 From: Zach Brown Date: Sun, 22 Jun 2014 15:37:12 -0500 Subject: [PATCH] Add float methods to configs --- .../0029-Add-float-methods-to-configs.patch | 90 +++++++++++++++++++ .../0155-Add-getFloat-method-to-configs.patch | 47 ++++++++++ 2 files changed, 137 insertions(+) create mode 100644 Bukkit-Patches/0029-Add-float-methods-to-configs.patch create mode 100644 CraftBukkit-Patches/0155-Add-getFloat-method-to-configs.patch diff --git a/Bukkit-Patches/0029-Add-float-methods-to-configs.patch b/Bukkit-Patches/0029-Add-float-methods-to-configs.patch new file mode 100644 index 0000000000..4cd5df6dfb --- /dev/null +++ b/Bukkit-Patches/0029-Add-float-methods-to-configs.patch @@ -0,0 +1,90 @@ +From dc0d012d546ff97273c1dc7eb099ac84c0748ca9 Mon Sep 17 00:00:00 2001 +From: Zach Brown +Date: Mon, 19 May 2014 22:51:45 -0500 +Subject: [PATCH] Add float methods to configs + + +diff --git a/src/main/java/org/bukkit/configuration/ConfigurationSection.java b/src/main/java/org/bukkit/configuration/ConfigurationSection.java +index 1bd7fb5..9afc1dc 100644 +--- a/src/main/java/org/bukkit/configuration/ConfigurationSection.java ++++ b/src/main/java/org/bukkit/configuration/ConfigurationSection.java +@@ -355,6 +355,48 @@ public interface ConfigurationSection { + */ + public boolean isDouble(String path); + ++ // PaperSpigot start - Add getFloat ++ /** ++ * Gets the requested float by path. ++ *

++ * If the float does not exist but a default value has been specified, ++ * this will return the default value. If the float does not exist and no ++ * default value was specified, this will return 0. ++ * ++ * @param path Path of the float to get. ++ * @return Requested float. ++ */ ++ public float getFloat(String path); ++ ++ /** ++ * Gets the requested float by path, returning a default value if not ++ * found. ++ *

++ * If the float does not exist then the specified default value will ++ * returned regardless of if a default has been identified in the root ++ * {@link Configuration}. ++ * ++ * @param path Path of the float to get. ++ * @param def The default value to return if the path is not found or is ++ * not a float. ++ * @return Requested float. ++ */ ++ public float getFloat(String path, float def); ++ ++ /** ++ * Checks if the specified path is a float. ++ *

++ * If the path exists but is not a float, this will return false. If the ++ * path does not exist, this will return false. If the path does not exist ++ * but a default value has been specified, this will check if that default ++ * value is a gloat and return appropriately. ++ * ++ * @param path Path of the float to check. ++ * @return Whether or not the specified path is a float. ++ */ ++ public boolean isFloat(String path); ++ // PaperSpigot end ++ + /** + * Gets the requested long by path. + *

+diff --git a/src/main/java/org/bukkit/configuration/MemorySection.java b/src/main/java/org/bukkit/configuration/MemorySection.java +index f180bf5..0e2b26a 100644 +--- a/src/main/java/org/bukkit/configuration/MemorySection.java ++++ b/src/main/java/org/bukkit/configuration/MemorySection.java +@@ -336,6 +336,23 @@ public class MemorySection implements ConfigurationSection { + return val instanceof Double; + } + ++ // PaperSpigot start - Add getFloat ++ public float getFloat(String path) { ++ Object def = getDefault(path); ++ return getFloat(path, (def instanceof Float) ? toFloat(def) : 0); ++ } ++ ++ public float getFloat(String path, float def) { ++ Object val = get(path, def); ++ return (val instanceof Float) ? toFloat(val) : def; ++ } ++ ++ public boolean isFloat(String path) { ++ Object val = get(path); ++ return val instanceof Float; ++ } ++ // PaperSpigot end ++ + public long getLong(String path) { + Object def = getDefault(path); + return getLong(path, (def instanceof Number) ? toLong(def) : 0); +-- +1.9.1 + diff --git a/CraftBukkit-Patches/0155-Add-getFloat-method-to-configs.patch b/CraftBukkit-Patches/0155-Add-getFloat-method-to-configs.patch new file mode 100644 index 0000000000..849799adf2 --- /dev/null +++ b/CraftBukkit-Patches/0155-Add-getFloat-method-to-configs.patch @@ -0,0 +1,47 @@ +From 4ab2112e922501a5ea9f47ab927c97c8787b0cb7 Mon Sep 17 00:00:00 2001 +From: Zach Brown +Date: Mon, 19 May 2014 21:08:44 -0500 +Subject: [PATCH] Add getFloat method to configs + + +diff --git a/src/main/java/org/spigotmc/SpigotConfig.java b/src/main/java/org/spigotmc/SpigotConfig.java +index 5818cab..5ddd593 100644 +--- a/src/main/java/org/spigotmc/SpigotConfig.java ++++ b/src/main/java/org/spigotmc/SpigotConfig.java +@@ -120,6 +120,14 @@ public class SpigotConfig + return config.getBoolean( path, config.getBoolean( path ) ); + } + ++ // PaperSpigot start - Add getFloat ++ private static float getFloat(String path, float def) ++ { ++ config.addDefault( path, def ); ++ return config.getFloat( path, config.getFloat( path ) ); ++ } ++ // PaperSpigot end ++ + private static int getInt(String path, int def) + { + config.addDefault( path, def ); +diff --git a/src/main/java/org/spigotmc/SpigotWorldConfig.java b/src/main/java/org/spigotmc/SpigotWorldConfig.java +index f9f8c05..c340fb3 100644 +--- a/src/main/java/org/spigotmc/SpigotWorldConfig.java ++++ b/src/main/java/org/spigotmc/SpigotWorldConfig.java +@@ -52,6 +52,14 @@ public class SpigotWorldConfig + return config.getDouble( "world-settings." + worldName + "." + path, config.getDouble( "world-settings.default." + path ) ); + } + ++ // PaperSpigot start - Add getFloat ++ private float getFloat(String path, float def) ++ { ++ config.addDefault( "world-settings.default." + path, def ); ++ return config.getFloat( "world-settings." + worldName + "." + path, config.getFloat( "world-settings.default." + path ) ); ++ } ++ // PaperSpigot end ++ + private int getInt(String path, int def) + { + config.addDefault( "world-settings.default." + path, def ); +-- +1.9.1 +