Skip to content

Commit 43bf8e8

Browse files
committed
utils ktdoc cleanup
1 parent 9315d3f commit 43bf8e8

File tree

24 files changed

+51
-634
lines changed

24 files changed

+51
-634
lines changed

src/main/kotlin/com/lambda/util/EnchantmentUtils.kt

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,6 @@ import net.minecraft.registry.RegistryKey
2727
import net.minecraft.registry.entry.RegistryEntry
2828

2929
object EnchantmentUtils {
30-
/**
31-
* Returns the list of enchantments from a given [ItemStack]
32-
*/
3330
val ItemStack.enchantments: ItemEnchantmentsComponent
3431
get() = getOrDefault(DataComponentTypes.ENCHANTMENTS, ItemEnchantmentsComponent.DEFAULT)
3532

@@ -40,21 +37,12 @@ object EnchantmentUtils {
4037
get() = !getOrDefault(DataComponentTypes.ENCHANTMENTS, ItemEnchantmentsComponent.DEFAULT).isEmpty
4138
|| !getOrDefault(DataComponentTypes.STORED_ENCHANTMENTS, ItemEnchantmentsComponent.DEFAULT).isEmpty
4239

43-
/**
44-
* Returns the given enchantment level from a [net.minecraft.item.ItemStack]
45-
*/
4640
fun ItemStack.getEnchantment(key: RegistryKey<Enchantment>) =
4741
enchantments.enchantmentEntries.find { it.key?.matchesKey(key) == true }?.intValue ?: 0
4842

49-
/**
50-
* Iterates over all the enchantments for the given [ItemStack]
51-
*/
5243
fun <T> ItemStack.forEachEnchantment(block: (RegistryEntry<Enchantment>, Int) -> T) =
5344
enchantments.enchantmentEntries.map { block(it.key, it.intValue) }
5445

55-
/**
56-
* Iterates over all the enchantments of the given [net.minecraft.entity.LivingEntity]'s [EquipmentSlot]
57-
*/
5846
fun <T> LivingEntity.forEachSlot(
5947
vararg slots: EquipmentSlot,
6048
block: (entry: RegistryEntry<Enchantment>, level: Int) -> T

src/main/kotlin/com/lambda/util/FileUtils.kt

Lines changed: 3 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -61,34 +61,17 @@ object FileUtils {
6161
return path
6262
}
6363

64-
/**
65-
* Executes the [block] if the file is older than the given [duration]
66-
*/
6764
inline fun File.isOlderThan(duration: Duration, block: (File) -> Unit) =
6865
ifExists { if (duration.inWholeMilliseconds < System.currentTimeMillis() - lastModified()) block(this) }
6966

70-
/**
71-
* Returns whether the receiver file is older than [duration]
72-
*/
7367
fun File.isOlderThan(duration: Duration) =
7468
duration.inWholeMilliseconds < System.currentTimeMillis() - lastModified()
7569

76-
/**
77-
* Executes the [block] if the receiver file exists and is not empty
78-
*/
7970
inline fun File.ifExists(block: (File) -> Unit): File {
8071
if (length() > 0) block(this)
8172
return this
8273
}
8374

84-
/**
85-
* Ensures the current file exists by creating it if it does not.
86-
*
87-
* If the file already exists, it will not be recreated. The necessary
88-
* parent directories will be created if they do not exist.
89-
*
90-
* @param block Lambda executed if the file doesn't exist or the file is empty
91-
*/
9275
inline fun File.createIfNotExists(block: (File) -> Unit = {}): File {
9376
if (length() == 0L) {
9477
parentFile.mkdirs()
@@ -100,24 +83,15 @@ object FileUtils {
10083
return this
10184
}
10285

103-
/**
104-
* Executes the [block] if the receiver file does not exist or is empty.
105-
*/
10686
inline fun File.ifNotExists(block: (File) -> Unit): File {
10787
if (length() == 0L) block(this)
10888
return this
10989
}
11090

11191
/**
112-
* Modifies the receiver file if the downloaded file compare check succeeds
113-
*
114-
* @receiver The destination file to write the bytes to
115-
*
116-
* @param url The url to download the file from
117-
* @param compare Compare method. -1 if remote is larger. 0 if both file have the same size. 1 if local is larger
118-
* @param block Configuration block for the request
119-
*
120-
* @return An exception or the file
92+
* Changes the local file if [compare]:
93+
* - is -1 and the remote is larger
94+
* - is 1 and local is larger
12195
*/
12296
suspend fun File.downloadCompare(
12397
url: String,
@@ -133,72 +107,21 @@ object FileUtils {
133107
}
134108
}
135109

136-
/**
137-
* Downloads the given file url if the file is not present
138-
*
139-
* @receiver The destination file to write the bytes to
140-
*
141-
* @param url The url to download the file from
142-
* @param block Configuration block for the request
143-
*
144-
* @return An exception or the file
145-
*/
146110
suspend fun File.downloadIfNotPresent(
147111
url: String,
148112
block: HttpRequestBuilder.() -> Unit = {},
149113
) = runCatching { createIfNotExists { LambdaHttp.download(url, this, block) } }
150114

151-
/**
152-
* Downloads the given file url if the file is not present
153-
*
154-
* @receiver The url to download the file from
155-
*
156-
* @param file The destination file to write the bytes to
157-
* @param block Configuration block for the request
158-
*
159-
* @return An exception or the file
160-
*/
161115
suspend fun String.downloadIfNotPresent(
162116
file: File,
163117
block: HttpRequestBuilder.() -> Unit = {},
164118
) = runCatching { file.createIfNotExists { LambdaHttp.download(this, file, block) } }
165119

166-
/**
167-
* Lambda that downloads the given file url if the file is not present
168-
*
169-
* @receiver The destination file to write the bytes to
170-
* @param block Configuration block for the request
171-
*
172-
* @return A lambda that returns an exception or the file
173-
*/
174-
fun File.downloadIfNotPresent(block: HttpRequestBuilder.() -> Unit = {}): suspend (String) -> Result<Unit> =
175-
{ url -> runCatching { createIfNotExists { LambdaHttp.download(url, this, block) } } }
176-
177-
/**
178-
* Downloads the given file url if the file is present
179-
*
180-
* @receiver The destination file to write the bytes to
181-
*
182-
* @param url The url to download the file from
183-
* @param block Configuration block for the request
184-
*
185-
* @return An exception or the file
186-
*/
187120
suspend fun File.downloadIfPresent(
188121
url: String,
189122
block: HttpRequestBuilder.() -> Unit = {},
190123
) = runCatching { ifExists { LambdaHttp.download(url, this, block) } }
191124

192-
/**
193-
* Downloads the given file url if the file is present
194-
*
195-
* @receiver The url to download the file from
196-
*
197-
* @param file The destination file to write the bytes to
198-
* @param block Configuration block for the request
199-
*
200-
* @return An exception or the file
201-
*/
202125
suspend fun String.downloadIfPresent(
203126
file: File,
204127
block: HttpRequestBuilder.() -> Unit = {},

src/main/kotlin/com/lambda/util/FolderRegister.kt

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,6 @@ import kotlin.io.path.notExists
3131

3232
/**
3333
* The [FolderRegister] object is responsible for managing the directory structure of the application.
34-
*
35-
* @property minecraft The root directory of the Minecraft client.
36-
* @property lambda The directory for the Lambda client, located within the Minecraft directory.
37-
* @property config The directory for storing configuration files, located within the Lambda directory.
38-
* @property packetLogs The directory for storing packet logs, located within the Lambda directory.
39-
* @property replay The directory for storing replay files, located within the Lambda directory.
4034
*/
4135
object FolderRegister : Loadable {
4236
val minecraft: Path = mc.runDirectory.toPath()

src/main/kotlin/com/lambda/util/KeyCode.kt

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -155,14 +155,7 @@ enum class KeyCode(val code: Int) {
155155
private val keyCodeMap = entries.associateBy { it.code }
156156
private val nameMap = entries.associateBy { it.name.lowercase() }
157157

158-
/**
159-
* Returns the KeyCode enum instance from the key code number or [Unbound] if invalid
160-
*/
161158
fun fromKeyCode(keyCode: Int) = keyCodeMap[keyCode] ?: Unbound
162-
163-
/**
164-
* Returns the KeyCode enum instance from the key code name or [Unbound] if invalid
165-
*/
166159
fun fromKeyName(name: String) = nameMap[name.lowercase()] ?: Unbound
167160

168161
/**
@@ -172,10 +165,6 @@ enum class KeyCode(val code: Int) {
172165
* If the key corresponds to a printable character or letter, it is mapped
173166
* to its corresponding [KeyCode] based on the US layout.
174167
*
175-
* @param keyCode The key code to map.
176-
* @param scanCode The scan code of the key.
177-
* @return The corresponding [KeyCode].
178-
*
179168
* @see <a href="https://github.com/glfw/glfw/issues/1502#issuecomment-1005841055">ImGui impl
180169
*/
181170
fun virtualMapUS(keyCode: Int, scanCode: Int): KeyCode {

src/main/kotlin/com/lambda/util/Nameables.kt

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,6 @@
1717

1818
package com.lambda.util
1919

20-
/**
21-
* @property name represents the name or identifier of the object.
22-
*/
2320
interface Nameable {
2421
val name: String
2522
val commandName get() = name.trim().replace(' ', '_')

src/main/kotlin/com/lambda/util/PacketUtils.kt

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,17 +26,13 @@ import net.minecraft.network.packet.Packet
2626
object PacketUtils {
2727
/**
2828
* Sends a packet through the regular packet pipeline
29-
*
30-
* @param block Lambda that returns the packet to be sent
3129
*/
3230
fun ClientPlayNetworkHandler.sendPacket(block: () -> Packet<*>) = connection.send(block())
3331

3432
/**
3533
* Sends a packet to the server without notifying the client.
3634
* It bypasses the mixins that would normally intercept the packet
3735
* and send it through the client's event bus.
38-
*
39-
* @param packet The packet to send.
4036
*/
4137
fun ClientPlayNetworkHandler.sendPacketSilently(packet: Packet<*>) {
4238
if (!connection.isOpen || connection.packetListener?.accepts(packet) == true) return
@@ -49,8 +45,6 @@ object PacketUtils {
4945
* Handles a packet without notifying the client.
5046
* It bypasses the mixins that would normally intercept the packet
5147
* and send it through the client's event bus.
52-
*
53-
* @param packet The packet to handle.
5448
*/
5549
fun ClientPlayNetworkHandler.handlePacketSilently(packet: Packet<*>) {
5650
if (!connection.isOpen || connection.packetListener?.accepts(packet) == false) return

src/main/kotlin/com/lambda/util/Pointer.kt

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,6 @@ package com.lambda.util
2020
import kotlin.properties.ReadWriteProperty
2121
import kotlin.reflect.KProperty
2222

23-
/**
24-
* A class representing a pointer to a value.
25-
*
26-
* It is a high-level abstraction over a mutable variable that allows for easy access to the value.
27-
*/
2823
data class Pointer<T>(var value: T? = null) : ReadWriteProperty<Any?, T?> {
2924
override fun getValue(thisRef: Any?, property: KProperty<*>): T? = value
3025
override fun setValue(thisRef: Any?, property: KProperty<*>, value: T?) {

src/main/kotlin/com/lambda/util/StringUtils.kt

Lines changed: 7 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -25,49 +25,31 @@ import kotlin.io.encoding.Base64
2525
import kotlin.io.encoding.ExperimentalEncodingApi
2626

2727
object StringUtils {
28-
/**
29-
* Returns a sanitized file path for both Unix and Linux systems
30-
*/
3128
fun String.sanitizeForFilename() =
3229
replace(Regex("[\\\\/:*?\"<>|]"), "_")
3330
.trim()
3431
.take(255) // truncate to 255 characters for Windows compatibility
3532

3633

37-
/**
38-
* Capitalizes the first character of a string using its Unicode mapping
39-
*/
4034
fun String.capitalize() = replaceFirstChar { it.titlecase() }
4135

42-
/**
43-
* Returns a Minecraft [net.minecraft.util.Identifier] from a string with the given namespace
44-
*/
4536
fun String.toIdentifier(namespace: String = Lambda.MOD_ID): Identifier =
4637
Identifier.of(namespace, this)
4738

48-
/**
49-
* Returns a [Lambda] Minecraft [Identifier] from a string
50-
*/
5139
val String.asIdentifier: Identifier get() = toIdentifier()
5240

5341
/**
5442
* Find similar strings in a set of words.
5543
*
56-
* @param target The string to compare against.
57-
* @param words The set of words to compare against.
58-
* @param threshold The maximum Levenshtein distance between the target and the words.
44+
* @see <a href="https://en.wikipedia.org/wiki/Levenshtein_distance">Levenshtein distance</a<
5945
*/
60-
fun findSimilarStrings(
61-
target: String,
46+
fun String.findSimilarStrings(
6247
words: Set<String>,
6348
threshold: Int,
64-
) = words.filter { it.levenshteinDistance(target) <= threshold }.toSet()
49+
) = words.filter { it.levenshteinDistance(this) <= threshold }.toSet()
6550

6651
/**
67-
* See [Levenshtein distance](https://en.wikipedia.org/wiki/Levenshtein_distance)
68-
*
69-
* @receiver The string to compare.
70-
* @param rhs The string to compare against.
52+
* @see <a href="https://en.wikipedia.org/wiki/Levenshtein_distance">Levenshtein distance</a<
7153
*/
7254
fun CharSequence.levenshteinDistance(rhs: CharSequence): Int {
7355
if (this == rhs) {
@@ -108,11 +90,6 @@ object StringUtils {
10890
return cost[len0 - 1]
10991
}
11092

111-
/**
112-
* Takes the receiver string and decodes it to the input type
113-
*
114-
* @return Instance of [T]
115-
*/
11693
inline fun <reified T : Any> String.json() = gson.fromJson(this, T::class.java)
11794

11895
/**
@@ -122,39 +99,21 @@ object StringUtils {
12299
fun String.base64UrlDecode() = Base64.UrlSafe.decode(this).decodeToString()
123100

124101
/**
125-
* See [MessageDigest section](https://docs.oracle.com/en/java/javase/11/docs/specs/security/standard-names.html#messagedigest-algorithms) of the Java Security Standard Algorithm Names Specification
126-
*
127-
* @receiver The string to hash
128-
* @param algorithm The algorithm instance to use
129-
* @param extra Additional data to digest with the string
130-
*
131-
* @return The string representation of the hash
102+
* @see <a href="https://docs.oracle.com/en/java/javase/11/docs/specs/security/standard-names.html#messagedigest-algorithms">Java Security Standard Algorithm Names Specification</a>
132103
*/
133104
fun String.hashString(algorithm: String, vararg extra: ByteArray): String =
134105
toByteArray().hash(algorithm, *extra)
135106
.joinToString(separator = "") { "%02x".format(it) }
136107

137108
/**
138-
* See [MessageDigest section](https://docs.oracle.com/en/java/javase/11/docs/specs/security/standard-names.html#messagedigest-algorithms) of the Java Security Standard Algorithm Names Specification
139-
*
140-
* @receiver The byte array to hash
141-
* @param algorithm The algorithm instance to use
142-
* @param extra Additional data to digest with the byte array
143-
*
144-
* @return The string representation of the hash
109+
* @see <a href="https://docs.oracle.com/en/java/javase/11/docs/specs/security/standard-names.html#messagedigest-algorithms">Java Security Standard Algorithm Names Specification</a>
145110
*/
146111
fun ByteArray.hashString(algorithm: String, vararg extra: ByteArray): String =
147112
hash(algorithm, *extra)
148113
.joinToString(separator = "") { "%02x".format(it) }
149114

150115
/**
151-
* See [MessageDigest section](https://docs.oracle.com/en/java/javase/11/docs/specs/security/standard-names.html#messagedigest-algorithms) of the Java Security Standard Algorithm Names Specification
152-
*
153-
* @receiver The byte array to hash
154-
* @param algorithm The algorithm instance to use
155-
* @param extra Additional data to digest with the byte array
156-
*
157-
* @return The digested data
116+
* @see <a href="https://docs.oracle.com/en/java/javase/11/docs/specs/security/standard-names.html#messagedigest-algorithms">Java Security Standard Algorithm Names Specification</a>
158117
*/
159118
fun ByteArray.hash(algorithm: String, vararg extra: ByteArray): ByteArray =
160119
MessageDigest

0 commit comments

Comments
 (0)