aboutsummaryrefslogtreecommitdiffhomepage
path: root/patches/api/0059-Add-UnknownCommandEvent.patch
blob: fb53ee7d609687ffd5684952bfd1b406c76a0e85 (plain)
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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Sweepyoface <github@sweepy.pw>
Date: Sat, 17 Jun 2017 18:48:06 -0400
Subject: [PATCH] Add UnknownCommandEvent


diff --git a/src/main/java/org/bukkit/event/command/UnknownCommandEvent.java b/src/main/java/org/bukkit/event/command/UnknownCommandEvent.java
new file mode 100644
index 0000000000000000000000000000000000000000..9bdeeecdb6021d61fd9141270011e56b06a58a76
--- /dev/null
+++ b/src/main/java/org/bukkit/event/command/UnknownCommandEvent.java
@@ -0,0 +1,110 @@
+package org.bukkit.event.command;
+
+import net.kyori.adventure.text.Component;
+import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
+import org.bukkit.command.CommandSender;
+import org.bukkit.event.Event;
+import org.bukkit.event.HandlerList;
+import org.jetbrains.annotations.ApiStatus;
+import org.jetbrains.annotations.Contract;
+import org.jetbrains.annotations.NotNull;
+import org.jetbrains.annotations.Nullable;
+
+/**
+ * Thrown when a player executes a command that is not defined
+ */
+public class UnknownCommandEvent extends Event {
+
+    private static final HandlerList HANDLER_LIST = new HandlerList();
+
+    @NotNull private final CommandSender sender;
+    @NotNull private final String commandLine;
+    @Nullable private Component message;
+
+    @ApiStatus.Internal
+    public UnknownCommandEvent(@NotNull final CommandSender sender, @NotNull final String commandLine, @Nullable final Component message) {
+        super(false);
+        this.sender = sender;
+        this.commandLine = commandLine;
+        this.message = message;
+    }
+
+    /**
+     * Gets the CommandSender or ConsoleCommandSender
+     *
+     * @return Sender of the command
+     */
+    @NotNull
+    public CommandSender getSender() {
+        return this.sender;
+    }
+
+    /**
+     * Gets the command that was sent
+     *
+     * @return Command sent
+     */
+    @NotNull
+    public String getCommandLine() {
+        return this.commandLine;
+    }
+
+    /**
+     * Gets message that will be returned
+     *
+     * @return Unknown command message
+     * @deprecated use {@link #message()}
+     */
+    @Nullable
+    @Deprecated
+    public String getMessage() {
+        return this.message == null ? null : LegacyComponentSerializer.legacySection().serialize(this.message);
+    }
+
+    /**
+     * Sets message that will be returned
+     * <p>
+     * Set to {@code null} to avoid any message being sent
+     *
+     * @param message the message to be returned, or {@code null}
+     * @deprecated use {@link #message(Component)}
+     */
+    @Deprecated
+    public void setMessage(@Nullable String message) {
+        this.message(message == null ? null : LegacyComponentSerializer.legacySection().deserialize(message));
+    }
+
+    /**
+     * Gets message that will be returned
+     *
+     * @return Unknown command message
+     */
+    @Nullable
+    @Contract(pure = true)
+    public Component message() {
+        return this.message;
+    }
+
+    /**
+     * Sets message that will be returned
+     * <p>
+     * Set to {@code null} to avoid any message being sent
+     *
+     * @param message the message to be returned, or {@code null}
+     */
+    public void message(@Nullable Component message) {
+        this.message = message;
+    }
+
+    @NotNull
+    @Override
+    public HandlerList getHandlers() {
+        return HANDLER_LIST;
+    }
+
+    @NotNull
+    public static HandlerList getHandlerList() {
+        return HANDLER_LIST;
+    }
+}
+