Skip to content

Commit

Permalink
Fix onDisable methods.
Browse files Browse the repository at this point in the history
  • Loading branch information
seyfahni committed May 7, 2019
1 parent 47a5a99 commit f702949
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public class OnlineTimeBukkitPlugin extends JavaPlugin implements PluginProxy {
private AccumulatingOnlineTimeStorage onlineTimeStorage;
private PlayerNameStorage playerNameStorage;

BukkitTask flushCacheTask;
private BukkitTask flushCacheTask;

@Override
public void onEnable() {
Expand Down Expand Up @@ -249,7 +249,22 @@ private void flushOnlineTimeCache() {

@Override
public void onDisable() {

if (onlineTimeStorage != null) {
try {
flushCacheTask.cancel();
flushOnlineTimeCache();
onlineTimeStorage.close();
} catch (StorageException ex) {
getLogger().log(Level.SEVERE, "error while closing online time storage", ex);
}
}
if (playerNameStorage != null) {
try {
playerNameStorage.close();
} catch (StorageException ex) {
getLogger().log(Level.SEVERE, "error while closing player name storage", ex);
}
}
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@
import java.util.*;
import java.util.concurrent.TimeUnit;
import java.util.logging.Level;
import java.util.regex.Matcher;
import java.util.stream.Collectors;

public class OnlineTimeBungeePlugin extends Plugin implements PluginProxy {
Expand Down Expand Up @@ -93,10 +92,10 @@ public void onEnable() {
public void onDisable() {
getProxy().getPluginManager().unregisterCommands(this);
getProxy().getPluginManager().unregisterListeners(this);
flushCacheTask.cancel();
flushOnlineTimeCache();
if (onlineTimeStorage != null) {
try {
flushCacheTask.cancel();
flushOnlineTimeCache();
onlineTimeStorage.close();
} catch (StorageException ex) {
getLogger().log(Level.SEVERE, "error while closing online time storage", ex);
Expand Down

0 comments on commit f702949

Please sign in to comment.