Skip to content

Commit d0039d8

Browse files
author
Jan Kluka
committed
1.2
Updated currency api
1 parent 2566c25 commit d0039d8

4 files changed

Lines changed: 36 additions & 24 deletions

File tree

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package dev.drawethree.xprison.api.currency.model;
2+
3+
import org.bukkit.inventory.ItemStack;
4+
5+
public interface PhysicalItemCurrency {
6+
7+
/**
8+
* Gets the configured physical item for this currency, if any.
9+
* This can be used in GUIs or displays to represent the currency visually.
10+
*
11+
* @return The {@link ItemStack} used as the item, or null if not set.
12+
*/
13+
ItemStack getPhysicalItem();
14+
}

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

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
package dev.drawethree.xprison.api.currency.model;
22

3-
import org.bukkit.inventory.ItemStack;
4-
53
/**
64
* Represents the metadata and formatting configuration of a currency in the XPrison API.
75
* This includes display name, format rules, symbol settings, and optional icon.
@@ -17,13 +15,6 @@ public interface XPrisonCurrency {
1715
*/
1816
String getName();
1917

20-
/**
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-
2718
/**
2819
* Gets the maximum amount of a currency player can have
2920
*
@@ -60,14 +51,6 @@ public interface XPrisonCurrency {
6051
*/
6152
String format(double amount);
6253

63-
/**
64-
* Gets the configured physical item for this currency, if any.
65-
* This can be used in GUIs or displays to represent the currency visually.
66-
*
67-
* @return The {@link ItemStack} used as the item, or null if not set.
68-
*/
69-
ItemStack getPhysicalItem();
70-
7154
/**
7255
* Retrieves the custom {@link XPrisonCurrencyHandler} responsible for managing balance operations
7356
* for this currency. If this method returns {@code null}, the currency is assumed to be managed

src/main/java/dev/drawethree/xprison/api/enchants/model/XPrisonEnchantment.java

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package dev.drawethree.xprison.api.enchants.model;
22

3+
import dev.drawethree.xprison.api.XPrisonAPI;
34
import dev.drawethree.xprison.api.currency.model.XPrisonCurrency;
45

56
/**
@@ -89,12 +90,26 @@ public interface XPrisonEnchantment {
8990
void unload();
9091

9192
/**
92-
* Gets the currency used to purchase or upgrade this enchantment.
93+
* Gets the name of the currency used to purchase or upgrade this enchantment.
9394
* <p>
94-
* This defines which type of currency (e.g., Tokens, Gems, Vault/Money)
95-
* will be consumed when a player interacts with this enchant.
95+
* This defines which type of currency (e.g., "Tokens", "Gems", "Vault") will be consumed
96+
* when a player interacts with this enchant. The name should match a registered currency
97+
* in the XPrison currency system.
9698
*
97-
* @return The {@link XPrisonCurrency} implementation representing the currency type.
99+
* @return The name of the currency used for this enchantment.
98100
*/
99-
XPrisonCurrency getCurrency();
101+
String getCurrencyName();
102+
103+
/**
104+
* Retrieves the {@link XPrisonCurrency} instance associated with the currency name returned by {@link #getCurrencyName()}.
105+
* <p>
106+
* This is a convenience method to directly access the currency object via the XPrison API,
107+
* typically used to format amounts, apply caps, or access metadata like display name or symbol.
108+
*
109+
* @return The {@link XPrisonCurrency} instance, or {@code null} if the currency is not registered.
110+
*/
111+
default XPrisonCurrency getCurrency() {
112+
return XPrisonAPI.getInstance().getCurrencyApi().getCurrency(getCurrencyName());
113+
}
114+
100115
}

src/main/java/dev/drawethree/xprison/api/enchants/model/XPrisonEnchantmentBase.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public abstract class XPrisonEnchantmentBase implements XPrisonEnchantment, Refu
3535
protected long baseCost;
3636
protected long increaseCost;
3737
protected XPrisonEnchantmentGuiProperties guiProperties;
38-
protected XPrisonCurrency currency;
38+
protected String currencyName;
3939
protected boolean refundEnabled;
4040
protected int refundGuiSlot;
4141
protected double refundPercentage;
@@ -78,7 +78,7 @@ private void loadBaseProperties(JsonObject config) {
7878
this.maxLevel = JsonUtils.getRequiredInt(config,"maxLevel");
7979
this.baseCost = JsonUtils.getRequiredLong(config, "initialCost");
8080
this.increaseCost = JsonUtils.getRequiredLong(config,"increaseCostBy");
81-
this.currency = XPrisonAPI.getInstance().getCurrencyApi().getCurrency(JsonUtils.getOptionalString(config,"currency", "Tokens"));
81+
this.currencyName = JsonUtils.getOptionalString(config,"currency", "Tokens");
8282

8383
JsonObject refundObject = JsonUtils.getRequiredObject(config,"refund");
8484
this.refundEnabled = JsonUtils.getRequiredBoolean(refundObject,"enabled");

0 commit comments

Comments
 (0)