Skip to content

Commit e4fafb3

Browse files
committed
Add developer API docs and Dokka Javadoc support
1 parent 5443538 commit e4fafb3

13 files changed

Lines changed: 335 additions & 0 deletions

File tree

build.gradle.kts

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
import io.izzel.taboolib.gradle.*
22
import org.gradle.api.publish.maven.MavenPublication
3+
import org.jetbrains.dokka.gradle.DokkaTask
34
import org.jetbrains.kotlin.gradle.dsl.JvmTarget
45

56
plugins {
67
java
78
`maven-publish`
89
id("io.izzel.taboolib") version "2.0.36"
10+
id("org.jetbrains.dokka") version "1.9.20"
911
kotlin("jvm") version "2.3.0"
1012
}
1113

@@ -48,6 +50,18 @@ tasks.withType<JavaCompile> {
4850
options.encoding = "UTF-8"
4951
}
5052

53+
tasks.withType<DokkaTask>().configureEach {
54+
moduleName.set("MatrixLib API")
55+
dokkaSourceSets.configureEach {
56+
includes.from("docs/api/overview.md")
57+
jdkVersion.set(8)
58+
skipDeprecated.set(false)
59+
reportUndocumented.set(false)
60+
noStdlibLink.set(false)
61+
noJdkLink.set(false)
62+
}
63+
}
64+
5165
kotlin {
5266
compilerOptions {
5367
jvmTarget = JvmTarget.fromTarget("1.8")
@@ -60,6 +74,16 @@ configure<JavaPluginExtension> {
6074
withSourcesJar()
6175
}
6276

77+
val dokkaJavadocJar by tasks.registering(Jar::class) {
78+
dependsOn(tasks.named("dokkaJavadoc"))
79+
archiveClassifier.set("javadoc")
80+
from(tasks.named("dokkaJavadoc"))
81+
}
82+
83+
tasks.named("assemble") {
84+
dependsOn(dokkaJavadocJar)
85+
}
86+
6387
val sharedApiRepoDirCandidates = listOf(
6488
layout.projectDirectory.dir("../_publish/matrix-api"),
6589
layout.projectDirectory.dir("../../_publish/matrix-api")
@@ -74,6 +98,7 @@ publishing {
7498
create<MavenPublication>("matrixlibApi") {
7599
from(components["java"])
76100
artifactId = "matrixlib-api"
101+
artifact(dokkaJavadocJar)
77102
}
78103
}
79104
repositories {
@@ -89,3 +114,9 @@ tasks.register("publishMatrixApi") {
89114
description = "Publish MatrixLib API artifact to the shared local repository."
90115
dependsOn("publishAllPublicationsToMatrixPublicRepository")
91116
}
117+
118+
tasks.register("generateJavadoc") {
119+
group = "documentation"
120+
description = "Generate Javadoc-style API docs with Dokka."
121+
dependsOn("dokkaJavadoc")
122+
}

docs/api/overview.md

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
Module MatrixLib API
2+
3+
MatrixLib API 面向 Matrix 系列插件开发者,当前提供:
4+
5+
- 统一品牌与控制台输出
6+
- 文本与 YAML bundle
7+
- 菜单与动作执行
8+
- Bukkit / Folia 兼容探测
9+
- 共享货币与结算
10+
- 全息兼容桥接
11+
- bStats 注册封装
12+
- GitHub Releases 更新检查与审批下载
13+
14+
## Code Tree
15+
16+
```text
17+
src/main/kotlin/com/y54895/matrixlib/
18+
├─ MatrixLib.kt
19+
├─ api/
20+
│ ├─ action/ActionApi.kt
21+
│ ├─ brand/MatrixBranding.kt
22+
│ ├─ compat/CompatApi.kt
23+
│ ├─ console/MatrixConsoleVisuals.kt
24+
│ ├─ economy/MatrixEconomy.kt
25+
│ ├─ hologram/
26+
│ │ ├─ MatrixHologramRequest.kt
27+
│ │ ├─ MatrixHolograms.kt
28+
│ │ └─ internal/
29+
│ ├─ menu/MenuApi.kt
30+
│ ├─ metrics/MatrixBStats.kt
31+
│ ├─ resource/MatrixResourceFiles.kt
32+
│ ├─ text/
33+
│ │ ├─ MatrixText.kt
34+
│ │ └─ MatrixYamlBundle.kt
35+
│ └─ update/MatrixPluginUpdates.kt
36+
├─ command/MatrixLibCommands.kt
37+
└─ metrics/BStatsMetrics.kt
38+
```
39+
40+
Public API recommendation:
41+
42+
- Prefer types under `api/`
43+
- Treat `api/hologram/internal/` as provider internals
44+
- Treat `command/` and `metrics/` as MatrixLib runtime wiring, not downstream extension points
45+
46+
推荐入口类型:
47+
48+
- `MatrixBranding`
49+
- `MatrixText`
50+
- `MatrixYamlBundle`
51+
- `MenuLoader`
52+
- `MenuRenderer`
53+
- `MatrixEconomy`
54+
- `MatrixHolograms`
55+
- `MatrixBStats`
56+
- `MatrixPluginUpdates`

src/main/kotlin/com/y54895/matrixlib/api/action/ActionApi.kt

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,34 @@ import com.y54895.matrixlib.api.text.MatrixText
44
import org.bukkit.Sound
55
import org.bukkit.entity.Player
66

7+
/**
8+
* Runtime action context used by Matrix menu and UI layers.
9+
*
10+
* @property player player who triggered the action set
11+
* @property placeholders resolved placeholders for action interpolation
12+
* @property backAction optional callback used by the built-in `back` action
13+
*/
714
data class ActionContext(
815
val player: Player,
916
val placeholders: Map<String, String>,
1017
val backAction: Runnable? = null
1118
)
1219

20+
/**
21+
* Executes Matrix action strings against a player context.
22+
*
23+
* Supported built-in actions:
24+
* - `close`
25+
* - `back`
26+
* - `tell:<message>`
27+
* - `sound:<SOUND>-<volume>-<pitch>`
28+
* - any other non-blank string is treated as a player command
29+
*/
1330
object ActionExecutor {
1431

32+
/**
33+
* Execute a list of actions in order.
34+
*/
1535
fun execute(context: ActionContext, actions: List<String>) {
1636
actions.forEach { executeSingle(context, it) }
1737
}

src/main/kotlin/com/y54895/matrixlib/api/brand/MatrixBranding.kt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
package com.y54895.matrixlib.api.brand
22

3+
/**
4+
* Shared branding descriptor used by Matrix console, text, and command surfaces.
5+
*/
36
data class MatrixBranding(
47
val displayName: String,
58
val rootCommand: String,

src/main/kotlin/com/y54895/matrixlib/api/console/MatrixConsoleVisuals.kt

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,27 @@ import com.y54895.matrixlib.api.text.MatrixText
55
import org.bukkit.Bukkit
66
import taboolib.common.platform.function.info
77

8+
/**
9+
* Key-value line rendered inside Matrix console lifecycle blocks.
10+
*/
811
data class MatrixConsoleFact(
912
val label: String,
1013
val value: String
1114
)
1215

16+
/**
17+
* Shared lifecycle banner renderer for Matrix plugins.
18+
*
19+
* This API keeps console output visually consistent across the Matrix series.
20+
*/
1321
object MatrixConsoleVisuals {
1422

1523
private const val MIN_BORDER_WIDTH = 66
1624
private val colorCodePattern = Regex("&[0-9a-fk-orA-FK-OR]")
1725

26+
/**
27+
* Render the boot block used during plugin load.
28+
*/
1829
fun renderBoot(
1930
branding: MatrixBranding,
2031
headline: String,
@@ -30,6 +41,9 @@ object MatrixConsoleVisuals {
3041
)
3142
}
3243

44+
/**
45+
* Render an arbitrary lifecycle stage block.
46+
*/
3347
fun renderStage(
3448
branding: MatrixBranding,
3549
stage: String,
@@ -44,6 +58,9 @@ object MatrixConsoleVisuals {
4458
)
4559
}
4660

61+
/**
62+
* Render the ready block used after plugin enable completed successfully.
63+
*/
4764
fun renderReady(
4865
branding: MatrixBranding,
4966
version: String,
@@ -58,6 +75,9 @@ object MatrixConsoleVisuals {
5875
)
5976
}
6077

78+
/**
79+
* Render the failure block used when startup aborts.
80+
*/
6181
fun renderFailure(
6282
branding: MatrixBranding,
6383
reason: String
@@ -70,6 +90,9 @@ object MatrixConsoleVisuals {
7090
)
7191
}
7292

93+
/**
94+
* Render the shutdown block used during plugin disable.
95+
*/
7396
fun renderShutdown(
7497
branding: MatrixBranding,
7598
details: List<MatrixConsoleFact> = emptyList()

src/main/kotlin/com/y54895/matrixlib/api/hologram/MatrixHologramRequest.kt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,17 @@ package com.y54895.matrixlib.api.hologram
22

33
import org.bukkit.Location
44

5+
/**
6+
* Anchor mode used when converting a logical hologram request to a rendered location.
7+
*/
58
enum class MatrixHologramAnchor {
69
EXACT,
710
BLOCK_CENTER
811
}
912

13+
/**
14+
* Immutable hologram update request consumed by [MatrixHolograms].
15+
*/
1016
data class MatrixHologramRequest(
1117
val namespace: String,
1218
val id: String,
@@ -16,6 +22,9 @@ data class MatrixHologramRequest(
1622
val heightOverride: Double? = null
1723
) {
1824

25+
/**
26+
* Build the provider-facing hologram id.
27+
*/
1928
fun qualifiedId(): String {
2029
val resolvedNamespace = namespace.trim().ifBlank { "matrix" }.lowercase()
2130
return "${resolvedNamespace}_${id.trim()}"

src/main/kotlin/com/y54895/matrixlib/api/hologram/MatrixHolograms.kt

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@ import taboolib.platform.BukkitPlugin
2020
import java.io.File
2121
import java.util.concurrent.ConcurrentHashMap
2222

23+
/**
24+
* Shared hologram bridge that picks one supported provider at runtime and keeps
25+
* Matrix plugin requests synchronized with that provider.
26+
*/
2327
object MatrixHolograms {
2428

2529
private const val resourcePath = "Hologram/config.yml"
@@ -63,17 +67,26 @@ object MatrixHolograms {
6367
requests.clear()
6468
}
6569

70+
/**
71+
* Reload hologram settings and rebuild the active provider cache.
72+
*/
6673
fun reload() {
6774
settings = loadSettings()
6875
refreshAdapter(rebuildCached = true, force = true)
6976
}
7077

78+
/**
79+
* Return the active hologram config file.
80+
*/
7181
fun configFile(): File {
7282
val plugin = BukkitPlugin.getInstance()
7383
MatrixResourceFiles.saveResourceIfAbsent(plugin, resourcePath)
7484
return MatrixResourceFiles.dataFile(plugin, resourcePath)
7585
}
7686

87+
/**
88+
* Create or update a hologram request in the active provider.
89+
*/
7790
fun createOrUpdate(request: MatrixHologramRequest) {
7891
val qualifiedId = request.qualifiedId()
7992
if (request.lines.isEmpty()) {
@@ -85,12 +98,18 @@ object MatrixHolograms {
8598
adapter?.createOrUpdate(render(request))
8699
}
87100

101+
/**
102+
* Remove a hologram by namespace and id.
103+
*/
88104
fun remove(namespace: String, id: String) {
89105
val qualifiedId = qualifiedId(namespace, id)
90106
requests.remove(qualifiedId)
91107
adapter?.remove(qualifiedId)
92108
}
93109

110+
/**
111+
* Remove all holograms in a namespace.
112+
*/
94113
fun clearNamespace(namespace: String) {
95114
val prefix = "${namespace.trim().ifBlank { "matrix" }.lowercase()}_"
96115
val keys = requests.keys.filter { it.startsWith(prefix) }
@@ -100,10 +119,16 @@ object MatrixHolograms {
100119
}
101120
}
102121

122+
/**
123+
* Return the configured default vertical offset.
124+
*/
103125
fun defaultHeight(): Double {
104126
return settings.defaultHeight
105127
}
106128

129+
/**
130+
* Return the selected provider name or a status marker.
131+
*/
107132
fun providerSummary(): String {
108133
return if (!settings.enabled) {
109134
"disabled"
@@ -112,6 +137,9 @@ object MatrixHolograms {
112137
}
113138
}
114139

140+
/**
141+
* Whether the hologram bridge is enabled in config.
142+
*/
115143
fun isEnabled(): Boolean {
116144
return settings.enabled
117145
}

0 commit comments

Comments
 (0)