com.skillw.asahi.internal.namespacing.prefix.lang.util.Util.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of Pouvoir Show documentation
Show all versions of Pouvoir Show documentation
Bukkit Script Engine Plugin.
package com.skillw.asahi.internal.namespacing.prefix.lang.util
import com.skillw.asahi.api.annotation.AsahiPrefix
import com.skillw.asahi.api.prefixParser
import com.skillw.asahi.api.quest
import com.skillw.asahi.api.quester
import com.skillw.asahi.internal.util.Clock
import com.skillw.asahi.internal.util.MapTemplate
import taboolib.common5.Coerce
import java.awt.Color
import java.text.SimpleDateFormat
import java.util.*
/**
* @className Util
*
* @author Glom
* @date 2023/1/14 0:45 Copyright 2024 Glom.
*/
@AsahiPrefix(["arrayOf"], "lang")
private fun arrayOf() = prefixParser {
val array = quest>()
result { array.get() }
}
@AsahiPrefix(["listOf"], "lang")
private fun listOf() = prefixParser {
val list = quest>()
result { list.get() }
}
@AsahiPrefix(["setOf"], "lang")
private fun setOf() = prefixParser {
val set = quest>()
result { set.get() }
}
@AsahiPrefix(["mapOf"], "lang")
private fun mapOf() = prefixParser {
if (expect("with")) {
val template = quest()
val list = quest>()
result { template.get().build(list.get()) }
} else {
val map = quest>()
result { map.get() }
}
}
@AsahiPrefix(["mapListOf"], "lang")
private fun mapListOf() = prefixParser>> {
expect("with")
val templateGetter = quest()
val list = quest>()
result {
val template = templateGetter.get()
list.get().mapNotNull { template.build(it as? List? ?: return@mapNotNull null) }
.toMutableList()
}
}
@AsahiPrefix(["pair"], "lang")
private fun pair() = prefixParser> {
val pair = quest>()
result { pair.get() }
}
@AsahiPrefix(["mapTemplate"], "lang")
private fun mapTemplate() = prefixParser {
val list = quest>()
result { MapTemplate(list.get().map { it.toString() }) }
}
/**
* @className Operator
*
* @author Glom
* @date 2023/1/14 0:42 Copyright 2024 Glom.
*/
@AsahiPrefix(["join"], "lang")
private fun join() = prefixParser {
val list = quest>()
val by = if (expect("by")) quest() else quester { "" }
result {
list.get().joinToString(by.get().replace("\\n", "\n"))
}
}
@AsahiPrefix(["replace"], "lang")
private fun replace() = prefixParser {
val str = quest()
expect("with")
val replacement = quest
© 2015 - 2024 Weber Informatics LLC | Privacy Policy