mirror of
https://github.com/ChestShop-authors/ChestShop-3.git
synced 2025-01-13 02:20:36 +01:00
Fixed economy issues - thanks niji!
This commit is contained in:
parent
d5b791f8c8
commit
7e093d0b5e
@ -45,7 +45,6 @@ public class playerInteract extends PlayerListener{
|
|||||||
|
|
||||||
Action buy = (Config.getBoolean("reverse_buttons") ? Action.LEFT_CLICK_BLOCK : Action.RIGHT_CLICK_BLOCK);
|
Action buy = (Config.getBoolean("reverse_buttons") ? Action.LEFT_CLICK_BLOCK : Action.RIGHT_CLICK_BLOCK);
|
||||||
|
|
||||||
|
|
||||||
if(action == buy){
|
if(action == buy){
|
||||||
player.sendMessage("You are buying!");
|
player.sendMessage("You are buying!");
|
||||||
} else{
|
} else{
|
||||||
|
@ -1,12 +1,12 @@
|
|||||||
package com.Acrobot.ChestShop.Listeners;
|
package com.Acrobot.ChestShop.Listeners;
|
||||||
|
|
||||||
|
import com.Acrobot.ChestShop.ChestShop;
|
||||||
import com.Acrobot.ChestShop.Economy;
|
import com.Acrobot.ChestShop.Economy;
|
||||||
import com.Acrobot.ChestShop.Items.Odd;
|
import com.Acrobot.ChestShop.Items.Odd;
|
||||||
import com.Acrobot.ChestShop.Permission;
|
import com.Acrobot.ChestShop.Permission;
|
||||||
import com.Acrobot.ChestShop.Protection.LWCplugin;
|
import com.Acrobot.ChestShop.Protection.LWCplugin;
|
||||||
import com.Acrobot.ChestShop.Protection.LockettePlugin;
|
import com.Acrobot.ChestShop.Protection.LockettePlugin;
|
||||||
import com.Acrobot.ChestShop.Protection.Security;
|
import com.Acrobot.ChestShop.Protection.Security;
|
||||||
import com.Acrobot.ChestShop.ChestShop;
|
|
||||||
import com.griefcraft.lwc.LWCPlugin;
|
import com.griefcraft.lwc.LWCPlugin;
|
||||||
import com.nijikokun.bukkit.Permissions.Permissions;
|
import com.nijikokun.bukkit.Permissions.Permissions;
|
||||||
import com.nijikokun.register.payment.Methods;
|
import com.nijikokun.register.payment.Methods;
|
||||||
@ -22,12 +22,15 @@ import org.yi.acru.bukkit.Lockette.Lockette;
|
|||||||
*/
|
*/
|
||||||
public class pluginEnable extends ServerListener{
|
public class pluginEnable extends ServerListener{
|
||||||
|
|
||||||
private Methods Methods = new Methods();
|
private Methods methods = new Methods();
|
||||||
|
|
||||||
|
|
||||||
public void onPluginEnable(PluginEnableEvent event){
|
public void onPluginEnable(PluginEnableEvent event){
|
||||||
|
|
||||||
if(!this.Methods.hasMethod()){
|
//Economy plugins
|
||||||
if(this.Methods.setMethod(event.getPlugin())){
|
if(!this.methods.hasMethod()){
|
||||||
Economy.economy = this.Methods.getMethod();
|
if(methods.setMethod(event.getPlugin())){
|
||||||
|
Economy.economy = methods.getMethod();
|
||||||
System.out.println("[ChestShop] " + Economy.economy.getName() + " " + Economy.economy.getVersion() + " loaded.");
|
System.out.println("[ChestShop] " + Economy.economy.getName() + " " + Economy.economy.getVersion() + " loaded.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2,6 +2,14 @@ package com.nijikokun.register.payment;
|
|||||||
|
|
||||||
import org.bukkit.plugin.Plugin;
|
import org.bukkit.plugin.Plugin;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method.java
|
||||||
|
* Interface for all sub-methods for payment.
|
||||||
|
*
|
||||||
|
* @author: Nijikokun<nijikokun@gmail.com> (@nijikokun)
|
||||||
|
* @copyright: Copyright (C) 2011
|
||||||
|
* @license: GNUv3 Affero License <http://www.gnu.org/licenses/agpl-3.0.html>
|
||||||
|
*/
|
||||||
public interface Method {
|
public interface Method {
|
||||||
public Object getPlugin();
|
public Object getPlugin();
|
||||||
public String getName();
|
public String getName();
|
||||||
|
@ -1,31 +0,0 @@
|
|||||||
package com.nijikokun.register.payment;
|
|
||||||
|
|
||||||
import java.util.HashSet;
|
|
||||||
import java.util.Set;
|
|
||||||
import org.bukkit.plugin.Plugin;
|
|
||||||
|
|
||||||
public class MethodFactory {
|
|
||||||
|
|
||||||
private static Set<Method> Methods = new HashSet<Method>();
|
|
||||||
private static Set<String> Dependencies = new HashSet<String>();
|
|
||||||
|
|
||||||
public static Method createMethod(Plugin plugin) {
|
|
||||||
for (Method method: Methods) {
|
|
||||||
if (method.isCompatible(plugin)) {
|
|
||||||
method.setPlugin(plugin);
|
|
||||||
return method;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void addMethod(String name, Method method) {
|
|
||||||
Dependencies.add(name);
|
|
||||||
Methods.add(method);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Set<String> getDependencies() {
|
|
||||||
return Dependencies;
|
|
||||||
}
|
|
||||||
}
|
|
@ -3,44 +3,80 @@ package com.nijikokun.register.payment;
|
|||||||
import org.bukkit.plugin.Plugin;
|
import org.bukkit.plugin.Plugin;
|
||||||
import org.bukkit.plugin.PluginManager;
|
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.
|
||||||
|
*
|
||||||
|
* @author: Nijikokun<nijikokun@gmail.com> (@nijikokun)
|
||||||
|
* @copyright: Copyright (C) 2011
|
||||||
|
* @license: GNUv3 Affero License <http://www.gnu.org/licenses/agpl-3.0.html>
|
||||||
|
*/
|
||||||
public class Methods {
|
public class Methods {
|
||||||
|
|
||||||
private Method Method = null;
|
private Method Method = null;
|
||||||
|
private Set<Method> Methods = new HashSet<Method>();
|
||||||
|
private Set<String> Dependencies = new HashSet<String>();
|
||||||
|
|
||||||
public boolean setMethod(Plugin method) {
|
public Methods() {
|
||||||
PluginManager manager = method.getServer().getPluginManager();
|
this.addMethod("iConomy", new com.nijikokun.register.payment.methods.iCo4());
|
||||||
|
this.addMethod("iConomy", new com.nijikokun.register.payment.methods.iCo5());
|
||||||
|
this.addMethod("BOSEconomy", new com.nijikokun.register.payment.methods.BOSE());
|
||||||
|
this.addMethod("Essentials", new com.nijikokun.register.payment.methods.EE17());
|
||||||
|
}
|
||||||
|
|
||||||
if (method != null && method.isEnabled()) {
|
public Set<String> getDependencies() {
|
||||||
Method plugin = MethodFactory.createMethod(method);
|
return Dependencies;
|
||||||
if (plugin != null) Method = plugin;
|
}
|
||||||
} else {
|
|
||||||
for(String name: MethodFactory.getDependencies()) {
|
|
||||||
if(hasMethod()) break;
|
|
||||||
|
|
||||||
method = manager.getPlugin(name);
|
public Method createMethod(Plugin plugin) {
|
||||||
if(method == null) continue;
|
for (Method method: Methods) {
|
||||||
if(!method.isEnabled()) manager.enablePlugin(method);
|
if (method.isCompatible(plugin)) {
|
||||||
if(!method.isEnabled()) continue;
|
method.setPlugin(plugin);
|
||||||
|
return method;
|
||||||
Method plugin = MethodFactory.createMethod(method);
|
|
||||||
if (plugin != null) Method = plugin;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void addMethod(String name, Method method) {
|
||||||
|
Dependencies.add(name);
|
||||||
|
Methods.add(method);
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean hasMethod() {
|
||||||
|
return (this.Method != null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean setMethod(Plugin method) {
|
||||||
|
if(hasMethod()) return true;
|
||||||
|
|
||||||
|
PluginManager manager = method.getServer().getPluginManager();
|
||||||
|
Plugin plugin = null;
|
||||||
|
|
||||||
|
for(String name: this.getDependencies()) {
|
||||||
|
if(hasMethod()) break;
|
||||||
|
if(method.getDescription().getName().equals(name)) plugin = method; else plugin = manager.getPlugin(name);
|
||||||
|
if(plugin == null) continue;
|
||||||
|
if(!plugin.isEnabled()) continue;
|
||||||
|
|
||||||
|
Method current = this.createMethod(plugin);
|
||||||
|
if (current != null) this.Method = current;
|
||||||
|
}
|
||||||
|
|
||||||
return hasMethod();
|
return hasMethod();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Method getMethod() {
|
||||||
|
return Method;
|
||||||
|
}
|
||||||
|
|
||||||
public boolean checkDisabled(Plugin method) {
|
public boolean checkDisabled(Plugin method) {
|
||||||
if(!hasMethod()) return true;
|
if(!hasMethod()) return true;
|
||||||
if (Method.isCompatible(method)) Method = null;
|
if (Method.isCompatible(method)) Method = null;
|
||||||
return (Method == null);
|
return (Method == null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean hasMethod() {
|
|
||||||
return (Method != null);
|
|
||||||
}
|
|
||||||
|
|
||||||
public Method getMethod() {
|
|
||||||
return Method;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -1,18 +1,12 @@
|
|||||||
package com.nijikokun.register.payment.methods;
|
package com.nijikokun.register.payment.methods;
|
||||||
|
|
||||||
import com.nijikokun.register.payment.Method;
|
import com.nijikokun.register.payment.Method;
|
||||||
import com.nijikokun.register.payment.MethodFactory;
|
|
||||||
import cosine.boseconomy.BOSEconomy;
|
import cosine.boseconomy.BOSEconomy;
|
||||||
import org.bukkit.plugin.Plugin;
|
import org.bukkit.plugin.Plugin;
|
||||||
|
|
||||||
public class BOSE implements Method {
|
public class BOSE implements Method {
|
||||||
private BOSEconomy BOSEconomy;
|
private BOSEconomy BOSEconomy;
|
||||||
|
|
||||||
static {
|
|
||||||
MethodFactory.addMethod("BOSEconomy", new BOSE());
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public BOSEconomy getPlugin() {
|
public BOSEconomy getPlugin() {
|
||||||
return this.BOSEconomy;
|
return this.BOSEconomy;
|
||||||
}
|
}
|
||||||
@ -74,7 +68,7 @@ public class BOSE implements Method {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public double balance() {
|
public double balance() {
|
||||||
return (double) this.BOSEconomy.getPlayerMoney(this.name);
|
return Double.valueOf(this.BOSEconomy.getPlayerMoney(this.name));
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean set(double amount) {
|
public boolean set(double amount) {
|
||||||
@ -84,7 +78,7 @@ public class BOSE implements Method {
|
|||||||
|
|
||||||
public boolean add(double amount) {
|
public boolean add(double amount) {
|
||||||
int IntAmount = (int)Math.ceil(amount);
|
int IntAmount = (int)Math.ceil(amount);
|
||||||
//int balance = (int)this.balance();
|
int balance = (int)this.balance();
|
||||||
return this.BOSEconomy.addPlayerMoney(this.name, IntAmount, false);
|
return this.BOSEconomy.addPlayerMoney(this.name, IntAmount, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -147,7 +141,7 @@ public class BOSE implements Method {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public double balance() {
|
public double balance() {
|
||||||
return (double) this.BOSEconomy.getBankMoney(name);
|
return Double.valueOf(this.BOSEconomy.getBankMoney(name));
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean set(double amount) {
|
public boolean set(double amount) {
|
||||||
|
@ -4,17 +4,14 @@ import com.earth2me.essentials.Essentials;
|
|||||||
import com.earth2me.essentials.api.Economy;
|
import com.earth2me.essentials.api.Economy;
|
||||||
import com.earth2me.essentials.api.NoLoanPermittedException;
|
import com.earth2me.essentials.api.NoLoanPermittedException;
|
||||||
import com.earth2me.essentials.api.UserDoesNotExistException;
|
import com.earth2me.essentials.api.UserDoesNotExistException;
|
||||||
|
|
||||||
import com.nijikokun.register.payment.Method;
|
import com.nijikokun.register.payment.Method;
|
||||||
import com.nijikokun.register.payment.MethodFactory;
|
|
||||||
import org.bukkit.plugin.Plugin;
|
import org.bukkit.plugin.Plugin;
|
||||||
|
|
||||||
public class EE17 implements Method {
|
public class EE17 implements Method {
|
||||||
private Essentials Essentials;
|
private Essentials Essentials;
|
||||||
|
|
||||||
static {
|
|
||||||
MethodFactory.addMethod("Essentials", new EE17());
|
|
||||||
}
|
|
||||||
|
|
||||||
public Essentials getPlugin() {
|
public Essentials getPlugin() {
|
||||||
return this.Essentials;
|
return this.Essentials;
|
||||||
}
|
}
|
||||||
@ -57,6 +54,8 @@ public class EE17 implements Method {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public boolean isCompatible(Plugin plugin) {
|
public boolean isCompatible(Plugin plugin) {
|
||||||
|
try { Class.forName("com.earth2me.essentials.api.Economy"); }
|
||||||
|
catch(Exception e) { return false; }
|
||||||
return plugin.getDescription().getName().equalsIgnoreCase("essentials") && plugin instanceof Essentials;
|
return plugin.getDescription().getName().equalsIgnoreCase("essentials") && plugin instanceof Essentials;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2,17 +2,14 @@ package com.nijikokun.register.payment.methods;
|
|||||||
|
|
||||||
import com.nijiko.coelho.iConomy.iConomy;
|
import com.nijiko.coelho.iConomy.iConomy;
|
||||||
import com.nijiko.coelho.iConomy.system.Account;
|
import com.nijiko.coelho.iConomy.system.Account;
|
||||||
|
|
||||||
import com.nijikokun.register.payment.Method;
|
import com.nijikokun.register.payment.Method;
|
||||||
import com.nijikokun.register.payment.MethodFactory;
|
|
||||||
import org.bukkit.plugin.Plugin;
|
import org.bukkit.plugin.Plugin;
|
||||||
|
|
||||||
public class iCo4 implements Method {
|
public class iCo4 implements Method {
|
||||||
private iConomy iConomy;
|
private iConomy iConomy;
|
||||||
|
|
||||||
static {
|
|
||||||
MethodFactory.addMethod("iConomy", new iCo4());
|
|
||||||
}
|
|
||||||
|
|
||||||
public iConomy getPlugin() {
|
public iConomy getPlugin() {
|
||||||
return this.iConomy;
|
return this.iConomy;
|
||||||
}
|
}
|
||||||
@ -54,7 +51,7 @@ public class iCo4 implements Method {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public boolean isCompatible(Plugin plugin) {
|
public boolean isCompatible(Plugin plugin) {
|
||||||
return plugin.getDescription().getName().equalsIgnoreCase("iconomy") && plugin instanceof iConomy;
|
return plugin.getDescription().getName().equalsIgnoreCase("iconomy") && !plugin.getClass().getName().equals("com.iConomy.iConomy") && plugin instanceof iConomy;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setPlugin(Plugin plugin) {
|
public void setPlugin(Plugin plugin) {
|
||||||
|
@ -5,17 +5,14 @@ import com.iConomy.system.Account;
|
|||||||
import com.iConomy.system.BankAccount;
|
import com.iConomy.system.BankAccount;
|
||||||
import com.iConomy.system.Holdings;
|
import com.iConomy.system.Holdings;
|
||||||
import com.iConomy.util.Constants;
|
import com.iConomy.util.Constants;
|
||||||
|
|
||||||
import com.nijikokun.register.payment.Method;
|
import com.nijikokun.register.payment.Method;
|
||||||
import com.nijikokun.register.payment.MethodFactory;
|
|
||||||
import org.bukkit.plugin.Plugin;
|
import org.bukkit.plugin.Plugin;
|
||||||
|
|
||||||
public class iCo5 implements Method {
|
public class iCo5 implements Method {
|
||||||
private iConomy iConomy;
|
private iConomy iConomy;
|
||||||
|
|
||||||
static {
|
|
||||||
MethodFactory.addMethod("iConomy", new iCo5());
|
|
||||||
}
|
|
||||||
|
|
||||||
public iConomy getPlugin() {
|
public iConomy getPlugin() {
|
||||||
return this.iConomy;
|
return this.iConomy;
|
||||||
}
|
}
|
||||||
@ -37,7 +34,7 @@ public class iCo5 implements Method {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public boolean hasBank(String bank) {
|
public boolean hasBank(String bank) {
|
||||||
return (hasBanks()) && this.iConomy.Banks.exists(bank);
|
return (!hasBanks()) ? false : this.iConomy.Banks.exists(bank);
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean hasAccount(String name) {
|
public boolean hasAccount(String name) {
|
||||||
@ -45,7 +42,7 @@ public class iCo5 implements Method {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public boolean hasBankAccount(String bank, String name) {
|
public boolean hasBankAccount(String bank, String name) {
|
||||||
return (!hasBank(bank)) && this.iConomy.getBank(name).hasAccount(name);
|
return (hasBank(bank)) ? false : this.iConomy.getBank(name).hasAccount(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
public MethodAccount getAccount(String name) {
|
public MethodAccount getAccount(String name) {
|
||||||
@ -57,7 +54,7 @@ public class iCo5 implements Method {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public boolean isCompatible(Plugin plugin) {
|
public boolean isCompatible(Plugin plugin) {
|
||||||
return plugin.getDescription().getName().equalsIgnoreCase("iconomy") && plugin instanceof iConomy;
|
return plugin.getDescription().getName().equalsIgnoreCase("iconomy") && plugin.getClass().getName().equals("com.iConomy.iConomy") && plugin instanceof iConomy;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setPlugin(Plugin plugin) {
|
public void setPlugin(Plugin plugin) {
|
||||||
|
Loading…
Reference in New Issue
Block a user