Begin switching to JSpecify annotations (#11448)

* Begin switching to JSpecify annotations

* more

* fixes
This commit is contained in:
Jake Potrebic 2024-09-29 12:52:13 -07:00 committed by GitHub
parent 6d7a438fad
commit f9c7f2a5c1
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
66 changed files with 750 additions and 920 deletions

View file

@ -6,7 +6,7 @@ Subject: [PATCH] Brigadier based command API
Co-authored-by: Jake Potrebic <jake.m.potrebic@gmail.com>
diff --git a/build.gradle.kts b/build.gradle.kts
index 4da053d427f3f9c5e7fc144408836ebef80026c6..540fe7e2c110e79c3742f229b3ed8c54b101d260 100644
index 37ff4cb89dfb28eab6f836840ff1838d67895c1e..2074c9aee1affbce57571398f8519f0d425cf5e3 100644
--- a/build.gradle.kts
+++ b/build.gradle.kts
@@ -27,6 +27,7 @@ configurations.api {
@ -17,7 +17,7 @@ index 4da053d427f3f9c5e7fc144408836ebef80026c6..540fe7e2c110e79c3742f229b3ed8c54
// api dependencies are listed transitively to API consumers
api("com.google.guava:guava:32.1.2-jre")
api("com.google.code.gson:gson:2.10.1")
@@ -92,9 +93,29 @@ sourceSets {
@@ -93,9 +94,29 @@ sourceSets {
}
}
// Paper end
@ -102,10 +102,10 @@ index 0000000000000000000000000000000000000000..28b44789e3be586c4b680fff56e5d2ff
+}
diff --git a/src/main/java/com/destroystokyo/paper/event/brigadier/AsyncPlayerSendCommandsEvent.java b/src/main/java/com/destroystokyo/paper/event/brigadier/AsyncPlayerSendCommandsEvent.java
new file mode 100644
index 0000000000000000000000000000000000000000..ba5472a068075f8f7fb5b9bce05e783ca9b4ffdf
index 0000000000000000000000000000000000000000..18e0618901eb6eec7677661b8448cb95926ee3ab
--- /dev/null
+++ b/src/main/java/com/destroystokyo/paper/event/brigadier/AsyncPlayerSendCommandsEvent.java
@@ -0,0 +1,73 @@
@@ -0,0 +1,72 @@
+package com.destroystokyo.paper.event.brigadier;
+
+import com.mojang.brigadier.tree.RootCommandNode;
@ -115,7 +115,7 @@ index 0000000000000000000000000000000000000000..ba5472a068075f8f7fb5b9bce05e783c
+import org.bukkit.event.HandlerList;
+import org.bukkit.event.player.PlayerEvent;
+import org.jetbrains.annotations.ApiStatus;
+import org.jetbrains.annotations.NotNull;
+import org.jspecify.annotations.NullMarked;
+
+/**
+ * Fired any time a Brigadier RootCommandNode is generated for a player to inform the client of commands.
@ -138,6 +138,7 @@ index 0000000000000000000000000000000000000000..ba5472a068075f8f7fb5b9bce05e783c
+ * <p>This is a draft/experimental API and is subject to change.</p>
+ */
+@ApiStatus.Experimental
+@NullMarked
+public class AsyncPlayerSendCommandsEvent<S extends CommandSourceStack> extends PlayerEvent {
+
+ private static final HandlerList handlers = new HandlerList();
@ -145,7 +146,7 @@ index 0000000000000000000000000000000000000000..ba5472a068075f8f7fb5b9bce05e783c
+ private final boolean hasFiredAsync;
+
+ @ApiStatus.Internal
+ public AsyncPlayerSendCommandsEvent(@NotNull Player player, @NotNull RootCommandNode<S> node, boolean hasFiredAsync) {
+ public AsyncPlayerSendCommandsEvent(final Player player, final RootCommandNode<S> node, final boolean hasFiredAsync) {
+ super(player, !Bukkit.isPrimaryThread());
+ this.node = node;
+ this.hasFiredAsync = hasFiredAsync;
@ -156,8 +157,8 @@ index 0000000000000000000000000000000000000000..ba5472a068075f8f7fb5b9bce05e783c
+ *
+ * @return the root command node
+ */
+ public @NotNull RootCommandNode<S> getCommandNode() {
+ return node;
+ public RootCommandNode<S> getCommandNode() {
+ return this.node;
+ }
+
+ /**
@ -166,25 +167,23 @@ index 0000000000000000000000000000000000000000..ba5472a068075f8f7fb5b9bce05e783c
+ * @return whether this event has already fired asynchronously
+ */
+ public boolean hasFiredAsync() {
+ return hasFiredAsync;
+ return this.hasFiredAsync;
+ }
+
+ @NotNull
+ public HandlerList getHandlers() {
+ return handlers;
+ }
+
+ @NotNull
+ public static HandlerList getHandlerList() {
+ return handlers;
+ }
+}
diff --git a/src/main/java/com/destroystokyo/paper/event/brigadier/AsyncPlayerSendSuggestionsEvent.java b/src/main/java/com/destroystokyo/paper/event/brigadier/AsyncPlayerSendSuggestionsEvent.java
new file mode 100644
index 0000000000000000000000000000000000000000..6ac205de582983863bd5b3c0fa70d4375dd751c5
index 0000000000000000000000000000000000000000..f2ed3af699c2df92227693830c135d0b4718d41f
--- /dev/null
+++ b/src/main/java/com/destroystokyo/paper/event/brigadier/AsyncPlayerSendSuggestionsEvent.java
@@ -0,0 +1,85 @@
@@ -0,0 +1,84 @@
+package com.destroystokyo.paper.event.brigadier;
+
+import com.mojang.brigadier.suggestion.Suggestions;
@ -194,13 +193,14 @@ index 0000000000000000000000000000000000000000..6ac205de582983863bd5b3c0fa70d437
+import org.bukkit.event.HandlerList;
+import org.bukkit.event.player.PlayerEvent;
+import org.jetbrains.annotations.ApiStatus;
+import org.jetbrains.annotations.NotNull;
+import org.jspecify.annotations.NullMarked;
+
+/**
+ * Called when sending {@link Suggestions} to the client. Will be called asynchronously if a plugin
+ * marks the {@link com.destroystokyo.paper.event.server.AsyncTabCompleteEvent} event handled asynchronously,
+ * otherwise called synchronously.
+ */
+@NullMarked
+public class AsyncPlayerSendSuggestionsEvent extends PlayerEvent implements Cancellable {
+
+ private static final HandlerList handlers = new HandlerList();
@ -210,7 +210,7 @@ index 0000000000000000000000000000000000000000..6ac205de582983863bd5b3c0fa70d437
+ private final String buffer;
+
+ @ApiStatus.Internal
+ public AsyncPlayerSendSuggestionsEvent(@NotNull Player player, @NotNull Suggestions suggestions, @NotNull String buffer) {
+ public AsyncPlayerSendSuggestionsEvent(final Player player, final Suggestions suggestions, final String buffer) {
+ super(player, !Bukkit.isPrimaryThread());
+ this.suggestions = suggestions;
+ this.buffer = buffer;
@ -221,8 +221,8 @@ index 0000000000000000000000000000000000000000..6ac205de582983863bd5b3c0fa70d437
+ *
+ * @return the input buffer
+ */
+ public @NotNull String getBuffer() {
+ return buffer;
+ public String getBuffer() {
+ return this.buffer;
+ }
+
+ /**
@ -230,8 +230,8 @@ index 0000000000000000000000000000000000000000..6ac205de582983863bd5b3c0fa70d437
+ *
+ * @return the suggestions
+ */
+ public @NotNull Suggestions getSuggestions() {
+ return suggestions;
+ public Suggestions getSuggestions() {
+ return this.suggestions;
+ }
+
+ /**
@ -239,7 +239,7 @@ index 0000000000000000000000000000000000000000..6ac205de582983863bd5b3c0fa70d437
+ *
+ * @param suggestions suggestions
+ */
+ public void setSuggestions(@NotNull Suggestions suggestions) {
+ public void setSuggestions(final Suggestions suggestions) {
+ this.suggestions = suggestions;
+ }
+
@ -256,16 +256,14 @@ index 0000000000000000000000000000000000000000..6ac205de582983863bd5b3c0fa70d437
+ * {@inheritDoc}
+ */
+ @Override
+ public void setCancelled(boolean cancel) {
+ public void setCancelled(final boolean cancel) {
+ this.cancelled = cancel;
+ }
+
+ @NotNull
+ public HandlerList getHandlers() {
+ return handlers;
+ }
+
+ @NotNull
+ public static HandlerList getHandlerList() {
+ return handlers;
+ }