Register API #8f66f7dcae80945250301a9d9e644a74ab28d0b6

Supports BOSE7
This commit is contained in:
snowleo 2011-07-16 14:04:30 +02:00
parent e6685abe4d
commit 5ad12b52f8
7 changed files with 235 additions and 40 deletions

View File

@ -26,7 +26,7 @@ dist.jar=${dist.dir}/Essentials.jar
dist.javadoc.dir=${dist.dir}/javadoc
endorsed.classpath=
excludes=
file.reference.BOSEconomy.jar=../lib/BOSEconomy.jar
file.reference.BOSEconomy7.jar=../lib/BOSEconomy7.jar
file.reference.craftbukkit-0.0.1-SNAPSHOT.jar=..\\lib\\craftbukkit-0.0.1-SNAPSHOT.jar
file.reference.iCo4.jar=../lib/iCo4.jar
file.reference.iCo5.jar=../lib/iCo5.jar
@ -37,9 +37,9 @@ jar.compress=false
javac.classpath=\
${file.reference.Permissions3.jar}:\
${file.reference.craftbukkit-0.0.1-SNAPSHOT.jar}:\
${file.reference.BOSEconomy.jar}:\
${file.reference.iCo4.jar}:\
${file.reference.iCo5.jar}
${file.reference.iCo5.jar}:\
${file.reference.BOSEconomy7.jar}
# Space-separated list of extra javac options
javac.compilerargs=
javac.deprecation=false

View File

