Class BasePlugin
- Namespace
- CounterStrikeSharp.API.Core
- Assembly
- CounterStrikeSharp.API.dll
public abstract class BasePlugin : IPlugin, IDisposable
- Inheritance
-
BasePlugin
- Implements
Constructors
BasePlugin()
public BasePlugin()
Fields
CommandHandlers
public readonly Dictionary<Delegate, BasePlugin.CallbackSubscriber> CommandHandlers
Field Value
CommandListeners
public readonly Dictionary<Delegate, BasePlugin.CallbackSubscriber> CommandListeners
Field Value
ConvarChangeHandlers
public readonly Dictionary<Delegate, BasePlugin.CallbackSubscriber> ConvarChangeHandlers
Field Value
EntityOutputHooks
public readonly Dictionary<Delegate, BasePlugin.CallbackSubscriber> EntityOutputHooks
Field Value
Handlers
public readonly Dictionary<Delegate, BasePlugin.CallbackSubscriber> Handlers
Field Value
Listeners
public readonly Dictionary<Delegate, BasePlugin.CallbackSubscriber> Listeners
Field Value
Timers
public readonly List<Timer> Timers
Field Value
Properties
CommandManager
public ICommandManager CommandManager { get; set; }
Property Value
Localizer
public IStringLocalizer Localizer { get; set; }
Property Value
Logger
public ILogger Logger { get; set; }
Property Value
ModuleAuthor
public virtual string ModuleAuthor { get; }
Property Value
ModuleDescription
public virtual string ModuleDescription { get; }
Property Value
ModuleDirectory
public string ModuleDirectory { get; }
Property Value
ModuleName
Name of the plugin.
public abstract string ModuleName { get; }
Property Value
ModulePath
public string ModulePath { get; set; }
Property Value
ModuleVersion
Module version.
public abstract string ModuleVersion { get; }
Property Value
Methods
AddCommand(string, string, CommandCallback)
Registers a new server command.
public void AddCommand(string name, string description, CommandInfo.CommandCallback handler)
Parameters
name
stringThe name of the command.
description
stringThe description of the command.
handler
CommandInfo.CommandCallbackThe callback function to be invoked when the command is executed.
AddCommandListener(string?, CommandListenerCallback, HookMode)
public void AddCommandListener(string? name, CommandInfo.CommandListenerCallback handler, HookMode mode = HookMode.Pre)
Parameters
name
stringhandler
CommandInfo.CommandListenerCallbackmode
HookMode
AddTimer(float, Action, TimerFlags?)
public Timer AddTimer(float interval, Action callback, TimerFlags? flags = null)
Parameters
interval
floatcallback
Actionflags
TimerFlags?
Returns
DeregisterEventHandler(string, Delegate, bool)
public void DeregisterEventHandler(string name, Delegate handler, bool post)
Parameters
Dispose()
Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
public void Dispose()
Dispose(bool)
protected virtual void Dispose(bool disposing)
Parameters
disposing
bool
HookEntityOutput(string, string, EntityOutputHandler, HookMode)
public void HookEntityOutput(string classname, string outputName, EntityIO.EntityOutputHandler handler, HookMode mode = HookMode.Pre)
Parameters
classname
stringoutputName
stringhandler
EntityIO.EntityOutputHandlermode
HookMode
HookSingleEntityOutput(CEntityInstance, string, EntityOutputHandler)
public void HookSingleEntityOutput(CEntityInstance entityInstance, string outputName, EntityIO.EntityOutputHandler handler)
Parameters
entityInstance
CEntityInstanceoutputName
stringhandler
EntityIO.EntityOutputHandler
InitializeConfig(object, Type)
public void InitializeConfig(object instance, Type pluginType)
Parameters
Load(bool)
This method is called by CounterStrikeSharp on plugin load and should be treated as plugin constructor.
Called with true
on a hot reload (DLL file replaced in plugins folder)
public virtual void Load(bool hotReload)
Parameters
hotReload
bool
RegisterAllAttributes(object)
public void RegisterAllAttributes(object instance)
Parameters
instance
object
RegisterAttributeHandlers(object)
Registers all game event handlers that are decorated with the [GameEventHandler]
attribute.
public void RegisterAttributeHandlers(object instance)
Parameters
instance
objectThe instance of the object where the event handlers are defined.
RegisterConsoleCommandAttributeHandlers(object)
public void RegisterConsoleCommandAttributeHandlers(object instance)
Parameters
instance
object
RegisterEntityOutputAttributeHandlers(object)
public void RegisterEntityOutputAttributeHandlers(object instance)
Parameters
instance
object
RegisterEventHandler<T>(GameEventHandler<T>, HookMode)
Registers a game event handler.
public void RegisterEventHandler<T>(BasePlugin.GameEventHandler<T> handler, HookMode hookMode = HookMode.Post) where T : GameEvent
Parameters
handler
BasePlugin.GameEventHandler<T>The event handler to register.
hookMode
HookModeThe mode in which the event handler is hooked. Default is
HookMode.Post
.
Type Parameters
T
The type of the game event.
RegisterFakeConVars(object)
Used to bind a fake ConVar to a plugin command. Only required for ConVars that are not public properties of the plugin class.
public void RegisterFakeConVars(object instance)
Parameters
instance
object
RegisterFakeConVars(Type, object)
public void RegisterFakeConVars(Type type, object instance = null)
Parameters
RegisterListener<T>(T)
public void RegisterListener<T>(T handler) where T : Delegate
Parameters
handler
T
Type Parameters
T
RemoveCommand(string, CommandCallback)
public void RemoveCommand(string name, CommandInfo.CommandCallback handler)
Parameters
name
stringhandler
CommandInfo.CommandCallback
RemoveCommandListener(string, CommandListenerCallback, HookMode)
public void RemoveCommandListener(string name, CommandInfo.CommandListenerCallback handler, HookMode mode)
Parameters
name
stringhandler
CommandInfo.CommandListenerCallbackmode
HookMode
RemoveListener(string, Delegate)
public void RemoveListener(string name, Delegate handler)
Parameters
UnhookEntityOutput(string, string, EntityOutputHandler, HookMode)
public void UnhookEntityOutput(string classname, string outputName, EntityIO.EntityOutputHandler handler, HookMode mode = HookMode.Pre)
Parameters
classname
stringoutputName
stringhandler
EntityIO.EntityOutputHandlermode
HookMode
UnhookSingleEntityOutput(CEntityInstance, string, EntityOutputHandler)
public void UnhookSingleEntityOutput(CEntityInstance entityInstance, string outputName, EntityIO.EntityOutputHandler handler)
Parameters
entityInstance
CEntityInstanceoutputName
stringhandler
EntityIO.EntityOutputHandler
Unload(bool)
Will be called by CounterStrikeSharp on plugin unload. In this method the plugin should cleanup any extra resources. Event handlers, listeners etc. will automatically be deregistered.
public virtual void Unload(bool hotReload)
Parameters
hotReload
bool