PaperMC/patches/api/Add-UnknownCommandEvent.patch

118 lines
3.4 KiB
Diff
Raw Normal View History

2021-06-11 14:02:28 +02:00
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..0000000000000000000000000000000000000000
--- /dev/null
+++ b/src/main/java/org/bukkit/event/command/UnknownCommandEvent.java
@@ -0,0 +0,0 @@
+package org.bukkit.event.command;
+
+import net.kyori.adventure.text.Component;
+import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
2021-06-11 14:02:28 +02:00
+import org.bukkit.command.CommandSender;
+import org.bukkit.event.Event;
+import org.bukkit.event.HandlerList;
2024-02-01 10:15:57 +01:00
+import org.jetbrains.annotations.ApiStatus;
+import org.jetbrains.annotations.Contract;
+import org.jspecify.annotations.NullMarked;
+import org.jspecify.annotations.Nullable;
2021-06-11 14:02:28 +02:00
+
+/**
+ * Thrown when a player executes a command that is not defined
+ */
+@NullMarked
2021-06-11 14:02:28 +02:00
+public class UnknownCommandEvent extends Event {
2024-02-01 10:15:57 +01:00
+
+ private static final HandlerList HANDLER_LIST = new HandlerList();
+
+ private final CommandSender sender;
+ private final String commandLine;
+ private @Nullable Component message;
2021-06-11 14:02:28 +02:00
+
2024-02-01 10:15:57 +01:00
+ @ApiStatus.Internal
+ public UnknownCommandEvent(final CommandSender sender, final String commandLine, final @Nullable Component message) {
2021-06-11 14:02:28 +02:00
+ super(false);
+ this.sender = sender;
+ this.commandLine = commandLine;
+ this.message = message;
+ }
+
+ /**
+ * Gets the CommandSender or ConsoleCommandSender
+ *
+ * @return Sender of the command
+ */
+ public CommandSender getSender() {
2024-02-01 10:15:57 +01:00
+ return this.sender;
2021-06-11 14:02:28 +02:00
+ }
+
+ /**
2024-02-01 10:15:57 +01:00
+ * Gets the command that was sent
2021-06-11 14:02:28 +02:00
+ *
+ * @return Command sent
+ */
+ public String getCommandLine() {
2024-02-01 10:15:57 +01:00
+ return this.commandLine;
2021-06-11 14:02:28 +02:00
+ }
+
+ /**
+ * Gets message that will be returned
+ *
+ * @return Unknown command message
+ * @deprecated use {@link #message()}
+ */
+ @Deprecated
+ public @Nullable String getMessage() {
+ return this.message == null ? null : LegacyComponentSerializer.legacySection().serialize(this.message);
2021-06-11 14:02:28 +02:00
+ }
+
+ /**
+ * Sets message that will be returned
+ * <p>
2024-02-01 10:15:57 +01:00
+ * Set to {@code null} to avoid any message being sent
2021-06-11 14:02:28 +02:00
+ *
2024-02-01 10:15:57 +01:00
+ * @param message the message to be returned, or {@code null}
2021-06-11 14:02:28 +02:00
+ * @deprecated use {@link #message(Component)}
+ */
+ @Deprecated
+ public void setMessage(@Nullable String message) {
+ this.message(message == null ? null : LegacyComponentSerializer.legacySection().deserialize(message));
2021-06-11 14:02:28 +02:00
+ }
+
+ /**
+ * Gets message that will be returned
+ *
+ * @return Unknown command message
+ */
+ @Contract(pure = true)
+ public @Nullable Component message() {
2021-06-11 14:02:28 +02:00
+ return this.message;
+ }
+
+ /**
+ * Sets message that will be returned
+ * <p>
2024-02-01 10:15:57 +01:00
+ * Set to {@code null} to avoid any message being sent
2021-06-11 14:02:28 +02:00
+ *
2024-02-01 10:15:57 +01:00
+ * @param message the message to be returned, or {@code null}
2021-06-11 14:02:28 +02:00
+ */
+ public void message(@Nullable Component message) {
+ this.message = message;
+ }
+
+ @Override
+ public HandlerList getHandlers() {
2024-02-01 10:15:57 +01:00
+ return HANDLER_LIST;
2021-06-11 14:02:28 +02:00
+ }
+
+ public static HandlerList getHandlerList() {
2024-02-01 10:15:57 +01:00
+ return HANDLER_LIST;
2021-06-11 14:02:28 +02:00
+ }
+}
+