-
-
Notifications
You must be signed in to change notification settings - Fork 431
Expand file tree
/
Copy pathEffCancelCooldown.java
More file actions
69 lines (58 loc) · 1.98 KB
/
EffCancelCooldown.java
File metadata and controls
69 lines (58 loc) · 1.98 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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
package ch.njol.skript.effects;
import ch.njol.skript.lang.EventRestrictedSyntax;
import ch.njol.util.coll.CollectionUtils;
import org.bukkit.event.Event;
import org.jetbrains.annotations.Nullable;
import ch.njol.skript.Skript;
import ch.njol.skript.command.ScriptCommandEvent;
import ch.njol.skript.doc.Description;
import ch.njol.skript.doc.Example;
import ch.njol.skript.doc.Name;
import ch.njol.skript.doc.Since;
import ch.njol.skript.lang.Effect;
import ch.njol.skript.lang.Expression;
import ch.njol.skript.lang.SkriptParser;
import ch.njol.skript.log.ErrorQuality;
import ch.njol.util.Kleenean;
@Name("Cancel Command Cooldown")
@Description({"Only usable in commands. Makes it so the current command usage isn't counted towards the cooldown."})
@Example("""
command /nick <text>:
executable by: players
cooldown: 10 seconds
trigger:
if length of arg-1 is more than 16:
# Makes it so that invalid arguments don't make you wait for the cooldown again
cancel the cooldown
send "Your nickname may be at most 16 characters."
stop
set the player's display name to arg-1
""")
@Since("2.2-dev34")
public class EffCancelCooldown extends Effect implements EventRestrictedSyntax {
static {
Skript.registerEffect(EffCancelCooldown.class,
"(cancel|ignore) [the] [current] [command] cooldown",
"un(cancel|ignore) [the] [current] [command] cooldown");
}
private boolean cancel;
@Override
public boolean init(Expression<?>[] exprs, int matchedPattern, Kleenean isDelayed, SkriptParser.ParseResult parseResult) {
cancel = matchedPattern == 0;
return true;
}
@Override
public Class<? extends Event>[] supportedEvents() {
return CollectionUtils.array(ScriptCommandEvent.class);
}
@Override
protected void execute(Event e) {
if (!(e instanceof ScriptCommandEvent))
return;
((ScriptCommandEvent) e).setCooldownCancelled(cancel);
}
@Override
public String toString(@Nullable Event e, boolean debug) {
return (cancel ? "" : "un") + "cancel the command cooldown";
}
}