Skip to content

Support invoke #20

@smallshen

Description

@smallshen

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions