From dd2e36c9146456f9ccd97459d6796e922f9f9c95 Mon Sep 17 00:00:00 2001 From: CWX Date: Sat, 18 Jan 2025 13:51:53 +0000 Subject: [PATCH] use prim ctor and fixed warnings: TradeCallbacks, TraderCallbacks, WeatherCallbacks, WishlistCallbacks --- Core/Callbacks/TradeCallbacks.cs | 12 +--------- Core/Callbacks/TraderCallbacks.cs | 37 ++++++++++------------------- Core/Callbacks/WeatherCallbacks.cs | 21 ++++------------ Core/Callbacks/WishlistCallbacks.cs | 12 +--------- 4 files changed, 18 insertions(+), 64 deletions(-) diff --git a/Core/Callbacks/TradeCallbacks.cs b/Core/Callbacks/TradeCallbacks.cs index 9bbaf4e0..697b4c36 100644 --- a/Core/Callbacks/TradeCallbacks.cs +++ b/Core/Callbacks/TradeCallbacks.cs @@ -7,18 +7,8 @@ using Core.Models.Eft.Trade; namespace Core.Callbacks; [Injectable] -public class TradeCallbacks +public class TradeCallbacks(TradeController _tradeController) { - protected TradeController _tradeController; - - public TradeCallbacks - ( - TradeController tradeController - ) - { - _tradeController = tradeController; - } - /// /// Handle client/game/profile/items/moving TradingConfirm event /// diff --git a/Core/Callbacks/TraderCallbacks.cs b/Core/Callbacks/TraderCallbacks.cs index cf63b8d8..06807886 100644 --- a/Core/Callbacks/TraderCallbacks.cs +++ b/Core/Callbacks/TraderCallbacks.cs @@ -2,9 +2,6 @@ using Core.Controllers; using Core.DI; using Core.Models.Eft.Common; -using Core.Models.Eft.Common.Tables; -using Core.Models.Eft.HttpResponse; -using Core.Models.Enums; using Core.Models.Spt.Config; using Core.Servers; using Core.Utils; @@ -14,32 +11,23 @@ namespace Core.Callbacks; [Injectable(InjectableTypeOverride = typeof(OnLoad), TypePriority = OnLoadOrder.TraderCallbacks)] [Injectable(InjectableTypeOverride = typeof(OnUpdate), TypePriority = OnUpdateOrder.TraderCallbacks)] [Injectable(InjectableTypeOverride = typeof(TraderCallbacks))] -public class TraderCallbacks : OnLoad, OnUpdate +public class TraderCallbacks( + HttpResponseUtil _httpResponseUtil, + TraderController _traderController, + ConfigServer _configServer +) : OnLoad, OnUpdate { - protected HttpResponseUtil _httpResponseUtil; - protected TraderController _traderController; - protected ConfigServer _configServer; - - public TraderCallbacks - ( - HttpResponseUtil httpResponseUtil, - TraderController traderController, - ConfigServer configServer - ) - { - _httpResponseUtil = httpResponseUtil; - _traderController = traderController; - _configServer = configServer; - } - - public async Task OnLoad() + private readonly TraderConfig _traderConfig = _configServer.GetConfig(); + + public Task OnLoad() { _traderController.Load(); + return Task.CompletedTask; } - public async Task OnUpdate(long _) + public Task OnUpdate(long _) { - return _traderController.Update(); + return Task.FromResult(_traderController.Update()); } public string GetRoute() @@ -94,7 +82,6 @@ public class TraderCallbacks : OnLoad, OnUpdate /// public string GetModdedTraderData(string url, EmptyRequestData info, string sessionID) { - var traderConfig = _configServer.GetConfig(); - return _httpResponseUtil.NoBody(traderConfig.ModdedTraders); + return _httpResponseUtil.NoBody(_traderConfig.ModdedTraders); } } diff --git a/Core/Callbacks/WeatherCallbacks.cs b/Core/Callbacks/WeatherCallbacks.cs index e118e51f..ce3339b6 100644 --- a/Core/Callbacks/WeatherCallbacks.cs +++ b/Core/Callbacks/WeatherCallbacks.cs @@ -1,29 +1,16 @@ using Core.Annotations; using Core.Controllers; using Core.Models.Eft.Common; -using Core.Models.Eft.HttpResponse; -using Core.Models.Eft.Weather; -using Core.Models.Spt.Weather; using Core.Utils; namespace Core.Callbacks; [Injectable] -public class WeatherCallbacks +public class WeatherCallbacks( + HttpResponseUtil _httpResponseUtil, + WeatherController _weatherController +) { - protected HttpResponseUtil _httpResponseUtil; - protected WeatherController _weatherController; - - public WeatherCallbacks - ( - HttpResponseUtil httpResponseUtil, - WeatherController weatherController - ) - { - _httpResponseUtil = httpResponseUtil; - _weatherController = weatherController; - } - /// /// Handle client/weather /// diff --git a/Core/Callbacks/WishlistCallbacks.cs b/Core/Callbacks/WishlistCallbacks.cs index 4af8d259..b9f68a31 100644 --- a/Core/Callbacks/WishlistCallbacks.cs +++ b/Core/Callbacks/WishlistCallbacks.cs @@ -7,18 +7,8 @@ using Core.Models.Eft.Wishlist; namespace Core.Callbacks; [Injectable] -public class WishlistCallbacks +public class WishlistCallbacks(WishlistController _wishlistController) { - protected WishlistController _wishlistController; - - public WishlistCallbacks - ( - WishlistController wishlistController - ) - { - _wishlistController = wishlistController; - } - /// /// Handle AddToWishList event ///