summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKHobbits <rob@khobbits.co.uk>2012-02-26 04:15:14 +0000
committerKHobbits <rob@khobbits.co.uk>2012-02-26 04:15:14 +0000
commita5b38ce1a492edb69c14239d976ff72db84915ef (patch)
tree00b653778e16a30431c32a7b34f1480d960c17ec
parent5d048d2c1dbfccf2db5188a7b2e3f9f303d9c273 (diff)
downloadEssentials-a5b38ce1a492edb69c14239d976ff72db84915ef.tar
Essentials-a5b38ce1a492edb69c14239d976ff72db84915ef.tar.gz
Essentials-a5b38ce1a492edb69c14239d976ff72db84915ef.tar.lz
Essentials-a5b38ce1a492edb69c14239d976ff72db84915ef.tar.xz
Essentials-a5b38ce1a492edb69c14239d976ff72db84915ef.zip
Add Minimum Balance, to allow people to manage overdrafts.
-rw-r--r--Essentials/src/com/earth2me/essentials/ISettings.java2
-rw-r--r--Essentials/src/com/earth2me/essentials/IUser.java2
-rw-r--r--Essentials/src/com/earth2me/essentials/Settings.java16
-rw-r--r--Essentials/src/com/earth2me/essentials/Trade.java6
-rw-r--r--Essentials/src/com/earth2me/essentials/User.java13
-rw-r--r--Essentials/src/com/earth2me/essentials/api/Economy.java4
-rw-r--r--Essentials/src/com/earth2me/essentials/commands/Commandeco.java4
-rw-r--r--Essentials/src/com/earth2me/essentials/user/User.java11
-rw-r--r--Essentials/src/config.yml6
9 files changed, 57 insertions, 7 deletions
diff --git a/Essentials/src/com/earth2me/essentials/ISettings.java b/Essentials/src/com/earth2me/essentials/ISettings.java
index e567673b6..cded5bde5 100644
--- a/Essentials/src/com/earth2me/essentials/ISettings.java
+++ b/Essentials/src/com/earth2me/essentials/ISettings.java
@@ -115,6 +115,8 @@ public interface ISettings extends IConf
boolean warnOnSmite();
double getMaxMoney();
+
+ double getMinMoney();
boolean isEcoLogEnabled();
diff --git a/Essentials/src/com/earth2me/essentials/IUser.java b/Essentials/src/com/earth2me/essentials/IUser.java
index bff556ab4..df5401886 100644
--- a/Essentials/src/com/earth2me/essentials/IUser.java
+++ b/Essentials/src/com/earth2me/essentials/IUser.java
@@ -32,6 +32,8 @@ public interface IUser extends Player
void takeMoney(double value);
void giveMoney(double value);
+
+ boolean canAfford(double value);
String getGroup();
diff --git a/Essentials/src/com/earth2me/essentials/Settings.java b/Essentials/src/com/earth2me/essentials/Settings.java
index 40fb47f6c..39179b957 100644
--- a/Essentials/src/com/earth2me/essentials/Settings.java
+++ b/Essentials/src/com/earth2me/essentials/Settings.java
@@ -539,6 +539,22 @@ public class Settings implements ISettings
}
return max;
}
+
+ private final static double MINMONEY = -10000000000000.0;
+
+ @Override
+ public double getMinMoney()
+ {
+ double min = config.getDouble("min-money", MINMONEY);
+ if (min > 0) {
+ min = -min;
+ }
+ if (min < MINMONEY)
+ {
+ min = MINMONEY;
+ }
+ return min;
+ }
@Override
public boolean isEcoLogEnabled()
diff --git a/Essentials/src/com/earth2me/essentials/Trade.java b/Essentials/src/com/earth2me/essentials/Trade.java
index 933b54b3f..5ed80d35b 100644
--- a/Essentials/src/com/earth2me/essentials/Trade.java
+++ b/Essentials/src/com/earth2me/essentials/Trade.java
@@ -143,8 +143,7 @@ public class Trade
{
if (getMoney() != null)
{
- final double mon = user.getMoney();
- if (mon < getMoney() && getMoney() > 0 && !user.isAuthorized("essentials.eco.loan"))
+ if (!user.canAfford(getMoney()) && getMoney() > 0)
{
throw new ChargeException(_("notEnoughMoney"));
}
@@ -163,9 +162,8 @@ public class Trade
&& !user.isAuthorized("essentials.nocommandcost.all")
&& !user.isAuthorized("essentials.nocommandcost." + command))
{
- final double mon = user.getMoney();
final double cost = ess.getSettings().getCommandCost(command.charAt(0) == '/' ? command.substring(1) : command);
- if (mon < cost && cost > 0 && !user.isAuthorized("essentials.eco.loan"))
+ if (!user.canAfford(cost) && cost > 0)
{
throw new ChargeException(_("notEnoughMoney"));
}
diff --git a/Essentials/src/com/earth2me/essentials/User.java b/Essentials/src/com/earth2me/essentials/User.java
index 7225e1dba..a799653a8 100644
--- a/Essentials/src/com/earth2me/essentials/User.java
+++ b/Essentials/src/com/earth2me/essentials/User.java
@@ -154,8 +154,17 @@ public class User extends UserData implements Comparable<User>, IReplyTo, IUser
public boolean canAfford(final double cost)
{
+ return canAfford(cost, true);
+ }
+
+ public boolean canAfford(final double cost, final boolean permcheck)
+ {
final double mon = getMoney();
- return mon >= cost || isAuthorized("essentials.eco.loan");
+ if (!permcheck || isAuthorized("essentials.eco.loan"))
+ {
+ return (mon + cost) > ess.getSettings().getMinMoney();
+ }
+ return cost <= mon;
}
public void dispose()
@@ -384,7 +393,7 @@ public class User extends UserData implements Comparable<User>, IReplyTo, IUser
public void updateMoneyCache(final double value)
{
if (ess.getPaymentMethod().hasMethod() && super.getMoney() != value)
- {
+ {
super.setMoney(value);
}
}
diff --git a/Essentials/src/com/earth2me/essentials/api/Economy.java b/Essentials/src/com/earth2me/essentials/api/Economy.java
index 1d45c8df9..a1d421c38 100644
--- a/Essentials/src/com/earth2me/essentials/api/Economy.java
+++ b/Essentials/src/com/earth2me/essentials/api/Economy.java
@@ -115,6 +115,10 @@ public final class Economy
{
throw new UserDoesNotExistException(name);
}
+ if (balance < ess.getSettings().getMinMoney())
+ {
+ throw new NoLoanPermittedException();
+ }
if (balance < 0.0 && !user.isAuthorized("essentials.eco.loan"))
{
throw new NoLoanPermittedException();
diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandeco.java b/Essentials/src/com/earth2me/essentials/commands/Commandeco.java
index 8f432ca6e..d2efc1845 100644
--- a/Essentials/src/com/earth2me/essentials/commands/Commandeco.java
+++ b/Essentials/src/com/earth2me/essentials/commands/Commandeco.java
@@ -1,5 +1,6 @@
package com.earth2me.essentials.commands;
+import static com.earth2me.essentials.I18n._;
import com.earth2me.essentials.User;
import java.util.Locale;
import org.bukkit.Server;
@@ -45,6 +46,9 @@ public class Commandeco extends EssentialsCommand
break;
case TAKE:
+ if (!player.canAfford(amount, false)) {
+ throw new Exception(_("notEnoughMoney"));
+ }
player.takeMoney(amount);
break;
diff --git a/Essentials/src/com/earth2me/essentials/user/User.java b/Essentials/src/com/earth2me/essentials/user/User.java
index 0e544ae06..5249c8718 100644
--- a/Essentials/src/com/earth2me/essentials/user/User.java
+++ b/Essentials/src/com/earth2me/essentials/user/User.java
@@ -196,4 +196,15 @@ public class User extends UserBase implements IUser
unlock();
}
}
+
+ @Override
+ public boolean canAfford(final double cost)
+ {
+ final double mon = getMoney();
+ if (isAuthorized("essentials.eco.loan"))
+ {
+ return (mon + cost) > ess.getSettings().getMinMoney();
+ }
+ return cost <= mon;
+ }
}
diff --git a/Essentials/src/config.yml b/Essentials/src/config.yml
index 00585f35f..97b73e4c5 100644
--- a/Essentials/src/config.yml
+++ b/Essentials/src/config.yml
@@ -281,10 +281,10 @@ spawn-if-no-home: true
update-bed-at-daytime: true
# Allow players to have multiple homes.
+# Players need essentials.sethome.multiple before they can have more than 1 home, default to 'default' below.
# Define different amounts of multiple homes for different permissions, e.g. essentials.sethome.multiple.vip
# People with essentials.sethome.multiple.unlimited are not limited by these numbers.
sethome-multiple:
- # essentials.sethome.multiple
default: 3
# essentials.sethome.multiple.vip
vip: 5
@@ -321,6 +321,10 @@ currency-symbol: '$'
# The amount is always limited to 10 trillions because of the limitations of a java double
max-money: 10000000000000
+# Set the minimum amount of money a player can have
+# Setting this to 0, will disable overdrafts/loans compeltely. Users need 'essentials.eco.loan' perm to go below 0.
+min-money: -10000000000000
+
# Enable this to log all interactions with trade/buy/sell signs and sell command
economy-log-enabled: false