From b94a02738cd9516529b5f25d0721d2dcd474db26 Mon Sep 17 00:00:00 2001 From: theEvilReaper Date: Thu, 7 May 2026 21:05:20 +0200 Subject: [PATCH 1/3] chore: add usage of the package info file to improve annotation usage --- .../bounce/common/ListenerHandling.java | 5 +-- .../bounce/common/adapter/AreaAdapter.java | 23 +++++++---- .../common/adapter/PushDataAdapter.java | 16 ++++---- .../bounce/common/adapter/package-info.java | 4 ++ .../bounce/common/config/GameConfig.java | 12 +++--- .../common/config/GameConfigBuilder.java | 38 +++++++++++++++---- .../common/config/GameConfigReader.java | 7 ++-- .../common/config/InternalGameConfig.java | 4 +- .../bounce/common/config/package-info.java | 4 ++ .../bounce/common/ground/Area.java | 16 +++++--- .../bounce/common/ground/GroundArea.java | 13 ++++--- .../bounce/common/ground/package-info.java | 4 ++ .../bounce/common/map/GameMap.java | 7 ++-- .../bounce/common/map/MapFilters.java | 11 +++--- .../bounce/common/map/package-info.java | 4 ++ .../bounce/common/package-info.java | 4 ++ .../bounce/common/push/PushData.java | 18 ++++----- .../bounce/common/push/PushDataBuilder.java | 26 ++++++++++--- .../bounce/common/push/PushEntry.java | 7 ++-- .../bounce/common/push/package-info.java | 5 +++ .../bounce/common/util/Messages.java | 13 +++---- .../bounce/common/util/package-info.java | 5 +++ 22 files changed, 163 insertions(+), 83 deletions(-) create mode 100644 common/src/main/java/net/theevilreaper/bounce/common/adapter/package-info.java create mode 100644 common/src/main/java/net/theevilreaper/bounce/common/config/package-info.java create mode 100644 common/src/main/java/net/theevilreaper/bounce/common/ground/package-info.java create mode 100644 common/src/main/java/net/theevilreaper/bounce/common/map/package-info.java create mode 100644 common/src/main/java/net/theevilreaper/bounce/common/package-info.java create mode 100644 common/src/main/java/net/theevilreaper/bounce/common/push/package-info.java create mode 100644 common/src/main/java/net/theevilreaper/bounce/common/util/package-info.java diff --git a/common/src/main/java/net/theevilreaper/bounce/common/ListenerHandling.java b/common/src/main/java/net/theevilreaper/bounce/common/ListenerHandling.java index 9851bf0..08e0898 100644 --- a/common/src/main/java/net/theevilreaper/bounce/common/ListenerHandling.java +++ b/common/src/main/java/net/theevilreaper/bounce/common/ListenerHandling.java @@ -8,7 +8,6 @@ import net.minestom.server.event.player.PlayerBlockPlaceEvent; import net.minestom.server.event.player.PlayerSwapItemEvent; import net.minestom.server.event.trait.CancellableEvent; -import org.jetbrains.annotations.NotNull; import java.util.function.Consumer; @@ -16,7 +15,7 @@ * The interface provides a default method to register some listeners to cancel specific events. * * @author theEvilReaper - * @version 1.0.0 + * @version 1.0.1 * @since 1.0.0 */ public interface ListenerHandling { @@ -28,7 +27,7 @@ public interface ListenerHandling { * * @param eventNode the event node to register the listeners */ - default void registerCancelListener(@NotNull EventNode eventNode) { + default void registerCancelListener(EventNode eventNode) { eventNode.addListener(PlayerBlockBreakEvent.class, CANCELLABLE_EVENT::accept); eventNode.addListener(PlayerBlockPlaceEvent.class, CANCELLABLE_EVENT::accept); eventNode.addListener(ItemDropEvent.class, CANCELLABLE_EVENT::accept); diff --git a/common/src/main/java/net/theevilreaper/bounce/common/adapter/AreaAdapter.java b/common/src/main/java/net/theevilreaper/bounce/common/adapter/AreaAdapter.java index 8ad92a9..1d126ea 100644 --- a/common/src/main/java/net/theevilreaper/bounce/common/adapter/AreaAdapter.java +++ b/common/src/main/java/net/theevilreaper/bounce/common/adapter/AreaAdapter.java @@ -12,17 +12,23 @@ import net.theevilreaper.bounce.common.ground.Area; import net.theevilreaper.bounce.common.ground.GroundArea; import net.theevilreaper.bounce.common.push.PushData; -import org.jetbrains.annotations.NotNull; import java.lang.reflect.Type; +/** + * Serializer and Deserializer implementation for {@link Area} object. + * + * @author theEvilReaper + * @version 1.0.0 + * @since 1.0.0 + */ public final class AreaAdapter implements JsonSerializer, JsonDeserializer { + + /** + * {@inheritDoc} + */ @Override - public @NotNull Area deserialize( - @NotNull JsonElement element, - @NotNull Type type, - @NotNull JsonDeserializationContext context - ) { + public Area deserialize(JsonElement element, Type type, JsonDeserializationContext context) { JsonObject jsonObject = element.getAsJsonObject(); Vec min = context.deserialize(jsonObject.get("min"), Vec.class); @@ -39,8 +45,11 @@ public final class AreaAdapter implements JsonSerializer, JsonDeserializer return new GroundArea(min, max, groundBlock, pushData); } + /** + * {@inheritDoc} + */ @Override - public @NotNull JsonElement serialize(@NotNull Area area, @NotNull Type type, @NotNull JsonSerializationContext context) { + public JsonElement serialize(Area area, Type type, JsonSerializationContext context) { JsonObject jsonObject = new JsonObject(); jsonObject.add("min", context.serialize(area.min(), Vec.class)); jsonObject.add("max", context.serialize(area.max(), Vec.class)); diff --git a/common/src/main/java/net/theevilreaper/bounce/common/adapter/PushDataAdapter.java b/common/src/main/java/net/theevilreaper/bounce/common/adapter/PushDataAdapter.java index af7b819..ac9e224 100644 --- a/common/src/main/java/net/theevilreaper/bounce/common/adapter/PushDataAdapter.java +++ b/common/src/main/java/net/theevilreaper/bounce/common/adapter/PushDataAdapter.java @@ -11,18 +11,20 @@ import net.minestom.server.instance.block.Block; import net.theevilreaper.bounce.common.push.PushData; import net.theevilreaper.bounce.common.push.PushEntry; -import org.jetbrains.annotations.NotNull; import java.lang.reflect.Type; +/** + * Serializer and Deserializer implementation for {@link PushData} object. + * + * @author theEvilReaper + * @version 1.0.0 + * @since 1.0.0 + */ public class PushDataAdapter implements JsonDeserializer, JsonSerializer { @Override - public @NotNull PushData deserialize( - @NotNull JsonElement element, - @NotNull Type type, - @NotNull JsonDeserializationContext context - ) { + public PushData deserialize(JsonElement element, Type type, JsonDeserializationContext context) { JsonArray jsonArray = element.getAsJsonArray(); PushData.Builder builder = PushData.builder(); @@ -47,7 +49,7 @@ public class PushDataAdapter implements JsonDeserializer, JsonSerializ } @Override - public @NotNull JsonElement serialize(@NotNull PushData data, @NotNull Type type, @NotNull JsonSerializationContext context) { + public JsonElement serialize(PushData data, Type type, JsonSerializationContext context) { JsonArray jsonArray = new JsonArray(); data.push().forEach(pushEntry -> { diff --git a/common/src/main/java/net/theevilreaper/bounce/common/adapter/package-info.java b/common/src/main/java/net/theevilreaper/bounce/common/adapter/package-info.java new file mode 100644 index 0000000..ab464a5 --- /dev/null +++ b/common/src/main/java/net/theevilreaper/bounce/common/adapter/package-info.java @@ -0,0 +1,4 @@ +@NotNullByDefault +package net.theevilreaper.bounce.common.adapter; + +import org.jetbrains.annotations.NotNullByDefault; \ No newline at end of file diff --git a/common/src/main/java/net/theevilreaper/bounce/common/config/GameConfig.java b/common/src/main/java/net/theevilreaper/bounce/common/config/GameConfig.java index 8acfda1..16c7e1d 100644 --- a/common/src/main/java/net/theevilreaper/bounce/common/config/GameConfig.java +++ b/common/src/main/java/net/theevilreaper/bounce/common/config/GameConfig.java @@ -25,7 +25,7 @@ public sealed interface GameConfig permits GameConfigImpl, InternalGameConfig { * @return the builder instance */ @Contract(pure = true) - static @NotNull Builder builder() { + static Builder builder() { return new GameConfigBuilder(); } @@ -73,7 +73,7 @@ sealed interface Builder permits GameConfigBuilder { * @param minPlayers the minimum number of players * @return the builder instance */ - @NotNull Builder minPlayers(int minPlayers); + Builder minPlayers(int minPlayers); /** * Sets the maximum number of players allowed in the game. @@ -81,7 +81,7 @@ sealed interface Builder permits GameConfigBuilder { * @param maxPlayers the maximum number of players * @return the builder instance */ - @NotNull Builder maxPlayers(int maxPlayers); + Builder maxPlayers(int maxPlayers); /** * Sets the lobby time in seconds. @@ -90,7 +90,7 @@ sealed interface Builder permits GameConfigBuilder { * @return the builder instance * @throws IllegalArgumentException if the lobby time is than the {@link GameConfig#FORCE_START_TIME} */ - @NotNull Builder lobbyTime(int lobbyTime); + Builder lobbyTime(int lobbyTime); /** * Sets the maximum game time in seconds. @@ -98,14 +98,14 @@ sealed interface Builder permits GameConfigBuilder { * @param gameTime the maximum game time * @return the builder instance */ - @NotNull Builder gameTime(int gameTime); + Builder gameTime(int gameTime); /** * Builds the game configuration. * * @return the created configuration */ - @NotNull GameConfig build(); + GameConfig build(); } } diff --git a/common/src/main/java/net/theevilreaper/bounce/common/config/GameConfigBuilder.java b/common/src/main/java/net/theevilreaper/bounce/common/config/GameConfigBuilder.java index 48ffb4a..2faf1df 100644 --- a/common/src/main/java/net/theevilreaper/bounce/common/config/GameConfigBuilder.java +++ b/common/src/main/java/net/theevilreaper/bounce/common/config/GameConfigBuilder.java @@ -1,7 +1,12 @@ package net.theevilreaper.bounce.common.config; -import org.jetbrains.annotations.NotNull; - +/** + * Concrete implementation of the {@link GameConfig.Builder} interface. + * + * @author theEvilReaper + * @version 1.0.0 + * @since 1.0.0 + */ public final class GameConfigBuilder implements GameConfig.Builder { private int minPlayers; @@ -9,20 +14,33 @@ public final class GameConfigBuilder implements GameConfig.Builder { private int lobbyTime; private int maxGameTime; + GameConfigBuilder() { + // Hide the public constructor + } + + /** + * {@inheritDoc} + */ @Override - public GameConfig.@NotNull Builder minPlayers(int minPlayers) { + public GameConfig.Builder minPlayers(int minPlayers) { this.minPlayers = minPlayers; return this; } + /** + * {@inheritDoc} + */ @Override - public GameConfig.@NotNull Builder maxPlayers(int maxPlayers) { + public GameConfig.Builder maxPlayers(int maxPlayers) { this.maxPlayers = maxPlayers; return this; } + /** + * {@inheritDoc} + */ @Override - public GameConfig.@NotNull Builder lobbyTime(int lobbyTime) { + public GameConfig.Builder lobbyTime(int lobbyTime) { if (lobbyTime <= GameConfig.FORCE_START_TIME) { throw new IllegalArgumentException("Lobby time must be greater than " + GameConfig.FORCE_START_TIME); } @@ -30,14 +48,20 @@ public final class GameConfigBuilder implements GameConfig.Builder { return this; } + /** + * {@inheritDoc} + */ @Override - public GameConfig.@NotNull Builder gameTime(int gameTime) { + public GameConfig.Builder gameTime(int gameTime) { this.maxGameTime = gameTime; return this; } + /** + * {@inheritDoc} + */ @Override - public @NotNull GameConfig build() { + public GameConfig build() { return new GameConfigImpl(minPlayers, maxPlayers, lobbyTime, maxGameTime); } } diff --git a/common/src/main/java/net/theevilreaper/bounce/common/config/GameConfigReader.java b/common/src/main/java/net/theevilreaper/bounce/common/config/GameConfigReader.java index 8172262..ef737f4 100644 --- a/common/src/main/java/net/theevilreaper/bounce/common/config/GameConfigReader.java +++ b/common/src/main/java/net/theevilreaper/bounce/common/config/GameConfigReader.java @@ -1,6 +1,5 @@ package net.theevilreaper.bounce.common.config; -import org.jetbrains.annotations.NotNull; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -22,7 +21,7 @@ *
  • gameTime
  • * *

    - * If a property can not be found in the file, the default value will be used. + * If a property cannot be found in the file, the default value will be used. * The default values are defined in the {@link InternalGameConfig} class. * * @author theEvilReaper @@ -41,7 +40,7 @@ public final class GameConfigReader { * * @param path the root directory of the game */ - public GameConfigReader(@NotNull Path path) { + public GameConfigReader(Path path) { this.path = path.resolve("config.properties"); } @@ -51,7 +50,7 @@ public GameConfigReader(@NotNull Path path) { * * @return the new game configuration */ - public @NotNull GameConfig getConfig() { + public GameConfig getConfig() { if (!Files.exists(path)) { CONFIG_LOGGER.warn("No config file found. Using default values"); return InternalGameConfig.defaultConfig(); diff --git a/common/src/main/java/net/theevilreaper/bounce/common/config/InternalGameConfig.java b/common/src/main/java/net/theevilreaper/bounce/common/config/InternalGameConfig.java index 29fdbf6..6e9e9d0 100644 --- a/common/src/main/java/net/theevilreaper/bounce/common/config/InternalGameConfig.java +++ b/common/src/main/java/net/theevilreaper/bounce/common/config/InternalGameConfig.java @@ -1,7 +1,5 @@ package net.theevilreaper.bounce.common.config; -import org.jetbrains.annotations.NotNull; - /** * The {@link InternalGameConfig} is the fallback configuration if no other configuration is available. * It provides default values for the game configuration. @@ -27,7 +25,7 @@ record InternalGameConfig( * * @return the default configuration */ - public static @NotNull GameConfig defaultConfig() { + public static GameConfig defaultConfig() { return Instances.INTERNAL; } diff --git a/common/src/main/java/net/theevilreaper/bounce/common/config/package-info.java b/common/src/main/java/net/theevilreaper/bounce/common/config/package-info.java new file mode 100644 index 0000000..4ab8d35 --- /dev/null +++ b/common/src/main/java/net/theevilreaper/bounce/common/config/package-info.java @@ -0,0 +1,4 @@ +@NotNullByDefault +package net.theevilreaper.bounce.common.config; + +import org.jetbrains.annotations.NotNullByDefault; \ No newline at end of file diff --git a/common/src/main/java/net/theevilreaper/bounce/common/ground/Area.java b/common/src/main/java/net/theevilreaper/bounce/common/ground/Area.java index 245abe5..bab02a4 100644 --- a/common/src/main/java/net/theevilreaper/bounce/common/ground/Area.java +++ b/common/src/main/java/net/theevilreaper/bounce/common/ground/Area.java @@ -3,8 +3,14 @@ import net.minestom.server.coordinate.Vec; import net.minestom.server.instance.block.Block; import net.theevilreaper.bounce.common.push.PushData; -import org.jetbrains.annotations.NotNull; +/** + * The {@link Area} interface represents an area in the game. + * + * @author theEvilReaper + * @version 1.0.0 + * @since 0.1.0 + */ public interface Area { void calculatePositions(); @@ -21,26 +27,26 @@ public interface Area { * * @return the point as {@link Vec} */ - @NotNull Vec min(); + Vec min(); /** * Returns the maximum point of the area. * * @return the point as {@link Vec} */ - @NotNull Vec max(); + Vec max(); /** * Returns the push data associated with this area. * * @return the push data as {@link PushData} */ - @NotNull PushData data(); + PushData data(); /** * Returns the ground block of this area. * * @return the ground block */ - @NotNull Block groundBlock(); + Block groundBlock(); } diff --git a/common/src/main/java/net/theevilreaper/bounce/common/ground/GroundArea.java b/common/src/main/java/net/theevilreaper/bounce/common/ground/GroundArea.java index 32983b0..bb3fdf9 100644 --- a/common/src/main/java/net/theevilreaper/bounce/common/ground/GroundArea.java +++ b/common/src/main/java/net/theevilreaper/bounce/common/ground/GroundArea.java @@ -20,7 +20,7 @@ public final class GroundArea implements Area { private final Block groundBlock; private final List positions; - public GroundArea(@NotNull Vec min, @NotNull Vec max, @NotNull Block groundBlock, @NotNull PushData pushData) { + public GroundArea(Vec min, Vec max, Block groundBlock, PushData pushData) { this.min = min; this.max = max; this.data = pushData; @@ -28,6 +28,9 @@ public GroundArea(@NotNull Vec min, @NotNull Vec max, @NotNull Block groundBlock this.positions = new ArrayList<>(); } + /** + * {@inheritDoc} + */ @Override public void calculatePositions() { // Avoid double calculations @@ -59,7 +62,7 @@ public boolean hasPositions() { * {@inheritDoc} */ @Override - public @NotNull PushData data() { + public PushData data() { return data; } @@ -67,7 +70,7 @@ public boolean hasPositions() { * {@inheritDoc} */ @Override - public @NotNull Vec max() { + public Vec max() { return max; } @@ -75,14 +78,14 @@ public boolean hasPositions() { * {@inheritDoc} */ @Override - public @NotNull Vec min() { + public Vec min() { return min; } /** * {@inheritDoc} */ - public @NotNull Block groundBlock() { + public Block groundBlock() { return groundBlock; } } diff --git a/common/src/main/java/net/theevilreaper/bounce/common/ground/package-info.java b/common/src/main/java/net/theevilreaper/bounce/common/ground/package-info.java new file mode 100644 index 0000000..1825775 --- /dev/null +++ b/common/src/main/java/net/theevilreaper/bounce/common/ground/package-info.java @@ -0,0 +1,4 @@ +@NotNullByDefault +package net.theevilreaper.bounce.common.ground; + +import org.jetbrains.annotations.NotNullByDefault; \ No newline at end of file diff --git a/common/src/main/java/net/theevilreaper/bounce/common/map/GameMap.java b/common/src/main/java/net/theevilreaper/bounce/common/map/GameMap.java index 5352f17..1aed166 100644 --- a/common/src/main/java/net/theevilreaper/bounce/common/map/GameMap.java +++ b/common/src/main/java/net/theevilreaper/bounce/common/map/GameMap.java @@ -3,7 +3,6 @@ import net.minestom.server.coordinate.Pos; import net.theevilreaper.aves.map.BaseMap; import net.theevilreaper.bounce.common.push.PushData; -import org.jetbrains.annotations.NotNull; /** * The {@link GameMap} contains all relevant information about a map which is used in the context of the game. @@ -26,7 +25,7 @@ public final class GameMap extends BaseMap { * @param gameSpawn the spawn position during the game * @param pushData the {@link PushData} which includes information about push values */ - public GameMap(@NotNull String name, @NotNull Pos spawn, @NotNull Pos gameSpawn, @NotNull PushData pushData, @NotNull String... builders) { + public GameMap(String name, Pos spawn, Pos gameSpawn, PushData pushData, String... builders) { super(name, spawn, builders); this.gameSpawn = gameSpawn; this.pushData = pushData; @@ -38,7 +37,7 @@ public GameMap(@NotNull String name, @NotNull Pos spawn, @NotNull Pos gameSpawn, * * @return the reference */ - public @NotNull PushData getPushData() { + public PushData getPushData() { return this.pushData; } @@ -47,7 +46,7 @@ public GameMap(@NotNull String name, @NotNull Pos spawn, @NotNull Pos gameSpawn, * * @return the game spawn position */ - public @NotNull Pos getGameSpawn() { + public Pos getGameSpawn() { return gameSpawn; } } \ No newline at end of file diff --git a/common/src/main/java/net/theevilreaper/bounce/common/map/MapFilters.java b/common/src/main/java/net/theevilreaper/bounce/common/map/MapFilters.java index daca9d3..f2cd0b3 100644 --- a/common/src/main/java/net/theevilreaper/bounce/common/map/MapFilters.java +++ b/common/src/main/java/net/theevilreaper/bounce/common/map/MapFilters.java @@ -2,7 +2,6 @@ import net.theevilreaper.aves.map.MapEntry; import net.theevilreaper.bounce.common.config.GameConfig; -import org.jetbrains.annotations.NotNull; import java.nio.file.Files; import java.nio.file.Path; @@ -10,11 +9,11 @@ import java.util.stream.Stream; /** - * The class is a utility class which provides a method to filter through a stream of paths and returns a list of maps. + * The class is a utility class that provides a method to filter through a stream of paths and returns a list of maps. * It is used to filter the available maps for the game and setup. * * @author theEvilReaper - * @version 1.0.0 + * @version 1.0.1 * @since 1.0.0 */ public interface MapFilters { @@ -25,9 +24,9 @@ public interface MapFilters { * Filters through the given stream of paths and returns a list of maps which are available for the game. * * @param mapStream a stream of paths - * @return a list which contains different maps which are available for the game + * @return a list that contains different maps which are available for the game */ - static @NotNull List filterMapsForGame(@NotNull Stream mapStream) { + static List filterMapsForGame(Stream mapStream) { return mapStream .filter(Files::isDirectory) .filter(path -> Files.exists(path.resolve(REGION_FOLDER))) @@ -42,7 +41,7 @@ public interface MapFilters { * @param mapStream a stream of paths * @return a list which contains different maps which are available for the setup */ - static @NotNull List filterMapsForSetup(@NotNull Stream mapStream) { + static List filterMapsForSetup(Stream mapStream) { return mapStream .filter(Files::isDirectory) .filter(path -> Files.exists(path.resolve(REGION_FOLDER))) diff --git a/common/src/main/java/net/theevilreaper/bounce/common/map/package-info.java b/common/src/main/java/net/theevilreaper/bounce/common/map/package-info.java new file mode 100644 index 0000000..f812786 --- /dev/null +++ b/common/src/main/java/net/theevilreaper/bounce/common/map/package-info.java @@ -0,0 +1,4 @@ +@NotNullByDefault +package net.theevilreaper.bounce.common.map; + +import org.jetbrains.annotations.NotNullByDefault; \ No newline at end of file diff --git a/common/src/main/java/net/theevilreaper/bounce/common/package-info.java b/common/src/main/java/net/theevilreaper/bounce/common/package-info.java new file mode 100644 index 0000000..9b7f63c --- /dev/null +++ b/common/src/main/java/net/theevilreaper/bounce/common/package-info.java @@ -0,0 +1,4 @@ +@NotNullByDefault +package net.theevilreaper.bounce.common; + +import org.jetbrains.annotations.NotNullByDefault; \ No newline at end of file diff --git a/common/src/main/java/net/theevilreaper/bounce/common/push/PushData.java b/common/src/main/java/net/theevilreaper/bounce/common/push/PushData.java index 56b7355..bce7433 100644 --- a/common/src/main/java/net/theevilreaper/bounce/common/push/PushData.java +++ b/common/src/main/java/net/theevilreaper/bounce/common/push/PushData.java @@ -14,10 +14,10 @@ * * @param push a map where the key is a {@link Block} and the value is a {@code double} representing the push value for that block. * @author theEvilReaper - * @version 1.0.0 + * @version 1.0.1 * @since 0.1.0 */ -public record PushData(@NotNull List push) { +public record PushData(List push) { private static Map pushMap; @@ -31,7 +31,7 @@ public record PushData(@NotNull List push) { * @param block the block to check for presence in the push data * @return true when the provided block is in the data otherwise false */ - public boolean hasBlock(@NotNull Block block) { + public boolean hasBlock(Block block) { return pushMap.containsKey(block); } @@ -41,7 +41,7 @@ public boolean hasBlock(@NotNull Block block) { * @return a new {@link PushData.Builder} instance to build a {@link PushData} object */ @Contract(pure = true) - public static @NotNull PushData.Builder builder() { + public static PushData.Builder builder() { return new PushDataBuilder(); } @@ -52,7 +52,7 @@ public boolean hasBlock(@NotNull Block block) { * @return a new {@link PushData.Builder} instance containing the push values from the provided {@link PushData} */ @Contract(value = "_ -> new", pure = true) - public static @NotNull PushData.Builder builder(@NotNull PushData pushData) { + public static PushData.Builder builder(PushData pushData) { return new PushDataBuilder(pushData); } @@ -62,7 +62,7 @@ public boolean hasBlock(@NotNull Block block) { * @param block the block for which the push value is requested * @return the push value associated with the block, or 0.0 if the block is not present in the map */ - public int getPush(@NotNull Block block) { + public int getPush(Block block) { return pushMap.getOrDefault(block, 0); } @@ -83,7 +83,7 @@ public sealed interface Builder permits PushDataBuilder { * @param entry the {@link PushEntry} containing the block and its push value * @return the builder instance for method chaining */ - @NotNull Builder add(@NotNull PushEntry entry); + Builder add(PushEntry entry); /** * Adds a block with its associated push value at a specific index in the push data. @@ -92,7 +92,7 @@ public sealed interface Builder permits PushDataBuilder { * @param entry the {@link PushEntry} containing the block and its push value * @return the builder instance for method chaining */ - @NotNull Builder add(int index, @NotNull PushEntry entry); + Builder add(int index, PushEntry entry); /** @@ -109,6 +109,6 @@ public sealed interface Builder permits PushDataBuilder { * * @return a new {@link PushData} instance containing the accumulated push values */ - @NotNull PushData build(); + PushData build(); } } diff --git a/common/src/main/java/net/theevilreaper/bounce/common/push/PushDataBuilder.java b/common/src/main/java/net/theevilreaper/bounce/common/push/PushDataBuilder.java index 453d70f..d0c4356 100644 --- a/common/src/main/java/net/theevilreaper/bounce/common/push/PushDataBuilder.java +++ b/common/src/main/java/net/theevilreaper/bounce/common/push/PushDataBuilder.java @@ -1,21 +1,35 @@ package net.theevilreaper.bounce.common.push; -import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.UnmodifiableView; import java.util.ArrayList; import java.util.Collections; import java.util.List; +/** + * The {@link PushDataBuilder} class is used to build {@link PushData} instances. + * + * @author Joltra + * @version 1.0.0 + * @since 1.0.0 + */ public final class PushDataBuilder implements PushData.Builder { private final List blocks; + /** + * Creates a new {@link PushDataBuilder} instance. + */ public PushDataBuilder() { this.blocks = new ArrayList<>(); } - public PushDataBuilder(@NotNull PushData pushData) { + /** + * Creates a new {@link PushDataBuilder} instance initialized with the provided {@link PushData}. + * + * @param pushData the existing {@link PushData} to initialize the builder with + */ + public PushDataBuilder(PushData pushData) { this.blocks = new ArrayList<>(); for (int i = 0; i < pushData.push().size(); i++) { PushEntry entry = pushData.push().get(i); @@ -31,13 +45,13 @@ public PushDataBuilder(@NotNull PushData pushData) { * {@inheritDoc} */ @Override - public PushData.@NotNull Builder add(@NotNull PushEntry entry) { + public PushData.Builder add(PushEntry entry) { this.blocks.add(entry); return this; } @Override - public PushData.@NotNull Builder add(int index, @NotNull PushEntry entry) { + public PushData.Builder add(int index, PushEntry entry) { this.blocks.add(index, entry); return this; } @@ -46,7 +60,7 @@ public PushDataBuilder(@NotNull PushData pushData) { * {@inheritDoc} */ @Override - public @NotNull @UnmodifiableView List getPushValues() { + public @UnmodifiableView List getPushValues() { return Collections.unmodifiableList(this.blocks); } @@ -54,7 +68,7 @@ public PushDataBuilder(@NotNull PushData pushData) { * {@inheritDoc} */ @Override - public @NotNull PushData build() { + public PushData build() { return new PushData(this.blocks); } } diff --git a/common/src/main/java/net/theevilreaper/bounce/common/push/PushEntry.java b/common/src/main/java/net/theevilreaper/bounce/common/push/PushEntry.java index ac9181c..796bd17 100644 --- a/common/src/main/java/net/theevilreaper/bounce/common/push/PushEntry.java +++ b/common/src/main/java/net/theevilreaper/bounce/common/push/PushEntry.java @@ -1,7 +1,6 @@ package net.theevilreaper.bounce.common.push; import net.minestom.server.instance.block.Block; -import org.jetbrains.annotations.NotNull; import java.util.Objects; @@ -27,7 +26,7 @@ public final class PushEntry { * @param value the initial value for this PushEntry * @return a new PushEntry instance representing a ground block entry */ - public static @NotNull PushEntry groundEntry(@NotNull Block block, int value) { + public static PushEntry groundEntry(Block block, int value) { return new PushEntry(block, value, true); } @@ -38,7 +37,7 @@ public final class PushEntry { * @param value the initial value for this PushEntry * @return a new PushEntry instance */ - public static @NotNull PushEntry pushEntry(@NotNull Block block, int value) { + public static PushEntry pushEntry(Block block, int value) { return new PushEntry(block, value, false); } @@ -109,7 +108,7 @@ public int getValue() { * * @return the block associated with this PushEntry */ - public @NotNull Block getBlock() { + public Block getBlock() { return block; } diff --git a/common/src/main/java/net/theevilreaper/bounce/common/push/package-info.java b/common/src/main/java/net/theevilreaper/bounce/common/push/package-info.java new file mode 100644 index 0000000..5e83a41 --- /dev/null +++ b/common/src/main/java/net/theevilreaper/bounce/common/push/package-info.java @@ -0,0 +1,5 @@ + +@NotNullByDefault +package net.theevilreaper.bounce.common.push; + +import org.jetbrains.annotations.NotNullByDefault; \ No newline at end of file diff --git a/common/src/main/java/net/theevilreaper/bounce/common/util/Messages.java b/common/src/main/java/net/theevilreaper/bounce/common/util/Messages.java index 0520c83..dec102d 100644 --- a/common/src/main/java/net/theevilreaper/bounce/common/util/Messages.java +++ b/common/src/main/java/net/theevilreaper/bounce/common/util/Messages.java @@ -5,7 +5,6 @@ import net.kyori.adventure.text.minimessage.MiniMessage; import net.kyori.adventure.text.minimessage.tag.resolver.TagResolver; import org.jetbrains.annotations.Contract; -import org.jetbrains.annotations.NotNull; public abstract class Messages { @@ -21,32 +20,32 @@ public abstract class Messages { protected Messages() { } @Contract(value = "_ -> new", pure = true) - public static @NotNull Component withPrefix(@NotNull String component) { + public static Component withPrefix(String component) { return PREFIX.append(MINI_MESSAGE.deserialize(component)); } @Contract(value = "_ -> new", pure = true) - public static @NotNull Component withPrefix(@NotNull Component component) { + public static Component withPrefix(Component component) { return PREFIX.append(component); } @Contract(value = "_ -> new", pure = true) - public static @NotNull Component withMini(@NotNull String text) { + public static Component withMini(String text) { return MINI_MESSAGE.deserialize(text); } @Contract(value = "_, _ -> new", pure = true) - public static @NotNull Component withMini(@NotNull String text, @NotNull TagResolver... resolvers) { + public static Component withMini(String text, TagResolver... resolvers) { return MINI_MESSAGE.deserialize(text, resolvers); } @Contract(value = "_ -> new", pure = true) - public static @NotNull Component withMiniPrefix(@NotNull String text) { + public static Component withMiniPrefix(String text) { return PREFIX.append(MINI_MESSAGE.deserialize(text)); } @Contract(value = "_, _ -> new", pure = true) - public static @NotNull Component withMiniPrefix(@NotNull String text, @NotNull TagResolver... resolvers) { + public static Component withMiniPrefix(String text, TagResolver... resolvers) { return PREFIX.append(MINI_MESSAGE.deserialize(text, resolvers)); } } diff --git a/common/src/main/java/net/theevilreaper/bounce/common/util/package-info.java b/common/src/main/java/net/theevilreaper/bounce/common/util/package-info.java new file mode 100644 index 0000000..47d37c6 --- /dev/null +++ b/common/src/main/java/net/theevilreaper/bounce/common/util/package-info.java @@ -0,0 +1,5 @@ + +@NotNullByDefault +package net.theevilreaper.bounce.common.util; + +import org.jetbrains.annotations.NotNullByDefault; \ No newline at end of file From fcb0058c591ccb17d01747ad68436aa3cbc73b28 Mon Sep 17 00:00:00 2001 From: theEvilReaper Date: Thu, 7 May 2026 21:10:54 +0200 Subject: [PATCH 2/3] test: add new test cases --- .../common/config/GameConfigReaderTest.java | 72 ++++++++++++++ .../bounce/common/map/MapFiltersTest.java | 95 +++++++++++++++++++ 2 files changed, 167 insertions(+) create mode 100644 common/src/test/java/net/theevilreaper/bounce/common/config/GameConfigReaderTest.java create mode 100644 common/src/test/java/net/theevilreaper/bounce/common/map/MapFiltersTest.java diff --git a/common/src/test/java/net/theevilreaper/bounce/common/config/GameConfigReaderTest.java b/common/src/test/java/net/theevilreaper/bounce/common/config/GameConfigReaderTest.java new file mode 100644 index 0000000..12a8ce1 --- /dev/null +++ b/common/src/test/java/net/theevilreaper/bounce/common/config/GameConfigReaderTest.java @@ -0,0 +1,72 @@ +package net.theevilreaper.bounce.common.config; + +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.condition.DisabledOnOs; +import org.junit.jupiter.api.condition.OS; +import org.junit.jupiter.api.io.TempDir; + +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Path; + +import static org.junit.jupiter.api.Assertions.*; + +class GameConfigReaderTest { + + @TempDir + Path tempDir; + + @Test + void testMissingFileReturnsDefaultConfig() { + GameConfig config = new GameConfigReader(tempDir.resolve("nonexistent")).getConfig(); + assertEquals(InternalGameConfig.defaultConfig(), config); + } + + @Test + void testEmptyFileReturnsDefaultConfig() throws IOException { + Files.createFile(tempDir.resolve("config.properties")); + GameConfig config = new GameConfigReader(tempDir).getConfig(); + assertEquals(InternalGameConfig.defaultConfig(), config); + } + + @Test + void testValidConfigFile() throws IOException { + Files.writeString(tempDir.resolve("config.properties"), """ + minPlayers=2 + maxPlayers=8 + lobbyTime=30 + gameTime=300 + """); + GameConfig config = new GameConfigReader(tempDir).getConfig(); + assertAll( + () -> assertEquals(2, config.minPlayers()), + () -> assertEquals(8, config.maxPlayers()), + () -> assertEquals(30, config.lobbyTime()), + () -> assertEquals(300, config.gameTime()) + ); + } + + @Test + void testPartialConfigFallsBackToDefaults() throws IOException { + Files.writeString(tempDir.resolve("config.properties"), "minPlayers=2\n"); + GameConfig config = new GameConfigReader(tempDir).getConfig(); + GameConfig defaults = InternalGameConfig.defaultConfig(); + assertAll( + () -> assertEquals(2, config.minPlayers()), + () -> assertEquals(defaults.maxPlayers(), config.maxPlayers()), + () -> assertEquals(defaults.lobbyTime(), config.lobbyTime()), + () -> assertEquals(defaults.gameTime(), config.gameTime()) + ); + } + + @Test + @DisabledOnOs(OS.WINDOWS) // File permissions funktionieren auf Windows nicht zuverlässig + void testUnreadableFileReturnsDefaultConfig() throws IOException { + Path config = tempDir.resolve("config.properties"); + Files.writeString(config, "minPlayers=2\n"); + config.toFile().setReadable(false); + + GameConfig result = new GameConfigReader(tempDir).getConfig(); + assertEquals(InternalGameConfig.defaultConfig(), result); + } +} diff --git a/common/src/test/java/net/theevilreaper/bounce/common/map/MapFiltersTest.java b/common/src/test/java/net/theevilreaper/bounce/common/map/MapFiltersTest.java new file mode 100644 index 0000000..6baddd7 --- /dev/null +++ b/common/src/test/java/net/theevilreaper/bounce/common/map/MapFiltersTest.java @@ -0,0 +1,95 @@ +package net.theevilreaper.bounce.common.map; + +import net.theevilreaper.aves.map.MapEntry; +import net.theevilreaper.bounce.common.config.GameConfig; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.io.TempDir; + +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Path; +import java.util.List; +import java.util.stream.Stream; + +import static org.junit.jupiter.api.Assertions.*; + +class MapFiltersTest { + + @TempDir + Path tempDir; + + @Test + void testFilterMapsForGameReturnsValidMap() throws IOException { + Path map = tempDir.resolve("map1"); + Files.createDirectory(map); + Files.createDirectory(map.resolve(MapFilters.REGION_FOLDER)); + Files.createFile(map.resolve(GameConfig.MAP_FILE)); + + List result = MapFilters.filterMapsForGame(Stream.of(map)); + assertEquals(1, result.size()); + } + + @Test + void testFilterMapsForGameExcludesMissingRegionFolder() throws IOException { + Path map = tempDir.resolve("map_no_region"); + Files.createDirectory(map); + Files.createFile(map.resolve(GameConfig.MAP_FILE)); + + List result = MapFilters.filterMapsForGame(Stream.of(map)); + assertTrue(result.isEmpty()); + } + + @Test + void testFilterMapsForGameExcludesMissingMapFile() throws IOException { + Path map = tempDir.resolve("map_no_config"); + Files.createDirectory(map); + Files.createDirectory(map.resolve(MapFilters.REGION_FOLDER)); + + List result = MapFilters.filterMapsForGame(Stream.of(map)); + assertTrue(result.isEmpty()); + } + + @Test + void testFilterMapsForGameExcludesFiles() throws IOException { + Path file = tempDir.resolve("not_a_directory.txt"); + Files.createFile(file); + + List result = MapFilters.filterMapsForGame(Stream.of(file)); + assertTrue(result.isEmpty()); + } + + @Test + void testFilterMapsForSetupReturnsValidMap() throws IOException { + Path map = tempDir.resolve("map1"); + Files.createDirectory(map); + Files.createDirectory(map.resolve(MapFilters.REGION_FOLDER)); + + List result = MapFilters.filterMapsForSetup(Stream.of(map)); + assertEquals(1, result.size()); + } + + @Test + void testFilterMapsForSetupExcludesMissingRegionFolder() throws IOException { + Path map = tempDir.resolve("map_no_region"); + Files.createDirectory(map); + + List result = MapFilters.filterMapsForSetup(Stream.of(map)); + assertTrue(result.isEmpty()); + } + + @Test + void testFilterMapsForSetupDoesNotRequireMapFile() throws IOException { + Path map = tempDir.resolve("map_no_config"); + Files.createDirectory(map); + Files.createDirectory(map.resolve(MapFilters.REGION_FOLDER)); + + List result = MapFilters.filterMapsForSetup(Stream.of(map)); + assertEquals(1, result.size()); + } + + @Test + void testEmptyStreamReturnsEmptyList() { + assertTrue(MapFilters.filterMapsForGame(Stream.empty()).isEmpty()); + assertTrue(MapFilters.filterMapsForSetup(Stream.empty()).isEmpty()); + } +} \ No newline at end of file From 200f0b99ec15e5a7e31e6d630fd0ab9007fbed61 Mon Sep 17 00:00:00 2001 From: theEvilReaper Date: Thu, 7 May 2026 21:14:11 +0200 Subject: [PATCH 3/3] chore(common): remove comment --- .../bounce/common/config/GameConfigReaderTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/common/src/test/java/net/theevilreaper/bounce/common/config/GameConfigReaderTest.java b/common/src/test/java/net/theevilreaper/bounce/common/config/GameConfigReaderTest.java index 12a8ce1..c198891 100644 --- a/common/src/test/java/net/theevilreaper/bounce/common/config/GameConfigReaderTest.java +++ b/common/src/test/java/net/theevilreaper/bounce/common/config/GameConfigReaderTest.java @@ -60,7 +60,7 @@ void testPartialConfigFallsBackToDefaults() throws IOException { } @Test - @DisabledOnOs(OS.WINDOWS) // File permissions funktionieren auf Windows nicht zuverlässig + @DisabledOnOs(OS.WINDOWS) void testUnreadableFileReturnsDefaultConfig() throws IOException { Path config = tempDir.resolve("config.properties"); Files.writeString(config, "minPlayers=2\n");