From 20ce9eaffb7f3a65c5e99b67efb2217f9fffd869 Mon Sep 17 00:00:00 2001 From: Parker Hawke Date: Sat, 4 Mar 2023 08:40:21 +1100 Subject: [PATCH] #1141: Add methods to edit custom chat completions --- .../craftbukkit/entity/CraftPlayer.java | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java b/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java index 7bfea1927..42e734fc5 100644 --- a/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java +++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java @@ -38,6 +38,7 @@ import net.minecraft.network.PacketDataSerializer; import net.minecraft.network.chat.IChatBaseComponent; import net.minecraft.network.chat.PlayerChatMessage; import net.minecraft.network.protocol.game.ClientboundClearTitlesPacket; +import net.minecraft.network.protocol.game.ClientboundCustomChatCompletionsPacket; import net.minecraft.network.protocol.game.ClientboundPlayerInfoRemovePacket; import net.minecraft.network.protocol.game.ClientboundPlayerInfoUpdatePacket; import net.minecraft.network.protocol.game.ClientboundSetBorderCenterPacket; @@ -839,6 +840,28 @@ public class CraftPlayer extends CraftHumanEntity implements Player { getHandle().connection.send(packet); } + @Override + public void addCustomChatCompletions(Collection completions) { + this.sendCustomChatCompletionPacket(completions, ClientboundCustomChatCompletionsPacket.a.ADD); + } + + @Override + public void removeCustomChatCompletions(Collection completions) { + this.sendCustomChatCompletionPacket(completions, ClientboundCustomChatCompletionsPacket.a.REMOVE); + } + + @Override + public void setCustomChatCompletions(Collection completions) { + this.sendCustomChatCompletionPacket(completions, ClientboundCustomChatCompletionsPacket.a.SET); + } + + private void sendCustomChatCompletionPacket(Collection completions, ClientboundCustomChatCompletionsPacket.a action) { // PAIL rename Action + if (getHandle().connection == null) return; + + ClientboundCustomChatCompletionsPacket packet = new ClientboundCustomChatCompletionsPacket(action, new ArrayList<>(completions)); + getHandle().connection.send(packet); + } + @Override public void setRotation(float yaw, float pitch) { throw new UnsupportedOperationException("Cannot set rotation of players. Consider teleporting instead.");