From 7d17bd7dd135e8013f478218c0b3c6d4c70edf04 Mon Sep 17 00:00:00 2001 From: bm01 Date: Sat, 28 Apr 2012 09:26:33 +0200 Subject: [PATCH] Fixed Config NPE, made LoadTreasures singleton for consistency --- .../java/com/gmail/nossr50/config/Config.java | 8 ++-- .../gmail/nossr50/config/LoadTreasures.java | 38 ++++++++++++------- src/main/java/com/gmail/nossr50/mcMMO.java | 10 ----- .../com/gmail/nossr50/skills/Excavation.java | 14 +++---- .../com/gmail/nossr50/skills/Fishing.java | 10 ++--- 5 files changed, 40 insertions(+), 40 deletions(-) diff --git a/src/main/java/com/gmail/nossr50/config/Config.java b/src/main/java/com/gmail/nossr50/config/Config.java index d0b2849fe..f79c3054d 100644 --- a/src/main/java/com/gmail/nossr50/config/Config.java +++ b/src/main/java/com/gmail/nossr50/config/Config.java @@ -324,15 +324,15 @@ public class Config extends ConfigLoader { public HUDType defaulthud; - public Config(mcMMO plugin) { + private Config(mcMMO plugin) { super(plugin, "config.yml"); config = plugin.getConfig(); xpGainMultiplier = getExperienceGainsGlobalMultiplier(); + load(); } @Override - public void load() { - + protected void load() { // If it doesn't exist, copy it from the .jar if (!configFile.exists()) { dataFolder.mkdir(); @@ -355,7 +355,7 @@ public class Config extends ConfigLoader { defaulthud = x; } } - + if(defaulthud == null) defaulthud = HUDType.STANDARD; } diff --git a/src/main/java/com/gmail/nossr50/config/LoadTreasures.java b/src/main/java/com/gmail/nossr50/config/LoadTreasures.java index 492840677..60f8feb8b 100644 --- a/src/main/java/com/gmail/nossr50/config/LoadTreasures.java +++ b/src/main/java/com/gmail/nossr50/config/LoadTreasures.java @@ -17,27 +17,37 @@ import com.gmail.nossr50.datatypes.treasure.FishingTreasure; import com.gmail.nossr50.datatypes.treasure.Treasure; public class LoadTreasures extends ConfigLoader{ + private static LoadTreasures instance; - public static List excavationFromDirt = new ArrayList(); - public static List excavationFromGrass = new ArrayList(); - public static List excavationFromSand = new ArrayList(); - public static List excavationFromGravel = new ArrayList(); - public static List excavationFromClay = new ArrayList(); - public static List excavationFromMycel = new ArrayList(); - public static List excavationFromSoulSand = new ArrayList(); - public static List fishingRewardsTier1 = new ArrayList(); - public static List fishingRewardsTier2 = new ArrayList(); - public static List fishingRewardsTier3 = new ArrayList(); - public static List fishingRewardsTier4 = new ArrayList(); - public static List fishingRewardsTier5 = new ArrayList(); + public static LoadTreasures getInstance() { + if (instance == null) { + instance = new LoadTreasures(mcMMO.p); + } - public LoadTreasures(mcMMO plugin) { + return instance; + } + + public List excavationFromDirt = new ArrayList(); + public List excavationFromGrass = new ArrayList(); + public List excavationFromSand = new ArrayList(); + public List excavationFromGravel = new ArrayList(); + public List excavationFromClay = new ArrayList(); + public List excavationFromMycel = new ArrayList(); + public List excavationFromSoulSand = new ArrayList(); + public List fishingRewardsTier1 = new ArrayList(); + public List fishingRewardsTier2 = new ArrayList(); + public List fishingRewardsTier3 = new ArrayList(); + public List fishingRewardsTier4 = new ArrayList(); + public List fishingRewardsTier5 = new ArrayList(); + + private LoadTreasures(mcMMO plugin) { super(plugin, "treasures.yml"); config = plugin.getTreasuresConfig(); + load(); } @Override - public void load() { + protected void load() { // If it doesn't exist, copy it from the .jar if (!configFile.exists()) { diff --git a/src/main/java/com/gmail/nossr50/mcMMO.java b/src/main/java/com/gmail/nossr50/mcMMO.java index 4f760b42d..0c6d8dee2 100644 --- a/src/main/java/com/gmail/nossr50/mcMMO.java +++ b/src/main/java/com/gmail/nossr50/mcMMO.java @@ -46,10 +46,6 @@ public class mcMMO extends JavaPlugin { public static Database database; public static mcMMO p; - //Config file stuff - Config config; - LoadTreasures config2; - //Jar stuff public static File mcmmo; @@ -71,12 +67,6 @@ public class mcMMO extends JavaPlugin { leaderboardDirectory = flatFileDirectory + "Leaderboards" + File.separator; usersFile = flatFileDirectory + "mcmmo.users"; - this.config = new Config(this); - this.config.load(); - - this.config2 = new LoadTreasures(this); - this.config2.load(); - if (!Config.getInstance().getUseMySQL()) { Users.loadUsers(); } diff --git a/src/main/java/com/gmail/nossr50/skills/Excavation.java b/src/main/java/com/gmail/nossr50/skills/Excavation.java index ed94dee7c..ce46ec3c8 100644 --- a/src/main/java/com/gmail/nossr50/skills/Excavation.java +++ b/src/main/java/com/gmail/nossr50/skills/Excavation.java @@ -71,31 +71,31 @@ public class Excavation { if (Permissions.getInstance().excavationTreasures(player)) { switch (type) { case DIRT: - treasures = LoadTreasures.excavationFromDirt; + treasures = LoadTreasures.getInstance().excavationFromDirt; break; case GRASS: - treasures = LoadTreasures.excavationFromGrass; + treasures = LoadTreasures.getInstance().excavationFromGrass; break; case SAND: - treasures = LoadTreasures.excavationFromSand; + treasures = LoadTreasures.getInstance().excavationFromSand; break; case GRAVEL: - treasures = LoadTreasures.excavationFromGravel; + treasures = LoadTreasures.getInstance().excavationFromGravel; break; case CLAY: - treasures = LoadTreasures.excavationFromClay; + treasures = LoadTreasures.getInstance().excavationFromClay; break; case MYCEL: - treasures = LoadTreasures.excavationFromMycel; + treasures = LoadTreasures.getInstance().excavationFromMycel; break; case SOUL_SAND: - treasures = LoadTreasures.excavationFromSoulSand; + treasures = LoadTreasures.getInstance().excavationFromSoulSand; break; default: diff --git a/src/main/java/com/gmail/nossr50/skills/Fishing.java b/src/main/java/com/gmail/nossr50/skills/Fishing.java index 7c6f319d1..3f133fe51 100644 --- a/src/main/java/com/gmail/nossr50/skills/Fishing.java +++ b/src/main/java/com/gmail/nossr50/skills/Fishing.java @@ -74,23 +74,23 @@ public class Fishing { switch (getFishingLootTier(PP)) { case 1: - rewards = LoadTreasures.fishingRewardsTier1; + rewards = LoadTreasures.getInstance().fishingRewardsTier1; break; case 2: - rewards = LoadTreasures.fishingRewardsTier2; + rewards = LoadTreasures.getInstance().fishingRewardsTier2; break; case 3: - rewards = LoadTreasures.fishingRewardsTier3; + rewards = LoadTreasures.getInstance().fishingRewardsTier3; break; case 4: - rewards = LoadTreasures.fishingRewardsTier4; + rewards = LoadTreasures.getInstance().fishingRewardsTier4; break; case 5: - rewards = LoadTreasures.fishingRewardsTier5; + rewards = LoadTreasures.getInstance().fishingRewardsTier5; break; default: