mirror of
https://github.com/PurpurMC/Purpur.git
synced 2026-02-17 16:37:43 +01:00
176 lines
5.9 KiB
Diff
176 lines
5.9 KiB
Diff
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
|
From: William Blake Galbreath <blake.galbreath@gmail.com>
|
|
Date: Fri, 31 May 2019 00:08:28 -0500
|
|
Subject: [PATCH] ExecuteCommandEvent
|
|
|
|
|
|
diff --git a/src/main/java/org/bukkit/command/SimpleCommandMap.java b/src/main/java/org/bukkit/command/SimpleCommandMap.java
|
|
index b8623575b1c1b565560c2dd6438190716845a652..0bc24d0effe9b2e44c41a1c00060b0ebf7395c4a 100644
|
|
--- a/src/main/java/org/bukkit/command/SimpleCommandMap.java
|
|
+++ b/src/main/java/org/bukkit/command/SimpleCommandMap.java
|
|
@@ -143,6 +143,19 @@ public class SimpleCommandMap implements CommandMap {
|
|
return false;
|
|
}
|
|
|
|
+ // Purpur start
|
|
+ String[] parsedArgs = Arrays.copyOfRange(args, 1, args.length);
|
|
+ org.purpurmc.purpur.event.ExecuteCommandEvent event = new org.purpurmc.purpur.event.ExecuteCommandEvent(sender, target, sentCommandLabel, parsedArgs);
|
|
+ if (!event.callEvent()) {
|
|
+ return true; // cancelled
|
|
+ }
|
|
+
|
|
+ sender = event.getSender();
|
|
+ target = event.getCommand();
|
|
+ sentCommandLabel = event.getLabel();
|
|
+ parsedArgs = event.getArgs();
|
|
+ // Purpur end
|
|
+
|
|
// Paper start - Plugins do weird things to workaround normal registration
|
|
if (target.timings == null) {
|
|
target.timings = co.aikar.timings.TimingsManager.getCommandTiming(null, target);
|
|
@@ -152,7 +165,7 @@ public class SimpleCommandMap implements CommandMap {
|
|
try {
|
|
try (co.aikar.timings.Timing ignored = target.timings.startTiming()) { // Paper - use try with resources
|
|
// Note: we don't return the result of target.execute as thats success / failure, we return handled (true) or not handled (false)
|
|
- target.execute(sender, sentCommandLabel, Arrays.copyOfRange(args, 1, args.length));
|
|
+ target.execute(sender, sentCommandLabel, parsedArgs); // Purpur
|
|
} // target.timings.stopTiming(); // Spigot // Paper
|
|
} catch (CommandException ex) {
|
|
server.getPluginManager().callEvent(new com.destroystokyo.paper.event.server.ServerExceptionEvent(new com.destroystokyo.paper.exception.ServerCommandException(ex, target, sender, args))); // Paper
|
|
diff --git a/src/main/java/org/purpurmc/purpur/event/ExecuteCommandEvent.java b/src/main/java/org/purpurmc/purpur/event/ExecuteCommandEvent.java
|
|
new file mode 100644
|
|
index 0000000000000000000000000000000000000000..103d5699d0993f358749b3d288b924e48b734693
|
|
--- /dev/null
|
|
+++ b/src/main/java/org/purpurmc/purpur/event/ExecuteCommandEvent.java
|
|
@@ -0,0 +1,130 @@
|
|
+package org.purpurmc.purpur.event;
|
|
+
|
|
+import org.apache.commons.lang.Validate;
|
|
+import org.bukkit.command.Command;
|
|
+import org.bukkit.command.CommandSender;
|
|
+import org.bukkit.event.Cancellable;
|
|
+import org.bukkit.event.Event;
|
|
+import org.bukkit.event.HandlerList;
|
|
+import org.jetbrains.annotations.NotNull;
|
|
+import org.jetbrains.annotations.Nullable;
|
|
+
|
|
+/**
|
|
+ * This event is called whenever someone runs a command
|
|
+ */
|
|
+public class ExecuteCommandEvent extends Event implements Cancellable {
|
|
+ private static final HandlerList handlers = new HandlerList();
|
|
+ private boolean cancel = false;
|
|
+ private CommandSender sender;
|
|
+ private Command command;
|
|
+ private String label;
|
|
+ private String[] args;
|
|
+
|
|
+ public ExecuteCommandEvent(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @Nullable String[] args) {
|
|
+ this.sender = sender;
|
|
+ this.command = command;
|
|
+ this.label = label;
|
|
+ this.args = args;
|
|
+ }
|
|
+
|
|
+ /**
|
|
+ * Gets the command that the player is attempting to execute.
|
|
+ *
|
|
+ * @return Command the player is attempting to execute
|
|
+ */
|
|
+ @NotNull
|
|
+ public Command getCommand() {
|
|
+ return command;
|
|
+ }
|
|
+
|
|
+ /**
|
|
+ * Sets the command that the player will execute.
|
|
+ *
|
|
+ * @param command New command that the player will execute
|
|
+ * @throws IllegalArgumentException if command is null or empty
|
|
+ */
|
|
+ public void setCommand(@NotNull Command command) throws IllegalArgumentException {
|
|
+ Validate.notNull(command, "Command cannot be null");
|
|
+ this.command = command;
|
|
+ }
|
|
+
|
|
+ /**
|
|
+ * Gets the sender that this command will be executed as.
|
|
+ *
|
|
+ * @return Sender this command will be executed as
|
|
+ */
|
|
+ @NotNull
|
|
+ public CommandSender getSender() {
|
|
+ return sender;
|
|
+ }
|
|
+
|
|
+ /**
|
|
+ * Sets the sender that this command will be executed as.
|
|
+ *
|
|
+ * @param sender New sender which this event will execute as
|
|
+ * @throws IllegalArgumentException if the sender provided is null
|
|
+ */
|
|
+ public void setSender(@NotNull final CommandSender sender) throws IllegalArgumentException {
|
|
+ Validate.notNull(sender, "Sender cannot be null");
|
|
+ this.sender = sender;
|
|
+ }
|
|
+
|
|
+ /**
|
|
+ * Get the label used to execute this command
|
|
+ *
|
|
+ * @return Label used to execute this command
|
|
+ */
|
|
+ @NotNull
|
|
+ public String getLabel() {
|
|
+ return label;
|
|
+ }
|
|
+
|
|
+ /**
|
|
+ * Set the label used to execute this command
|
|
+ *
|
|
+ * @param label Label used
|
|
+ */
|
|
+ public void setLabel(@NotNull String label) {
|
|
+ this.label = label;
|
|
+ }
|
|
+
|
|
+ /**
|
|
+ * Get the args passed to the command
|
|
+ *
|
|
+ * @return Args passed to the command
|
|
+ */
|
|
+ @NotNull
|
|
+ public String[] getArgs() {
|
|
+ return args;
|
|
+ }
|
|
+
|
|
+ /**
|
|
+ * Set the args passed to the command
|
|
+ *
|
|
+ * @param args Args passed to the command
|
|
+ */
|
|
+ public void setArgs(@NotNull String[] args) {
|
|
+ this.args = args;
|
|
+ }
|
|
+
|
|
+ @Override
|
|
+ public boolean isCancelled() {
|
|
+ return cancel;
|
|
+ }
|
|
+
|
|
+ @Override
|
|
+ public void setCancelled(boolean cancel) {
|
|
+ this.cancel = cancel;
|
|
+ }
|
|
+
|
|
+ @NotNull
|
|
+ @Override
|
|
+ public HandlerList getHandlers() {
|
|
+ return handlers;
|
|
+ }
|
|
+
|
|
+ @NotNull
|
|
+ public static HandlerList getHandlerList() {
|
|
+ return handlers;
|
|
+ }
|
|
+}
|