diff --git a/lib/Register.jar b/lib/Register.jar deleted file mode 100644 index de3a0e08..00000000 Binary files a/lib/Register.jar and /dev/null differ diff --git a/lib/Vault.jar b/lib/Vault.jar new file mode 100644 index 00000000..4a452b0f Binary files /dev/null and b/lib/Vault.jar differ diff --git a/plugin.yml b/plugin.yml index cc85a15a..987119a8 100644 --- a/plugin.yml +++ b/plugin.yml @@ -2,7 +2,7 @@ name: Factions version: 1.7_dev main: com.massivecraft.factions.P authors: [Olof Larsson, Brett Flannigan] -softdepend: [PermissionsEx, Permissions, Essentials, EssentialsChat, HeroChat, iChat, LocalAreaChat, LWC, nChat, ChatManager, CAPI, AuthMe, Register, Spout, WorldEdit, WorldGuard] +softdepend: [PermissionsEx, Permissions, Essentials, EssentialsChat, HeroChat, iChat, LocalAreaChat, LWC, nChat, ChatManager, CAPI, AuthMe, Vault, Spout, WorldEdit, WorldGuard] commands: factions: description: Reference command for Factions. diff --git a/src/com/massivecraft/factions/FPlayer.java b/src/com/massivecraft/factions/FPlayer.java index 39f3ce22..1589e9b2 100644 --- a/src/com/massivecraft/factions/FPlayer.java +++ b/src/com/massivecraft/factions/FPlayer.java @@ -19,7 +19,6 @@ import com.massivecraft.factions.struct.FPerm; import com.massivecraft.factions.struct.Rel; import com.massivecraft.factions.util.RelationUtil; import com.massivecraft.factions.zcore.persist.PlayerEntity; -import com.nijikokun.register.payment.Method.MethodAccount; /** @@ -109,11 +108,7 @@ public class FPlayer extends PlayerEntity implements EconomyParticipator public boolean isSpyingChat() { return spyingChat; } // FIELD: account - public MethodAccount getAccount() - { - if ( ! Econ.shouldBeUsed()) return null; - return Econ.getMethod().getAccount(this.getId()); - } + public String getAccountId() { return this.getId(); } // -------------------------------------------- // // Construct @@ -507,7 +502,7 @@ public class FPlayer extends PlayerEntity implements EconomyParticipator { // Transfer all money if (Econ.shouldBeUsed()) - Econ.transferMoney(this, myFaction, this, myFaction.getAccount().balance()); + Econ.transferMoney(this, myFaction, this, Econ.getBalance(myFaction.getAccountId())); } if (myFaction.isNormal()) diff --git a/src/com/massivecraft/factions/Faction.java b/src/com/massivecraft/factions/Faction.java index 72e590c5..84c1cb4f 100644 --- a/src/com/massivecraft/factions/Faction.java +++ b/src/com/massivecraft/factions/Faction.java @@ -15,7 +15,6 @@ import com.massivecraft.factions.struct.FPerm; import com.massivecraft.factions.struct.Rel; import com.massivecraft.factions.util.*; import com.massivecraft.factions.zcore.persist.Entity; -import com.nijikokun.register.payment.Method.MethodAccount; public class Faction extends Entity implements EconomyParticipator @@ -85,26 +84,17 @@ public class Faction extends Entity implements EconomyParticipator // FIELD: account (fake field) // Bank functions public double money; - public String getAccountId() { return "faction-"+this.getId(); } - public MethodAccount getAccount() + public String getAccountId() { - String aid = this.getAccountId(); + String aid = "faction-"+this.getId(); // We need to override the default money given to players. - if ( ! Econ.getMethod().hasAccount(aid)) - { - if ( ! Econ.getMethod().createAccount(aid)) - { - P.p.log(Level.SEVERE, "Error creating faction bank account through Register: "+aid); -// return null; - } - MethodAccount acc = Econ.getMethod().getAccount(aid); - acc.set(0); - } - - return Econ.getMethod().getAccount(aid); + if ( ! Econ.hasAccount(aid)) + Econ.setBalance(aid, 0); + + return aid; } - + // FIELDS: Flag management // TODO: This will save... defaults if they where changed to... private Map flagOverrides; // Contains the modifications to the default values @@ -543,7 +533,7 @@ public class Faction extends Entity implements EconomyParticipator { if (Econ.shouldBeUsed()) { - Econ.getMethod().getAccount(getAccountId()).remove(); + Econ.setBalance(getAccountId(), 0); } this.getAccountId(); diff --git a/src/com/massivecraft/factions/cmd/CmdDisband.java b/src/com/massivecraft/factions/cmd/CmdDisband.java index eeddf0b0..4eeb8503 100644 --- a/src/com/massivecraft/factions/cmd/CmdDisband.java +++ b/src/com/massivecraft/factions/cmd/CmdDisband.java @@ -64,9 +64,8 @@ public class CmdDisband extends FCommand if (Econ.shouldBeUsed()) { //Give all the faction's money to the disbander - double amount = faction.getAccount().balance(); - fme.getAccount().add(amount); - faction.getAccount().remove(); + double amount = Econ.getBalance(faction.getAccountId()); + Econ.transferMoney(fme, faction, fme, amount, false); if (amount > 0.0) { diff --git a/src/com/massivecraft/factions/cmd/CmdMoneyDeposit.java b/src/com/massivecraft/factions/cmd/CmdMoneyDeposit.java index 3c5a8589..fa8626c6 100644 --- a/src/com/massivecraft/factions/cmd/CmdMoneyDeposit.java +++ b/src/com/massivecraft/factions/cmd/CmdMoneyDeposit.java @@ -36,10 +36,10 @@ public class CmdMoneyDeposit extends FCommand double amount = this.argAsDouble(0, 0d); EconomyParticipator faction = this.argAsFaction(1, myFaction); if (faction == null) return; - Econ.transferMoney(fme, fme, faction, amount); + boolean success = Econ.transferMoney(fme, fme, faction, amount); - if (Conf.logMoneyTransactions) - P.p.log(ChatColor.stripColor(P.p.txt.parse("%s deposited %s from the faction bank: %s", fme.getName(), Econ.moneyString(amount), faction.describeTo(null)))); + if (success && Conf.logMoneyTransactions) + P.p.log(ChatColor.stripColor(P.p.txt.parse("%s deposited %s in the faction bank: %s", fme.getName(), Econ.moneyString(amount), faction.describeTo(null)))); } } diff --git a/src/com/massivecraft/factions/cmd/CmdMoneyTransferFf.java b/src/com/massivecraft/factions/cmd/CmdMoneyTransferFf.java index 87f8d9ac..209f9052 100644 --- a/src/com/massivecraft/factions/cmd/CmdMoneyTransferFf.java +++ b/src/com/massivecraft/factions/cmd/CmdMoneyTransferFf.java @@ -39,9 +39,9 @@ public class CmdMoneyTransferFf extends FCommand EconomyParticipator to = this.argAsFaction(2); if (to == null) return; - Econ.transferMoney(fme, from, to, amount); + boolean success = Econ.transferMoney(fme, from, to, amount); - if (Conf.logMoneyTransactions) + if (success && Conf.logMoneyTransactions) P.p.log(ChatColor.stripColor(P.p.txt.parse("%s transferred %s from the faction \"%s\" to the faction \"%s\"", fme.getName(), Econ.moneyString(amount), from.describeTo(null), to.describeTo(null)))); } } diff --git a/src/com/massivecraft/factions/cmd/CmdMoneyTransferFp.java b/src/com/massivecraft/factions/cmd/CmdMoneyTransferFp.java index 05d3dd01..9b30a752 100644 --- a/src/com/massivecraft/factions/cmd/CmdMoneyTransferFp.java +++ b/src/com/massivecraft/factions/cmd/CmdMoneyTransferFp.java @@ -39,9 +39,9 @@ public class CmdMoneyTransferFp extends FCommand EconomyParticipator to = this.argAsBestFPlayerMatch(2); if (to == null) return; - Econ.transferMoney(fme, from, to, amount); + boolean success = Econ.transferMoney(fme, from, to, amount); - if (Conf.logMoneyTransactions) + if (success && Conf.logMoneyTransactions) P.p.log(ChatColor.stripColor(P.p.txt.parse("%s transferred %s from the faction \"%s\" to the player \"%s\"", fme.getName(), Econ.moneyString(amount), from.describeTo(null), to.describeTo(null)))); } } diff --git a/src/com/massivecraft/factions/cmd/CmdMoneyTransferPf.java b/src/com/massivecraft/factions/cmd/CmdMoneyTransferPf.java index 6c50eb95..fadb6fd1 100644 --- a/src/com/massivecraft/factions/cmd/CmdMoneyTransferPf.java +++ b/src/com/massivecraft/factions/cmd/CmdMoneyTransferPf.java @@ -39,9 +39,9 @@ public class CmdMoneyTransferPf extends FCommand EconomyParticipator to = this.argAsFaction(2); if (to == null) return; - Econ.transferMoney(fme, from, to, amount); + boolean success = Econ.transferMoney(fme, from, to, amount); - if (Conf.logMoneyTransactions) + if (success && Conf.logMoneyTransactions) P.p.log(ChatColor.stripColor(P.p.txt.parse("%s transferred %s from the player \"%s\" to the faction \"%s\"", fme.getName(), Econ.moneyString(amount), from.describeTo(null), to.describeTo(null)))); } } diff --git a/src/com/massivecraft/factions/cmd/CmdMoneyWithdraw.java b/src/com/massivecraft/factions/cmd/CmdMoneyWithdraw.java index cc02d62b..6c1b094c 100644 --- a/src/com/massivecraft/factions/cmd/CmdMoneyWithdraw.java +++ b/src/com/massivecraft/factions/cmd/CmdMoneyWithdraw.java @@ -34,9 +34,9 @@ public class CmdMoneyWithdraw extends FCommand double amount = this.argAsDouble(0, 0d); EconomyParticipator faction = this.argAsFaction(1, myFaction); if (faction == null) return; - Econ.transferMoney(fme, faction, fme, amount); + boolean success = Econ.transferMoney(fme, faction, fme, amount); - if (Conf.logMoneyTransactions) + if (success && Conf.logMoneyTransactions) P.p.log(ChatColor.stripColor(P.p.txt.parse("%s withdrew %s from the faction bank: %s", fme.getName(), Econ.moneyString(amount), faction.describeTo(null)))); } } diff --git a/src/com/massivecraft/factions/cmd/CmdShow.java b/src/com/massivecraft/factions/cmd/CmdShow.java index 4caeb6e1..3c7c60e7 100644 --- a/src/com/massivecraft/factions/cmd/CmdShow.java +++ b/src/com/massivecraft/factions/cmd/CmdShow.java @@ -83,7 +83,7 @@ public class CmdShow extends FCommand //Show bank contents if(Conf.bankEnabled) { - msg("Bank contains: "+Econ.moneyString(faction.getAccount().balance())); + msg("Bank contains: "+Econ.moneyString(Econ.getBalance(faction.getAccountId()))); } } diff --git a/src/com/massivecraft/factions/iface/EconomyParticipator.java b/src/com/massivecraft/factions/iface/EconomyParticipator.java index 07fa39d4..2a6a86d0 100644 --- a/src/com/massivecraft/factions/iface/EconomyParticipator.java +++ b/src/com/massivecraft/factions/iface/EconomyParticipator.java @@ -1,10 +1,9 @@ package com.massivecraft.factions.iface; -import com.nijikokun.register.payment.Method.MethodAccount; public interface EconomyParticipator extends RelationParticipator { - public MethodAccount getAccount(); + public String getAccountId(); public void msg(String str, Object... args); } \ No newline at end of file diff --git a/src/com/massivecraft/factions/integration/Econ.java b/src/com/massivecraft/factions/integration/Econ.java index b04557ef..cff3919b 100644 --- a/src/com/massivecraft/factions/integration/Econ.java +++ b/src/com/massivecraft/factions/integration/Econ.java @@ -2,14 +2,11 @@ package com.massivecraft.factions.integration; import java.util.HashSet; import java.util.Set; +import java.util.logging.Level; import org.bukkit.Bukkit; -import org.bukkit.plugin.Plugin; +import org.bukkit.plugin.RegisteredServiceProvider; -import com.nijikokun.register.Register; -import com.nijikokun.register.payment.Method; -import com.nijikokun.register.payment.Method.MethodAccount; -import com.nijikokun.register.payment.Methods; import com.massivecraft.factions.Conf; import com.massivecraft.factions.FPlayer; import com.massivecraft.factions.Faction; @@ -19,70 +16,66 @@ import com.massivecraft.factions.iface.EconomyParticipator; import com.massivecraft.factions.struct.FPerm; import com.massivecraft.factions.util.RelationUtil; +import net.milkbowl.vault.economy.Economy; + + public class Econ { - private static Register register = null; - - public static Method getMethod() - { - if ( ! isSetup()) return null; - return Methods.getMethod(); - } + private static Economy econ = null; public static boolean shouldBeUsed() { - return Conf.econEnabled && register != null && register.isEnabled() && getMethod() != null; + return Conf.econEnabled && econ != null && econ.isEnabled(); } public static boolean isSetup() { - return register != null; + return econ != null; } public static void doSetup() { if (isSetup()) return; - Plugin plug = Bukkit.getServer().getPluginManager().getPlugin("Register"); - - if (plug != null && plug.getClass().getName().equals("com.nijikokun.register.Register")) + if (Bukkit.getServer().getPluginManager().getPlugin("Vault") != null) { - register = (Register)plug; + RegisteredServiceProvider rsp = Bukkit.getServer().getServicesManager().getRegistration(Economy.class); + econ = rsp.getProvider(); - P.p.log("Economy integration through Register plugin successful."); + P.p.log("Economy integration through Vault plugin successful."); if ( ! Conf.econEnabled) - P.p.log("NOTE: Economy is disabled. Enable in conf \"econEnabled\": true"); + P.p.log("NOTE: Economy is disabled. Enable with command: f config econEnabled true"); } else { - P.p.log("Economy integration is "+(Conf.econEnabled ? "enabled, but" : "disabled, and")+" the plugin \"Register\" is not installed."); + P.p.log("Economy integration is "+(Conf.econEnabled ? "enabled, but" : "disabled, and")+" the plugin \"Vault\" is not installed."); } P.p.cmdBase.cmdHelp.updateHelp(); } - - public static MethodAccount getUniverseAccount() - { - if (Conf.econUniverseAccount == null) return null; - if (Conf.econUniverseAccount.length() == 0) return null; - return getMethod().getAccount(Conf.econUniverseAccount); - } - + public static void modifyUniverseMoney(double delta) { if (!shouldBeUsed()) return; - MethodAccount acc = getUniverseAccount(); - if (acc == null) return; - acc.add(delta); + if (Conf.econUniverseAccount == null) return; + if (Conf.econUniverseAccount.length() == 0) return; + if ( ! econ.hasAccount(Conf.econUniverseAccount)) return; + + modifyBalance(Conf.econUniverseAccount, delta); } - + public static void sendBalanceInfo(FPlayer to, EconomyParticipator about) { - to.msg("%s's balance is %s.", about.describeTo(to, true), Econ.moneyString(about.getAccount().balance())); + if (!shouldBeUsed()) + { + P.p.log(Level.WARNING, "Vault does not appear to be hooked into an economy plugin."); + return; + } + to.msg("%s's balance is %s.", about.describeTo(to, true), Econ.moneyString(econ.getBalance(about.getAccountId()))); } - + public static boolean canIControllYou(EconomyParticipator i, EconomyParticipator you) { Faction fI = RelationUtil.getFaction(i); @@ -106,11 +99,15 @@ public class Econ if (you instanceof Faction && FPerm.WITHDRAW.has(i, fYou)) return true; // Otherwise you may not! ;,,; - i.msg("%s lack permission to controll %s's money.", i.describeTo(i, true), you.describeTo(i)); + i.msg("%s lacks permission to control %s's money.", i.describeTo(i, true), you.describeTo(i)); return false; } public static boolean transferMoney(EconomyParticipator invoker, EconomyParticipator from, EconomyParticipator to, double amount) + { + return transferMoney(invoker, from, to, amount, true); + } + public static boolean transferMoney(EconomyParticipator invoker, EconomyParticipator from, EconomyParticipator to, double amount, boolean notify) { if ( ! shouldBeUsed()) return false; @@ -128,22 +125,22 @@ public class Econ if ( ! canIControllYou(invoker, from)) return false; // Is there enough money for the transaction to happen? - if ( ! from.getAccount().hasEnough(amount)) + if ( ! econ.has(from.getAccountId(), amount)) { // There was not enough money to pay - if (invoker != null) - { + if (invoker != null && notify) invoker.msg("%s can't afford to transfer %s to %s.", from.describeTo(invoker, true), moneyString(amount), to.describeTo(invoker)); - } + return false; } // Transfer money - from.getAccount().subtract(amount); - to.getAccount().add(amount); + econ.withdrawPlayer(from.getAccountId(), amount); + econ.depositPlayer(to.getAccountId(), amount); // Inform - sendTransferInfo(invoker, from, to, amount); + if (notify) + sendTransferInfo(invoker, from, to, amount); return true; } @@ -209,14 +206,14 @@ public class Econ { if ( ! shouldBeUsed()) return false; - MethodAccount acc = ep.getAccount(); + String acc = ep.getAccountId(); String You = ep.describeTo(ep, true); if (delta >= 0) { // The player should gain money // There is no risk of failure - acc.add(delta); + econ.depositPlayer(acc, delta); modifyUniverseMoney(-delta); ep.msg("%s gained %s %s.", You, moneyString(delta), forDoingThis); return true; @@ -226,10 +223,10 @@ public class Econ // The player should loose money // The player might not have enough. - if (acc.hasEnough(-delta)) + if (econ.has(acc, -delta)) { // There is enough money to pay - acc.add(delta); + econ.withdrawPlayer(acc, -delta); modifyUniverseMoney(-delta); ep.msg("%s lost %s %s.", You, moneyString(-delta), forDoingThis); return true; @@ -246,7 +243,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 getMethod().format(amount); + return econ.format(amount); } public static void oldMoneyDoTransfer() @@ -257,7 +254,7 @@ public class Econ { if (faction.money > 0) { - faction.getAccount().add(faction.money); + econ.depositPlayer(faction.getAccountId(), faction.money); faction.money = 0; } } @@ -298,4 +295,46 @@ public class Econ { return calculateTotalLandValue(ownedLand) * Conf.econClaimRefundMultiplier; } + + + // -------------------------------------------- // + // Standard account management methods + // -------------------------------------------- // + + public static boolean hasAccount(String name) + { + return econ.hasAccount(name); + } + + public static double getBalance(String account) + { + return econ.getBalance(account); + } + + public static boolean setBalance(String account, double amount) + { + double current = econ.getBalance(account); + if (current > amount) + return econ.withdrawPlayer(account, current - amount).transactionSuccess(); + else + return econ.depositPlayer(account, amount - current).transactionSuccess(); + } + + public static boolean modifyBalance(String account, double amount) + { + if (amount < 0) + return econ.withdrawPlayer(account, -amount).transactionSuccess(); + else + return econ.depositPlayer(account, amount).transactionSuccess(); + } + + public static boolean deposit(String account, double amount) + { + return econ.depositPlayer(account, amount).transactionSuccess(); + } + + public static boolean withdraw(String account, double amount) + { + return econ.withdrawPlayer(account, amount).transactionSuccess(); + } } diff --git a/src/com/massivecraft/factions/util/RelationUtil.java b/src/com/massivecraft/factions/util/RelationUtil.java index 214cc419..c9c0e1d1 100644 --- a/src/com/massivecraft/factions/util/RelationUtil.java +++ b/src/com/massivecraft/factions/util/RelationUtil.java @@ -25,7 +25,7 @@ public class RelationUtil if (thatFaction == null) return "ERROR"; // ERROR Faction myFaction = getFaction(me); - if (myFaction == null) return "ERROR"; // ERROR + if (myFaction == null) return thatFaction.getTag(); // no relation, but can show basic faction tag if (that instanceof Faction) {