summaryrefslogtreecommitdiffstats
path: root/Essentials/src/com/earth2me/essentials/register/payment/methods/MCUR.java
blob: 53d8ed1201cc4b733767a3952bcede04a2f290c2 (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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
package com.earth2me.essentials.register.payment.methods;

import com.earth2me.essentials.register.payment.Method;

import me.ashtheking.currency.Currency;
import me.ashtheking.currency.CurrencyList;

import org.bukkit.plugin.Plugin;


/**
 * MultiCurrency Method implementation.
 *
 * @author Acrobot
 * @copyright (c) 2011
 * @license AOL license <http://aol.nexua.org>
 */
public class MCUR implements Method
{
	private Currency currencyList;

	public Object getPlugin()
	{
		return this.currencyList;
	}

	public String getName()
	{
		return "MultiCurrency";
	}

	public String getVersion()
	{
		return "0.09";
	}

	public int fractionalDigits()
	{
		return -1;
	}

	public String format(double amount)
	{
		return amount + " Currency";
	}

	public boolean hasBanks()
	{
		return false;
	}

	public boolean hasBank(String bank)
	{
		return false;
	}

	public boolean hasAccount(String name)
	{
		return true;
	}

	public boolean hasBankAccount(String bank, String name)
	{
		return false;
	}

	public boolean createAccount(String name)
	{
		CurrencyList.setValue((String)CurrencyList.maxCurrency(name)[0], name, 0);
		return true;
	}

	public boolean createAccount(String name, Double balance)
	{
		CurrencyList.setValue((String)CurrencyList.maxCurrency(name)[0], name, balance);
		return true;
	}

	public MethodAccount getAccount(String name)
	{
		return new MCurrencyAccount(name);
	}

	public MethodBankAccount getBankAccount(String bank, String name)
	{
		return null;
	}

	public boolean isCompatible(Plugin plugin)
	{
		return (plugin.getDescription().getName().equalsIgnoreCase("Currency")
				|| plugin.getDescription().getName().equalsIgnoreCase("MultiCurrency"))
			   && plugin instanceof Currency;
	}

	public void setPlugin(Plugin plugin)
	{
		currencyList = (Currency)plugin;
	}


	public class MCurrencyAccount implements MethodAccount
	{
		private String name;

		public MCurrencyAccount(String name)
		{
			this.name = name;
		}

		public double balance()
		{
			return CurrencyList.getValue((String)CurrencyList.maxCurrency(name)[0], name);
		}

		public boolean set(double amount)
		{
			CurrencyList.setValue((String)CurrencyList.maxCurrency(name)[0], name, amount);
			return true;
		}

		public boolean add(double amount)
		{
			return CurrencyList.add(name, amount);
		}

		public boolean subtract(double amount)
		{
			return CurrencyList.subtract(name, amount);
		}

		public boolean multiply(double amount)
		{
			return CurrencyList.multiply(name, amount);
		}

		public boolean divide(double amount)
		{
			return CurrencyList.divide(name, amount);
		}

		public boolean hasEnough(double amount)
		{
			return CurrencyList.hasEnough(name, amount);
		}

		public boolean hasOver(double amount)
		{
			return CurrencyList.hasOver(name, amount);
		}

		public boolean hasUnder(double amount)
		{
			return CurrencyList.hasUnder(name, amount);
		}

		public boolean isNegative()
		{
			return CurrencyList.isNegative(name);
		}

		public boolean remove()
		{
			return CurrencyList.remove(name);
		}
	}
}