MagicCheese1 / Damage-Indicator

Minecraft Bukkit plugin for indicating damage dealt to entities
https://www.spigotmc.org/resources/87113/
MIT License
16 stars 3 forks source link

Support hex colours in indicator format / Cache reflective calls #11

Closed lynxplay closed 2 years ago

lynxplay commented 2 years ago

Support hex colours in indicator format

This commit intoduces hex colour support in the indicator format. While it accepts the default legacy format using the chat colour code §x followed by the six hex chars all prefixed by a § (e.g. §x§F§F§F§F§F§F) representing the colour white, it also introduces a smaller format which uses the §# colour code followed by the six hex chars without prefixes (e.g. §#FFFFFF) representing the colour white.

One notable issue when using hex colours is the decimal format used in the plugin. Hex colour codes that contain the char '0' would be replaced by the decimal formatter as they are a valid zero. To prevent this, the hex colour codes should be escaped using decimal string literals, which are denoted by being wrapped in single quotes.

This commit updates the readme to reflect that.


Cache reflective calls

The prior implementation of the packet manager would run the respective reflective constructor/method/field lookups when the logic that required these was executed. Besides the lazy loading of these reflective references, the results were not cached anywhere and hence re-computed every time any method on the packet manager was called.

To improve both speed and error tracing, this commit moves all the reflective initialization logic into a newly introduced factory for each packet manager. This factory will locate any constructor/method/field needed for the packet manager of a specific version and pass the instances to the constructor of that packet manager which then stores them as fields.

This change allows the packet managers to directly access the reflection instances needed to access server internals as well as ensures that any reflection error is cought at creation time of the packet manager instead of runtime.