Skip to content

Commit 8f4c0cd

Browse files
authored
Merge pull request #52 from TheNextLvl-net/renovate/net.thenextlvl.core-i18n-3.x
fix(deps): update dependency net.thenextlvl.core:i18n to v3
2 parents d26736f + e149c15 commit 8f4c0cd

4 files changed

Lines changed: 25 additions & 21 deletions

File tree

build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ dependencies {
3131
compileOnly("io.papermc.paper:paper-api:1.21.5-R0.1-SNAPSHOT")
3232
compileOnly("net.thenextlvl.services:service-io:2.2.0")
3333

34-
implementation("net.thenextlvl.core:i18n:1.0.21")
34+
implementation("net.thenextlvl.core:i18n:3.2.0")
3535
implementation("net.thenextlvl.core:files:3.0.0")
3636
implementation("net.thenextlvl.core:paper:2.1.1")
3737
implementation("org.bstats:bstats-bukkit:3.1.0")

src/main/java/net/thenextlvl/economist/EconomistPlugin.java

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import core.i18n.file.ComponentBundle;
55
import core.io.IO;
66
import io.papermc.paper.plugin.lifecycle.event.types.LifecycleEvents;
7+
import net.kyori.adventure.key.Key;
78
import net.kyori.adventure.text.minimessage.MiniMessage;
89
import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder;
910
import net.kyori.adventure.text.minimessage.tag.resolver.TagResolver;
@@ -30,6 +31,7 @@
3031
import org.jspecify.annotations.NullMarked;
3132

3233
import java.io.File;
34+
import java.nio.file.Path;
3335
import java.sql.SQLException;
3436
import java.util.List;
3537
import java.util.Locale;
@@ -44,21 +46,20 @@ public class EconomistPlugin extends JavaPlugin {
4446
new PluginConfig()
4547
).validate().save().getRoot();
4648

47-
private final File translations = new File(getDataFolder(), "translations");
48-
49-
private final ComponentBundle bundle = new ComponentBundle(translations,
50-
audience -> audience instanceof Player player ? player.locale() : Locale.US)
51-
.register("economist", Locale.US)
52-
.register("economist_german", Locale.GERMANY)
53-
.miniMessage(bundle -> MiniMessage.builder().tags(TagResolver.resolver(
54-
TagResolver.standard(),
55-
Placeholder.component("prefix", bundle.component(Locale.US, "prefix"))
56-
)).build());
57-
58-
private final ComponentBundle abbreviations = new ComponentBundle(translations,
59-
audience -> audience instanceof Player player ? player.locale() : Locale.US)
60-
.register("abbreviations", Locale.US)
61-
.register("abbreviations_german", Locale.GERMANY);
49+
private final Key abbreviationsKey = Key.key("economist", "translations");
50+
private final Key translationsKey = Key.key("economist", "translations");
51+
private final Path translations = getDataPath().resolve("translations");
52+
53+
private final ComponentBundle bundle = ComponentBundle.builder(translationsKey, translations)
54+
.placeholder("prefix", "prefix")
55+
.resource("economist", Locale.US)
56+
.resource("economist_german", Locale.GERMANY)
57+
.build();
58+
59+
private final ComponentBundle abbreviations = ComponentBundle.builder(abbreviationsKey, translations)
60+
.resource("abbreviations", Locale.US)
61+
.resource("abbreviations_german", Locale.GERMANY)
62+
.build();
6263

6364
private final EconomistBankController bankController = new EconomistBankController(this);
6465
private final EconomistEconomyController economyController = new EconomistEconomyController(this);

src/main/java/net/thenextlvl/economist/controller/Abbreviation.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package net.thenextlvl.economist.controller;
22

3+
import net.kyori.adventure.text.serializer.plain.PlainTextComponentSerializer;
34
import net.thenextlvl.economist.EconomistPlugin;
45
import org.bukkit.plugin.java.JavaPlugin;
56
import org.jspecify.annotations.NullMarked;
@@ -155,8 +156,9 @@ static String format(double amount, NumberFormat format, Locale locale) {
155156
.max((entry, other) -> entry.getKey().compareTo(other.getKey()))
156157
.map(entry -> {
157158
var prefix = negative ? "-" : "";
158-
var abbreviation = plugin.abbreviations().format(locale, entry.getValue());
159+
var translation = plugin.abbreviations().component(entry.getValue(), locale);
159160
var formatted = format.format(positive / entry.getKey().doubleValue());
161+
var abbreviation = PlainTextComponentSerializer.plainText().serialize(translation);
160162
return prefix + formatted + abbreviation;
161163
}).orElseGet(() -> format.format(amount));
162164
}

src/main/java/net/thenextlvl/economist/controller/EconomistEconomyController.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package net.thenextlvl.economist.controller;
22

3+
import net.kyori.adventure.text.serializer.plain.PlainTextComponentSerializer;
34
import net.thenextlvl.economist.EconomistPlugin;
45
import net.thenextlvl.economist.api.Account;
56
import net.thenextlvl.economist.api.EconomyController;
@@ -75,14 +76,14 @@ private DataController dataController() {
7576

7677
@Override
7778
public String getCurrencyNamePlural(Locale locale) {
78-
var format = plugin.bundle().format(locale, "currency.name.plural");
79-
return format != null ? format : "currency.name.plural";
79+
var translation = plugin.bundle().component("currency.name.plural", locale);
80+
return PlainTextComponentSerializer.plainText().serialize(translation);
8081
}
8182

8283
@Override
8384
public String getCurrencyNameSingular(Locale locale) {
84-
var format = plugin.bundle().format(locale, "currency.name.singular");
85-
return format != null ? format : "currency.name.singular";
85+
var translation = plugin.bundle().component("currency.name.singular", locale);
86+
return PlainTextComponentSerializer.plainText().serialize(translation);
8687
}
8788

8889
@Override

0 commit comments

Comments
 (0)