Skip to content

Commit 78bed95

Browse files
committed
fixing args not working
1 parent 9f02b60 commit 78bed95

File tree

2 files changed

+54
-55
lines changed

2 files changed

+54
-55
lines changed

CustomCommands/CustomCommands.cs

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,32 +2,31 @@
22
using CounterStrikeSharp.API.Core.Attributes;
33
using CustomCommands.Interfaces;
44
using Microsoft.Extensions.Logging;
5-
using System.Text.Json;
65

76
namespace CustomCommands;
87

98
[MinimumApiVersion(213)]
109
public partial class CustomCommands : BasePlugin, IPluginConfig<CustomCommandsConfig>
1110
{
1211
public override string ModuleName => "CustomCommands";
13-
public override string ModuleVersion => "2.2.0";
12+
public override string ModuleVersion => "2.3.0";
1413
public override string ModuleAuthor => "HerrMagic";
1514
public override string ModuleDescription => "Create your own commands per config";
1615

1716
public CustomCommandsConfig Config { get; set; } = new();
18-
private readonly IRegisterCommands RegisterCommands;
19-
private readonly IPluginGlobals PluginGlobals;
20-
private readonly ILoadJson LoadJson;
21-
private readonly IEventManager EventManager;
17+
private readonly IRegisterCommands _registerCommands;
18+
private readonly IPluginGlobals _pluginGlobals;
19+
private readonly ILoadJson _loadJson;
20+
private readonly IEventManager _eventManager;
2221

2322
public CustomCommands(IRegisterCommands RegisterCommands, ILogger<CustomCommands> Logger,
2423
IPluginGlobals PluginGlobals, ILoadJson LoadJson, IEventManager EventManager)
2524
{
2625
this.Logger = Logger;
27-
this.RegisterCommands = RegisterCommands;
28-
this.PluginGlobals = PluginGlobals;
29-
this.LoadJson = LoadJson;
30-
this.EventManager = EventManager;
26+
_registerCommands = RegisterCommands;
27+
_pluginGlobals = PluginGlobals;
28+
_loadJson = LoadJson;
29+
_eventManager = EventManager;
3130
}
3231

3332
public void OnConfigParsed(CustomCommandsConfig config)
@@ -46,28 +45,28 @@ public override void Load(bool hotReload)
4645
Logger.LogInformation(
4746
$"{ModuleName} loaded!");
4847

49-
PluginGlobals.Config = Config;
48+
_pluginGlobals.Config = Config;
5049

51-
var comms = LoadJson.GetCommandsFromJsonFiles(ModuleDirectory);
50+
var comms = Task.Run(async () => await _loadJson.GetCommandsFromJsonFiles(ModuleDirectory)).Result;
5251

5352
if (comms == null)
5453
{
5554
Logger.LogError("No commands found please create a config file");
5655
return;
5756
}
5857

59-
EventManager.RegisterListeners();
58+
_eventManager.RegisterListeners();
6059

6160
if (comms != null)
6261
{
63-
PluginGlobals.CustomCommands = comms;
62+
_pluginGlobals.CustomCommands = comms;
6463

65-
RegisterCommands.CheckForDuplicateCommands();
66-
RegisterCommands.ConvertingCommandsForRegister();
64+
_registerCommands.CheckForDuplicateCommands();
65+
_registerCommands.ConvertingCommandsForRegister();
6766

6867
// Add commands from the JSON file to the server
69-
foreach (var cmd in PluginGlobals.CustomCommands)
70-
RegisterCommands.AddCommands(cmd);
68+
foreach (var cmd in _pluginGlobals.CustomCommands)
69+
_registerCommands.AddCommands(cmd);
7170
}
7271
}
7372
}

CustomCommands/Services/RegisterCommands.cs

