Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -20,12 +21,14 @@
*/
public interface ListenerHandling {

Consumer<CancellableEvent> 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<Event> eventNode) {
default void registerCancelListener(EventNode<Event> eventNode) {
eventNode.addListener(PlayerBlockBreakEvent.class, CANCELLABLE_EVENT::accept);
eventNode.addListener(PlayerBlockPlaceEvent.class, CANCELLABLE_EVENT::accept);
eventNode.addListener(ItemDropEvent.class, CANCELLABLE_EVENT::accept);
Expand Down
29 changes: 14 additions & 15 deletions common/src/main/java/net/onelitefeather/cygnus/common/Messages.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
Expand Down Expand Up @@ -78,57 +77,57 @@ 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 + "><player>", 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("<red><player> <color:#249D9F>was</color> <color:#ff0000>TAKEN!</color>", playerTag));
}


@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))
Expand All @@ -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)
Expand All @@ -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("<color:#249D9F>" + player.getUsername() + "</color>"))
.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("<color:#249D9F>" + player.getUsername() + "</color>"))
.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("<red>(" + pageCount + " TO WIN)"))
.append(Component.newline())
.append(SURVIVOR_JOIN_LOWER_PART);
Expand Down
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -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();
}

Expand Down Expand Up @@ -101,15 +100,15 @@ 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.
*
* @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.
Expand All @@ -118,15 +117,15 @@ 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.
*
* @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.
Expand All @@ -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.
Expand All @@ -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();
}

}
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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);
}
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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);
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package net.onelitefeather.cygnus.common.config;

import org.jetbrains.annotations.NotNull;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand Down Expand Up @@ -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");
}

Expand All @@ -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();
Expand Down
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -31,7 +29,7 @@ record InternalGameConfig(
*
* @return the default configuration
*/
public static @NotNull GameConfig defaultConfig() {
public static GameConfig defaultConfig() {
return Instances.INTERNAL;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
@NotNullByDefault
package net.onelitefeather.cygnus.common.config;

import org.jetbrains.annotations.NotNullByDefault;
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
@NotNullByDefault
package net.onelitefeather.cygnus.common.event;

import org.jetbrains.annotations.NotNullByDefault;
Loading