Skip to content

Commit 21ee098

Browse files
author
Jan Kluka
committed
1.2
Updated currency api
1 parent 5c3961b commit 21ee098

File tree

3 files changed

+84
-112
lines changed

3 files changed

+84
-112
lines changed

src/main/java/dev/drawethree/xprison/api/currency/XPrisonCurrencyAPI.java

Lines changed: 54 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,16 @@
11
package dev.drawethree.xprison.api.currency;
22

3+
import dev.drawethree.xprison.api.currency.enums.LostCause;
4+
import dev.drawethree.xprison.api.currency.enums.ReceiveCause;
35
import dev.drawethree.xprison.api.currency.model.XPrisonCurrency;
6+
import org.bukkit.OfflinePlayer;
47

58
import java.util.Collection;
69

7-
/**
8-
* API for interacting with XPrison's currency system.
9-
* <p>
10-
* Allows external plugins to register new currencies or retrieve existing ones.
11-
*/
1210
public interface XPrisonCurrencyAPI {
1311

1412
/**
1513
* Registers a new custom currency to the system.
16-
* <p>
1714
* If a currency with the same name (case-insensitive) already exists, it will be overwritten.
1815
*
1916
* @param currency The {@link XPrisonCurrency} implementation to register.
@@ -34,4 +31,55 @@ public interface XPrisonCurrencyAPI {
3431
* @return A collection of all {@link XPrisonCurrency} objects.
3532
*/
3633
Collection<XPrisonCurrency> getAllCurrencies();
34+
35+
/**
36+
* Gets the current amount of a specific currency for the specified player.
37+
*
38+
* @param player The player whose balance to retrieve.
39+
* @param currencyName The currency to check.
40+
* @return The amount of currency the player currently has.
41+
*/
42+
double getBalance(OfflinePlayer player, String currencyName);
43+
44+
/**
45+
* Adds a specified amount of a specific currency to the player's balance.
46+
*
47+
* @param player The player to add currency to.
48+
* @param currencyName The currency to add.
49+
* @param amount The amount to add.
50+
* @param receiveCause The reason for receiving the currency.
51+
* @return true if added successfully, false otherwise.
52+
*/
53+
boolean addBalance(OfflinePlayer player, String currencyName, double amount, ReceiveCause receiveCause);
54+
55+
/**
56+
* Removes a specified amount of a specific currency from the player's balance.
57+
*
58+
* @param player The player to remove currency from.
59+
* @param currencyName The currency to remove.
60+
* @param amount The amount to remove.
61+
* @param lostCause The reason for removing the currency.
62+
* @return true if removed successfully, false otherwise.
63+
*/
64+
boolean removeBalance(OfflinePlayer player, String currencyName, double amount, LostCause lostCause);
65+
66+
/**
67+
* Sets the balance of a specific currency for the player.
68+
*
69+
* @param player The player whose balance to set.
70+
* @param currencyName The currency to set.
71+
* @param amount The amount to set.
72+
* @return true if set successfully, false otherwise.
73+
*/
74+
boolean setBalance(OfflinePlayer player, String currencyName, double amount);
75+
76+
/**
77+
* Checks if the player has at least the specified amount of the given currency.
78+
*
79+
* @param player The player to check.
80+
* @param currencyName The currency to check.
81+
* @param amount The minimum amount required.
82+
* @return true if player has enough, false otherwise.
83+
*/
84+
boolean has(OfflinePlayer player, String currencyName, double amount);
3785
}

src/main/java/dev/drawethree/xprison/api/currency/model/AbstractXPrisonCurrency.java

Lines changed: 0 additions & 65 deletions
This file was deleted.
Lines changed: 30 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,74 +1,63 @@
11
package dev.drawethree.xprison.api.currency.model;
22

3-
import dev.drawethree.xprison.api.currency.enums.LostCause;
4-
import dev.drawethree.xprison.api.currency.enums.ReceiveCause;
5-
import org.bukkit.OfflinePlayer;
3+
import org.bukkit.inventory.ItemStack;
64

