Skip to content

Commit

Permalink
More work
Browse files Browse the repository at this point in the history
  • Loading branch information
MSWS committed Sep 6, 2024
1 parent b47d04c commit 488e9c0
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 11 deletions.
20 changes: 12 additions & 8 deletions Commands/CommandManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,19 @@ public void Start(BasePlugin? basePlugin, bool hotReload) {
}

public override bool RegisterCommand(ICommand command) {
base.RegisterCommand(command);
plugin?.AddCommand(command.Name, command.Description ?? string.Empty,
(player, info) => {
var wrapper = player == null ? null : new PlayerWrapper(player);
var args = info.GetCommandString.Split(" ");
Server.NextFrameAsync(async () => {
await ProcessCommand(wrapper, args);
var result = base.RegisterCommand(command);
if (result == false) return false;
foreach (var alias in command.Aliases) {
plugin?.AddCommand(command.Name, command.Description ?? string.Empty,
(player, info) => {
var wrapper = player == null ? null : new PlayerWrapper(player);
var args = info.GetCommandString.Split(" ");
Server.NextFrameAsync(async () => {
await ProcessCommand(wrapper, args);
});
});
});
}

return true;
}
}
1 change: 1 addition & 0 deletions Commands/GangCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ public class GangCommand(IGangManager gangMgr) : ICommand {

public string Name => "css_gang";
public string? Description => "Master command for gangs";
public string[] Aliases => ["css_gang", "css_gangs"];

public async Task<CommandResult> Execute(PlayerWrapper? executor,
CommandInfoWrapper info) {
Expand Down
6 changes: 3 additions & 3 deletions Gangs/GangServiceCollection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using CounterStrikeSharp.API.Core;
using GangsAPI.Extensions;
using GangsAPI.Services;
using GangsAPI.Services.Commands;
using Microsoft.Extensions.DependencyInjection;
using Mock;
using SQLImpl;
Expand All @@ -11,14 +12,13 @@ namespace GangsImpl;
public class GangServiceCollection : IPluginServiceCollection<CS2Gangs> {
public void ConfigureServices(IServiceCollection serviceCollection) {
serviceCollection.AddPluginBehavior<IGangManager, MockGangManager>();
// serviceCollection.AddPluginBehavior<IGangManager, SQLStatManager>();
serviceCollection.AddPluginBehavior<IGangManager, SQLGangManager>();
serviceCollection.AddPluginBehavior<IPlayerManager, MockPlayerManager>();
serviceCollection.AddPluginBehavior<IStatManager, SQLStatManager>();
serviceCollection.AddPluginBehavior<IStatManager, MockStatManager>();
serviceCollection
.AddPluginBehavior<IGangStatManager, MockInstanceStatManager>();
serviceCollection
.AddPluginBehavior<IPlayerStatManager, MockInstanceStatManager>();
serviceCollection.RegisterCommands();
serviceCollection.AddPluginBehavior<ICommandManager, CommandManager>();
}
}
2 changes: 2 additions & 0 deletions GangsAPI/Services/Commands/ICommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@ namespace GangsAPI.Services.Commands;

public interface ICommand : IPluginBehavior {
string Name { get; }

string? Description => null;
string Usage => "";
string[] RequiredFlags => [];
string[] RequiredGroups => [];
string[] Aliases => [Name];

bool CanExecute(PlayerWrapper? executor) {
if (executor == null) return true;
Expand Down

0 comments on commit 488e9c0

Please sign in to comment.