Skip to content

Commit 3952794

Browse files
committed
Impl Reserve's multi-currency support
1 parent 920ddf4 commit 3952794

File tree

1 file changed

+11
-15
lines changed

1 file changed

+11
-15
lines changed

src/main/java/org/maxgamer/quickshop/economy/Economy_Reserve.java

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -70,15 +70,12 @@ public Economy_Reserve(@NotNull QuickShop plugin) {
7070
setup();
7171
}
7272

73-
/**
74-
* @deprecated Reserve no-longer active after Minecraft 1.14.
75-
*/
7673
@SuppressWarnings("ConstantConditions")
77-
@Deprecated
7874
private void setup() {
7975
try {
80-
if (((Reserve) plugin.getServer().getPluginManager().getPlugin("Reserve")).economyProvided()) {
81-
reserve = ((Reserve) plugin.getServer().getPluginManager().getPlugin("Reserve")).economy();
76+
Reserve re = ((Reserve) plugin.getServer().getPluginManager().getPlugin("Reserve"));
77+
if (re.economyProvided()) {
78+
reserve = re.economy();
8279
}
8380
} catch (Exception throwable) {
8481
reserve = null;
@@ -97,7 +94,7 @@ private void setup() {
9794
@Override
9895
public boolean deposit(@NotNull UUID name, double amount, @NotNull World world, @Nullable String currency) {
9996
try {
100-
return Objects.requireNonNull(reserve).addHoldings(name, new BigDecimal(amount));
97+
return Objects.requireNonNull(reserve).addHoldings(name, new BigDecimal(amount), world.getName(), currency);
10198
} catch (Exception throwable) {
10299
plugin.getSentryErrorReporter().ignoreThrow();
103100
plugin.getLogger().log(Level.WARNING, errorMsg, throwable);
@@ -121,7 +118,7 @@ public boolean deposit(@NotNull OfflinePlayer trader, double amount, @NotNull Wo
121118
@Override
122119
public String format(double balance, @NotNull World world, @Nullable String currency) {
123120
try {
124-
return Objects.requireNonNull(reserve).format(new BigDecimal(balance));
121+
return Objects.requireNonNull(reserve).format(new BigDecimal(balance), world.getName(), currency);
125122
} catch (Exception throwable) {
126123
plugin.getSentryErrorReporter().ignoreThrow();
127124
plugin.getLogger().log(Level.WARNING, errorMsg, throwable);
@@ -148,7 +145,7 @@ private String formatInternal(double balance) {
148145
@Deprecated
149146
public double getBalance(@NotNull UUID name, @NotNull World world, @Nullable String currency) {
150147
try {
151-
return Objects.requireNonNull(reserve).getHoldings(name).doubleValue();
148+
return Objects.requireNonNull(reserve).getHoldings(name, world.getName(), currency).doubleValue();
152149
} catch (Exception throwable) {
153150
plugin.getSentryErrorReporter().ignoreThrow();
154151
plugin.getLogger().log(Level.WARNING, errorMsg, throwable);
@@ -175,7 +172,7 @@ public double getBalance(@NotNull OfflinePlayer player, @NotNull World world, @N
175172
@Deprecated
176173
public boolean transfer(@NotNull UUID from, @NotNull UUID to, double amount, @NotNull World world, @Nullable String currency) {
177174
try {
178-
return Objects.requireNonNull(reserve).transferHoldings(from, to, new BigDecimal(amount));
175+
return Objects.requireNonNull(reserve).transferHoldings(from, to, new BigDecimal(amount), world.getName(), currency);
179176
} catch (Exception throwable) {
180177
plugin.getSentryErrorReporter().ignoreThrow();
181178
plugin.getLogger().log(Level.WARNING, errorMsg, throwable);
@@ -193,9 +190,6 @@ public boolean transfer(@NotNull UUID from, @NotNull UUID to, double amount, @No
193190
@Override
194191
public boolean withdraw(@NotNull UUID name, double amount, @NotNull World world, @Nullable String currency) {
195192
try {
196-
if ((!plugin.getConfiguration().getBoolean("shop.allow-economy-loan")) && getBalance(name, world, currency) < amount) {
197-
return false;
198-
}
199193
return Objects.requireNonNull(reserve).removeHoldings(name, new BigDecimal(amount));
200194
} catch (Exception throwable) {
201195
plugin.getSentryErrorReporter().ignoreThrow();
@@ -218,7 +212,9 @@ public boolean withdraw(@NotNull OfflinePlayer trader, double amount, @NotNull W
218212
*/
219213
@Override
220214
public boolean hasCurrency(@NotNull World world, @NotNull String currency) {
221-
return false;
215+
if (!isValid())
216+
return false;
217+
return reserve.hasCurrency(currency, world.getName());
222218
}
223219

224220
/**
@@ -228,7 +224,7 @@ public boolean hasCurrency(@NotNull World world, @NotNull String currency) {
228224
*/
229225
@Override
230226
public boolean supportCurrency() {
231-
return false;
227+
return true;
232228
}
233229

234230
/**

0 commit comments

Comments
 (0)