added currency core support

This commit is contained in:
Sleaker 2011-12-30 09:03:21 -08:00
parent aef24c4511
commit b872ce41d2
6 changed files with 217 additions and 7 deletions

BIN
lib/CurrencyCore.jar Normal file

Binary file not shown.

View File

@ -1,6 +1,6 @@
name: Vault
main: net.milkbowl.vault.Vault
version: 1.2.0-b000
version: 1.2.1-b000
authors: [Cereal, Sleaker]
website: http://dev.bukkit.org/server-mods/vault
load: startup

View File

@ -20,6 +20,13 @@
<scope>system</scope>
<systemPath>${project.basedir}/lib/3co.jar</systemPath>
</dependency>
<dependency>
<groupId>is.currency</groupId>
<artifactId>Currency</artifactId>
<version>0.3</version>
<scope>system</scope>
<systemPath>${project.basedir}/lib/CurrencyCore.jar</systemPath>
</dependency>
<dependency>
<groupId>cosine.boseconomy.BOSEconomy</groupId>
<artifactId>BOSEconomy</artifactId>

View File

@ -37,6 +37,7 @@ import net.milkbowl.vault.economy.Economy;
import net.milkbowl.vault.economy.plugins.Economy_3co;
import net.milkbowl.vault.economy.plugins.Economy_BOSE6;
import net.milkbowl.vault.economy.plugins.Economy_BOSE7;
import net.milkbowl.vault.economy.plugins.Economy_CurrencyCore;
import net.milkbowl.vault.economy.plugins.Economy_EconXP;
import net.milkbowl.vault.economy.plugins.Economy_Essentials;
import net.milkbowl.vault.economy.plugins.Economy_MineConomy;
@ -221,6 +222,13 @@ public class Vault extends JavaPlugin {
log.info(String.format("[%s][Economy] BOSEconomy7 found: %s", getDescription().getName(), bose7.isEnabled() ? "Loaded" : "Waiting"));
}
//Try to load CurrencyCore
if (packageExists(new String[] { "is.currency.Currency" })) {
Economy cCore = new Economy_CurrencyCore(this);
getServer().getServicesManager().register(net.milkbowl.vault.economy.Economy.class, cCore, this, ServicePriority.Normal);
log.info(String.format("[%s][Economy] CurrencyCore found: %s", getDescription().getName(), cCore.isEnabled() ? "Loaded" : "Waiting"));
}
// Try to load Essentials Economy
if (packageExists(new String[] { "com.earth2me.essentials.api.Economy", "com.earth2me.essentials.api.NoLoanPermittedException", "com.earth2me.essentials.api.UserDoesNotExistException" })) {
Economy essentials = new Economy_Essentials(this);

View File

@ -34,25 +34,22 @@ import org.bukkit.event.server.PluginDisableEvent;
import org.bukkit.event.server.PluginEnableEvent;
import org.bukkit.event.server.ServerListener;
import org.bukkit.plugin.Plugin;
import org.bukkit.plugin.PluginManager;
public class Economy_3co implements Economy {
private static final Logger log = Logger.getLogger("Minecraft");
private String name = "3co";
private Plugin plugin = null;
private PluginManager pluginManager = null;
private ECO economy = null;
private EconomyServerListener economyServerListener = null;
public Economy_3co(Plugin plugin) {
this.plugin = plugin;
pluginManager = this.plugin.getServer().getPluginManager();
economyServerListener = new EconomyServerListener(this);
this.pluginManager.registerEvent(Type.PLUGIN_ENABLE, economyServerListener, Priority.Monitor, plugin);
this.pluginManager.registerEvent(Type.PLUGIN_DISABLE, economyServerListener, Priority.Monitor, plugin);
this.plugin.getServer().getPluginManager().registerEvent(Type.PLUGIN_ENABLE, economyServerListener, Priority.Monitor, plugin);
this.plugin.getServer().getPluginManager().registerEvent(Type.PLUGIN_DISABLE, economyServerListener, Priority.Monitor, plugin);
// Load Plugin in case it was loaded before
if (economy == null) {

View File

@ -0,0 +1,198 @@
package net.milkbowl.vault.economy.plugins;
import is.currency.Currency;
import is.currency.syst.AccountContext;
import java.util.Arrays;
import java.util.List;
import java.util.logging.Logger;
import org.bukkit.event.Event.Priority;
import org.bukkit.event.Event.Type;
import org.bukkit.event.server.PluginDisableEvent;
import org.bukkit.event.server.PluginEnableEvent;
import org.bukkit.event.server.ServerListener;
import org.bukkit.plugin.Plugin;
import net.milkbowl.vault.economy.Economy;
import net.milkbowl.vault.economy.EconomyResponse;
import net.milkbowl.vault.economy.EconomyResponse.ResponseType;
public class Economy_CurrencyCore implements Economy {
private Currency currency;
private static final Logger log = Logger.getLogger("Minecraft");
private final Plugin plugin;
private EconomyServerListener economyServerListener = null;
private final String name = "CurrencyCore";
public Economy_CurrencyCore(Plugin plugin) {
this.plugin = plugin;
economyServerListener = new EconomyServerListener(this);
this.plugin.getServer().getPluginManager().registerEvent(Type.PLUGIN_ENABLE, economyServerListener, Priority.Monitor, plugin);
this.plugin.getServer().getPluginManager().registerEvent(Type.PLUGIN_DISABLE, economyServerListener, Priority.Monitor, plugin);
// Load Plugin in case it was loaded before
if(currency == null) {
Plugin currencyPlugin = plugin.getServer().getPluginManager().getPlugin("CurrencyCore");
if(currencyPlugin != null && currencyPlugin.getClass().getName().equals("is.currency.Currency")) {
this.currency = (Currency) currencyPlugin;
log.info(String.format("[%s][Economy] %s hooked.", plugin.getDescription().getName(), name));
}
}
}
private class EconomyServerListener extends ServerListener {
private Economy_CurrencyCore economy = null;
public EconomyServerListener(Economy_CurrencyCore economy) {
this.economy = economy;
}
public void onPluginEnable(PluginEnableEvent event) {
if(this.economy.currency == null) {
Plugin currencyPlugin = plugin.getServer().getPluginManager().getPlugin("CurrencyCore");
if(currencyPlugin != null && currencyPlugin.getClass().getName().equals("is.currency.Currency")) {
this.economy.currency = (Currency) currencyPlugin;
log.info(String.format("[%s][Economy] %s hooked.", plugin.getDescription().getName(), this.economy.getName()));
}
}
}
public void onPluginDisable(PluginDisableEvent event) {
if (this.economy.currency != null) {
if (event.getPlugin().getDescription().getName().equals("CurrencyCore")) {
this.economy.currency = null;
log.info(String.format("[%s][Economy] %s unhooked.", plugin.getDescription().getName(), this.economy.getName()));
}
}
}
}
@Override
public boolean isEnabled() {
return currency != null;
}
@Override
public String getName() {
return name;
}
@Override
public String format(double amount) {
return this.currency.getFormatHelper().format(amount);
}
@Override
public double getBalance(String playerName) {
AccountContext account = this.currency.getAccountManager().getAccount(playerName);
if (account == null)
return 0.0;
return account.getBalance();
}
@Override
public boolean has(String playerName, double amount) {
AccountContext account = this.currency.getAccountManager().getAccount(playerName);
if (account == null)
return false;
else
return account.hasBalance(amount);
}
@Override
public EconomyResponse withdrawPlayer(String playerName, double amount) {
AccountContext account = this.currency.getAccountManager().getAccount(playerName);
if (account == null) {
return new EconomyResponse(0.0, 0.0, ResponseType.FAILURE, "That account does not exist");
} else if (!account.hasBalance(amount)) {
return new EconomyResponse(0.0, account.getBalance(), ResponseType.FAILURE, "Insufficient funds");
}
account.subtractBalance(amount);
return new EconomyResponse(amount, account.getBalance(), ResponseType.SUCCESS, "");
}
@Override
public EconomyResponse depositPlayer(String playerName, double amount) {
AccountContext account = this.currency.getAccountManager().getAccount(playerName);
if (account == null) {
return new EconomyResponse(0.0, 0.0, ResponseType.FAILURE, "That account does not exist");
}
account.addBalance(amount);
return new EconomyResponse(amount, account.getBalance(), ResponseType.SUCCESS, "");
}
@Override
public EconomyResponse createBank(String name, String player) {
if (this.currency.getAccountManager().hasAccount(name)) {
return new EconomyResponse(0, currency.getAccountManager().getAccount(name).getBalance(), ResponseType.FAILURE, "That account already exists.");
}
this.currency.getAccountManager().createAccount(name);
return new EconomyResponse(0, 0, ResponseType.SUCCESS, "");
}
@Override
public EconomyResponse bankBalance(String name) {
if (this.currency.getAccountManager().hasAccount(name)) {
return new EconomyResponse(0, getBalance(name), ResponseType.FAILURE, "That account already exists.");
}
this.currency.getAccountManager().createAccount(name);
return new EconomyResponse(0, 0, ResponseType.SUCCESS, "");
}
@Override
public EconomyResponse bankHas(String name, double amount) {
AccountContext account = this.currency.getAccountManager().getAccount(name);
if (account == null) {
return new EconomyResponse(0, 0, ResponseType.FAILURE, "That account does not exist!");
} else if (!account.hasBalance(amount)) {
return new EconomyResponse(0, account.getBalance(), ResponseType.FAILURE, "That account does not have enough!");
} else {
return new EconomyResponse(0, account.getBalance(), ResponseType.SUCCESS, "");
}
}
@Override
public EconomyResponse bankWithdraw(String name, double amount) {
AccountContext account = this.currency.getAccountManager().getAccount(name);
if (account == null) {
return new EconomyResponse(0, 0, ResponseType.FAILURE, "That account does not exist!");
} else if (!account.hasBalance(amount)) {
return new EconomyResponse(0, account.getBalance(), ResponseType.FAILURE, "That account does not have enough!");
} else {
account.subtractBalance(amount);
return new EconomyResponse(amount, account.getBalance(), ResponseType.SUCCESS, "");
}
}
@Override
public EconomyResponse bankDeposit(String name, double amount) {
AccountContext account = this.currency.getAccountManager().getAccount(name);
if (account == null) {
return new EconomyResponse(0, 0, ResponseType.FAILURE, "That account does not exist!");
} else {
account.addBalance(amount);
return new EconomyResponse(amount, account.getBalance(), ResponseType.SUCCESS, "");
}
}
@Override
public EconomyResponse isBankOwner(String name, String playerName) {
return new EconomyResponse(0, 0, ResponseType.NOT_IMPLEMENTED, "Currency does not support Bank members.");
}
@Override
public EconomyResponse isBankMember(String name, String playerName) {
return new EconomyResponse(0, 0, ResponseType.NOT_IMPLEMENTED, "Currency does not support Bank members.");
}
@Override
public List<String> getBanks() {
return Arrays.asList(this.currency.getAccountManager().getAccounts());
}
}