mirror of
https://github.com/MilkBowl/Vault.git
synced 2024-11-23 19:16:31 +01:00
Craftconomy support, cause I'm nice like that.
This commit is contained in:
parent
a7c1b34232
commit
edf4c1fefb
BIN
lib/Craftconomy.jar
Normal file
BIN
lib/Craftconomy.jar
Normal file
Binary file not shown.
@ -1,6 +1,6 @@
|
||||
name: Vault
|
||||
main: net.milkbowl.vault.Vault
|
||||
version: 1.2.4-b${BUILD_NUMBER}
|
||||
version: 1.2.5-b${BUILD_NUMBER}
|
||||
authors: [cereal, Sleaker, mung3r]
|
||||
website: http://dev.bukkit.org/server-mods/vault
|
||||
load: startup
|
||||
|
7
pom.xml
7
pom.xml
@ -179,6 +179,13 @@
|
||||
<systemPath>${project.basedir}/lib/Register.jar</systemPath>
|
||||
<version>1.5</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>me.greatman.Craftconomy</groupId>
|
||||
<artifactId>Craftconomy</artifactId>
|
||||
<version>1.0.0</version>
|
||||
<scope>system</scope>
|
||||
<systemPath>${project.basedir}/lib/Craftconomy.jar</systemPath>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
<build>
|
||||
<resources>
|
||||
|
@ -40,6 +40,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_Craftconomy;
|
||||
import net.milkbowl.vault.economy.plugins.Economy_CurrencyCore;
|
||||
import net.milkbowl.vault.economy.plugins.Economy_EconXP;
|
||||
import net.milkbowl.vault.economy.plugins.Economy_Essentials;
|
||||
@ -214,6 +215,13 @@ public class Vault extends JavaPlugin {
|
||||
|
||||
}
|
||||
|
||||
//Try Loading Craftconomy
|
||||
if (packageExists(new String[] {"me.greatman.Craftconomy.Craftconomy"})) {
|
||||
Economy econ = new Economy_Craftconomy(this);
|
||||
sm.register(Economy.class, econ, this, ServicePriority.Normal);
|
||||
log.info(String.format("[%s][Economy] CraftConomy found: %s", getDescription().getName(), econ.isEnabled() ? "Loaded" : "Waiting"));
|
||||
}
|
||||
|
||||
//Try loading eWallet
|
||||
if (packageExists(new String[] { "me.ethan.eWallet.ECO" })) {
|
||||
Economy econ = new Economy_eWallet(this);
|
||||
|
223
src/net/milkbowl/vault/economy/plugins/Economy_Craftconomy.java
Normal file
223
src/net/milkbowl/vault/economy/plugins/Economy_Craftconomy.java
Normal file
@ -0,0 +1,223 @@
|
||||
package net.milkbowl.vault.economy.plugins;
|
||||
|
||||
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 org.bukkit.plugin.PluginManager;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
import me.greatman.Craftconomy.Account;
|
||||
import me.greatman.Craftconomy.AccountHandler;
|
||||
import me.greatman.Craftconomy.Craftconomy;
|
||||
|
||||
import net.milkbowl.vault.economy.Economy;
|
||||
import net.milkbowl.vault.economy.EconomyResponse;
|
||||
import net.milkbowl.vault.economy.EconomyResponse.ResponseType;
|
||||
|
||||
public class Economy_Craftconomy implements Economy {
|
||||
private static final Logger log = Logger.getLogger("Minecraft");
|
||||
|
||||
private String name = "Craftconomy";
|
||||
private JavaPlugin plugin = null;
|
||||
private PluginManager pluginManager = null;
|
||||
protected Craftconomy economy = null;
|
||||
private EconomyServerListener economyServerListener = null;
|
||||
|
||||
public Economy_Craftconomy(JavaPlugin plugin) {
|
||||
this.plugin = plugin;
|
||||
this.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);
|
||||
|
||||
// Load Plugin in case it was loaded before
|
||||
if (economy == null) {
|
||||
Plugin ec = plugin.getServer().getPluginManager().getPlugin("Craftconomy");
|
||||
if (ec != null && ec.isEnabled() && ec.getClass().getName().equals("me.greatman.Craftconomy.Craftconomy")) {
|
||||
economy = (Craftconomy) ec;
|
||||
log.info(String.format("[%s][Economy] %s hooked.", plugin.getDescription().getName(), name));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private class EconomyServerListener extends ServerListener {
|
||||
Economy_Craftconomy economy = null;
|
||||
|
||||
public EconomyServerListener(Economy_Craftconomy economy) {
|
||||
this.economy = economy;
|
||||
}
|
||||
|
||||
public void onPluginEnable(PluginEnableEvent event) {
|
||||
if (economy.economy == null) {
|
||||
Plugin ec = plugin.getServer().getPluginManager().getPlugin("Craftconomy");
|
||||
|
||||
if (ec != null && ec.isEnabled() && ec.getClass().getName().equals("me.greatman.Craftconomy.Craftconomy")) {
|
||||
economy.economy = (Craftconomy) ec;
|
||||
log.info(String.format("[%s][Economy] %s hooked.", plugin.getDescription().getName(), economy.name));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void onPluginDisable(PluginDisableEvent event) {
|
||||
if (economy.economy != null) {
|
||||
if (event.getPlugin().getDescription().getName().equals("Craftconomy")) {
|
||||
economy.economy = null;
|
||||
log.info(String.format("[%s][Economy] %s unhooked.", plugin.getDescription().getName(), economy.name));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEnabled() {
|
||||
if (economy == null) {
|
||||
return false;
|
||||
} else {
|
||||
return economy.isEnabled();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String format(double amount) {
|
||||
return Craftconomy.format(amount);
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getBalance(String playerName) {
|
||||
if (AccountHandler.exists(playerName)) {
|
||||
return AccountHandler.getAccount(playerName).getBalance();
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public EconomyResponse withdrawPlayer(String playerName, double amount) {
|
||||
double balance;
|
||||
Account account = AccountHandler.getAccount(playerName);
|
||||
if (account.hasEnough(amount)) {
|
||||
balance = account.substractMoney(amount);
|
||||
return new EconomyResponse(amount, balance, ResponseType.SUCCESS, "");
|
||||
} else {
|
||||
return new EconomyResponse(0, account.getBalance(), ResponseType.FAILURE, "Insufficient funds");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public EconomyResponse depositPlayer(String playerName, double amount) {
|
||||
Account account = AccountHandler.getAccount(playerName);
|
||||
account.addMoney(amount);
|
||||
return new EconomyResponse(amount, account.getBalance(), ResponseType.SUCCESS, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean has(String playerName, double amount) {
|
||||
return getBalance(playerName) >= amount;
|
||||
}
|
||||
|
||||
@Override
|
||||
public EconomyResponse createBank(String name, String player) {
|
||||
if (AccountHandler.exists(name)) {
|
||||
return new EconomyResponse(0, AccountHandler.getAccount(player).getBalance(), ResponseType.FAILURE, "That account already exists.");
|
||||
}
|
||||
AccountHandler.getAccount(name);
|
||||
return new EconomyResponse(0, 0, ResponseType.SUCCESS, "");
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public EconomyResponse bankHas(String name, double amount) {
|
||||
if (!AccountHandler.exists(name)) {
|
||||
return new EconomyResponse(0, 0, ResponseType.FAILURE, "Account does not exists!");
|
||||
}
|
||||
|
||||
double balance = AccountHandler.getAccount(name).getBank().getBalance();
|
||||
if ( balance >= amount) {
|
||||
return new EconomyResponse(0, balance, ResponseType.SUCCESS, "");
|
||||
} else {
|
||||
return new EconomyResponse(0, balance, ResponseType.FAILURE, "The account does not have enough!");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public EconomyResponse bankWithdraw(String name, double amount) {
|
||||
double balance;
|
||||
if (!AccountHandler.exists(name)) {
|
||||
return new EconomyResponse(0, 0, ResponseType.FAILURE, "Account does not exists!");
|
||||
}
|
||||
|
||||
Account account = AccountHandler.getAccount(name);
|
||||
if (account.getBank().hasEnough(amount)) {
|
||||
balance = account.getBank().substractMoney(amount);
|
||||
return new EconomyResponse(amount, balance, ResponseType.SUCCESS, "");
|
||||
} else {
|
||||
balance = account.getBank().getBalance();
|
||||
return new EconomyResponse(0, balance, ResponseType.FAILURE, "Insufficient funds");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public EconomyResponse bankDeposit(String name, double amount) {
|
||||
if (!AccountHandler.exists(name)) {
|
||||
return new EconomyResponse(0, 0, ResponseType.FAILURE, "Account does not exists!");
|
||||
}
|
||||
Account account = AccountHandler.getAccount(name);
|
||||
return new EconomyResponse(amount, account.getBank().addMoney(amount), EconomyResponse.ResponseType.SUCCESS, "");
|
||||
}
|
||||
|
||||
@Override
|
||||
public EconomyResponse isBankOwner(String name, String playerName) {
|
||||
return new EconomyResponse(0, 0, ResponseType.NOT_IMPLEMENTED, "Craftconomy does not support Bank owners.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public EconomyResponse isBankMember(String name, String playerName) {
|
||||
return new EconomyResponse(0, 0, ResponseType.NOT_IMPLEMENTED, "Craftconomy does not support Bank members.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public EconomyResponse bankBalance(String name) {
|
||||
if (!AccountHandler.exists(name)) {
|
||||
return new EconomyResponse(0, 0, ResponseType.FAILURE, "There is no bank account with that name");
|
||||
} else {
|
||||
return new EconomyResponse(0, AccountHandler.getAccount(name).getBank().getBalance(), ResponseType.SUCCESS, null);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getBanks() {
|
||||
throw new UnsupportedOperationException("Craftconomy does not support listing of bank accounts");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasBankSupport() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasAccount(String playerName) {
|
||||
return AccountHandler.exists(playerName);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean createPlayerAccount(String playerName) {
|
||||
if (AccountHandler.exists(playerName)) {
|
||||
return false;
|
||||
}
|
||||
AccountHandler.getAccount(playerName);
|
||||
return true;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user