From 63dc921539598631d6205abfec09039a29ae701f Mon Sep 17 00:00:00 2001 From: xHyroM Date: Wed, 30 Aug 2023 00:41:09 +0200 Subject: [PATCH] feat: task schedulers --- .../bukkit/BukkitLightEcoBootstrap.java | 6 +++ .../bukkit/BukkitSchedulerAdapter.java | 53 +++++++++++++++++++ .../bukkit/commands/BalanceCommand.java | 2 +- .../lighteco/bukkit/commands/GiveCommand.java | 2 +- .../lighteco/bukkit/commands/PayCommand.java | 2 +- .../lighteco/bukkit/commands/SetCommand.java | 2 +- .../lighteco/bukkit/commands/TakeCommand.java | 2 +- .../listeners/BukkitConnectionListener.java | 21 +++++++- .../lighteco/bukkittest/TestPlugin.java | 1 - .../command/AbstractCommandManager.java | 12 ++--- .../manager/user/StandardUserManager.java | 1 + .../common/manager/user/UserManager.java | 1 + .../lighteco/common/model/user/User.java | 19 ++++--- .../common/plugin/AbstractLightEcoPlugin.java | 5 ++ .../plugin/bootstrap/LightEcoBootstrap.java | 2 + .../plugin/scheduler/SchedulerAdapter.java | 9 ++++ .../plugin/scheduler/SchedulerTask.java | 5 ++ .../lighteco/common/storage/Storage.java | 1 - .../lighteco/common/task/UserSaveTask.java | 35 ++++++++++++ .../money/bukkit/hooks/vault/Vault.java | 26 +++------ 20 files changed, 165 insertions(+), 42 deletions(-) create mode 100644 bukkit/src/main/java/dev/xhyrom/lighteco/bukkit/BukkitSchedulerAdapter.java create mode 100644 common/src/main/java/dev/xhyrom/lighteco/common/plugin/scheduler/SchedulerAdapter.java create mode 100644 common/src/main/java/dev/xhyrom/lighteco/common/plugin/scheduler/SchedulerTask.java create mode 100644 common/src/main/java/dev/xhyrom/lighteco/common/task/UserSaveTask.java diff --git a/bukkit/src/main/java/dev/xhyrom/lighteco/bukkit/BukkitLightEcoBootstrap.java b/bukkit/src/main/java/dev/xhyrom/lighteco/bukkit/BukkitLightEcoBootstrap.java index e65cab0..086541e 100644 --- a/bukkit/src/main/java/dev/xhyrom/lighteco/bukkit/BukkitLightEcoBootstrap.java +++ b/bukkit/src/main/java/dev/xhyrom/lighteco/bukkit/BukkitLightEcoBootstrap.java @@ -4,6 +4,7 @@ import dev.xhyrom.lighteco.bukkit.logger.BukkitLogger; import dev.xhyrom.lighteco.common.plugin.bootstrap.LightEcoBootstrap; import dev.xhyrom.lighteco.common.plugin.bootstrap.LoaderBootstrap; import dev.xhyrom.lighteco.common.plugin.logger.PluginLogger; +import dev.xhyrom.lighteco.common.plugin.scheduler.SchedulerAdapter; import lombok.Getter; import org.bukkit.Server; import org.bukkit.entity.Entity; @@ -49,6 +50,11 @@ public class BukkitLightEcoBootstrap implements LightEcoBootstrap, LoaderBootstr return this.loader.getServer(); } + @Override + public SchedulerAdapter getScheduler() { + return new BukkitSchedulerAdapter(this); + } + @Override public Path getDataDirectory() { return this.loader.getDataFolder().toPath(); diff --git a/bukkit/src/main/java/dev/xhyrom/lighteco/bukkit/BukkitSchedulerAdapter.java b/bukkit/src/main/java/dev/xhyrom/lighteco/bukkit/BukkitSchedulerAdapter.java new file mode 100644 index 0000000..add1c98 --- /dev/null +++ b/bukkit/src/main/java/dev/xhyrom/lighteco/bukkit/BukkitSchedulerAdapter.java @@ -0,0 +1,53 @@ +package dev.xhyrom.lighteco.bukkit; + +import dev.xhyrom.lighteco.common.plugin.scheduler.SchedulerAdapter; +import dev.xhyrom.lighteco.common.plugin.scheduler.SchedulerTask; +import org.bukkit.scheduler.BukkitScheduler; +import org.bukkit.scheduler.BukkitTask; + +import java.util.concurrent.TimeUnit; + +public class BukkitSchedulerAdapter implements SchedulerAdapter { + private final BukkitLightEcoBootstrap bootstrap; + private final BukkitScheduler scheduler; + + public BukkitSchedulerAdapter(BukkitLightEcoBootstrap bootstrap) { + this.bootstrap = bootstrap; + this.scheduler = bootstrap.getServer().getScheduler(); + } + + @Override + public SchedulerTask asyncLater(Runnable runnable, long delay, TimeUnit unit) { + return new Task( + this.scheduler.runTaskLaterAsynchronously( + this.bootstrap.getLoader(), + runnable, + unit.toSeconds(delay) * 20 + ) + ); + } + + @Override + public SchedulerTask asyncRepeating(Runnable runnable, long interval, TimeUnit unit) { + return new Task( + this.scheduler.runTaskTimerAsynchronously( + this.bootstrap.getLoader(), + runnable, + 0, + unit.toSeconds(interval) * 20 + ) + ); + } + + public class Task implements SchedulerTask { + private final BukkitTask task; + public Task(BukkitTask task) { + this.task = task; + } + + @Override + public void cancel() { + this.task.cancel(); + } + } +} diff --git a/bukkit/src/main/java/dev/xhyrom/lighteco/bukkit/commands/BalanceCommand.java b/bukkit/src/main/java/dev/xhyrom/lighteco/bukkit/commands/BalanceCommand.java index cfde5d8..3c9e295 100644 --- a/bukkit/src/main/java/dev/xhyrom/lighteco/bukkit/commands/BalanceCommand.java +++ b/bukkit/src/main/java/dev/xhyrom/lighteco/bukkit/commands/BalanceCommand.java @@ -45,7 +45,7 @@ public class BalanceCommand implements Command { } this.manager.plugin.getUserManager().loadUser(target.getUniqueId()) - .thenAcceptAsync(result -> { + .thenAccept(result -> { String username = result.getUsername() == null ? target.getName() != null ? target.getName() diff --git a/bukkit/src/main/java/dev/xhyrom/lighteco/bukkit/commands/GiveCommand.java b/bukkit/src/main/java/dev/xhyrom/lighteco/bukkit/commands/GiveCommand.java index 8a22273..e138c0d 100644 --- a/bukkit/src/main/java/dev/xhyrom/lighteco/bukkit/commands/GiveCommand.java +++ b/bukkit/src/main/java/dev/xhyrom/lighteco/bukkit/commands/GiveCommand.java @@ -44,7 +44,7 @@ public class GiveCommand implements Command { if (!this.manager.canUse(sender, currency)) return; this.manager.plugin.getUserManager().loadUser(target.getUniqueId()) - .thenAcceptAsync(result -> { + .thenAccept(result -> { String name = target.getName() != null ? target.getName() : args.getRaw("target"); result.setUsername(name); diff --git a/bukkit/src/main/java/dev/xhyrom/lighteco/bukkit/commands/PayCommand.java b/bukkit/src/main/java/dev/xhyrom/lighteco/bukkit/commands/PayCommand.java index 1d15542..4e07a94 100644 --- a/bukkit/src/main/java/dev/xhyrom/lighteco/bukkit/commands/PayCommand.java +++ b/bukkit/src/main/java/dev/xhyrom/lighteco/bukkit/commands/PayCommand.java @@ -43,7 +43,7 @@ public class PayCommand implements Command { if (!this.manager.canUse(sender, currency)) return; this.manager.plugin.getUserManager().loadUser(target.getUniqueId()) - .thenAcceptAsync(result -> { + .thenAccept(result -> { String username = result.getUsername() == null ? target.getName() != null ? target.getName() diff --git a/bukkit/src/main/java/dev/xhyrom/lighteco/bukkit/commands/SetCommand.java b/bukkit/src/main/java/dev/xhyrom/lighteco/bukkit/commands/SetCommand.java index f8a547d..c45f9ff 100644 --- a/bukkit/src/main/java/dev/xhyrom/lighteco/bukkit/commands/SetCommand.java +++ b/bukkit/src/main/java/dev/xhyrom/lighteco/bukkit/commands/SetCommand.java @@ -44,7 +44,7 @@ public class SetCommand implements Command { if (!this.manager.canUse(sender, currency)) return; this.manager.plugin.getUserManager().loadUser(target.getUniqueId()) - .thenAcceptAsync(result -> { + .thenAccept(result -> { String name = target.getName() != null ? target.getName() : args.getRaw("target"); result.setUsername(name); diff --git a/bukkit/src/main/java/dev/xhyrom/lighteco/bukkit/commands/TakeCommand.java b/bukkit/src/main/java/dev/xhyrom/lighteco/bukkit/commands/TakeCommand.java index 5f9d54a..3f25263 100644 --- a/bukkit/src/main/java/dev/xhyrom/lighteco/bukkit/commands/TakeCommand.java +++ b/bukkit/src/main/java/dev/xhyrom/lighteco/bukkit/commands/TakeCommand.java @@ -44,7 +44,7 @@ public class TakeCommand implements Command { if (!this.manager.canUse(sender, currency)) return; this.manager.plugin.getUserManager().loadUser(target.getUniqueId()) - .thenAcceptAsync(result -> { + .thenAccept(result -> { String name = target.getName() != null ? target.getName() : args.getRaw("target"); result.setUsername(name); diff --git a/bukkit/src/main/java/dev/xhyrom/lighteco/bukkit/listeners/BukkitConnectionListener.java b/bukkit/src/main/java/dev/xhyrom/lighteco/bukkit/listeners/BukkitConnectionListener.java index 80f1fa5..4c8aaad 100644 --- a/bukkit/src/main/java/dev/xhyrom/lighteco/bukkit/listeners/BukkitConnectionListener.java +++ b/bukkit/src/main/java/dev/xhyrom/lighteco/bukkit/listeners/BukkitConnectionListener.java @@ -1,13 +1,17 @@ package dev.xhyrom.lighteco.bukkit.listeners; import dev.xhyrom.lighteco.bukkit.BukkitLightEcoPlugin; +import dev.xhyrom.lighteco.common.model.user.User; import net.kyori.adventure.text.minimessage.MiniMessage; +import org.bukkit.Bukkit; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; import org.bukkit.event.Listener; import org.bukkit.event.player.AsyncPlayerPreLoginEvent; import org.bukkit.event.player.PlayerQuitEvent; +import java.util.UUID; + public class BukkitConnectionListener implements Listener { private final BukkitLightEcoPlugin plugin; private final MiniMessage miniMessage = MiniMessage.miniMessage(); @@ -34,7 +38,22 @@ public class BukkitConnectionListener implements Listener { } } + @EventHandler public void onPlayerQuit(PlayerQuitEvent event) { - this.plugin.getUserManager().unload(event.getPlayer().getUniqueId()); + UUID uniqueId = event.getPlayer().getUniqueId(); + + User user = this.plugin.getUserManager().getIfLoaded(uniqueId); + if (!user.isDirty()) { + this.plugin.getUserManager().unload(uniqueId); + return; + } + + this.plugin.getUserManager().saveUser(user) + .thenAccept(v -> { + // make sure the player is offline before unloading + if (Bukkit.getPlayer(uniqueId) != null) return; + + this.plugin.getUserManager().unload(uniqueId); + }); } } diff --git a/bukkittest/src/main/java/dev/xhyrom/lighteco/bukkittest/TestPlugin.java b/bukkittest/src/main/java/dev/xhyrom/lighteco/bukkittest/TestPlugin.java index 45f5d96..a012e8e 100644 --- a/bukkittest/src/main/java/dev/xhyrom/lighteco/bukkittest/TestPlugin.java +++ b/bukkittest/src/main/java/dev/xhyrom/lighteco/bukkittest/TestPlugin.java @@ -7,7 +7,6 @@ import dev.xhyrom.lighteco.api.model.user.User; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; import org.bukkit.event.player.AsyncPlayerChatEvent; -import org.bukkit.event.player.PlayerChatEvent; import org.bukkit.plugin.java.JavaPlugin; import java.util.List; diff --git a/common/src/main/java/dev/xhyrom/lighteco/common/manager/command/AbstractCommandManager.java b/common/src/main/java/dev/xhyrom/lighteco/common/manager/command/AbstractCommandManager.java index 2a815a1..3fef971 100644 --- a/common/src/main/java/dev/xhyrom/lighteco/common/manager/command/AbstractCommandManager.java +++ b/common/src/main/java/dev/xhyrom/lighteco/common/manager/command/AbstractCommandManager.java @@ -112,8 +112,7 @@ public abstract class AbstractCommandManager implements CommandManager { ) ); - this.plugin.getUserManager().saveUser(target) - .thenAccept(v -> removeFromMustWait(target.getUniqueId(), sender.getUniqueId())); + removeFromMustWait(target.getUniqueId(), sender.getUniqueId()); } @Override @@ -133,8 +132,7 @@ public abstract class AbstractCommandManager implements CommandManager { ) ); - this.plugin.getUserManager().saveUser(target) - .thenAccept(v -> removeFromMustWait(target.getUniqueId(), sender.getUniqueId())); + removeFromMustWait(target.getUniqueId(), sender.getUniqueId()); } @Override @@ -154,8 +152,7 @@ public abstract class AbstractCommandManager implements CommandManager { ) ); - this.plugin.getUserManager().saveUser(target) - .thenAccept(v -> removeFromMustWait(target.getUniqueId(), sender.getUniqueId())); + removeFromMustWait(target.getUniqueId(), sender.getUniqueId()); } @Override @@ -209,7 +206,6 @@ public abstract class AbstractCommandManager implements CommandManager { ) ); - this.plugin.getUserManager().saveUsers(user, target) - .thenAccept(v -> removeFromMustWait(sender.getUniqueId(), target.getUniqueId())); + removeFromMustWait(target.getUniqueId(), sender.getUniqueId()); } } diff --git a/common/src/main/java/dev/xhyrom/lighteco/common/manager/user/StandardUserManager.java b/common/src/main/java/dev/xhyrom/lighteco/common/manager/user/StandardUserManager.java index 3735de0..cf8b43d 100644 --- a/common/src/main/java/dev/xhyrom/lighteco/common/manager/user/StandardUserManager.java +++ b/common/src/main/java/dev/xhyrom/lighteco/common/manager/user/StandardUserManager.java @@ -5,6 +5,7 @@ import dev.xhyrom.lighteco.common.model.user.User; import dev.xhyrom.lighteco.common.plugin.LightEcoPlugin; import java.util.Arrays; +import java.util.Collection; import java.util.UUID; import java.util.concurrent.CompletableFuture; diff --git a/common/src/main/java/dev/xhyrom/lighteco/common/manager/user/UserManager.java b/common/src/main/java/dev/xhyrom/lighteco/common/manager/user/UserManager.java index b5cb08c..ec3ec86 100644 --- a/common/src/main/java/dev/xhyrom/lighteco/common/manager/user/UserManager.java +++ b/common/src/main/java/dev/xhyrom/lighteco/common/manager/user/UserManager.java @@ -3,6 +3,7 @@ package dev.xhyrom.lighteco.common.manager.user; import dev.xhyrom.lighteco.common.manager.Manager; import dev.xhyrom.lighteco.common.model.user.User; +import java.util.Collection; import java.util.UUID; import java.util.concurrent.CompletableFuture; diff --git a/common/src/main/java/dev/xhyrom/lighteco/common/model/user/User.java b/common/src/main/java/dev/xhyrom/lighteco/common/model/user/User.java index 24cea22..275c1f7 100644 --- a/common/src/main/java/dev/xhyrom/lighteco/common/model/user/User.java +++ b/common/src/main/java/dev/xhyrom/lighteco/common/model/user/User.java @@ -20,9 +20,14 @@ public class User { @Getter private final UUID uniqueId; + + @Getter + @Setter + private boolean dirty = false; @Getter @Setter private String username; + private final HashMap balances = new HashMap<>(); public User(LightEcoPlugin plugin, UUID uniqueId) { @@ -46,6 +51,8 @@ public class User { balance = balance.setScale(currency.fractionalDigits(), RoundingMode.DOWN); balances.put(currency, balance); + + this.setDirty(true); } public void deposit(@NonNull Currency currency, @NonNull BigDecimal amount) throws IllegalArgumentException { @@ -53,7 +60,7 @@ public class User { throw new IllegalArgumentException("Amount cannot be negative"); } - setBalance(currency, getBalance(currency).add(amount)); + this.setBalance(currency, this.getBalance(currency).add(amount)); } public void withdraw(@NonNull Currency currency, @NonNull BigDecimal amount) throws IllegalArgumentException { @@ -61,15 +68,11 @@ public class User { throw new IllegalArgumentException("Amount cannot be negative"); } - if (getBalance(currency).compareTo(amount) < 0) { + if (this.getBalance(currency).compareTo(amount) < 0) { // Withdraw all - amount = getBalance(currency); + amount = this.getBalance(currency); } - setBalance(currency, getBalance(currency).subtract(amount)); - } - - public void invalidateCaches() { - balances.clear(); + this.setBalance(currency, this.getBalance(currency).subtract(amount)); } } diff --git a/common/src/main/java/dev/xhyrom/lighteco/common/plugin/AbstractLightEcoPlugin.java b/common/src/main/java/dev/xhyrom/lighteco/common/plugin/AbstractLightEcoPlugin.java index 9c813ad..93228bb 100644 --- a/common/src/main/java/dev/xhyrom/lighteco/common/plugin/AbstractLightEcoPlugin.java +++ b/common/src/main/java/dev/xhyrom/lighteco/common/plugin/AbstractLightEcoPlugin.java @@ -8,10 +8,13 @@ import dev.xhyrom.lighteco.common.dependencies.DependencyManager; import dev.xhyrom.lighteco.common.dependencies.DependencyManagerImpl; import dev.xhyrom.lighteco.common.storage.Storage; import dev.xhyrom.lighteco.common.storage.StorageFactory; +import dev.xhyrom.lighteco.common.task.UserSaveTask; import eu.okaeri.configs.ConfigManager; import eu.okaeri.configs.yaml.snakeyaml.YamlSnakeYamlConfigurer; import lombok.Getter; +import java.util.concurrent.TimeUnit; + @Getter public abstract class AbstractLightEcoPlugin implements LightEcoPlugin { private DependencyManager dependencyManager; @@ -51,6 +54,8 @@ public abstract class AbstractLightEcoPlugin implements LightEcoPlugin { this.api = new LightEcoApi(this); LightEcoProvider.set(this.api); this.registerApiOnPlatform(this.api); + + this.getBootstrap().getScheduler().asyncRepeating(new UserSaveTask(this), 3, TimeUnit.SECONDS); } public final void disable() { diff --git a/common/src/main/java/dev/xhyrom/lighteco/common/plugin/bootstrap/LightEcoBootstrap.java b/common/src/main/java/dev/xhyrom/lighteco/common/plugin/bootstrap/LightEcoBootstrap.java index 8a7a02f..f3069c3 100644 --- a/common/src/main/java/dev/xhyrom/lighteco/common/plugin/bootstrap/LightEcoBootstrap.java +++ b/common/src/main/java/dev/xhyrom/lighteco/common/plugin/bootstrap/LightEcoBootstrap.java @@ -1,6 +1,7 @@ package dev.xhyrom.lighteco.common.plugin.bootstrap; import dev.xhyrom.lighteco.common.plugin.logger.PluginLogger; +import dev.xhyrom.lighteco.common.plugin.scheduler.SchedulerAdapter; import java.io.InputStream; import java.nio.file.Path; @@ -10,6 +11,7 @@ import java.util.UUID; public interface LightEcoBootstrap { Object getLoader(); PluginLogger getLogger(); + SchedulerAdapter getScheduler(); Path getDataDirectory(); List getOnlinePlayers(); InputStream getResourceStream(String filename); diff --git a/common/src/main/java/dev/xhyrom/lighteco/common/plugin/scheduler/SchedulerAdapter.java b/common/src/main/java/dev/xhyrom/lighteco/common/plugin/scheduler/SchedulerAdapter.java new file mode 100644 index 0000000..f751406 --- /dev/null +++ b/common/src/main/java/dev/xhyrom/lighteco/common/plugin/scheduler/SchedulerAdapter.java @@ -0,0 +1,9 @@ +package dev.xhyrom.lighteco.common.plugin.scheduler; + +import java.util.concurrent.TimeUnit; + +public interface SchedulerAdapter { + SchedulerTask asyncLater(Runnable runnable, long delay, TimeUnit unit); + + SchedulerTask asyncRepeating(Runnable runnable, long interval, TimeUnit unit); +} diff --git a/common/src/main/java/dev/xhyrom/lighteco/common/plugin/scheduler/SchedulerTask.java b/common/src/main/java/dev/xhyrom/lighteco/common/plugin/scheduler/SchedulerTask.java new file mode 100644 index 0000000..8fdd521 --- /dev/null +++ b/common/src/main/java/dev/xhyrom/lighteco/common/plugin/scheduler/SchedulerTask.java @@ -0,0 +1,5 @@ +package dev.xhyrom.lighteco.common.plugin.scheduler; + +public interface SchedulerTask { + void cancel(); +} diff --git a/common/src/main/java/dev/xhyrom/lighteco/common/storage/Storage.java b/common/src/main/java/dev/xhyrom/lighteco/common/storage/Storage.java index 18a0b06..2f3049e 100644 --- a/common/src/main/java/dev/xhyrom/lighteco/common/storage/Storage.java +++ b/common/src/main/java/dev/xhyrom/lighteco/common/storage/Storage.java @@ -5,7 +5,6 @@ import dev.xhyrom.lighteco.api.storage.StorageProvider; import dev.xhyrom.lighteco.common.plugin.LightEcoPlugin; import dev.xhyrom.lighteco.common.util.ThrowableRunnable; -import java.util.ArrayList; import java.util.List; import java.util.UUID; import java.util.concurrent.Callable; diff --git a/common/src/main/java/dev/xhyrom/lighteco/common/task/UserSaveTask.java b/common/src/main/java/dev/xhyrom/lighteco/common/task/UserSaveTask.java new file mode 100644 index 0000000..00f5001 --- /dev/null +++ b/common/src/main/java/dev/xhyrom/lighteco/common/task/UserSaveTask.java @@ -0,0 +1,35 @@ +package dev.xhyrom.lighteco.common.task; + +import dev.xhyrom.lighteco.common.model.user.User; +import dev.xhyrom.lighteco.common.plugin.LightEcoPlugin; + +import java.util.concurrent.ExecutionException; + +public class UserSaveTask implements Runnable { + private final LightEcoPlugin plugin; + + public UserSaveTask(LightEcoPlugin plugin) { + this.plugin = plugin; + } + + @Override + public void run() { + User[] users = this.plugin.getUserManager().values().stream() + .filter(User::isDirty) + .toArray(User[]::new); + + if (users.length == 0) { + return; + } + + try { + this.plugin.getUserManager().saveUsers(users).get(); + + for (User user : users) { + user.setDirty(false); + } + } catch (InterruptedException | RuntimeException | ExecutionException e) { + this.plugin.getBootstrap().getLogger().error("Failed to save users", e); + } + } +} diff --git a/currency-money/src/main/java/dev/xhyrom/lighteco/currency/money/bukkit/hooks/vault/Vault.java b/currency-money/src/main/java/dev/xhyrom/lighteco/currency/money/bukkit/hooks/vault/Vault.java index f82f3c2..d1d18f8 100644 --- a/currency-money/src/main/java/dev/xhyrom/lighteco/currency/money/bukkit/hooks/vault/Vault.java +++ b/currency-money/src/main/java/dev/xhyrom/lighteco/currency/money/bukkit/hooks/vault/Vault.java @@ -7,12 +7,10 @@ import dev.xhyrom.lighteco.api.model.user.User; import net.milkbowl.vault.economy.AbstractEconomy; import net.milkbowl.vault.economy.EconomyResponse; import org.bukkit.Bukkit; -import org.jetbrains.annotations.NotNull; import java.math.BigDecimal; import java.util.List; import java.util.UUID; -import java.util.concurrent.ExecutionException; public class Vault extends AbstractEconomy { private final LightEco provider; @@ -118,21 +116,8 @@ public class Vault extends AbstractEconomy { ); } - return saveUser(amount, user); - } - - @NotNull - private EconomyResponse saveUser(double amount, User user) { - try { - provider.getUserManager().saveUser(user).get(); - } catch (InterruptedException | ExecutionException e) { - return new EconomyResponse( - amount, - bigDecimalToDouble(user.getBalance(currency)), - EconomyResponse.ResponseType.FAILURE, - "Cannot save user" - ); - } + // Can happen on background + this.provider.getUserManager().saveUser(user); return new EconomyResponse( amount, @@ -163,7 +148,12 @@ public class Vault extends AbstractEconomy { ); } - return saveUser(amount, user); + return new EconomyResponse( + amount, + bigDecimalToDouble(user.getBalance(currency)), + EconomyResponse.ResponseType.SUCCESS, + "" + ); } @Override