Support invoke
Opened this issue · 3 comments
There is a operator fun called "invoke"
after simply adding
operator fun <T> T.invoke(block : T.() -> Unit) : T {
return this.apply(block)
}
could achieve
player {
displayName = "name"
msg("message")
etc...
}
sender {
msg("anything")
}
event<PlayerMoveEvent> {
isCancelled = true
player {
msg("You can move yet")
etc...
}
}
makes code cleaner, get rid of with(player) or player.apply { }
it works for anything after that three lines but might effect some classes that already have invoke fun
val component = ComponentBuilder()
component {
append("wow")
etc...
}
it looks like the component in net.md_5.bungee.api.chat.ComponentBuilder having a dsl support but actually no
one thing forget, It doesn't works fine with some class that has val constructer
I don't think that use a Generic Typed invoke
is a good pratice.
About the ComponentBuilder, I will work on it, is something that could be more clean using DSL.
I think have a dsl support for https://github.com/KyoriPowered/adventure would be great. Since it have Bungeecord, Velocity, bukkit etc support.