1 package net
.encode
.wurmesp
.util
;
3 import java
.util
.HashMap
;
5 public class CronoManager
{
6 private long timelapse
;
8 private long remaining
;
12 public CronoManager(long timelapse
) {
13 this.timelapse
= timelapse
;
14 this.time
= System
.currentTimeMillis();
15 this.future
= this.time
+ this.timelapse
;
16 this.last
= this.remaining
= (this.future
- System
.currentTimeMillis()) / 1000L;
19 public void restart(long timelapse
) {
20 this.timelapse
= timelapse
;
21 this.time
= System
.currentTimeMillis();
22 this.future
= this.time
+ this.timelapse
;
23 this.last
= this.remaining
= (this.future
- System
.currentTimeMillis()) / 1000L;
26 public HashMap
<CronoDataType
, Long
> getTime() {
27 this.last
= this.remaining
= (this.future
- System
.currentTimeMillis()) / 1000L;
28 long days
= (long)Math
.floor(this.remaining
/ 86400L);
29 long hours
= (long)Math
.floor(this.remaining
% 86400L / 3600L);
30 long minutes
= (long)Math
.floor(this.remaining
% 86400L % 3600L / 60L);
31 long seconds
= (long)Math
.floor(this.remaining
% 86400L % 3600L % 60L);
32 HashMap
<CronoDataType
, Long
> returnedTime
= new HashMap
<CronoDataType
, Long
>();
33 returnedTime
.put(CronoDataType
.DAYS
, days
);
34 returnedTime
.put(CronoDataType
.HOURS
, hours
);
35 returnedTime
.put(CronoDataType
.MINUTES
, minutes
);
36 returnedTime
.put(CronoDataType
.SECONDS
, seconds
);
40 public int getDays() {
41 this.last
= this.remaining
= (this.future
- System
.currentTimeMillis()) / 1000L;
42 long days
= (long)Math
.floor(this.remaining
/ 86400L);
46 public int getHours() {
47 this.last
= this.remaining
= (this.future
- System
.currentTimeMillis()) / 1000L;
48 long hours
= (long)Math
.floor(this.remaining
% 86400L / 3600L);
52 public int getMinutes() {
53 this.last
= this.remaining
= (this.future
- System
.currentTimeMillis()) / 1000L;
54 long minutes
= (long)Math
.floor(this.remaining
% 86400L % 3600L / 60L);
58 public int getSeconds() {
59 this.last
= this.remaining
= (this.future
- System
.currentTimeMillis()) / 1000L;
60 long seconds
= (long)Math
.floor(this.remaining
% 86400L % 3600L % 60L);
64 public boolean hasNext() {
65 this.remaining
= (this.future
- System
.currentTimeMillis()) / 1000L;
66 return this.remaining
< this.last
;
69 public boolean hasEnded() {
70 return System
.currentTimeMillis() > this.future
;
73 public static enum CronoDataType
{