Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ jobs:
publish: true
publish-on-discord: false
project-to-publish: "publish"
java-version: "25"
secrets:
MAVEN_USERNAME: ${{ secrets.MAVEN_USERNAME }}
MAVEN_PASSWORD: ${{ secrets.MAVEN_PASSWORD }}
Expand Down
3 changes: 2 additions & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@ dependencies {
compileOnly("com.willfp:EcoBits:1.8.4")
compileOnly("com.bencodez:votingplugin:6.17.2")
compileOnly("com.github.Emibergo02:RedisEconomy:4.3.19")
compileOnly("su.nightexpress.coinsengine:CoinsEngine:2.7.0")
compileOnly("io.lettuce:lettuce-core:6.4.0.RELEASE")
compileOnly("su.nightexpress.excellenteconomy:ExcellentEconomy:2.8.0")

compileOnly("fr.maxlego08.menu:zmenu-api:1.1.0.6")

Expand Down
Binary file modified gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
5 changes: 3 additions & 2 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#Wed Nov 06 13:30:45 CET 2024
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.8-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-9.6.1-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
50 changes: 32 additions & 18 deletions gradlew

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

40 changes: 22 additions & 18 deletions gradlew.bat

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 11 additions & 1 deletion readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ The `Currencies` enum allows easy management of various in-game currencies like
- [zMenu](https://www.spigotmc.org/resources/110402/) - `ZMENUITEMS`
- [EcoBits](https://www.spigotmc.org/resources/109967/) - `ECOBITS`
- [CoinsEngine](https://www.spigotmc.org/resources/84121/) - `COINSENGINE`
- [ExcellentEconomy](https://modrinth.com/plugin/excellenteconomy) - `EXCELLENTEECONOMY`
- [ExcellentEconomy](https://modrinth.com/plugin/excellenteconomy) - `EXCELLENTECONOMY`
- [VotingPlugin](https://www.spigotmc.org/resources/15358/) - `VOTINGPLUGIN`
- [RedisEconomy](https://www.spigotmc.org/resources/105965/) - `REDISECONOMY`
- [RoyaleEconomy](https://polymart.org/product/113/royaleeconomy-1-8-1-21) - `ROYALEECONOMY`
Expand Down Expand Up @@ -92,6 +92,16 @@ Each currency is represented as an enum value in `Currencies`. You can access a
Currencies currency = Currencies.VAULT;
```

### Resolving a Currency from a String

To resolve a currency from a config value (e.g. a string stored in a YAML file), use `Currencies.fromName(String)` instead of `Enum.valueOf`. It redirects deprecated aliases to their canonical constant and logs a one-time warning, so old configs keep working while new ones use the correct name.

```java
Currencies currency = Currencies.fromName("EXCELLENTECONOMY");
```

Note: `EXCELLENTEECONOMY` is a deprecated alias of `EXCELLENTECONOMY` and is only kept for backward compatibility.

### Creating a Provider Instance

The `createProvider` method should be used to instantiate the provider for the following currencies: `ZMENUITEMS`,`ITEM`,. You must pass the appropriate parameters that match the expected types for each specific provider class.
Expand Down
37 changes: 36 additions & 1 deletion src/main/java/fr/traqueur/currencies/Currencies.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@
import java.math.BigDecimal;
import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import java.util.UUID;

/**
Expand Down Expand Up @@ -80,7 +82,14 @@ public enum Currencies {
/**
* The currency ExcellentEconomy from the plugin ExcellentEconomy (new name for CraftEngine)
*/
EXCELLENTEECONOMY("ExcellentEconomy", ExcellentEconomyProvider.class, true, true)
EXCELLENTECONOMY("ExcellentEconomy", ExcellentEconomyProvider.class, true, true),
/**
* @deprecated Use {@link #EXCELLENTECONOMY} instead. Kept so old code and configs
* referencing {@code EXCELLENTEECONOMY} keep working. Will be removed
* in a future version.
*/
@Deprecated
EXCELLENTEECONOMY("ExcellentEconomy", ExcellentEconomyProvider.class, true, true, EXCELLENTECONOMY)
;

static {
Expand All @@ -92,6 +101,8 @@ public enum Currencies {
private final boolean autoCreate;
private final boolean currencySpecific;
private final Map<String, CurrencyProvider> providers;
private final Currencies renamedTo;
private static final Set<String> WARNED_DEPRECATED = new HashSet<>();

Currencies(String name, Class<? extends CurrencyProvider> providerClass) {
this(name, providerClass, true, false);
Expand All @@ -102,11 +113,35 @@ public enum Currencies {
}

Currencies(String name, Class<? extends CurrencyProvider> providerClass, boolean autoCreate, boolean currencySpecific) {
this(name, providerClass, autoCreate, currencySpecific, null);
}

Currencies(String name, Class<? extends CurrencyProvider> providerClass, boolean autoCreate, boolean currencySpecific, Currencies renamedTo) {
this.name = name;
this.providerClass = providerClass;
this.autoCreate = autoCreate;
this.providers = new HashMap<>();
this.currencySpecific = currencySpecific;
this.renamedTo = renamedTo;
}

/**
* Resolve a currency by its name, redirecting deprecated aliases to their canonical
* constant while logging a one-time warning.
*
* @param name The name of the currency (e.g. {@code "VAULT"}, {@code "EXCELLENTECONOMY"}).
* @return The canonical currency.
* @throws IllegalArgumentException if the name is unknown.
*/
public static Currencies fromName(String name) {
Currencies currency = Currencies.valueOf(name);
if (currency.renamedTo != null) {
if (WARNED_DEPRECATED.add(name)) {
Bukkit.getLogger().warning("The currency name '" + name + "' is deprecated, use '" + currency.renamedTo.name() + "' instead.");
}
return currency.renamedTo;
}
return currency;
}

/**
Expand Down
Loading