From a88fd61a23653b8c43ef4be649a7c96aa23484d3 Mon Sep 17 00:00:00 2001 From: sweepyoface Date: Sat, 17 Jun 2017 20:53:31 -0400 Subject: [PATCH] Add UnknownCommandEvent (#746) --- .../0057-Add-UnknownCommandEvent.patch | 90 +++++++++++++++++++ .../0218-Add-UnknownCommandEvent.patch | 35 ++++++++ 2 files changed, 125 insertions(+) create mode 100644 Spigot-API-Patches/0057-Add-UnknownCommandEvent.patch create mode 100644 Spigot-Server-Patches/0218-Add-UnknownCommandEvent.patch diff --git a/Spigot-API-Patches/0057-Add-UnknownCommandEvent.patch b/Spigot-API-Patches/0057-Add-UnknownCommandEvent.patch new file mode 100644 index 0000000000..db09901ad1 --- /dev/null +++ b/Spigot-API-Patches/0057-Add-UnknownCommandEvent.patch @@ -0,0 +1,90 @@ +From e044b4907713d4e48736de551bd97da999966ac1 Mon Sep 17 00:00:00 2001 +From: Sweepyoface +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 00000000..73f99907 +--- /dev/null ++++ b/src/main/java/org/bukkit/event/command/UnknownCommandEvent.java +@@ -0,0 +1,75 @@ ++package org.bukkit.event.command; ++ ++import org.bukkit.command.CommandSender; ++import org.bukkit.event.HandlerList; ++import org.bukkit.event.Event; ++ ++import javax.annotation.Nullable; ++ ++/** ++ * Thrown when a player executes a command that is not defined ++ */ ++public class UnknownCommandEvent extends Event { ++ private static final HandlerList handlers = new HandlerList(); ++ private CommandSender sender; ++ private String commandLine; ++ private String message; ++ ++ public UnknownCommandEvent(final CommandSender sender, final String commandLine, final String message) { ++ super(false); ++ this.sender = sender; ++ this.commandLine = commandLine; ++ this.message = message; ++ } ++ ++ /** ++ * Gets the CommandSender or ConsoleCommandSender ++ *

++ * ++ * @return Sender of the command ++ */ ++ public CommandSender getSender() { ++ return sender; ++ } ++ ++ /** ++ * Gets the command that was send ++ *

++ * ++ * @return Command sent ++ */ ++ public String getCommandLine() { ++ return commandLine; ++ } ++ ++ /** ++ * Gets message that will be returned ++ *

++ * ++ * @return Unknown command message ++ */ ++ @Nullable ++ public String getMessage() { ++ return message; ++ } ++ ++ ++ /** ++ * Sets message that will be returned ++ *

++ * Set to null to avoid any message being sent ++ */ ++ public void setMessage(String message) { ++ this.message = message; ++ } ++ ++ @Override ++ public HandlerList getHandlers() { ++ return handlers; ++ } ++ ++ public static HandlerList getHandlerList() { ++ return handlers; ++ } ++} ++ +-- +2.13.0.windows.1 + diff --git a/Spigot-Server-Patches/0218-Add-UnknownCommandEvent.patch b/Spigot-Server-Patches/0218-Add-UnknownCommandEvent.patch new file mode 100644 index 0000000000..15c8f2648f --- /dev/null +++ b/Spigot-Server-Patches/0218-Add-UnknownCommandEvent.patch @@ -0,0 +1,35 @@ +From 32caa989fcdb514b6a23096fc52a6a45b3b126d6 Mon Sep 17 00:00:00 2001 +From: Sweepyoface +Date: Sat, 17 Jun 2017 18:48:21 -0400 +Subject: [PATCH] Add UnknownCommandEvent + + +diff --git a/src/main/java/org/bukkit/craftbukkit/CraftServer.java b/src/main/java/org/bukkit/craftbukkit/CraftServer.java +index df6a75b05..2a5107f66 100644 +--- a/src/main/java/org/bukkit/craftbukkit/CraftServer.java ++++ b/src/main/java/org/bukkit/craftbukkit/CraftServer.java +@@ -78,6 +78,7 @@ import org.bukkit.craftbukkit.util.Versioning; + import org.bukkit.craftbukkit.util.permissions.CraftDefaultPermissions; + import org.bukkit.entity.Entity; + import org.bukkit.entity.Player; ++import org.bukkit.event.command.UnknownCommandEvent; + import org.bukkit.event.inventory.InventoryType; + import org.bukkit.event.player.PlayerChatTabCompleteEvent; + import org.bukkit.event.world.WorldInitEvent; +@@ -671,7 +672,13 @@ public final class CraftServer implements Server { + + // Spigot start + if (StringUtils.isNotEmpty(org.spigotmc.SpigotConfig.unknownCommandMessage)) { +- sender.sendMessage(org.spigotmc.SpigotConfig.unknownCommandMessage); ++ // Paper start ++ UnknownCommandEvent event = new UnknownCommandEvent(sender, commandLine, org.spigotmc.SpigotConfig.unknownCommandMessage); ++ Bukkit.getServer().getPluginManager().callEvent(event); ++ if (StringUtils.isNotEmpty(event.getMessage())) { ++ sender.sendMessage(event.getMessage()); ++ } ++ // Paper end + } + // Spigot end + +-- +2.13.1