Archiviert
13
0
Dieses Repository wurde am 2024-12-25 archiviert. Du kannst Dateien ansehen und es klonen, aber nicht pushen oder Issues/Pull-Requests öffnen.
Paper-Old/Spigot-API-Patches/0055-Add-UnknownCommandEvent.patch

127 Zeilen
3.6 KiB
Diff

From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
2017-06-18 02:53:31 +02:00
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..d5632d352590dec6982a372b285a8d4a332fa589
2017-06-18 02:53:31 +02:00
--- /dev/null
+++ b/src/main/java/org/bukkit/event/command/UnknownCommandEvent.java
@@ -0,0 +1,114 @@
2017-06-18 02:53:31 +02:00
+package org.bukkit.event.command;
+
+import net.kyori.adventure.text.Component;
+import org.bukkit.Bukkit;
2017-06-18 02:53:31 +02:00
+import org.bukkit.command.CommandSender;
+import org.bukkit.event.HandlerList;
+import org.bukkit.event.Event;
+
+import org.jetbrains.annotations.NotNull;
+import org.jetbrains.annotations.Nullable;
2017-06-18 02:53:31 +02:00
+
+/**
+ * Thrown when a player executes a command that is not defined
+ */
+public class UnknownCommandEvent extends Event {
+ private static final HandlerList handlers = new HandlerList();
+ @NotNull private CommandSender sender;
+ @NotNull private String commandLine;
+ @Nullable private Component message;
2017-06-18 02:53:31 +02:00
+
+ @Deprecated
+ public UnknownCommandEvent(@NotNull final CommandSender sender, @NotNull final String commandLine, @Nullable final String message) {
+ this(sender, commandLine, message == null ? null : Bukkit.getUnsafe().legacyComponentSerializer().deserialize(message));
+ }
+
+ public UnknownCommandEvent(@NotNull final CommandSender sender, @NotNull final String commandLine, @Nullable final Component message) {
2017-06-18 02:53:31 +02:00
+ super(false);
+ this.sender = sender;
+ this.commandLine = commandLine;
+ this.message = message;
+ }
+
+ /**
+ * Gets the CommandSender or ConsoleCommandSender
+ * <p>
+ *
+ * @return Sender of the command
+ */
+ @NotNull
2017-06-18 02:53:31 +02:00
+ public CommandSender getSender() {
+ return sender;
+ }
+
+ /**
+ * Gets the command that was send
+ * <p>
+ *
+ * @return Command sent
+ */
+ @NotNull
2017-06-18 02:53:31 +02:00
+ public String getCommandLine() {
+ return commandLine;
+ }
+
+ /**
+ * Gets message that will be returned
+ * <p>
+ *
+ * @return Unknown command message
+ * @deprecated use {@link #message()}
2017-06-18 02:53:31 +02:00
+ */
+ @Nullable
+ @Deprecated
2017-06-18 02:53:31 +02:00
+ public String getMessage() {
+ return this.message == null ? null : Bukkit.getUnsafe().legacyComponentSerializer().serialize(this.message);
2017-06-18 02:53:31 +02:00
+ }
+
+ /**
+ * Sets message that will be returned
+ * <p>
+ * Set to null to avoid any message being sent
2017-07-03 17:38:49 +02:00
+ *
+ * @param message the message to be returned, or null
+ * @deprecated use {@link #message(Component)}
2017-06-18 02:53:31 +02:00
+ */
+ @Deprecated
+ public void setMessage(@Nullable String message) {
+ this.message(message == null ? null : Bukkit.getUnsafe().legacyComponentSerializer().deserialize(message));
+ }
+
+ /**
+ * Gets message that will be returned
+ * <p>
+ *
+ * @return Unknown command message
+ */
+ @Nullable
+ public Component message() {
+ return this.message;
+ }
+
+ /**
+ * Sets message that will be returned
+ * <p>
+ * Set to null to avoid any message being sent
+ *
+ * @param message the message to be returned, or null
+ */
+ public void message(@Nullable Component message) {
2017-06-18 02:53:31 +02:00
+ this.message = message;
+ }
+
+ @NotNull
2017-06-18 02:53:31 +02:00
+ @Override
+ public HandlerList getHandlers() {
+ return handlers;
+ }
+
+ @NotNull
2017-06-18 02:53:31 +02:00
+ public static HandlerList getHandlerList() {
+ return handlers;
+ }
+}
+