Skip to content

Commit

Permalink
Replaced the shutdown thread with a hook.
Browse files Browse the repository at this point in the history
  • Loading branch information
jamierocks committed Oct 7, 2014
1 parent 0b3d405 commit c6b04dc
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@
import unomodding.minecraft.playtimelimiter.exceptions.UnknownPlayerException;
import unomodding.minecraft.playtimelimiter.threads.PlayTimeCheckerTask;
import unomodding.minecraft.playtimelimiter.threads.PlayTimeSaverTask;
import unomodding.minecraft.playtimelimiter.threads.ShutdownThread;

import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;

Expand All @@ -34,7 +32,6 @@ public final class PlayTimeLimiter extends Plugin {
private Map<String, Integer> timeLoggedIn = new HashMap<String, Integer>();
private Map<String, Boolean> seenWarningMessages = new HashMap<String, Boolean>();

private boolean shutdownHookAdded = false;
private Timer savePlayTimeTimer = null;
private Timer checkPlayTimeTimer = null;
private boolean started = false;
Expand All @@ -47,14 +44,6 @@ public void disable() {

public boolean enable() {
instance = this;
if (!this.shutdownHookAdded) {
this.shutdownHookAdded = true;
try {
Runtime.getRuntime().addShutdownHook(new ShutdownThread(this));
} catch (Exception e) {
e.printStackTrace();
}
}

if(!getConfig().containsKey("timeStarted")) {
getConfig().setInt("timeStarted", (int) (System.currentTimeMillis() / 1000));
Expand Down Expand Up @@ -90,7 +79,7 @@ public boolean enable() {
this.loadPlayTime();

// Enable Listener
Canary.hooks().registerListener(new PlayerListener(this), this);
Canary.hooks().registerListener(new PlayTimeListener(this), this);

// Enable Commands
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,22 @@
import net.canarymod.hook.HookHandler;
import net.canarymod.hook.player.ConnectionHook;
import net.canarymod.hook.player.DisconnectionHook;
import net.canarymod.hook.system.ServerShutdownHook;
import net.canarymod.plugin.PluginListener;
import unomodding.minecraft.playtimelimiter.utils.FileUtils;
import unomodding.minecraft.playtimelimiter.utils.Timestamper;

public class PlayerListener implements PluginListener {
public class PlayTimeListener implements PluginListener {
private final PlayTimeLimiter plugin;

public PlayerListener(PlayTimeLimiter instance) {
public PlayTimeListener(PlayTimeLimiter instance) {
this.plugin = instance;
}

@HookHandler
public void onSeverShutdown(ServerShutdownHook hook) {
this.plugin.savePlayTime(true); // Force save playtime when server is shut down
}

@HookHandler
public void onPlayerJoin(ConnectionHook hook) {
Expand Down

This file was deleted.

0 comments on commit c6b04dc

Please sign in to comment.