11/**
2- * Copyright 2014 by UnoModding, RyanTheAllmighty and Contributors
2+ * Copyright 2014-2015 by UnoModding, RyanTheAllmighty and Contributors
33 *
44 * This work is licensed under the Creative Commons Attribution-ShareAlike 3.0 Unported License.
55 * To view a copy of this license, visit http://creativecommons.org/licenses/by-sa/3.0/.
1414import java .io .IOException ;
1515import java .util .HashMap ;
1616import java .util .Map ;
17- import java .util .Timer ;
1817import java .util .UUID ;
1918
2019import org .bukkit .ChatColor ;
@@ -44,8 +43,6 @@ public class PlayTimeLimiter extends JavaPlugin {
4443 private Map <String , Boolean > seenWarningMessages = new HashMap <String , Boolean >();
4544
4645 private boolean shutdownHookAdded = false ;
47- private Timer savePlayTimeTimer = null ;
48- private Timer checkPlayTimeTimer = null ;
4946 private boolean started = false ;
5047 private final Gson GSON = new Gson ();
5148
@@ -94,14 +91,14 @@ public void onEnable() {
9491 getConfig ().set ("timeTravels" , true );
9592 saveConfig ();
9693 }
97- if (!getConfig ().isSet ("timeCap" )) {
94+ /* if (!getConfig().isSet("timeCap")) {
9895 getConfig().set("timeCap", true);
9996 saveConfig();
10097 }
10198 if (!getConfig().isSet("timeCapValue")) {
10299 getConfig().set("timeCapValue", 18000);
103100 saveConfig();
104- }
101+ }*/
105102
106103 getLogger ().info (
107104 String .format ("Server started at %s which was %s seconds ago!" ,
@@ -118,18 +115,13 @@ public void onEnable() {
118115 // Load the playtime from file
119116 this .loadPlayTime ();
120117
121- if (savePlayTimeTimer == null ) {
122- this .savePlayTimeTimer = new Timer ();
123- this .savePlayTimeTimer .scheduleAtFixedRate (new PlayTimeSaverTask (
124- this ), 30000 ,
125- getConfig ().getInt ("secondsBetweenPlayTimeSaving" ) * 1000 );
126- }
127- if (checkPlayTimeTimer == null ) {
128- this .checkPlayTimeTimer = new Timer ();
129- this .checkPlayTimeTimer .scheduleAtFixedRate (
130- new PlayTimeCheckerTask (this ), 30000 ,
131- getConfig ().getInt ("secondsBetweenPlayTimeChecks" ) * 1000 );
132- }
118+ this .getServer ().getScheduler ().scheduleSyncRepeatingTask (this ,
119+ new PlayTimeSaverTask (this ), 30000 ,
120+ getConfig ().getInt ("secondsBetweenPlayTimeSaving" ) * 1000 );
121+ this .getServer ().getScheduler ().scheduleSyncRepeatingTask (this ,
122+ new PlayTimeCheckerTask (this ), 30000 ,
123+ getConfig ().getInt ("secondsBetweenPlayTimeChecks" ) * 1000 );
124+
133125
134126 try {
135127 Metrics metrics = new Metrics (this );
@@ -232,6 +224,10 @@ public void setPlayerLoggedIn(UUID uuid) {
232224 (int ) (System .currentTimeMillis () / 1000 ));
233225 }
234226
227+ public void setPlayerLoggedOut (UUID uuid ) {
228+ setPlayerLoggedOut (uuid .toString ());
229+ }
230+
235231 private void setPlayerLoggedOut (String uuid ) {
236232 if (this .timeLoggedIn .containsKey (uuid )) {
237233 int timePlayed = (int ) ((System .currentTimeMillis () / 1000 ) - this .timeLoggedIn
@@ -260,10 +256,6 @@ private void setPlayerLoggedOut(String uuid) {
260256 }
261257 }
262258
263- public void setPlayerLoggedOut (UUID uuid ) {
264- setPlayerLoggedOut (uuid );
265- }
266-
267259 public boolean hasPlayerSeenMessage (UUID uuid , int time ) {
268260 if (this .seenWarningMessages .containsKey (uuid + ":" + time )) {
269261 return this .seenWarningMessages .get (uuid + ":" + time );
0 commit comments