generated from UndefinedCreations/Template
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(dsl-builder): add type-safe kotlin builder using extension funct…
…ions
- Loading branch information
1 parent
1ea81e8
commit 078f7d9
Showing
2 changed files
with
19 additions
and
11 deletions.
There are no files selected for viewing
13 changes: 13 additions & 0 deletions
13
api/src/main/kotlin/com/undefined/stellar/util/Builders.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package com.undefined.stellar.util | ||
|
||
import com.undefined.stellar.StellarCommand | ||
|
||
fun command(name: String, description: String, permissions: List<String>, builder: StellarCommand.() -> Unit): StellarCommand { | ||
val command = StellarCommand(name, description) | ||
command.builder() | ||
return command | ||
} | ||
|
||
fun command(name: String, description: String, builder: StellarCommand.() -> Unit): StellarCommand = command(name, description, listOf(), builder) | ||
|
||
fun command(name: String, builder: StellarCommand.() -> Unit): StellarCommand = command(name, "", builder) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,17 @@ | ||
package com.undefined.stellar | ||
|
||
import com.undefined.stellar.util.command | ||
import org.bukkit.entity.Player | ||
import org.bukkit.plugin.java.JavaPlugin | ||
|
||
class Main : JavaPlugin() { | ||
|
||
override fun onEnable() { | ||
val main = StellarCommand("test") | ||
main.addLocationArgument("location") | ||
.addRequirements(4) | ||
.addOnlinePlayersArgument("string") | ||
.addExecution<Player> { | ||
sender.sendMessage(this.getArgument<Player>("string").name) | ||
} | ||
.onRegister { | ||
println("This runs on register") | ||
} | ||
.register(this) | ||
command("test") { | ||
addStringArgument("string") | ||
addExecution<Player> { sender.sendMessage(getArgument<String>("string")) } | ||
register(this@Main) | ||
} | ||
} | ||
|
||
} |