Support for iConomy 6 and other economy plugins added through Register support (with new conf.json setting "econRegisterEnabled", defaults to false); you will need to have the Register plugin on your server
This commit is contained in:
parent
2aa51a4781
commit
492d983464
BIN
lib/Register.jar
Normal file
BIN
lib/Register.jar
Normal file
Binary file not shown.
Binary file not shown.
@ -184,6 +184,7 @@ public class Conf {
|
||||
public static String capePeaceful = "https://github.com/MassiveCraft/Factions/raw/master/capes/peaceful.png";
|
||||
|
||||
// Economy settings
|
||||
public static boolean econRegisterEnabled = false;
|
||||
public static boolean econIConomyEnabled = false;
|
||||
public static boolean econEssentialsEcoEnabled = false;
|
||||
public static double econCostClaimWilderness = 30.0;
|
||||
|
@ -6,11 +6,14 @@ import org.bukkit.plugin.Plugin;
|
||||
import com.massivecraft.factions.listeners.FactionsServerListener;
|
||||
|
||||
import com.earth2me.essentials.api.Economy;
|
||||
import com.nijikokun.register.payment.Methods;
|
||||
import com.nijikokun.register.payment.Method.MethodAccount;
|
||||
import com.iConomy.*;
|
||||
import com.iConomy.system.*;
|
||||
|
||||
|
||||
public class Econ {
|
||||
private static boolean registerUse = false;
|
||||
private static boolean iConomyUse = false;
|
||||
private static boolean essEcoUse = false;
|
||||
|
||||
@ -24,6 +27,12 @@ public class Econ {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!registerHooked()) {
|
||||
Plugin plug = factions.getServer().getPluginManager().getPlugin("Register");
|
||||
if (plug != null && plug.getClass().getName().equals("com.nijikokun.register.Register") && plug.isEnabled()) {
|
||||
registerSet(true);
|
||||
}
|
||||
}
|
||||
if (!iConomyHooked()) {
|
||||
Plugin plug = factions.getServer().getPluginManager().getPlugin("iConomy");
|
||||
if (plug != null && plug.getClass().getName().equals("com.iConomy.iConomy") && plug.isEnabled()) {
|
||||
@ -38,9 +47,19 @@ public class Econ {
|
||||
}
|
||||
}
|
||||
|
||||
public static void registerSet(boolean enable) {
|
||||
registerUse = enable;
|
||||
if (enable) {
|
||||
Factions.log("Register hook available, "+(Conf.econRegisterEnabled ? "and interface is enabled" : "but disabled (\"econRegisterEnabled\": false)")+".");
|
||||
}
|
||||
else {
|
||||
Factions.log("Un-hooked from Register.");
|
||||
}
|
||||
}
|
||||
|
||||
public static void iConomySet(boolean enable) {
|
||||
iConomyUse = enable;
|
||||
if (enable) {
|
||||
if (enable && !registerUse) {
|
||||
Factions.log("iConomy hook available, "+(Conf.econIConomyEnabled ? "and interface is enabled" : "but disabled (\"econIConomyEnabled\": false)")+".");
|
||||
}
|
||||
else {
|
||||
@ -50,7 +69,7 @@ public class Econ {
|
||||
|
||||
public static void essentialsEcoSet(boolean enable) {
|
||||
essEcoUse = enable;
|
||||
if (enable) {
|
||||
if (enable && !registerUse) {
|
||||
Factions.log("EssentialsEco hook available, "+(Conf.econEssentialsEcoEnabled ? "and interface is enabled" : "but disabled (\"econEssentialsEcoEnabled\": false)")+".");
|
||||
}
|
||||
else {
|
||||
@ -58,6 +77,10 @@ public class Econ {
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean registerHooked() {
|
||||
return registerUse;
|
||||
}
|
||||
|
||||
public static boolean iConomyHooked() {
|
||||
return iConomyUse;
|
||||
}
|
||||
@ -66,9 +89,15 @@ public class Econ {
|
||||
return essEcoUse;
|
||||
}
|
||||
|
||||
public static boolean registerAvailable() {
|
||||
return Conf.econRegisterEnabled && registerUse && Methods.hasMethod();
|
||||
}
|
||||
|
||||
// If economy is enabled in conf.json, and we're successfully hooked into an economy plugin
|
||||
public static boolean enabled() {
|
||||
return (Conf.econIConomyEnabled && iConomyUse) || (Conf.econEssentialsEcoEnabled && essEcoUse);
|
||||
return (Conf.econRegisterEnabled && registerUse && Methods.hasMethod())
|
||||
|| (Conf.econIConomyEnabled && iConomyUse)
|
||||
|| (Conf.econEssentialsEcoEnabled && essEcoUse);
|
||||
}
|
||||
|
||||
// mainly for internal use, for a little less code repetition
|
||||
@ -84,11 +113,23 @@ public class Econ {
|
||||
Holdings holdings = account.getHoldings();
|
||||
return holdings;
|
||||
}
|
||||
public static MethodAccount getRegisterAccount(String playerName) {
|
||||
if (!enabled()) {
|
||||
return null;
|
||||
}
|
||||
if (!Methods.getMethod().hasAccount(playerName)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
MethodAccount account = Methods.getMethod().getAccount(playerName);
|
||||
return account;
|
||||
}
|
||||
|
||||
|
||||
// format money string based on server's set currency type, like "24 gold" or "$24.50"
|
||||
public static String moneyString(double amount) {
|
||||
return iConomyUse ? iConomy.format(amount) : Economy.format(amount);
|
||||
return registerAvailable() ? Methods.getMethod().format(amount)
|
||||
: (iConomyUse ? iConomy.format(amount) : Economy.format(amount));
|
||||
}
|
||||
|
||||
// whether a player can afford specified amount
|
||||
@ -98,7 +139,15 @@ public class Econ {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (iConomyUse) {
|
||||
if (registerAvailable()) {
|
||||
MethodAccount holdings = getRegisterAccount(playerName);
|
||||
if (holdings == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return holdings.hasEnough(amount);
|
||||
}
|
||||
else if (iConomyUse) {
|
||||
Holdings holdings = getIconomyHoldings(playerName);
|
||||
if (holdings == null) {
|
||||
return false;
|
||||
@ -122,7 +171,15 @@ public class Econ {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (iConomyUse) {
|
||||
if (registerAvailable()) {
|
||||
MethodAccount holdings = getRegisterAccount(playerName);
|
||||
if (holdings == null || !holdings.hasEnough(amount)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return holdings.subtract(amount);
|
||||
}
|
||||
else if (iConomyUse) {
|
||||
Holdings holdings = getIconomyHoldings(playerName);
|
||||
if (holdings == null || !holdings.hasEnough(amount)) {
|
||||
return false;
|
||||
@ -151,7 +208,15 @@ public class Econ {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (iConomyUse) {
|
||||
if (registerAvailable()) {
|
||||
MethodAccount holdings = getRegisterAccount(playerName);
|
||||
if (holdings == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return holdings.add(amount);
|
||||
}
|
||||
else if (iConomyUse) {
|
||||
Holdings holdings = getIconomyHoldings(playerName);
|
||||
if (holdings == null) {
|
||||
return false;
|
||||
|
@ -10,12 +10,15 @@ import com.massivecraft.factions.SpoutFeatures;
|
||||
|
||||
|
||||
public class FactionsServerListener extends ServerListener {
|
||||
@Override
|
||||
public void onPluginDisable(PluginDisableEvent event) {
|
||||
@Override
|
||||
public void onPluginDisable(PluginDisableEvent event) {
|
||||
String name = event.getPlugin().getDescription().getName();
|
||||
if (Econ.iConomyHooked() && name.equals("iConomy")) {
|
||||
if (Econ.registerHooked() && name.equals("Register")) {
|
||||
Econ.registerSet(false);
|
||||
}
|
||||
else if (Econ.iConomyHooked() && name.equals("iConomy")) {
|
||||
Econ.iConomySet(false);
|
||||
}
|
||||
}
|
||||
else if (Econ.essentialsEcoHooked() && name.equals("Essentials")) {
|
||||
Econ.essentialsEcoSet(false);
|
||||
}
|
||||
@ -24,18 +27,21 @@ public class FactionsServerListener extends ServerListener {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPluginEnable(PluginEnableEvent event) {
|
||||
@Override
|
||||
public void onPluginEnable(PluginEnableEvent event) {
|
||||
Plugin plug = event.getPlugin();
|
||||
String name = plug.getDescription().getName();
|
||||
if (!Econ.iConomyHooked() && name.equals("iConomy") && plug.getClass().getName().equals("com.iConomy.iConomy")) {
|
||||
if (!Econ.registerHooked() && name.equals("Register") && plug.getClass().getName().equals("com.nijikokun.register.Register")) {
|
||||
Econ.registerSet(true);
|
||||
}
|
||||
else if (!Econ.iConomyHooked() && name.equals("iConomy") && plug.getClass().getName().equals("com.iConomy.iConomy")) {
|
||||
Econ.iConomySet(true);
|
||||
}
|
||||
else if (!Econ.essentialsEcoHooked() && name.equals("Essentials")) {
|
||||
Econ.essentialsEcoSet(true);
|
||||
}
|
||||
}
|
||||
else if (name.equals("Spout")) {
|
||||
SpoutFeatures.setAvailable(true, plug.getDescription().getFullName());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -12,6 +12,7 @@ softdepend:
|
||||
- ChatManager
|
||||
- AuthMe
|
||||
- iConomy
|
||||
- Register
|
||||
- Spout
|
||||
- WorldEdit
|
||||
- WorldGuard
|
||||
|
Loading…
Reference in New Issue
Block a user