Skip to content

Adding CurrencyProviders

Sv3ks edited this page Mar 16, 2023 · 2 revisions

All currencies in HyperCurrencies has a provider, which is responsible for managing the currency and its data. A provider is extending the method CurrencyProvider, and contains two methods; change and get.

Let's start with CurrencyProvider#change.

CurrencyProvider#change returns a boolean value, describing whether or not the change succeed. To know if you should set, add or remove balance, you are given a ChangeType, which is an enum containing one of the three changetypes. The method is also giving you the currency name, the player's uuid and the amount of balance to be changed.

public abstract boolean change(ChangeType type, String name, UUID uuid, double amount);

CurrencyProvider#change syntax

A pretty simple way of using the ChangeType enum is with a switch statement:

@Override
public boolean change(ChangeType type, String name, UUID uuid, double amount) {
    switch (type) {
        case ADD:
            // Add balance
            break;
        case REMOVE:
            // Subtract/remove balance
            break;
        case SET:
            // Set balance
            break;
    }

    return true;
}

Next up is the get method, which is used to get a player's balance (as a double). You given the player's uuid and the name of the currency, the rest is up to you to gather.

Lastly, you need to provide an providerId. The CurrencyProvider class already contains CurrencyProvider#getProviderId, so you only need to set the variable to whatever keyword you would like to be representing your provider. I recommend doing this in a constructor:

public MyProvider() {
    providerId = "myprovider";
}

HyperCurrencies is by default containing two providers, the first one of course being "hypercurrencies", the default provider, and the second one being "vault". To register a provider, use HyperCurrencies.addProvider(new YourProvider()) in your onEnable() class, and at this point it's specially important that your plugin is soft-depending or depending HyperCurrencies, which will make sure HyperCurrencies loads before your plugin.

Introduction

For developers

Clone this wiki locally