Skip to content

Commit e2ee12d

Browse files
brickmonsterOwen1212055
authored andcommitted
Add some missing annotations and use jspecify
1 parent ce0fa4c commit e2ee12d

2 files changed

Lines changed: 40 additions & 42 deletions

File tree

paper-api/src/main/java/org/bukkit/entity/Player.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,7 @@ default net.kyori.adventure.identity.Identity identity() {
293293
* set in the client, the {@link CompletableFuture} will complete with a
294294
* null value.
295295
*/
296-
CompletableFuture<byte[]> retrieveCookie(NamespacedKey key);
296+
CompletableFuture<byte @Nullable []> retrieveCookie(NamespacedKey key);
297297

298298
/**
299299
* Stores a cookie in this player's client.
@@ -1178,7 +1178,7 @@ void sendSignChange(Location loc, java.util.@Nullable List<? extends net.kyori.a
11781178
* (constructed e.g. via {@link Material#createBlockData()})
11791179
*/
11801180
@Deprecated // Paper
1181-
public void sendSignChange(Location loc, @Nullable String[] lines) throws IllegalArgumentException;
1181+
public void sendSignChange(Location loc, @Nullable String @Nullable [] lines) throws IllegalArgumentException;
11821182

11831183
/**
11841184
* Send a sign change. This fakes a sign change packet for a user at
@@ -1204,7 +1204,7 @@ void sendSignChange(Location loc, java.util.@Nullable List<? extends net.kyori.a
12041204
* (constructed e.g. via {@link Material#createBlockData()})
12051205
*/
12061206
@Deprecated // Paper
1207-
public void sendSignChange(Location loc, @Nullable String[] lines, DyeColor dyeColor) throws IllegalArgumentException;
1207+
public void sendSignChange(Location loc, @Nullable String @Nullable [] lines, DyeColor dyeColor) throws IllegalArgumentException;
12081208

12091209
/**
12101210
* Send a sign change. This fakes a sign change packet for a user at
@@ -1231,7 +1231,7 @@ void sendSignChange(Location loc, java.util.@Nullable List<? extends net.kyori.a
12311231
* (constructed e.g. via {@link Material#createBlockData()})
12321232
*/
12331233
@Deprecated // Paper
1234-
public void sendSignChange(Location loc, @Nullable String[] lines, DyeColor dyeColor, boolean hasGlowingText) throws IllegalArgumentException;
1234+
public void sendSignChange(Location loc, @Nullable String @Nullable [] lines, DyeColor dyeColor, boolean hasGlowingText) throws IllegalArgumentException;
12351235

12361236
/**
12371237
* Send a TileState change. This fakes a TileState change for a user at
@@ -2836,7 +2836,7 @@ default boolean hasResourcePack() {
28362836
* @throws IllegalArgumentException Thrown if the hash is not 20 bytes
28372837
* long.
28382838
*/
2839-
public void addResourcePack(UUID id, String url, @Nullable byte[] hash, @Nullable String prompt, boolean force);
2839+
public void addResourcePack(UUID id, String url, byte @Nullable [] hash, @Nullable String prompt, boolean force);
28402840

28412841
/**
28422842
* Request that the player's client remove a resource pack sent by the

paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java

Lines changed: 35 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
import java.util.logging.Level;
4343
import java.util.logging.Logger;
4444
import java.util.stream.Collectors;
45-
import javax.annotation.Nullable;
45+
import net.kyori.adventure.util.TriState;
4646
import net.md_5.bungee.api.chat.BaseComponent;
4747
import net.minecraft.advancements.AdvancementProgress;
4848
import net.minecraft.commands.Commands;
@@ -202,7 +202,8 @@
202202
import org.bukkit.potion.PotionEffect;
203203
import org.bukkit.potion.PotionEffectType;
204204
import org.bukkit.scoreboard.Scoreboard;
205-
import org.jetbrains.annotations.NotNull;
205+
import org.jspecify.annotations.NonNull;
206+
import org.jspecify.annotations.Nullable;
206207

207208
@DelegateDeserialization(CraftOfflinePlayer.class)
208209
public class CraftPlayer extends CraftHumanEntity implements Player {
@@ -328,7 +329,7 @@ public interface TransferCookieConnection {
328329
void kickPlayer(Component reason, org.bukkit.event.player.PlayerKickEvent.Cause cause); // Paper - kick event causes
329330
}
330331

331-
public record CookieFuture(ResourceLocation key, CompletableFuture<byte[]> future) {
332+
public record CookieFuture(ResourceLocation key, CompletableFuture<byte @Nullable []> future) {
332333

333334
}
334335
private final Queue<CookieFuture> requestedCookies = new LinkedList<>();
@@ -357,10 +358,10 @@ public boolean isTransferred() {
357358
}
358359

359360
@Override
360-
public CompletableFuture<byte[]> retrieveCookie(NamespacedKey key) {
361+
public CompletableFuture<byte @Nullable []> retrieveCookie(final NamespacedKey key) {
361362
Preconditions.checkArgument(key != null, "Cookie key cannot be null");
362363

363-
CompletableFuture<byte[]> future = new CompletableFuture<>();
364+
CompletableFuture<byte @Nullable []> future = new CompletableFuture<>();
364365
ResourceLocation nms = CraftNamespacedKey.toMinecraft(key);
365366
this.requestedCookies.add(new CookieFuture(nms, future));
366367

@@ -458,7 +459,7 @@ public void sendMessage(UUID sender, String... messages) {
458459
@Override
459460
@Deprecated
460461
public void sendActionBar(BaseComponent[] message) {
461-
if (getHandle().connection == null) return;
462+
if (getHandle().connection == null || message == null) return;
462463
net.minecraft.network.protocol.game.ClientboundSetActionBarTextPacket packet = new net.minecraft.network.protocol.game.ClientboundSetActionBarTextPacket(org.bukkit.craftbukkit.util.CraftChatMessage.bungeeToVanilla(message));
463464
getHandle().connection.send(packet);
464465
}
@@ -478,7 +479,7 @@ public void sendActionBar(char alternateChar, String message) {
478479
}
479480

480481
@Override
481-
public void setPlayerListHeaderFooter(BaseComponent[] header, BaseComponent[] footer) {
482+
public void setPlayerListHeaderFooter(BaseComponent @Nullable [] header, BaseComponent @Nullable [] footer) {
482483
if (header != null) {
483484
String headerJson = CraftChatMessage.bungeeToJson(header);
484485
playerListHeader = net.kyori.adventure.text.serializer.gson.GsonComponentSerializer.gson().deserialize(headerJson);
@@ -497,12 +498,11 @@ public void setPlayerListHeaderFooter(BaseComponent[] header, BaseComponent[] fo
497498
}
498499

499500
@Override
500-
public void setPlayerListHeaderFooter(BaseComponent header, BaseComponent footer) {
501+
public void setPlayerListHeaderFooter(@Nullable BaseComponent header, @Nullable BaseComponent footer) {
501502
this.setPlayerListHeaderFooter(header == null ? null : new BaseComponent[]{header},
502503
footer == null ? null : new BaseComponent[]{footer});
503504
}
504505

505-
506506
@Override
507507
public void setTitleTimes(int fadeInTicks, int stayTicks, int fadeOutTicks) {
508508
getHandle().connection.send(new ClientboundSetTitlesAnimationPacket(fadeInTicks, stayTicks, fadeOutTicks));
@@ -736,15 +736,15 @@ public void sendOpLevel(byte level) {
736736
}
737737

738738
@Override
739-
public void addAdditionalChatCompletions(@NotNull Collection<String> completions) {
739+
public void addAdditionalChatCompletions(@NonNull Collection<String> completions) {
740740
this.getHandle().connection.send(new net.minecraft.network.protocol.game.ClientboundCustomChatCompletionsPacket(
741741
net.minecraft.network.protocol.game.ClientboundCustomChatCompletionsPacket.Action.ADD,
742742
new ArrayList<>(completions)
743743
));
744744
}
745745

746746
@Override
747-
public void removeAdditionalChatCompletions(@NotNull Collection<String> completions) {
747+
public void removeAdditionalChatCompletions(@NonNull Collection<String> completions) {
748748
this.getHandle().connection.send(new net.minecraft.network.protocol.game.ClientboundCustomChatCompletionsPacket(
749749
net.minecraft.network.protocol.game.ClientboundCustomChatCompletionsPacket.Action.REMOVE,
750750
new ArrayList<>(completions)
@@ -1101,17 +1101,17 @@ public void sendSignChange(Location loc, @Nullable List<? extends net.kyori.adve
11011101
}
11021102
// Paper end
11031103
@Override
1104-
public void sendSignChange(Location loc, String[] lines) {
1104+
public void sendSignChange(Location loc, @Nullable String @Nullable [] lines) {
11051105
this.sendSignChange(loc, lines, DyeColor.BLACK);
11061106
}
11071107

11081108
@Override
1109-
public void sendSignChange(Location loc, String[] lines, DyeColor dyeColor) {
1109+
public void sendSignChange(Location loc, @Nullable String @Nullable [] lines, DyeColor dyeColor) {
11101110
this.sendSignChange(loc, lines, dyeColor, false);
11111111
}
11121112

11131113
@Override
1114-
public void sendSignChange(Location loc, String[] lines, DyeColor dyeColor, boolean hasGlowingText) {
1114+
public void sendSignChange(Location loc, @Nullable String @Nullable [] lines, DyeColor dyeColor, boolean hasGlowingText) {
11151115
Preconditions.checkArgument(loc != null, "Location cannot be null");
11161116
Preconditions.checkArgument(dyeColor != null, "DyeColor cannot be null");
11171117

@@ -1142,7 +1142,7 @@ private void sendSignChange0(Component[] components, Location loc, DyeColor dyeC
11421142
}
11431143

11441144
@Override
1145-
public void sendBlockUpdate(@NotNull Location location, @NotNull TileState tileState) throws IllegalArgumentException {
1145+
public void sendBlockUpdate(@NonNull Location location, @NonNull TileState tileState) throws IllegalArgumentException {
11461146
Preconditions.checkArgument(location != null, "Location can not be null");
11471147
Preconditions.checkArgument(tileState != null, "TileState can not be null");
11481148

@@ -1153,12 +1153,12 @@ public void sendBlockUpdate(@NotNull Location location, @NotNull TileState tileS
11531153
}
11541154

11551155
@Override
1156-
public void sendEquipmentChange(LivingEntity entity, EquipmentSlot slot, ItemStack item) {
1157-
this.sendEquipmentChange(entity, java.util.Collections.singletonMap(slot, item)); // Paper - replace Map.of to allow null values
1156+
public void sendEquipmentChange(LivingEntity entity, EquipmentSlot slot, @Nullable ItemStack item) {
1157+
this.sendEquipmentChange(entity, java.util.Collections.singletonMap(slot, item));
11581158
}
11591159

11601160
@Override
1161-
public void sendEquipmentChange(LivingEntity entity, Map<EquipmentSlot, ItemStack> items) {
1161+
public void sendEquipmentChange(LivingEntity entity, Map<EquipmentSlot, @Nullable ItemStack> items) {
11621162
Preconditions.checkArgument(entity != null, "Entity cannot be null");
11631163
Preconditions.checkArgument(items != null, "items cannot be null");
11641164
Preconditions.checkArgument(!items.isEmpty(), "items cannot be empty");
@@ -1380,7 +1380,7 @@ public boolean teleport(Location location, PlayerTeleportEvent.TeleportCause cau
13801380
}
13811381

13821382
@Override
1383-
public void lookAt(@NotNull org.bukkit.entity.Entity entity, @NotNull LookAnchor playerAnchor, @NotNull LookAnchor entityAnchor) {
1383+
public void lookAt(org.bukkit.entity.@NonNull Entity entity, @NonNull LookAnchor playerAnchor, @NonNull LookAnchor entityAnchor) {
13841384
this.getHandle().lookAt(toNmsAnchor(playerAnchor), ((CraftEntity) entity).getHandle(), toNmsAnchor(entityAnchor));
13851385
}
13861386

@@ -2006,8 +2006,7 @@ public void sendExperienceChange(float progress, int level) {
20062006
this.getHandle().connection.send(packet);
20072007
}
20082008

2009-
@Nullable
2010-
private static WeakReference<Plugin> getPluginWeakReference(@Nullable Plugin plugin) {
2009+
private static @Nullable WeakReference<Plugin> getPluginWeakReference(@Nullable Plugin plugin) {
20112010
return (plugin == null) ? null : CraftPlayer.pluginWeakReferences.computeIfAbsent(plugin, WeakReference::new);
20122011
}
20132012

@@ -2276,7 +2275,7 @@ public boolean isListed(Player other) {
22762275
}
22772276

22782277
@Override
2279-
public boolean unlistPlayer(@NotNull Player other) {
2278+
public boolean unlistPlayer(@NonNull Player other) {
22802279
Preconditions.checkNotNull(other, "hidden entity cannot be null");
22812280
if (this.getHandle().connection == null) return false;
22822281
if (!this.canSee(other)) return false;
@@ -2290,7 +2289,7 @@ public boolean unlistPlayer(@NotNull Player other) {
22902289
}
22912290

22922291
@Override
2293-
public boolean listPlayer(@NotNull Player other) {
2292+
public boolean listPlayer(@NonNull Player other) {
22942293
Preconditions.checkNotNull(other, "hidden entity cannot be null");
22952294
if (this.getHandle().connection == null) return false;
22962295
if (!this.canSee(other)) throw new IllegalStateException("Player cannot see other player");
@@ -2445,29 +2444,29 @@ public void setResourcePack(String url) {
24452444
}
24462445

24472446
@Override
2448-
public void setResourcePack(String url, byte[] hash) {
2447+
public void setResourcePack(String url, byte @Nullable [] hash) {
24492448
this.setResourcePack(url, hash, false);
24502449
}
24512450

24522451
@Override
2453-
public void setResourcePack(String url, byte[] hash, String prompt) {
2452+
public void setResourcePack(String url, byte @Nullable [] hash, String prompt) {
24542453
this.setResourcePack(url, hash, prompt, false);
24552454
}
24562455

24572456
@Override
2458-
public void setResourcePack(String url, byte[] hash, boolean force) {
2457+
public void setResourcePack(String url, byte @Nullable [] hash, boolean force) {
24592458
this.setResourcePack(url, hash, (String) null, force);
24602459
}
24612460

24622461
@Override
2463-
public void setResourcePack(String url, byte[] hash, String prompt, boolean force) {
2462+
public void setResourcePack(String url, byte @Nullable [] hash, String prompt, boolean force) {
24642463
Preconditions.checkArgument(url != null, "Resource pack URL cannot be null");
24652464

24662465
this.setResourcePack(UUID.nameUUIDFromBytes(url.getBytes(StandardCharsets.UTF_8)), url, hash, prompt, force);
24672466
}
24682467

24692468
@Override
2470-
public void setResourcePack(UUID id, String url, byte[] hash, String prompt, boolean force) {
2469+
public void setResourcePack(UUID id, String url, byte @Nullable [] hash, String prompt, boolean force) {
24712470
Preconditions.checkArgument(id != null, "Resource pack ID cannot be null");
24722471
Preconditions.checkArgument(url != null, "Resource pack URL cannot be null");
24732472

@@ -2481,7 +2480,7 @@ public void setResourcePack(UUID id, String url, byte[] hash, String prompt, boo
24812480
}
24822481

24832482
@Override
2484-
public void addResourcePack(UUID id, String url, byte[] hash, String prompt, boolean force) {
2483+
public void addResourcePack(UUID id, String url, byte @Nullable [] hash, String prompt, boolean force) {
24852484
Preconditions.checkArgument(url != null, "Resource pack URL cannot be null");
24862485

24872486
String hashStr = "";
@@ -2495,7 +2494,7 @@ public void addResourcePack(UUID id, String url, byte[] hash, String prompt, boo
24952494

24962495
// Paper start - adventure
24972496
@Override
2498-
public void setResourcePack(final UUID uuid, final String url, final byte[] hashBytes, final net.kyori.adventure.text.Component prompt, final boolean force) {
2497+
public void setResourcePack(final UUID uuid, final String url, final byte @Nullable [] hashBytes, final net.kyori.adventure.text.Component prompt, final boolean force) {
24992498
Preconditions.checkArgument(uuid != null, "Resource pack UUID cannot be null");
25002499
Preconditions.checkArgument(url != null, "Resource pack URL cannot be null");
25012500
final String hash;
@@ -2534,7 +2533,7 @@ public void sendResourcePacks(final net.kyori.adventure.resource.ResourcePackReq
25342533
}
25352534

25362535
@Override
2537-
public void removeResourcePacks(final UUID id, final UUID ... others) {
2536+
public void removeResourcePacks(final UUID id, final UUID... others) {
25382537
if (this.getHandle().connection == null) return;
25392538
this.sendBundle(net.kyori.adventure.util.MonkeyBars.nonEmptyArrayToList(pack -> new ClientboundResourcePackPopPacket(Optional.of(pack)), id, others));
25402539
}
@@ -2683,13 +2682,12 @@ public void setAllowFlight(boolean value) {
26832682

26842683
// Paper start - flying fall damage
26852684
@Override
2686-
public void setFlyingFallDamage(@NotNull net.kyori.adventure.util.TriState flyingFallDamage) {
2685+
public void setFlyingFallDamage(@NonNull TriState flyingFallDamage) {
26872686
getHandle().flyingFallDamage = flyingFallDamage;
26882687
}
26892688

2690-
@NotNull
26912689
@Override
2692-
public net.kyori.adventure.util.TriState hasFlyingFallDamage() {
2690+
public @NonNull TriState hasFlyingFallDamage() {
26932691
return getHandle().flyingFallDamage;
26942692
}
26952693
// Paper end - flying fall damage
@@ -3035,7 +3033,7 @@ public void openSign(Sign sign) {
30353033
}
30363034

30373035
@Override
3038-
public void openSign(@NotNull Sign sign, @NotNull Side side) {
3036+
public void openSign(@NonNull Sign sign, @NonNull Side side) {
30393037
CraftSign.openSign(sign, this, side);
30403038
}
30413039

@@ -3205,7 +3203,7 @@ public void clearTitle() {
32053203
private @Nullable Set<net.kyori.adventure.bossbar.BossBar> activeBossBars;
32063204

32073205
@Override
3208-
public @NotNull Iterable<? extends net.kyori.adventure.bossbar.BossBar> activeBossBars() {
3206+
public @NonNull Iterable<? extends net.kyori.adventure.bossbar.BossBar> activeBossBars() {
32093207
if (this.activeBossBars != null) {
32103208
return java.util.Collections.unmodifiableSet(this.activeBossBars);
32113209
}
@@ -3513,7 +3511,7 @@ public void sendEntityEffect(final EntityEffect effect, final org.bukkit.entity.
35133511
// Paper end - entity effect API
35143512

35153513
@Override
3516-
public @NotNull PlayerGiveResult give(@NotNull final Collection<@NotNull ItemStack> items, final boolean dropIfFull) {
3514+
public @NonNull PlayerGiveResult give(final @NonNull Collection<@NonNull ItemStack> items, final boolean dropIfFull) {
35173515
Preconditions.checkArgument(items != null, "items cannot be null");
35183516
if (items.isEmpty()) return PaperPlayerGiveResult.EMPTY; // Early opt out for empty input.
35193517

0 commit comments

Comments
 (0)