Economy integration is now handled through Vault instead of Register. You will need to download and install the Vault plugin now if you want to use any Economy-related features. If you're not using the Register plugin for anything other than Factions, it should be safe to remove it from your server.

Vault: http://dev.bukkit.org/server-mods/vault/

Note: for proper faction bank support in iCo5 and EssentialsEco, I recommend waiting for Vault 1.2.5 to be released which addresses faction account creation issues.
This commit is contained in:
Brettflan 2012-01-16 19:36:32 -06:00
parent 1a4dfd8409
commit a5e2a62eac
15 changed files with 111 additions and 96 deletions

Binary file not shown.

BIN
lib/Vault.jar Normal file

Binary file not shown.

View File

@ -2,7 +2,7 @@ name: Factions
version: 1.6.3_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.

View File

@ -19,7 +19,6 @@ import com.massivecraft.factions.struct.Relation;
import com.massivecraft.factions.struct.Role;
import com.massivecraft.factions.util.RelationUtil;
import com.massivecraft.factions.zcore.persist.PlayerEntity;
import com.nijikokun.register.payment.Method.MethodAccount;
/**
@ -143,11 +142,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
@ -617,7 +612,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())

View File

@ -18,8 +18,6 @@ import com.massivecraft.factions.struct.Relation;
import com.massivecraft.factions.struct.Role;
import com.massivecraft.factions.util.*;
import com.massivecraft.factions.zcore.persist.Entity;
import com.nijikokun.register.payment.Method.MethodAccount;
import java.util.logging.Level;
public class Faction extends Entity implements EconomyParticipator
@ -121,24 +119,15 @@ 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);
}
if ( ! Econ.hasAccount(aid))
Econ.setBalance(aid, 0);
return Econ.getMethod().getAccount(aid);
return aid;
}
// FIELD: permanentPower
@ -706,7 +695,7 @@ public class Faction extends Entity implements EconomyParticipator
{
if (Econ.shouldBeUsed())
{
Econ.getMethod().getAccount(getAccountId()).remove();
Econ.setBalance(getAccountId(), 0);
}
this.getAccountId();

View File

@ -81,9 +81,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)
{

View File

@ -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))));
}
}

View File

@ -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))));
}
}

View File

@ -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))));
}
}

View File

@ -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))));
}
}

View File

@ -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))));
}
}

View File

@ -82,7 +82,7 @@ public class CmdShow extends FCommand
//Show bank contents
if(Conf.bankEnabled) {
msg("<a>Bank contains: <i>"+Econ.moneyString(faction.getAccount().balance()));
msg("<a>Bank contains: <i>"+Econ.moneyString(Econ.getBalance(faction.getAccountId())));
}
}

View File

@ -1,10 +1,8 @@
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);
}

View File

@ -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,75 +16,66 @@ import com.massivecraft.factions.iface.EconomyParticipator;
import com.massivecraft.factions.struct.Permission;
import com.massivecraft.factions.struct.Role;
import com.massivecraft.factions.util.RelationUtil;
import java.util.logging.Level;
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<Economy> 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)
{
if (!shouldBeUsed())
{
P.p.log(Level.WARNING, "Register does not appear to be hooked into an economy plugin.");
P.p.log(Level.WARNING, "Vault does not appear to be hooked into an economy plugin.");
return;
}
to.msg("<a>%s's<i> balance is <h>%s<i>.", about.describeTo(to, true), Econ.moneyString(about.getAccount().balance()));
to.msg("<a>%s's<i> balance is <h>%s<i>.", about.describeTo(to, true), Econ.moneyString(econ.getBalance(about.getAccountId())));
}
public static boolean canIControllYou(EconomyParticipator i, EconomyParticipator you)
@ -116,11 +104,15 @@ public class Econ
if (you instanceof Faction && fI == fYou && (Conf.bankMembersCanWithdraw || ((FPlayer)i).getRole().value >= Role.MODERATOR.value)) return true;
// Otherwise you may not! ;,,;
i.msg("<h>%s<i> lack permission to controll <h>%s's<i> money.", i.describeTo(i, true), you.describeTo(i));
i.msg("<h>%s<i> lacks permission to control <h>%s's<i> 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;
@ -138,21 +130,21 @@ 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("<h>%s<b> can't afford to transfer <h>%s<b> to %s<b>.", 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
if (notify)
sendTransferInfo(invoker, from, to, amount);
return true;
@ -219,14 +211,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("<h>%s<i> gained <h>%s<i> %s.", You, moneyString(delta), forDoingThis);
return true;
@ -236,10 +228,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("<h>%s<i> lost <h>%s<i> %s.", You, moneyString(-delta), forDoingThis);
return true;
@ -256,7 +248,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()
@ -267,7 +259,7 @@ public class Econ
{
if (faction.money > 0)
{
faction.getAccount().add(faction.money);
econ.depositPlayer(faction.getAccountId(), faction.money);
faction.money = 0;
}
}
@ -308,4 +300,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();
}
}

View File

@ -19,7 +19,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)
{