In progress: Using MassiveCraftCore and Allman indentation style and minor refactoring.
This commit is contained in:
@@ -12,7 +12,7 @@ import com.nijikokun.register.payment.Method.MethodAccount;
|
||||
import com.iConomy.*;
|
||||
import com.iConomy.system.*;
|
||||
import com.massivecraft.factions.Conf;
|
||||
import com.massivecraft.factions.Factions;
|
||||
import com.massivecraft.factions.P;
|
||||
|
||||
|
||||
public class Econ {
|
||||
@@ -21,11 +21,11 @@ public class Econ {
|
||||
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);
|
||||
P.p.getServer().getPluginManager().registerEvent(Event.Type.PLUGIN_ENABLE, new FactionsServerListener(P.p), Event.Priority.Monitor, P.p);
|
||||
P.p.getServer().getPluginManager().registerEvent(Event.Type.PLUGIN_DISABLE, new FactionsServerListener(P.p), Event.Priority.Monitor, P.p);
|
||||
}
|
||||
|
||||
public static void setup(Factions factions) {
|
||||
public static void setup(P factions) {
|
||||
if (enabled()) {
|
||||
return;
|
||||
}
|
||||
@@ -50,80 +50,96 @@ public class Econ {
|
||||
}
|
||||
}
|
||||
|
||||
public static void registerSet(boolean enable) {
|
||||
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)")+".");
|
||||
P.p.log("Register hook available, "+(Conf.econRegisterEnabled ? "and interface is enabled" : "but disabled (\"econRegisterEnabled\": false)")+".");
|
||||
}
|
||||
else {
|
||||
Factions.log("Un-hooked from Register.");
|
||||
P.p.log("Un-hooked from Register.");
|
||||
}
|
||||
FCommandHelp.updateHelp();
|
||||
}
|
||||
|
||||
public static void iConomySet(boolean enable) {
|
||||
public static void iConomySet(boolean enable)
|
||||
{
|
||||
iConomyUse = enable;
|
||||
if (enable && !registerUse) {
|
||||
Factions.log("iConomy hook available, "+(Conf.econIConomyEnabled ? "and interface is enabled" : "but disabled (\"econIConomyEnabled\": false)")+".");
|
||||
P.p.log("iConomy hook available, "+(Conf.econIConomyEnabled ? "and interface is enabled" : "but disabled (\"econIConomyEnabled\": false)")+".");
|
||||
}
|
||||
else {
|
||||
Factions.log("Un-hooked from iConomy.");
|
||||
P.p.log("Un-hooked from iConomy.");
|
||||
}
|
||||
FCommandHelp.updateHelp();
|
||||
}
|
||||
|
||||
public static void essentialsEcoSet(boolean enable) {
|
||||
public static void essentialsEcoSet(boolean enable)
|
||||
{
|
||||
essEcoUse = enable;
|
||||
if (enable && !registerUse) {
|
||||
Factions.log("EssentialsEco hook available, "+(Conf.econEssentialsEcoEnabled ? "and interface is enabled" : "but disabled (\"econEssentialsEcoEnabled\": false)")+".");
|
||||
if (enable && !registerUse)
|
||||
{
|
||||
P.p.log("EssentialsEco hook available, "+(Conf.econEssentialsEcoEnabled ? "and interface is enabled" : "but disabled (\"econEssentialsEcoEnabled\": false)")+".");
|
||||
}
|
||||
else {
|
||||
Factions.log("Un-hooked from EssentialsEco.");
|
||||
else
|
||||
{
|
||||
P.p.log("Un-hooked from EssentialsEco.");
|
||||
}
|
||||
FCommandHelp.updateHelp();
|
||||
}
|
||||
|
||||
public static boolean registerHooked() {
|
||||
public static boolean registerHooked()
|
||||
{
|
||||
return registerUse;
|
||||
}
|
||||
|
||||
public static boolean iConomyHooked() {
|
||||
public static boolean iConomyHooked()
|
||||
{
|
||||
return iConomyUse;
|
||||
}
|
||||
|
||||
public static boolean essentialsEcoHooked() {
|
||||
public static boolean essentialsEcoHooked()
|
||||
{
|
||||
return essEcoUse;
|
||||
}
|
||||
|
||||
public static boolean registerAvailable() {
|
||||
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.econRegisterEnabled && registerUse && Methods.hasMethod())
|
||||
public static boolean enabled()
|
||||
{
|
||||
return (Conf.econRegisterEnabled && registerUse && Methods.hasMethod())
|
||||
|| (Conf.econIConomyEnabled && iConomyUse)
|
||||
|| (Conf.econEssentialsEcoEnabled && essEcoUse);
|
||||
}
|
||||
|
||||
// mainly for internal use, for a little less code repetition
|
||||
public static Holdings getIconomyHoldings(String playerName) {
|
||||
if (!enabled()) {
|
||||
public static Holdings getIconomyHoldings(String playerName)
|
||||
{
|
||||
if ( ! enabled())
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
Account account = iConomy.getAccount(playerName);
|
||||
if (account == null) {
|
||||
if (account == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
Holdings holdings = account.getHoldings();
|
||||
return holdings;
|
||||
}
|
||||
public static MethodAccount getRegisterAccount(String playerName) {
|
||||
if (!enabled()) {
|
||||
public static MethodAccount getRegisterAccount(String playerName)
|
||||
{
|
||||
if (!enabled())
|
||||
{
|
||||
return null;
|
||||
}
|
||||
if (!Methods.getMethod().hasAccount(playerName)) {
|
||||
if (!Methods.getMethod().hasAccount(playerName))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -133,7 +149,8 @@ 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) {
|
||||
public static String moneyString(double amount)
|
||||
{
|
||||
return registerAvailable() ? Methods.getMethod().format(amount)
|
||||
: (iConomyUse ? iConomy.format(amount) : Economy.format(amount));
|
||||
}
|
||||
@@ -141,102 +158,129 @@ public class Econ {
|
||||
// whether a player can afford specified amount
|
||||
public static boolean canAfford(String playerName, double amount) {
|
||||
// if Economy support is not enabled, they can certainly afford to pay nothing
|
||||
if (!enabled()) {
|
||||
if (!enabled())
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
if (registerAvailable()) {
|
||||
if (registerAvailable())
|
||||
{
|
||||
MethodAccount holdings = getRegisterAccount(playerName);
|
||||
if (holdings == null) {
|
||||
if (holdings == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return holdings.hasEnough(amount);
|
||||
}
|
||||
else if (iConomyUse) {
|
||||
else if (iConomyUse)
|
||||
{
|
||||
Holdings holdings = getIconomyHoldings(playerName);
|
||||
if (holdings == null) {
|
||||
if (holdings == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return holdings.hasEnough(amount);
|
||||
}
|
||||
else {
|
||||
try {
|
||||
else
|
||||
{
|
||||
try
|
||||
{
|
||||
return Economy.hasEnough(playerName, amount);
|
||||
}
|
||||
catch (Exception ex) {
|
||||
catch (Exception ex)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// deduct money from their account; returns true if successful
|
||||
public static boolean deductMoney(String playerName, double amount) {
|
||||
if (!enabled()) {
|
||||
public static boolean deductMoney(String playerName, double amount)
|
||||
{
|
||||
if (!enabled())
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
if (registerAvailable()) {
|
||||
if (registerAvailable())
|
||||
{
|
||||
MethodAccount holdings = getRegisterAccount(playerName);
|
||||
if (holdings == null || !holdings.hasEnough(amount)) {
|
||||
if (holdings == null || !holdings.hasEnough(amount))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return holdings.subtract(amount);
|
||||
}
|
||||
else if (iConomyUse) {
|
||||
else if (iConomyUse)
|
||||
{
|
||||
Holdings holdings = getIconomyHoldings(playerName);
|
||||
if (holdings == null || !holdings.hasEnough(amount)) {
|
||||
if (holdings == null || !holdings.hasEnough(amount))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
holdings.subtract(amount);
|
||||
return true;
|
||||
}
|
||||
else {
|
||||
try {
|
||||
if (!Economy.hasEnough(playerName, amount)) {
|
||||
else
|
||||
{
|
||||
try
|
||||
{
|
||||
if (!Economy.hasEnough(playerName, amount))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
Economy.subtract(playerName, amount);
|
||||
return true;
|
||||
}
|
||||
catch (Exception ex) {
|
||||
catch (Exception ex)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// add money to their account; returns true if successful
|
||||
public static boolean addMoney(String playerName, double amount) {
|
||||
if (!enabled()) {
|
||||
public static boolean addMoney(String playerName, double amount)
|
||||
{
|
||||
if (!enabled())
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
if (registerAvailable()) {
|
||||
if (registerAvailable())
|
||||
{
|
||||
MethodAccount holdings = getRegisterAccount(playerName);
|
||||
if (holdings == null) {
|
||||
if (holdings == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return holdings.add(amount);
|
||||
}
|
||||
else if (iConomyUse) {
|
||||
else if (iConomyUse)
|
||||
{
|
||||
Holdings holdings = getIconomyHoldings(playerName);
|
||||
if (holdings == null) {
|
||||
if (holdings == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
holdings.add(amount);
|
||||
return true;
|
||||
}
|
||||
else {
|
||||
try {
|
||||
else
|
||||
{
|
||||
try
|
||||
{
|
||||
Economy.add(playerName, amount);
|
||||
return true;
|
||||
}
|
||||
catch (Exception ex) {
|
||||
catch (Exception ex)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -244,8 +288,10 @@ public class Econ {
|
||||
|
||||
|
||||
// calculate the cost for claiming land
|
||||
public static double calculateClaimCost(int ownedLand, boolean takingFromAnotherFaction) {
|
||||
if (!enabled()) {
|
||||
public static double calculateClaimCost(int ownedLand, boolean takingFromAnotherFaction)
|
||||
{
|
||||
if (!enabled())
|
||||
{
|
||||
return 0.0;
|
||||
}
|
||||
|
||||
@@ -256,12 +302,14 @@ public class Econ {
|
||||
}
|
||||
|
||||
// calculate refund amount for unclaiming land
|
||||
public static double calculateClaimRefund(int ownedLand) {
|
||||
public static double calculateClaimRefund(int ownedLand)
|
||||
{
|
||||
return calculateClaimCost(ownedLand - 1, false) * Conf.econClaimRefundMultiplier;
|
||||
}
|
||||
|
||||
// calculate value of all owned land
|
||||
public static double calculateTotalLandValue(int ownedLand) {
|
||||
public static double calculateTotalLandValue(int ownedLand)
|
||||
{
|
||||
double amount = 0;
|
||||
for (int x = 0; x < ownedLand; x++) {
|
||||
amount += calculateClaimCost(x, false);
|
||||
@@ -270,7 +318,8 @@ public class Econ {
|
||||
}
|
||||
|
||||
// calculate refund amount for all owned land
|
||||
public static double calculateTotalLandRefund(int ownedLand) {
|
||||
public static double calculateTotalLandRefund(int ownedLand)
|
||||
{
|
||||
return calculateTotalLandValue(ownedLand) * Conf.econClaimRefundMultiplier;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user