diff --git a/ReallifeGamemode.Server/Commands/AdminCommands.cs b/ReallifeGamemode.Server/Commands/AdminCommands.cs index 07d94fe1..e800c7b5 100644 --- a/ReallifeGamemode.Server/Commands/AdminCommands.cs +++ b/ReallifeGamemode.Server/Commands/AdminCommands.cs @@ -2432,7 +2432,7 @@ namespace ReallifeGamemode.Server.Commands ChatService.SendMessage(player, "~b~[ADMIN]~s~ Die Türen wurden erfolgreich neugeladen."); } - [Command("house", "~m~Benutzung: ~s~/house [add / remove / price / type]", GreedyArg = true)] + [Command("house", "~m~Benutzung: ~s~/house [add / remove / price / type / reloadhouses]", GreedyArg = true)] public void CmdAdminHouse(Client player, string option1, string option2 = null) { if (!player.GetUser()?.IsAdmin(AdminLevel.HEADADMIN) ?? true) @@ -2550,8 +2550,13 @@ namespace ReallifeGamemode.Server.Commands return; } + else if(option1 == "reloadhouses") + { + HouseManager.ReloadAllHouses(); + player.SendNotification("Alle Häuser wurden neu geladen"); + } - player.SendChatMessage("~m~Benutzung: ~s~/house [add / remove / price / type]"); + player.SendChatMessage("~m~Benutzung: ~s~/house [add / remove / price / type / reloadhouses]"); } #endregion diff --git a/ReallifeGamemode.Server/Extensions/HouseExtensions.cs b/ReallifeGamemode.Server/Extensions/HouseExtensions.cs new file mode 100644 index 00000000..b9edd7cb --- /dev/null +++ b/ReallifeGamemode.Server/Extensions/HouseExtensions.cs @@ -0,0 +1,21 @@ +using Microsoft.EntityFrameworkCore; +using ReallifeGamemode.Server.Entities; +using ReallifeGamemode.Server.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace ReallifeGamemode.Server.Extensions +{ + static class HouseExtensions + { + public static House Refresh(this House house) + { + using(var dbContext = new DatabaseContext()) + { + return dbContext.Houses.Where(h => h.Id == house.Id).Include(h => h.User).FirstOrDefault(); + } + } + } +} diff --git a/ReallifeGamemode.Server/Managers/HouseManager.cs b/ReallifeGamemode.Server/Managers/HouseManager.cs index 7d0d600d..fcde9f25 100644 --- a/ReallifeGamemode.Server/Managers/HouseManager.cs +++ b/ReallifeGamemode.Server/Managers/HouseManager.cs @@ -14,6 +14,7 @@ namespace ReallifeGamemode.Server.Managers { private static readonly Dictionary houseMarkers = new Dictionary(); private static readonly Dictionary houseLabels = new Dictionary(); + private static readonly Dictionary houseColShapes = new Dictionary(); public static void LoadHouses() { @@ -21,7 +22,19 @@ namespace ReallifeGamemode.Server.Managers { foreach (House house in dbContext.Houses.Include(h => h.User)) { - LoadHouse(house); + LoadHouse(house, false); + } + } + } + + public async static void ReloadAllHouses() + { + using (var dbContext = new DatabaseContext()) + { + foreach(House house in await dbContext.Houses.Include(h => h.User).ToListAsync()) + { + RemoveHouse(house); + LoadHouse(house, false); } } } @@ -61,8 +74,10 @@ namespace ReallifeGamemode.Server.Managers } } - public static void LoadHouse(House house) + public static void LoadHouse(House house, bool loadUser = true) { + if (loadUser) house = house.Refresh(); + houseMarkers[house.Id] = NAPI.Marker.CreateMarker(MarkerType.VerticalCylinder, house.Position.Subtract(new Vector3(0, 0, 1.7)), new Vector3(), new Vector3(), 1.6f, new Color(255, 255, 255)); string text = $"~g~Zum Verkauf\n~s~{house.Type}\nPreis: ~y~{house.Price.ToMoneyString()}"; if(house.User != null) @@ -74,11 +89,17 @@ namespace ReallifeGamemode.Server.Managers public static void RemoveHouse(House house) { - houseMarkers[house.Id].Entity().Delete(); - houseLabels[house.Id].Entity().Delete(); + if (houseMarkers.ContainsKey(house.Id)) + { + houseMarkers[house.Id].Entity().Delete(); + houseMarkers.Remove(house.Id); + } - houseMarkers.Remove(house.Id); - houseLabels.Remove(house.Id); + if(houseLabels.ContainsKey(house.Id)) + { + houseLabels[house.Id].Entity().Delete(); + houseLabels.Remove(house.Id); + } } } }