Skip to content

Economy Display

Info

Available for LabyMod 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

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
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;
    }
}