From 8d3da5e3a25b2ba559f4168691a155a0a3fa1481 Mon Sep 17 00:00:00 2001 From: RisaDev <151885272+RisaDev@users.noreply.github.com> Date: Wed, 23 Oct 2024 23:19:48 +0300 Subject: [PATCH] Fix commands --- CustomizePlus/Core/Services/CommandService.cs | 70 ++++++++++++------- 1 file changed, 44 insertions(+), 26 deletions(-) diff --git a/CustomizePlus/Core/Services/CommandService.cs b/CustomizePlus/Core/Services/CommandService.cs index 8b8c770..285c182 100644 --- a/CustomizePlus/Core/Services/CommandService.cs +++ b/CustomizePlus/Core/Services/CommandService.cs @@ -186,14 +186,15 @@ public class CommandService : IDisposable if (!isTurningOffAllProfiles) { profileName = subArgumentList[1].Trim(); - foreach(var profile in _profileManager.Profiles) + foreach (var profile in _profileManager.Profiles) { if (!profile.Characters.Any(x => x.ToNameWithoutOwnerName() == characterName)) continue; if (profile.Name != profileName) { - profilesToDisable.Add(profile); + if(profile.Enabled) + profilesToDisable.Add(profile); continue; } @@ -203,7 +204,7 @@ public class CommandService : IDisposable else profilesToDisable = _profileManager.Profiles.Where(x => x.Characters.Any(x => x.ToNameWithoutOwnerName() == characterName) && x.Enabled).ToList(); - if (targetProfile == null || (isTurningOffAllProfiles && profilesToDisable.Count == 0)) + if((!isTurningOffAllProfiles && targetProfile == null) || (isTurningOffAllProfiles && profilesToDisable.Count == 0)) { _chatService.PrintInChat(new SeStringBuilder() .AddText("Cannot execute command because profile ") @@ -214,39 +215,56 @@ public class CommandService : IDisposable return; } - if (state != null) + if(!isTurningOffAllProfiles) { - if(targetProfile.Enabled == state) + if (state != null) { - _chatService.PrintInChat(new SeStringBuilder() - .AddText("Profile ") - .AddYellow(targetProfile.Name) - .AddText(" for ") - .AddBlue(characterName) - .AddText(" is already ") - .AddGreen((bool)state ? "enabled" : "disabled").BuiltString); - return; + if (targetProfile!.Enabled == state) + { + _chatService.PrintInChat(new SeStringBuilder() + .AddText("Profile ") + .AddYellow(targetProfile.Name) + .AddText(" for ") + .AddBlue(characterName) + .AddText(" is already ") + .AddGreen((bool)state ? "enabled" : "disabled").BuiltString); + return; + } + + _profileManager.SetEnabled(targetProfile, (bool)state); } - - _profileManager.SetEnabled(targetProfile, (bool)state); + else + _profileManager.SetEnabled(targetProfile!, !targetProfile!.Enabled); } - else - _profileManager.SetEnabled(targetProfile, !targetProfile.Enabled); - - if(targetProfile.Enabled) + + if (isTurningOffAllProfiles || targetProfile!.Enabled) { foreach (var profile in profilesToDisable) _profileManager.SetEnabled(profile, false); } if (_pluginConfiguration.CommandSettings.PrintSuccessMessages) - _chatService.PrintInChat(new SeStringBuilder() - .AddText("Profile ") - .AddYellow(targetProfile.Name) - .AddText(" was successfully ") - .AddBlue(state != null ? ((bool)state ? "enabled" : "disabled") : "toggled") - .AddText(" for ") - .AddRed(string.Join(',', targetProfile.Characters.Select(x => x.ToNameWithoutOwnerName()))).BuiltString); + { + if (isTurningOffAllProfiles) + _chatService.PrintInChat(new SeStringBuilder() + .AddYellow($"{profilesToDisable.Count} profile(s)") + .AddText(" successfully ") + .AddBlue("disabled") + .AddText(" for ") + .AddRed(characterName).BuiltString); + else + _chatService.PrintInChat(new SeStringBuilder() + .AddText("Profile ") + .AddYellow(targetProfile!.Name) + .AddText(" was successfully ") + .AddBlue(state != null ? ((bool)state ? "enabled" : "disabled") : "toggled") + .AddText(" for ") + .AddRed(string.Join(',', targetProfile.Characters.Select(x => x.ToNameWithoutOwnerName()))) + .AddText(". ") + .AddItalics($"({profilesToDisable.Count} profile(s) disabled)") + .BuiltString); + } + } catch (Exception e) {