Skip to content

Commit

Permalink
[ci skip] chore: use jspecify nullability annotations instead of jetb…
Browse files Browse the repository at this point in the history
…rains
  • Loading branch information
granny committed Feb 1, 2025
1 parent 6112322 commit c5773de
Show file tree
Hide file tree
Showing 197 changed files with 1,464 additions and 1,216 deletions.
4 changes: 2 additions & 2 deletions bukkit/src/main/java/net/pl3x/map/bukkit/BukkitNetwork.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,9 @@
import org.bukkit.World;
import org.bukkit.entity.Player;
import org.bukkit.map.MapView;
import org.jetbrains.annotations.NotNull;
import org.jspecify.annotations.NullMarked;

@NullMarked
public class BukkitNetwork extends Network {
private final Pl3xMapBukkit plugin;

Expand Down Expand Up @@ -92,7 +93,6 @@ public void register() {
);
}

@NotNull
private void sendCustomPayloadPacket(Player player, CustomPacketPayload customPacketPayload, FriendlyByteBuf friendlyByteBuf) {
byte[] byteArray = new byte[friendlyByteBuf.readableBytes()];
friendlyByteBuf.readBytes(byteArray);
Expand Down
19 changes: 10 additions & 9 deletions bukkit/src/main/java/net/pl3x/map/bukkit/BukkitPlayer.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,41 +45,42 @@
import org.bukkit.craftbukkit.CraftWorld;
import org.bukkit.craftbukkit.entity.CraftPlayer;
import org.bukkit.persistence.PersistentDataType;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jspecify.annotations.NullMarked;
import org.jspecify.annotations.Nullable;

@NullMarked
public class BukkitPlayer extends Player {
private final NamespacedKey hiddenKey = new NamespacedKey(Pl3xMapBukkit.getProvidingPlugin(Pl3xMapBukkit.class), "hidden");

public BukkitPlayer(org.bukkit.entity.@NotNull Player player) {
public BukkitPlayer(org.bukkit.entity.Player player) {
super(player.getName(), player);
}

@Override
@SuppressWarnings("unchecked")
public org.bukkit.entity.@NotNull Player getPlayer() {
public org.bukkit.entity.Player getPlayer() {
return super.getPlayer();
}

@Override
public @NotNull String getName() {
public String getName() {
return getPlayer().getName();
}

@Override
public @NotNull UUID getUUID() {
public UUID getUUID() {
return getPlayer().getUniqueId();
}

@Override
public @NotNull World getWorld() {
public World getWorld() {
org.bukkit.World world = getPlayer().getWorld();
return Pl3xMap.api().getWorldRegistry().getOrDefault(world.getName(),
() -> new BukkitWorld(((CraftWorld) world).getHandle(), world.getName()));
}

@Override
public @NotNull Point getPosition() {
public Point getPosition() {
Location loc = getPlayer().getLocation();
return Point.of(loc.getBlockX(), loc.getBlockZ());
}
Expand Down Expand Up @@ -157,7 +158,7 @@ public void setPersistentlyHidden(boolean hidden) {
}

@Override
public @NotNull String toString() {
public String toString() {
return "BukkitPlayer{"
+ "player=" + getPlayer().getUniqueId()
+ "}";
Expand Down
13 changes: 7 additions & 6 deletions bukkit/src/main/java/net/pl3x/map/bukkit/BukkitWorld.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,13 @@
import net.pl3x.map.core.util.Colors;
import net.pl3x.map.core.util.Mathf;
import net.pl3x.map.core.world.World;
import org.jetbrains.annotations.NotNull;
import org.jspecify.annotations.NullMarked;

@NullMarked
public class BukkitWorld extends World {
private final ServerLevel level;

public BukkitWorld(@NotNull ServerLevel level, @NotNull String name) {
public BukkitWorld(ServerLevel level, String name) {
super(
name,
level.getSeed(),
Expand Down Expand Up @@ -88,8 +89,8 @@ public BukkitWorld(@NotNull ServerLevel level, @NotNull String name) {

@Override
@SuppressWarnings({"unchecked"})
public <T> @NotNull T getLevel() {
return (@NotNull T) this.level;
public <T> T getLevel() {
return (T) this.level;
}

@Override
Expand Down Expand Up @@ -138,15 +139,15 @@ public double getBorderMaxZ() {
}

@Override
public @NotNull Collection<@NotNull Player> getPlayers() {
public Collection<Player> getPlayers() {
return this.<ServerLevel>getLevel().players().stream()
.map(player -> Pl3xMap.api().getPlayerRegistry().get(player.getUUID()))
.filter(Objects::nonNull)
.collect(Collectors.toSet());
}

@Override
public @NotNull String toString() {
public String toString() {
return "BukkitWorld{"
+ "name=" + getName()
+ ",seed=" + getSeed()
Expand Down
7 changes: 4 additions & 3 deletions bukkit/src/main/java/net/pl3x/map/bukkit/Pl3xMapBukkit.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,9 @@
import org.bukkit.event.world.WorldLoadEvent;
import org.bukkit.event.world.WorldUnloadEvent;
import org.bukkit.plugin.java.JavaPlugin;
import org.jetbrains.annotations.NotNull;
import org.jspecify.annotations.NullMarked;

@NullMarked
public class Pl3xMapBukkit extends JavaPlugin implements Listener {
private final Pl3xMapImpl pl3xmap;
private final PlayerListener playerListener = new PlayerListener();
Expand Down Expand Up @@ -86,15 +87,15 @@ public void onDisable() {
}

@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
public void onPlayerJoin(@NotNull PlayerJoinEvent event) {
public void onPlayerJoin(PlayerJoinEvent event) {
PlayerRegistry registry = Pl3xMap.api().getPlayerRegistry();
UUID uuid = event.getPlayer().getUniqueId();
Player bukkitPlayer = registry.getOrDefault(uuid, () -> new BukkitPlayer(event.getPlayer()));
this.playerListener.onJoin(bukkitPlayer);
}

@EventHandler(priority = EventPriority.MONITOR)
public void onPlayerQuit(@NotNull PlayerQuitEvent event) {
public void onPlayerQuit(PlayerQuitEvent event) {
PlayerRegistry registry = Pl3xMap.api().getPlayerRegistry();
UUID uuid = event.getPlayer().getUniqueId();
Player bukkitPlayer = registry.unregister(uuid);
Expand Down
23 changes: 12 additions & 11 deletions bukkit/src/main/java/net/pl3x/map/bukkit/Pl3xMapImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,10 @@
import org.bukkit.Bukkit;
import org.bukkit.craftbukkit.CraftWorld;
import org.bukkit.plugin.java.JavaPlugin;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jspecify.annotations.NullMarked;
import org.jspecify.annotations.Nullable;

@NullMarked
public class Pl3xMapImpl extends Pl3xMap {
@SuppressWarnings("deprecation")
private final RandomSource randomSource = RandomSource.createThreadSafe();
Expand All @@ -65,7 +66,7 @@ public class Pl3xMapImpl extends Pl3xMap {
private BukkitAudiences adventure;
private Path jarPath;

public Pl3xMapImpl(@NotNull JavaPlugin plugin) {
public Pl3xMapImpl(JavaPlugin plugin) {
super(true);
this.plugin = plugin;
}
Expand All @@ -86,7 +87,7 @@ public void disable() {
}

@Override
public @NotNull String getPlatform() {
public String getPlatform() {
String name = Bukkit.getName();
if ("CraftBukkit".equals(name)) {
// Spigot erroneously reports itself as CraftBukkit,
Expand All @@ -102,7 +103,7 @@ public void disable() {

@Override
@SuppressWarnings("deprecation")
public @NotNull String getVersion() {
public String getVersion() {
return this.plugin.getDescription().getVersion();
}

Expand All @@ -122,20 +123,20 @@ public String getServerVersion() {
}

@Override
public @NotNull AudienceProvider adventure() {
public AudienceProvider adventure() {
if (this.adventure == null) {
throw new IllegalStateException("Tried to access Adventure without a running server!");
}
return this.adventure;
}

@Override
public @NotNull Path getMainDir() {
public Path getMainDir() {
return this.plugin.getDataFolder().toPath();
}

@Override
public @NotNull Path getJarPath() {
public Path getJarPath() {
if (this.jarPath == null) {
try {
this.jarPath = Path.of(Pl3xMap.class.getProtectionDomain().getCodeSource().getLocation().toURI());
Expand All @@ -152,7 +153,7 @@ public int getColorForPower(byte power) {
}

@Override
public net.pl3x.map.core.world.@Nullable Block getFlower(@NotNull World world, net.pl3x.map.core.world.@NotNull Biome biome, int blockX, int blockY, int blockZ) {
public net.pl3x.map.core.world.@Nullable Block getFlower(World world, net.pl3x.map.core.world.Biome biome, int blockX, int blockY, int blockZ) {
// https://github.com/Draradech/FlowerMap (CC0-1.0 license)
Biome nms = world.<ServerLevel>getLevel().registryAccess().lookupOrThrow(Registries.BIOME).getValue(ResourceLocation.parse(biome.getKey()));
if (nms == null) {
Expand All @@ -162,7 +163,7 @@ public int getColorForPower(byte power) {
if (flowers.isEmpty()) {
return null;
}
RandomPatchConfiguration config = (RandomPatchConfiguration) flowers.get(0).config();
RandomPatchConfiguration config = (RandomPatchConfiguration) flowers.getFirst().config();
SimpleBlockConfiguration flower = (SimpleBlockConfiguration) config.feature().value().feature().value().config();
Block block = flower.toPlace().getState(this.randomSource, new BlockPos(blockX, blockY, blockZ)).getBlock();
return getBlockRegistry().get(BuiltInRegistries.BLOCK.getKey(block).toString());
Expand Down Expand Up @@ -194,7 +195,7 @@ protected void loadPlayers() {
}

@Override
public @NotNull World cloneWorld(@NotNull World world) {
public World cloneWorld(World world) {
return new BukkitWorld(world.getLevel(), world.getName());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,14 @@
import org.incendo.cloud.bukkit.CloudBukkitCapabilities;
import org.incendo.cloud.execution.ExecutionCoordinator;
import org.incendo.cloud.paper.LegacyPaperCommandManager;
import org.jetbrains.annotations.NotNull;
import org.jspecify.annotations.NullMarked;

@NullMarked
public class BukkitCommandManager implements CommandHandler {
private final LegacyPaperCommandManager<@NotNull Sender> manager;
private final Command.Builder<@NotNull Sender> root;
private final LegacyPaperCommandManager<Sender> manager;
private final Command.Builder<Sender> root;

public BukkitCommandManager(@NotNull Plugin plugin) throws Exception {
public BukkitCommandManager(Plugin plugin) throws Exception {
this.manager = new LegacyPaperCommandManager<Sender>(plugin,
ExecutionCoordinator.simpleCoordinator(),
SenderMapper.create(BukkitSender::create, Sender::getSender));
Expand All @@ -67,17 +68,17 @@ public BukkitCommandManager(@NotNull Plugin plugin) throws Exception {
}

@Override
public @NotNull LegacyPaperCommandManager<@NotNull Sender> getManager() {
public LegacyPaperCommandManager<Sender> getManager() {
return this.manager;
}

@Override
public @NotNull PlatformParsers getPlatformParsers() {
public PlatformParsers getPlatformParsers() {
return new BukkitParsers();
}

@Override
public Command.@NotNull Builder<@NotNull Sender> getRoot() {
public Command.Builder<Sender> getRoot() {
return this.root;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,10 @@
import org.incendo.cloud.bukkit.parser.selector.SinglePlayerSelectorParser;
import org.incendo.cloud.context.CommandContext;
import org.incendo.cloud.parser.ParserDescriptor;
import org.jspecify.annotations.NullMarked;
import org.jspecify.annotations.Nullable;

@NullMarked
public class BukkitParsers implements PlatformParsers {
@Override
public ParserDescriptor<Sender, ?> columnPosParser() {
Expand All @@ -35,7 +38,7 @@ public Point resolvePointFromColumnPos(String name, CommandContext<Sender> conte
}

@Override
public Player resolvePlayerFromPlayerSelector(String name, CommandContext<Sender> context) {
public @Nullable Player resolvePlayerFromPlayerSelector(String name, CommandContext<Sender> context) {
Sender sender = context.sender();
SinglePlayerSelector playerSelector = context.getOrDefault(name, null);
if (playerSelector == null) {
Expand Down
23 changes: 12 additions & 11 deletions bukkit/src/main/java/net/pl3x/map/bukkit/command/BukkitSender.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,24 +30,25 @@
import net.pl3x.map.core.command.Sender;
import net.pl3x.map.core.world.World;
import org.bukkit.command.CommandSender;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jspecify.annotations.NullMarked;
import org.jspecify.annotations.Nullable;

@NullMarked
public class BukkitSender extends Sender {
public static @NotNull Sender create(@NotNull CommandSender sender) {
public static Sender create(CommandSender sender) {
if (sender instanceof org.bukkit.entity.Player) {
return new Player(sender);
}
return new BukkitSender(sender);
}

public BukkitSender(@NotNull CommandSender sender) {
public BukkitSender(CommandSender sender) {
super(sender);
}

@Override
@SuppressWarnings("unchecked")
public @NotNull CommandSender getSender() {
public CommandSender getSender() {
return super.getSender();
}

Expand All @@ -72,29 +73,29 @@ public int hashCode() {
}

@Override
public @NotNull String toString() {
public String toString() {
return "BukkitSender{"
+ "sender=" + getSender().getName()
+ "}";
}

public static class Player extends BukkitSender implements Audience, Sender.Player<org.bukkit.entity.Player> {
public Player(@NotNull CommandSender sender) {
public Player(CommandSender sender) {
super(sender);
}

@Override
public org.bukkit.entity.@NotNull Player getPlayer() {
public org.bukkit.entity.Player getPlayer() {
return (org.bukkit.entity.Player) getSender();
}

@Override
public @NotNull Audience audience() {
public Audience audience() {
return Pl3xMap.api().adventure().player(getPlayer().getUniqueId());
}

@Override
public @NotNull UUID getUUID() {
public UUID getUUID() {
return getPlayer().getUniqueId();
}

Expand All @@ -104,7 +105,7 @@ public Player(@NotNull CommandSender sender) {
}

@Override
public @NotNull String toString() {
public String toString() {
return "BukkitSender$Player{"
+ "player=" + getPlayer().getUniqueId()
+ "}";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
import net.minecraft.network.protocol.common.custom.CustomPacketPayload;
import net.minecraft.resources.ResourceLocation;
import net.pl3x.map.core.network.Constants;
import org.jspecify.annotations.NullMarked;

@NullMarked
public record ClientboundMapPayload(int protocol, int response, int mapId, byte scale, int centerX, int centerZ, String worldName) implements CustomPacketPayload {
public static final StreamCodec<FriendlyByteBuf, ClientboundMapPayload> STREAM_CODEC = CustomPacketPayload.codec(ClientboundMapPayload::write, ClientboundMapPayload::new);
public static final Type<ClientboundMapPayload> TYPE = new Type<>(ResourceLocation.fromNamespaceAndPath(Constants.MODID, "client_map_data"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
import net.minecraft.network.protocol.common.custom.CustomPacketPayload;
import net.minecraft.resources.ResourceLocation;
import net.pl3x.map.core.network.Constants;
import org.jspecify.annotations.NullMarked;

@NullMarked
public record ClientboundServerPayload(int protocol, int response, String webAddress) implements CustomPacketPayload {
public static final StreamCodec<FriendlyByteBuf, ClientboundServerPayload> STREAM_CODEC = CustomPacketPayload.codec(ClientboundServerPayload::write, ClientboundServerPayload::new);
public static final Type<ClientboundServerPayload> TYPE = new Type<>(ResourceLocation.fromNamespaceAndPath(Constants.MODID, "client_server_data"));
Expand Down
Loading

0 comments on commit c5773de

Please sign in to comment.