Browse Source

refactoring: Outsourced time feature

The time feature for the quiz has a seperate method now which returns the difference of the current time and the time you played the last time. If the difference is greater than 0 you can't play.
remotes/origin/quiz
Friederike von Gruben 2 years ago
parent
commit
d08bdb85e0
  1. 14
      src/main/java/org/bitbiome/commands/QuizCommand.java

14
src/main/java/org/bitbiome/commands/QuizCommand.java

@ -18,11 +18,9 @@ public class QuizCommand implements CommandAPI {
String path = "src\\main\\resources\\quiz.json";
JSONObject quiz = JsonParser.readJSONFile(path);
long currentTime = System.currentTimeMillis();
long minTime = Long.parseLong(quiz.get("lastPlayed").toString()) + (60 * 5 * 1000);
if (minTime >= currentTime) {
long diff = minTime - currentTime;
System.out.println("Du darfst erst in " + diff / 1000 / 60 + " minuten spielen.");
long diffTime = canPlayAgain(quiz.getLong("lastPlayed"));
if (diffTime > 0) {
print("Du darfst erst in " + diffTime / 1000 / 60 + " minuten spielen.");
return;
}
@ -87,6 +85,12 @@ public class QuizCommand implements CommandAPI {
return gold;
}
public static long canPlayAgain(long lastPlayedTime) {
long currentTime = System.currentTimeMillis();
long minTime = lastPlayedTime + (60 * 5 * 1000);
return minTime - currentTime;
}
}
Loading…
Cancel
Save