Skip to content

Custom Economy Integration

Jeremiah Osborne edited this page Oct 17, 2023 · 15 revisions

This Documentation only applies to DisplayShops v2.0

To implement your own Economy into DisplayShops, simply create a new instance of the EcoHook class and feed it your currency's case-sensitive name (For this example, Vault is used to show what logic is required):

new EcoHook("Vault") {
    @Override
    public String getSingularName() {return getVaultEconomy().currencyNameSingular();}

    @Override
    public String getPluralName() {return getVaultEconomy().currencyNamePlural();}

    @Override
    public boolean deposit(@NotNull UUID playerUniqueId, double amount) {
        final OfflinePlayer offlinePlayer = INSTANCE.getServer().getOfflinePlayer(playerUniqueId);
        return getVaultEconomy().depositPlayer(offlinePlayer, amount).transactionSuccess();
    }

    @Override
    public boolean deposit(@NotNull OfflinePlayer player, double amount) {
        return getVaultEconomy().depositPlayer(player, amount).transactionSuccess();
    }

    @Override
    public boolean withdraw(@NotNull UUID playerUniqueId, double amount) {
        final OfflinePlayer offlinePlayer = INSTANCE.getServer().getOfflinePlayer(playerUniqueId);
        return getVaultEconomy().withdrawPlayer(offlinePlayer, amount).transactionSuccess();
    }

    @Override
    public boolean withdraw(@NotNull OfflinePlayer player, double amount) {
        return getVaultEconomy().withdrawPlayer(player, amount).transactionSuccess();
    }

    @Override
    public double getBalance(@NotNull UUID playerUniqueId) {
        final OfflinePlayer offlinePlayer = INSTANCE.getServer().getOfflinePlayer(playerUniqueId);
        return getVaultEconomy().getBalance(offlinePlayer);
    }

    @Override
    public double getBalance(@NotNull OfflinePlayer player) {
        return getVaultEconomy().getBalance(player);
    }
};

Configuring Currency Appearance (Optional)

If you would like to configure the Appearance of the currency, such as the symbol or display name, from the code, then override the following methods:

public String getAltName();
public void setAltName(String altName);
public String getSymbol();
public void setSymbol(String symbol);
public int getDecimalPlacement();
public void setDecimalPlacement(int decimalPlacement);
public boolean isRawPlaceholderValue();
public void setRawPlaceholderValue(boolean rawPlaceholderValue);

Alternative

If not done through code, then add your custom currency to the currency-settings section within the config.yml:

currency-settings:
  Vault:
    name: "Money ({symbol})"
    symbol: "$"
    decimal-placement: 2
    raw-placeholder-value: false

Ensure the name, in this case Vault, is set to the name of your custom currency (case-sensitive).

If you would like the currency to be used by default simply set the default-currency-type option to the name of your custom currency in the same config.yml.


That's it! Once this is done, your economy has its own EcoHook injected into the DisplayShops EconomyHandler registry. From this point on, DisplayShops will allow the player to select the economy within their Shop's edit menu as the accepted currency.

Premade injections like PlayerPoints and EcoBits that may have multiple economies can have specific economies specified within a blacklist to prevent them from being used by players for their shops.

In addition, when accomplishing other tasks using the DisplayShops API the following code can be utilized to perform economy calls based on a shop's chosen currency (getBalance() is of course just one of the accessible methods):

EcoHook ecoHook = DisplayShops.getPluginInstance().getEconomyHandler().getEcoHook(shop.getCurrencyType());
if (ecoHook != null) return;

double balance = ecoHook.getBalance(player.getUniqueId());

Currency Removal (Disabling a Currency)

Within the config.yml, the currency's identifier must be added to the currency-blacklist list. Otherwise the currency will remain in rotation and will not function properly if other settings are not present.

For example, if the Vault currency needs to be removed the following would be used within the config.yml:

# Economy currencies within this list will be unavailable for player's to select in their shop's edit menu without permission.
# Preset economy IDs: [ "Vault", "item-for-item", "PlayerPoints" ]
currency-blacklist: [ "Vault" ]

Example Project Code

A Simple Economy Plugin was made showing specifically how to tackle this task.

Wiki

General Help

Configuration

Advanced Help

DisplayShops 2.0

I Need Help!

Clone this wiki locally