Commit 0c2084b2 authored by Giant's avatar Giant
Browse files

Add Eco to GiantCore.

Finalize some more fields.
parent ed2d3cee
package nl.giantit.minecraft.giantcore;
import nl.giantit.minecraft.giantcore.Database.Database;
import nl.giantit.minecraft.giantcore.core.Eco.Eco;
import nl.giantit.minecraft.giantcore.perms.PermHandler;
import org.bukkit.plugin.Plugin;
......@@ -15,9 +16,10 @@ import java.util.HashMap;
public class GiantCore extends JavaPlugin {
private static GiantCore instance;
private double protocolVersion = 0.2;
private HashMap<PermHandler.Engines, HashMap<Boolean, PermHandler>> permHandler = new HashMap<PermHandler.Engines, HashMap<Boolean, PermHandler>>();
private HashMap<Plugin, Database> dbList = new HashMap<Plugin, Database>();
private final double protocolVersion = 0.2;
private final HashMap<PermHandler.Engines, HashMap<Boolean, PermHandler>> permHandler = new HashMap<PermHandler.Engines, HashMap<Boolean, PermHandler>>();
private final HashMap<Eco.Engines, Eco> ecoHandler = new HashMap<Eco.Engines, Eco>();
private final HashMap<Plugin, Database> dbList = new HashMap<Plugin, Database>();
//private Messages msgHandler;
private void setInstance() {
......@@ -88,6 +90,17 @@ public class GiantCore extends JavaPlugin {
return pH;
}
public Eco getEcoHandler(Eco.Engines ecoEngine) {
if(this.ecoHandler.containsKey(ecoEngine)) {
return this.ecoHandler.get(ecoEngine);
}
Eco eH = new Eco(this, ecoEngine);
this.ecoHandler.put(ecoEngine, eH);
return eH;
}
public static GiantCore getInstance() {
return instance;
}
......
package nl.giantit.minecraft.giantcore.core.Eco;
import nl.giantit.minecraft.giantcore.GiantCore;
import nl.giantit.minecraft.giantcore.core.Eco.Engines.AEco_Engine;
import nl.giantit.minecraft.giantcore.core.Eco.Engines.bose6_Engine;
import nl.giantit.minecraft.giantcore.core.Eco.Engines.bose7_Engine;
import nl.giantit.minecraft.giantcore.core.Eco.Engines.Craftconomy_Engine;
import nl.giantit.minecraft.giantcore.core.Eco.Engines.CurrencyCore_Engine;
import nl.giantit.minecraft.giantcore.core.Eco.Engines.Essentials_Engine;
import nl.giantit.minecraft.giantcore.core.Eco.Engines.ic4_Engine;
import nl.giantit.minecraft.giantcore.core.Eco.Engines.ic5_Engine;
import nl.giantit.minecraft.giantcore.core.Eco.Engines.ic6_Engine;
import nl.giantit.minecraft.giantcore.core.Eco.Engines.McMoney_Engine;
import nl.giantit.minecraft.giantcore.core.Eco.Engines.MineConomy_Engine;
import nl.giantit.minecraft.giantcore.core.Eco.Engines.MultiCurrency_Engine;
import java.lang.reflect.InvocationTargetException;
import java.util.logging.Level;
/**
*
* @author Giant
*/
public class Eco {
private iEco Engine = null;
private GiantCore plugin;
private Engines engine;
public enum Engines {
AECO("AECO", AEco_Engine.class),
CRAFTCONOMY("Craftconomy", CurrencyCore_Engine.class),
CURRENCYCORE("CurrencyCore", Craftconomy_Engine.class),
ESSENTIALS("Essentials Economy", Essentials_Engine.class),
MCMONEY("McMoney", McMoney_Engine.class),
MINECONOMY("MineConomy", MineConomy_Engine.class),
MULTICURRENCY("MultiCurrency", MultiCurrency_Engine.class),
BOSE6("BOSEconomy 6", bose6_Engine.class),
BOSE7("BOSEconomy 7", bose7_Engine.class),
ICONOMY4("iConomy 4", ic4_Engine.class),
ICONOMY5("iConomy 5", ic5_Engine.class),
ICONOMY6("iConomy 6", ic6_Engine.class);
private final String value;
private final Class gameClass;
private Engines(String s, Class gameClass) {
this.value = s;
this.gameClass = gameClass;
}
public Class getGameClass() {
return this.gameClass;
}
@Override
public String toString() {
return this.value;
}
}
private boolean packageExists(String...Packages) {
try{
for(String pckg : Packages) {
Class.forName(pckg);
}
return true;
}catch(ClassNotFoundException e) {
return false;
}
}
public static Engines findEngine(String engine) {
if(engine.equalsIgnoreCase("AECO")) {
return Engines.AECO;
}else if(engine.equalsIgnoreCase("CRAFTCONOMY")) {
return Engines.CRAFTCONOMY;
}else if(engine.equalsIgnoreCase("CURRENCYCORE")) {
return Engines.CURRENCYCORE;
}else if(engine.equalsIgnoreCase("ESSENTIALS")) {
return Engines.ESSENTIALS;
}else if(engine.equalsIgnoreCase("MCMONEY")) {
return Engines.MCMONEY;
}else if(engine.equalsIgnoreCase("MINECONOMY")) {
return Engines.MINECONOMY;
}else if(engine.equalsIgnoreCase("MULTICURRENCY")) {
return Engines.MULTICURRENCY;
}else if(engine.equalsIgnoreCase("BOSE6")) {
return Engines.BOSE6;
}else if(engine.equalsIgnoreCase("BOSE7")) {
return Engines.BOSE7;
}else if(engine.equalsIgnoreCase("ICONOMY4")) {
return Engines.ICONOMY4;
}else if(engine.equalsIgnoreCase("ICONOMY5")) {
return Engines.ICONOMY5;
}else if(engine.equalsIgnoreCase("ICONOMY6")) {
return Engines.ICONOMY6;
}
return null;
}
public Eco(GiantCore plugin, Engines engine) {
this.plugin = plugin;
try {
this.Engine = (iEco)engine.getGameClass().getConstructor(iEco.class).newInstance(this);
}catch(NoSuchMethodException ex) {
plugin.getLogger().log(Level.SEVERE, null, ex);
}catch(InstantiationException ex) {
plugin.getLogger().log(Level.SEVERE, null, ex);
}catch(IllegalAccessException ex) {
plugin.getLogger().log(Level.SEVERE, null, ex);
}catch(IllegalArgumentException ex) {
plugin.getLogger().log(Level.SEVERE, null, ex);
}catch(InvocationTargetException ex) {
plugin.getLogger().log(Level.SEVERE, null, ex);
}
}
public boolean isLoaded() {
return (this.Engine != null && this.Engine.isLoaded());
}
public iEco getEngine() {
return this.Engine;
}
public String getEngineName() {
return this.engine.toString();
}
}
package nl.giantit.minecraft.giantcore.core.Eco.Engines;
import nl.giantit.minecraft.giantcore.GiantCore;
import nl.giantit.minecraft.giantcore.core.Eco.iEco;
import org.bukkit.Bukkit;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.server.PluginEnableEvent;
import org.bukkit.event.server.PluginDisableEvent;
import org.bukkit.entity.Player;
import org.bukkit.plugin.Plugin;
import java.lang.reflect.Method;
import java.util.logging.Level;
import org.neocraft.AEco.AEco;
/**
*
* @author Giant
*/
public class AEco_Engine implements iEco {
private GiantCore plugin;
private org.neocraft.AEco.part.Economy.Economy eco = null;
private Method createWallet = null;
public AEco_Engine(GiantCore plugin) {
this.plugin = plugin;
Bukkit.getServer().getPluginManager().registerEvents(new EcoListener(this), plugin);
if(eco == null) {
Plugin ecoEn = plugin.getServer().getPluginManager().getPlugin("AEco");
if(ecoEn != null && ecoEn.isEnabled()) {
eco = AEco.ECONOMY;
try{
createWallet = eco.getClass().getMethod("createWallet", String.class);
createWallet.setAccessible(true);
}catch(SecurityException e) {
}catch(NoSuchMethodException e) {
}catch(NullPointerException e) {
}
if(eco == null) {
plugin.getLogger().log(Level.WARNING, "Failed to hook into AEco!");
}else{
plugin.getLogger().log(Level.INFO, "Succesfully hooked into AEco!");
}
}
}
}
@Override
public boolean isLoaded() {
return eco != null;
}
@Override
public double getBalance(Player player) {
return this.getBalance(player.getName());
}
@Override
public double getBalance(String player) {
return (double) eco.cash(player);
}
@Override
public boolean withdraw(Player player, double amount) {
return this.withdraw(player.getName(), amount);
}
@Override
public boolean withdraw(String player, double amount) {
if(amount > 0) {
int balance = eco.cash(player);
amount = Math.ceil(amount);
if((balance - amount) >= 0) {
eco.set(player, ((int) (balance - amount)));
return true;
}
}
return false;
}
@Override
public boolean deposit(Player player, double amount) {
return this.deposit(player.getName(), amount);
}
@Override
public boolean deposit(String player, double amount) {
if(amount > 0) {
int balance = eco.cash(player);
eco.set(player, ((int) (balance + Math.ceil(amount))));
return true;
}
return false;
}
public class EcoListener implements Listener {
private AEco_Engine eco;
public EcoListener(AEco_Engine eco) {
this.eco = eco;
}
@EventHandler()
public void onPluginEnable(PluginEnableEvent event) {
if(eco.eco == null) {
Plugin ecoEn = plugin.getServer().getPluginManager().getPlugin("AEco");
if(ecoEn != null && ecoEn.isEnabled()) {
eco.eco = AEco.ECONOMY;
try{
createWallet = eco.eco.getClass().getMethod("createWallet", String.class);
createWallet.setAccessible(true);
}catch(SecurityException e) {
}catch(NoSuchMethodException e) {
}catch(NullPointerException e) {
}
plugin.getLogger().log(Level.INFO, "Succesfully hooked into AEco!");
}
}
}
@EventHandler()
public void onPluginDisable(PluginDisableEvent event) {
if(eco.eco != null) {
if(event.getPlugin().getDescription().getName().equals("AEco")) {
eco.eco = null;
plugin.getLogger().log(Level.INFO, "Succesfully unhooked into AEco!");
}
}
}
}
}
package nl.giantit.minecraft.giantcore.core.Eco.Engines;
import nl.giantit.minecraft.giantcore.GiantCore;
import nl.giantit.minecraft.giantcore.core.Eco.iEco;
import org.bukkit.Bukkit;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.server.PluginEnableEvent;
import org.bukkit.event.server.PluginDisableEvent;
import org.bukkit.entity.Player;
import org.bukkit.plugin.Plugin;
import java.util.logging.Level;
import me.greatman.Craftconomy.Craftconomy;
import me.greatman.Craftconomy.Account;
import me.greatman.Craftconomy.AccountHandler;
/**
*
* @author Giant
*/
public class Craftconomy_Engine implements iEco {
private GiantCore plugin;
private Craftconomy eco = null;
public Craftconomy_Engine(GiantCore plugin) {
this.plugin = plugin;
Bukkit.getServer().getPluginManager().registerEvents(new EcoListener(this), plugin);
if(eco == null) {
Plugin ecoEn = plugin.getServer().getPluginManager().getPlugin("Craftconomy");
if(ecoEn != null && ecoEn.isEnabled()) {
eco = (Craftconomy) ecoEn;
if(eco == null) {
plugin.getLogger().log(Level.WARNING, "Failed to hook into Craftconomy!");
}else{
plugin.getLogger().log(Level.INFO, "Succesfully hooked into Craftconomy!");
}
}
}
}
@Override
public boolean isLoaded() {
return eco != null;
}
@Override
public double getBalance(Player player) {
return this.getBalance(player.getName());
}
@Override
public double getBalance(String player) {
Account acc = AccountHandler.getAccount(player);
return acc.getDefaultBalance();
}
@Override
public boolean withdraw(Player player, double amount) {
return this.withdraw(player.getName(), amount);
}
@Override
public boolean withdraw(String player, double amount) {
if(amount > 0) {
Account acc = AccountHandler.getAccount(player);
if(acc.hasEnough(amount)) {
acc.substractMoney(amount);
return true;
}
}
return false;
}
@Override
public boolean deposit(Player player, double amount) {
return this.deposit(player.getName(), amount);
}
@Override
public boolean deposit(String player, double amount) {
if(amount > 0) {
Account acc = AccountHandler.getAccount(player);
acc.addMoney(amount);
return true;
}
return false;
}
public class EcoListener implements Listener {
private Craftconomy_Engine eco;
public EcoListener(Craftconomy_Engine eco) {
this.eco = eco;
}
@EventHandler()
public void onPluginEnable(PluginEnableEvent event) {
if(eco.eco == null) {
Plugin ecoEn = plugin.getServer().getPluginManager().getPlugin("Craftconomy");
if(ecoEn != null && ecoEn.isEnabled()) {
eco.eco = (Craftconomy) ecoEn;
plugin.getLogger().log(Level.INFO, "Succesfully hooked into Craftconomy!");
}
}
}
@EventHandler()
public void onPluginDisable(PluginDisableEvent event) {
if(eco.eco != null) {
if(event.getPlugin().getDescription().getName().equals("Craftconomy")) {
eco.eco = null;
plugin.getLogger().log(Level.INFO, "Succesfully unhooked into Craftconomy!");
}
}
}
}
}
package nl.giantit.minecraft.giantcore.core.Eco.Engines;
import nl.giantit.minecraft.giantcore.GiantCore;
import nl.giantit.minecraft.giantcore.core.Eco.iEco;
import org.bukkit.Bukkit;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.server.PluginEnableEvent;
import org.bukkit.event.server.PluginDisableEvent;
import org.bukkit.entity.Player;
import org.bukkit.plugin.Plugin;
import java.util.logging.Level;
import is.currency.Currency;
import is.currency.syst.AccountContext;
/**
*
* @author Giant
*/
public class CurrencyCore_Engine implements iEco {
private GiantCore plugin;
private Currency eco = null;
public CurrencyCore_Engine(GiantCore plugin) {
this.plugin = plugin;
Bukkit.getServer().getPluginManager().registerEvents(new EcoListener(this), plugin);
if(eco == null) {
Plugin ecoEn = plugin.getServer().getPluginManager().getPlugin("CurrencyCore");
if(ecoEn != null && ecoEn.isEnabled()) {
eco = (Currency) ecoEn;
if(eco == null) {
plugin.getLogger().log(Level.WARNING, "Failed to hook into CurrencyCore!");
}else{
plugin.getLogger().log(Level.INFO, "Succesfully hooked into CurrencyCore!");
}
}
}
}
@Override
public boolean isLoaded() {
return eco.isEnabled();
}
@Override
public double getBalance(Player player) {
return this.getBalance(player.getName());
}
@Override
public double getBalance(String player) {
AccountContext acc = eco.getAccountManager().getAccount(player);
if(acc == null)
return 0.0;
return acc.getBalance();
}
@Override
public boolean withdraw(Player player, double amount) {
return this.withdraw(player.getName(), amount);
}
@Override
public boolean withdraw(String player, double amount) {
if(amount > 0) {
AccountContext acc = eco.getAccountManager().getAccount(player);
if(acc != null) {
if(acc.hasBalance(amount)) {
acc.subtractBalance(amount);
return true;
}
}
}
return false;
}
@Override
public boolean deposit(Player player, double amount) {
return this.deposit(player.getName(), amount);
}
@Override
public boolean deposit(String player, double amount) {
if(amount > 0) {
AccountContext acc = eco.getAccountManager().getAccount(player);
if(acc != null) {
acc.addBalance(amount);
return true;
}
}
return false;
}
public class EcoListener implements Listener {
private CurrencyCore_Engine eco;
public EcoListener(CurrencyCore_Engine eco) {
this.eco = eco;
}
@EventHandler()
public void onPluginEnable(PluginEnableEvent event) {
if(eco.eco == null) {
Plugin ecoEn = plugin.getServer().getPluginManager().getPlugin("CurrencyCore");
if(ecoEn != null && ecoEn.isEnabled()) {
eco.eco = (Currency) ecoEn;
plugin.getLogger().log(Level.INFO, "Succesfully hooked into CurrencyCore!");
}
}
}
@EventHandler()
public void onPluginDisable(PluginDisableEvent event) {
if(eco.eco != null) {
if(event.getPlugin().getDescription().getName().equals("CurrencyCore")) {
eco.eco = null;
plugin.getLogger().log(Level.INFO, "Succesfully unhooked into CurrencyCore!");
}
}
}
}