-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCooldown.java
More file actions
53 lines (41 loc) · 1.39 KB
/
Cooldown.java
File metadata and controls
53 lines (41 loc) · 1.39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
package com.imdrops.xhg;
import org.bukkit.entity.Player;
public class Cooldown {
private double cooldownStart;
private double cooldownTime;
private double intervalBetweenChatInfo;
private double lastChatMessage;
public Cooldown(int millisBetweenChatInfo){
intervalBetweenChatInfo = millisBetweenChatInfo;
}
public void setCooldown(double seconds){
this.cooldownTime = seconds * 1000;
this.cooldownStart = System.currentTimeMillis();
}
public boolean isCooldownOver(){
if (cooldownStart + cooldownTime < System.currentTimeMillis()){
cooldownTime = 0;
cooldownStart = 0;
return true;
}
return false;
}
public int getCooldownRemaining(){
return (int) (cooldownTime - (System.currentTimeMillis() - cooldownStart))/ 1000;
}
public boolean isCooldownActive(){
if(cooldownTime == 0){
return false;
}
return true;
}
public void printCooldownTime(Player p){
if(this.isCooldownOver()){
return;
}
if(System.currentTimeMillis() > lastChatMessage + intervalBetweenChatInfo){
lastChatMessage = System.currentTimeMillis();
p.sendMessage("§c" + this.getCooldownRemaining() + " §2seconds cooldown left.");
}
}
}