EssentialGG / Vigilance

Configuration Utility using Elementa
GNU Lesser General Public License v3.0
54 stars 12 forks source link

Inconvenient to set values in a Propery Listener/Action #36

Open My-Name-Is-Jeff opened 2 years ago

My-Name-Is-Jeff commented 2 years ago

As seen here (implementation still has the same behavior in the current version of Vigilance), the value of the field is set after the listener is called:

https://github.com/Sk1erLLC/Vigilance/blob/553f6cb8612101ecddaa1fac59b171c1e81a0612/src/main/kotlin/club/sk1er/vigilance/data/PropertyData.kt#L29-L32

This means you cannot directly set any given value in the listener, because it will be overwritten right after the action has been completed

Because of this, to set the same field as the one called in the listener to a different value, you must wait until after the setValue function is completed before calling your own code

Example:

https://github.com/Skytils/SkytilsMod/blob/5aea845da5ecfe8f94a345dab4c15240e2e19096/src/main/kotlin/skytils/skytilsmod/core/Config.kt#L2397