Skip to content

Commit 78b09b2

Browse files
committed
refactor: Kotlin official codestyles
1 parent b0e2a94 commit 78b09b2

File tree

34 files changed

+177
-141
lines changed

34 files changed

+177
-141
lines changed

surf-npc-api/src/main/kotlin/dev/slne/surf/npc/api/SurfNpcApi.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,16 @@ import dev.slne.surf.npc.api.npc.Npc
44
import dev.slne.surf.npc.api.npc.location.NpcLocation
55
import dev.slne.surf.npc.api.npc.property.NpcProperty
66
import dev.slne.surf.npc.api.npc.property.NpcPropertyType
7-
import dev.slne.surf.npc.api.result.NpcCreationResult
8-
import dev.slne.surf.npc.api.result.NpcDeletionResult
97
import dev.slne.surf.npc.api.npc.rotation.NpcRotation
108
import dev.slne.surf.npc.api.npc.rotation.NpcRotationType
119
import dev.slne.surf.npc.api.npc.skin.NpcSkin
10+
import dev.slne.surf.npc.api.result.NpcCreationResult
11+
import dev.slne.surf.npc.api.result.NpcDeletionResult
1212
import dev.slne.surf.surfapi.core.api.util.requiredService
1313
import it.unimi.dsi.fastutil.objects.ObjectList
1414
import it.unimi.dsi.fastutil.objects.ObjectSet
1515
import net.kyori.adventure.text.Component
16-
import java.util.UUID
16+
import java.util.*
1717

1818
/**
1919
* API for managing NPCs (Non-Player Characters) in the Surf framework.

surf-npc-api/src/main/kotlin/dev/slne/surf/npc/api/dsl/NpcDslBuilder.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@ package dev.slne.surf.npc.api.dsl
22

33
import dev.slne.surf.npc.api.npc.location.NpcLocation
44
import dev.slne.surf.npc.api.npc.property.NpcProperty
5-
import dev.slne.surf.npc.api.result.NpcCreationResult
65
import dev.slne.surf.npc.api.npc.rotation.NpcRotation
76
import dev.slne.surf.npc.api.npc.rotation.NpcRotationType
87
import dev.slne.surf.npc.api.npc.skin.NpcSkin
8+
import dev.slne.surf.npc.api.result.NpcCreationResult
99
import dev.slne.surf.npc.api.surfNpcApi
1010
import net.kyori.adventure.text.Component
1111

surf-npc-api/src/main/kotlin/dev/slne/surf/npc/api/dsl/NpcDslSubBuilders.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,8 @@ class NpcPropertyBuilder {
117117
/**
118118
* The type of the property. Defaults to the "string" type.
119119
*/
120-
var type: NpcPropertyType = surfNpcApi.getPropertyType("string") ?: error("Default property type 'string' not found")
120+
var type: NpcPropertyType =
121+
surfNpcApi.getPropertyType("string") ?: error("Default property type 'string' not found")
121122

