-
-
Notifications
You must be signed in to change notification settings - Fork 134
/
CommandEvent.java
108 lines (86 loc) · 2.6 KB
/
CommandEvent.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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
package world.bentobox.bentobox.api.events.command;
import org.bukkit.Bukkit;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.event.Cancellable;
import org.bukkit.event.HandlerList;
import org.eclipse.jdt.annotation.NonNull;
import world.bentobox.bentobox.api.events.BentoBoxEvent;
/**
* Fired when a command event happens.
*
* @author tastybento
*/
public class CommandEvent extends BentoBoxEvent implements Cancellable {
private boolean cancelled;
private final CommandSender sender;
private final Command command;
private final String label;
private final String[] args;
private static final HandlerList handlers = new HandlerList();
@Override
public @NonNull HandlerList getHandlers() {
return getHandlerList();
}
public static HandlerList getHandlerList() {
return handlers;
}
private CommandEvent(CommandSender sender, Command command, String label, String[] args) {
super();
this.sender = sender;
this.command = command;
this.label = label;
this.args = args;
}
public static CommandEventBuilder builder() {
return new CommandEventBuilder();
}
public static class CommandEventBuilder {
// Here field are NOT final. They are just used for the building.
private CommandSender sender;
private Command command;
private String label;
private String[] args;
public CommandEventBuilder setSender(CommandSender sender) {
this.sender = sender;
return this;
}
public CommandEventBuilder setCommand(Command command) {
this.command = command;
return this;
}
public CommandEventBuilder setLabel(String label) {
this.label = label;
return this;
}
public CommandEventBuilder setArgs(String[] args) {
this.args = args;
return this;
}
public CommandEvent build() {
CommandEvent event = new CommandEvent(sender, command, label, args);
Bukkit.getPluginManager().callEvent(event);
return event;
}
}
public CommandSender getSender() {
return sender;
}
public Command getCommand() {
return command;
}
public String getLabel() {
return label;
}
public String[] getArgs() {
return args;
}
@Override
public boolean isCancelled() {
return cancelled;
}
@Override
public void setCancelled(boolean arg0) {
cancelled = arg0;
}
}