75
/**
8-
* Represents a generic currency system in the XPrison API.
6+
* Represents the metadata and formatting configuration of a currency in the XPrison API.
7+
* This includes display name, format rules, symbol settings, and optional icon.
98
* <p>
10-
* This interface abstracts common currency operations such as querying,
11-
* adding, removing, and setting balances for players. Implementations
12-
* could represent different currency types like Tokens, Gems, Money, etc.
13-
* <p>
14-
* Methods that modify balances return a boolean indicating whether the
15-
* operation was successful (e.g., not blocked, not insufficient funds, etc.).
9+
* Currency balance operations are handled by a separate CurrencyService.
1610
*/
1711
public interface XPrisonCurrency {
1812

1913
/**
20-
* Gets the name of this currency.
21-
* <p>
22-
* This is typically used for display purposes, configuration keys,
23-
* or to distinguish between multiple currency types (e.g., "Tokens", "Gems", "Money").
14+
* Gets the internal ID or key of the currency (e.g., "money", "tokens").
2415
*
25-
* @return The name of the currency.
16+
* @return The unique name of this currency.
2617
*/
2718
String getName();
2819

2920
/**
30-
* Gets the current amount of this currency for the specified player.
21+
* Gets the starting amount of a currency
22+
*
23+
* @return The amount each player will have on first join
24+
*/
25+
double getStartingAmount();
26+
27+
/**
28+
* Gets the display name of the currency (e.g., "Money", "Tokens").
3129
*
32-
* @param player The player (offline or online) whose balance to retrieve.
33-
* @return The amount of currency the player currently has.
30+
* @return The friendly display name of the currency.
3431
*/
35-
double getBalance(OfflinePlayer player);
32+
String getDisplayName();
3633

3734
/**
38-
* Adds a specified amount of currency to the player's balance.
35+
* Gets the prefix of the currency (e.g., "$").
3936
*
40-
* @param player The player to add currency to.
41-
* @param amount The amount of currency to add.
42-
* @param receiveCause Why currency was added
43-
* @return true if the currency was successfully added, false otherwise.
37+
* @return The friendly display name of the currency.
4438
*/
45-
boolean addBalance(OfflinePlayer player, double amount, ReceiveCause receiveCause);
39+
String getPrefix();
4640

4741
/**
48-
* Removes a specified amount of currency from the player's balance.
42+
* Gets the suffix of the currency.
4943
*
50-
* @param player The player to remove currency from.
51-
* @param amount The amount of currency to remove.
52-
* @param lostCause Why currency was lost
53-
* @return true if the currency was successfully removed, false (e.g., insufficient funds) otherwise.
44+
* @return The friendly display name of the currency.
5445
*/
55-
boolean removeBalance(OfflinePlayer player, double amount, LostCause lostCause);
46+
String getSuffix();
5647

5748
/**
58-
* Sets the player's currency balance to a new specified amount.
49+
* Formats a raw double value according to the currency's configuration.
5950
*
60-
* @param player The player whose balance to set.
61-
* @param amount The new amount to set.
62-
* @return true if the balance was successfully set, false otherwise.
51+
* @param amount The amount to format.
52+
* @return The formatted currency string (e.g., "$1.2k", "$3,000").
6353
*/
64-
boolean setBalance(OfflinePlayer player, double amount);
54+
String format(double amount);
6555

6656
/**
67-
* Checks if the specified player has at least the given amount of this currency.
57+
* Gets the configured physical item for this currency, if any.
58+
* This can be used in GUIs or displays to represent the currency visually.
6859
*
69-
* @param player The player whose balance to check.
70-
* @param amount The minimum amount to verify.
71-
* @return true if the player has at least the specified amount, false otherwise.
60+
* @return The {@link ItemStack} used as the item, or null if not set.
7261
*/
73-
boolean has(OfflinePlayer player, double amount);
62+
ItemStack getPhysicalItem();
7463
}

0 commit comments

Comments
 (0)