mirror of
https://github.com/plexusorg/Plex-FAWE.git
synced 2024-12-22 17:27:38 +00:00
[Doctools] Read source files for command ordering
This commit is contained in:
parent
487da77a72
commit
a0b9810c44
@ -14,4 +14,5 @@ dependencies {
|
|||||||
"implementation"(project(":worldedit-libs:core:ap"))
|
"implementation"(project(":worldedit-libs:core:ap"))
|
||||||
"implementation"(project(":worldedit-core"))
|
"implementation"(project(":worldedit-core"))
|
||||||
"implementation"(kotlin("stdlib-jdk8"))
|
"implementation"(kotlin("stdlib-jdk8"))
|
||||||
|
"implementation"(kotlin("reflect"))
|
||||||
}
|
}
|
||||||
|
@ -48,10 +48,10 @@ import java.nio.file.Files
|
|||||||
import java.nio.file.Paths
|
import java.nio.file.Paths
|
||||||
import java.util.stream.Stream
|
import java.util.stream.Stream
|
||||||
import kotlin.streams.toList
|
import kotlin.streams.toList
|
||||||
import org.enginehub.piston.annotation.Command as CommandAnnotation
|
|
||||||
|
|
||||||
class DocumentationPrinter private constructor() {
|
class DocumentationPrinter private constructor() {
|
||||||
|
|
||||||
|
private val nameRegex = Regex("name = \"(.+?)\"")
|
||||||
private val serializer = PlainComponentSerializer({ "" }, TranslatableComponent::key)
|
private val serializer = PlainComponentSerializer({ "" }, TranslatableComponent::key)
|
||||||
private val commands = WorldEdit.getInstance().platformManager.platformCommandManager.commandManager.allCommands
|
private val commands = WorldEdit.getInstance().platformManager.platformCommandManager.commandManager.allCommands
|
||||||
.map { it.name to it }.toList().toMap()
|
.map { it.name to it }.toList().toMap()
|
||||||
@ -59,10 +59,19 @@ class DocumentationPrinter private constructor() {
|
|||||||
private val permsOutput = StringBuilder()
|
private val permsOutput = StringBuilder()
|
||||||
|
|
||||||
private suspend inline fun <reified T> SequenceScope<String>.yieldAllCommandsIn() {
|
private suspend inline fun <reified T> SequenceScope<String>.yieldAllCommandsIn() {
|
||||||
for (method in T::class.java.methods) {
|
val sourceFile = Paths.get("worldedit-core/src/main/java/" + T::class.qualifiedName!!.replace('.', '/') + ".java")
|
||||||
val cmdAnno = method.getDeclaredAnnotation(CommandAnnotation::class.java)
|
require(Files.exists(sourceFile)) { "Source not found for ${T::class.qualifiedName}"}
|
||||||
if (cmdAnno != null) {
|
Files.newBufferedReader(sourceFile).useLines { lines ->
|
||||||
yield(cmdAnno.name)
|
var inCommand = false
|
||||||
|
for (line in lines) {
|
||||||
|
if (inCommand) {
|
||||||
|
when (val match = nameRegex.find(line)) {
|
||||||
|
null -> if (line.trim() == ")") inCommand = false
|
||||||
|
else -> yield(match.groupValues[1])
|
||||||
|
}
|
||||||
|
} else if (line.contains("@Command(")) {
|
||||||
|
inCommand = true
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -219,8 +228,7 @@ Other Permissions
|
|||||||
private fun cmdsToPerms(cmds: List<Command>, prefix: String) {
|
private fun cmdsToPerms(cmds: List<Command>, prefix: String) {
|
||||||
cmds.forEach { c ->
|
cmds.forEach { c ->
|
||||||
permsOutput.append(" ").append(cmdToPerm(prefix, c)).append("\n")
|
permsOutput.append(" ").append(cmdToPerm(prefix, c)).append("\n")
|
||||||
c.parts.filter { p -> p is SubCommandPart }
|
c.parts.filterIsInstance<SubCommandPart>()
|
||||||
.map { p -> p as SubCommandPart }
|
|
||||||
.forEach { scp ->
|
.forEach { scp ->
|
||||||
cmdsToPerms(scp.commands.sortedBy { it.name }, prefix + c.name + " ")
|
cmdsToPerms(scp.commands.sortedBy { it.name }, prefix + c.name + " ")
|
||||||
}
|
}
|
||||||
@ -260,6 +268,7 @@ Other Permissions
|
|||||||
cmdOutput.appendln()
|
cmdOutput.appendln()
|
||||||
for ((k, v) in entries) {
|
for ((k, v) in entries) {
|
||||||
val rstSafe = v.replace("\"", "\\\"").replace("\n", "\n" + " ".repeat(2))
|
val rstSafe = v.replace("\"", "\\\"").replace("\n", "\n" + " ".repeat(2))
|
||||||
|
.lineSequence().map { line -> line.ifBlank { "" } }.joinToString(separator = "\n")
|
||||||
cmdOutput.append(" ".repeat(2))
|
cmdOutput.append(" ".repeat(2))
|
||||||
.append(k)
|
.append(k)
|
||||||
.append(",")
|
.append(",")
|
||||||
|
Loading…
Reference in New Issue
Block a user