diff --git a/common/src/main/java/net/onelitefeather/cygnus/common/ListenerHandling.java b/common/src/main/java/net/onelitefeather/cygnus/common/ListenerHandling.java index f904619..88bdcb6 100644 --- a/common/src/main/java/net/onelitefeather/cygnus/common/ListenerHandling.java +++ b/common/src/main/java/net/onelitefeather/cygnus/common/ListenerHandling.java @@ -7,9 +7,10 @@ import net.minestom.server.event.player.PlayerBlockInteractEvent; import net.minestom.server.event.player.PlayerBlockPlaceEvent; import net.minestom.server.event.player.PlayerSwapItemEvent; -import org.jetbrains.annotations.NotNull; +import net.minestom.server.event.trait.CancellableEvent; + +import java.util.function.Consumer; -import static net.theevilreaper.aves.inventory.util.InventoryConstants.CANCELLABLE_EVENT; /** * The interface provides a default method to register some listeners to cancel specific events. @@ -20,12 +21,14 @@ */ public interface ListenerHandling { + Consumer CANCELLABLE_EVENT = event -> event.setCancelled(true); + /** * Registers some {@link Event} listener to cancel specific default events. * * @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/onelitefeather/cygnus/common/Messages.java b/common/src/main/java/net/onelitefeather/cygnus/common/Messages.java index a9639e2..95da6e4 100644 --- a/common/src/main/java/net/onelitefeather/cygnus/common/Messages.java +++ b/common/src/main/java/net/onelitefeather/cygnus/common/Messages.java @@ -8,7 +8,6 @@ import net.minestom.server.entity.Player; import net.onelitefeather.cygnus.common.config.GameConfig; import org.jetbrains.annotations.Contract; -import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; /** @@ -78,49 +77,49 @@ private 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 String component, @NotNull TagResolver... resolvers) { + public static Component withPrefix(String component, TagResolver... resolvers) { return PREFIX.append(Component.space()).append(MINI_MESSAGE.deserialize(component, resolvers)); } @Contract(value = "_ -> new", pure = true) - public static @NotNull Component withPrefix(@NotNull Component component) { + public static Component withPrefix(Component component) { return PREFIX.append(Component.space()).append(component); } @Contract(value = "_ -> new", pure = true) - public static @NotNull Component withMini(@NotNull String text) { + public static Component withMini(String text) { return MiniMessage.miniMessage().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(Component.space()).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(Component.space()).append(MINI_MESSAGE.deserialize(text, resolvers)); } @Contract(value = "_ -> new", pure = true) - public static @NotNull Component getPageFoundComponent(@NotNull Player player) { + public static Component getPageFoundComponent(Player player) { var playerName = Tag.preProcessParsed(player.getUsername()); var playerTag = TagResolver.builder().tag("player", (argumentQueue, context) -> playerName).build(); return PREFIX.append(Component.space()).append(withMini("<" + SECONDARY_COLOR + ">", playerTag)).append(Component.space()).append(PAGE_FOUND_PART); } @Contract(value = "_ -> new", pure = true) - public static @NotNull Component getDeathComponent(@NotNull Player player) { + public static Component getDeathComponent(Player player) { var playerName = Tag.preProcessParsed(player.getUsername()); var playerTag = TagResolver.builder().tag("player", (argumentQueue, context) -> playerName).build(); return PREFIX.append(Component.space()).append(withMini(" was TAKEN!", playerTag)); @@ -128,7 +127,7 @@ private Messages() { @Contract(value = "_, _ -> new", pure = true) - public static @NotNull Component getViewComponent(@NotNull String time, @NotNull Component pageStatus) { + public static Component getViewComponent(String time, Component pageStatus) { return Component.text("Time:", NamedTextColor.GRAY) .append(Component.space()) .append(Component.text(time, NamedTextColor.RED)) @@ -139,7 +138,7 @@ private Messages() { } @Contract(value = "_ -> new", pure = true) - public static @NotNull Component getSlenderWinMessage(@Nullable Player player) { + public static Component getSlenderWinMessage(@Nullable Player player) { if (player == null || player.getDisplayName() == null) { return Component.newline() .append(SLENDER_WIN_MESSAGE) @@ -155,19 +154,19 @@ private Messages() { } @Contract(value = "_ -> new", pure = true) - public static @NotNull Component getJoinMessage(@NotNull Player player) { + public static Component getJoinMessage(Player player) { return PREFIX.append(Component.space()).append(withMini("" + player.getUsername() + "")) .append(Component.space()).append(JOIN_PART); } @Contract(value = "_ -> new", pure = true) - public static @NotNull Component getLeaveMessage(@NotNull Player player) { + public static Component getLeaveMessage(Player player) { return PREFIX.append(Component.space()).append(withMini("" + player.getUsername() + "")) .append(Component.space()).append(LEAVE_PART); } @Contract(value = "_ -> new", pure = true) - public static @NotNull Component getSurvivorJoinMessage(@NotNull String pageCount) { + public static Component getSurvivorJoinMessage(String pageCount) { return SURVIVOR_JOIN_PART_UPPER.append(withMini("(" + pageCount + " TO WIN)")) .append(Component.newline()) .append(SURVIVOR_JOIN_LOWER_PART); diff --git a/common/src/main/java/net/onelitefeather/cygnus/common/config/GameConfig.java b/common/src/main/java/net/onelitefeather/cygnus/common/config/GameConfig.java index 65522cb..1d07b5d 100644 --- a/common/src/main/java/net/onelitefeather/cygnus/common/config/GameConfig.java +++ b/common/src/main/java/net/onelitefeather/cygnus/common/config/GameConfig.java @@ -1,7 +1,6 @@ package net.onelitefeather.cygnus.common.config; import org.jetbrains.annotations.Contract; -import org.jetbrains.annotations.NotNull; /** * The {@link GameConfig} interface represents the structure for a configuration which is used by the game. @@ -39,7 +38,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(); } @@ -101,7 +100,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. @@ -109,7 +108,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. @@ -118,7 +117,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. @@ -126,7 +125,7 @@ sealed interface Builder permits GameConfigBuilder { * @param gameTime the maximum game time * @return the builder instance */ - @NotNull Builder gameTime(int gameTime); + Builder gameTime(int gameTime); /** * Sets the size of the slender team. @@ -135,7 +134,7 @@ sealed interface Builder permits GameConfigBuilder { * @return the builder instance * @throws IllegalArgumentException if the slender team size is smaller than 1 */ - @NotNull Builder slenderTeamSize(int slenderTeamSize); + Builder slenderTeamSize(int slenderTeamSize); /** * Sets the size of the survivor team. @@ -144,14 +143,14 @@ sealed interface Builder permits GameConfigBuilder { * @return the builder instance * @throws IllegalArgumentException if the survivor team size is smaller than 1 */ - @NotNull Builder survivorTeamSize(int survivorTeamSize); + Builder survivorTeamSize(int survivorTeamSize); /** * Builds the game configuration. * * @return the created configuration */ - @NotNull GameConfig build(); + GameConfig build(); } } diff --git a/common/src/main/java/net/onelitefeather/cygnus/common/config/GameConfigBuilder.java b/common/src/main/java/net/onelitefeather/cygnus/common/config/GameConfigBuilder.java index e3d1cce..6438c18 100644 --- a/common/src/main/java/net/onelitefeather/cygnus/common/config/GameConfigBuilder.java +++ b/common/src/main/java/net/onelitefeather/cygnus/common/config/GameConfigBuilder.java @@ -1,7 +1,5 @@ package net.onelitefeather.cygnus.common.config; -import org.jetbrains.annotations.NotNull; - public final class GameConfigBuilder implements GameConfig.Builder { private int minPlayers; @@ -12,19 +10,19 @@ public final class GameConfigBuilder implements GameConfig.Builder { private int survivorTeamSize; @Override - public GameConfig.@NotNull Builder minPlayers(int minPlayers) { + public GameConfig.Builder minPlayers(int minPlayers) { this.minPlayers = minPlayers; return this; } @Override - public GameConfig.@NotNull Builder maxPlayers(int maxPlayers) { + public GameConfig.Builder maxPlayers(int maxPlayers) { this.maxPlayers = maxPlayers; return this; } @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); } @@ -33,13 +31,13 @@ public final class GameConfigBuilder implements GameConfig.Builder { } @Override - public GameConfig.@NotNull Builder gameTime(int gameTime) { + public GameConfig.Builder gameTime(int gameTime) { this.maxGameTime = gameTime; return this; } @Override - public GameConfig.@NotNull Builder slenderTeamSize(int slenderTeamSize) { + public GameConfig.Builder slenderTeamSize(int slenderTeamSize) { int minSlenderSize = InternalGameConfig.defaultConfig().slenderTeamSize(); if (slenderTeamSize < minSlenderSize) { throw new IllegalArgumentException("Slender team size must be at least " + minSlenderSize); @@ -49,7 +47,7 @@ public final class GameConfigBuilder implements GameConfig.Builder { } @Override - public GameConfig.@NotNull Builder survivorTeamSize(int survivorTeamSize) { + public GameConfig.Builder survivorTeamSize(int survivorTeamSize) { int minSurvivorSize = InternalGameConfig.defaultConfig().slenderTeamSize() + 1; if (survivorTeamSize < minSurvivorSize) { throw new IllegalArgumentException("Survivor team size must be at least " + minSurvivorSize); @@ -59,7 +57,7 @@ public final class GameConfigBuilder implements GameConfig.Builder { } @Override - public @NotNull GameConfig build() { + public GameConfig build() { return new GameConfigImpl(minPlayers, maxPlayers, lobbyTime, maxGameTime, slenderTeamSize, survivorTeamSize); } } diff --git a/common/src/main/java/net/onelitefeather/cygnus/common/config/GameConfigReader.java b/common/src/main/java/net/onelitefeather/cygnus/common/config/GameConfigReader.java index bccbd82..33b5608 100644 --- a/common/src/main/java/net/onelitefeather/cygnus/common/config/GameConfigReader.java +++ b/common/src/main/java/net/onelitefeather/cygnus/common/config/GameConfigReader.java @@ -1,6 +1,5 @@ package net.onelitefeather.cygnus.common.config; -import org.jetbrains.annotations.NotNull; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -43,7 +42,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"); } @@ -53,7 +52,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/onelitefeather/cygnus/common/config/InternalGameConfig.java b/common/src/main/java/net/onelitefeather/cygnus/common/config/InternalGameConfig.java index 7561f74..568945e 100644 --- a/common/src/main/java/net/onelitefeather/cygnus/common/config/InternalGameConfig.java +++ b/common/src/main/java/net/onelitefeather/cygnus/common/config/InternalGameConfig.java @@ -1,7 +1,5 @@ package net.onelitefeather.cygnus.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. @@ -31,7 +29,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/onelitefeather/cygnus/common/config/package-info.java b/common/src/main/java/net/onelitefeather/cygnus/common/config/package-info.java new file mode 100644 index 0000000..dfb0375 --- /dev/null +++ b/common/src/main/java/net/onelitefeather/cygnus/common/config/package-info.java @@ -0,0 +1,4 @@ +@NotNullByDefault +package net.onelitefeather.cygnus.common.config; + +import org.jetbrains.annotations.NotNullByDefault; \ No newline at end of file diff --git a/common/src/main/java/net/onelitefeather/cygnus/common/event/package-info.java b/common/src/main/java/net/onelitefeather/cygnus/common/event/package-info.java new file mode 100644 index 0000000..e9fd712 --- /dev/null +++ b/common/src/main/java/net/onelitefeather/cygnus/common/event/package-info.java @@ -0,0 +1,4 @@ +@NotNullByDefault +package net.onelitefeather.cygnus.common.event; + +import org.jetbrains.annotations.NotNullByDefault; \ No newline at end of file diff --git a/common/src/main/java/net/onelitefeather/cygnus/common/map/GameMap.java b/common/src/main/java/net/onelitefeather/cygnus/common/map/GameMap.java index 10535d2..3475b27 100644 --- a/common/src/main/java/net/onelitefeather/cygnus/common/map/GameMap.java +++ b/common/src/main/java/net/onelitefeather/cygnus/common/map/GameMap.java @@ -5,7 +5,6 @@ import net.minestom.server.coordinate.Vec; import net.minestom.server.utils.Direction; import net.onelitefeather.cygnus.common.page.PageResource; -import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.UnknownNullability; import java.util.HashSet; @@ -45,7 +44,7 @@ public GameMap() { * @param survivorSpawns the spawn positions for the survivors * @param builders the builders for the map */ - public GameMap(@NotNull String name, Pos spawn, Pos slenderSpawn, @NotNull Set pageFaces, @NotNull Set survivorSpawns, String... builders) { + public GameMap(String name, Pos spawn, Pos slenderSpawn, Set pageFaces, Set survivorSpawns, String... builders) { super(name, spawn, builders); this.slenderSpawn = slenderSpawn; this.pageFaces = pageFaces; @@ -58,7 +57,7 @@ public GameMap(@NotNull String name, Pos spawn, Pos slenderSpawn, @NotNull Set

getPageFaces() { + public Set getPageFaces() { return pageFaces; } @@ -131,7 +130,7 @@ public boolean hasEnoughSurvivorSpawns() { * * @return the underlying set */ - public @NotNull Set getSurvivorSpawns() { + public Set getSurvivorSpawns() { return survivorSpawns; } } diff --git a/common/src/main/java/net/onelitefeather/cygnus/common/map/MapEntry.java b/common/src/main/java/net/onelitefeather/cygnus/common/map/MapEntry.java index 9ddd251..833ba3e 100644 --- a/common/src/main/java/net/onelitefeather/cygnus/common/map/MapEntry.java +++ b/common/src/main/java/net/onelitefeather/cygnus/common/map/MapEntry.java @@ -1,19 +1,18 @@ package net.onelitefeather.cygnus.common.map; import net.onelitefeather.cygnus.common.config.GameConfig; -import org.jetbrains.annotations.NotNull; import java.nio.file.Files; import java.nio.file.Path; // Maps as path -public record MapEntry(@NotNull Path path) { +public record MapEntry(Path path) { public boolean hasMapFile() { return Files.exists(path.resolve(GameConfig.MAP_FILE_NAME)); } - public @NotNull Path getMapFile() { + public Path getMapFile() { return path.resolve(GameConfig.MAP_FILE_NAME); } } diff --git a/common/src/main/java/net/onelitefeather/cygnus/common/map/MapPool.java b/common/src/main/java/net/onelitefeather/cygnus/common/map/MapPool.java index 0a4df0f..fcfec8a 100644 --- a/common/src/main/java/net/onelitefeather/cygnus/common/map/MapPool.java +++ b/common/src/main/java/net/onelitefeather/cygnus/common/map/MapPool.java @@ -2,7 +2,6 @@ import net.minestom.server.MinecraftServer; import net.minestom.server.utils.validate.Check; -import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.UnmodifiableView; import org.slf4j.Logger; @@ -41,7 +40,7 @@ public class MapPool { * * @param path the path where the maps are stored */ - public MapPool(@NotNull Path path) { + public MapPool(Path path) { referenceList = loadMapsEntries(path); this.peekMap(); } @@ -52,7 +51,7 @@ public MapPool(@NotNull Path path) { * @param path the path where the maps are stored * @return a list with all available maps */ - private @NotNull List loadMapsEntries(@NotNull Path path) { + private List loadMapsEntries(Path path) { List mapEntries = new ArrayList<>(); try (Stream stream = Files.list(path)) { mapEntries = stream.filter(Files::isDirectory).map(MapEntry::new).filter(MapEntry::hasMapFile).collect(Collectors.toList()); @@ -106,7 +105,7 @@ public void clear() { * * @return the lobby map entry */ - public @NotNull MapEntry getLobbyEntry() { + public MapEntry getLobbyEntry() { return this.lobbyMap; } @@ -115,7 +114,7 @@ public void clear() { * * @return an unmodifiable list with all available maps */ - public @NotNull @UnmodifiableView List getAvailableMaps() { + public @UnmodifiableView List getAvailableMaps() { return Collections.unmodifiableList(this.referenceList); } } diff --git a/common/src/main/java/net/onelitefeather/cygnus/common/map/MapProvider.java b/common/src/main/java/net/onelitefeather/cygnus/common/map/MapProvider.java index e1785a2..e80ad3f 100644 --- a/common/src/main/java/net/onelitefeather/cygnus/common/map/MapProvider.java +++ b/common/src/main/java/net/onelitefeather/cygnus/common/map/MapProvider.java @@ -17,7 +17,6 @@ import net.onelitefeather.cygnus.common.page.PageResource; import net.onelitefeather.cygnus.common.page.adapter.PageResourceAdapter; import net.onelitefeather.cygnus.common.util.Helper; -import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.UnmodifiableView; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -47,7 +46,7 @@ public final class MapProvider { private final PageProvider pageProvider; - public MapProvider(@NotNull Path path, @NotNull InstanceContainer instance, @NotNull PageProvider pageProvider) { + public MapProvider(Path path, InstanceContainer instance, PageProvider pageProvider) { this.mapPool = new MapPool(path.resolve(MAP_PATH)); this.instance = instance; this.pageProvider = pageProvider; @@ -87,11 +86,11 @@ public void loadGameMap() { this.pageProvider.collectStartPages(gameInstance); } - public void saveMap(@NotNull Path path, @NotNull BaseMap baseMap) { + public void saveMap(Path path, BaseMap baseMap) { this.fileHandler.save(path, baseMap instanceof GameMap gameMap ? gameMap : baseMap); } - private void loadChunk(@NotNull InstanceContainer instance, @NotNull T pos) { + private void loadChunk(InstanceContainer instance, T pos) { if (!ChunkUtils.isLoaded(instance, pos)) { instance.loadChunk(pos).whenComplete((chunk, throwable) -> { if (throwable != null) { @@ -110,14 +109,14 @@ public void switchToGameMap() { this.instance = null; } - public void prepareInstanceData(@NotNull InstanceContainer instance) { + public void prepareInstanceData(InstanceContainer instance) { instance.setTimeRate(0); instance.setTimeSynchronizationTicks(0); instance.setTime(Helper.MIDNIGHT_TIME); instance.enableAutoChunkLoad(true); } - public void setInstance(@NotNull InstanceContainer instance) { + public void setInstance(InstanceContainer instance) { this.instance = instance; } @@ -126,11 +125,11 @@ public void setMidnight() { this.instance.setTime(Helper.MIDNIGHT_TIME); } - public @NotNull Instance getInstance() { + public Instance getInstance() { return this.instance != null ? instance : gameInstance; } - public @NotNull @UnmodifiableView List getAvailableMaps() { + public @UnmodifiableView List getAvailableMaps() { return Collections.unmodifiableList(this.mapPool.getAvailableMaps()); } @@ -138,7 +137,7 @@ public InstanceContainer getGameInstance() { return gameInstance; } - public @NotNull BaseMap getActiveMap() { + public BaseMap getActiveMap() { return this.activeMap; } diff --git a/common/src/main/java/net/onelitefeather/cygnus/common/map/package-info.java b/common/src/main/java/net/onelitefeather/cygnus/common/map/package-info.java new file mode 100644 index 0000000..9c87bca --- /dev/null +++ b/common/src/main/java/net/onelitefeather/cygnus/common/map/package-info.java @@ -0,0 +1,4 @@ +@NotNullByDefault +package net.onelitefeather.cygnus.common.map; + +import org.jetbrains.annotations.NotNullByDefault; \ No newline at end of file diff --git a/common/src/main/java/net/onelitefeather/cygnus/common/package-info.java b/common/src/main/java/net/onelitefeather/cygnus/common/package-info.java new file mode 100644 index 0000000..79e7c9f --- /dev/null +++ b/common/src/main/java/net/onelitefeather/cygnus/common/package-info.java @@ -0,0 +1,5 @@ + +@NotNullByDefault +package net.onelitefeather.cygnus.common; + +import org.jetbrains.annotations.NotNullByDefault; \ No newline at end of file diff --git a/common/src/main/java/net/onelitefeather/cygnus/common/page/PageEntity.java b/common/src/main/java/net/onelitefeather/cygnus/common/page/PageEntity.java index 44c4b2a..f7ff101 100644 --- a/common/src/main/java/net/onelitefeather/cygnus/common/page/PageEntity.java +++ b/common/src/main/java/net/onelitefeather/cygnus/common/page/PageEntity.java @@ -17,7 +17,6 @@ import net.onelitefeather.cygnus.common.config.GameConfig; import net.onelitefeather.cygnus.common.page.event.PageEvent; import net.onelitefeather.cygnus.common.util.Helper; -import org.jetbrains.annotations.NotNull; import java.util.UUID; import java.util.concurrent.CompletableFuture; @@ -50,7 +49,7 @@ public final class PageEntity extends Entity { * @param spawnPos the position where the entity should spawn * @param pageCount the current page count */ - PageEntity(@NotNull Instance instance, @NotNull Pos spawnPos, int pageCount) { + PageEntity(Instance instance, Pos spawnPos, int pageCount) { super(EntityType.ITEM_DISPLAY); this.setInstance(instance, spawnPos); this.hitBox = new Entity(EntityType.INTERACTION); @@ -130,7 +129,7 @@ public void remove() { } @Override - public @NotNull CompletableFuture teleport(@NotNull Pos position) { + public CompletableFuture teleport(Pos position) { this.hitBox.teleport(position.sub(HALF_BLOCK)); return super.teleport(position); } @@ -182,7 +181,7 @@ public int hashCode() { * * @return the page item */ - public @NotNull ItemStack getPageItem() { + public ItemStack getPageItem() { return pageItem; } @@ -191,7 +190,7 @@ public int hashCode() { * * @return the hitbox id */ - public @NotNull UUID getHitBoxUUID() { + public UUID getHitBoxUUID() { return this.hitBox.getUuid(); } } diff --git a/common/src/main/java/net/onelitefeather/cygnus/common/page/PageFactory.java b/common/src/main/java/net/onelitefeather/cygnus/common/page/PageFactory.java index a85fda8..ce08b6e 100644 --- a/common/src/main/java/net/onelitefeather/cygnus/common/page/PageFactory.java +++ b/common/src/main/java/net/onelitefeather/cygnus/common/page/PageFactory.java @@ -5,7 +5,6 @@ import net.minestom.server.utils.Direction; import net.minestom.server.utils.validate.Check; import org.jetbrains.annotations.Contract; -import org.jetbrains.annotations.NotNull; /** * The factory should be used to create references from a {@link PageEntity}. @@ -28,10 +27,10 @@ private PageFactory() {} * @return the created entity reference */ @Contract(value = "_, _, _, _ -> new" , pure = true) - public static @NotNull PageEntity createPage( - @NotNull Instance instance, - @NotNull Pos spawnPos, - @NotNull Direction direction, + public static PageEntity createPage( + Instance instance, + Pos spawnPos, + Direction direction, int pageCount ) { Check.argCondition(direction == Direction.UP || direction == Direction.DOWN, "The direction " + direction + " is not supported"); diff --git a/common/src/main/java/net/onelitefeather/cygnus/common/page/PageProvider.java b/common/src/main/java/net/onelitefeather/cygnus/common/page/PageProvider.java index 42b3a94..461dd22 100644 --- a/common/src/main/java/net/onelitefeather/cygnus/common/page/PageProvider.java +++ b/common/src/main/java/net/onelitefeather/cygnus/common/page/PageProvider.java @@ -2,7 +2,6 @@ import net.kyori.adventure.text.Component; import net.kyori.adventure.text.format.NamedTextColor; -import net.minestom.server.coordinate.Pos; import net.minestom.server.entity.Player; import net.minestom.server.instance.Instance; import net.minestom.server.utils.Direction; @@ -11,7 +10,6 @@ import net.onelitefeather.cygnus.common.util.Helper; import net.theevilreaper.aves.util.Broadcaster; import net.theevilreaper.aves.util.functional.VoidConsumer; -import org.jetbrains.annotations.NotNull; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -49,7 +47,7 @@ public final class PageProvider { private Component pageStatus = Component.empty(); - public PageProvider(@NotNull VoidConsumer pageFinishFunction) { + public PageProvider(VoidConsumer pageFinishFunction) { this.pageFinishFunction = pageFinishFunction; this.globalCache = new ArrayList<>(); this.usedResources = new HashMap<>(); @@ -59,7 +57,7 @@ public PageProvider(@NotNull VoidConsumer pageFinishFunction) { this.currentPageCount = 1; } - public void loadPageData(@NotNull Set positions) { + public void loadPageData(Set positions) { Check.argCondition(!globalCache.isEmpty(), "Can't load pages twice"); if (positions.isEmpty()) { @@ -69,7 +67,7 @@ public void loadPageData(@NotNull Set positions) { } // Find start pages - public void collectStartPages(@NotNull Instance instance) { + public void collectStartPages(Instance instance) { Check.argCondition(this.globalCache.size() < MIN_ACTIVE_PAGE_COUNT, "Not enough pages to start the game"); var counter = 0; @@ -81,7 +79,7 @@ public void collectStartPages(@NotNull Instance instance) { if (candidateHashes.add(page.hashCode())) { Direction direction = page.face(); - var position = Helper.updatePosition(Pos.fromPoint(page.position()), direction); + var position = Helper.updatePosition(page.position().asPos(), direction); PageEntity entity = PageFactory.createPage(instance, position, direction, this.currentPageCount++); this.activePages.put(entity.getHitBoxUUID(), entity); this.usedResources.put(entity.getHitBoxUUID(), page); @@ -121,7 +119,7 @@ public void cleanUp() { this.activePages.clear(); } - public void triggerTTLHandling(@NotNull UUID uuid) { + public void triggerTTLHandling(UUID uuid) { if (this.globalCache.isEmpty()) { this.activePages.get(uuid).enableInteraction(); return; @@ -130,7 +128,7 @@ public void triggerTTLHandling(@NotNull UUID uuid) { try { CACHE_LOCK.lock(); var newPos = this.globalCache.remove(Helper.getRandomInt(this.globalCache.size())); - pageEntity.teleport(Helper.updatePosition(Pos.fromPoint(newPos.position()), newPos.face())); + pageEntity.teleport(Helper.updatePosition(newPos.position().asPos(), newPos.face())); activePages.put(pageEntity.getHitBoxUUID(), pageEntity); var resource = this.usedResources.remove(pageEntity.getHitBoxUUID()); this.globalCache.add(resource); @@ -141,7 +139,7 @@ public void triggerTTLHandling(@NotNull UUID uuid) { pageEntity.enableInteraction(); } - public void triggerPageFound(@NotNull Player player, @NotNull UUID uuid) { + public void triggerPageFound(Player player, UUID uuid) { var pageEntity = removeEntity(uuid); player.getInventory().addItemStack(pageEntity.getPageItem()); Broadcaster.broadcast(Messages.getPageFoundComponent(player)); @@ -155,7 +153,7 @@ public void triggerPageFound(@NotNull Player player, @NotNull UUID uuid) { } } - private void updatePageData(@NotNull PageEntity entity) { + private void updatePageData(PageEntity entity) { PageResource resource; try { CACHE_LOCK.lock(); @@ -163,7 +161,7 @@ private void updatePageData(@NotNull PageEntity entity) { } finally { CACHE_LOCK.unlock(); } - entity.teleport(Helper.updatePosition(Pos.fromPoint(resource.position()), resource.face())); + entity.teleport(Helper.updatePosition(resource.position().asPos(), resource.face())); entity.updateItemStack(++this.currentPageCount); try { PAGE_LOCK.lock(); @@ -182,7 +180,7 @@ private void updatePageDisplay() { ); } - private @NotNull PageEntity removeEntity(@NotNull UUID uuid) { + private PageEntity removeEntity(UUID uuid) { try { PAGE_LOCK.lock(); return this.activePages.remove(uuid); @@ -196,7 +194,7 @@ private void updatePageDisplay() { * * @return the current page status */ - public @NotNull Component getPageStatus() { + public Component getPageStatus() { return pageStatus; } diff --git a/common/src/main/java/net/onelitefeather/cygnus/common/page/PageResource.java b/common/src/main/java/net/onelitefeather/cygnus/common/page/PageResource.java index 4ed496b..1455aae 100644 --- a/common/src/main/java/net/onelitefeather/cygnus/common/page/PageResource.java +++ b/common/src/main/java/net/onelitefeather/cygnus/common/page/PageResource.java @@ -2,7 +2,6 @@ import net.minestom.server.coordinate.Point; import net.minestom.server.utils.Direction; -import org.jetbrains.annotations.NotNull; /** * The {@link PageResource} class represents a data structure used for spawning a page entity @@ -12,4 +11,4 @@ * @param position The position at which to spawn a page. * @param face The face used in the resource setup process. */ -public record PageResource(@NotNull Point position, @NotNull Direction face) { } \ No newline at end of file +public record PageResource(Point position, Direction face) { } \ No newline at end of file diff --git a/common/src/main/java/net/onelitefeather/cygnus/common/page/adapter/PageResourceAdapter.java b/common/src/main/java/net/onelitefeather/cygnus/common/page/adapter/PageResourceAdapter.java index 01d8f2f..475a32b 100644 --- a/common/src/main/java/net/onelitefeather/cygnus/common/page/adapter/PageResourceAdapter.java +++ b/common/src/main/java/net/onelitefeather/cygnus/common/page/adapter/PageResourceAdapter.java @@ -9,9 +9,9 @@ import com.google.gson.JsonSerializer; import net.minestom.server.coordinate.Point; import net.minestom.server.coordinate.Vec; -import net.minestom.server.utils.Direction; import net.onelitefeather.cygnus.common.page.PageResource; import net.onelitefeather.cygnus.common.util.DirectionFaceHelper; +import org.jetbrains.annotations.Nullable; import java.lang.reflect.Type; @@ -26,7 +26,7 @@ public final class PageResourceAdapter implements JsonSerializer, private static final String FACE_KEY = "face"; @Override - public JsonElement serialize(PageResource src, Type typeOfSrc, JsonSerializationContext context) { + public @Nullable JsonElement serialize(@Nullable PageResource src, Type typeOfSrc, JsonSerializationContext context) { if (src == null) return null; JsonObject object = new JsonObject(); object.addProperty(FACE_KEY, src.face().name()); diff --git a/common/src/main/java/net/onelitefeather/cygnus/common/page/adapter/package-info.java b/common/src/main/java/net/onelitefeather/cygnus/common/page/adapter/package-info.java new file mode 100644 index 0000000..450871b --- /dev/null +++ b/common/src/main/java/net/onelitefeather/cygnus/common/page/adapter/package-info.java @@ -0,0 +1,5 @@ + +@NotNullByDefault +package net.onelitefeather.cygnus.common.page.adapter; + +import org.jetbrains.annotations.NotNullByDefault; \ No newline at end of file diff --git a/common/src/main/java/net/onelitefeather/cygnus/common/page/event/PageEvent.java b/common/src/main/java/net/onelitefeather/cygnus/common/page/event/PageEvent.java index 0086f35..5609f13 100644 --- a/common/src/main/java/net/onelitefeather/cygnus/common/page/event/PageEvent.java +++ b/common/src/main/java/net/onelitefeather/cygnus/common/page/event/PageEvent.java @@ -3,7 +3,6 @@ import net.minestom.server.entity.Player; import net.minestom.server.event.Event; import net.onelitefeather.cygnus.common.page.PageEntity; -import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; /** @@ -13,14 +12,14 @@ * @param reason the reason why the event was called * @param player the player who performed the action or null */ -public record PageEvent(@NotNull PageEntity entity, @NotNull Reason reason, @Nullable Player player) implements Event { +public record PageEvent(PageEntity entity, Reason reason, @Nullable Player player) implements Event { /** * Creates a new instance from the event without a player reference. * @param entity the page entity * @param reason the reason why the event was called */ - public PageEvent(@NotNull PageEntity entity, @NotNull Reason reason) { + public PageEvent(PageEntity entity, Reason reason) { this(entity, reason, null); } diff --git a/common/src/main/java/net/onelitefeather/cygnus/common/page/event/package-info.java b/common/src/main/java/net/onelitefeather/cygnus/common/page/event/package-info.java new file mode 100644 index 0000000..4cf49fa --- /dev/null +++ b/common/src/main/java/net/onelitefeather/cygnus/common/page/event/package-info.java @@ -0,0 +1,4 @@ +@NotNullByDefault +package net.onelitefeather.cygnus.common.page.event; + +import org.jetbrains.annotations.NotNullByDefault; \ No newline at end of file diff --git a/common/src/main/java/net/onelitefeather/cygnus/common/page/package-info.java b/common/src/main/java/net/onelitefeather/cygnus/common/page/package-info.java new file mode 100644 index 0000000..0c4139c --- /dev/null +++ b/common/src/main/java/net/onelitefeather/cygnus/common/page/package-info.java @@ -0,0 +1,4 @@ +@NotNullByDefault +package net.onelitefeather.cygnus.common.page; + +import org.jetbrains.annotations.NotNullByDefault; \ No newline at end of file diff --git a/common/src/main/java/net/onelitefeather/cygnus/common/util/DirectionFaceHelper.java b/common/src/main/java/net/onelitefeather/cygnus/common/util/DirectionFaceHelper.java index 6ef1289..36e5ed0 100644 --- a/common/src/main/java/net/onelitefeather/cygnus/common/util/DirectionFaceHelper.java +++ b/common/src/main/java/net/onelitefeather/cygnus/common/util/DirectionFaceHelper.java @@ -1,7 +1,6 @@ package net.onelitefeather.cygnus.common.util; import net.minestom.server.utils.Direction; -import org.jetbrains.annotations.NotNull; /** * The {@link DirectionFaceHelper} class provides utility methods to handle the direction of a face. @@ -18,7 +17,7 @@ public final class DirectionFaceHelper { * @param face the face to parse * @return the parsed face */ - public static @NotNull Direction parseDirection(@NotNull String face) { + public static Direction parseDirection(String face) { if (face.trim().isEmpty()) return Direction.NORTH; Direction direction = null; @@ -48,7 +47,7 @@ public static boolean isValidFace(double pitch) { * @param pitch the pitch to check * @return the invalid direction */ - public static @NotNull Direction getInvalidDirection(double pitch) { + public static Direction getInvalidDirection(double pitch) { return pitch > 50 ? Direction.DOWN : Direction.UP; } diff --git a/common/src/main/java/net/onelitefeather/cygnus/common/util/Helper.java b/common/src/main/java/net/onelitefeather/cygnus/common/util/Helper.java index a3529d4..a7c7218 100644 --- a/common/src/main/java/net/onelitefeather/cygnus/common/util/Helper.java +++ b/common/src/main/java/net/onelitefeather/cygnus/common/util/Helper.java @@ -3,7 +3,6 @@ import net.minestom.server.coordinate.Pos; import net.minestom.server.utils.Direction; import org.jetbrains.annotations.Contract; -import org.jetbrains.annotations.NotNull; import java.security.SecureRandom; import java.util.concurrent.ThreadLocalRandom; @@ -46,7 +45,7 @@ public static int getRandomInt(int maximumValue) { } @Contract(pure = true) - public static @NotNull Pos updatePosition(@NotNull Pos pos, @NotNull Direction direction) { + public static Pos updatePosition(Pos pos, Direction direction) { return switch (direction) { case NORTH -> pos.add(0.5, .5, 1); // ? case SOUTH -> pos.add(0.5, .5, PAGE_VISIBLE_OFFSET); //Yes //z = 1 diff --git a/common/src/main/java/net/onelitefeather/cygnus/common/util/package-info.java b/common/src/main/java/net/onelitefeather/cygnus/common/util/package-info.java new file mode 100644 index 0000000..466fe45 --- /dev/null +++ b/common/src/main/java/net/onelitefeather/cygnus/common/util/package-info.java @@ -0,0 +1,5 @@ + +@NotNullByDefault +package net.onelitefeather.cygnus.common.util; + +import org.jetbrains.annotations.NotNullByDefault; \ No newline at end of file