From e02db741d673c74b0906f64d595627085d112800 Mon Sep 17 00:00:00 2001 From: CyberL1 Date: Sat, 3 Feb 2024 11:48:22 +0100 Subject: [PATCH] feat: world creating --- .../Controllers/WorldsController.cs | 27 +++++++++++++++++++ .../Entities/WorldCreate.cs | 8 ++++++ 2 files changed, 35 insertions(+) create mode 100644 Minecraft-Realms-Emulator/Entities/WorldCreate.cs diff --git a/Minecraft-Realms-Emulator/Controllers/WorldsController.cs b/Minecraft-Realms-Emulator/Controllers/WorldsController.cs index 3e61f08..c0325f0 100644 --- a/Minecraft-Realms-Emulator/Controllers/WorldsController.cs +++ b/Minecraft-Realms-Emulator/Controllers/WorldsController.cs @@ -75,5 +75,32 @@ namespace Minecraft_Realms_Emulator.Controllers return world; } + + [HttpPost("{id}/initialize")] + public async Task> Initialize(int id, WorldCreate body) + { + var worlds = await _context.Worlds.ToListAsync(); + + var world = worlds.Find(p => p.Id == id); + + if (world == null) return NotFound("World not found"); + if (world.State != State.UNINITIALIZED.ToString()) return NotFound("World already initialized"); + + world.Name = body.Name; + world.Motd = body.Description; + world.State = State.OPEN.ToString(); + + _context.Worlds.Update(world); + _context.SaveChanges(); + + return Ok(world); + } + + [HttpPost("{id}/reset")] + public ActionResult Reset(int id) + { + Console.WriteLine($"Resetting world {id}"); + return Ok(true); + } } } diff --git a/Minecraft-Realms-Emulator/Entities/WorldCreate.cs b/Minecraft-Realms-Emulator/Entities/WorldCreate.cs new file mode 100644 index 0000000..71efe94 --- /dev/null +++ b/Minecraft-Realms-Emulator/Entities/WorldCreate.cs @@ -0,0 +1,8 @@ +namespace Minecraft_Realms_Emulator.Entities +{ + public class WorldCreate + { + public string? Name { get; set; } + public string? Description { get; set; } + } +} \ No newline at end of file