mirror of
https://github.com/roflmuffin/CounterStrikeSharp.git
synced 2025-12-05 15:40:24 -08:00
Added initial UnregisterAllAttributes function
This commit is contained in:
@@ -387,14 +387,19 @@ namespace CounterStrikeSharp.API.Core
|
||||
Timers.Add(timer);
|
||||
return timer;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public void RegisterAllAttributes(object instance)
|
||||
{
|
||||
this.RegisterAttributeHandlers(instance);
|
||||
this.RegisterConsoleCommandAttributeHandlers(instance);
|
||||
this.RegisterEntityOutputAttributeHandlers(instance);
|
||||
}
|
||||
public void UnregisterAllAttributes(object instance)
|
||||
{
|
||||
this.UnregisterConsoleCommandAttributeHandlers(instance);
|
||||
// this.RegisterAttributeHandlers(instance);
|
||||
// this.RegisterEntityOutputAttributeHandlers(instance);
|
||||
}
|
||||
|
||||
public void InitializeConfig(object instance, Type pluginType)
|
||||
{
|
||||
@@ -470,6 +475,23 @@ namespace CounterStrikeSharp.API.Core
|
||||
}
|
||||
}
|
||||
|
||||
public void UnregisterConsoleCommandAttributeHandlers(object instance)
|
||||
{
|
||||
var eventHandlers = instance.GetType()
|
||||
.GetMethods()
|
||||
.Where(method => method.GetCustomAttributes<ConsoleCommandAttribute>().Any())
|
||||
.ToArray();
|
||||
|
||||
foreach (var eventHandler in eventHandlers)
|
||||
{
|
||||
var attributes = eventHandler.GetCustomAttributes<ConsoleCommandAttribute>();
|
||||
foreach (var commandInfo in attributes)
|
||||
{
|
||||
RemoveCommand(commandInfo.Command, eventHandler.CreateDelegate<CommandInfo.CommandCallback>(instance));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void RegisterEntityOutputAttributeHandlers(object instance)
|
||||
{
|
||||
var handlers = instance.GetType()
|
||||
|
||||
@@ -59,6 +59,7 @@ namespace CounterStrikeSharp.API.Core
|
||||
IStringLocalizer Localizer { get; set; }
|
||||
|
||||
void RegisterAllAttributes(object instance);
|
||||
void UnregisterAllAttributes(object instance);
|
||||
|
||||
void InitializeConfig(object instance, Type pluginType);
|
||||
}
|
||||
|
||||
@@ -215,6 +215,8 @@ namespace CounterStrikeSharp.API.Core.Plugin
|
||||
|
||||
_logger.LogInformation("Unloading plugin {Name}", Plugin.ModuleName);
|
||||
|
||||
Plugin.UnregisterAllAttributes(Plugin);
|
||||
|
||||
Plugin.Unload(hotReload);
|
||||
|
||||
Plugin.Dispose();
|
||||
|
||||
Reference in New Issue
Block a user