-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
91 additions
and
49 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
62 changes: 62 additions & 0 deletions
62
src/main/java/net/anvian/sodiumextrainformation/util/SessionManager.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
package net.anvian.sodiumextrainformation.util; | ||
|
||
import net.anvian.sodiumextrainformation.SodiumExtraInformationClient; | ||
import org.slf4j.Logger; | ||
|
||
public class SessionManager { | ||
private static final Logger LOGGER = SodiumExtraInformationClient.LOGGER; | ||
|
||
private long sessionStartTime; | ||
private long totalTimePlayed; | ||
private boolean inSession; | ||
private boolean isPaused; | ||
|
||
public synchronized void startSession() { | ||
sessionStartTime = System.currentTimeMillis(); | ||
inSession = true; | ||
isPaused = false; | ||
LOGGER.info("Session started"); | ||
} | ||
|
||
public synchronized void endSession() { | ||
inSession = false; | ||
LOGGER.info("Session ended"); | ||
} | ||
|
||
public synchronized void pauseSession() { | ||
isPaused = true; | ||
totalTimePlayed += (System.currentTimeMillis() - sessionStartTime); | ||
LOGGER.info("Session paused"); | ||
} | ||
|
||
public synchronized void resumeSession() { | ||
isPaused = false; | ||
sessionStartTime = System.currentTimeMillis(); | ||
LOGGER.info("Session resumed"); | ||
} | ||
|
||
public synchronized void updateSessionTime() { | ||
long currentTime = System.currentTimeMillis(); | ||
totalTimePlayed += (currentTime - sessionStartTime); | ||
sessionStartTime = currentTime; | ||
} | ||
|
||
public void resetSession() { | ||
sessionStartTime = 0; | ||
totalTimePlayed = 0; | ||
inSession = false; | ||
isPaused = false; | ||
} | ||
|
||
public boolean isInSession() { | ||
return inSession; | ||
} | ||
|
||
public boolean isPaused() { | ||
return isPaused; | ||
} | ||
|
||
public long getTotalTimePlayed() { | ||
return totalTimePlayed / 1000; | ||
} | ||
} |