| 1 | /* |
| 2 | * Decompiled with CFR 0.151. |
| 3 | */ |
| 4 | package net.encode.wurmesp.util; |
| 5 | |
| 6 | import java.util.HashMap; |
| 7 | |
| 8 | public class CronoManager { |
| 9 | private long timelapse; |
| 10 | private long time; |
| 11 | private long remaining; |
| 12 | private long future; |
| 13 | private long last; |
| 14 | |
| 15 | public CronoManager(long timelapse) { |
| 16 | this.timelapse = timelapse; |
| 17 | this.time = System.currentTimeMillis(); |
| 18 | this.future = this.time + this.timelapse; |
| 19 | this.last = this.remaining = (this.future - System.currentTimeMillis()) / 1000L; |
| 20 | } |
| 21 | |
| 22 | public void restart(long timelapse) { |
| 23 | this.timelapse = timelapse; |
| 24 | this.time = System.currentTimeMillis(); |
| 25 | this.future = this.time + this.timelapse; |
| 26 | this.last = this.remaining = (this.future - System.currentTimeMillis()) / 1000L; |
| 27 | } |
| 28 | |
| 29 | public HashMap<CronoDataType, Long> getTime() { |
| 30 | this.last = this.remaining = (this.future - System.currentTimeMillis()) / 1000L; |
| 31 | long days = (long)Math.floor(this.remaining / 86400L); |
| 32 | long hours = (long)Math.floor(this.remaining % 86400L / 3600L); |
| 33 | long minutes = (long)Math.floor(this.remaining % 86400L % 3600L / 60L); |
| 34 | long seconds = (long)Math.floor(this.remaining % 86400L % 3600L % 60L); |
| 35 | HashMap<CronoDataType, Long> returnedTime = new HashMap<CronoDataType, Long>(); |
| 36 | returnedTime.put(CronoDataType.DAYS, days); |
| 37 | returnedTime.put(CronoDataType.HOURS, hours); |
| 38 | returnedTime.put(CronoDataType.MINUTES, minutes); |
| 39 | returnedTime.put(CronoDataType.SECONDS, seconds); |
| 40 | return returnedTime; |
| 41 | } |
| 42 | |
| 43 | public int getDays() { |
| 44 | this.last = this.remaining = (this.future - System.currentTimeMillis()) / 1000L; |
| 45 | long days = (long)Math.floor(this.remaining / 86400L); |
| 46 | return (int)days; |
| 47 | } |
| 48 | |
| 49 | public int getHours() { |
| 50 | this.last = this.remaining = (this.future - System.currentTimeMillis()) / 1000L; |
| 51 | long hours = (long)Math.floor(this.remaining % 86400L / 3600L); |
| 52 | return (int)hours; |
| 53 | } |
| 54 | |
| 55 | public int getMinutes() { |
| 56 | this.last = this.remaining = (this.future - System.currentTimeMillis()) / 1000L; |
| 57 | long minutes = (long)Math.floor(this.remaining % 86400L % 3600L / 60L); |
| 58 | return (int)minutes; |
| 59 | } |
| 60 | |
| 61 | public int getSeconds() { |
| 62 | this.last = this.remaining = (this.future - System.currentTimeMillis()) / 1000L; |
| 63 | long seconds = (long)Math.floor(this.remaining % 86400L % 3600L % 60L); |
| 64 | return (int)seconds; |
| 65 | } |
| 66 | |
| 67 | public boolean hasNext() { |
| 68 | this.remaining = (this.future - System.currentTimeMillis()) / 1000L; |
| 69 | return this.remaining < this.last; |
| 70 | } |
| 71 | |
| 72 | public boolean hasEnded() { |
| 73 | return System.currentTimeMillis() > this.future; |
| 74 | } |
| 75 | |
| 76 | public static enum CronoDataType { |
| 77 | DAYS, |
| 78 | HOURS, |
| 79 | MINUTES, |
| 80 | SECONDS; |
| 81 | |
| 82 | } |
| 83 | } |
| 84 | |