Skip to content

Commit ad6408b

Browse files
authored
Merge pull request #11 from HerrMagiic/dev
v1.0.8
2 parents 6c63b94 + 95811d1 commit ad6408b

31 files changed

+740
-422
lines changed

Diff for: .github/img/ColorsCS2.png

28.7 KB
Loading

Diff for: CustomCommands/Commands.example.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,12 @@
3939
"say hello"
4040
],
4141
"Permission": {
42-
"ReguiresAllPermissions": false,
42+
"RequiresAllPermissions": false,
4343
"PermissionList": [
4444
"@css/cvar",
4545
"@custom/permission",
4646
"#css/simple-admin"
4747
]
4848
}
4949
}
50-
]
50+
]

Diff for: CustomCommands/Commands/Others.example.json

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
[
2+
{
3+
"Title": "Discord",
4+
"Description": "Command for Discord",
5+
"Command": "discord",
6+
"Message": "{PREFIX}{GREEN}Discord: \n <link>",
7+
"PrintTo": 0
8+
},
9+
{
10+
"Title": "Steam",
11+
"Description": "Command for SteamGroup",
12+
"Command": "steam,steamgroup,group",
13+
"Message": "SteamGroup: <link>",
14+
"CenterMessage": {
15+
"Message": "<div>Steam Group</div><br><div><font color='#00ff00'>https...</font></div>",
16+
"Time": 10
17+
},
18+
"PrintTo": 7
19+
}
20+
]

Diff for: CustomCommands/Commands/ServerCommands.example.json

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
[
2+
{
3+
"Title": "Fast restart",
4+
"Command": "rg",
5+
"Message": [
6+
"Restarting game..."
7+
],
8+
"PrintTo": 0,
9+
"Description": "restarting game",
10+
"ServerCommands": [
11+
"mp_restartgame 1"
12+
],
13+
"Permission": {
14+
"RequiresAllPermissions": false,
15+
"PermissionList": [
16+
"@css/cvar",
17+
"@custom/permission",
18+
"#css/simple-admin"
19+
]
20+
}
21+
}
22+
]

Diff for: CustomCommands/CustomCommands.cs

+27-48
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,33 @@
1-
using CounterStrikeSharp.API;
2-
using CounterStrikeSharp.API.Core;
1+
using CounterStrikeSharp.API.Core;
32
using CounterStrikeSharp.API.Core.Attributes;
4-
using CounterStrikeSharp.API.Modules.Utils;
5-
using CustomCommands.Model;
3+
using CustomCommands.Interfaces;
64
using Microsoft.Extensions.Logging;
7-
using System.Text.Json;
85

96
namespace CustomCommands;
107

