001/* This file is part of Vault.
002
003    Vault is free software: you can redistribute it and/or modify
004    it under the terms of the GNU Lesser General Public License as published by
005    the Free Software Foundation, either version 3 of the License, or
006    (at your option) any later version.
007
008    Vault is distributed in the hope that it will be useful,
009    but WITHOUT ANY WARRANTY; without even the implied warranty of
010    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
011    GNU Lesser General Public License for more details.
012
013    You should have received a copy of the GNU Lesser General Public License
014    along with Vault.  If not, see <http://www.gnu.org/licenses/>.
015 */
016
017package net.milkbowl.vault.economy;
018
019import java.util.List;
020
021/**
022 * The main economy API
023 *
024 */
025public interface Economy {
026
027    /**
028     * Checks if economy method is enabled.
029     * @return Success or Failure
030     */
031    public boolean isEnabled();
032
033    /**
034     * Gets name of economy method
035     * @return Name of Ecoomy Method
036     */
037    public String getName();
038
039    /**
040     * Returns true if the given implementation supports banks.
041     * @return true if the implementation supports banks
042     */
043    public boolean hasBankSupport();
044
045    /**
046     * Some economy plugins round off after a certain number of digits.
047     * This function returns the number of digits the plugin keeps
048     * or -1 if no rounding occurs.
049     * @return number of digits after the decimal point kept
050     */
051    public int fractionalDigits();
052
053    /**
054     * Format amount into a human readable String This provides translation into
055     * economy specific formatting to improve consistency between plugins.  
056     *
057     * @param amount to format
058     * @return Human readable string describing amount
059     */
060    public String format(double amount);
061
062    /**
063     * Returns the name of the currency in plural form.
064     * If the economy being used does not support currency names then an empty string will be returned.
065     * 
066     * @return name of the currency (plural)
067     */
068    public String currencyNamePlural();
069
070
071    /**
072     * Returns the name of the currency in singular form.
073     * If the economy being used does not support currency names then an empty string will be returned.
074     * 
075     * @return name of the currency (singular)
076     */
077    public String currencyNameSingular();
078
079    /**
080     * Checks if this player has an account on the server yet
081     * This will always return true if the player has joined the server at least once
082     * as all major economy plugins auto-generate a player account when the player joins the server
083     * 
084     * @param playerName to check
085     * @return if the player has an account
086     */
087    public boolean hasAccount(String playerName);
088
089    /**
090     * Checks if this player has an account on the server yet on the given world
091     * This will always return true if the player has joined the server at least once
092     * as all major economy plugins auto-generate a player account when the player joins the server
093     * 
094     * @param playerName to check in the world
095     * @param worldName world-specific account
096     * @return if the player has an account
097     */
098    public boolean hasAccount(String playerName, String worldName);
099
100    /**
101     * Gets balance of a player
102     * 
103     * @param playerName of the player
104     * @return Amount currently held in players account
105     */
106    public double getBalance(String playerName);
107    
108    /**
109     * Gets balance of a player on the specified world.
110     * IMPLEMENTATION SPECIFIC - if an economy plugin does not support this the global balance will be returned.
111     * @param playerName
112     * @param world name of the world
113     * @return Amount currently held in players account
114     */
115    public double getBalance(String playerName, String world);
116
117    /**
118     * Checks if the player account has the amount - DO NOT USE NEGATIVE AMOUNTS
119     * 
120     * @param playerName to check
121     * @param amount to check for
122     * @return True if <b>playerName</b> has <b>amount</b>, False else wise
123     */
124    public boolean has(String playerName, double amount);
125    
126    /**
127     * Checks if the player account has the amount in a given world - DO NOT USE NEGATIVE AMOUNTS
128     * IMPLEMENTATION SPECIFIC - if an economy plugin does not support this the global balance will be returned.
129     * 
130     * @param playerName to check
131     * @param worldName to check with
132     * @param amount to check for
133     * @return True if <b>playerName</b> has <b>amount</b>, False else wise
134     */
135    public boolean has(String playerName, String worldName, double amount);
136    
137    /**
138     * Withdraw an amount from a player - DO NOT USE NEGATIVE AMOUNTS
139     * 
140     * @param playerName Name of player
141     * @param amount Amount to withdraw
142     * @return Detailed response of transaction
143     */
144    public EconomyResponse withdrawPlayer(String playerName, double amount);
145
146    /**
147     * Withdraw an amount from a player on a given world - DO NOT USE NEGATIVE AMOUNTS
148     * IMPLEMENTATION SPECIFIC - if an economy plugin does not support this the global balance will be returned.
149     * @param playerName Name of player
150     * @param worldName - name of the world
151     * @param amount Amount to withdraw
152     * @return Detailed response of transaction
153     */
154    public EconomyResponse withdrawPlayer(String playerName, String worldName, double amount);
155    
156    /**
157     * Deposit an amount to a player - DO NOT USE NEGATIVE AMOUNTS
158     * 
159     * @param playerName Name of player
160     * @param amount Amount to deposit
161     * @return Detailed response of transaction
162     */
163    public EconomyResponse depositPlayer(String playerName, double amount);
164
165    /**
166     * Deposit an amount to a player - DO NOT USE NEGATIVE AMOUNTS
167     * IMPLEMENTATION SPECIFIC - if an economy plugin does not support this the global balance will be returned.
168     * @param playerName Name of player
169     * @param amount Amount to deposit
170     * @return Detailed response of transaction
171     */
172    public EconomyResponse depositPlayer(String playerName, String worldName, double amount);
173   
174    /**
175     * Creates a bank account with the specified name and the player as the owner
176     * @param name of account
177     * @param player the account should be linked to
178     * @return EconomyResponse Object
179     */
180    public EconomyResponse createBank(String name, String player);
181
182    /**
183     * Deletes a bank account with the specified name.
184     * @param name of the back to delete
185     * @return if the operation completed successfully
186     */
187    public EconomyResponse deleteBank(String name);
188
189    /**
190     * Returns the amount the bank has
191     * @param name of the account
192     * @return EconomyResponse Object
193     */
194    public EconomyResponse bankBalance(String name);
195
196    /**
197     * Returns true or false whether the bank has the amount specified - DO NOT USE NEGATIVE AMOUNTS
198     * 
199     * @param name of the account
200     * @param amount to check for
201     * @return EconomyResponse Object
202     */
203    public EconomyResponse bankHas(String name, double amount);
204
205    /**
206     * Withdraw an amount from a bank account - DO NOT USE NEGATIVE AMOUNTS
207     * 
208     * @param name of the account
209     * @param amount to withdraw
210     * @return EconomyResponse Object
211     */
212    public EconomyResponse bankWithdraw(String name, double amount);
213
214    /**
215     * Deposit an amount into a bank account - DO NOT USE NEGATIVE AMOUNTS
216     * 
217     * @param name of the account
218     * @param amount to deposit
219     * @return EconomyResponse Object
220     */
221    public EconomyResponse bankDeposit(String name, double amount);
222
223    /**
224     * Check if a player is the owner of a bank account
225     * 
226     * @param name of the account
227     * @param playerName to check for ownership
228     * @return EconomyResponse Object
229     */
230    public EconomyResponse isBankOwner(String name, String playerName);
231
232    /**
233     * Check if the player is a member of the bank account
234     * 
235     * @param name of the account
236     * @param playerName to check membership
237     * @return EconomyResponse Object
238     */
239    public EconomyResponse isBankMember(String name, String playerName);
240
241    /**
242     * Gets the list of banks
243     * @return the List of Banks
244     */
245    public List<String> getBanks();
246
247    /**
248     * Attempts to create a player account for the given player
249     * @return if the account creation was successful
250     */
251    public boolean createPlayerAccount(String playerName);
252    
253    /**
254     * Attempts to create a player account for the given player on the specified world
255     * IMPLEMENTATION SPECIFIC - if an economy plugin does not support this the global balance will be returned.
256     * @return if the account creation was successful
257     */
258    public boolean createPlayerAccount(String playerName, String worldName);
259}