diff --git a/src/main/java/com/alttd/GUI/windows/BuyGUI.java b/src/main/java/com/alttd/GUI/windows/BuyGUI.java index f11e8d1..c028286 100644 --- a/src/main/java/com/alttd/GUI/windows/BuyGUI.java +++ b/src/main/java/com/alttd/GUI/windows/BuyGUI.java @@ -37,7 +37,7 @@ public class BuyGUI extends GUIMerchant { } private void buy(VillagerType villagerType, Player player, Material material, int amount, Price price) { - Economy econ = VillagerUI.getEcon(); + Economy econ = VillagerUI.getInstance().getEconomy(); double balance = econ.getBalance(player); double cost = price.getPrice(amount); diff --git a/src/main/java/com/alttd/GUI/windows/SellGUI.java b/src/main/java/com/alttd/GUI/windows/SellGUI.java index 7255ecc..fd78512 100644 --- a/src/main/java/com/alttd/GUI/windows/SellGUI.java +++ b/src/main/java/com/alttd/GUI/windows/SellGUI.java @@ -38,7 +38,7 @@ public class SellGUI extends GUIMerchant { } private void sell(VillagerType villagerType, Player player, Material material, int amount, Price price) { - Economy econ = VillagerUI.getEcon(); + Economy econ = VillagerUI.getInstance().getEconomy(); double cost = price.getPrice(amount); EconUser econUser = EconUser.users.get(player.getUniqueId()); int oldPoints = econUser.getPointsMap().get(villagerType.getName()); diff --git a/src/main/java/com/alttd/VillagerUI.java b/src/main/java/com/alttd/VillagerUI.java index 573ade4..9548fa9 100644 --- a/src/main/java/com/alttd/VillagerUI.java +++ b/src/main/java/com/alttd/VillagerUI.java @@ -9,22 +9,19 @@ import com.alttd.config.WorthConfig; import com.alttd.events.VillagerInteract; import com.alttd.util.Logger; import net.milkbowl.vault.economy.Economy; +import org.bukkit.Bukkit; import org.bukkit.plugin.RegisteredServiceProvider; import org.bukkit.plugin.java.JavaPlugin; public class VillagerUI extends JavaPlugin { public static VillagerUI instance; - private static Economy econ = null; + private Economy economy = null; public static VillagerUI getInstance() { return instance; } - public static Economy getEcon() { - return econ; - } - @Override public void onLoad() { instance = this; @@ -37,11 +34,8 @@ public class VillagerUI extends JavaPlugin { Config.reload(); VillagerConfig.reload(); WorthConfig.reload(); - if (!setupEconomy()) { - Logger.severe("% - Unable to find vault", getDescription().getName()); - getServer().getPluginManager().disablePlugin(this); + if (!setupEconomy()) return; - } Database.init(); Logger.info("--------------------------------------------------"); Logger.info("Villager UI started"); @@ -53,13 +47,28 @@ public class VillagerUI extends JavaPlugin { getServer().getPluginManager().registerEvents(new VillagerInteract(), this); } - private boolean setupEconomy() { - if (getServer().getPluginManager().getPlugin("Vault") == null) return false; - RegisteredServiceProvider rsp = getServer().getServicesManager().getRegistration(Economy.class); - if (rsp == null) return false; - econ = rsp.getProvider(); + public Economy getEconomy() { + if(economy == null) + setupEconomy(); + return economy; + } - return econ != null; + private boolean setupEconomy() { + if (Bukkit.getPluginManager().getPlugin("Vault") == null) { + this.getLogger().severe("Vault was not found. Please download vault."); + Bukkit.getPluginManager().disablePlugin(this); + return false; + } else { + RegisteredServiceProvider rsp = this.getServer().getServicesManager().getRegistration(Economy.class); + if (rsp == null) { + this.getLogger().severe("Can't find economy! Disabling plugin."); + Bukkit.getPluginManager().disablePlugin(this); + return false; + } else { + this.economy = (Economy)rsp.getProvider(); + return this.economy != null; + } + } } }