Skip to content

Commit

Permalink
feat: add caution admonition for plugin loading phases in Velocity
Browse files Browse the repository at this point in the history
  • Loading branch information
Timongcraft committed Aug 17, 2024
1 parent 7f4230d commit cd9b658
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions docs/velocity/dev/getting-started/api-basics.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -93,13 +93,17 @@ Dependencies on other plugins are also to be specified there, but we'll get to t

### A word of caution

:::caution

In Velocity, plugin loading is split into two steps: construction and initialization. The code in
your plugin's constructor is part of the construction phase. There is very little you can do safely
during construction, especially as the API does not specify which operations are safe to run during
construction. Notably, you can't register an event listener in your constructor, because you need to
have a valid plugin registration, but Velocity can't register the plugin until the plugin has been
constructed, causing a "chicken or the egg" problem.
:::
To break this vicious cycle, you should always wait for initialization, which is indicated when
Velocity fires the <Javadoc name={"com.velocitypowered.api.event.proxy.ProxyInitializeEvent"} project={"velocity"}>`ProxyInitializeEvent`</Javadoc>.
We can do things on initialization by adding a listener for this event, as shown below.
Expand Down

0 comments on commit cd9b658

Please sign in to comment.