Skip to content

Commit 52a1f2d

Browse files
authored
Merge pull request #23 from SLNE-Development/feat/docs
Feat/docs
2 parents dd8f028 + a84d791 commit 52a1f2d

File tree

11 files changed

+382
-15
lines changed

11 files changed

+382
-15
lines changed

.idea/php.xml

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

surf-api-core/surf-api-core-api/src/main/kotlin/dev/slne/surf/surfapi/core/api/SurfCoreApi.kt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,22 @@ interface SurfCoreApi {
1616
*/
1717
fun sendPlayerToServer(playerUuid: UUID, server: String)
1818

19+
/**
20+
* Returns the platform-specific player object for the specified player.
21+
*/
1922
fun getPlayer(playerUuid: UUID): Any?
2023

2124
companion object {
25+
26+
/**
27+
* The instance of the SurfCoreApi.
28+
*/
2229
@JvmStatic
2330
val instance = requiredService<SurfCoreApi>()
2431
}
2532
}
2633

34+
/**
35+
* The instance of the SurfCoreApi.
36+
*/
2737
val surfCoreApi get() = SurfCoreApi.instance

surf-api-core/surf-api-core-api/src/main/kotlin/dev/slne/surf/surfapi/core/api/collection/TransformingObjectSet.kt

Lines changed: 103 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,29 +3,127 @@ package dev.slne.surf.surfapi.core.api.collection
33
import it.unimi.dsi.fastutil.objects.ObjectIterator
44
import it.unimi.dsi.fastutil.objects.ObjectSet
55

6+
/**
7+
* A specialized implementation of [ObjectSet] that transforms elements between two types, `O` and `M`, using
8+
* the provided transformation functions. This enables a dynamic view of a set where elements are transformed
9+
* on-the-fly during iteration or when performing operations.
10+
*
11+
* @param O The type of the elements in the underlying set.
12+
* @param M The type of the transformed elements in this set.
13+
* @property fromSet The underlying set containing elements of type `O`.
14+
* @property toTransformer A function that transforms elements of type `O` to type `M`. Can return null to filter out elements.
15+
* @property fromTransformer A function that transforms elements of type `M` to type `O`. Can return null to filter out elements.
16+
*/
617
class TransformingObjectSet<O, M>(
718
private val fromSet: ObjectSet<O>,
819
private val toTransformer: (O) -> M?,
920
private val fromTransformer: (M) -> O?,
1021
) : ObjectSet<M> {
22+
23+
/**
24+
* Returns an iterator that transforms elements from the underlying set during iteration.
25+
*
26+
* @return An iterator over the transformed elements of type `M`.
27+
*/
1128
override fun iterator() = object : ObjectIterator<M> {
1229
private val iterator = fromSet.iterator()
1330
override fun remove() = iterator.remove()
1431
override fun next(): M? = toTransformer(iterator.next())
1532
override fun hasNext() = iterator.hasNext()
1633
}
1734

35+
/**
36+
* Adds a transformed element to the underlying set.
37+
*
38+
* @param element The element of type `M` to add.
39+
* @return `true` if the underlying set was modified, `false` otherwise.
40+
*/
1841
override fun add(element: M?) = fromSet.add(transformFrom(element))
42+
43+
/**
44+
* Removes a transformed element from the underlying set.
45+
*
46+
* @param element The element of type `M` to remove.
47+
* @return `true` if the element was removed, `false` otherwise.
48+
*/
1949
override fun remove(element: M) = fromSet.remove(transformFrom(element))
20-
override fun addAll(elements: Collection<M?>) = fromSet.addAll(elements.mapNotNull(::transformFrom))
21-
override fun removeAll(elements: Collection<M?>) = fromSet.removeAll(elements.mapNotNull(::transformFrom))
22-
override fun retainAll(elements: Collection<M?>) = fromSet.retainAll(elements.mapNotNull(::transformFrom))
50+
51+
/**
52+
* Adds all transformed elements from the given collection to the underlying set.
53+
*
54+
* @param elements A collection of elements of type `M`.
55+
* @return `true` if the underlying set was modified, `false` otherwise.
56+
*/
57+
override fun addAll(elements: Collection<M?>) =
58+
fromSet.addAll(elements.mapNotNull(::transformFrom))
59+
60+
/**
61+
* Removes all transformed elements in the given collection from the underlying set.
62+
*
63+
* @param elements A collection of elements of type `M`.
64+
* @return `true` if the underlying set was modified, `false` otherwise.
65+
*/
66+
override fun removeAll(elements: Collection<M?>) =
67+
fromSet.removeAll(elements.mapNotNull(::transformFrom))
68+
69+
/**
70+
* Retains only the transformed elements in the given collection in the underlying set.
71+
*
72+
* @param elements A collection of elements of type `M`.
73+
* @return `true` if the underlying set was modified, `false` otherwise.
74+
*/
75+
override fun retainAll(elements: Collection<M?>) =
76+
fromSet.retainAll(elements.mapNotNull(::transformFrom))
77+
78+
/**
79+
* Removes all elements from the underlying set.
80+
*/
2381
override fun clear() = fromSet.clear()
82+
83+
/**
84+
* Returns the number of elements in the transformed set.
85+
*
86+
* @return The size of the underlying set.
87+
*/
2488
override val size: Int get() = fromSet.size
89+
90+
/**
91+
* Checks if the transformed set is empty.
92+
*
93+
* @return `true` if the underlying set is empty, `false` otherwise.
94+
*/
2595
override fun isEmpty() = fromSet.isEmpty()
96+
97+
/**
98+
* Checks if the transformed set contains the specified element.
99+
*
100+
* @param element The element of type `M` to check.
101+
* @return `true` if the element is in the transformed set, `false` otherwise.
102+
*/
26103
override fun contains(element: M?) = fromSet.contains(transformFrom(element))
27-
override fun containsAll(elements: Collection<M?>) = fromSet.containsAll(elements.mapNotNull(::transformFrom))
28104

105+
/**
106+
* Checks if the transformed set contains all elements in the specified collection.
107+
*
108+
* @param elements A collection of elements of type `M`.
109+
* @return `true` if all elements are in the transformed set, `false` otherwise.
110+
*/
111+
override fun containsAll(elements: Collection<M?>) =
112+
fromSet.containsAll(elements.mapNotNull(::transformFrom))
113+
114+
/**
115+
* Transforms an element of type `M` to type `O` using the provided [fromTransformer].
116+
*
117+
* @param element The element of type `M`.
118+
* @return The transformed element of type `O`, or `null` if the transformation is not possible.
119+
*/
29120
private fun transformFrom(element: M?) = if (element != null) fromTransformer(element) else null
121+
122+
/**
123+
* Transforms an element of type `O` to type `M` using the provided [toTransformer].
124+
*
125+
* @param element The element of type `O`.
126+
* @return The transformed element of type `M`, or `null` if the transformation is not possible.
127+
*/
30128
private fun transformTo(element: O?) = if (element != null) toTransformer(element) else null
31-
}
129+
}

