diff --git a/server/src/main/java/nl/andrewl/aos2_server/PlayerManager.java b/server/src/main/java/nl/andrewl/aos2_server/PlayerManager.java index f36b7b9..662df22 100644 --- a/server/src/main/java/nl/andrewl/aos2_server/PlayerManager.java +++ b/server/src/main/java/nl/andrewl/aos2_server/PlayerManager.java @@ -47,7 +47,7 @@ public class PlayerManager { joinMessage = username + " joined the game."; } player.setPosition(getBestSpawnPoint(player)); - player.setMode(PlayerMode.CREATIVE); + player.setMode(PlayerMode.NORMAL); // Tell all other players that this one has joined. broadcastTcpMessageToAllBut(new PlayerJoinMessage( player.getId(), player.getUsername(), player.getTeam() == null ? -1 : player.getTeam().getId(), diff --git a/server/src/main/java/nl/andrewl/aos2_server/cli/ingame/PlayerCommandHandler.java b/server/src/main/java/nl/andrewl/aos2_server/cli/ingame/PlayerCommandHandler.java index dc7471a..8c5fadd 100644 --- a/server/src/main/java/nl/andrewl/aos2_server/cli/ingame/PlayerCommandHandler.java +++ b/server/src/main/java/nl/andrewl/aos2_server/cli/ingame/PlayerCommandHandler.java @@ -4,6 +4,7 @@ import nl.andrewl.aos2_server.ClientCommunicationHandler; import nl.andrewl.aos2_server.Server; import nl.andrewl.aos2_server.cli.ingame.commands.KillCommand; import nl.andrewl.aos2_server.cli.ingame.commands.KillDeathRatioCommand; +import nl.andrewl.aos2_server.cli.ingame.commands.PlayerModeCommand; import nl.andrewl.aos2_server.model.ServerPlayer; import nl.andrewl.aos_core.net.client.ChatMessage; @@ -25,6 +26,7 @@ public class PlayerCommandHandler { commands = new HashMap<>(); commands.put("kd", new KillDeathRatioCommand()); commands.put("kill", new KillCommand()); + commands.put("mode", new PlayerModeCommand()); } public void handle(String rawCommand, ServerPlayer player, ClientCommunicationHandler handler) { diff --git a/server/src/main/java/nl/andrewl/aos2_server/cli/ingame/commands/PlayerModeCommand.java b/server/src/main/java/nl/andrewl/aos2_server/cli/ingame/commands/PlayerModeCommand.java new file mode 100644 index 0000000..62c2939 --- /dev/null +++ b/server/src/main/java/nl/andrewl/aos2_server/cli/ingame/commands/PlayerModeCommand.java @@ -0,0 +1,26 @@ +package nl.andrewl.aos2_server.cli.ingame.commands; + +import nl.andrewl.aos2_server.ClientCommunicationHandler; +import nl.andrewl.aos2_server.Server; +import nl.andrewl.aos2_server.cli.ingame.PlayerCommand; +import nl.andrewl.aos2_server.model.ServerPlayer; +import nl.andrewl.aos_core.model.PlayerMode; +import nl.andrewl.aos_core.net.client.ChatMessage; + +public class PlayerModeCommand implements PlayerCommand { + @Override + public void handle(String[] args, ServerPlayer player, ClientCommunicationHandler handler, Server server) { + if (args.length < 1) { + handler.sendTcpMessage(ChatMessage.privateMessage("Missing required mode argument.")); + return; + } + String modeText = args[0].trim().toUpperCase(); + try { + PlayerMode mode = PlayerMode.valueOf(modeText); + player.setMode(mode); + server.getPlayerManager().broadcastUdpMessage(player.getUpdateMessage(System.currentTimeMillis())); + } catch (IllegalArgumentException e) { + handler.sendTcpMessage(ChatMessage.privateMessage("Invalid mode. Should be NORMAL, CREATIVE, or SPECTATOR.")); + } + } +} diff --git a/server/src/main/java/nl/andrewl/aos2_server/logic/PlayerActionManager.java b/server/src/main/java/nl/andrewl/aos2_server/logic/PlayerActionManager.java index 764818e..dfaccd9 100644 --- a/server/src/main/java/nl/andrewl/aos2_server/logic/PlayerActionManager.java +++ b/server/src/main/java/nl/andrewl/aos2_server/logic/PlayerActionManager.java @@ -100,8 +100,7 @@ public class PlayerActionManager { updated = switch (player.getMode()) { case NORMAL -> normalMovementController.tickMovement(dt, player, input, server, world, server.getConfig().physics); - case CREATIVE -> creativeMovementController.tickMovement(dt, player, input, server, world, server.getConfig().physics); - case SPECTATOR -> false; + case CREATIVE, SPECTATOR -> creativeMovementController.tickMovement(dt, player, input, server, world, server.getConfig().physics); } || updated; input.reset(); // Reset our input state after processing this tick's player input. } diff --git a/server/src/main/resources/redfort.wld b/server/src/main/resources/redfort.wld index 0a72483..d05d247 100644 Binary files a/server/src/main/resources/redfort.wld and b/server/src/main/resources/redfort.wld differ