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 @@ -8,15 +8,14 @@
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;

/**
* 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 {
Expand All @@ -28,7 +27,7 @@ public interface ListenerHandling {
*
* @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
Original file line number Diff line number Diff line change
Expand Up @@ -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<Area>, JsonDeserializer<Area> {

/**
* {@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);
Expand All @@ -39,8 +45,11 @@ public final class AreaAdapter implements JsonSerializer<Area>, 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));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<PushData>, JsonSerializer<PushData> {

@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();

Expand All @@ -47,7 +49,7 @@ public class PushDataAdapter implements JsonDeserializer<PushData>, 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 -> {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
@NotNullByDefault
package net.theevilreaper.bounce.common.adapter;

import org.jetbrains.annotations.NotNullByDefault;
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

Expand Down Expand Up @@ -73,15 +73,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 @@ -90,22 +90,22 @@ 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);

/**
* Builds the game configuration.
*
* @return the created configuration
*/
@NotNull GameConfig build();
GameConfig build();
}

}
Original file line number Diff line number Diff line change
@@ -1,43 +1,67 @@
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;
private int maxPlayers;
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);
}
this.lobbyTime = lobbyTime;
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);
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package net.theevilreaper.bounce.common.config;

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

Expand All @@ -22,7 +21,7 @@
* <li>gameTime</li>
* </ul>
* <p>
* 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
Expand All @@ -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");
}

Expand All @@ -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();
Expand Down
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -27,7 +25,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.theevilreaper.bounce.common.config;

import org.jetbrains.annotations.NotNullByDefault;
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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();
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,17 @@ public final class GroundArea implements Area {
private final Block groundBlock;
private final List<Vec> 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;
this.groundBlock = groundBlock;
this.positions = new ArrayList<>();
}

/**
* {@inheritDoc}
*/
@Override
public void calculatePositions() {
// Avoid double calculations
Expand Down Expand Up @@ -59,30 +62,30 @@ public boolean hasPositions() {
* {@inheritDoc}
*/
@Override
public @NotNull PushData data() {
public PushData data() {
return data;
}

/**
* {@inheritDoc}
*/
@Override
public @NotNull Vec max() {
public Vec max() {
return max;
}

/**
* {@inheritDoc}
*/
@Override
public @NotNull Vec min() {
public Vec min() {
return min;
}

/**
* {@inheritDoc}
*/
public @NotNull Block groundBlock() {
public Block groundBlock() {
return groundBlock;
}
}
Loading
Loading