Fixed Config NPE, made LoadTreasures singleton for consistency

This commit is contained in:
bm01 2012-04-28 09:26:33 +02:00
parent 357eded2c3
commit 7d17bd7dd1
5 changed files with 40 additions and 40 deletions

View File

@ -324,15 +324,15 @@ public class Config extends ConfigLoader {
public HUDType defaulthud; public HUDType defaulthud;
public Config(mcMMO plugin) { private Config(mcMMO plugin) {
super(plugin, "config.yml"); super(plugin, "config.yml");
config = plugin.getConfig(); config = plugin.getConfig();
xpGainMultiplier = getExperienceGainsGlobalMultiplier(); xpGainMultiplier = getExperienceGainsGlobalMultiplier();
load();
} }
@Override @Override
public void load() { protected void load() {
// If it doesn't exist, copy it from the .jar // If it doesn't exist, copy it from the .jar
if (!configFile.exists()) { if (!configFile.exists()) {
dataFolder.mkdir(); dataFolder.mkdir();

View File

@ -17,27 +17,37 @@ import com.gmail.nossr50.datatypes.treasure.FishingTreasure;
import com.gmail.nossr50.datatypes.treasure.Treasure; import com.gmail.nossr50.datatypes.treasure.Treasure;
public class LoadTreasures extends ConfigLoader{ public class LoadTreasures extends ConfigLoader{
private static LoadTreasures instance;
public static List<ExcavationTreasure> excavationFromDirt = new ArrayList<ExcavationTreasure>(); public static LoadTreasures getInstance() {
public static List<ExcavationTreasure> excavationFromGrass = new ArrayList<ExcavationTreasure>(); if (instance == null) {
public static List<ExcavationTreasure> excavationFromSand = new ArrayList<ExcavationTreasure>(); instance = new LoadTreasures(mcMMO.p);
public static List<ExcavationTreasure> excavationFromGravel = new ArrayList<ExcavationTreasure>(); }
public static List<ExcavationTreasure> excavationFromClay = new ArrayList<ExcavationTreasure>();
public static List<ExcavationTreasure> excavationFromMycel = new ArrayList<ExcavationTreasure>();
public static List<ExcavationTreasure> excavationFromSoulSand = new ArrayList<ExcavationTreasure>();
public static List<FishingTreasure> fishingRewardsTier1 = new ArrayList<FishingTreasure>();
public static List<FishingTreasure> fishingRewardsTier2 = new ArrayList<FishingTreasure>();
public static List<FishingTreasure> fishingRewardsTier3 = new ArrayList<FishingTreasure>();
public static List<FishingTreasure> fishingRewardsTier4 = new ArrayList<FishingTreasure>();
public static List<FishingTreasure> fishingRewardsTier5 = new ArrayList<FishingTreasure>();
public LoadTreasures(mcMMO plugin) { return instance;
}
public List<ExcavationTreasure> excavationFromDirt = new ArrayList<ExcavationTreasure>();
public List<ExcavationTreasure> excavationFromGrass = new ArrayList<ExcavationTreasure>();
public List<ExcavationTreasure> excavationFromSand = new ArrayList<ExcavationTreasure>();
public List<ExcavationTreasure> excavationFromGravel = new ArrayList<ExcavationTreasure>();
public List<ExcavationTreasure> excavationFromClay = new ArrayList<ExcavationTreasure>();
public List<ExcavationTreasure> excavationFromMycel = new ArrayList<ExcavationTreasure>();
public List<ExcavationTreasure> excavationFromSoulSand = new ArrayList<ExcavationTreasure>();
public List<FishingTreasure> fishingRewardsTier1 = new ArrayList<FishingTreasure>();
public List<FishingTreasure> fishingRewardsTier2 = new ArrayList<FishingTreasure>();
public List<FishingTreasure> fishingRewardsTier3 = new ArrayList<FishingTreasure>();
public List<FishingTreasure> fishingRewardsTier4 = new ArrayList<FishingTreasure>();
public List<FishingTreasure> fishingRewardsTier5 = new ArrayList<FishingTreasure>();
private LoadTreasures(mcMMO plugin) {
super(plugin, "treasures.yml"); super(plugin, "treasures.yml");
config = plugin.getTreasuresConfig(); config = plugin.getTreasuresConfig();
load();
} }
@Override @Override
public void load() { protected void load() {
// If it doesn't exist, copy it from the .jar // If it doesn't exist, copy it from the .jar
if (!configFile.exists()) { if (!configFile.exists()) {

View File

@ -46,10 +46,6 @@ public class mcMMO extends JavaPlugin {
public static Database database; public static Database database;
public static mcMMO p; public static mcMMO p;
//Config file stuff
Config config;
LoadTreasures config2;
//Jar stuff //Jar stuff
public static File mcmmo; public static File mcmmo;
@ -71,12 +67,6 @@ public class mcMMO extends JavaPlugin {
leaderboardDirectory = flatFileDirectory + "Leaderboards" + File.separator; leaderboardDirectory = flatFileDirectory + "Leaderboards" + File.separator;
usersFile = flatFileDirectory + "mcmmo.users"; usersFile = flatFileDirectory + "mcmmo.users";
this.config = new Config(this);
this.config.load();
this.config2 = new LoadTreasures(this);
this.config2.load();
if (!Config.getInstance().getUseMySQL()) { if (!Config.getInstance().getUseMySQL()) {
Users.loadUsers(); Users.loadUsers();
} }

View File

@ -71,31 +71,31 @@ public class Excavation {
if (Permissions.getInstance().excavationTreasures(player)) { if (Permissions.getInstance().excavationTreasures(player)) {
switch (type) { switch (type) {
case DIRT: case DIRT:
treasures = LoadTreasures.excavationFromDirt; treasures = LoadTreasures.getInstance().excavationFromDirt;
break; break;
case GRASS: case GRASS:
treasures = LoadTreasures.excavationFromGrass; treasures = LoadTreasures.getInstance().excavationFromGrass;
break; break;
case SAND: case SAND:
treasures = LoadTreasures.excavationFromSand; treasures = LoadTreasures.getInstance().excavationFromSand;
break; break;
case GRAVEL: case GRAVEL:
treasures = LoadTreasures.excavationFromGravel; treasures = LoadTreasures.getInstance().excavationFromGravel;
break; break;
case CLAY: case CLAY:
treasures = LoadTreasures.excavationFromClay; treasures = LoadTreasures.getInstance().excavationFromClay;
break; break;
case MYCEL: case MYCEL:
treasures = LoadTreasures.excavationFromMycel; treasures = LoadTreasures.getInstance().excavationFromMycel;
break; break;
case SOUL_SAND: case SOUL_SAND:
treasures = LoadTreasures.excavationFromSoulSand; treasures = LoadTreasures.getInstance().excavationFromSoulSand;
break; break;
default: default:

View File

@ -74,23 +74,23 @@ public class Fishing {
switch (getFishingLootTier(PP)) { switch (getFishingLootTier(PP)) {
case 1: case 1:
rewards = LoadTreasures.fishingRewardsTier1; rewards = LoadTreasures.getInstance().fishingRewardsTier1;
break; break;
case 2: case 2:
rewards = LoadTreasures.fishingRewardsTier2; rewards = LoadTreasures.getInstance().fishingRewardsTier2;
break; break;
case 3: case 3:
rewards = LoadTreasures.fishingRewardsTier3; rewards = LoadTreasures.getInstance().fishingRewardsTier3;
break; break;
case 4: case 4:
rewards = LoadTreasures.fishingRewardsTier4; rewards = LoadTreasures.getInstance().fishingRewardsTier4;
break; break;
case 5: case 5:
rewards = LoadTreasures.fishingRewardsTier5; rewards = LoadTreasures.getInstance().fishingRewardsTier5;
break; break;
default: default: