Economy integration now works for EssentialsEco as well
This commit is contained in:
parent
100a1ffb1e
commit
e6ac1c0f98
BIN
lib/Essentials.jar
Normal file
BIN
lib/Essentials.jar
Normal file
Binary file not shown.
@ -149,6 +149,7 @@ public class Conf {
|
||||
|
||||
// Economy settings
|
||||
public static boolean econIConomyEnabled = false;
|
||||
public static boolean econEssentialsEcoEnabled = false;
|
||||
public static double econCostClaimWilderness = 30.0;
|
||||
public static double econCostClaimFromFactionBonus = 30.0;
|
||||
public static double econClaimAdditionalMultiplier = 0.5;
|
||||
|
@ -4,29 +4,51 @@ import org.bukkit.event.Event;
|
||||
|
||||
import com.massivecraft.factions.listeners.FactionsServerListener;
|
||||
|
||||
import com.earth2me.essentials.api.Economy;
|
||||
import com.iConomy.*;
|
||||
import com.iConomy.system.*;
|
||||
|
||||
|
||||
public class Econ {
|
||||
private static iConomy iConomyPlugin;
|
||||
private static boolean iConomyUse = false;
|
||||
private static boolean essEcoUse = false;
|
||||
|
||||
public static void monitorPlugins() {
|
||||
Factions.instance.getServer().getPluginManager().registerEvent(Event.Type.PLUGIN_ENABLE, new FactionsServerListener(), Event.Priority.Monitor, Factions.instance);
|
||||
Factions.instance.getServer().getPluginManager().registerEvent(Event.Type.PLUGIN_DISABLE, new FactionsServerListener(), Event.Priority.Monitor, Factions.instance);
|
||||
}
|
||||
|
||||
public static void iConomySet(iConomy instance) {
|
||||
iConomyPlugin = instance;
|
||||
public static void iConomySet(boolean enable) {
|
||||
iConomyUse = enable;
|
||||
if (enable) {
|
||||
Factions.log("Hooked into iConomy, "+(Conf.econIConomyEnabled ? "and interface is enabled" : "but interface is currently disabled (\"econIConomyEnabled\": false)")+".");
|
||||
}
|
||||
else {
|
||||
Factions.log("Un-hooked from iConomy.");
|
||||
}
|
||||
}
|
||||
|
||||
public static void essentialsEcoSet(boolean enable) {
|
||||
essEcoUse = enable;
|
||||
if (enable) {
|
||||
Factions.log("Hooked into EssentialsEco, "+(Conf.econEssentialsEcoEnabled ? "and interface is enabled" : "but interface is currently disabled (\"econEssentialsEcoEnabled\": false)")+".");
|
||||
}
|
||||
else {
|
||||
Factions.log("Un-hooked from EssentialsEco.");
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean iConomyHooked() {
|
||||
return iConomyPlugin != null;
|
||||
return iConomyUse;
|
||||
}
|
||||
|
||||
public static boolean essentialsEcoHooked() {
|
||||
return essEcoUse;
|
||||
}
|
||||
|
||||
// If economy is enabled in conf.json, and we're successfully hooked into an economy plugin
|
||||
public static boolean enabled() {
|
||||
return Conf.econIConomyEnabled && iConomyPlugin != null;
|
||||
return (Conf.econIConomyEnabled && iConomyUse) || (Conf.econEssentialsEcoEnabled && essEcoUse);
|
||||
}
|
||||
|
||||
// mainly for internal use, for a little less code repetition
|
||||
@ -46,7 +68,7 @@ public class Econ {
|
||||
|
||||
// format money string based on server's set currency type, like "24 gold" or "$24.50"
|
||||
public static String moneyString(double amount) {
|
||||
return iConomy.format(amount);
|
||||
return iConomyUse ? iConomy.format(amount) : Economy.format(amount);
|
||||
}
|
||||
|
||||
// whether a player can afford specified amount
|
||||
@ -56,6 +78,7 @@ public class Econ {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (iConomyUse) {
|
||||
Holdings holdings = getIconomyHoldings(playerName);
|
||||
if (holdings == null) {
|
||||
return false;
|
||||
@ -63,6 +86,15 @@ public class Econ {
|
||||
|
||||
return holdings.hasEnough(amount);
|
||||
}
|
||||
else {
|
||||
try {
|
||||
return Economy.hasEnough(playerName, amount);
|
||||
}
|
||||
catch (Exception ex) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// deduct money from their account; returns true if successful
|
||||
public static boolean deductMoney(String playerName, double amount) {
|
||||
@ -70,6 +102,7 @@ public class Econ {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (iConomyUse) {
|
||||
Holdings holdings = getIconomyHoldings(playerName);
|
||||
if (holdings == null || !holdings.hasEnough(amount)) {
|
||||
return false;
|
||||
@ -78,6 +111,19 @@ public class Econ {
|
||||
holdings.subtract(amount);
|
||||
return true;
|
||||
}
|
||||
else {
|
||||
try {
|
||||
if (!Economy.hasEnough(playerName, amount)) {
|
||||
return false;
|
||||
}
|
||||
Economy.subtract(playerName, amount);
|
||||
return true;
|
||||
}
|
||||
catch (Exception ex) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// add money to their account; returns true if successful
|
||||
public static boolean addMoney(String playerName, double amount) {
|
||||
@ -85,6 +131,7 @@ public class Econ {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (iConomyUse) {
|
||||
Holdings holdings = getIconomyHoldings(playerName);
|
||||
if (holdings == null) {
|
||||
return false;
|
||||
@ -93,6 +140,16 @@ public class Econ {
|
||||
holdings.add(amount);
|
||||
return true;
|
||||
}
|
||||
else {
|
||||
try {
|
||||
Economy.add(playerName, amount);
|
||||
return true;
|
||||
}
|
||||
catch (Exception ex) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// calculate the cost for claiming land
|
||||
|
@ -146,6 +146,7 @@ public class Factions extends JavaPlugin {
|
||||
|
||||
setupPermissions();
|
||||
integrateEssentialsChat();
|
||||
setupEcon();
|
||||
|
||||
Econ.monitorPlugins();
|
||||
|
||||
@ -213,6 +214,25 @@ public class Factions extends JavaPlugin {
|
||||
}
|
||||
}
|
||||
|
||||
private void setupEcon() {
|
||||
if (Econ.enabled()) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!Econ.iConomyHooked()) {
|
||||
Plugin plug = this.getServer().getPluginManager().getPlugin("iConomy");
|
||||
if (plug != null && plug.getClass().getName().equals("com.iConomy.iConomy")) {
|
||||
Econ.iConomySet(true);
|
||||
}
|
||||
}
|
||||
if (!Econ.essentialsEcoHooked()) {
|
||||
Plugin plug = this.getServer().getPluginManager().getPlugin("Essentials");
|
||||
if (plug != null) {
|
||||
Econ.essentialsEcoSet(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void integrateEssentialsChat() {
|
||||
if (essChat != null) {
|
||||
return;
|
||||
|
@ -5,35 +5,30 @@ import org.bukkit.event.server.ServerListener;
|
||||
import org.bukkit.event.server.PluginDisableEvent;
|
||||
import org.bukkit.event.server.PluginEnableEvent;
|
||||
|
||||
import com.massivecraft.factions.Conf;
|
||||
import com.massivecraft.factions.Econ;
|
||||
import com.massivecraft.factions.Factions;
|
||||
|
||||
import com.iConomy.*;
|
||||
|
||||
|
||||
public class FactionsServerListener extends ServerListener {
|
||||
@Override
|
||||
public void onPluginDisable(PluginDisableEvent event) {
|
||||
if (Econ.iConomyHooked()) {
|
||||
if (event.getPlugin().getDescription().getName().equals("iConomy")) {
|
||||
Econ.iConomySet(null);
|
||||
Factions.log("Un-hooked from iConomy.");
|
||||
String name = event.getPlugin().getDescription().getName();
|
||||
if (Econ.iConomyHooked() && name.equals("iConomy")) {
|
||||
Econ.iConomySet(false);
|
||||
}
|
||||
if (Econ.essentialsEcoHooked() && name.equals("Essentials")) {
|
||||
Econ.essentialsEcoSet(false);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPluginEnable(PluginEnableEvent event) {
|
||||
if (!Econ.iConomyHooked()) {
|
||||
Plugin iConomy = Factions.instance.getServer().getPluginManager().getPlugin("iConomy");
|
||||
|
||||
if (iConomy != null) {
|
||||
if (iConomy.isEnabled() && iConomy.getClass().getName().equals("com.iConomy.iConomy")) {
|
||||
Econ.iConomySet((iConomy)iConomy);
|
||||
Factions.log("Hooked into iConomy, "+(Conf.econIConomyEnabled ? "and interface is enabled" : "but interface is currently disabled (\"econIConomyEnabled\": false)")+".");
|
||||
}
|
||||
Plugin plug = event.getPlugin();
|
||||
String name = plug.getDescription().getName();
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user