1.15.2 Use kotlinscript with DSL to create script plugin?

Discussion in 'Spigot Plugin Development' started by caxerx, Jan 21, 2020.

?

What you think this idea can be

Poll closed Apr 21, 2020.
  1. a new Script Plugin

    0 vote(s)
    0.0%
  2. a new API for readable programming

    1 vote(s)
    50.0%
  3. Nothing can be

    1 vote(s)
    50.0%
  4. both

    0 vote(s)
    0.0%
  1. Hello guys recently I am thinking about using the DSL pattern of Kotlin to create readable programming but I am not sure the availability. I hope can have a discussion about this.

    It's not only for creating script plugin, but also for benefiting Kotlin plugin developer to fast writing plugin.

    the script extension will use .kts, and the plugin will eval all of the kts via ScriptEngineManager

    create Event may look like this
    Code (Kotlin):
    on PlayerJoinEvent run {
       val name = "name" of player
       name eq "Abc123" then {
           stopRun
       }
     
       player msg "welcome to the server, $name !"
    }

    Basic looping

    Code (Kotlin):
    private val a = 1..10 random 2 //create iterable and get random of 2 numbers
    a loop {
        val b = this > 5
        b then {
            Common println "$this is > 5"
        } elseThen {
            Common println "$this is <= 5"
        }
    }

    Code (Kotlin):
    1..10 loop {
        Common println "No. $it"
    }
    or
    Code (Kotlin):
    1..10 loop {
        Common println "No. $this"
    }
    or
    Code (Kotlin):
    1..10 loop { num ->
        Common println "No. $num"
    }
    1..10 can make like "1 rangeTo 10" too

    assign value will still using val


    Code (Kotlin):
    val a = 1 //cross kts access
    private val b = 1
    command
    Code (Kotlin):
    Register command "/hi <player>" execute {
      val name = arg get 1 or "none" //nullable handle
      sender msg "greeting to $name!"
    }

    create GUI
    Code (Kotlin):
    val inv = Create chest {
        row = 1
        title = "title"
        items {
           1 to paper
           2 to paper
         }
    }
    create Item
    Code (Kotlin):
    val paper = Create item PAPER {
       name = "test"
       lore = "one|two|three|four"
       unbreakable = true
       itemflags = "HIDE_ATTRIBUTES|HIDE_DESTROYS|HIDE_ENCHANTS"
    }
    array

    Code (Java):
    val arr = Create array {
            Add num 1
            Add double 2.2
            Add string "abc"
            Add bool  false
        }

    map

    Code (Kotlin):
    val map = Create map {
            1 mapTo 2
            2 mapTo "abc"
            "xyz" mapTo 444
            0.0 mapTo "none"
            false mapTo "abc"
            "w" mapTo true
        }
    Any ideas ? Is it only can be readable programming tools or it can also make as script plugin ?
     
    #1 caxerx, Jan 21, 2020
    Last edited: Jan 21, 2020
  2. I have no experience with Skript, but isn't it exactly like what you showed?
     
  3. It's not really skript,it's just using the magic of kotlin dsl
    Actually you can do kotlin programming in kts