From 6cc2fc7a6e479903875e352d561e5005f7d99496 Mon Sep 17 00:00:00 2001 From: gmcferrin Date: Wed, 9 Jan 2013 22:09:07 -0500 Subject: [PATCH] Functions are still better than copy-pasted code. --- .../java/com/gmail/nossr50/config/Config.java | 68 ++++++------------- 1 file changed, 19 insertions(+), 49 deletions(-) diff --git a/src/main/java/com/gmail/nossr50/config/Config.java b/src/main/java/com/gmail/nossr50/config/Config.java index c99808d75..e242d7e7a 100644 --- a/src/main/java/com/gmail/nossr50/config/Config.java +++ b/src/main/java/com/gmail/nossr50/config/Config.java @@ -1,6 +1,5 @@ package com.gmail.nossr50.config; -import java.util.Iterator; import java.util.Set; import org.bukkit.configuration.ConfigurationSection; @@ -206,22 +205,7 @@ public class Config extends ConfigLoader { public boolean getPotatoDoubleDropsEnabled() { return config.getBoolean("Double_Drops.Herbalism.Potato", true); } public boolean herbalismDoubleDropsDisabled() { - ConfigurationSection section = config.getConfigurationSection("Double_Drops.Herbalism"); - Set keys = section.getKeys(false); - Iterator iterator = keys.iterator(); - - boolean disabled = true; - - while (iterator.hasNext()) { - String key = iterator.next(); - - if (config.getBoolean("Double_Drops.Herbalism." + key)) { - disabled = false; - break; - } - } - - return disabled; + return doubleDropsDisabled("Herbalism"); } /* Mining */ @@ -256,22 +240,7 @@ public class Config extends ConfigLoader { public boolean getEmeraldDoubleDropsEnabled() { return config.getBoolean("Double_Drops.Mining.Emerald", true); } public boolean miningDoubleDropsDisabled() { - ConfigurationSection section = config.getConfigurationSection("Double_Drops.Mining"); - Set keys = section.getKeys(false); - Iterator iterator = keys.iterator(); - - boolean disabled = true; - - while (iterator.hasNext()) { - String key = iterator.next(); - - if (config.getBoolean("Double_Drops.Mining." + key)) { - disabled = false; - break; - } - } - - return disabled; + return doubleDropsDisabled("Mining"); } public int getDetonatorItemID() { return config.getInt("Skills.Mining.Detonator_ID", 259); } @@ -303,22 +272,7 @@ public class Config extends ConfigLoader { public boolean getJungleDoubleDropsEnabled() { return config.getBoolean("Double_Drops.Woodcutting.Jungle", true); } public boolean woodcuttingDoubleDropsDisabled() { - ConfigurationSection section = config.getConfigurationSection("Double_Drops.Woodcutting"); - Set keys = section.getKeys(false); - Iterator iterator = keys.iterator(); - - boolean disabled = true; - - while (iterator.hasNext()) { - String key = iterator.next(); - - if (config.getBoolean("Double_Drops.Woodcutting." + key)) { - disabled = false; - break; - } - } - - return disabled; + return doubleDropsDisabled("Woodcutting"); } /* AFK Leveling */ @@ -466,4 +420,20 @@ public class Config extends ConfigLoader { public double getFormulaMultiplierAxes() { return config.getDouble("Experience.Formula.Multiplier.Axes", 1.0); } public double getFormulaMultiplierAcrobatics() { return config.getDouble("Experience.Formula.Multiplier.Acrobatics", 1.0); } public double getFormulaMultiplierFishing() { return config.getDouble("Experience.Formula.Multiplier.Fishing", 1.0); } + + private boolean doubleDropsDisabled(String skillName) { + ConfigurationSection section = config.getConfigurationSection("Double_Drops." + skillName); + Set keys = section.getKeys(false); + + boolean disabled = true; + + for (String key : keys) { + if (config.getBoolean("Double_Drops." + skillName + "." + key)) { + disabled = false; + break; + } + } + + return disabled; + } }