mirror of
https://github.com/RaidMax/IW4M-Admin.git
synced 2025-06-10 15:20:48 -05:00
implement script plugin command registration - issue #132
This commit is contained in:
41
Application/Misc/ScriptCommand.cs
Normal file
41
Application/Misc/ScriptCommand.cs
Normal file
@ -0,0 +1,41 @@
|
||||
using SharedLibraryCore;
|
||||
using SharedLibraryCore.Commands;
|
||||
using SharedLibraryCore.Configuration;
|
||||
using SharedLibraryCore.Interfaces;
|
||||
using System;
|
||||
using System.Threading.Tasks;
|
||||
using static SharedLibraryCore.Database.Models.EFClient;
|
||||
|
||||
namespace IW4MAdmin.Application.Misc
|
||||
{
|
||||
/// <summary>
|
||||
/// generic script command implementation
|
||||
/// </summary>
|
||||
public class ScriptCommand : Command
|
||||
{
|
||||
private readonly Action<GameEvent> _executeAction;
|
||||
|
||||
public ScriptCommand(string name, string alias, string description, Permission permission,
|
||||
CommandArgument[] args, Action<GameEvent> executeAction, CommandConfiguration config, ITranslationLookup layout)
|
||||
: base(config, layout)
|
||||
{
|
||||
|
||||
_executeAction = executeAction;
|
||||
Name = name;
|
||||
Alias = alias;
|
||||
Description = description;
|
||||
Permission = permission;
|
||||
Arguments = args;
|
||||
}
|
||||
|
||||
public override Task ExecuteAsync(GameEvent E)
|
||||
{
|
||||
if (_executeAction == null)
|
||||
{
|
||||
throw new InvalidOperationException($"No execute action defined for command \"{Name}\"");
|
||||
}
|
||||
|
||||
return Task.Run(() => _executeAction(E));
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user