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
9 changes: 4 additions & 5 deletions src/main/java/net/theevilreaper/bounce/Bounce.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@
import net.theevilreaper.bounce.util.BounceScoreboard;
import net.theevilreaper.xerus.api.phase.LinearPhaseSeries;
import net.theevilreaper.xerus.api.phase.Phase;
import org.jetbrains.annotations.NotNull;

import java.nio.file.Path;
import java.nio.file.Paths;
Expand Down Expand Up @@ -111,7 +110,7 @@ private void registerPhases() {
this.phaseSeries.add(new RestartPhase());
}

private void registerListener(@NotNull EventNode<Event> node) {
private void registerListener(EventNode<Event> node) {
node.addListener(AsyncPlayerConfigurationEvent.class, new PlayerConfigurationListener(
this.phaseSeries::getCurrentPhase,
this.mapProvider.getActiveInstance(),
Expand All @@ -130,7 +129,7 @@ private void registerListener(@NotNull EventNode<Event> node) {
node.addListener(PlayerChatEvent.class, new PlayerChatListener());
}

private void registerGameListener(@NotNull EventNode<Event> node) {
private void registerGameListener(EventNode<Event> node) {
node.addListener(BounceGameFinishEvent.class, new GameFinishListener(profileService));
node.addListener(ScoreUpdateEvent.class, new ScoreUpdateListener(scoreboard::updatePlayerLine));
node.addListener(FinalAttackEvent.class, new AttackListener(this.phaseSeries::getCurrentPhase));
Expand All @@ -143,7 +142,7 @@ private void registerCommands() {
MinecraftServer.getCommandManager().register(new StartCommand(this.phaseSeries::getCurrentPhase));
}

private void handleGameLeave(@NotNull Player player) {
private void handleGameLeave(Player player) {
BounceProfile profile = this.profileService.remove(player);

if (profile == null) return;
Expand All @@ -152,7 +151,7 @@ private void handleGameLeave(@NotNull Player player) {
this.scoreboard.removeViewer(player);
}

private void handleGeneralJoin(@NotNull Player player) {
private void handleGeneralJoin(Player player) {
this.mapProvider.teleportToSpawn(player, false);
this.scoreboard.addViewer(player);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,12 @@

import net.minestom.server.entity.Player;
import net.minestom.server.entity.attribute.Attribute;
import org.jetbrains.annotations.NotNull;

/**
* The {@link AttributeHelper} is a utility class to manage player attributes related to jumping.
*
* @author theEvilReaper
* @version 1.0.0
* @version 1.0.1
* @since 0.1.0
*/
public final class AttributeHelper {
Expand All @@ -21,7 +20,7 @@ public final class AttributeHelper {
*
* @param player the player whose jump strength is to be disabled
*/
public static void disableJumpStrength(@NotNull Player player) {
public static void disableJumpStrength(Player player) {
player.getAttribute(Attribute.JUMP_STRENGTH).setBaseValue(ZERO_JUMP);
}

Expand All @@ -30,11 +29,11 @@ public static void disableJumpStrength(@NotNull Player player) {
*
* @param player the player whose jump strength is to be reset
*/
public static void resetJumpStrength(@NotNull Player player) {
public static void resetJumpStrength(Player player) {
player.getAttribute(Attribute.JUMP_STRENGTH).setBaseValue(DEFAULT_JUMP_HEIGHT);
}

private AttributeHelper() {

// Nothing to do here
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@

@NotNullByDefault
package net.theevilreaper.bounce.attribute;

import org.jetbrains.annotations.NotNullByDefault;
22 changes: 17 additions & 5 deletions src/main/java/net/theevilreaper/bounce/commands/StartCommand.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package net.theevilreaper.bounce.commands;

import net.minestom.server.command.CommandSender;
import net.minestom.server.command.builder.Command;
import net.theevilreaper.bounce.common.config.GameConfig;
import net.theevilreaper.bounce.common.util.Messages;
import net.theevilreaper.bounce.timer.LobbyPhase;
Expand All @@ -9,7 +11,6 @@
import net.kyori.adventure.text.format.NamedTextColor;
import net.minestom.server.command.builder.CommandContext;
import net.minestom.server.command.builder.condition.Conditions;
import org.jetbrains.annotations.NotNull;

import java.util.function.Supplier;

Expand All @@ -19,24 +20,35 @@
* It checks if the game is paused if the timer is long enough, and if the game has already been force started.
*
* @author theEvilReaper
* @version 1.0.0
* @version 1.0.1
* @since 1.0.0
**/
public class StartCommand extends net.minestom.server.command.builder.Command {
public class StartCommand extends Command {

private final Supplier<Phase> phaseSupplier;
private final Component unableToStart = Messages.withPrefix(
Component.text("Unable to start the game because the timer is to low!", NamedTextColor.RED)
);

public StartCommand(@NotNull Supplier<Phase> phaseSupplier) {
/**
* Creates a new instance of the command with the given {@link Supplier<Phase>}.
*
* @param phaseSupplier which returns the current phase
*/
public StartCommand(Supplier<Phase> phaseSupplier) {
super("start");
this.phaseSupplier = phaseSupplier;
this.setCondition(Conditions::playerOnly);
addSyntax(this::forceStart);
}

private void forceStart(@NotNull net.minestom.server.command.CommandSender sender, @NotNull CommandContext commandContext) {
/**
* Handles the command logic to force start the game.
*
* @param sender which is involved
* @param commandContext of the command
*/
private void forceStart(CommandSender sender, CommandContext commandContext) {
Phase phase = phaseSupplier.get();

if (!(phase instanceof LobbyPhase lobbyPhase)) return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,26 +9,26 @@
import net.minestom.server.entity.Player;
import net.theevilreaper.bounce.profile.BounceProfile;
import net.theevilreaper.bounce.util.GameMessages;
import org.jetbrains.annotations.NotNull;

import java.util.function.Function;

public class StatsCommand extends Command {

private final Function<Player, BounceProfile> profileFunction;
private final ArgumentString playerArgument;
public StatsCommand(@NotNull Function<Player, BounceProfile> profileFunction) {

public StatsCommand(Function<Player, BounceProfile> profileFunction) {
super("stats");
this.profileFunction = profileFunction;
this.playerArgument = ArgumentType.String("player");
addSyntax(this::handleOwnStats);
}

private void handleOtherStats(@NotNull CommandSender sender, @NotNull CommandContext context) {
private void handleOtherStats(CommandSender sender, CommandContext context) {
Player player = (Player) sender;
String playerName = context.get(playerArgument);

if (playerName == null || playerName.isEmpty()) {
if (playerName.isEmpty()) {
sender.sendMessage(GameMessages.INVALID_PLAYER_NAME);
return;
}
Expand All @@ -54,7 +54,7 @@ private void handleOtherStats(@NotNull CommandSender sender, @NotNull CommandCon

}

private void handleOwnStats(@NotNull CommandSender sender, @NotNull CommandContext context) {
private void handleOwnStats(CommandSender sender, CommandContext context) {
Player player = (Player) sender;
BounceProfile profile = profileFunction.apply(player);

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@

@NotNullByDefault
package net.theevilreaper.bounce.commands;

import org.jetbrains.annotations.NotNullByDefault;
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
package net.theevilreaper.bounce.event;

import net.theevilreaper.xerus.api.event.GameFinishEvent;
import org.jetbrains.annotations.NotNull;

/**
* The {@link BounceGameFinishEvent} extends the {@link GameFinishEvent} to provide specific reasons for finishing a Bounce game.
* It includes reasons such as time over, one player left, or a player left the game.
*
* @author theEvilReaper
* @version 1.0.0
* @version 1.0.1
* @since 0.1.0
*/
public class BounceGameFinishEvent extends GameFinishEvent<BounceGameFinishEvent.Reason> {
Expand All @@ -18,7 +17,7 @@ public class BounceGameFinishEvent extends GameFinishEvent<BounceGameFinishEvent
*
* @param reason the reason for finishing the game
*/
public BounceGameFinishEvent(@NotNull Reason reason) {
public BounceGameFinishEvent(Reason reason) {
super(reason);
}

Expand Down
18 changes: 14 additions & 4 deletions src/main/java/net/theevilreaper/bounce/event/PlayerLavaEvent.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,16 @@

import net.minestom.server.entity.Player;
import net.minestom.server.event.trait.PlayerEvent;
import org.jetbrains.annotations.NotNull;

public class PlayerLavaEvent implements PlayerEvent {
/**
* Called when a player falls into lava.
*
* @version 1.0.0
* @since 0.1.0
* @author theEvilReaper
*/
@SuppressWarnings("java:S6206")
public final class PlayerLavaEvent implements PlayerEvent {

private final Player player;

Expand All @@ -13,12 +20,15 @@ public class PlayerLavaEvent implements PlayerEvent {
*
* @param player the player who is in lava
*/
public PlayerLavaEvent(@NotNull Player player) {
public PlayerLavaEvent(Player player) {
this.player = player;
}

/**
* {@inheritDoc}
*/
@Override
public @NotNull Player getPlayer() {
public Player getPlayer() {
return this.player;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,13 @@

import net.minestom.server.entity.Player;
import net.minestom.server.event.trait.PlayerEvent;
import org.jetbrains.annotations.NotNull;

/**
* The {@link ScoreUpdateEvent} is triggered when a player's score is updated.
* This event is used to handle the logic related to updating the player's score.
*
* @author theEvilReaper
* @version 1.0.0
* @version 1.0.1
* @since 0.1.0
*/
public class ScoreUpdateEvent implements PlayerEvent {
Expand All @@ -23,7 +22,7 @@ public class ScoreUpdateEvent implements PlayerEvent {
* @param player the player whose score is being updated
* @param points the number of points to be added to the player's score
*/
public ScoreUpdateEvent(@NotNull Player player, int points) {
public ScoreUpdateEvent(Player player, int points) {
this.player = player;
this.points = points;
}
Expand All @@ -43,7 +42,7 @@ public int getPoints() {
* @return the player whose score is being updated
*/
@Override
public @NotNull Player getPlayer() {
public Player getPlayer() {
return player;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@

@NotNullByDefault
package net.theevilreaper.bounce.event;

import org.jetbrains.annotations.NotNullByDefault;
12 changes: 6 additions & 6 deletions src/main/java/net/theevilreaper/bounce/jump/PlayerJumpTask.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
import net.theevilreaper.bounce.common.map.GameMap;
import net.theevilreaper.bounce.common.push.PushData;
import net.theevilreaper.bounce.event.PlayerLavaEvent;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.util.List;

Expand All @@ -23,17 +23,17 @@ public final class PlayerJumpTask {
private final Player player;
private final PushData pushData;

private GameMap map;
private Task task;
private @Nullable GameMap map;
private @Nullable Task task;
private Block lastBlockBelow = Block.AIR; // Track previous block below player
private long lastPushTime = 0;

public PlayerJumpTask(@NotNull Player player, @NotNull PushData pushData) {
public PlayerJumpTask(Player player, PushData pushData) {
this.player = player;
this.pushData = pushData;
}

public void start(@NotNull GameMap bounceMap) {
public void start(GameMap bounceMap) {
if (this.task != null) return;
this.map = bounceMap;
this.task = MinecraftServer.getSchedulerManager().buildTask(this::onTick)
Expand Down Expand Up @@ -84,7 +84,7 @@ private void onTick() {
lastBlockBelow = foundJumpBlock;
}

private @NotNull List<int[]> getCheckPositions() {
private List<int[]> getCheckPositions() {
Pos playerPos = player.getPosition();
double halfWidth = 0.3;
double minX = playerPos.x() - halfWidth;
Expand Down
5 changes: 5 additions & 0 deletions src/main/java/net/theevilreaper/bounce/jump/package-info.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@

@NotNullByDefault
package net.theevilreaper.bounce.jump;

import org.jetbrains.annotations.NotNullByDefault;
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,13 @@
import net.minestom.server.entity.Player;
import net.minestom.server.event.player.PlayerChatEvent;
import net.theevilreaper.bounce.common.util.Messages;
import org.jetbrains.annotations.NotNull;

import java.util.function.Consumer;

public final class PlayerChatListener implements Consumer<PlayerChatEvent> {

@Override
public void accept(@NotNull PlayerChatEvent event) {
public void accept(PlayerChatEvent event) {
Player player = event.getPlayer();
Component message = player.getDisplayName().append(Messages.SEPARATOR).append(Component.text(event.getRawMessage(), NamedTextColor.WHITE));
event.setFormattedMessage(message);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import net.minestom.server.instance.Instance;
import net.theevilreaper.bounce.timer.LobbyPhase;
import net.theevilreaper.xerus.api.phase.Phase;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.util.function.Consumer;
Expand All @@ -20,11 +19,11 @@ public class PlayerConfigurationListener implements Consumer<AsyncPlayerConfigur
private static final Component FULL_SERVER = Component.text("Unable to join because the server is full!", NamedTextColor.RED);
private final int maxPlayers;
private final Supplier<@Nullable Phase> phaseSupplier;
private final Supplier<@NotNull Instance> instanceSupplier;
private final Supplier<Instance> instanceSupplier;

public PlayerConfigurationListener(
@NotNull Supplier<Phase> phaseSupplier,
@NotNull Supplier<Instance> instanceSupplier,
Supplier<Phase> phaseSupplier,
Supplier<Instance> instanceSupplier,
int maxPlayers
) {
this.phaseSupplier = phaseSupplier;
Expand All @@ -33,7 +32,7 @@ public PlayerConfigurationListener(
}

@Override
public void accept(@NotNull AsyncPlayerConfigurationEvent event) {
public void accept(AsyncPlayerConfigurationEvent event) {
Player player = event.getPlayer();
if (MinecraftServer.getConnectionManager().getOnlinePlayers().size() >= maxPlayers) {
player.kick(FULL_SERVER);
Expand Down
Loading
Loading