AsyncSendPlayerSuggestionsEvent Brigadier Event
Going to be used for ACF to be able to send Tooltips to client :) This is after completions are calculated, to control what is sent to the client.
This commit is contained in:
parent
a9e20e5f62
commit
0dd1907568
3 changed files with 113 additions and 4 deletions
|
@ -0,0 +1,77 @@
|
||||||
|
package com.destroystokyo.paper.event.brigadier;
|
||||||
|
|
||||||
|
import com.mojang.brigadier.suggestion.Suggestions;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.event.Cancellable;
|
||||||
|
import org.bukkit.event.Event;
|
||||||
|
import org.bukkit.event.HandlerList;
|
||||||
|
import org.bukkit.event.player.PlayerEvent;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Called when sending Suggestions to the client. Will be called asynchronously if a plugin
|
||||||
|
* marks the AsyncTabComplete event handled asynchronously, otherwise called synchronously.
|
||||||
|
*/
|
||||||
|
public class AsyncSendPlayerSuggestionsEvent extends PlayerEvent implements Cancellable {
|
||||||
|
|
||||||
|
private static final HandlerList handlers = new HandlerList();
|
||||||
|
private boolean cancelled = false;
|
||||||
|
|
||||||
|
private Suggestions suggestions;
|
||||||
|
private final String buffer;
|
||||||
|
|
||||||
|
public AsyncSendPlayerSuggestionsEvent(Player player, Suggestions suggestions, String buffer) {
|
||||||
|
super(player, !Bukkit.isPrimaryThread());
|
||||||
|
this.suggestions = suggestions;
|
||||||
|
this.buffer = buffer;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return The input buffer sent to request these suggestions
|
||||||
|
*/
|
||||||
|
public String getBuffer() {
|
||||||
|
return buffer;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return The suggestions being sent to client
|
||||||
|
*/
|
||||||
|
public Suggestions getSuggestions() {
|
||||||
|
return suggestions;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param suggestions The suggestions to be sent to client if need to change them
|
||||||
|
*/
|
||||||
|
public void setSuggestions(Suggestions suggestions) {
|
||||||
|
this.suggestions = suggestions;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritDoc}
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public boolean isCancelled() {
|
||||||
|
return this.cancelled;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Cancels sending suggestions to the client
|
||||||
|
* {@inheritDoc}
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void setCancelled(boolean cancel) {
|
||||||
|
this.cancelled = cancel;
|
||||||
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
public HandlerList getHandlers() {
|
||||||
|
return handlers;
|
||||||
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
public static HandlerList getHandlerList() {
|
||||||
|
return handlers;
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,4 +1,4 @@
|
||||||
From c6d1d92f36b8a4031a470e690908abe589ca58d8 Mon Sep 17 00:00:00 2001
|
From 93ca45257861ecd220c28c8e9b14638d6e3206dc Mon Sep 17 00:00:00 2001
|
||||||
From: Aikar <aikar@aikar.co>
|
From: Aikar <aikar@aikar.co>
|
||||||
Date: Sun, 19 Apr 2020 18:15:29 -0400
|
Date: Sun, 19 Apr 2020 18:15:29 -0400
|
||||||
Subject: [PATCH] Implement Brigadier Mojang API
|
Subject: [PATCH] Implement Brigadier Mojang API
|
||||||
|
@ -68,6 +68,38 @@ index 0b23a0548d..c988c929f1 100644
|
||||||
@Override
|
@Override
|
||||||
public boolean hasPermission(int i) {
|
public boolean hasPermission(int i) {
|
||||||
// CraftBukkit start
|
// CraftBukkit start
|
||||||
|
diff --git a/src/main/java/net/minecraft/server/PlayerConnection.java b/src/main/java/net/minecraft/server/PlayerConnection.java
|
||||||
|
index 38ec22f4c0..376f7f8f0b 100644
|
||||||
|
--- a/src/main/java/net/minecraft/server/PlayerConnection.java
|
||||||
|
+++ b/src/main/java/net/minecraft/server/PlayerConnection.java
|
||||||
|
@@ -576,8 +576,12 @@ public class PlayerConnection implements PacketListenerPlayIn {
|
||||||
|
ParseResults<CommandListenerWrapper> parseresults = this.minecraftServer.getCommandDispatcher().a().parse(stringreader, this.player.getCommandListener());
|
||||||
|
|
||||||
|
this.minecraftServer.getCommandDispatcher().a().getCompletionSuggestions(parseresults).thenAccept((suggestions) -> {
|
||||||
|
- if (((Suggestions) suggestions).isEmpty()) return; // CraftBukkit - don't send through empty suggestions - prevents [<args>] from showing for plugins with nothing more to offer
|
||||||
|
- this.networkManager.sendPacket(new PacketPlayOutTabComplete(packetplayintabcomplete.b(), (Suggestions) suggestions)); // CraftBukkit - decompile error
|
||||||
|
+ // Paper start
|
||||||
|
+ com.destroystokyo.paper.event.brigadier.AsyncSendPlayerSuggestionsEvent suggestEvent = new com.destroystokyo.paper.event.brigadier.AsyncSendPlayerSuggestionsEvent(this.getPlayer(), suggestions, buffer);
|
||||||
|
+ suggestEvent.setCancelled(suggestions.isEmpty());
|
||||||
|
+ if (!suggestEvent.callEvent()) return;
|
||||||
|
+ this.networkManager.sendPacket(new PacketPlayOutTabComplete(packetplayintabcomplete.b(), (Suggestions) suggestEvent.getSuggestions())); // CraftBukkit - decompile error // Paper
|
||||||
|
+ // Paper end
|
||||||
|
});
|
||||||
|
}); // Paper - This needs to be on main
|
||||||
|
}
|
||||||
|
@@ -587,7 +591,11 @@ public class PlayerConnection implements PacketListenerPlayIn {
|
||||||
|
|
||||||
|
builder = builder.createOffset(builder.getInput().lastIndexOf(' ') + 1);
|
||||||
|
completions.forEach(builder::suggest);
|
||||||
|
- player.playerConnection.sendPacket(new PacketPlayOutTabComplete(packetplayintabcomplete.b(), builder.buildFuture().join()));
|
||||||
|
+ Suggestions suggestions = builder.buildFuture().join();
|
||||||
|
+ com.destroystokyo.paper.event.brigadier.AsyncSendPlayerSuggestionsEvent suggestEvent = new com.destroystokyo.paper.event.brigadier.AsyncSendPlayerSuggestionsEvent(this.getPlayer(), suggestions, buffer);
|
||||||
|
+ suggestEvent.setCancelled(suggestions.isEmpty());
|
||||||
|
+ if (!suggestEvent.callEvent()) return;
|
||||||
|
+ this.networkManager.sendPacket(new PacketPlayOutTabComplete(packetplayintabcomplete.b(), suggestEvent.getSuggestions()));
|
||||||
|
}
|
||||||
|
// Paper end - async tab completion
|
||||||
|
|
||||||
diff --git a/src/main/java/org/bukkit/craftbukkit/command/BukkitCommandWrapper.java b/src/main/java/org/bukkit/craftbukkit/command/BukkitCommandWrapper.java
|
diff --git a/src/main/java/org/bukkit/craftbukkit/command/BukkitCommandWrapper.java b/src/main/java/org/bukkit/craftbukkit/command/BukkitCommandWrapper.java
|
||||||
index 5f33c9e52a..e16ecdea7d 100644
|
index 5f33c9e52a..e16ecdea7d 100644
|
||||||
--- a/src/main/java/org/bukkit/craftbukkit/command/BukkitCommandWrapper.java
|
--- a/src/main/java/org/bukkit/craftbukkit/command/BukkitCommandWrapper.java
|
||||||
|
|
|
@ -1,14 +1,14 @@
|
||||||
From 954203816cd42cff061c4a633ad346bd3dab5073 Mon Sep 17 00:00:00 2001
|
From dcd786960faeeeea7fa3106571ac2e20aae1cf0a Mon Sep 17 00:00:00 2001
|
||||||
From: Aikar <aikar@aikar.co>
|
From: Aikar <aikar@aikar.co>
|
||||||
Date: Sat, 2 May 2020 03:09:46 -0400
|
Date: Sat, 2 May 2020 03:09:46 -0400
|
||||||
Subject: [PATCH] Validate PickItem Packet and kick for invalid
|
Subject: [PATCH] Validate PickItem Packet and kick for invalid
|
||||||
|
|
||||||
|
|
||||||
diff --git a/src/main/java/net/minecraft/server/PlayerConnection.java b/src/main/java/net/minecraft/server/PlayerConnection.java
|
diff --git a/src/main/java/net/minecraft/server/PlayerConnection.java b/src/main/java/net/minecraft/server/PlayerConnection.java
|
||||||
index 38ec22f4c0..2d83db9b22 100644
|
index 376f7f8f0b..a33289749c 100644
|
||||||
--- a/src/main/java/net/minecraft/server/PlayerConnection.java
|
--- a/src/main/java/net/minecraft/server/PlayerConnection.java
|
||||||
+++ b/src/main/java/net/minecraft/server/PlayerConnection.java
|
+++ b/src/main/java/net/minecraft/server/PlayerConnection.java
|
||||||
@@ -683,7 +683,14 @@ public class PlayerConnection implements PacketListenerPlayIn {
|
@@ -691,7 +691,14 @@ public class PlayerConnection implements PacketListenerPlayIn {
|
||||||
@Override
|
@Override
|
||||||
public void a(PacketPlayInPickItem packetplayinpickitem) {
|
public void a(PacketPlayInPickItem packetplayinpickitem) {
|
||||||
PlayerConnectionUtils.ensureMainThread(packetplayinpickitem, this, this.player.getWorldServer());
|
PlayerConnectionUtils.ensureMainThread(packetplayinpickitem, this, this.player.getWorldServer());
|
||||||
|
|
Loading…
Reference in a new issue