2011-10-05 12:13:54 +02:00
package com.massivecraft.factions.integration ;
Added basic support for iConomy, where most Factions commands can be made to cost (or give) money. For claiming land, there are some extra features. Each additional land claimed by default costs more than the last, with the multiplier being configurable. For example, the first claim might cost $30, the 2nd $45, the third $60, and so forth. When land is claimed from a weakened faction, there is a configurable bonus amount of money deducted from the cost of claiming the land, as an incentive; this number can be changed to a negative value to instead make it cost more to claim such land. When land is unclaimed, a configurable percentage of the cost of claiming the land can be refunded (defaults to 70% of the cost). The total value of a faction's claimed land is now shown in the info given by /f who [faction tag], along with the depreciated (refund) value.
2011-08-02 01:05:01 +02:00
2011-10-13 14:41:07 +02:00
import java.util.HashSet ;
import java.util.Set ;
2012-01-17 02:38:14 +01:00
import java.util.logging.Level ;
2011-10-13 14:41:07 +02:00
2011-10-12 17:25:01 +02:00
import org.bukkit.Bukkit ;
2012-01-17 02:38:14 +01:00
import org.bukkit.plugin.RegisteredServiceProvider ;
Added basic support for iConomy, where most Factions commands can be made to cost (or give) money. For claiming land, there are some extra features. Each additional land claimed by default costs more than the last, with the multiplier being configurable. For example, the first claim might cost $30, the 2nd $45, the third $60, and so forth. When land is claimed from a weakened faction, there is a configurable bonus amount of money deducted from the cost of claiming the land, as an incentive; this number can be changed to a negative value to instead make it cost more to claim such land. When land is unclaimed, a configurable percentage of the cost of claiming the land can be refunded (defaults to 70% of the cost). The total value of a faction's claimed land is now shown in the info given by /f who [faction tag], along with the depreciated (refund) value.
2011-08-02 01:05:01 +02:00
2013-04-09 13:15:25 +02:00
import com.massivecraft.factions.ConfServer ;
2013-04-09 13:24:55 +02:00
import com.massivecraft.factions.FPerm ;
2011-10-12 17:25:01 +02:00
import com.massivecraft.factions.FPlayer ;
import com.massivecraft.factions.Faction ;
2013-04-09 13:00:09 +02:00
import com.massivecraft.factions.Factions ;
2011-10-12 17:25:01 +02:00
import com.massivecraft.factions.iface.EconomyParticipator ;
import com.massivecraft.factions.util.RelationUtil ;
Added basic support for iConomy, where most Factions commands can be made to cost (or give) money. For claiming land, there are some extra features. Each additional land claimed by default costs more than the last, with the multiplier being configurable. For example, the first claim might cost $30, the 2nd $45, the third $60, and so forth. When land is claimed from a weakened faction, there is a configurable bonus amount of money deducted from the cost of claiming the land, as an incentive; this number can be changed to a negative value to instead make it cost more to claim such land. When land is unclaimed, a configurable percentage of the cost of claiming the land can be refunded (defaults to 70% of the cost). The total value of a faction's claimed land is now shown in the info given by /f who [faction tag], along with the depreciated (refund) value.
2011-08-02 01:05:01 +02:00
2012-01-17 02:38:14 +01:00
import net.milkbowl.vault.economy.Economy ;
2012-12-28 23:46:32 +01:00
import net.milkbowl.vault.economy.EconomyResponse ;
2012-01-17 02:38:14 +01:00
2011-10-10 01:21:05 +02:00
public class Econ
{
2013-04-19 09:50:33 +02:00
// -------------------------------------------- //
// DERPY OLDSCHOOL SETUP
// -------------------------------------------- //
2012-02-22 18:43:53 +01:00
public static void setup ( )
2012-01-28 12:24:39 +01:00
{
2013-04-19 09:50:33 +02:00
if ( economy ! = null ) return ;
2012-01-30 06:11:39 +01:00
2013-04-09 13:15:25 +02:00
String integrationFail = " Economy integration is " + ( ConfServer . econEnabled ? " enabled, but " : " disabled, and " ) + " the plugin \" Vault \" " ;
2012-01-30 06:11:39 +01:00
2012-01-28 12:24:39 +01:00
if ( Bukkit . getServer ( ) . getPluginManager ( ) . getPlugin ( " Vault " ) = = null )
{
2013-04-09 13:12:13 +02:00
Factions . get ( ) . log ( integrationFail + " is not installed. " ) ;
2012-01-28 12:24:39 +01:00
return ;
}
2012-01-30 06:11:39 +01:00
RegisteredServiceProvider < Economy > rsp = Bukkit . getServer ( ) . getServicesManager ( ) . getRegistration ( Economy . class ) ;
if ( rsp = = null )
2012-01-28 12:24:39 +01:00
{
2013-04-09 13:12:13 +02:00
Factions . get ( ) . log ( integrationFail + " is not hooked into an economy plugin. " ) ;
2012-01-30 06:11:39 +01:00
return ;
2011-08-04 09:25:12 +02:00
}
2013-04-19 09:50:33 +02:00
economy = rsp . getProvider ( ) ;
2012-01-30 06:11:39 +01:00
2013-04-09 13:12:13 +02:00
Factions . get ( ) . log ( " Economy integration through Vault plugin successful. " ) ;
2012-01-30 06:11:39 +01:00
2013-04-09 13:15:25 +02:00
if ( ! ConfServer . econEnabled )
2013-04-09 13:12:13 +02:00
Factions . get ( ) . log ( " NOTE: Economy is disabled. You can enable it with the command: f config econEnabled true " ) ;
2012-02-22 18:43:53 +01:00
}
2013-04-19 09:50:33 +02:00
// -------------------------------------------- //
// FIELDS
// -------------------------------------------- //
private static Economy economy = null ;
// -------------------------------------------- //
// STATE
// -------------------------------------------- //
public static boolean isEnabled ( )
2012-02-22 18:43:53 +01:00
{
2013-04-19 09:50:33 +02:00
return ConfServer . econEnabled & & economy ! = null & & economy . isEnabled ( ) ;
2012-02-22 18:43:53 +01:00
}
2013-04-19 09:50:33 +02:00
// -------------------------------------------- //
// UTIL
// -------------------------------------------- //
2013-04-19 14:24:35 +02:00
public static boolean payForAction ( double cost , FPlayer fsender , String actionDescription )
2012-02-22 18:43:53 +01:00
{
2013-04-19 09:50:33 +02:00
if ( ! isEnabled ( ) ) return true ;
if ( cost = = 0D ) return true ;
if ( fsender . isUsingAdminMode ( ) ) return true ;
Faction fsenderFaction = fsender . getFaction ( ) ;
2012-01-17 02:38:14 +01:00
2013-04-19 09:50:33 +02:00
if ( ConfServer . bankEnabled & & ConfServer . bankFactionPaysCosts & & fsenderFaction . isNormal ( ) )
{
return modifyMoney ( fsenderFaction , - cost , actionDescription ) ;
}
else
{
return modifyMoney ( fsender , - cost , actionDescription ) ;
}
}
// -------------------------------------------- //
// ASSORTED
// -------------------------------------------- //
2012-01-30 06:11:39 +01:00
2011-10-12 17:25:01 +02:00
public static void modifyUniverseMoney ( double delta )
2011-10-08 22:03:44 +02:00
{
2013-04-19 09:50:33 +02:00
if ( ! isEnabled ( ) ) return ;
2011-10-13 06:44:59 +02:00
2013-04-09 13:15:25 +02:00
if ( ConfServer . econUniverseAccount = = null ) return ;
if ( ConfServer . econUniverseAccount . length ( ) = = 0 ) return ;
2013-04-19 09:50:33 +02:00
if ( ! economy . hasAccount ( ConfServer . econUniverseAccount ) ) return ;
2012-01-17 02:38:14 +01:00
2013-04-09 13:15:25 +02:00
modifyBalance ( ConfServer . econUniverseAccount , delta ) ;
Added basic support for iConomy, where most Factions commands can be made to cost (or give) money. For claiming land, there are some extra features. Each additional land claimed by default costs more than the last, with the multiplier being configurable. For example, the first claim might cost $30, the 2nd $45, the third $60, and so forth. When land is claimed from a weakened faction, there is a configurable bonus amount of money deducted from the cost of claiming the land, as an incentive; this number can be changed to a negative value to instead make it cost more to claim such land. When land is unclaimed, a configurable percentage of the cost of claiming the land can be refunded (defaults to 70% of the cost). The total value of a faction's claimed land is now shown in the info given by /f who [faction tag], along with the depreciated (refund) value.
2011-08-02 01:05:01 +02:00
}
2012-01-17 02:38:14 +01:00
2011-10-13 14:41:07 +02:00
public static void sendBalanceInfo ( FPlayer to , EconomyParticipator about )
{
2013-04-19 09:50:33 +02:00
if ( ! isEnabled ( ) )
2012-01-17 02:38:14 +01:00
{
2013-04-09 13:12:13 +02:00
Factions . get ( ) . log ( Level . WARNING , " Vault does not appear to be hooked into an economy plugin. " ) ;
2012-01-17 02:38:14 +01:00
return ;
}
2013-04-19 09:50:33 +02:00
to . msg ( " <a>%s's<i> balance is <h>%s<i>. " , about . describeTo ( to , true ) , Econ . moneyString ( economy . getBalance ( about . getAccountId ( ) ) ) ) ;
2011-10-13 14:41:07 +02:00
}
2012-01-17 02:38:14 +01:00
2011-10-13 14:41:07 +02:00
public static boolean canIControllYou ( EconomyParticipator i , EconomyParticipator you )
2011-10-08 22:03:44 +02:00
{
2011-10-23 02:43:25 +02:00
Faction fI = RelationUtil . getFaction ( i ) ;
Faction fYou = RelationUtil . getFaction ( you ) ;
2011-10-12 17:25:01 +02:00
// This is a system invoker. Accept it.
2011-10-23 02:43:25 +02:00
if ( fI = = null ) return true ;
2011-10-12 17:25:01 +02:00
// Bypassing players can do any kind of transaction
2013-04-16 11:27:03 +02:00
if ( i instanceof FPlayer & & ( ( FPlayer ) i ) . isUsingAdminMode ( ) ) return true ;
2011-10-12 17:25:01 +02:00
// You can deposit to anywhere you feel like. It's your loss if you can't withdraw it again.
2011-10-13 14:41:07 +02:00
if ( i = = you ) return true ;
2011-10-12 17:25:01 +02:00
// A faction can always transfer away the money of it's members and its own money...
// This will however probably never happen as a faction does not have free will.
// Ohh by the way... Yes it could. For daily rent to the faction.
2011-10-23 02:43:25 +02:00
if ( i = = fI & & fI = = fYou ) return true ;
2011-10-12 17:25:01 +02:00
2011-10-24 11:56:41 +02:00
// Factions can be controlled by those that have permissions
if ( you instanceof Faction & & FPerm . WITHDRAW . has ( i , fYou ) ) return true ;
2011-10-12 17:25:01 +02:00
// Otherwise you may not! ;,,;
2012-01-17 02:38:14 +01:00
i . msg ( " <h>%s<i> lacks permission to control <h>%s's<i> money. " , i . describeTo ( i , true ) , you . describeTo ( i ) ) ;
2011-10-12 17:25:01 +02:00
return false ;
2011-09-22 11:22:24 +02:00
}
2011-10-12 17:25:01 +02:00
public static boolean transferMoney ( EconomyParticipator invoker , EconomyParticipator from , EconomyParticipator to , double amount )
2012-01-17 02:38:14 +01:00
{
return transferMoney ( invoker , from , to , amount , true ) ;
}
public static boolean transferMoney ( EconomyParticipator invoker , EconomyParticipator from , EconomyParticipator to , double amount , boolean notify )
2011-10-08 22:03:44 +02:00
{
2013-04-19 09:50:33 +02:00
if ( ! isEnabled ( ) ) return false ;
2011-10-13 06:44:59 +02:00
2011-10-12 17:25:01 +02:00
// The amount must be positive.
// If the amount is negative we must flip and multiply amount with -1.
if ( amount < 0 )
2011-10-08 22:03:44 +02:00
{
2011-10-12 17:25:01 +02:00
amount * = - 1 ;
EconomyParticipator temp = from ;
from = to ;
to = temp ;
Added basic support for iConomy, where most Factions commands can be made to cost (or give) money. For claiming land, there are some extra features. Each additional land claimed by default costs more than the last, with the multiplier being configurable. For example, the first claim might cost $30, the 2nd $45, the third $60, and so forth. When land is claimed from a weakened faction, there is a configurable bonus amount of money deducted from the cost of claiming the land, as an incentive; this number can be changed to a negative value to instead make it cost more to claim such land. When land is unclaimed, a configurable percentage of the cost of claiming the land can be refunded (defaults to 70% of the cost). The total value of a faction's claimed land is now shown in the info given by /f who [faction tag], along with the depreciated (refund) value.
2011-08-02 01:05:01 +02:00
}
2011-10-12 17:25:01 +02:00
// Check the rights
2011-10-13 14:41:07 +02:00
if ( ! canIControllYou ( invoker , from ) ) return false ;
2011-10-12 17:25:01 +02:00
// Is there enough money for the transaction to happen?
2013-04-19 09:50:33 +02:00
if ( ! economy . has ( from . getAccountId ( ) , amount ) )
2011-10-12 17:25:01 +02:00
{
// There was not enough money to pay
2012-01-17 02:38:14 +01:00
if ( invoker ! = null & & notify )
2013-04-19 09:50:33 +02:00
{
2011-10-13 14:41:07 +02:00
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 ) ) ;
2013-04-19 09:50:33 +02:00
}
2011-10-12 17:25:01 +02:00
return false ;
}
// Transfer money
2013-04-19 09:50:33 +02:00
EconomyResponse erw = economy . withdrawPlayer ( from . getAccountId ( ) , amount ) ;
2011-10-12 17:25:01 +02:00
2013-04-19 09:50:33 +02:00
if ( erw . transactionSuccess ( ) )
{
EconomyResponse erd = economy . depositPlayer ( to . getAccountId ( ) , amount ) ;
if ( erd . transactionSuccess ( ) )
{
if ( notify )
{
sendTransferInfo ( invoker , from , to , amount ) ;
}
2012-12-28 23:46:32 +01:00
return true ;
2013-04-19 09:50:33 +02:00
}
else
{
2012-12-28 23:46:32 +01:00
// transaction failed, refund account
2013-04-19 09:50:33 +02:00
economy . depositPlayer ( from . getAccountId ( ) , amount ) ;
2012-12-28 23:46:32 +01:00
}
}
// if we get here something with the transaction failed
2012-01-17 02:38:14 +01:00
if ( notify )
2012-12-28 23:46:32 +01:00
invoker . msg ( " Unable to transfer %s<b> to <h>%s<b> from <h>%s<b>. " , moneyString ( amount ) , to . describeTo ( invoker ) , from . describeTo ( invoker , true ) ) ;
2011-10-13 14:41:07 +02:00
2012-12-28 23:46:32 +01:00
return false ;
2011-10-13 14:41:07 +02:00
}
public static Set < FPlayer > getFplayers ( EconomyParticipator ep )
{
Set < FPlayer > fplayers = new HashSet < FPlayer > ( ) ;
if ( ep = = null )
{
// Add nothing
}
else if ( ep instanceof FPlayer )
{
fplayers . add ( ( FPlayer ) ep ) ;
}
else if ( ep instanceof Faction )
{
fplayers . addAll ( ( ( Faction ) ep ) . getFPlayers ( ) ) ;
}
return fplayers ;
}
public static void sendTransferInfo ( EconomyParticipator invoker , EconomyParticipator from , EconomyParticipator to , double amount )
{
Set < FPlayer > recipients = new HashSet < FPlayer > ( ) ;
recipients . addAll ( getFplayers ( invoker ) ) ;
recipients . addAll ( getFplayers ( from ) ) ;
recipients . addAll ( getFplayers ( to ) ) ;
2011-10-12 17:25:01 +02:00
if ( invoker = = null )
{
2011-10-13 14:41:07 +02:00
for ( FPlayer recipient : recipients )
{
recipient . msg ( " <h>%s<i> was transfered from <h>%s<i> to <h>%s<i>. " , moneyString ( amount ) , from . describeTo ( recipient ) , to . describeTo ( recipient ) ) ;
}
}
else if ( invoker = = from )
{
for ( FPlayer recipient : recipients )
{
recipient . msg ( " <h>%s<i> <h>gave %s<i> to <h>%s<i>. " , from . describeTo ( recipient , true ) , moneyString ( amount ) , to . describeTo ( recipient ) ) ;
}
2011-10-12 17:25:01 +02:00
}
2011-10-13 14:41:07 +02:00
else if ( invoker = = to )
2011-10-12 17:25:01 +02:00
{
2011-10-13 14:41:07 +02:00
for ( FPlayer recipient : recipients )
{
recipient . msg ( " <h>%s<i> <h>took %s<i> from <h>%s<i>. " , to . describeTo ( recipient , true ) , moneyString ( amount ) , from . describeTo ( recipient ) ) ;
}
2011-10-12 17:25:01 +02:00
}
else
2011-10-08 22:03:44 +02:00
{
2011-10-13 14:41:07 +02:00
for ( FPlayer recipient : recipients )
{
recipient . msg ( " <h>%s<i> transfered <h>%s<i> from <h>%s<i> to <h>%s<i>. " , invoker . describeTo ( recipient , true ) , moneyString ( amount ) , from . describeTo ( recipient ) , to . describeTo ( recipient ) ) ;
}
Added basic support for iConomy, where most Factions commands can be made to cost (or give) money. For claiming land, there are some extra features. Each additional land claimed by default costs more than the last, with the multiplier being configurable. For example, the first claim might cost $30, the 2nd $45, the third $60, and so forth. When land is claimed from a weakened faction, there is a configurable bonus amount of money deducted from the cost of claiming the land, as an incentive; this number can be changed to a negative value to instead make it cost more to claim such land. When land is unclaimed, a configurable percentage of the cost of claiming the land can be refunded (defaults to 70% of the cost). The total value of a faction's claimed land is now shown in the info given by /f who [faction tag], along with the depreciated (refund) value.
2011-08-02 01:05:01 +02:00
}
}
2012-03-13 15:48:34 +01:00
public static boolean hasAtLeast ( EconomyParticipator ep , double delta , String toDoThis )
{
2013-04-19 09:50:33 +02:00
if ( ! isEnabled ( ) ) return true ;
2012-03-13 15:48:34 +01:00
2013-04-19 09:50:33 +02:00
if ( ! economy . has ( ep . getAccountId ( ) , delta ) )
2012-03-13 15:48:34 +01:00
{
if ( toDoThis ! = null & & ! toDoThis . isEmpty ( ) )
ep . msg ( " <h>%s<i> can't afford <h>%s<i> %s. " , ep . describeTo ( ep , true ) , moneyString ( delta ) , toDoThis ) ;
return false ;
}
return true ;
}
2013-04-19 09:50:33 +02:00
public static boolean modifyMoney ( EconomyParticipator ep , double delta , String actionDescription )
2011-10-08 22:03:44 +02:00
{
2013-04-19 09:50:33 +02:00
if ( ! isEnabled ( ) ) return false ;
if ( delta = = 0 ) return true ;
String accountId = ep . getAccountId ( ) ;
2011-10-12 17:25:01 +02:00
String You = ep . describeTo ( ep , true ) ;
2013-04-19 09:50:33 +02:00
boolean hasActionDesctription = ( actionDescription ! = null & & ! actionDescription . isEmpty ( ) ) ;
2012-01-31 18:07:47 +01:00
if ( delta > 0 )
2011-10-08 22:03:44 +02:00
{
2011-10-12 17:25:01 +02:00
// The player should gain money
2012-12-28 23:46:32 +01:00
// The account might not have enough space
2013-04-19 09:50:33 +02:00
EconomyResponse er = economy . depositPlayer ( accountId , delta ) ;
if ( er . transactionSuccess ( ) )
{
2012-12-28 23:46:32 +01:00
modifyUniverseMoney ( - delta ) ;
2013-04-19 09:50:33 +02:00
if ( hasActionDesctription )
{
ep . msg ( " <h>%s<i> gained <h>%s<i> since did %s. " , You , moneyString ( delta ) , actionDescription ) ;
}
2012-12-28 23:46:32 +01:00
return true ;
2013-04-19 09:50:33 +02:00
}
else
{
2012-12-28 23:46:32 +01:00
// transfer to account failed
2013-04-19 09:50:33 +02:00
if ( hasActionDesctription )
{
ep . msg ( " <h>%s<i> would have gained <h>%s<i> since did %s, but the deposit failed. " , You , moneyString ( delta ) , actionDescription ) ;
}
2012-12-28 23:46:32 +01:00
return false ;
}
2011-09-22 11:22:24 +02:00
}
2011-10-12 17:25:01 +02:00
else
2011-10-08 22:03:44 +02:00
{
2011-10-12 17:25:01 +02:00
// The player should loose money
// The player might not have enough.
2013-04-19 09:50:33 +02:00
EconomyResponse er = economy . withdrawPlayer ( accountId , - delta ) ;
if ( er . transactionSuccess ( ) )
2011-10-12 17:25:01 +02:00
{
// There is enough money to pay
modifyUniverseMoney ( - delta ) ;
2013-04-19 09:50:33 +02:00
if ( hasActionDesctription )
{
ep . msg ( " <h>%s<i> lost <h>%s<i> since did %s. " , You , moneyString ( delta ) , actionDescription ) ;
}
2011-10-12 17:25:01 +02:00
return true ;
}
else
{
// There was not enough money to pay
2013-04-19 09:50:33 +02:00
if ( hasActionDesctription )
{
ep . msg ( " <h>%s<i> can't afford <h>%s<i> to %s. " , You , moneyString ( - delta ) , actionDescription ) ;
}
2011-10-12 17:25:01 +02:00
return false ;
}
2011-09-22 11:22:24 +02:00
}
}
Added basic support for iConomy, where most Factions commands can be made to cost (or give) money. For claiming land, there are some extra features. Each additional land claimed by default costs more than the last, with the multiplier being configurable. For example, the first claim might cost $30, the 2nd $45, the third $60, and so forth. When land is claimed from a weakened faction, there is a configurable bonus amount of money deducted from the cost of claiming the land, as an incentive; this number can be changed to a negative value to instead make it cost more to claim such land. When land is unclaimed, a configurable percentage of the cost of claiming the land can be refunded (defaults to 70% of the cost). The total value of a faction's claimed land is now shown in the info given by /f who [faction tag], along with the depreciated (refund) value.
2011-08-02 01:05:01 +02:00
// format money string based on server's set currency type, like "24 gold" or "$24.50"
2011-10-08 22:03:44 +02:00
public static String moneyString ( double amount )
{
2013-04-19 09:50:33 +02:00
return economy . format ( amount ) ;
2011-10-12 17:25:01 +02:00
}
Added basic support for iConomy, where most Factions commands can be made to cost (or give) money. For claiming land, there are some extra features. Each additional land claimed by default costs more than the last, with the multiplier being configurable. For example, the first claim might cost $30, the 2nd $45, the third $60, and so forth. When land is claimed from a weakened faction, there is a configurable bonus amount of money deducted from the cost of claiming the land, as an incentive; this number can be changed to a negative value to instead make it cost more to claim such land. When land is unclaimed, a configurable percentage of the cost of claiming the land can be refunded (defaults to 70% of the cost). The total value of a faction's claimed land is now shown in the info given by /f who [faction tag], along with the depreciated (refund) value.
2011-08-02 01:05:01 +02:00
// calculate the cost for claiming land
2011-10-08 22:03:44 +02:00
public static double calculateClaimCost ( int ownedLand , boolean takingFromAnotherFaction )
{
2013-04-19 09:50:33 +02:00
if ( ! isEnabled ( ) ) return 0D ;
Added basic support for iConomy, where most Factions commands can be made to cost (or give) money. For claiming land, there are some extra features. Each additional land claimed by default costs more than the last, with the multiplier being configurable. For example, the first claim might cost $30, the 2nd $45, the third $60, and so forth. When land is claimed from a weakened faction, there is a configurable bonus amount of money deducted from the cost of claiming the land, as an incentive; this number can be changed to a negative value to instead make it cost more to claim such land. When land is unclaimed, a configurable percentage of the cost of claiming the land can be refunded (defaults to 70% of the cost). The total value of a faction's claimed land is now shown in the info given by /f who [faction tag], along with the depreciated (refund) value.
2011-08-02 01:05:01 +02:00
// basic claim cost, plus land inflation cost, minus the potential bonus given for claiming from another faction
2013-04-09 13:15:25 +02:00
return ConfServer . econCostClaimWilderness
+ ( ConfServer . econCostClaimWilderness * ConfServer . econClaimAdditionalMultiplier * ownedLand )
- ( takingFromAnotherFaction ? ConfServer . econCostClaimFromFactionBonus : 0 ) ;
Added basic support for iConomy, where most Factions commands can be made to cost (or give) money. For claiming land, there are some extra features. Each additional land claimed by default costs more than the last, with the multiplier being configurable. For example, the first claim might cost $30, the 2nd $45, the third $60, and so forth. When land is claimed from a weakened faction, there is a configurable bonus amount of money deducted from the cost of claiming the land, as an incentive; this number can be changed to a negative value to instead make it cost more to claim such land. When land is unclaimed, a configurable percentage of the cost of claiming the land can be refunded (defaults to 70% of the cost). The total value of a faction's claimed land is now shown in the info given by /f who [faction tag], along with the depreciated (refund) value.
2011-08-02 01:05:01 +02:00
}
// calculate refund amount for unclaiming land
2011-10-08 22:03:44 +02:00
public static double calculateClaimRefund ( int ownedLand )
{
2013-04-09 13:15:25 +02:00
return calculateClaimCost ( ownedLand - 1 , false ) * ConfServer . econClaimRefundMultiplier ;
Added basic support for iConomy, where most Factions commands can be made to cost (or give) money. For claiming land, there are some extra features. Each additional land claimed by default costs more than the last, with the multiplier being configurable. For example, the first claim might cost $30, the 2nd $45, the third $60, and so forth. When land is claimed from a weakened faction, there is a configurable bonus amount of money deducted from the cost of claiming the land, as an incentive; this number can be changed to a negative value to instead make it cost more to claim such land. When land is unclaimed, a configurable percentage of the cost of claiming the land can be refunded (defaults to 70% of the cost). The total value of a faction's claimed land is now shown in the info given by /f who [faction tag], along with the depreciated (refund) value.
2011-08-02 01:05:01 +02:00
}
// calculate value of all owned land
2011-10-08 22:03:44 +02:00
public static double calculateTotalLandValue ( int ownedLand )
{
Added basic support for iConomy, where most Factions commands can be made to cost (or give) money. For claiming land, there are some extra features. Each additional land claimed by default costs more than the last, with the multiplier being configurable. For example, the first claim might cost $30, the 2nd $45, the third $60, and so forth. When land is claimed from a weakened faction, there is a configurable bonus amount of money deducted from the cost of claiming the land, as an incentive; this number can be changed to a negative value to instead make it cost more to claim such land. When land is unclaimed, a configurable percentage of the cost of claiming the land can be refunded (defaults to 70% of the cost). The total value of a faction's claimed land is now shown in the info given by /f who [faction tag], along with the depreciated (refund) value.
2011-08-02 01:05:01 +02:00
double amount = 0 ;
2013-04-19 09:50:33 +02:00
for ( int x = 0 ; x < ownedLand ; x + + )
{
Added basic support for iConomy, where most Factions commands can be made to cost (or give) money. For claiming land, there are some extra features. Each additional land claimed by default costs more than the last, with the multiplier being configurable. For example, the first claim might cost $30, the 2nd $45, the third $60, and so forth. When land is claimed from a weakened faction, there is a configurable bonus amount of money deducted from the cost of claiming the land, as an incentive; this number can be changed to a negative value to instead make it cost more to claim such land. When land is unclaimed, a configurable percentage of the cost of claiming the land can be refunded (defaults to 70% of the cost). The total value of a faction's claimed land is now shown in the info given by /f who [faction tag], along with the depreciated (refund) value.
2011-08-02 01:05:01 +02:00
amount + = calculateClaimCost ( x , false ) ;
}
return amount ;
}
// calculate refund amount for all owned land
2011-10-08 22:03:44 +02:00
public static double calculateTotalLandRefund ( int ownedLand )
{
2013-04-09 13:15:25 +02:00
return calculateTotalLandValue ( ownedLand ) * ConfServer . econClaimRefundMultiplier ;
Added basic support for iConomy, where most Factions commands can be made to cost (or give) money. For claiming land, there are some extra features. Each additional land claimed by default costs more than the last, with the multiplier being configurable. For example, the first claim might cost $30, the 2nd $45, the third $60, and so forth. When land is claimed from a weakened faction, there is a configurable bonus amount of money deducted from the cost of claiming the land, as an incentive; this number can be changed to a negative value to instead make it cost more to claim such land. When land is unclaimed, a configurable percentage of the cost of claiming the land can be refunded (defaults to 70% of the cost). The total value of a faction's claimed land is now shown in the info given by /f who [faction tag], along with the depreciated (refund) value.
2011-08-02 01:05:01 +02:00
}
2012-01-17 02:38:14 +01:00
// -------------------------------------------- //
// Standard account management methods
// -------------------------------------------- //
public static boolean hasAccount ( String name )
{
2013-04-19 09:50:33 +02:00
return economy . hasAccount ( name ) ;
2012-01-17 02:38:14 +01:00
}
public static double getBalance ( String account )
{
2013-04-19 09:50:33 +02:00
return economy . getBalance ( account ) ;
2012-01-17 02:38:14 +01:00
}
public static boolean setBalance ( String account , double amount )
{
2013-04-19 09:50:33 +02:00
double current = economy . getBalance ( account ) ;
2012-01-17 02:38:14 +01:00
if ( current > amount )
2013-04-19 09:50:33 +02:00
return economy . withdrawPlayer ( account , current - amount ) . transactionSuccess ( ) ;
2012-01-17 02:38:14 +01:00
else
2013-04-19 09:50:33 +02:00
return economy . depositPlayer ( account , amount - current ) . transactionSuccess ( ) ;
2012-01-17 02:38:14 +01:00
}
public static boolean modifyBalance ( String account , double amount )
{
if ( amount < 0 )
2013-04-19 09:50:33 +02:00
return economy . withdrawPlayer ( account , - amount ) . transactionSuccess ( ) ;
2012-01-17 02:38:14 +01:00
else
2013-04-19 09:50:33 +02:00
return economy . depositPlayer ( account , amount ) . transactionSuccess ( ) ;
2012-01-17 02:38:14 +01:00
}
public static boolean deposit ( String account , double amount )
{
2013-04-19 09:50:33 +02:00
return economy . depositPlayer ( account , amount ) . transactionSuccess ( ) ;
2012-01-17 02:38:14 +01:00
}
public static boolean withdraw ( String account , double amount )
{
2013-04-19 09:50:33 +02:00
return economy . withdrawPlayer ( account , amount ) . transactionSuccess ( ) ;
2012-01-17 02:38:14 +01:00
}
Added basic support for iConomy, where most Factions commands can be made to cost (or give) money. For claiming land, there are some extra features. Each additional land claimed by default costs more than the last, with the multiplier being configurable. For example, the first claim might cost $30, the 2nd $45, the third $60, and so forth. When land is claimed from a weakened faction, there is a configurable bonus amount of money deducted from the cost of claiming the land, as an incentive; this number can be changed to a negative value to instead make it cost more to claim such land. When land is unclaimed, a configurable percentage of the cost of claiming the land can be refunded (defaults to 70% of the cost). The total value of a faction's claimed land is now shown in the info given by /f who [faction tag], along with the depreciated (refund) value.
2011-08-02 01:05:01 +02:00
}