11-
[MinimumApiVersion(98)]
8+
[MinimumApiVersion(142)]
129
public partial class CustomCommands : BasePlugin, IPluginConfig<CustomCommandsConfig>
1310
{
1411
public override string ModuleName => "CustomCommands";
15-
public override string ModuleVersion => "1.0.7";
12+
public override string ModuleVersion => "1.0.8";
1613
public override string ModuleAuthor => "HerrMagic";
1714
public override string ModuleDescription => "Create your own commands per config";
1815

19-
private List<CenterClientElement> centerClientOn = new();
20-
private CenterServerElement centerServerOn = new();
21-
22-
private List<CCSPlayerController> PlayerList = new();
2316
public CustomCommandsConfig Config { get; set; } = new();
24-
private string PrefixCache = "";
17+
private readonly IRegisterCommands RegisterCommands;
18+
private readonly IPluginGlobals PluginGlobals;
19+
private readonly ILoadJson LoadJson;
20+
private readonly IEventManager EventManager;
21+
22+
public CustomCommands(IRegisterCommands RegisterCommands, ILogger<CustomCommands> Logger,
23+
IPluginGlobals PluginGlobals, ILoadJson LoadJson, IEventManager EventManager)
24+
{
25+
this.Logger = Logger;
26+
this.RegisterCommands = RegisterCommands;
27+
this.PluginGlobals = PluginGlobals;
28+
this.LoadJson = LoadJson;
29+
this.EventManager = EventManager;
30+
}
2531

2632
public void OnConfigParsed(CustomCommandsConfig config)
2733
{
@@ -32,52 +38,25 @@ public override void Load(bool hotReload)
3238
{
3339
if (!Config.IsPluginEnabled)
3440
{
35-
Console.WriteLine($"{Config.LogPrefix} {ModuleName} is disabled");
41+
Logger.LogInformation($"{Config.LogPrefix} {ModuleName} is disabled");
3642
return;
3743
}
38-
39-
Console.WriteLine(
44+
45+
Logger.LogInformation(
4046
$"CustomCommands has been loaded, and the hot reload flag was {hotReload}, path is {ModulePath}");
4147

42-
if (Config.Prefix != PrefixCache)
43-
PrefixCache = Config.Prefix;
48+
PluginGlobals.Config = Config;
4449

45-
var comms = LoadCommandsFromJson();
50+
var comms = LoadJson.LoadCommandsFromJson(ModuleDirectory);
4651

47-
RegisterListeners();
52+
EventManager.RegisterListeners();
4853

49-
5054
if (comms != null)
5155
{
52-
comms = CheckForDuplicateCommands(comms);
56+
comms = RegisterCommands.CheckForDuplicateCommands(comms);
57+
// Add commands from the JSON file to the server
5358
foreach (var com in comms)
54-
AddCommands(com);
59+
RegisterCommands.AddCommands(com);
5560
}
56-
57-
if (hotReload)
58-
InitializeLists();
59-
}
60-
61-
private List<Commands>? LoadCommandsFromJson()
62-
{
63-
string jsonPath = Path.Combine(ModuleDirectory, "Commands.json");
64-
if (File.Exists(jsonPath))
65-
{
66-
var json = File.ReadAllText(jsonPath);
67-
return JsonSerializer.Deserialize<List<Commands>>(json);
68-
}
69-
else
70-
{
71-
Logger.LogWarning("No Config file found. Please create one");
72-
return null;
73-
}
74-
}
75-
76-
private void InitializeLists()
77-
{
78-
Utilities.GetPlayers().ForEach(controller =>
79-
{
80-
PlayerList.Add(controller);
81-
});
8261
}
8362
}

Diff for: CustomCommands/CustomCommands.csproj

+6-2
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,14 @@
44
<TargetFramework>net7.0</TargetFramework>
55
<ImplicitUsings>enable</ImplicitUsings>
66
<Nullable>enable</Nullable>
7-
<!--<OutputPath>.</OutputPath>-->
87
<AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath>
98
<AppendRuntimeIdentifierToOutputPath>false</AppendRuntimeIdentifierToOutputPath>
109
<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
1110
</PropertyGroup>
1211

1312
<ItemGroup>
14-
<PackageReference Include="CounterStrikeSharp.API" Version="1.0.98" />
13+
<PackageReference Include="CounterStrikeSharp.API" Version="1.0.142" />
14+
<PackageReference Include="Scrutor" Version="4.2.2" />
1515
</ItemGroup>
1616

1717
<ItemGroup>
@@ -20,4 +20,8 @@
2020
</None>
2121
</ItemGroup>
2222

23+
<ItemGroup>
24+
<None Update="lang\**\*.*" CopyToOutputDirectory="PreserveNewest" />
25+
</ItemGroup>
26+
2327
</Project>

Diff for: CustomCommands/CustomCommandsServiceCollection.cs

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
2+
using CounterStrikeSharp.API.Core;
3+
using CustomCommands.Interfaces;
4+
using Microsoft.Extensions.DependencyInjection;
5+
6+
namespace CustomCommands;
7+
8+
public class CustomCommandsServiceCollection : IPluginServiceCollection<CustomCommands>
9+
{
10+
public void ConfigureServices(IServiceCollection services)
11+
{
12+
services.Scan(scan => scan
13+
.FromAssemblyOf<IPermissionsManager>()
14+
.AddClasses()
15+
.AsImplementedInterfaces()
16+
.WithSingletonLifetime()
17+
);
18+
}
19+
}

Diff for: CustomCommands/Events.cs

-24
This file was deleted.

0 commit comments

Comments
 (0)