mirror of
https://github.com/MilkBowl/Vault.git
synced 2024-11-22 18:46:41 +01:00
merged prelim Bose7 from upstream
This commit is contained in:
parent
0728ee3ac1
commit
1bc729c65f
BIN
lib/BOSEconomy7.jar
Normal file
BIN
lib/BOSEconomy7.jar
Normal file
Binary file not shown.
@ -24,7 +24,8 @@ import java.util.logging.Logger;
|
||||
|
||||
import net.milkbowl.vault.economy.Economy;
|
||||
import net.milkbowl.vault.economy.plugins.Economy_3co;
|
||||
import net.milkbowl.vault.economy.plugins.Economy_BOSE;
|
||||
import net.milkbowl.vault.economy.plugins.Economy_BOSE6;
|
||||
import net.milkbowl.vault.economy.plugins.Economy_BOSE7;
|
||||
import net.milkbowl.vault.economy.plugins.Economy_Essentials;
|
||||
import net.milkbowl.vault.economy.plugins.Economy_MultiCurrency;
|
||||
import net.milkbowl.vault.economy.plugins.Economy_iConomy4;
|
||||
@ -93,13 +94,20 @@ public class Vault extends JavaPlugin {
|
||||
|
||||
// Try to load BOSEconomy
|
||||
if (packageExists(new String[] { "cosine.boseconomy.BOSEconomy" })) {
|
||||
Economy bose = new Economy_BOSE(this);
|
||||
getServer().getServicesManager().register(net.milkbowl.vault.economy.Economy.class, bose, this, ServicePriority.Normal);
|
||||
log.info(String.format("[%s][Economy] BOSEconomy found: %s", getDescription().getName(), bose.isEnabled() ? "Loaded" : "Waiting"));
|
||||
Economy bose6 = new Economy_BOSE6(this);
|
||||
getServer().getServicesManager().register(net.milkbowl.vault.economy.Economy.class, bose6, this, ServicePriority.Normal);
|
||||
log.info(String.format("[%s][Economy] BOSEconomy6 found: %s", getDescription().getName(), bose6.isEnabled() ? "Loaded" : "Waiting"));
|
||||
} else {
|
||||
log.info(String.format("[%s][Economy] BOSEconomy not found.", getDescription().getName()));
|
||||
log.info(String.format("[%s][Economy] BOSEconomy6 not found.", getDescription().getName()));
|
||||
}
|
||||
// Try to load BOSEconomy
|
||||
if (packageExists(new String[] { "cosine.boseconomy.BOSEconomy" })) {
|
||||
Economy bose7 = new Economy_BOSE7(this);
|
||||
getServer().getServicesManager().register(net.milkbowl.vault.economy.Economy.class, bose7, this, ServicePriority.Normal);
|
||||
log.info(String.format("[%s][Economy] BOSEconomy7 found: %s", getDescription().getName(), bose7.isEnabled() ? "Loaded" : "Waiting"));
|
||||
} else {
|
||||
log.info(String.format("[%s][Economy] BOSEconomy7 not found.", getDescription().getName()));
|
||||
}
|
||||
|
||||
// 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);
|
||||
|
@ -34,7 +34,7 @@ import org.bukkit.plugin.PluginManager;
|
||||
|
||||
import cosine.boseconomy.BOSEconomy;
|
||||
|
||||
public class Economy_BOSE implements Economy {
|
||||
public class Economy_BOSE6 implements Economy {
|
||||
private static final Logger log = Logger.getLogger("Minecraft");
|
||||
|
||||
private String name = "BOSEconomy";
|
||||
@ -43,7 +43,7 @@ public class Economy_BOSE implements Economy {
|
||||
private BOSEconomy economy = null;
|
||||
private EconomyServerListener economyServerListener = null;
|
||||
|
||||
public Economy_BOSE(Plugin plugin) {
|
||||
public Economy_BOSE6(Plugin plugin) {
|
||||
this.plugin = plugin;
|
||||
pluginManager = this.plugin.getServer().getPluginManager();
|
||||
|
||||
@ -55,7 +55,7 @@ public class Economy_BOSE implements Economy {
|
||||
// Load Plugin in case it was loaded before
|
||||
if (economy == null) {
|
||||
Plugin bose = plugin.getServer().getPluginManager().getPlugin("BOSEconomy");
|
||||
if (bose != null && bose.isEnabled()) {
|
||||
if (bose != null && bose.isEnabled() && bose.getDescription().getVersion().startsWith("0.6")) {
|
||||
economy = (BOSEconomy) bose;
|
||||
log.info(String.format("[%s][Economy] %s hooked.", plugin.getDescription().getName(), name));
|
||||
}
|
||||
@ -166,9 +166,9 @@ public class Economy_BOSE implements Economy {
|
||||
}
|
||||
|
||||
private class EconomyServerListener extends ServerListener {
|
||||
Economy_BOSE economy = null;
|
||||
Economy_BOSE6 economy = null;
|
||||
|
||||
public EconomyServerListener(Economy_BOSE economy) {
|
||||
public EconomyServerListener(Economy_BOSE6 economy) {
|
||||
this.economy = economy;
|
||||
}
|
||||
|
||||
@ -176,7 +176,7 @@ public class Economy_BOSE implements Economy {
|
||||
if (economy.economy == null) {
|
||||
Plugin bose = plugin.getServer().getPluginManager().getPlugin("BOSEconomy");
|
||||
|
||||
if (bose != null && bose.isEnabled()) {
|
||||
if (bose != null && bose.isEnabled() && bose.getDescription().getVersion().startsWith("0.6")) {
|
||||
economy.economy = (BOSEconomy) bose;
|
||||
log.info(String.format("[%s][Economy] %s hooked.", plugin.getDescription().getName(), economy.name));
|
||||
}
|
||||
@ -185,7 +185,7 @@ public class Economy_BOSE implements Economy {
|
||||
|
||||
public void onPluginDisable(PluginDisableEvent event) {
|
||||
if (economy.economy != null) {
|
||||
if (event.getPlugin().getDescription().getName().equals("BOSEconomy")) {
|
||||
if (event.getPlugin().getDescription().getName().equals("BOSEconomy") && event.getPlugin().getDescription().getVersion().startsWith("0.6")) {
|
||||
economy.economy = null;
|
||||
log.info(String.format("[%s][Economy] %s unhooked.", plugin.getDescription().getName(), economy.name));
|
||||
}
|
204
src/net/milkbowl/vault/economy/plugins/Economy_BOSE7.java
Normal file
204
src/net/milkbowl/vault/economy/plugins/Economy_BOSE7.java
Normal file
@ -0,0 +1,204 @@
|
||||
/**
|
||||
* Copyright (C) 2011 Morgan Humes <morgan@lanaddict.com>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation; either version 2
|
||||
* of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program 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 General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*
|
||||
*/
|
||||
|
||||
package net.milkbowl.vault.economy.plugins;
|
||||
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import net.milkbowl.vault.economy.Economy;
|
||||
import net.milkbowl.vault.economy.EconomyResponse;
|
||||
|
||||
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 cosine.boseconomy.BOSEconomy;
|
||||
|
||||
public class Economy_BOSE7 implements Economy {
|
||||
private static final Logger log = Logger.getLogger("Minecraft");
|
||||
|
||||
private String name = "BOSEconomy";
|
||||
private Plugin plugin = null;
|
||||
private PluginManager pluginManager = null;
|
||||
private BOSEconomy economy = null;
|
||||
private EconomyServerListener economyServerListener = null;
|
||||
|
||||
public Economy_BOSE7(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);
|
||||
|
||||
// Load Plugin in case it was loaded before
|
||||
if (economy == null) {
|
||||
Plugin bose = plugin.getServer().getPluginManager().getPlugin("BOSEconomy");
|
||||
if (bose != null && bose.isEnabled() && bose.getDescription().getVersion().startsWith("0.7")) {
|
||||
economy = (BOSEconomy) bose;
|
||||
log.info(String.format("[%s][Economy] %s hooked.", plugin.getDescription().getName(), name));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEnabled() {
|
||||
if (economy == null) {
|
||||
return false;
|
||||
} else {
|
||||
return economy.isEnabled();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getBalance(String playerName) {
|
||||
final double balance;
|
||||
|
||||
balance = (double) economy.getPlayerMoney(playerName);
|
||||
|
||||
final double fBalance = balance;
|
||||
return fBalance;
|
||||
}
|
||||
|
||||
@Override
|
||||
public EconomyResponse withdrawPlayer(String playerName, double amount) {
|
||||
double balance;
|
||||
EconomyResponse.ResponseType type;
|
||||
String errorMessage = null;
|
||||
|
||||
if (amount < 0) {
|
||||
errorMessage = "Cannot withdraw negative funds";
|
||||
type = EconomyResponse.ResponseType.FAILURE;
|
||||
amount = 0;
|
||||
balance = (double) economy.getPlayerMoney(playerName);
|
||||
|
||||
return new EconomyResponse(balance, balance, type, errorMessage);
|
||||
}
|
||||
|
||||
amount = Math.ceil(amount);
|
||||
balance = (double) economy.getPlayerMoney(playerName);
|
||||
if (balance - amount < 0) {
|
||||
errorMessage = "Insufficient funds";
|
||||
type = EconomyResponse.ResponseType.FAILURE;
|
||||
amount = 0;
|
||||
balance = (double) economy.getPlayerMoney(playerName);
|
||||
|
||||
return new EconomyResponse(balance, balance, type, errorMessage);
|
||||
}
|
||||
if (economy.setPlayerMoney(playerName, (int) (balance - amount), false)) {
|
||||
type = EconomyResponse.ResponseType.SUCCESS;
|
||||
balance = (double) economy.getPlayerMoney(playerName);
|
||||
|
||||
return new EconomyResponse(amount, balance, type, errorMessage);
|
||||
} else {
|
||||
errorMessage = "Error withdrawing funds";
|
||||
type = EconomyResponse.ResponseType.FAILURE;
|
||||
amount = 0;
|
||||
balance = (double) economy.getPlayerMoney(playerName);
|
||||
|
||||
return new EconomyResponse(amount, balance, type, errorMessage);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public EconomyResponse depositPlayer(String playerName, double amount) {
|
||||
double balance;
|
||||
EconomyResponse.ResponseType type;
|
||||
String errorMessage = null;
|
||||
|
||||
if (amount < 0) {
|
||||
errorMessage = "Cannot deposit negative funds";
|
||||
type = EconomyResponse.ResponseType.FAILURE;
|
||||
amount = 0;
|
||||
balance = (double) economy.getPlayerMoney(playerName);
|
||||
|
||||
return new EconomyResponse(balance, balance, type, errorMessage);
|
||||
}
|
||||
amount = Math.ceil(amount);
|
||||
balance = (double) economy.getPlayerMoney(playerName);
|
||||
if (economy.setPlayerMoney(playerName, (int) (balance + amount), false)) {
|
||||
type = EconomyResponse.ResponseType.SUCCESS;
|
||||
balance = (double) economy.getPlayerMoney(playerName);
|
||||
|
||||
return new EconomyResponse(amount, balance, type, errorMessage);
|
||||
} else {
|
||||
errorMessage = "Error withdrawing funds";
|
||||
type = EconomyResponse.ResponseType.FAILURE;
|
||||
amount = 0;
|
||||
balance = (double) economy.getPlayerMoney(playerName);
|
||||
|
||||
return new EconomyResponse(balance, balance, type, errorMessage);
|
||||
}
|
||||
}
|
||||
|
||||
public String getMoneyNamePlural() {
|
||||
return economy.getMoneyNamePlural();
|
||||
}
|
||||
|
||||
public String getMoneyNameSingular() {
|
||||
return economy.getMoneyName();
|
||||
}
|
||||
|
||||
private class EconomyServerListener extends ServerListener {
|
||||
Economy_BOSE7 economy = null;
|
||||
|
||||
public EconomyServerListener(Economy_BOSE7 economy) {
|
||||
this.economy = economy;
|
||||
}
|
||||
|
||||
public void onPluginEnable(PluginEnableEvent event) {
|
||||
if (economy.economy == null) {
|
||||
Plugin bose = plugin.getServer().getPluginManager().getPlugin("BOSEconomy");
|
||||
|
||||
if (bose != null && bose.isEnabled() && bose.getDescription().getVersion().startsWith("0.7")) {
|
||||
economy.economy = (BOSEconomy) bose;
|
||||
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("BOSEconomy") && event.getPlugin().getDescription().getVersion().startsWith("0.7")) {
|
||||
economy.economy = null;
|
||||
log.info(String.format("[%s][Economy] %s unhooked.", plugin.getDescription().getName(), economy.name));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String format(double amount) {
|
||||
if (amount == 1) {
|
||||
return String.format("%f %s", amount, getMoneyNameSingular());
|
||||
} else {
|
||||
return String.format("%f %s", amount, getMoneyNamePlural());
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user