CurrencyHandler

CurrencyHandler

CurrencyHandler is a Economy API that features support for more than just money.

Plugins can register their own currencies (e.g. own Levels), which can be used by every other plugin, without knowing the registering plugin. This allows plugins to be expandable without any code change on their side.

Metrics

This plugin utilises Hidendra's plugin metrics system. You can opt-out under <yourPluginFolder>/PluginMetrics/config.yml

The following informations will be collected:

  • A unique identifier
  • The server's version of Java
  • Whether the server is in offline or online mode
  • The plugin's version
  • The server's implementation and game version
  • The OS version/name and architecture
  • The core count for the CPU
  • The number of players online
  • The Metrics version
  • Your online-mode
  • Your server location
  • The keys of your registered currencies

Handlers

Every handler need a own input format. The handler author needs to specify this format in their documentation.

This plugin itself provides 5 default handlers.

Default Handlers

Money (requires Vault)
key: money
input format: any number

Food
key: food
input format: integer

Health
key: health
input format: integer

Enchantment Level
key: enchantlevel
input format: integer

Item
key: item
input format: list with entryformat "<itemid>:<itemdata> <amount>" or "<itemid> <amount>"


Usage as Admin

Usually you don't have to do more than putting the .jar into you plugins folder. However, you can deactivate the default handler via the config.yml.

All other things are handled by other plugins and their config files.


Usage as Developer

(You should take a look at the source code, this section is not very well written yet.)

Use currencies

To check if a Handler is stored use the static CurrencyHandler.hasHandler(String key). To get a Handler object use the static method CurrencyHandler.getHandler(String key).

For the usage of Handler objects scroll down to the HandlerInterface section.

Register currencies

To register a new currency you need to call the static method CurrencyHandler.registerHandler(String key, Handler handler), where the handler is a instance of a class, which implements the Handler interface specified below. Try to make your key as unique as possible (or simply configurable) to avoid conflicts with other plugins.

Handler Interface
public interface Handler
{
    /**
     * Check if a player owns enough of the handled currency
     * 
     * @param holder the "owner" of the currency
     * @param amount the amount of the handled currency
     * @return true if the amount of the handled currency is greater or equal
     *         the amount, false if not or when one of the input parameters does not match the requirements of the Handler
     */
    public abstract boolean hasCurrency(Object holder, Object amount);
    
    /**
     * Withdraw an amount of the handled currency from a player
     * If one of the input parameter does not match the requirements, nothing will happen.
     * 
     * @param holder the "owner" of the currency
     * @param amount the amount of the handled currency
     */
    public abstract void withdrawCurrency(Object holder, Object amount);
    
    /**
     * Give an amount of the handled currency to a player
     * If one of the input parameter does not match the requirements, nothing will happen.
     * 
     * @param holder the "owner" of the currency
     * @param amount the amount of the handled currency
     */
    public abstract void giveCurrency(Object holder, Object amount);
    
    /**
     * Set the amount of the handled currency to a player
     * If one of the input parameter does not match the requirements, nothing will happen.
     * 
     * @param holder the "owner" of the currency
     * @param amount the amount of the handled currency
     * @throws UnsupportedOperationException when a handler does not support this
     */
    public abstract void setCurrency(Object holder, Object amount) throws UnsupportedOperationException;
    
    /**
     * Get a string, which describes the given object
     * If one of the input parameter does not match the requirements, nothing will happen.
     * 
     * @param value the object that needs to be formated
     * @return the String, after the handler's format
     */
    public abstract String getFormatedString(Object value);
    
    /**
     * Get the name of the currency.
     * 
     * @return the name of the currency as String
     */
    public abstract String getCurrencyName();
    
    /**
     * Check if the given Object is usable by this handler.
     * It's advised to check this method before interacting with the handler.
     * 
     * @param obj the object that needs to be checked
     * @return true if the object can be used as amount by this handler, false if not
     */
    public abstract boolean checkInputObject(Object obj);
    
    /**
     * Check if the given Object is usable as holder by this handler.
     * It's advised to check this method before interacting with the handler.
     * 
     * @param obj the object that needs to be checked
     * @return true if the object can be used as holder by this handler, false if not
     */
    public abstract boolean checkInputHolder(Object obj);
}

Source Code

GitHub


Comments

Posts Quoted:
Reply
Clear All Quotes

About This Project

Categories

Members

Recent Files