@ -1,14 +1,12 @@
package com.earth2me.essentials.register.payment;
import java.util.HashSet;
import java.util.Set;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.bukkit.plugin.Plugin;
import org.bukkit.plugin.PluginManager;
/***
import java.util.HashSet;
import java.util.Set;
/**
* Methods.java
* Controls the getting / setting of methods & the method of payment used.
*
@ -19,18 +17,36 @@ import org.bukkit.plugin.PluginManager;
public class Methods {
private boolean self = false;
private Method Method = null;
private String preferred = "";
private String preferred = "";
private Set<Method> Methods = new HashSet<Method>();
private Set<String> Dependencies = new HashSet<String>();
private Set<Method> Attachables = new HashSet<Method>();
private Set<Method> Attachables = new HashSet<Method>();
public Methods() {
this.addMethod("iConomy", new com.earth2me.essentials.register.payment.methods.iCo4());
this.addMethod("iConomy", new com.earth2me.essentials.register.payment.methods.iCo5());
this.addMethod("BOSEconomy", new com.earth2me.essentials.register.payment.methods.BOSE());
this._init();
}
public Set<String> getDependencies() {
/**
* Allows you to set which economy plugin is most preferred.
*
* @param preferred - preferred economy plugin
*/
public Methods(String preferred) {
this._init();
if(this.Dependencies.contains(preferred)) {
this.preferred = preferred;
}
}
private void _init() {
this.addMethod("iConomy", new com.earth2me.essentials.register.payment.methods.iCo4());
this.addMethod("iConomy", new com.earth2me.essentials.register.payment.methods.iCo5());
this.addMethod("BOSEconomy", new com.earth2me.essentials.register.payment.methods.BOSE6());
this.addMethod("BOSEconomy", new com.earth2me.essentials.register.payment.methods.BOSE7());
}
public Set<String> getDependencies() {
return Dependencies;
}
@ -60,7 +76,7 @@ public class Methods {
int count = 0;
boolean match = false;
Plugin plugin = null;
Plugin plugin;
PluginManager manager = method.getServer().getPluginManager();
for(String name: this.getDependencies()) {
@ -68,14 +84,6 @@ public class Methods {
if(method.getDescription().getName().equals(name)) plugin = method; else plugin = manager.getPlugin(name);
if(plugin == null) continue;
if(!plugin.isEnabled()) {
this.self = true;
//Logger.getLogger("Minecraft").log(Level.SEVERE, name + " Plugin was found, but not enabled before Essentials. Read the Essentials thread for help.");
//manager.enablePlugin(plugin);
}
if(plugin == null) continue;
Method current = this.createMethod(plugin);
if(current == null) continue;
@ -86,7 +94,7 @@ public class Methods {
}
}
if(!this.preferred.isEmpty()) {
if(!this.preferred.isEmpty()) {
do {
if(hasMethod()) {
match = true;

View File

@ -4,7 +4,7 @@ import com.earth2me.essentials.register.payment.Method;
import cosine.boseconomy.BOSEconomy;
import org.bukkit.plugin.Plugin;
public class BOSE implements Method {
public class BOSE6 implements Method {
private BOSEconomy BOSEconomy;
public BOSEconomy getPlugin() {
@ -38,7 +38,7 @@ public class BOSE implements Method {
}
public boolean hasBankAccount(String bank, String name) {
return this.BOSEconomy.isBankOwner(bank, name);
return this.BOSEconomy.isBankOwner(bank, name) || this.BOSEconomy.isBankMember(bank, name);
}
public MethodAccount getAccount(String name) {
@ -47,11 +47,12 @@ public class BOSE implements Method {
}
public MethodBankAccount getBankAccount(String bank, String name) {
return new BOSEBankAccount(bank, name, BOSEconomy);
if(!hasBankAccount(bank, name)) return null;
return new BOSEBankAccount(bank, BOSEconomy);
}
public boolean isCompatible(Plugin plugin) {
return plugin.getDescription().getName().equalsIgnoreCase("boseconomy") && plugin instanceof BOSEconomy;
return plugin.getDescription().getName().equalsIgnoreCase("boseconomy") && plugin instanceof BOSEconomy && plugin.getDescription().getVersion().equals("0.6.2");
}
public void setPlugin(Plugin plugin) {
@ -122,11 +123,9 @@ public class BOSE implements Method {
public class BOSEBankAccount implements MethodBankAccount {
private String bank;
private String name;
private BOSEconomy BOSEconomy;
public BOSEBankAccount(String bank, String name, BOSEconomy bOSEconomy) {
this.name = name;
public BOSEBankAccount(String bank, BOSEconomy bOSEconomy) {
this.bank = bank;
this.BOSEconomy = bOSEconomy;
}
@ -140,36 +139,36 @@ public class BOSE implements Method {
}
public double balance() {
return Double.valueOf(this.BOSEconomy.getBankMoney(name));
return Double.valueOf(this.BOSEconomy.getBankMoney(bank));
}
public boolean set(double amount) {
int IntAmount = (int)Math.ceil(amount);
return this.BOSEconomy.setBankMoney(name, IntAmount, true);
return this.BOSEconomy.setBankMoney(bank, IntAmount, true);
}
public boolean add(double amount) {
int IntAmount = (int)Math.ceil(amount);
int balance = (int)this.balance();
return this.BOSEconomy.setBankMoney(this.name, (balance + IntAmount), false);
return this.BOSEconomy.setBankMoney(bank, (balance + IntAmount), false);
}
public boolean subtract(double amount) {
int IntAmount = (int)Math.ceil(amount);
int balance = (int)this.balance();
return this.BOSEconomy.setBankMoney(this.name, (balance - IntAmount), false);
return this.BOSEconomy.setBankMoney(bank, (balance - IntAmount), false);
}
public boolean multiply(double amount) {
int IntAmount = (int)Math.ceil(amount);
int balance = (int)this.balance();
return this.BOSEconomy.setBankMoney(this.name, (balance * IntAmount), false);
return this.BOSEconomy.setBankMoney(bank, (balance * IntAmount), false);
}
public boolean divide(double amount) {
int IntAmount = (int)Math.ceil(amount);
int balance = (int)this.balance();
return this.BOSEconomy.setBankMoney(this.name, (balance / IntAmount), false);
return this.BOSEconomy.setBankMoney(bank, (balance / IntAmount), false);
}
public boolean hasEnough(double amount) {

View File

@ -0,0 +1,188 @@
package com.earth2me.essentials.register.payment.methods;
import com.earth2me.essentials.register.payment.Method;
import cosine.boseconomy.BOSEconomy;
import org.bukkit.plugin.Plugin;
/**
* @author Acrobot
*/
public class BOSE7 implements Method {
private BOSEconomy BOSEconomy;
public BOSEconomy getPlugin() {
return this.BOSEconomy;
}
public String getName() {
return "BOSEconomy";
}
public String getVersion() {
return "0.7.0";
}
public String format(double amount) {
String currency = this.BOSEconomy.getMoneyNamePlural();
if(amount == 1) currency = this.BOSEconomy.getMoneyName();
return amount + " " + currency;
}
public boolean hasBanks() {
return true;
}
public boolean hasBank(String bank) {
return this.BOSEconomy.bankExists(bank);
}
public boolean hasAccount(String name) {
return this.BOSEconomy.playerRegistered(name, false);
}
public boolean hasBankAccount(String bank, String name) {
return this.BOSEconomy.isBankOwner(bank, name) || this.BOSEconomy.isBankMember(bank, name);
}
public MethodAccount getAccount(String name) {
if(!hasAccount(name)) return null;
return new BOSEAccount(name, this.BOSEconomy);
}
public MethodBankAccount getBankAccount(String bank, String name) {
if(!hasBankAccount(bank, name)) return null;
return new BOSEBankAccount(bank, BOSEconomy);
}
public boolean isCompatible(Plugin plugin) {
return plugin.getDescription().getName().equalsIgnoreCase("boseconomy") && plugin instanceof BOSEconomy && !plugin.getDescription().getVersion().equals("0.6.2");
}
public void setPlugin(Plugin plugin) {
BOSEconomy = (BOSEconomy)plugin;
}
public class BOSEAccount implements MethodAccount {
private String name;
private BOSEconomy BOSEconomy;
public BOSEAccount(String name, BOSEconomy bOSEconomy) {
this.name = name;
this.BOSEconomy = bOSEconomy;
}
public double balance() {
return this.BOSEconomy.getPlayerMoneyDouble(this.name);
}
public boolean set(double amount) {
return this.BOSEconomy.setPlayerMoney(this.name, amount, false);
}
public boolean add(double amount) {
return this.BOSEconomy.addPlayerMoney(this.name, amount, false);
}
public boolean subtract(double amount) {
double balance = this.balance();
return this.BOSEconomy.setPlayerMoney(this.name, (balance - amount), false);
}
public boolean multiply(double amount) {
double balance = this.balance();
return this.BOSEconomy.setPlayerMoney(this.name, (balance * amount), false);
}
public boolean divide(double amount) {
double balance = this.balance();
return this.BOSEconomy.setPlayerMoney(this.name, (balance / amount), false);
}
public boolean hasEnough(double amount) {
return (this.balance() >= amount);
}
public boolean hasOver(double amount) {
return (this.balance() > amount);
}
public boolean hasUnder(double amount) {
return (this.balance() < amount);
}
public boolean isNegative() {
return (this.balance() < 0);
}
public boolean remove() {
return false;
}
}
public class BOSEBankAccount implements MethodBankAccount {
private String bank;
private BOSEconomy BOSEconomy;
public BOSEBankAccount(String bank, BOSEconomy bOSEconomy) {
this.bank = bank;
this.BOSEconomy = bOSEconomy;
}
public String getBankName() {
return this.bank;
}
public int getBankId() {
return -1;
}
public double balance() {
return this.BOSEconomy.getBankMoneyDouble(bank);
}
public boolean set(double amount) {
return this.BOSEconomy.setBankMoney(bank, amount, true);
}
public boolean add(double amount) {
double balance = this.balance();
return this.BOSEconomy.setBankMoney(bank, (balance + amount), false);
}
public boolean subtract(double amount) {
double balance = this.balance();
return this.BOSEconomy.setBankMoney(bank, (balance - amount), false);
}
public boolean multiply(double amount) {
double balance = this.balance();
return this.BOSEconomy.setBankMoney(bank, (balance * amount), false);
}
public boolean divide(double amount) {
double balance = this.balance();
return this.BOSEconomy.setBankMoney(bank, (balance / amount), false);
}
public boolean hasEnough(double amount) {
return (this.balance() >= amount);
}
public boolean hasOver(double amount) {
return (this.balance() > amount);
}
public boolean hasUnder(double amount) {
return (this.balance() < amount);
}
public boolean isNegative() {
return (this.balance() < 0);
}
public boolean remove() {
return this.BOSEconomy.removeBank(bank);
}
}
}

View File

@ -208,4 +208,4 @@ public class iCo5 implements Method {
return true;
}
}
}
}

Binary file not shown.

BIN
lib/BOSEconomy7.jar Normal file

Binary file not shown.