Skip to content

Commit e09cc5e

Browse files
committed
add documentation
1 parent b47d0e8 commit e09cc5e

File tree

15 files changed

+205
-19
lines changed

15 files changed

+205
-19
lines changed

build.gradle.kts

+1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
plugins {
22
kotlin("jvm") version "2.0.21"
33
kotlin("plugin.serialization") version "2.0.21"
4+
id("org.jetbrains.dokka") version "1.9.20"
45

56
id("com.gradleup.shadow") version "8.3.3"
67

src/main/kotlin/com/zp4rker/bukkot/builders/item/EnchantNode.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ package com.zp4rker.bukkot.builders.item
33
import org.bukkit.enchantments.Enchantment
44

55
/**
6-
* @author zp4rker
6+
* Node for [org.bukkit.inventory.ItemStack] enchantments
77
*/
88
class EnchantNode {
99
val set = mutableSetOf<EnchantContainer>()

src/main/kotlin/com/zp4rker/bukkot/builders/item/ItemAttributes.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import org.bukkit.attribute.Attribute
66
import org.bukkit.attribute.AttributeModifier
77

88
/**
9-
* @author zp4rker
9+
* Attributes for [org.bukkit.inventory.ItemStack]
1010
*/
1111
class ItemAttributes {
1212
val modifiers: Multimap<Attribute, AttributeModifier> = ArrayListMultimap.create()

src/main/kotlin/com/zp4rker/bukkot/builders/item/ItemBuilder.kt

+41-1
Original file line numberDiff line numberDiff line change
@@ -12,23 +12,46 @@ import org.bukkit.inventory.ItemStack
1212
import org.bukkit.inventory.meta.ItemMeta
1313

1414
/**
15-
* @author zp4rker
15+
* Creates a customised [ItemStack]
16+
*
17+
* @param type material of the itemstack
18+
* @param data customisations of itemstack
1619
*/
1720
fun item(type: Material, data: ItemStack.() -> Unit) = ItemStack(type).apply(data)
1821

22+
/**
23+
* Customises an [ItemStack]
24+
*
25+
* @param base the itemstack to start off with
26+
* @see item
27+
*/
1928
fun item(base: ItemStack, data: ItemStack.() -> Unit) = ItemStack(base).apply(data)
2029

30+
/**
31+
* Apply changes to [ItemMeta]
32+
*
33+
* @param data the meta to apply
34+
*/
2135
fun <T : ItemMeta> ItemStack.meta(data: T.() -> Unit) {
2236
val meta = itemMeta(type, data)
2337
itemMeta = meta
2438
}
2539

40+
/**
41+
* Customised [ItemMeta] for type
42+
*
43+
* @param type material to generate meta for
44+
* @param data the meta to apply
45+
*/
2646
@Suppress("UNCHECKED_CAST")
2747
fun <T : ItemMeta> itemMeta(type: Material, data: T.() -> Unit) = Bukkit.getItemFactory().getItemMeta(type)
2848
.let { it as? T }
2949
?.apply(data)
3050
?: throw IllegalArgumentException("Invalid ItemMeta for specified material.")
3151

52+
/**
53+
* [ItemMeta] lore lines as combined string in [net.kyori.adventure.text.minimessage.MiniMessage] format
54+
*/
3255
var ItemMeta.loreString: String?
3356
get() = lore()?.joinToString("\n") { it.minimessage() }
3457
set(value) {
@@ -37,9 +60,15 @@ var ItemMeta.loreString: String?
3760
}
3861
}
3962

63+
/**
64+
* [ItemMeta] lore lines in plain text
65+
*/
4066
val ItemMeta.plainLore: List<String>?
4167
get() = lore()?.map { it.plain() }
4268

69+
/**
70+
* [ItemMeta] lore lines in plain text as combined string
71+
*/
4372
val ItemMeta.plainLoreString: String?
4473
get() = plainLore?.joinToString("\n")
4574

@@ -61,6 +90,11 @@ var ItemMeta.unbreakable: Boolean
6190

6291
fun ItemMeta.flag(vararg flags: ItemFlag) = addItemFlags(*flags)
6392

93+
/**
94+
* Add [ItemAttributes] to [ItemMeta]
95+
*
96+
* @param data the attributes to apply
97+
*/
6498
fun ItemMeta.attributes(data: ItemAttributes.() -> Unit) {
6599
val attributes = ItemAttributes().apply(data)
66100
val mods = attributes.modifiers
@@ -71,6 +105,12 @@ fun ItemMeta.attributes(data: ItemAttributes.() -> Unit) {
71105
}
72106
}
73107

108+
/**
109+
* Add enchants to [ItemMeta]
110+
*
111+
* @param unsafe bypass level restriction
112+
* @param data the enchants to apply
113+
*/
74114
fun ItemMeta.enchant(unsafe: Boolean = false, data: EnchantNode.() -> Unit) {
75115
EnchantNode().apply(data).set.forEach {
76116
addEnchant(it.enchantment, it.level, unsafe)

src/main/kotlin/com/zp4rker/bukkot/extensions/Component.kt

+13-1
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,21 @@ import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer
66
import net.kyori.adventure.text.serializer.plain.PlainTextComponentSerializer
77

88
/**
9-
* @author zp4rker
9+
* Convert to legacy Minecraft string (i.e. "§3Test")
1010
*/
1111
fun Component.legacy() = LegacyComponentSerializer.legacySection().serialize(this)
12+
13+
/**
14+
* Convert to json string
15+
*/
1216
fun Component.json() = JSONComponentSerializer.json().serialize(this)
17+
18+
/**
19+
* Convert to plain text. All formatting stripped
20+
*/
1321
fun Component.plain() = PlainTextComponentSerializer.plainText().serialize(this)
22+
23+
/**
24+
* Convert to minimessage format (i.e. "<gold>Hello!</gold>")
25+
*/
1426
fun Component.minimessage() = MM.serialize(this)

src/main/kotlin/com/zp4rker/bukkot/extensions/Constants.kt

+4-1
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,12 @@ import org.bukkit.Server
66
import org.bukkit.plugin.PluginManager
77

88
/**
9-
* @author zp4rker
9+
* The server plugin manager
1010
*/
1111
object PMANAGER : PluginManager by Bukkit.getPluginManager()
1212
object SERVER : Server by Bukkit.getServer()
1313

14+
/**
15+
* Instance of [MiniMessage]
16+
*/
1417
val MM = MiniMessage.miniMessage()

src/main/kotlin/com/zp4rker/bukkot/extensions/Listener.kt

+6-1
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,17 @@ import org.bukkit.event.Listener
55
import org.bukkit.plugin.java.JavaPlugin
66

77
/**
8-
* @author zp4rker
8+
* Registers listener by plugin
9+
*
10+
* @param plugin the plugin to register the listener
911
*/
1012
fun Listener.register(plugin: JavaPlugin) {
1113
PMANAGER.registerEvents(this, plugin)
1214
}
1315

16+
/**
17+
* Unregisters a listener
18+
*/
1419
fun Listener.unregister() {
1520
HandlerList.unregisterAll(this)
1621
}

src/main/kotlin/com/zp4rker/bukkot/extensions/Plugin.kt

+28-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,14 @@ import org.bukkit.scheduler.BukkitRunnable
55
import org.bukkit.scheduler.BukkitTask
66

77
/**
8-
* @author zp4rker
8+
* Run a regular [BukkitRunnable]
9+
*
10+
* @param delay ticks before task runs. Set to 0 to run immediately
11+
* @param async whether or not to run in async
12+
* @param task the task to run in the [BukkitRunnable]
13+
*
14+
* @see BukkitRunnable.runTask
15+
* @see BukkitRunnable.runTaskLater
916
*/
1017
fun Plugin.runTask(delay: Long = 0, async: Boolean = false, task: BukkitRunnable.() -> Unit): BukkitTask {
1118
return if (delay > 0) {
@@ -23,6 +30,14 @@ fun Plugin.runTask(delay: Long = 0, async: Boolean = false, task: BukkitRunnable
2330
}
2431
}
2532

33+
/**
34+
* Run a timer [BukkitRunnable]
35+
*
36+
* @param period ticks between runs
37+
*
38+
* @see runTask
39+
* @see BukkitRunnable.runTaskTimer
40+
*/
2641
fun Plugin.runTaskTimer(
2742
delay: Long = 0,
2843
period: Long = 20,
@@ -36,6 +51,15 @@ fun Plugin.runTaskTimer(
3651
}
3752
}
3853

54+
/**
55+
* Run a timer [BukkitRunnable] limited amount of times
56+
*
57+
* @param repeat amount of times to repeat task. Specified as range (useful for using within task)
58+
* @param task the task to run in the [BukkitRunnable]. Has access to repeat number
59+
*
60+
* @see IntProgression
61+
* @see runTaskTimer
62+
*/
3963
fun Plugin.repeatTask(
4064
repeat: IntProgression,
4165
delay: Long = 0,
@@ -59,6 +83,9 @@ fun Plugin.repeatTask(
5983
}
6084
}
6185

86+
/**
87+
* Class to simplify [BukkitRunnable] lambdas
88+
*/
6289
internal class LambdaRunnable(private val task: BukkitRunnable.() -> Unit) : BukkitRunnable() {
6390
override fun run() {
6491
task()

src/main/kotlin/com/zp4rker/bukkot/extensions/String.kt

+20-2
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,28 @@ import net.kyori.adventure.text.Component
55
import org.bukkit.ChatColor
66

77
/**
8-
* @author zp4rker
8+
* Colours a legacy Minecraft string (i.e. "&3Test")
9+
*/
10+
fun String.colourify(char: Char = '&') = ChatColor.translateAlternateColorCodes(char, this)
11+
12+
/**
13+
* For the Americans
14+
*
15+
* @see colourify
16+
*/
17+
fun String.colorify(char: Char = '&') = colourify(char)
18+
19+
/**
20+
* Strip colours from string
921
*/
10-
fun String.colorify(char: Char = '&') = ChatColor.translateAlternateColorCodes(char, this)
1122
fun String.stripColors() = ChatColor.stripColor(this)
1223

24+
/**
25+
* Convert plain text to [Component] for use in Paper
26+
*/
1327
fun String.component() = Component.text(this)
28+
29+
/**
30+
* Convert [net.kyori.adventure.text.minimessage.MiniMessage] format to [Component]
31+
*/
1432
fun String.minimessage() = MM.deserialize(this)

src/main/kotlin/com/zp4rker/bukkot/extensions/TimeUnit.kt

+4-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ package com.zp4rker.bukkot.extensions
33
import java.util.concurrent.TimeUnit
44

55
/**
6-
* @author zp4rker
6+
* Convert time units to ticks
77
*/
88
fun TimeUnit.toTicks(d: Long): Long {
99
return when (this) {
@@ -23,6 +23,9 @@ fun TimeUnit.toTicks(d: Long): Long {
2323
}
2424
}
2525

26+
/**
27+
* [TimeUnit] for ticks
28+
*/
2629
object TickTimeUnit {
2730
fun toNanos(ticks: Long) = ticks * 50000000
2831
fun toMicros(ticks: Long) = ticks * 50000

src/main/kotlin/com/zp4rker/bukkot/listener/Anonymous.kt

+18-1
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,33 @@ import org.bukkit.plugin.EventExecutor
88
import org.bukkit.plugin.Plugin
99

1010
/**
11-
* @author zp4rker
11+
* Interface for anonymous listeners
12+
* @see listener
1213
*/
1314
interface AnonymousListener<T : Event> : Listener {
1415
fun onEvent(event: T)
1516
}
1617

18+
/**
19+
* Creates an instance of [AnonymousListener]
20+
*
21+
* @param action the function to be executed in the listener
22+
* @return an instance of [AnonymousListener]
23+
* @see register
24+
*/
1725
inline fun <T : Event> listener(crossinline action: AnonymousListener<T>.(T) -> Unit) = object : AnonymousListener<T> {
1826
override fun onEvent(event: T) = action(event)
1927
}
2028

29+
/**
30+
* Registers an [AnonymousListener]. Parameters derived from [org.bukkit.event.EventHandler]
31+
*
32+
* @param plugin the plugin registering the listener
33+
* @param priority the listener priority
34+
* @param ignoreCancelled whether the listener should still trigger for cancelled events
35+
*
36+
* @see [com.zp4rker.bukkot.extensions.unregister]
37+
*/
2138
inline fun <reified T : Event> AnonymousListener<T>.register(
2239
plugin: Plugin,
2340
priority: EventPriority = EventPriority.NORMAL,

src/main/kotlin/com/zp4rker/bukkot/listener/Inline.kt

+19-3
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,17 @@ import java.util.concurrent.Executors
88
import java.util.concurrent.ScheduledExecutorService
99
import java.util.concurrent.TimeUnit
1010

11-
/**
12-
* @author zp4rker
13-
*/
1411
typealias Predicate<T> = (T) -> Boolean
1512

13+
/**
14+
* Register a continuous listener
15+
*
16+
* @param T the event to listen to
17+
* @param predicate function to determine pre-requisites for listener to invoke action
18+
* @param priority the listener priority
19+
* @param ignoreCancelled whether the listener should still trigger for cancelled events
20+
* @param action the function to be executed in the listener
21+
*/
1622
inline fun <reified T : Event> Plugin.on(
1723
crossinline predicate: Predicate<T> = { true },
1824
priority: EventPriority = EventPriority.NORMAL,
@@ -26,6 +32,16 @@ inline fun <reified T : Event> Plugin.on(
2632

2733
val scheduler: ScheduledExecutorService = Executors.newSingleThreadScheduledExecutor()
2834

35+
/**
36+
* Register a limited listener
37+
*
38+
* @param T the event to listen to
39+
* @param amount amount of times this listener should listen for event
40+
* @param timeout milliseconds before listener times out even if [amount] has not been reached. Set to 0 for no timeout
41+
* @param timeoutAction the function to run when the listener times out
42+
*
43+
* @see on
44+
*/
2945
inline fun <reified T : Event> Plugin.expect(
3046
crossinline predicate: Predicate<T> = { true },
3147
amount: Int = 1,

0 commit comments

Comments
 (0)