From 7a0dc38ec28c5f683e02440222942a5b5d809e88 Mon Sep 17 00:00:00 2001 From: creatorfromhell Date: Sat, 4 Nov 2023 21:41:11 -0400 Subject: [PATCH] Cancel autosaver on disable. Update plugin file version. --- Bukkit/resources/plugin.yml | 2 +- .../tnemc/bukkit/hook/economy/TNEVault.java | 19 ++++++++++++------- Core/src/net/tnemc/core/TNECore.java | 9 +++++++-- PaperCore/resources/paper-plugin.yml | 2 +- 4 files changed, 21 insertions(+), 11 deletions(-) diff --git a/Bukkit/resources/plugin.yml b/Bukkit/resources/plugin.yml index 34ea4768..3b792413 100644 --- a/Bukkit/resources/plugin.yml +++ b/Bukkit/resources/plugin.yml @@ -1,6 +1,6 @@ #General Data name: TheNewEconomy -version: 0.1.2.0 +version: 0.1.2.6 description: The original feature-packed economy plugin for Minecraft. author: creatorfromhell api-version: 1.13 diff --git a/Bukkit/src/net/tnemc/bukkit/hook/economy/TNEVault.java b/Bukkit/src/net/tnemc/bukkit/hook/economy/TNEVault.java index 7545bbcf..a7614148 100644 --- a/Bukkit/src/net/tnemc/bukkit/hook/economy/TNEVault.java +++ b/Bukkit/src/net/tnemc/bukkit/hook/economy/TNEVault.java @@ -201,7 +201,7 @@ public double getBalance(String name, String world) { */ public double getBalance(OfflinePlayer player, String world) { final Optional account = TNECore.eco().account().findAccount(player.getUniqueId().toString()); - if(account.isEmpty()) { + if(player.getName() != null && account.isEmpty()) { return getBalance(player.getName(), world); } return getBalance(player.getUniqueId().toString(), world); @@ -224,7 +224,7 @@ public boolean has(String name, double amount) { */ public boolean has(OfflinePlayer player, double amount) { final Optional account = TNECore.eco().account().findAccount(player.getUniqueId().toString()); - if(account.isEmpty()) { + if(player.getName() != null && account.isEmpty()) { return has(player.getName(), TNECore.eco().region().defaultRegion(), amount); } return has(player.getUniqueId().toString(), TNECore.eco().region().defaultRegion(), amount); @@ -251,7 +251,7 @@ public boolean has(String name, String world, double amount) { */ public boolean has(OfflinePlayer player, String world, double amount) { final Optional account = TNECore.eco().account().findAccount(player.getUniqueId().toString()); - if(account.isEmpty()) { + if(player.getName() != null && account.isEmpty()) { return has(player.getName(), world, amount); } return has(player.getUniqueId().toString(), world, amount); @@ -274,7 +274,12 @@ public EconomyResponse withdrawPlayer(String name, double amount) { */ public EconomyResponse withdrawPlayer(OfflinePlayer player, double amount) { final EconomyResponse response = withdrawPlayer(player.getUniqueId().toString(), TNECore.eco().region().defaultRegion(), amount); - if(response.transactionSuccess()){ + + TNECore.log().debug("Player ID: " + player.getUniqueId()); + TNECore.log().debug("Player Name: " + player.getName()); + TNECore.log().debug("Response" + response.errorMessage); + + if(response.transactionSuccess() || player.getName() == null) { return response; } return withdrawPlayer(player.getName(), TNECore.eco().region().defaultRegion(), amount); @@ -324,7 +329,7 @@ public EconomyResponse withdrawPlayer(String name, String world, double amount) */ public EconomyResponse withdrawPlayer(OfflinePlayer player, String world, double amount) { final EconomyResponse response = withdrawPlayer(player.getUniqueId().toString(), world, amount); - if(response.transactionSuccess()){ + if(response.transactionSuccess() || player.getName() == null) { return response; } return withdrawPlayer(player.getName(), world, amount); @@ -347,7 +352,7 @@ public EconomyResponse depositPlayer(String name, double amount) { */ public EconomyResponse depositPlayer(OfflinePlayer player, double amount) { final EconomyResponse response = depositPlayer(player.getUniqueId().toString(), TNECore.eco().region().defaultRegion(), amount); - if(response.transactionSuccess()){ + if(response.transactionSuccess() || player.getName() == null) { return response; } return depositPlayer(player.getName(), TNECore.eco().region().defaultRegion(), amount); @@ -399,7 +404,7 @@ public EconomyResponse depositPlayer(String name, String world, double amount) { */ public EconomyResponse depositPlayer(OfflinePlayer player, String world, double amount) { final EconomyResponse response = depositPlayer(player.getUniqueId().toString(), world, amount); - if(response.transactionSuccess()){ + if(response.transactionSuccess() || player.getName() == null) { return response; } return depositPlayer(player.getName(), world, amount); diff --git a/Core/src/net/tnemc/core/TNECore.java b/Core/src/net/tnemc/core/TNECore.java index 19ed5c84..0dd85eb9 100644 --- a/Core/src/net/tnemc/core/TNECore.java +++ b/Core/src/net/tnemc/core/TNECore.java @@ -41,6 +41,7 @@ import net.tnemc.core.compatibility.LogProvider; import net.tnemc.core.compatibility.ServerConnector; import net.tnemc.core.compatibility.log.DebugLevel; +import net.tnemc.core.compatibility.scheduler.Chore; import net.tnemc.core.compatibility.scheduler.ChoreExecution; import net.tnemc.core.compatibility.scheduler.ChoreTime; import net.tnemc.core.config.DataConfig; @@ -112,6 +113,7 @@ public abstract class TNECore { /* Plugin Instance */ private static TNECore instance; + private Chore autoSaver = null; private TNEAPI api; protected CallbackManager callbackManager; @@ -367,7 +369,7 @@ protected void onEnable() { //Set up the auto saver if enabled. if(DataConfig.yaml().getBoolean("Data.AutoSaver.Enabled")) { - server.scheduler().createRepeatingTask(()->{ + this.autoSaver = server.scheduler().createRepeatingTask(()->{ storage.storeAll(); }, new ChoreTime(0), new ChoreTime(DataConfig.yaml().getInt("Data.AutoSaver.Interval"), TimeUnit.SECONDS), @@ -394,7 +396,10 @@ protected void onEnable() { public void onDisable() { - //Call onEnable for all modules loaded. + if(autoSaver != null) { + autoSaver.cancel(); + } + //store our data syncly because it needs to finish final Optional> data = Optional.ofNullable(storage.getEngine().datables().get(Account.class)); if(data.isPresent()) { diff --git a/PaperCore/resources/paper-plugin.yml b/PaperCore/resources/paper-plugin.yml index b6b3638e..004f7bb1 100644 --- a/PaperCore/resources/paper-plugin.yml +++ b/PaperCore/resources/paper-plugin.yml @@ -1,5 +1,5 @@ name: TheNewEconomy -version: 0.1.2.0 +version: 0.1.2.6 description: The original feature-packed economy plugin for Minecraft. author: creatorfromhell main: net.tnemc.paper.TNE