Custom economy types - LMBishop/MoneyPouch GitHub Wiki

MoneyPouch lets you create your own economy types, so you do not have to rely on your specific economy plugin being supported by MoneyPouch.

There are two ways which you can do this, through MoneyPouch or through your own plugin.

Through MoneyPouch

✔ Advantages ❌ Disadvantages
Simple to do Cannot be used as a currency in /mpshop
No Java knowledge needed Economy plugin must have way of giving money by command
No error checking possible

To add your own economy type, navigate to the directory /plugins/moneypouch/customeconomytype/.

Each .yml file in the above directory is an economy type. The name of the file is its ID and it must be alphanumeric and unique.

The files need to contain the following:

transaction-prize-command: "<command>"

Where <command> is the command to give money. Use %player% as a placeholder for the player's name, and %prize% as a placeholder for the reward.

Warning: ensure the command is correct, should it fail there is no way of MoneyPouch knowing!

An example can be seen here.

In the main config, replace the economy type of your desired pouch with the name of the file, excluding the .yml extension.

pouches:
  tier:
    custom-1:
      ...
      options:
        economytype: "<name of file excluding YML extension>"
      ...

You can also customise the prefix and suffix in the same file, as you would normally do with any other economy.

economy:
  <name of file excluding YML extension>:
    prefix: ""
    suffix: " Diamonds"

You should now see your custom economy listed in /mpa economies

and on any pouches assigned to them in /mpa list

Through your own plugin

✔ Advantages ❌ Disadvantages
Can be used as a currency in /mpshop Java knowledge required

You can import MoneyPouch using Maven via JitPack

<repository>
    <id>jitpack.io</id>
    <url>https://jitpack.io</url>
</repository>

<dependency>
    <groupId>com.github.LMBishop</groupId>
    <artifactId>MoneyPouch</artifactId>
    <version>-SNAPSHOT</version>
<dependency>

Create a new class which extends EconomyType.

The processPayment method is called when a prize needs to be given to a player. Should this transaction fail for any reason, throwing a PaymentFailedException is advisable, for MoneyPouch to log this error.

The doTransaction method is called when a player tries to purcahse a pouch from the shop using your currency. This should return false if the player does not have the funds, or any other error occurs, and true if it is successful.

The toString method is how the economy type will be represented in /mpa list and /mpa economies. You should simply use a human readable version of the currency name.

Example:

package com.leonardobishop.moneypouch.economytype;

import com.leonardobishop.moneypouch.MoneyPouch;
import org.bukkit.entity.Player;

public class XPEconomyType extends EconomyType {

    public XPEconomyType(String prefix, String suffix) {
        super(prefix, suffix);
    }

    @Override
    public void processPayment(Player player, long amount) {
        if (!player.isOnline()) {
            throw new PaymentFailedException("Player is offline!", new AssertionError("Player is offline!"));
        }
        player.giveExp(Integer.parseInt(String.valueOf(amount)));
    }

    @Override
    public boolean doTransaction(Player player, long amount) {
        if (player.getTotalExperience() < amount) {
            return false;
        }
        player.giveExp(Integer.parseInt(String.valueOf(amount)) * -1);
        return true;
    }

    @Override
    public String toString() {
        return "XP";
    }

}

You need to register the economy type with MoneyPouch as the server starts. All pouches are loaded from the config after the server has fully started up, so ensure your economy type is registered before this event as pouches using your economy will default to Invalid if your economy is not registered.

The best place to register with MoneyPouch is during your onEnable. Make sure MoneyPouch is listed as a softdepend to ensure MoneyPouch can accept your registration.

To register your economytype, simply call MoneyPouch#registerEconomyType(String id, EconomyType type), where the id is an alphanumeric and unique ID for your economy type (this is the string used in your MoneyPouch config to specify the economy type), and where type is a new instance of your economy type.

Example:

MoneyPouch moneyPouch = Bukkit.getPlugin("MoneyPouch");
                            // vvvv this string will be used in the config
moneyPouch.registerEconomyType("xp", new XPEconomyType("", " XP"));

Finally, to use your new economy type, set the "economytype" field of desired pouches to the ID you gave earlier

Example

pouches:
  tier:
    custom-1:
      ...
      options:
        economytype: "<ID (in our example it is "xp")>"
      ...
⚠️ **GitHub.com Fallback** ⚠️