mirror of
https://github.com/CyberL1/MyMcRealms.git
synced 2024-11-21 13:38:21 -05:00
chore: more cleanup
This commit is contained in:
parent
152ad2c0dc
commit
d502f2d0f4
@ -24,18 +24,18 @@ namespace MyMcRealms.Controllers
|
||||
if (world == null) return NotFound("World not found");
|
||||
|
||||
// Get player name
|
||||
var playerInfo = await new HttpClient().GetFromJsonAsync<MinecraftPlayerInfo>($"https://api.mojang.com/users/profiles/minecraft/{body.Name}");
|
||||
var playerInfo = await new HttpClient().GetFromJsonAsync<MinecraftPlayerResponse>($"https://api.mojang.com/users/profiles/minecraft/{body.Name}");
|
||||
|
||||
if (world.Whitelist.Any(p => p.Name == body.Name)) return BadRequest("Player already whitelisted");
|
||||
|
||||
var api = new MyMcAPI.Wrapper(world.OwnersToken);
|
||||
api.ExecuteCommand($"whitelist add {body.Name}");
|
||||
|
||||
List<Player> whitelistedPlayers = [];
|
||||
List<PlayerResponse> whitelistedPlayers = [];
|
||||
|
||||
foreach (var player in world.Whitelist)
|
||||
{
|
||||
Player whitelistedPlayer = new()
|
||||
PlayerResponse whitelistedPlayer = new()
|
||||
{
|
||||
Name = player.Name,
|
||||
Uuid = player.Uuid,
|
||||
@ -48,7 +48,7 @@ namespace MyMcRealms.Controllers
|
||||
whitelistedPlayers.Add(whitelistedPlayer);
|
||||
}
|
||||
|
||||
Player npl = new()
|
||||
PlayerResponse npl = new()
|
||||
{
|
||||
Name = body.Name,
|
||||
Uuid = playerInfo.Id,
|
||||
@ -96,7 +96,7 @@ namespace MyMcRealms.Controllers
|
||||
var player = world.Whitelist.Find(p => p.Uuid.Replace("-", "") == uuid);
|
||||
|
||||
// Get player name
|
||||
var playerInfo = await new HttpClient().GetFromJsonAsync<MinecraftPlayerInfo>($"https://sessionserver.mojang.com/session/minecraft/profile/{uuid}");
|
||||
var playerInfo = await new HttpClient().GetFromJsonAsync<MinecraftPlayerResponse>($"https://sessionserver.mojang.com/session/minecraft/profile/{uuid}");
|
||||
|
||||
if (!world.Whitelist.Any(p => p.Uuid.Replace("-", "") == uuid)) return BadRequest("Player not whitelisted");
|
||||
|
||||
|
@ -89,11 +89,11 @@ namespace MyMcRealms.Controllers
|
||||
string worldOwnerName = world.Ops.ToArray().Length == 0 ? "Owner" : world.Ops[0].Name;
|
||||
string worldOwnerUuid = world.Ops.ToArray().Length == 0 ? "069a79f444e94726a5befca90e38aaf5" : world.Ops[0].Uuid;
|
||||
string worldName = world.Ops.ToArray().Length == 0 ? world.ServerName : $"{world.Ops[0].Name}'s server";
|
||||
List<Player> whitelistedPlayers = [];
|
||||
List<PlayerResponse> whitelistedPlayers = [];
|
||||
|
||||
foreach (var player in world.Whitelist)
|
||||
{
|
||||
Player whitelistedPlayer = new()
|
||||
PlayerResponse whitelistedPlayer = new()
|
||||
{
|
||||
Name = player.Name,
|
||||
Uuid = player.Uuid,
|
||||
|
@ -2,12 +2,6 @@
|
||||
{
|
||||
public class PlayerRequest
|
||||
{
|
||||
public int Id { get; set; }
|
||||
public string Name { get; set; } = string.Empty;
|
||||
public string Uuid { get; set; } = string.Empty;
|
||||
public bool Operator { get; set; }
|
||||
public bool Accepted { get; set; }
|
||||
public bool Online { get; set; }
|
||||
public string Permission { get; set; } = "MEMBER";
|
||||
}
|
||||
}
|
||||
|
@ -1,8 +0,0 @@
|
||||
namespace MyMcRealms.Requests
|
||||
{
|
||||
public class WorldCreateRequest
|
||||
{
|
||||
public string? Name { get; set; }
|
||||
public string? Description { get; set; }
|
||||
}
|
||||
}
|
@ -1,6 +1,6 @@
|
||||
namespace MyMcRealms.Responses
|
||||
{
|
||||
public class MinecraftPlayerInfo
|
||||
public class MinecraftPlayerResponse
|
||||
{
|
||||
public string Id { get; set; } = string.Empty;
|
||||
public string Name { get; set; } = string.Empty;
|
12
MyMcRealms/Responses/PlayerResponse.cs
Normal file
12
MyMcRealms/Responses/PlayerResponse.cs
Normal file
@ -0,0 +1,12 @@
|
||||
namespace MyMcRealms.Responses
|
||||
{
|
||||
public class PlayerResponse
|
||||
{
|
||||
public string Name { get; set; } = string.Empty;
|
||||
public string Uuid { get; set; } = string.Empty;
|
||||
public bool Operator { get; set; }
|
||||
public bool Accepted { get; set; }
|
||||
public bool Online { get; set; }
|
||||
public string Permission { get; set; } = "MEMBER";
|
||||
}
|
||||
}
|
@ -12,7 +12,7 @@ namespace MyMcRealms.Responses
|
||||
public string? Motd { get; set; }
|
||||
public string State { get; set; } = "OPEN";
|
||||
public string WorldType { get; set; } = "NORMAL";
|
||||
public List<Player> Players { get; set; } = [];
|
||||
public List<PlayerResponse> Players { get; set; } = [];
|
||||
public int MaxPlayers { get; set; } = 10;
|
||||
public string? MinigameName { get; set; }
|
||||
public int? MinigameId { get; set; }
|
||||
@ -27,14 +27,4 @@ namespace MyMcRealms.Responses
|
||||
public string Compatibility { get; set; } = string.Empty;
|
||||
public string ActiveVersion { get; set; } = string.Empty;
|
||||
}
|
||||
|
||||
public class Player
|
||||
{
|
||||
public string Name { get; set; } = string.Empty;
|
||||
public string Uuid { get; set; } = string.Empty;
|
||||
public bool Operator { get; set; }
|
||||
public bool Accepted { get; set; }
|
||||
public bool Online { get; set; }
|
||||
public string Permission { get; set; } = "MEMBER";
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user