Skip to content

Economy Display

Warning

Not yet available in LabyMod 4! Only available for LabyMod 3 users with version greater than 3.7.4

Overview

It is also possible to display the balance of your economy system. If the user enters a shop or is in a trading situation, you can display the amount of the balance in the top right corner. You can also use this feature in games if you have to collect coins.

economy

The balance update has a smooth transition:

economy

Requirements

Example code

public void update() {
    updateBalanceDisplay(EnumBalanceType.CASH, true, 20);
    updateBalanceDisplay(EnumBalanceType.BANK, true, 10000);
}

/**
 * Just send this packet to update the value of the balance or to show/hide it
 */
public void updateBalanceDisplay( Player player, EnumBalanceType type, boolean visible, int balance ) {
    JsonObject economyObject = new JsonObject();
    JsonObject cashObject = new JsonObject();

    // Visibility
    cashObject.addProperty( "visible", visible );

    // Amount
    cashObject.addProperty( "balance", balance );

    /*
    // Icon (Optional)
    cashObject.addProperty( "icon", "<url to image>" );

    // Decimal number (Optional)    
    JsonObject decimalObject = new JsonObject();
    decimalObject.addProperty("format", "##.##"); // Decimal format
    decimalObject.addProperty("divisor", 100); // The value that divides the balance
    cashObject.add( "decimal", decimalObject );
    */

    // The display type can be "cash" or "bank".
    economyObject.add(type.getKey(), cashObject);

    // Send to LabyMod using the API
    LabyModProtocol.sendLabyModMessage( player, "economy", economyObject );
}

public enum EnumBalanceType {
    CASH("cash"),
    BANK("bank");

    private final String key;

    EnumBalanceType(String key) {
        this.key = key;
    }

    public String getKey() {
        return this.key;
    }
}