Lines changed: 37 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -7,33 +7,33 @@
77
namespace CustomCommands.Services;
88
public class RegisterCommands : IRegisterCommands
99
{
10-
private readonly ILogger<CustomCommands> Logger;
11-
private readonly IMessageManager MessageManager;
12-
private readonly IPluginGlobals PluginGlobals;
13-
private readonly PluginContext PluginContext;
14-
private readonly IPluginUtilities PluginUtilities;
15-
private readonly ICooldownManager CooldownManager;
10+
private readonly ILogger<CustomCommands> _logger;
11+
private readonly IMessageManager _messageManager;
12+
private readonly IPluginGlobals _pluginGlobals;
13+
private readonly PluginContext _pluginContext;
14+
private readonly IPluginUtilities _pluginUtilities;
15+
private readonly ICooldownManager _cooldownManager;
1616

1717
public RegisterCommands(ILogger<CustomCommands> Logger, IMessageManager MessageManager,
1818
IPluginGlobals PluginGlobals, IPluginContext PluginContext,
1919
IPluginUtilities PluginUtilities, ICooldownManager CooldownManager)
2020
{
21-
this.Logger = Logger;
22-
this.MessageManager = MessageManager;
23-
this.PluginGlobals = PluginGlobals;
24-
this.PluginContext = (PluginContext as PluginContext)!;
25-
this.PluginUtilities = PluginUtilities;
26-
this.CooldownManager = CooldownManager;
21+
_logger = Logger;
22+
_messageManager = MessageManager;
23+
_pluginGlobals = PluginGlobals;
24+
_pluginContext = (PluginContext as PluginContext)!;
25+
_pluginUtilities = PluginUtilities;
26+
_cooldownManager = CooldownManager;
2727
}
2828

2929
public void AddCommands(Commands cmd)
3030
{
3131
if (!cmd.IsRegisterable)
3232
return;
3333

34-
var pluginContext = (PluginContext.Plugin as CustomCommands)!;
35-
36-
pluginContext.AddCommand(cmd.Command, cmd.Description,
34+
var context = (_pluginContext.Plugin as CustomCommands)!;
35+
36+
context.AddCommand(cmd.Command, cmd.Description,
3737
[CommandHelper(whoCanExecute: CommandUsage.CLIENT_ONLY)]
3838
(player, info) =>
3939
{
@@ -45,7 +45,7 @@ public void AddCommands(Commands cmd)
4545
// Check if the command has arguments and if it does, check if the command exists and is the right one
4646
if (info.ArgCount > 1)
4747
{
48-
var findcommand = PluginGlobals.CustomCommands.Find(x => x.Command == command.Command && x.Argument == info.ArgString);
48+
var findcommand = _pluginGlobals.CustomCommands.Find(x => x.Command == command.Command && x.Argument == info.ArgString);
4949
// Check if the command is the right one with the right arguments
5050
if (findcommand is null)
5151
{
@@ -71,32 +71,32 @@ public void AddCommands(Commands cmd)
7171

7272
// Check if the player has the permission to use the command
7373
if (command!.Permission?.PermissionList.Count > 0 && command.Permission != null)
74-
if (!PluginUtilities.RequiresPermissions(player, command.Permission))
74+
if (!_pluginUtilities.RequiresPermissions(player, command.Permission))
7575
return;
7676

7777
// Check if the command is on cooldown
78-
if(CooldownManager.IsCommandOnCooldown(player, command)) return;
78+
if(_cooldownManager.IsCommandOnCooldown(player, command)) return;
7979

8080
// Set the cooldown for the command if it has a cooldown set
81-
CooldownManager.SetCooldown(player, command);
81+
_cooldownManager.SetCooldown(player, command);
8282

8383
// Sending the message to the player
84-
MessageManager.SendMessage(player, command);
85-
86-
// Execute the server commands
87-
PluginUtilities.ExecuteServerCommands(command, player);
84+
_messageManager.SendMessage(player, command);
8885

8986
// Execute the client commands
90-
PluginUtilities.ExecuteClientCommands(command, player);
87+
_pluginUtilities.ExecuteClientCommands(command, player);
9188

9289
// Execute the client commands from the server
93-
PluginUtilities.ExecuteClientCommandsFromServer(command, player);
90+
_pluginUtilities.ExecuteClientCommandsFromServer(command, player);
91+
92+
// Execute the server commands
93+
_pluginUtilities.ExecuteServerCommands(command, player);
9494
});
9595
}
9696

9797
public void CheckForDuplicateCommands()
9898
{
99-
var comms = PluginGlobals.CustomCommands;
99+
var comms = _pluginGlobals.CustomCommands;
100100
var duplicateCommands = new List<Commands>();
101101
var commandNames = new List<string>();
102102

@@ -119,32 +119,32 @@ public void CheckForDuplicateCommands()
119119
return;
120120

121121
// Log the duplicate commands
122-
Logger.LogError($"------------------------------------------------------------------------");
123-
Logger.LogError($"{PluginGlobals.Config.LogPrefix} Duplicate commands found, removing them from the list. Please check your config file for duplicate commands and remove them.");
122+
_logger.LogError($"------------------------------------------------------------------------");
123+
_logger.LogError($"{_pluginGlobals.Config.LogPrefix} Duplicate commands found, removing them from the list. Please check your config file for duplicate commands and remove them.");
124124
for (int i = 0; i < comms.Count; i++)
125125
{
126126
if(duplicateCommands.Contains(comms[i]))
127127
{
128-
Logger.LogError($"{PluginGlobals.Config.LogPrefix} Duplicate command found index {i+1}: ");
129-
Logger.LogError($"{PluginGlobals.Config.LogPrefix} - {comms[i].Title} ");
130-
Logger.LogError($"{PluginGlobals.Config.LogPrefix} - {comms[i].Description}");
131-
Logger.LogError($"{PluginGlobals.Config.LogPrefix} - {comms[i].Command}");
128+
_logger.LogError($"{_pluginGlobals.Config.LogPrefix} Duplicate command found index {i+1}: ");
129+
_logger.LogError($"{_pluginGlobals.Config.LogPrefix} - {comms[i].Title} ");
130+
_logger.LogError($"{_pluginGlobals.Config.LogPrefix} - {comms[i].Description}");
131+
_logger.LogError($"{_pluginGlobals.Config.LogPrefix} - {comms[i].Command}");
132132
continue;
133133
}
134134

135135
comms.Add(comms[i]);
136136
}
137-
Logger.LogError($"------------------------------------------------------------------------");
137+
_logger.LogError($"------------------------------------------------------------------------");
138138
}
139139

140140
public void ConvertingCommandsForRegister()
141141
{
142142
var newCmds = new List<Commands>();
143143

144-
foreach (var cmd in PluginGlobals.CustomCommands)
144+
foreach (var cmd in _pluginGlobals.CustomCommands)
145145
{
146-
var splitCommands = PluginUtilities.SplitStringByCommaOrSemicolon(cmd.Command);
147-
splitCommands = PluginUtilities.AddCSSTagsToAliases(splitCommands.ToList());
146+
var splitCommands = _pluginUtilities.SplitStringByCommaOrSemicolon(cmd.Command);
147+
splitCommands = _pluginUtilities.AddCSSTagsToAliases(splitCommands.ToList());
148148

149149
foreach (var split in splitCommands)
150150
{
@@ -173,6 +173,6 @@ public void ConvertingCommandsForRegister()
173173
}
174174
}
175175

176-
PluginGlobals.CustomCommands = newCmds;
176+
_pluginGlobals.CustomCommands = newCmds;
177177
}
178178
}

0 commit comments

Comments
 (0)