Add some missing annotations and an incorrect one (#12204)

This commit is contained in:
brickmonster
2025-05-18 23:31:49 +01:00
committed by GitHub
parent ce0fa4c438
commit fa360aa836
6 changed files with 62 additions and 64 deletions

View File

@@ -157,8 +157,8 @@ public class CraftWorld extends CraftRegionAccessor implements World {
private WorldBorder worldBorder;
private Environment environment;
private final CraftServer server = (CraftServer) Bukkit.getServer();
private final ChunkGenerator generator;
private final BiomeProvider biomeProvider;
private final @Nullable ChunkGenerator generator;
private final @Nullable BiomeProvider biomeProvider;
private final List<BlockPopulator> populators = new ArrayList<BlockPopulator>();
private final BlockMetadataStore blockMetadata = new BlockMetadataStore(this);
private final Object2IntOpenHashMap<SpawnCategory> spawnCategoryLimit = new Object2IntOpenHashMap<>();
@@ -286,12 +286,12 @@ public class CraftWorld extends CraftRegionAccessor implements World {
private static final Random rand = new Random();
public CraftWorld(ServerLevel world, ChunkGenerator gen, BiomeProvider biomeProvider, Environment env) {
public CraftWorld(ServerLevel world, @Nullable ChunkGenerator generator, @Nullable BiomeProvider biomeProvider, Environment environment) {
this.world = world;
this.generator = gen;
this.generator = generator;
this.biomeProvider = biomeProvider;
this.environment = env;
this.environment = environment;
// Paper start - per world spawn limits
for (SpawnCategory spawnCategory : SpawnCategory.values()) {
if (CraftSpawnCategory.isValidForLimits(spawnCategory)) {
@@ -909,7 +909,7 @@ public class CraftWorld extends CraftRegionAccessor implements World {
}
@Override
public Environment getEnvironment() {
public @NotNull Environment getEnvironment() {
return this.environment;
}
@@ -924,12 +924,12 @@ public class CraftWorld extends CraftRegionAccessor implements World {
}
@Override
public ChunkGenerator getGenerator() {
public @Nullable ChunkGenerator getGenerator() {
return this.generator;
}
@Override
public BiomeProvider getBiomeProvider() {
public @Nullable BiomeProvider getBiomeProvider() {
return this.biomeProvider;
}

View File

@@ -42,7 +42,7 @@ import java.util.concurrent.CompletableFuture;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.stream.Collectors;
import javax.annotation.Nullable;
import net.kyori.adventure.util.TriState;
import net.md_5.bungee.api.chat.BaseComponent;
import net.minecraft.advancements.AdvancementProgress;
import net.minecraft.commands.Commands;
@@ -202,7 +202,8 @@ import org.bukkit.plugin.messaging.StandardMessenger;
import org.bukkit.potion.PotionEffect;
import org.bukkit.potion.PotionEffectType;
import org.bukkit.scoreboard.Scoreboard;
import org.jetbrains.annotations.NotNull;
import org.jspecify.annotations.NonNull;
import org.jspecify.annotations.Nullable;
@DelegateDeserialization(CraftOfflinePlayer.class)
public class CraftPlayer extends CraftHumanEntity implements Player {
@@ -328,7 +329,7 @@ public class CraftPlayer extends CraftHumanEntity implements Player {
void kickPlayer(Component reason, org.bukkit.event.player.PlayerKickEvent.Cause cause); // Paper - kick event causes
}
public record CookieFuture(ResourceLocation key, CompletableFuture<byte[]> future) {
public record CookieFuture(ResourceLocation key, CompletableFuture<byte @Nullable []> future) {
}
private final Queue<CookieFuture> requestedCookies = new LinkedList<>();
@@ -357,10 +358,10 @@ public class CraftPlayer extends CraftHumanEntity implements Player {
}
@Override
public CompletableFuture<byte[]> retrieveCookie(NamespacedKey key) {
public CompletableFuture<byte @Nullable []> retrieveCookie(final NamespacedKey key) {
Preconditions.checkArgument(key != null, "Cookie key cannot be null");
CompletableFuture<byte[]> future = new CompletableFuture<>();
CompletableFuture<byte @Nullable []> future = new CompletableFuture<>();
ResourceLocation nms = CraftNamespacedKey.toMinecraft(key);
this.requestedCookies.add(new CookieFuture(nms, future));
@@ -458,7 +459,7 @@ public class CraftPlayer extends CraftHumanEntity implements Player {
@Override
@Deprecated
public void sendActionBar(BaseComponent[] message) {
if (getHandle().connection == null) return;
if (getHandle().connection == null || message == null) return;
net.minecraft.network.protocol.game.ClientboundSetActionBarTextPacket packet = new net.minecraft.network.protocol.game.ClientboundSetActionBarTextPacket(org.bukkit.craftbukkit.util.CraftChatMessage.bungeeToVanilla(message));
getHandle().connection.send(packet);
}
@@ -478,7 +479,7 @@ public class CraftPlayer extends CraftHumanEntity implements Player {
}
@Override
public void setPlayerListHeaderFooter(BaseComponent[] header, BaseComponent[] footer) {
public void setPlayerListHeaderFooter(BaseComponent @Nullable [] header, BaseComponent @Nullable [] footer) {
if (header != null) {
String headerJson = CraftChatMessage.bungeeToJson(header);
playerListHeader = net.kyori.adventure.text.serializer.gson.GsonComponentSerializer.gson().deserialize(headerJson);
@@ -497,12 +498,11 @@ public class CraftPlayer extends CraftHumanEntity implements Player {
}
@Override
public void setPlayerListHeaderFooter(BaseComponent header, BaseComponent footer) {
public void setPlayerListHeaderFooter(@Nullable BaseComponent header, @Nullable BaseComponent footer) {
this.setPlayerListHeaderFooter(header == null ? null : new BaseComponent[]{header},
footer == null ? null : new BaseComponent[]{footer});
}
@Override
public void setTitleTimes(int fadeInTicks, int stayTicks, int fadeOutTicks) {
getHandle().connection.send(new ClientboundSetTitlesAnimationPacket(fadeInTicks, stayTicks, fadeOutTicks));
@@ -736,7 +736,7 @@ public class CraftPlayer extends CraftHumanEntity implements Player {
}
@Override
public void addAdditionalChatCompletions(@NotNull Collection<String> completions) {
public void addAdditionalChatCompletions(@NonNull Collection<String> completions) {
this.getHandle().connection.send(new net.minecraft.network.protocol.game.ClientboundCustomChatCompletionsPacket(
net.minecraft.network.protocol.game.ClientboundCustomChatCompletionsPacket.Action.ADD,
new ArrayList<>(completions)
@@ -744,7 +744,7 @@ public class CraftPlayer extends CraftHumanEntity implements Player {
}
@Override
public void removeAdditionalChatCompletions(@NotNull Collection<String> completions) {
public void removeAdditionalChatCompletions(@NonNull Collection<String> completions) {
this.getHandle().connection.send(new net.minecraft.network.protocol.game.ClientboundCustomChatCompletionsPacket(
net.minecraft.network.protocol.game.ClientboundCustomChatCompletionsPacket.Action.REMOVE,
new ArrayList<>(completions)
@@ -1101,17 +1101,17 @@ public class CraftPlayer extends CraftHumanEntity implements Player {
}
// Paper end
@Override
public void sendSignChange(Location loc, String[] lines) {
public void sendSignChange(Location loc, @Nullable String @Nullable [] lines) {
this.sendSignChange(loc, lines, DyeColor.BLACK);
}
@Override
public void sendSignChange(Location loc, String[] lines, DyeColor dyeColor) {
public void sendSignChange(Location loc, @Nullable String @Nullable [] lines, DyeColor dyeColor) {
this.sendSignChange(loc, lines, dyeColor, false);
}
@Override
public void sendSignChange(Location loc, String[] lines, DyeColor dyeColor, boolean hasGlowingText) {
public void sendSignChange(Location loc, @Nullable String @Nullable [] lines, DyeColor dyeColor, boolean hasGlowingText) {
Preconditions.checkArgument(loc != null, "Location cannot be null");
Preconditions.checkArgument(dyeColor != null, "DyeColor cannot be null");
@@ -1142,7 +1142,7 @@ public class CraftPlayer extends CraftHumanEntity implements Player {
}
@Override
public void sendBlockUpdate(@NotNull Location location, @NotNull TileState tileState) throws IllegalArgumentException {
public void sendBlockUpdate(@NonNull Location location, @NonNull TileState tileState) throws IllegalArgumentException {
Preconditions.checkArgument(location != null, "Location can not be null");
Preconditions.checkArgument(tileState != null, "TileState can not be null");
@@ -1153,12 +1153,12 @@ public class CraftPlayer extends CraftHumanEntity implements Player {
}
@Override
public void sendEquipmentChange(LivingEntity entity, EquipmentSlot slot, ItemStack item) {
this.sendEquipmentChange(entity, java.util.Collections.singletonMap(slot, item)); // Paper - replace Map.of to allow null values
public void sendEquipmentChange(LivingEntity entity, EquipmentSlot slot, @Nullable ItemStack item) {
this.sendEquipmentChange(entity, java.util.Collections.singletonMap(slot, item));
}
@Override
public void sendEquipmentChange(LivingEntity entity, Map<EquipmentSlot, ItemStack> items) {
public void sendEquipmentChange(LivingEntity entity, Map<EquipmentSlot, @Nullable ItemStack> items) {
Preconditions.checkArgument(entity != null, "Entity cannot be null");
Preconditions.checkArgument(items != null, "items cannot be null");
Preconditions.checkArgument(!items.isEmpty(), "items cannot be empty");
@@ -1380,7 +1380,7 @@ public class CraftPlayer extends CraftHumanEntity implements Player {
}
@Override
public void lookAt(@NotNull org.bukkit.entity.Entity entity, @NotNull LookAnchor playerAnchor, @NotNull LookAnchor entityAnchor) {
public void lookAt(org.bukkit.entity.@NonNull Entity entity, @NonNull LookAnchor playerAnchor, @NonNull LookAnchor entityAnchor) {
this.getHandle().lookAt(toNmsAnchor(playerAnchor), ((CraftEntity) entity).getHandle(), toNmsAnchor(entityAnchor));
}
@@ -2006,8 +2006,7 @@ public class CraftPlayer extends CraftHumanEntity implements Player {
this.getHandle().connection.send(packet);
}
@Nullable
private static WeakReference<Plugin> getPluginWeakReference(@Nullable Plugin plugin) {
private static @Nullable WeakReference<Plugin> getPluginWeakReference(@Nullable Plugin plugin) {
return (plugin == null) ? null : CraftPlayer.pluginWeakReferences.computeIfAbsent(plugin, WeakReference::new);
}
@@ -2276,7 +2275,7 @@ public class CraftPlayer extends CraftHumanEntity implements Player {
}
@Override
public boolean unlistPlayer(@NotNull Player other) {
public boolean unlistPlayer(@NonNull Player other) {
Preconditions.checkNotNull(other, "hidden entity cannot be null");
if (this.getHandle().connection == null) return false;
if (!this.canSee(other)) return false;
@@ -2290,7 +2289,7 @@ public class CraftPlayer extends CraftHumanEntity implements Player {
}
@Override
public boolean listPlayer(@NotNull Player other) {
public boolean listPlayer(@NonNull Player other) {
Preconditions.checkNotNull(other, "hidden entity cannot be null");
if (this.getHandle().connection == null) return false;
if (!this.canSee(other)) throw new IllegalStateException("Player cannot see other player");
@@ -2445,29 +2444,29 @@ public class CraftPlayer extends CraftHumanEntity implements Player {
}
@Override
public void setResourcePack(String url, byte[] hash) {
public void setResourcePack(String url, byte @Nullable [] hash) {
this.setResourcePack(url, hash, false);
}
@Override
public void setResourcePack(String url, byte[] hash, String prompt) {
public void setResourcePack(String url, byte @Nullable [] hash, String prompt) {
this.setResourcePack(url, hash, prompt, false);
}
@Override
public void setResourcePack(String url, byte[] hash, boolean force) {
public void setResourcePack(String url, byte @Nullable [] hash, boolean force) {
this.setResourcePack(url, hash, (String) null, force);
}
@Override
public void setResourcePack(String url, byte[] hash, String prompt, boolean force) {
public void setResourcePack(String url, byte @Nullable [] hash, String prompt, boolean force) {
Preconditions.checkArgument(url != null, "Resource pack URL cannot be null");
this.setResourcePack(UUID.nameUUIDFromBytes(url.getBytes(StandardCharsets.UTF_8)), url, hash, prompt, force);
}
@Override
public void setResourcePack(UUID id, String url, byte[] hash, String prompt, boolean force) {
public void setResourcePack(UUID id, String url, byte @Nullable [] hash, String prompt, boolean force) {
Preconditions.checkArgument(id != null, "Resource pack ID cannot be null");
Preconditions.checkArgument(url != null, "Resource pack URL cannot be null");
@@ -2481,7 +2480,7 @@ public class CraftPlayer extends CraftHumanEntity implements Player {
}
@Override
public void addResourcePack(UUID id, String url, byte[] hash, String prompt, boolean force) {
public void addResourcePack(UUID id, String url, byte @Nullable [] hash, String prompt, boolean force) {
Preconditions.checkArgument(url != null, "Resource pack URL cannot be null");
String hashStr = "";
@@ -2495,7 +2494,7 @@ public class CraftPlayer extends CraftHumanEntity implements Player {
// Paper start - adventure
@Override
public void setResourcePack(final UUID uuid, final String url, final byte[] hashBytes, final net.kyori.adventure.text.Component prompt, final boolean force) {
public void setResourcePack(final UUID uuid, final String url, final byte @Nullable [] hashBytes, final net.kyori.adventure.text.Component prompt, final boolean force) {
Preconditions.checkArgument(uuid != null, "Resource pack UUID cannot be null");
Preconditions.checkArgument(url != null, "Resource pack URL cannot be null");
final String hash;
@@ -2534,7 +2533,7 @@ public class CraftPlayer extends CraftHumanEntity implements Player {
}
@Override
public void removeResourcePacks(final UUID id, final UUID ... others) {
public void removeResourcePacks(final UUID id, final UUID... others) {
if (this.getHandle().connection == null) return;
this.sendBundle(net.kyori.adventure.util.MonkeyBars.nonEmptyArrayToList(pack -> new ClientboundResourcePackPopPacket(Optional.of(pack)), id, others));
}
@@ -2683,13 +2682,12 @@ public class CraftPlayer extends CraftHumanEntity implements Player {
// Paper start - flying fall damage
@Override
public void setFlyingFallDamage(@NotNull net.kyori.adventure.util.TriState flyingFallDamage) {
public void setFlyingFallDamage(@NonNull TriState flyingFallDamage) {
getHandle().flyingFallDamage = flyingFallDamage;
}
@NotNull
@Override
public net.kyori.adventure.util.TriState hasFlyingFallDamage() {
public @NonNull TriState hasFlyingFallDamage() {
return getHandle().flyingFallDamage;
}
// Paper end - flying fall damage
@@ -3035,7 +3033,7 @@ public class CraftPlayer extends CraftHumanEntity implements Player {
}
@Override
public void openSign(@NotNull Sign sign, @NotNull Side side) {
public void openSign(@NonNull Sign sign, @NonNull Side side) {
CraftSign.openSign(sign, this, side);
}
@@ -3205,7 +3203,7 @@ public class CraftPlayer extends CraftHumanEntity implements Player {
private @Nullable Set<net.kyori.adventure.bossbar.BossBar> activeBossBars;
@Override
public @NotNull Iterable<? extends net.kyori.adventure.bossbar.BossBar> activeBossBars() {
public @NonNull Iterable<? extends net.kyori.adventure.bossbar.BossBar> activeBossBars() {
if (this.activeBossBars != null) {
return java.util.Collections.unmodifiableSet(this.activeBossBars);
}
@@ -3513,7 +3511,7 @@ public class CraftPlayer extends CraftHumanEntity implements Player {
// Paper end - entity effect API
@Override
public @NotNull PlayerGiveResult give(@NotNull final Collection<@NotNull ItemStack> items, final boolean dropIfFull) {
public @NonNull PlayerGiveResult give(final @NonNull Collection<@NonNull ItemStack> items, final boolean dropIfFull) {
Preconditions.checkArgument(items != null, "items cannot be null");
if (items.isEmpty()) return PaperPlayerGiveResult.EMPTY; // Early opt out for empty input.