mirror of
https://github.com/MilkBowl/Vault.git
synced 2024-11-10 21:01:03 +01:00
Added Craftconomy3 support
This commit is contained in:
parent
6ffd9dad7d
commit
e95cac855c
BIN
lib/Craftconomy3-b189.jar
Normal file
BIN
lib/Craftconomy3-b189.jar
Normal file
Binary file not shown.
7
pom.xml
7
pom.xml
@ -216,6 +216,13 @@
|
||||
<scope>system</scope>
|
||||
<systemPath>${project.basedir}/lib/Craftconomy.jar</systemPath>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>me.greatmancode</groupId>
|
||||
<artifactId>craftconomy3</artifactId>
|
||||
<version>3.0.0</version>
|
||||
<scope>system</scope>
|
||||
<systemPath>${project.basedir}/lib/Craftconomy3-b189.jar</systemPath>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>net.crystalyx.bukkit.simplyperms</groupId>
|
||||
<artifactId>SimplyPerms</artifactId>
|
||||
|
@ -40,6 +40,7 @@ import net.milkbowl.vault.economy.plugins.Economy_AEco;
|
||||
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_Craftconomy3;
|
||||
import net.milkbowl.vault.economy.plugins.Economy_CurrencyCore;
|
||||
import net.milkbowl.vault.economy.plugins.Economy_EconXP;
|
||||
import net.milkbowl.vault.economy.plugins.Economy_Essentials;
|
||||
@ -203,6 +204,9 @@ public class Vault extends JavaPlugin {
|
||||
|
||||
// Try to load Craftconomy
|
||||
hookEconomy("CraftConomy", Economy_Craftconomy.class, ServicePriority.Normal, "me.greatman.Craftconomy.Craftconomy");
|
||||
|
||||
// Try to load Craftconomy3
|
||||
hookEconomy("CraftConomy3", Economy_Craftconomy3.class, ServicePriority.Normal, "com.greatmancode.craftconomy3.CC3BukkitLoader");
|
||||
|
||||
// Try to load eWallet
|
||||
hookEconomy("eWallet", Economy_eWallet.class, ServicePriority.Normal, "me.ethan.eWallet.ECO");
|
||||
|
@ -176,7 +176,7 @@ public class Economy_Craftconomy implements Economy {
|
||||
return new EconomyResponse(0, 0, ResponseType.SUCCESS, "");
|
||||
}
|
||||
|
||||
return new EconomyResponse(0, 0, ResponseType.FAILURE, "Unable to create that bank account.");
|
||||
return new EconomyResponse(0, 0, ResponseType.FAILURE, "Unable to delete that bank account.");
|
||||
}
|
||||
|
||||
@Override
|
||||
|
299
src/net/milkbowl/vault/economy/plugins/Economy_Craftconomy3.java
Normal file
299
src/net/milkbowl/vault/economy/plugins/Economy_Craftconomy3.java
Normal file
@ -0,0 +1,299 @@
|
||||
/* This file is part of Vault.
|
||||
|
||||
Vault is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
Vault is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with Vault. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package net.milkbowl.vault.economy.plugins;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import net.milkbowl.vault.economy.Economy;
|
||||
import net.milkbowl.vault.economy.EconomyResponse;
|
||||
import net.milkbowl.vault.economy.EconomyResponse.ResponseType;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.server.PluginDisableEvent;
|
||||
import org.bukkit.event.server.PluginEnableEvent;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
|
||||
import com.greatmancode.craftconomy3.CC3BukkitLoader;
|
||||
import com.greatmancode.craftconomy3.Common;
|
||||
import com.greatmancode.craftconomy3.account.Account;
|
||||
import com.greatmancode.craftconomy3.currency.CurrencyManager;
|
||||
import com.greatmancode.craftconomy3.database.tables.AccountTable;
|
||||
|
||||
public class Economy_Craftconomy3 implements Economy {
|
||||
private static final Logger log = Logger.getLogger("Minecraft");
|
||||
|
||||
private final String name = "Craftconomy3";
|
||||
private Plugin plugin = null;
|
||||
protected CC3BukkitLoader economy = null;
|
||||
|
||||
public Economy_Craftconomy3(Plugin plugin) {
|
||||
this.plugin = plugin;
|
||||
Bukkit.getServer().getPluginManager().registerEvents(new EconomyServerListener(this), plugin);
|
||||
|
||||
// Load Plugin in case it was loaded before
|
||||
if (economy == null) {
|
||||
Plugin ec = plugin.getServer().getPluginManager().getPlugin("Craftconomy3");
|
||||
if (ec != null && ec.isEnabled() && ec.getClass().getName().equals("com.greatmancode.craftconomy3.CC3BukkitLoader")) {
|
||||
economy = (CC3BukkitLoader) ec;
|
||||
log.info(String.format("[%s][Economy] %s hooked.", plugin.getDescription().getName(), name));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public class EconomyServerListener implements Listener {
|
||||
Economy_Craftconomy3 economy = null;
|
||||
|
||||
public EconomyServerListener(Economy_Craftconomy3 economy) {
|
||||
this.economy = economy;
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.MONITOR)
|
||||
public void onPluginEnable(PluginEnableEvent event) {
|
||||
if (economy.economy == null) {
|
||||
Plugin ec = plugin.getServer().getPluginManager().getPlugin("Craftconomy3");
|
||||
|
||||
if (ec != null && ec.isEnabled() && ec.getClass().getName().equals("com.greatmancode.craftconomy3.CC3BukkitLoader")) {
|
||||
economy.economy = (CC3BukkitLoader) ec;
|
||||
log.info(String.format("[%s][Economy] %s hooked.", plugin.getDescription().getName(), economy.name));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.MONITOR)
|
||||
public void onPluginDisable(PluginDisableEvent event) {
|
||||
if (economy.economy != null) {
|
||||
if (event.getPlugin().getDescription().getName().equals("Craftconomy3")) {
|
||||
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 Common.getInstance().format(null, Common.getInstance().getCurrencyManager().getCurrency(CurrencyManager.defaultCurrencyID), amount);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String currencyNameSingular() {
|
||||
return Common.getInstance().getCurrencyManager().getCurrency(CurrencyManager.defaultCurrencyID).getName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String currencyNamePlural() {
|
||||
return Common.getInstance().getCurrencyManager().getCurrency(CurrencyManager.defaultCurrencyID).getPlural();
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getBalance(String playerName) {
|
||||
return Common.getInstance().getAccountManager().getAccount(playerName).getBalance(Common.getInstance().getServerCaller().getDefaultWorld(), Common.getInstance().getCurrencyManager().getCurrency(CurrencyManager.defaultCurrencyID).getName());
|
||||
}
|
||||
|
||||
@Override
|
||||
public EconomyResponse withdrawPlayer(String playerName, double amount) {
|
||||
if (amount < 0) {
|
||||
return new EconomyResponse(0, getBalance(playerName), ResponseType.FAILURE, "Cannot withdraw negative funds");
|
||||
}
|
||||
|
||||
double balance;
|
||||
Account account = Common.getInstance().getAccountManager().getAccount(playerName);
|
||||
if (account.hasEnough(amount, Common.getInstance().getServerCaller().getDefaultWorld(), Common.getInstance().getCurrencyManager().getCurrency(CurrencyManager.defaultCurrencyID).getName())) {
|
||||
balance = account.withdraw(amount, Common.getInstance().getServerCaller().getDefaultWorld(), Common.getInstance().getCurrencyManager().getCurrency(CurrencyManager.defaultCurrencyID).getName());
|
||||
return new EconomyResponse(amount, balance, ResponseType.SUCCESS, "");
|
||||
} else {
|
||||
return new EconomyResponse(0, getBalance(playerName), ResponseType.FAILURE, "Insufficient funds");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public EconomyResponse depositPlayer(String playerName, double amount) {
|
||||
if (amount < 0) {
|
||||
return new EconomyResponse(0, getBalance(playerName), ResponseType.FAILURE, "Cannot desposit negative funds");
|
||||
}
|
||||
|
||||
Account account = Common.getInstance().getAccountManager().getAccount(playerName);
|
||||
|
||||
double balance = account.deposit(amount, Common.getInstance().getServerCaller().getDefaultWorld(), Common.getInstance().getCurrencyManager().getCurrency(CurrencyManager.defaultCurrencyID).getName());
|
||||
return new EconomyResponse(amount, balance, ResponseType.SUCCESS, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean has(String playerName, double amount) {
|
||||
return getBalance(playerName) >= amount;
|
||||
}
|
||||
|
||||
@Override
|
||||
public EconomyResponse createBank(String name, String player) {
|
||||
boolean success = false;
|
||||
if (!Common.getInstance().getAccountManager().exist(Account.BANK_PREFIX + name)) {
|
||||
Common.getInstance().getAccountManager().getAccount(Account.BANK_PREFIX + name).getAccountACL().set(player, true, true, true, true, true);
|
||||
success = true;
|
||||
}
|
||||
if (success) {
|
||||
return new EconomyResponse(0, 0, ResponseType.SUCCESS, "");
|
||||
}
|
||||
|
||||
return new EconomyResponse(0, 0, ResponseType.FAILURE, "Unable to create that bank account. It already exists!");
|
||||
}
|
||||
|
||||
@Override
|
||||
public EconomyResponse deleteBank(String name) {
|
||||
boolean success = Common.getInstance().getAccountManager().delete(Account.BANK_PREFIX + name);
|
||||
if (success) {
|
||||
return new EconomyResponse(0, 0, ResponseType.SUCCESS, "");
|
||||
}
|
||||
|
||||
return new EconomyResponse(0, 0, ResponseType.FAILURE, "Unable to delete that bank account.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public EconomyResponse bankHas(String name, double amount) {
|
||||
|
||||
if (Common.getInstance().getAccountManager().exist(Account.BANK_PREFIX + name)) {
|
||||
Account account = Common.getInstance().getAccountManager().getAccount(Account.BANK_PREFIX + name);
|
||||
if (account.hasEnough(amount, Common.getInstance().getServerCaller().getDefaultWorld(), Common.getInstance().getCurrencyManager().getCurrency(CurrencyManager.defaultCurrencyID).getName())) {
|
||||
return new EconomyResponse(0, bankBalance(Account.BANK_PREFIX + name).balance, ResponseType.SUCCESS, "");
|
||||
} else {
|
||||
return new EconomyResponse(0, bankBalance(Account.BANK_PREFIX + name).balance, ResponseType.FAILURE, "The bank does not have enough money!");
|
||||
}
|
||||
}
|
||||
return new EconomyResponse(0, 0, ResponseType.FAILURE, "That bank does not exist!");
|
||||
}
|
||||
|
||||
@Override
|
||||
public EconomyResponse bankWithdraw(String name, double amount) {
|
||||
if (amount < 0) {
|
||||
return new EconomyResponse(0, 0, ResponseType.FAILURE, "Cannot withdraw negative funds");
|
||||
}
|
||||
|
||||
EconomyResponse er = bankHas(name, amount);
|
||||
if (!er.transactionSuccess())
|
||||
return er;
|
||||
else {
|
||||
if (Common.getInstance().getAccountManager().exist(Account.BANK_PREFIX + name)) {
|
||||
return new EconomyResponse(0, withdrawPlayer(Account.BANK_PREFIX + name, amount).balance, ResponseType.SUCCESS, "");
|
||||
}
|
||||
return new EconomyResponse(0, 0, ResponseType.FAILURE, "That bank does not exist!");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public EconomyResponse bankDeposit(String name, double amount) {
|
||||
if (amount < 0) {
|
||||
return new EconomyResponse(0, 0, ResponseType.FAILURE, "Cannot desposit negative funds");
|
||||
}
|
||||
|
||||
if (Common.getInstance().getAccountManager().exist(Account.BANK_PREFIX + name)) {
|
||||
return new EconomyResponse(0, depositPlayer(Account.BANK_PREFIX + name, amount).balance, ResponseType.SUCCESS, "");
|
||||
}
|
||||
return new EconomyResponse(0, 0, ResponseType.FAILURE, "That bank does not exist!");
|
||||
}
|
||||
|
||||
@Override
|
||||
public EconomyResponse isBankOwner(String name, String playerName) {
|
||||
if (Common.getInstance().getAccountManager().exist(Account.BANK_PREFIX + name)) {
|
||||
if (Common.getInstance().getAccountManager().getAccount(Account.BANK_PREFIX + name).getAccountACL().isOwner(playerName)) {
|
||||
return new EconomyResponse(0, bankBalance(Account.BANK_PREFIX + name).balance, ResponseType.SUCCESS, "");
|
||||
}
|
||||
return new EconomyResponse(0, 0, ResponseType.FAILURE, "This player is not the owner of the bank!");
|
||||
}
|
||||
return new EconomyResponse(0, 0, ResponseType.FAILURE, "That bank does not exist!");
|
||||
}
|
||||
|
||||
@Override
|
||||
public EconomyResponse isBankMember(String name, String playerName) {
|
||||
|
||||
// Basicly here if the user have access to deposit & withdraw he's a member
|
||||
EconomyResponse er = isBankOwner(name, playerName);
|
||||
if (er.transactionSuccess())
|
||||
return er;
|
||||
else {
|
||||
if (Common.getInstance().getAccountManager().exist(Account.BANK_PREFIX + name)) {
|
||||
Account account = Common.getInstance().getAccountManager().getAccount(Account.BANK_PREFIX + name);
|
||||
if (account.getAccountACL().canDeposit(playerName) && account.getAccountACL().canWithdraw(playerName)) {
|
||||
return new EconomyResponse(0, bankBalance(name).balance, ResponseType.SUCCESS, "");
|
||||
}
|
||||
}
|
||||
return new EconomyResponse(0, 0, ResponseType.FAILURE, "This player is not a member of the bank!");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public EconomyResponse bankBalance(String name) {
|
||||
if (Common.getInstance().getAccountManager().exist(Account.BANK_PREFIX + name)) {
|
||||
return new EconomyResponse(0, getBalance(Account.BANK_PREFIX + name), ResponseType.SUCCESS, "");
|
||||
}
|
||||
return new EconomyResponse(0, 0, ResponseType.FAILURE, "That bank does not exist!");
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getBanks() {
|
||||
List<AccountTable> accountList = Common.getInstance().getDatabaseManager().getDatabase().select(AccountTable.class).where().contains("name", Account.BANK_PREFIX).execute().find();
|
||||
ArrayList<String> list = new ArrayList<String>();
|
||||
Iterator<AccountTable> iterator = accountList.iterator();
|
||||
while (iterator.hasNext()) {
|
||||
list.add(iterator.next().name.replaceFirst(Account.BANK_PREFIX, ""));
|
||||
}
|
||||
return list;
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasBankSupport() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasAccount(String playerName) {
|
||||
return Common.getInstance().getAccountManager().exist(playerName);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean createPlayerAccount(String playerName) {
|
||||
if (Common.getInstance().getAccountManager().exist(playerName)) {
|
||||
return false;
|
||||
}
|
||||
Common.getInstance().getAccountManager().getAccount(playerName);
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int fractionalDigits() {
|
||||
return -1;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user