Improved getting econ
This commit is contained in:
parent
6893d7bac7
commit
755f8a4324
|
|
@ -37,7 +37,7 @@ public class BuyGUI extends GUIMerchant {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void buy(VillagerType villagerType, Player player, Material material, int amount, Price price) {
|
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 balance = econ.getBalance(player);
|
||||||
double cost = price.getPrice(amount);
|
double cost = price.getPrice(amount);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -38,7 +38,7 @@ public class SellGUI extends GUIMerchant {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void sell(VillagerType villagerType, Player player, Material material, int amount, Price price) {
|
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);
|
double cost = price.getPrice(amount);
|
||||||
EconUser econUser = EconUser.users.get(player.getUniqueId());
|
EconUser econUser = EconUser.users.get(player.getUniqueId());
|
||||||
int oldPoints = econUser.getPointsMap().get(villagerType.getName());
|
int oldPoints = econUser.getPointsMap().get(villagerType.getName());
|
||||||
|
|
|
||||||
|
|
@ -9,22 +9,19 @@ import com.alttd.config.WorthConfig;
|
||||||
import com.alttd.events.VillagerInteract;
|
import com.alttd.events.VillagerInteract;
|
||||||
import com.alttd.util.Logger;
|
import com.alttd.util.Logger;
|
||||||
import net.milkbowl.vault.economy.Economy;
|
import net.milkbowl.vault.economy.Economy;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.plugin.RegisteredServiceProvider;
|
import org.bukkit.plugin.RegisteredServiceProvider;
|
||||||
import org.bukkit.plugin.java.JavaPlugin;
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
|
|
||||||
public class VillagerUI extends JavaPlugin {
|
public class VillagerUI extends JavaPlugin {
|
||||||
|
|
||||||
public static VillagerUI instance;
|
public static VillagerUI instance;
|
||||||
private static Economy econ = null;
|
private Economy economy = null;
|
||||||
|
|
||||||
public static VillagerUI getInstance() {
|
public static VillagerUI getInstance() {
|
||||||
return instance;
|
return instance;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Economy getEcon() {
|
|
||||||
return econ;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onLoad() {
|
public void onLoad() {
|
||||||
instance = this;
|
instance = this;
|
||||||
|
|
@ -37,11 +34,8 @@ public class VillagerUI extends JavaPlugin {
|
||||||
Config.reload();
|
Config.reload();
|
||||||
VillagerConfig.reload();
|
VillagerConfig.reload();
|
||||||
WorthConfig.reload();
|
WorthConfig.reload();
|
||||||
if (!setupEconomy()) {
|
if (!setupEconomy())
|
||||||
Logger.severe("% - Unable to find vault", getDescription().getName());
|
|
||||||
getServer().getPluginManager().disablePlugin(this);
|
|
||||||
return;
|
return;
|
||||||
}
|
|
||||||
Database.init();
|
Database.init();
|
||||||
Logger.info("--------------------------------------------------");
|
Logger.info("--------------------------------------------------");
|
||||||
Logger.info("Villager UI started");
|
Logger.info("Villager UI started");
|
||||||
|
|
@ -53,13 +47,28 @@ public class VillagerUI extends JavaPlugin {
|
||||||
getServer().getPluginManager().registerEvents(new VillagerInteract(), this);
|
getServer().getPluginManager().registerEvents(new VillagerInteract(), this);
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean setupEconomy() {
|
public Economy getEconomy() {
|
||||||
if (getServer().getPluginManager().getPlugin("Vault") == null) return false;
|
if(economy == null)
|
||||||
RegisteredServiceProvider<Economy> rsp = getServer().getServicesManager().getRegistration(Economy.class);
|
setupEconomy();
|
||||||
if (rsp == null) return false;
|
return economy;
|
||||||
econ = rsp.getProvider();
|
}
|
||||||
|
|
||||||
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user