122123
/**
123124
* Builds the NPC property.

surf-npc-api/src/main/kotlin/dev/slne/surf/npc/api/event/NpcCollisionEvent.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@ import org.bukkit.event.HandlerList
1111
* @property npc The NPC involved in the collision.
1212
* @property player The player who collided with the NPC.
1313
*/
14-
class NpcCollisionEvent (
14+
class NpcCollisionEvent(
1515
val npc: Npc,
1616
val player: Player
17-
): Event() {
17+
) : Event() {
1818

1919
/**
2020
* Returns the handler list for this event.

surf-npc-api/src/main/kotlin/dev/slne/surf/npc/api/event/NpcCreateEvent.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import org.bukkit.event.HandlerList
99
*
1010
* @property npc The NPC that was created.
1111
*/
12-
class NpcCreateEvent (
12+
class NpcCreateEvent(
1313
val npc: Npc
1414
) : Event() {
1515

surf-npc-api/src/main/kotlin/dev/slne/surf/npc/api/event/NpcDeleteEvent.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import org.bukkit.event.HandlerList
99
*
1010
* @property npc The NPC that was deleted.
1111
*/
12-
class NpcDeleteEvent (
12+
class NpcDeleteEvent(
1313
val npc: Npc
1414
) : Event() {
1515

surf-npc-api/src/main/kotlin/dev/slne/surf/npc/api/event/NpcDespawnEvent.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import org.bukkit.event.HandlerList
1111
* @property npc The NPC that despawned.
1212
* @property player The player associated with the despawn event, if applicable.
1313
*/
14-
class NpcDespawnEvent (
14+
class NpcDespawnEvent(
1515
val npc: Npc,
1616
val player: Player
1717
) : Event() {

surf-npc-api/src/main/kotlin/dev/slne/surf/npc/api/event/NpcSpawnEvent.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import org.bukkit.event.HandlerList
1111
* @property npc The NPC that was spawned.
1212
* @property player The player associated with the spawn event, if applicable.
1313
*/
14-
class NpcSpawnEvent (
14+
class NpcSpawnEvent(
1515
val npc: Npc,
1616
val player: Player
1717
) : Event() {

surf-npc-bukkit/src/main/kotlin/dev/slne/surf/npc/bukkit/BukkitMain.kt

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,30 +4,21 @@ import com.github.retrooper.packetevents.PacketEvents
44
import com.github.retrooper.packetevents.event.PacketListenerPriority
55
import com.github.shynixn.mccoroutine.folia.SuspendingJavaPlugin
66
import dev.slne.surf.npc.api.npc.property.NpcPropertyType
7-
87
import dev.slne.surf.npc.bukkit.command.NpcCommand
98
import dev.slne.surf.npc.bukkit.listener.ConnectionListener
109
import dev.slne.surf.npc.bukkit.listener.NpcListener
11-
import dev.slne.surf.npc.bukkit.npc.property.impl.BooleanPropertyType
12-
import dev.slne.surf.npc.bukkit.npc.property.impl.ComponentPropertyType
13-
import dev.slne.surf.npc.bukkit.npc.property.impl.DoublePropertyType
14-
import dev.slne.surf.npc.bukkit.npc.property.impl.FloatPropertyType
15-
import dev.slne.surf.npc.bukkit.npc.property.impl.IntPropertyType
16-
import dev.slne.surf.npc.bukkit.npc.property.impl.LongPropertyType
17-
import dev.slne.surf.npc.bukkit.npc.property.impl.NamedTextColorPropertyType
18-
import dev.slne.surf.npc.bukkit.npc.property.impl.NpcLocationPropertyType
19-
import dev.slne.surf.npc.bukkit.npc.property.impl.NpcRotationPropertyType
20-
import dev.slne.surf.npc.bukkit.npc.property.impl.StringPropertyType
21-
import dev.slne.surf.npc.bukkit.npc.property.impl.UuidPropertyType
10+
import dev.slne.surf.npc.bukkit.npc.property.impl.*
2211
import dev.slne.surf.npc.core.property.propertyTypeRegistry
2312
import dev.slne.surf.npc.core.service.storageService
24-
2513
import org.bukkit.Bukkit
2614
import org.bukkit.plugin.java.JavaPlugin
2715

2816
class BukkitMain : SuspendingJavaPlugin() {
2917
override fun onEnable() {
30-
PacketEvents.getAPI().eventManager.registerListener(NpcListener(), PacketListenerPriority.NORMAL)
18+
PacketEvents.getAPI().eventManager.registerListener(
19+
NpcListener(),
20+
PacketListenerPriority.NORMAL
21+
)
3122
Bukkit.getPluginManager().registerEvents(ConnectionListener(), this)
3223

3324
propertyTypeRegistry.register(BooleanPropertyType(NpcPropertyType.Types.BOOLEAN))

surf-npc-bukkit/src/main/kotlin/dev/slne/surf/npc/bukkit/BukkitPackets.kt

Lines changed: 39 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -7,31 +7,33 @@ import com.github.retrooper.packetevents.protocol.player.GameMode
77
import com.github.retrooper.packetevents.protocol.player.UserProfile
88
import com.github.retrooper.packetevents.util.Vector3d
99
import com.github.retrooper.packetevents.wrapper.play.server.*
10-
import com.github.retrooper.packetevents.wrapper.play.server.WrapperPlayServerTeams
1110
import io.github.retrooper.packetevents.util.SpigotConversionUtil
1211
import net.kyori.adventure.text.Component
1312
import net.kyori.adventure.text.format.NamedTextColor
1413
import org.bukkit.Location
15-
import java.util.UUID
14+
import java.util.*
1615

17-
fun createPlayerInfoPacket(profile: UserProfile, displayName: Component, listed: Boolean = false) = WrapperPlayServerPlayerInfoUpdate(
18-
WrapperPlayServerPlayerInfoUpdate.Action.ADD_PLAYER,
19-
WrapperPlayServerPlayerInfoUpdate.PlayerInfo(
20-
profile,
21-
listed,
22-
0,
23-
GameMode.SURVIVAL,
24-
displayName,
25-
null
16+
fun createPlayerInfoPacket(profile: UserProfile, displayName: Component, listed: Boolean = false) =
17+
WrapperPlayServerPlayerInfoUpdate(
18+
WrapperPlayServerPlayerInfoUpdate.Action.ADD_PLAYER,
19+
WrapperPlayServerPlayerInfoUpdate.PlayerInfo(
20+
profile,
21+
listed,
22+
0,
23+
GameMode.SURVIVAL,
24+
displayName,
25+
null
26+
)
2627
)
27-
)
28+
2829
fun createEntityMetadataPacket(npcEntityId: Int) = WrapperPlayServerEntityMetadata(
2930
npcEntityId,
3031
listOf(
3132
EntityData(17, EntityDataTypes.BYTE, 0x7F.toByte()),
3233
EntityData(0, EntityDataTypes.BYTE, 0x02.toByte()),
3334
)
3435
)
36+
3537
fun createPlayerSpawnPacket(
3638
entityId: Int,
3739
uuid: UUID,
@@ -42,11 +44,18 @@ fun createPlayerSpawnPacket(
4244
entityId,
4345
uuid,
4446
EntityTypes.PLAYER,
45-
com.github.retrooper.packetevents.protocol.world.Location(Vector3d(location.x, location.y, location.z), yaw, pitch),
47+
com.github.retrooper.packetevents.protocol.world.Location(
48+
Vector3d(
49+
location.x,
50+
location.y,
51+
location.z
52+
), yaw, pitch
53+
),
4654
yaw,
4755
0,
4856
null
4957
)
58+
5059
fun createNametagSpawnPacket(
5160
entityId: Int,
5261
uuid: UUID,
@@ -55,11 +64,18 @@ fun createNametagSpawnPacket(
5564
entityId,
5665
uuid,
5766
EntityTypes.TEXT_DISPLAY,
58-
com.github.retrooper.packetevents.protocol.world.Location(Vector3d(location.x, location.y + 2, location.z), 0f, 0f),
67+
com.github.retrooper.packetevents.protocol.world.Location(
68+
Vector3d(
69+
location.x,
70+
location.y + 2,
71+
location.z
72+
), 0f, 0f
73+
),
5974
0f,
6075
0,
6176
null
6277
)
78+
6379
fun createNametagMetadataPacket(
6480
entityId: Int,
6581
displayName: Component
@@ -71,6 +87,7 @@ fun createNametagMetadataPacket(
7187
EntityData(27, EntityDataTypes.BYTE, 0x02.toByte())
7288
)
7389
)
90+
7491
fun createTeamCreatePacket(
7592
teamName: String,
7693
displayName: Component
@@ -96,14 +113,17 @@ fun createTeamAddEntityPacket(teamName: String, entityUuid: String) = WrapperPla
96113
nullInfo,
97114
entityUuid
98115
)
116+
99117
fun createDestroyPacket(vararg entityIds: Int) = WrapperPlayServerDestroyEntities(*entityIds)
100118
fun createPlayerInfoRemovePacket(npcUuid: UUID) = WrapperPlayServerPlayerInfoRemove(npcUuid)
101119
fun createRotationPackets(entityId: Int, yaw: Float, pitch: Float) = Pair(
102120
WrapperPlayServerEntityRotation(entityId, yaw, pitch, true),
103121
WrapperPlayServerEntityHeadLook(entityId, yaw)
104122
)
105-
fun createTeleportPacket(entityId: Int, location: Location, onGround: Boolean = false) = WrapperPlayServerEntityTeleport(
106-
entityId,
107-
SpigotConversionUtil.fromBukkitLocation(location),
108-
onGround
109-
)
123+
124+
fun createTeleportPacket(entityId: Int, location: Location, onGround: Boolean = false) =
125+
WrapperPlayServerEntityTeleport(
126+
entityId,
127+
SpigotConversionUtil.fromBukkitLocation(location),
128+
onGround
129+
)

0 commit comments

Comments
 (0)