Skip to content

Commit af3c132

Browse files
committed
Reintroduced toBuilder method in Currency
Added a `toBuilder` method to the `Currency` interface and implemented it in `WrappedCurrency` using a `NoOpBuilder`. This allows modification or reconstruction of a `Currency` instance.
1 parent 7da4eef commit af3c132

File tree

2 files changed

+78
-0
lines changed

2 files changed

+78
-0
lines changed

plugin/src/main/java/net/thenextlvl/service/wrapper/service/model/WrappedCurrency.java

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,14 @@
33
import net.kyori.adventure.text.Component;
44
import net.milkbowl.vault.economy.Economy;
55
import net.thenextlvl.service.api.economy.currency.Currency;
6+
import org.jetbrains.annotations.Unmodifiable;
67
import org.jspecify.annotations.NullMarked;
8+
import org.jspecify.annotations.Nullable;
79

810
import java.util.Locale;
11+
import java.util.Map;
912
import java.util.Optional;
13+
import java.util.OptionalInt;
1014
import java.util.function.Consumer;
1115

1216
@NullMarked
@@ -51,4 +55,71 @@ public int getFractionalDigits() {
5155
public boolean editCurrency(Consumer<Builder> consumer) {
5256
return false;
5357
}
58+
59+
@Override
60+
public Builder toBuilder() {
61+
return new NoOpBuilder(economy);
62+
}
63+
64+
private record NoOpBuilder(Economy economy) implements Builder {
65+
@Override
66+
public Builder name(String name) {
67+
return this;
68+
}
69+
70+
@Override
71+
public String name() {
72+
return economy.getName();
73+
}
74+
75+
@Override
76+
public @Unmodifiable Map<Locale, Component> displayNamesSingular() {
77+
return Map.of();
78+
}
79+
80+
@Override
81+
public Builder displayNameSingular(Locale locale, @Nullable Component name) {
82+
return this;
83+
}
84+
85+
@Override
86+
public Optional<Component> displayNameSingular(Locale locale) {
87+
return Optional.empty();
88+
}
89+
90+
@Override
91+
public @Unmodifiable Map<Locale, Component> displayNamesPlural() {
92+
return Map.of();
93+
}
94+
95+
@Override
96+
public Builder displayNamePlural(Locale locale, @Nullable Component name) {
97+
return this;
98+
}
99+
100+
@Override
101+
public Optional<Component> displayNamePlural(Locale locale) {
102+
return Optional.empty();
103+
}
104+
105+
@Override
106+
public Builder symbol(@Nullable Component symbol) {
107+
return this;
108+
}
109+
110+
@Override
111+
public Optional<Component> symbol() {
112+
return Optional.empty();
113+
}
114+
115+
@Override
116+
public Builder fractionalDigits(@Nullable Integer fractionalDigits) throws IllegalArgumentException {
117+
return this;
118+
}
119+
120+
@Override
121+
public OptionalInt fractionalDigits() {
122+
return OptionalInt.of(economy.fractionalDigits());
123+
}
124+
}
54125
}

src/main/java/net/thenextlvl/service/api/economy/currency/Currency.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,13 @@ default Component format(Number amount, Audience audience) {
115115
*/
116116
boolean editCurrency(Consumer<Builder> consumer) throws IllegalArgumentException;
117117

118+
/**
119+
* Converts the current {@code Currency} instance into a {@code Builder} for modification or reconstruction.
120+
*
121+
* @return a {@code Builder} instance initialized with the properties of the current {@code Currency}
122+
*/
123+
Builder toBuilder();
124+
118125
/**
119126
* A builder interface for constructing instances of {@link Currency}.
120127
* The {@code Builder} allows for the configuration of currency properties such as

0 commit comments

Comments
 (0)