roflmuffin / CounterStrikeSharp

CounterStrikeSharp allows you to write server plugins in C# for Counter-Strike 2/Source2/CS2
https://docs.cssharp.dev
Other
743 stars 111 forks source link

PluginCapability #381

Closed PhantomYopta closed 4 weeks ago

PhantomYopta commented 5 months ago

Could you please add an event to PluginCapability that triggers when a Capability is registered, and also ensure that it is triggered immediately if it's already registered? It's very difficult to deal with when you have a chain of dependencies.

roflmuffin commented 5 months ago

Currently capabilities are generally registered in the load method and then used from within all plugins loaded. How do you see this flow working? Will plugins register capabilities in all plugins loaded and then listen to the event?

Muinez commented 5 months ago

let's say there are 3 plugins

api of plugin 2 depends on the api of plugin 1

plugin 3 depends on api of plugin 2, but since plugin 2 depends on plugin 1, plugin 2 will have to register capability in OnAllPluginsLoaded and then plugin 3 will not be able to get api of plugin 2 in OnAllPluginsLoaded.

I think the problem is solved simply if the plugin simply subscribed in Load to the event when the capability was registered Thus a plugin that does not depend on other plugins simply registers capability in OnAllPluginsLoad, and other plugins that already depend on it, subscribe to capability registration in Load and register their api when event occurs.

B3none commented 5 months ago

Could you please add an event to PluginCapability that triggers when a Capability is registered, and also ensure that it is triggered immediately if it's already registered? It's very difficult to deal with when you have a chain of dependencies.

We had a slight issue when we implemented an event firing / listening flow for Retakes.

For us it was solved by ensuring the dependencies were loaded in the correct order (alphabetically) which required slight file name changes.

I suspect the way we're firing / listening to events in our plugin could be slightly modified to fit your use case.