Skip to content

Commit 3ac9273

Browse files
committed
NullReferenceException
1 parent 2050c77 commit 3ac9273

15 files changed

+88
-26
lines changed

CustomCommands/Commands.example.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
"say hello"
4040
],
4141
"Permission": {
42-
"ReguiresAllPermissions": false,
42+
"RequiresAllPermissions": false,
4343
"PermissionList": [
4444
"@css/cvar",
4545
"@custom/permission",
Lines changed: 20 additions & 0 deletions
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+
]
Lines changed: 22 additions & 0 deletions
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+
]

CustomCommands/CustomCommands.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
using CounterStrikeSharp.API.Core;
22
using CounterStrikeSharp.API.Core.Attributes;
3-
using CustomCommands.Services;
3+
using CustomCommands.Interfaces;
44
using Microsoft.Extensions.Logging;
55

66
namespace CustomCommands;
77

8-
[MinimumApiVersion(98)]
8+
[MinimumApiVersion(142)]
99
public partial class CustomCommands : BasePlugin, IPluginConfig<CustomCommandsConfig>
1010
{
1111
public override string ModuleName => "CustomCommands";

CustomCommands/CustomCommands.csproj

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@
1010
</PropertyGroup>
1111

1212
<ItemGroup>
13-
<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" />
1415
</ItemGroup>
1516

1617
<ItemGroup>
Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11

22
using CounterStrikeSharp.API.Core;
3-
using CustomCommands.Services;
43
using CustomCommands.Interfaces;
54
using Microsoft.Extensions.DependencyInjection;
65

@@ -10,12 +9,11 @@ public class CustomCommandsServiceCollection : IPluginServiceCollection<CustomCo
109
{
1110
public void ConfigureServices(IServiceCollection services)
1211
{
13-
services.AddSingleton<IMessageManager, MessageManager>();
14-
services.AddSingleton<IReplaceTagsFunctions, ReplaceTagsFunctions>();
15-
services.AddSingleton<IRegisterCommands, RegisterCommands>();
16-
services.AddSingleton<IPluginGlobals, PluginGlobals>();
17-
services.AddSingleton<ILoadJson, LoadJson>();
18-
services.AddSingleton<IPermissionsManager, PermissionsManager>();
19-
services.AddSingleton<IEventManager, EventManager>();
12+
services.Scan(scan => scan
13+
.FromAssemblyOf<IPermissionsManager>()
14+
.AddClasses()
15+
.AsImplementedInterfaces()
16+
.WithSingletonLifetime()
17+
);
2018
}
2119
}

CustomCommands/Model/CommandsConfig.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ public class Commands
1313
}
1414
public class Permission
1515
{
16-
public bool ReguiresAllPermissions { get; set; } = false;
16+
public bool RequiresAllPermissions { get; set; } = false;
1717
public List<string> PermissionList { get; set; } = new();
1818
}
1919
public class CenterElement

CustomCommands/Services/EventManager.cs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,20 @@
44
using CounterStrikeSharp.API.Core.Attributes.Registration;
55
using CounterStrikeSharp.API.Core.Plugin;
66
using CustomCommands.Interfaces;
7+
using Microsoft.Extensions.Logging;
78

89
namespace CustomCommands.Services;
910

1011
public class EventManager : IEventManager
1112
{
1213
private readonly IPluginGlobals PluginGlobals;
13-
private readonly CustomCommands PluginContext;
14+
private readonly PluginContext PluginContext;
1415
private readonly IReplaceTagsFunctions ReplaceTagsFunctions;
1516

1617
public EventManager(IPluginGlobals PluginGlobals, IPluginContext PluginContext, IReplaceTagsFunctions ReplaceTagsFunctions)
1718
{
1819
this.PluginGlobals = PluginGlobals;
19-
this.PluginContext = ((PluginContext as PluginContext)!.Plugin as CustomCommands)!;
20+
this.PluginContext = (PluginContext as PluginContext)!;
2021
this.ReplaceTagsFunctions = ReplaceTagsFunctions;
2122
}
2223

@@ -30,7 +31,8 @@ public HookResult OnPlayerDisconnect(EventPlayerDisconnect @event, GameEventInfo
3031

3132
public void RegisterListeners()
3233
{
33-
PluginContext.RegisterListener<Listeners.OnTick>(() =>
34+
CustomCommands plugin = (PluginContext.Plugin as CustomCommands)!;
35+
plugin.RegisterListener<Listeners.OnTick>(() =>
3436
{
3537
// Client Print To Center
3638
if(PluginGlobals.centerClientOn != null && PluginGlobals.centerClientOn.Count !> 0 )

CustomCommands/Services/LoadJson.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,4 +32,6 @@ public LoadJson(ILogger<CustomCommands> Logger)
3232
return null;
3333
}
3434
}
35+
36+
3537
}

CustomCommands/Services/MessageManager.cs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,20 @@
33
using CounterStrikeSharp.API.Core.Plugin;
44
using CustomCommands.Interfaces;
55
using CustomCommands.Model;
6+
using Microsoft.Extensions.Logging;
67

78
namespace CustomCommands.Services;
89
public class MessageManager : IMessageManager
910
{
1011
private readonly IPluginGlobals PluginGlobals;
1112
private readonly IReplaceTagsFunctions ReplaceTagsFunctions;
12-
private readonly CustomCommands PluginContext;
13+
private readonly PluginContext PluginContext;
1314

1415
public MessageManager(IPluginGlobals PluginGlobals, IReplaceTagsFunctions ReplaceTagsFunctions, IPluginContext PluginContext)
1516
{
1617
this.PluginGlobals = PluginGlobals;
1718
this.ReplaceTagsFunctions = ReplaceTagsFunctions;
18-
this.PluginContext = ((PluginContext as PluginContext)!.Plugin as CustomCommands)!;
19+
this.PluginContext = (PluginContext as PluginContext)!;
1920
}
2021

2122
public void SendMessage(CCSPlayerController player, Commands cmd)
@@ -53,6 +54,8 @@ public void SendMessage(CCSPlayerController player, Commands cmd)
5354

5455
public void PrintToCenterClient(CCSPlayerController player, Commands cmd)
5556
{
57+
CustomCommands plugin = (PluginContext.Plugin as CustomCommands)!;
58+
5659
string message = ReplaceTagsFunctions.ReplaceMessageTags(cmd.CenterMessage.Message, player);
5760

5861
var CenterClientElement = new CenterClientElement
@@ -61,15 +64,17 @@ public void PrintToCenterClient(CCSPlayerController player, Commands cmd)
6164
Message = message
6265
};
6366
PluginGlobals.centerClientOn.Add(CenterClientElement);
64-
PluginContext.AddTimer(cmd.CenterMessage.Time, () => PluginGlobals.centerClientOn.Remove(CenterClientElement));
67+
plugin.AddTimer(cmd.CenterMessage.Time, () => PluginGlobals.centerClientOn.Remove(CenterClientElement));
6568
}
6669

6770
public void PrintToAllCenter(Commands cmd)
6871
{
72+
CustomCommands plugin = (PluginContext.Plugin as CustomCommands)!;
73+
6974
PluginGlobals.centerServerOn.Message = cmd.CenterMessage.Message;
7075
PluginGlobals.centerServerOn.IsRunning = true;
7176

72-
PluginContext.AddTimer(cmd.CenterMessage.Time, () =>
77+
plugin.AddTimer(cmd.CenterMessage.Time, () =>
7378
{
7479
PluginGlobals.centerServerOn.IsRunning = false;
7580
});

0 commit comments

Comments
 (0)