summaryrefslogtreecommitdiffstats
path: root/Essentials/src/net/ess3/settings/Economy.java
blob: ffbd57045c76a43c11494c3457c4e5a7d9253002 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
package net.ess3.settings;

import java.util.HashMap;
import java.util.Map;
import lombok.Data;
import lombok.EqualsAndHashCode;
import net.ess3.economy.Worth;
import net.ess3.storage.Comment;
import net.ess3.storage.MapValueType;
import net.ess3.storage.StorageObject;


@Data
@EqualsAndHashCode(callSuper = false)
public class Economy implements StorageObject
{
	@Comment("Defines the balance with which new players begin. Defaults to 0.")
	private double startingBalance = 0.0;
	@MapValueType(Double.class)
	@Comment("Defines the cost to use the given commands PER USE")
	private Map<String, Double> commandCosts = new HashMap<String, Double>();
	@Comment("Set this to a currency symbol you want to use.")
	private String currencySymbol = "$";

	public String getCurrencySymbol()
	{
		return currencySymbol == null || currencySymbol.isEmpty() ? "$" : currencySymbol.substring(0, 1);
	}
	private final transient static double MAXMONEY = 10000000000000.0;
	@Comment(
	{
		"Set the maximum amount of money a player can have",
		"The amount is always limited to 10 trillions because of the limitations of a java double"
	})
	private double maxMoney = MAXMONEY;

	public double getMaxMoney()
	{
		return Math.abs(maxMoney) > MAXMONEY ? MAXMONEY : Math.abs(maxMoney);
	}
	
	@Comment(
	{
		"Set the minimum amount of money a player can have (must be above the negative of max-money).",
		"Setting this to 0, will disable overdrafts/loans completely.  Users need 'essentials.eco.loan' perm to go below 0."
	})
	private double minMoney = -MAXMONEY;
	public double getMinMoney()
	{
		return Math.abs(minMoney) > MAXMONEY ? -MAXMONEY : minMoney;
	}
	
	@Comment("Enable this to log all interactions with trade/buy/sell signs and sell command")
	private boolean logEnabled = false;
	private Worth worth = new Worth();
	private boolean tradeInStacks = false;

	public double getCommandCost(String command)
	{
		if (commandCosts == null)
		{
			return 0;
		}
		Double price = commandCosts.get(command);
		return price == null || Double.isNaN(price) || Double.isInfinite(price) ? 0 : price;
	}
}