Skip to content

Commit

Permalink
Cancel autosaver on disable. Update plugin file version.
Browse files Browse the repository at this point in the history
  • Loading branch information
creatorfromhell committed Nov 5, 2023
1 parent 3ff4e0b commit 7a0dc38
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 11 deletions.
2 changes: 1 addition & 1 deletion Bukkit/resources/plugin.yml
Original file line number Diff line number Diff line change
@@ -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
Expand Down
19 changes: 12 additions & 7 deletions Bukkit/src/net/tnemc/bukkit/hook/economy/TNEVault.java
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ public double getBalance(String name, String world) {
*/
public double getBalance(OfflinePlayer player, String world) {
final Optional<Account> 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);
Expand All @@ -224,7 +224,7 @@ public boolean has(String name, double amount) {
*/
public boolean has(OfflinePlayer player, double amount) {
final Optional<Account> 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);
Expand All @@ -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> 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);
Expand All @@ -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);
Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand Down Expand Up @@ -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);
Expand Down
9 changes: 7 additions & 2 deletions Core/src/net/tnemc/core/TNECore.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -112,6 +113,7 @@ public abstract class TNECore {

/* Plugin Instance */
private static TNECore instance;
private Chore<?> autoSaver = null;

private TNEAPI api;
protected CallbackManager callbackManager;
Expand Down Expand Up @@ -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),
Expand All @@ -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<Datable<?>> data = Optional.ofNullable(storage.getEngine().datables().get(Account.class));
if(data.isPresent()) {
Expand Down
2 changes: 1 addition & 1 deletion PaperCore/resources/paper-plugin.yml
Original file line number Diff line number Diff line change
@@ -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
Expand Down

0 comments on commit 7a0dc38

Please sign in to comment.