From 3e26a33f5a52a9e1b759a85c099fb20c970bd3c8 Mon Sep 17 00:00:00 2001 From: Andrew Lalis Date: Sun, 31 Jul 2022 11:35:43 +0200 Subject: [PATCH] Added /mode command, and improved redfort world. --- .../nl/andrewl/aos2_server/PlayerManager.java | 2 +- .../cli/ingame/PlayerCommandHandler.java | 2 ++ .../ingame/commands/PlayerModeCommand.java | 26 ++++++++++++++++++ .../logic/PlayerActionManager.java | 3 +- server/src/main/resources/redfort.wld | Bin 1665332 -> 1665332 bytes 5 files changed, 30 insertions(+), 3 deletions(-) create mode 100644 server/src/main/java/nl/andrewl/aos2_server/cli/ingame/commands/PlayerModeCommand.java 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 0a724839a6a488259726add4b4f27659b9fdc84b..d05d24729fd5aa821f7b976ce422de9da53cd91d 100644 GIT binary patch delta 570 zcmaivze@s99Kd_`ygT!ErI!*EZaJ6|WEmFGkD-Q$rproAk(R)g=A63u5c)0=M@uaZ zf^cnD|H0wVSWabsK)FctJ$v3AVh$g;gaCdaCrxtbELNf z6qw&!?f)^wY;(HVrdKQ06XXS3_bGCMd69XkYei1lbUDeNKH$Y#jP8P`$v^kLR|yZ{ zmN=(s=TLp)=dm_l`51)X#ak<^6X7~ar~gjv`>bCbEF0dz=JQ0*eV;rKRTK1Ti=PU? z#|!6%s-12?Cqke4$1RAr#2Hm9L1&i6`*~B{UDto;W4brr#ZCfQbT$1-# tsH%yI;SdnZc4QQBAWp=ExDgNHMSRE@GLB3jek6cM$RrZf4M*rA^9!wzy#W9K delta 352 zcmdmTDRs-G)P^mLRuN1b9Mf$g82>SGa89?01k#*9eiVoX@}r@23`ia*9t-8ifoLE< z9wZJ_mjD${gwjc1@phYJ#_cxAOkNYG7hGY=*#7Pd(`3f!GsT!2r%MX)3r_!fjVW?^ z&R3?2={whO@J*j7$ge#8`*o(M_WU1A+w*@gKequ{5@E^$wmiZNL~~A$FbC2=$3<9x z#oHq+S++-5vZk+?zFvpfcRSAu*4a!G7qD$#`-1fsBRWG`a{2}iW~b=}&)E64|IuV# zz%g+Fd;5MaHXsJk96-zo#9Tnk4a7V^%nQVPK+F%s0zfPX#6mzU48$TpEDFS8Kr9Z# M65IE4NtVU|01%pcfB*mh