surf-api-core/surf-api-core-api/src/main/kotlin/dev/slne/surf/surfapi/core/api/command/SurfCommandUtil.kt

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,40 @@ package dev.slne.surf.surfapi.core.api.command
33
import dev.slne.surf.surfapi.core.api.command.builder.CommandExceptionBuilder
44
import dev.slne.surf.surfapi.core.api.command.exception.WrapperCommandExceptionComponent
55
import net.kyori.adventure.text.ComponentLike
6-
import org.jetbrains.annotations.ApiStatus
76

8-
@ApiStatus.NonExtendable
7+
/**
8+
* Utility object for command-related operations and error handling in the Surf API.
9+
* Provides methods to create and throw custom command exceptions with user-friendly error messages.
10+
*/
911
object SurfCommandUtil {
12+
13+
/**
14+
* Creates a custom exception with the given message.
15+
*
16+
* @param message The message to include in the exception, as a [ComponentLike].
17+
* @return An instance of [WrapperCommandExceptionComponent].
18+
*/
1019
@JvmStatic
1120
fun createException(message: ComponentLike) =
1221
WrapperCommandExceptionComponent(message.asComponent())
1322

23+
/**
24+
* Throws a custom command exception with the given message.
25+
*
26+
* @param message The message to include in the exception, as a [ComponentLike].
27+
* @throws WrapperCommandExceptionComponent Always throws the created exception.
28+
*/
1429
@JvmStatic
1530
fun failWithMessage(message: ComponentLike) {
1631
throw createException(message)
1732
}
1833

34+
/**
35+
* Throws a custom command exception using a provided [CommandExceptionBuilder].
36+
*
37+
* @param builder The builder used to construct the exception message.
38+
* @throws WrapperCommandExceptionComponent Always throws the created exception.
39+
*/
1940
@JvmStatic
2041
fun failWithBuilder(builder: CommandExceptionBuilder) {
2142
throw createException(builder.build())

surf-api-core/surf-api-core-api/src/main/kotlin/dev/slne/surf/surfapi/core/api/command/exception/WrapperCommandExceptionComponent.kt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,12 @@ import dev.slne.surf.surfapi.core.api.messages.ComponentMessage
77
import net.kyori.adventure.text.Component
88
import java.io.Serial
99

10+
/**
11+
* A wrapper for [CommandSyntaxException] to integrate custom error messages
12+
* as [Component] objects within the Surf API.
13+
*
14+
* @param errorMessage The error message to associate with the exception.
15+
*/
1016
class WrapperCommandExceptionComponent(errorMessage: Component) : WrapperCommandSyntaxException(
1117
CommandSyntaxException(
1218
SimpleCommandExceptionType(

0 commit comments

Comments
 (0)