|
| 1 | +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 |
| 2 | +From: BillyGalbreath <blake.galbreath@gmail.com> |
| 3 | +Date: Mon, 11 Jul 2022 21:09:14 -0500 |
| 4 | +Subject: [PATCH] Chat Preview API |
| 5 | + |
| 6 | + |
| 7 | +diff --git a/src/main/java/org/purpurmc/purpur/event/player/PlayerPreviewChatEvent.java b/src/main/java/org/purpurmc/purpur/event/player/PlayerPreviewChatEvent.java |
| 8 | +new file mode 100644 |
| 9 | +index 0000000000000000000000000000000000000000..502896f69a139c9524625a2c0d9029f85276146b |
| 10 | +--- /dev/null |
| 11 | ++++ b/src/main/java/org/purpurmc/purpur/event/player/PlayerPreviewChatEvent.java |
| 12 | +@@ -0,0 +1,90 @@ |
| 13 | ++package org.purpurmc.purpur.event.player; |
| 14 | ++ |
| 15 | ++import net.kyori.adventure.text.Component; |
| 16 | ++import org.bukkit.Bukkit; |
| 17 | ++import org.bukkit.entity.Player; |
| 18 | ++import org.bukkit.event.Cancellable; |
| 19 | ++import org.bukkit.event.HandlerList; |
| 20 | ++import org.bukkit.event.player.PlayerEvent; |
| 21 | ++import org.jetbrains.annotations.NotNull; |
| 22 | ++import org.jetbrains.annotations.Nullable; |
| 23 | ++ |
| 24 | ++public class PlayerPreviewChatEvent extends PlayerEvent implements Cancellable { |
| 25 | ++ private static final HandlerList handlers = new HandlerList(); |
| 26 | ++ private final String originalQuery; |
| 27 | ++ private Component query; |
| 28 | ++ |
| 29 | ++ public PlayerPreviewChatEvent(@NotNull Player who, @NotNull String originalQuery, @Nullable Component query) { |
| 30 | ++ super(who, !Bukkit.isPrimaryThread()); |
| 31 | ++ this.originalQuery = originalQuery; |
| 32 | ++ this.query = query; |
| 33 | ++ } |
| 34 | ++ |
| 35 | ++ /** |
| 36 | ++ * The original query string as sent from the client |
| 37 | ++ * |
| 38 | ++ * @return The original query string |
| 39 | ++ */ |
| 40 | ++ @NotNull |
| 41 | ++ public String getOriginalQuery() { |
| 42 | ++ return originalQuery; |
| 43 | ++ } |
| 44 | ++ |
| 45 | ++ /** |
| 46 | ++ * Get the current query. |
| 47 | ++ * <p> |
| 48 | ++ * Null queries represent "no changes". |
| 49 | ++ * |
| 50 | ++ * @return Current query |
| 51 | ++ */ |
| 52 | ++ @Nullable |
| 53 | ++ public Component getQuery() { |
| 54 | ++ return this.query; |
| 55 | ++ } |
| 56 | ++ |
| 57 | ++ /** |
| 58 | ++ * Get the current query. |
| 59 | ++ * <p> |
| 60 | ++ * Null queries represent "no changes". |
| 61 | ++ * |
| 62 | ++ * @param query The current query |
| 63 | ++ */ |
| 64 | ++ public void setQuery(@Nullable Component query) { |
| 65 | ++ this.query = query; |
| 66 | ++ } |
| 67 | ++ |
| 68 | ++ /** |
| 69 | ++ * Gets the cancellation state of this event. |
| 70 | ++ * <p> |
| 71 | ++ * A cancelled event tells the client there are "no changes" |
| 72 | ++ * to the chat, the same as setting the query to null. |
| 73 | ++ * |
| 74 | ++ * @return true if this event is cancelled |
| 75 | ++ */ |
| 76 | ++ @Override |
| 77 | ++ public boolean isCancelled() { |
| 78 | ++ return this.query == null; |
| 79 | ++ } |
| 80 | ++ |
| 81 | ++ /** |
| 82 | ++ * Sets the cancellation state of this event. |
| 83 | ++ * <p> |
| 84 | ++ * A cancelled event tells the client there are "no changes" |
| 85 | ++ * to the chat, the same as setting the query to null. |
| 86 | ++ */ |
| 87 | ++ @Override |
| 88 | ++ public void setCancelled(boolean cancel) { |
| 89 | ++ this.query = null; |
| 90 | ++ } |
| 91 | ++ |
| 92 | ++ @Override |
| 93 | ++ @NotNull |
| 94 | ++ public HandlerList getHandlers() { |
| 95 | ++ return handlers; |
| 96 | ++ } |
| 97 | ++ |
| 98 | ++ @NotNull |
| 99 | ++ public static HandlerList getHandlerList() { |
| 100 | ++ return handlers; |
| 101 | ++ } |
| 102 | ++} |
0 commit comments