Added /mode command, and improved redfort world.

This commit is contained in:
Andrew Lalis 2022-07-31 11:35:43 +02:00
parent 53b8718a06
commit 3e26a33f5a
5 changed files with 30 additions and 3 deletions

View File

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

View File

@ -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) {

View File

@ -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."));
}
}
}

View File

@ -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.
}