diff --git a/MyMcRealms/Controllers/InvitesController.cs b/MyMcRealms/Controllers/InvitesController.cs index d74f25a..82fb2e9 100644 --- a/MyMcRealms/Controllers/InvitesController.cs +++ b/MyMcRealms/Controllers/InvitesController.cs @@ -1,11 +1,9 @@ using Microsoft.AspNetCore.Mvc; -using Minecraft_Realms_Emulator.Responses; -using MyMcRealms.Attributes; -using MyMcRealms.MyMcAPI; -using MyMcRealms.Requests; using MyMcRealms.Responses; +using MyMcRealms.Attributes; +using MyMcRealms.Requests; -namespace Minecraft_Realms_Emulator.Controllers +namespace MyMcRealms.Controllers { [Route("[controller]")] [ApiController] @@ -20,7 +18,7 @@ namespace Minecraft_Realms_Emulator.Controllers if (body.Name == playerName) return Forbid("You cannot invite yourself"); - var _api = new MyMcAPI(Environment.GetEnvironmentVariable("MYMC_API_KEY")); + var _api = new MyMcAPI.Wrapper(Environment.GetEnvironmentVariable("MYMC_API_KEY")); var world = (await _api.GetAllServers()).Servers[wId]; if (world == null) return NotFound("World not found"); @@ -30,7 +28,7 @@ namespace Minecraft_Realms_Emulator.Controllers if (world.Whitelist.Any(p => p.Name == body.Name)) return BadRequest("Player already whitelisted"); - var api = new MyMcAPI(world.OwnersToken); + var api = new MyMcAPI.Wrapper(world.OwnersToken); api.ExecuteCommand($"whitelist add {body.Name}"); List whitelistedPlayers = []; @@ -90,7 +88,7 @@ namespace Minecraft_Realms_Emulator.Controllers [HttpDelete("{wId}/invite/{uuid}")] public async Task> DeleteInvite(int wId, string uuid) { - var _api = new MyMcAPI(Environment.GetEnvironmentVariable("MYMC_API_KEY")); + var _api = new MyMcAPI.Wrapper(Environment.GetEnvironmentVariable("MYMC_API_KEY")); var world = (await _api.GetAllServers()).Servers[wId]; if (world == null) return NotFound("World not found"); @@ -102,7 +100,7 @@ namespace Minecraft_Realms_Emulator.Controllers if (!world.Whitelist.Any(p => p.Uuid.Replace("-", "") == uuid)) return BadRequest("Player not whitelisted"); - var api = new MyMcAPI(world.OwnersToken); + var api = new MyMcAPI.Wrapper(world.OwnersToken); api.ExecuteCommand($"whitelist remove {player.Name}"); return Ok(true); diff --git a/MyMcRealms/Controllers/OpsController.cs b/MyMcRealms/Controllers/OpsController.cs index aebdd12..0d28680 100644 --- a/MyMcRealms/Controllers/OpsController.cs +++ b/MyMcRealms/Controllers/OpsController.cs @@ -1,9 +1,8 @@ using Microsoft.AspNetCore.Mvc; -using Minecraft_Realms_Emulator.Responses; +using MyMcRealms.Responses; using MyMcRealms.Attributes; -using MyMcRealms.MyMcAPI; -namespace Minecraft_Realms_Emulator.Controllers +namespace MyMcRealms.Controllers { [Route("[controller]")] [ApiController] @@ -13,9 +12,9 @@ namespace Minecraft_Realms_Emulator.Controllers [HttpPost("{wId}/{uuid}")] public async Task> OpPlayer(int wId, string uuid) { - var _api = new MyMcAPI(Environment.GetEnvironmentVariable("MYMC_API_KEY")); + var _api = new MyMcAPI.Wrapper(Environment.GetEnvironmentVariable("MYMC_API_KEY")); var world = (await _api.GetAllServers()).Servers[wId]; - var api = new MyMcAPI(world.OwnersToken); + var api = new MyMcAPI.Wrapper(world.OwnersToken); var ops = world.Ops; var player = world.Whitelist.Find(p => p.Uuid.Replace("-", "") == uuid); @@ -41,9 +40,9 @@ namespace Minecraft_Realms_Emulator.Controllers [HttpDelete("{wId}/{uuid}")] public async Task> DeopPlayerAsync(int wId, string uuid) { - var _api = new MyMcAPI(Environment.GetEnvironmentVariable("MYMC_API_KEY")); + var _api = new MyMcAPI.Wrapper(Environment.GetEnvironmentVariable("MYMC_API_KEY")); var world = (await _api.GetAllServers()).Servers[wId]; - var api = new MyMcAPI(world.OwnersToken); + var api = new MyMcAPI.Wrapper(world.OwnersToken); var ops = world.Ops; var player = world.Whitelist.Find(p => p.Uuid.Replace("-", "") == uuid); diff --git a/MyMcRealms/Controllers/WorldsController.cs b/MyMcRealms/Controllers/WorldsController.cs index a2f00e1..8a47c24 100644 --- a/MyMcRealms/Controllers/WorldsController.cs +++ b/MyMcRealms/Controllers/WorldsController.cs @@ -22,7 +22,7 @@ namespace MyMcRealms.Controllers List allWorlds = []; - AllServersResponse AllServers = await new MyMcAPI.MyMcAPI(Environment.GetEnvironmentVariable("MYMC_API_KEY")).GetAllServers(); + AllServersResponse AllServers = await new MyMcAPI.Wrapper(Environment.GetEnvironmentVariable("MYMC_API_KEY")).GetAllServers(); foreach (var world in AllServers.Servers) { @@ -83,7 +83,7 @@ namespace MyMcRealms.Controllers [HttpGet("{id}")] public async Task> GetWorldById(int id) { - var worlds = await new MyMcAPI.MyMcAPI(Environment.GetEnvironmentVariable("MYMC_API_KEY")).GetAllServers(); + var worlds = await new MyMcAPI.Wrapper(Environment.GetEnvironmentVariable("MYMC_API_KEY")).GetAllServers(); var world = worlds.Servers[id]; string worldOwnerName = world.Ops.ToArray().Length == 0 ? "Owner" : world.Ops[0].Name; @@ -134,10 +134,10 @@ namespace MyMcRealms.Controllers [HttpPut("{id}/open")] public async Task> Open(int id) { - var _api = new MyMcAPI.MyMcAPI(Environment.GetEnvironmentVariable("MYMC_API_KEY")); + var _api = new MyMcAPI.Wrapper(Environment.GetEnvironmentVariable("MYMC_API_KEY")); var world = (await _api.GetAllServers()).Servers[id]; - var api = new MyMcAPI.MyMcAPI(world.OwnersToken); + var api = new MyMcAPI.Wrapper(world.OwnersToken); if (world == null) return NotFound("World not found"); @@ -149,10 +149,10 @@ namespace MyMcRealms.Controllers [HttpPut("{id}/close")] public async Task> Close(int id) { - var _api = new MyMcAPI.MyMcAPI(Environment.GetEnvironmentVariable("MYMC_API_KEY")); + var _api = new MyMcAPI.Wrapper(Environment.GetEnvironmentVariable("MYMC_API_KEY")); var world = (await _api.GetAllServers()).Servers[id]; - var api = new MyMcAPI.MyMcAPI(world.OwnersToken); + var api = new MyMcAPI.Wrapper(world.OwnersToken); if (world == null) return NotFound("World not found"); @@ -164,7 +164,7 @@ namespace MyMcRealms.Controllers [HttpGet("v1/{wId}/join/pc")] public async Task> Join(int wId) { - AllServersResponse AllServers = await new MyMcAPI.MyMcAPI(Environment.GetEnvironmentVariable("MYMC_API_KEY")).GetAllServers(); + AllServersResponse AllServers = await new MyMcAPI.Wrapper(Environment.GetEnvironmentVariable("MYMC_API_KEY")).GetAllServers(); ConnectionResponse connection = new() { diff --git a/MyMcRealms/MyMcAPI/Responses/ConsoleResponse.cs b/MyMcRealms/MyMcAPI/Responses/ConsoleResponse.cs deleted file mode 100644 index 7889ff1..0000000 --- a/MyMcRealms/MyMcAPI/Responses/ConsoleResponse.cs +++ /dev/null @@ -1,9 +0,0 @@ - -namespace MyMcRealms.MyMcAPI.Responses -{ - public class ConsoleResponse - { - public bool Success { get; set; } - public string Message { get; set; } = null!; - } -} diff --git a/MyMcRealms/MyMcAPI/Responses/HelloResponse.cs b/MyMcRealms/MyMcAPI/Responses/HelloResponse.cs deleted file mode 100644 index f7a1086..0000000 --- a/MyMcRealms/MyMcAPI/Responses/HelloResponse.cs +++ /dev/null @@ -1,7 +0,0 @@ -namespace MyMcRealms.MyMcAPI.Responses -{ - public class HelloResponse - { - public string Message { get; set; } = string.Empty; - } -} diff --git a/MyMcRealms/MyMcAPI/Wrapper.cs b/MyMcRealms/MyMcAPI/Wrapper.cs index 7597f34..72a77ae 100644 --- a/MyMcRealms/MyMcAPI/Wrapper.cs +++ b/MyMcRealms/MyMcAPI/Wrapper.cs @@ -2,12 +2,12 @@ namespace MyMcRealms.MyMcAPI { - public class MyMcAPI + public class Wrapper { private readonly string ApiUrl = "https://api.my-mc.link"; private readonly HttpClient httpClient = new(); - public MyMcAPI(string apiKey) + public Wrapper(string apiKey) { httpClient.DefaultRequestHeaders.Add("x-my-mc-auth", apiKey); httpClient.BaseAddress = new Uri(ApiUrl); diff --git a/MyMcRealms/Responses/MinecraftPlayerInfo.cs b/MyMcRealms/Responses/MinecraftPlayerInfo.cs index 2198d10..d8e2d07 100644 --- a/MyMcRealms/Responses/MinecraftPlayerInfo.cs +++ b/MyMcRealms/Responses/MinecraftPlayerInfo.cs @@ -1,4 +1,4 @@ -namespace Minecraft_Realms_Emulator.Responses +namespace MyMcRealms.Responses { public class MinecraftPlayerInfo { diff --git a/MyMcRealms/Responses/OpsResponse.cs b/MyMcRealms/Responses/OpsResponse.cs index a443ce5..fd89d15 100644 --- a/MyMcRealms/Responses/OpsResponse.cs +++ b/MyMcRealms/Responses/OpsResponse.cs @@ -1,4 +1,4 @@ -namespace Minecraft_Realms_Emulator.Responses +namespace MyMcRealms.Responses { public class OpsResponse {