-
-
Notifications
You must be signed in to change notification settings - Fork 390
/
Copy pathScriptCommandEvent.java
94 lines (80 loc) · 2.55 KB
/
ScriptCommandEvent.java
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
package ch.njol.skript.command;
import ch.njol.skript.effects.Delay;
import ch.njol.skript.util.Date;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.event.HandlerList;
public class ScriptCommandEvent extends CommandEvent {
private final ScriptCommand scriptCommand;
private final String commandLabel;
private final String rest;
private final Date executionDate = new Date();
private boolean cooldownCancelled;
/**
* @param scriptCommand The script command executed.
* @param sender The executor of this script command.
* @param commandLabel The command name (may be the used alias)
* @param rest The rest of the command string (the arguments)
*/
public ScriptCommandEvent(ScriptCommand scriptCommand, CommandSender sender, String commandLabel, String rest) {
super(sender, scriptCommand.getLabel(), rest.split(" "));
this.scriptCommand = scriptCommand;
this.commandLabel = commandLabel;
this.rest = rest;
}
/**
* @return The script command executed.
*/
public ScriptCommand getScriptCommand() {
return scriptCommand;
}
/**
* @return The used command label. This may be a command alias.
*/
public String getCommandLabel() {
return commandLabel;
}
/**
* @return The arguments combined into one string.
* @see CommandEvent#getArgs()
*/
public String getArgsString() {
return rest;
}
/**
* Only accurate when this event is not delayed (yet)
*/
public boolean isCooldownCancelled() {
return cooldownCancelled;
}
/**
* @deprecated Use {@link #setCooldownCancelled(boolean, boolean)} instead.
*/
@Deprecated(since = "INSERT VERSION", forRemoval = true)
public void setCooldownCancelled(boolean cooldownCancelled) {
//noinspection removal
setCooldownCancelled(cooldownCancelled, Delay.isDelayed(this));
}
/**
* Sets whether the cooldown should be cancelled.
*
* @param cooldownCancelled Whether the cooldown should be cancelled.
* @param delayed Whether this event is delayed. If true, the sender's cooldown will be retroactively set.
*/
public void setCooldownCancelled(boolean cooldownCancelled, boolean delayed) {
this.cooldownCancelled = cooldownCancelled;
if (delayed && getSender() instanceof Player player) {
Date date = cooldownCancelled ? null : executionDate;
scriptCommand.setLastUsage(player.getUniqueId(), this, date);
}
}
// Bukkit stuff
private final static HandlerList handlers = new HandlerList();
@Override
public HandlerList getHandlers() {
return handlers;
}
public static HandlerList getHandlerList() {
return handlers;
}
}