mirror of
https://github.com/PaperMC/Paper.git
synced 2024-12-29 12:27:59 +01:00
Fire TabCompleteEvent for legacy commands (#10834)
This commit is contained in:
parent
2cc4c182ae
commit
3a135ada91
@ -1974,3 +1974,16 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
|||||||
Command.broadcastCommandMessage(sender, ChatColor.GREEN + "Reload complete.");
|
Command.broadcastCommandMessage(sender, ChatColor.GREEN + "Reload complete.");
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
diff --git a/src/main/java/org/bukkit/event/server/TabCompleteEvent.java b/src/main/java/org/bukkit/event/server/TabCompleteEvent.java
|
||||||
|
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
|
||||||
|
--- a/src/main/java/org/bukkit/event/server/TabCompleteEvent.java
|
||||||
|
+++ b/src/main/java/org/bukkit/event/server/TabCompleteEvent.java
|
||||||
|
@@ -0,0 +0,0 @@ import org.jetbrains.annotations.NotNull;
|
||||||
|
* themselves. Plugins wishing to remove commands from tab completion are
|
||||||
|
* advised to ensure the client does not have permission for the relevant
|
||||||
|
* commands, or use {@link PlayerCommandSendEvent}.
|
||||||
|
+ * @apiNote Only called for bukkit API commands {@link org.bukkit.command.Command} and
|
||||||
|
+ * {@link org.bukkit.command.CommandExecutor} and not for brigadier commands ({@link io.papermc.paper.command.brigadier.Commands}).
|
||||||
|
*/
|
||||||
|
public class TabCompleteEvent extends Event implements Cancellable {
|
||||||
|
|
||||||
|
@ -1845,6 +1845,8 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
|||||||
+import com.mojang.brigadier.suggestion.SuggestionsBuilder;
|
+import com.mojang.brigadier.suggestion.SuggestionsBuilder;
|
||||||
+import com.mojang.brigadier.tree.LiteralCommandNode;
|
+import com.mojang.brigadier.tree.LiteralCommandNode;
|
||||||
+import io.papermc.paper.command.brigadier.CommandSourceStack;
|
+import io.papermc.paper.command.brigadier.CommandSourceStack;
|
||||||
|
+import java.util.ArrayList;
|
||||||
|
+import java.util.Collections;
|
||||||
+import net.minecraft.commands.CommandSource;
|
+import net.minecraft.commands.CommandSource;
|
||||||
+import org.bukkit.Bukkit;
|
+import org.bukkit.Bukkit;
|
||||||
+import org.bukkit.ChatColor;
|
+import org.bukkit.ChatColor;
|
||||||
@ -1857,6 +1859,9 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
|||||||
+import java.util.List;
|
+import java.util.List;
|
||||||
+import java.util.concurrent.CompletableFuture;
|
+import java.util.concurrent.CompletableFuture;
|
||||||
+import java.util.logging.Level;
|
+import java.util.logging.Level;
|
||||||
|
+import org.bukkit.entity.Entity;
|
||||||
|
+import org.bukkit.entity.Player;
|
||||||
|
+import org.bukkit.event.server.TabCompleteEvent;
|
||||||
+
|
+
|
||||||
+public class BukkitCommandNode extends LiteralCommandNode<CommandSourceStack> {
|
+public class BukkitCommandNode extends LiteralCommandNode<CommandSourceStack> {
|
||||||
+
|
+
|
||||||
@ -1951,6 +1956,14 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
|||||||
+ Bukkit.getServer().getLogger().log(Level.SEVERE, "Exception when " + sender.getName() + " attempted to tab complete " + builder.getRemaining(), ex);
|
+ Bukkit.getServer().getLogger().log(Level.SEVERE, "Exception when " + sender.getName() + " attempted to tab complete " + builder.getRemaining(), ex);
|
||||||
+ }
|
+ }
|
||||||
+
|
+
|
||||||
|
+ if (sender instanceof final Player player) {
|
||||||
|
+ TabCompleteEvent tabEvent = new org.bukkit.event.server.TabCompleteEvent(player, builder.getInput(), results != null ? results : new ArrayList<>(), true, pos); // Paper - AsyncTabCompleteEvent
|
||||||
|
+ if (!tabEvent.callEvent()) {
|
||||||
|
+ results = null;
|
||||||
|
+ } else {
|
||||||
|
+ results = tabEvent.getCompletions();
|
||||||
|
+ }
|
||||||
|
+ }
|
||||||
+ // Paper end
|
+ // Paper end
|
||||||
+ if (results == null) {
|
+ if (results == null) {
|
||||||
+ return builder.buildFuture();
|
+ return builder.buildFuture();
|
||||||
|
Loading…
Reference in New Issue
Block a user