Skip to content

Commit b563581

Browse files
refactor: extract repetitive skin assignment logic into assignSkin helper function
1 parent cca20d5 commit b563581

File tree

1 file changed

+20
-53
lines changed

1 file changed

+20
-53
lines changed

src/main/kotlin/dev/slne/surf/essentials/command/SkinChangeCommand.kt

Lines changed: 20 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import com.github.shynixn.mccoroutine.folia.launch
66
import dev.jorel.commandapi.kotlindsl.*
77
import dev.slne.surf.essentials.plugin
88
import dev.slne.surf.essentials.util.permission.EssentialsPermissionRegistry
9+
import dev.slne.surf.essentials.util.skin.SkinData
910
import dev.slne.surf.essentials.util.skin.retrieveSkin
1011
import dev.slne.surf.surfapi.core.api.messages.adventure.sendText
1112
import kotlinx.coroutines.withContext
@@ -31,19 +32,7 @@ fun skinChangeCommand() = commandTree("skin") {
3132
return@launch
3233
}
3334

34-
val profile = player.playerProfile.apply {
35-
setProperty(
36-
ProfileProperty(
37-
"textures",
38-
skinData.value,
39-
skinData.signature
40-
)
41-
)
42-
}
43-
44-
withContext(plugin.entityDispatcher(player)) {
45-
player.playerProfile = profile
46-
}
35+
assignSkin(player, skinData)
4736

4837
player.sendText {
4938
appendPrefix()
@@ -78,19 +67,7 @@ fun skinChangeCommand() = commandTree("skin") {
7867
return@launch
7968
}
8069

81-
val profile = target.playerProfile.apply {
82-
setProperty(
83-
ProfileProperty(
84-
"textures",
85-
skinData.value,
86-
skinData.signature
87-
)
88-
)
89-
}
90-
91-
withContext(plugin.entityDispatcher(target)) {
92-
target.playerProfile = profile
93-
}
70+
assignSkin(target, skinData)
9471

9572
executor.sendText {
9673
appendPrefix()
@@ -126,19 +103,7 @@ fun skinChangeCommand() = commandTree("skin") {
126103
return@launch
127104
}
128105

129-
val profile = player.playerProfile.apply {
130-
setProperty(
131-
ProfileProperty(
132-
"textures",
133-
skinData.value,
134-
skinData.signature
135-
)
136-
)
137-
}
138-
139-
withContext(plugin.entityDispatcher(player)) {
140-
player.playerProfile = profile
141-
}
106+
assignSkin(player, skinData)
142107

143108
player.sendText {
144109
appendPrefix()
@@ -170,19 +135,7 @@ fun skinChangeCommand() = commandTree("skin") {
170135
return@launch
171136
}
172137

173-
val profile = target.playerProfile.apply {
174-
setProperty(
175-
ProfileProperty(
176-
"textures",
177-
skinData.value,
178-
skinData.signature
179-
)
180-
)
181-
}
182-
183-
withContext(plugin.entityDispatcher(target)) {
184-
target.playerProfile = profile
185-
}
138+
assignSkin(target, skinData)
186139

187140
executor.sendText {
188141
appendPrefix()
@@ -199,4 +152,18 @@ fun skinChangeCommand() = commandTree("skin") {
199152
}
200153
}
201154
}
202-
}
155+
}
156+
157+
private suspend fun assignSkin(player: Player, skin: SkinData) =
158+
withContext(plugin.entityDispatcher(player)) {
159+
val profile = player.playerProfile.apply {
160+
setProperty(
161+
ProfileProperty(
162+
"textures",
163+
skin.value,
164+
skin.signature
165+
)
166+
)
167+
}
168+
player.playerProfile = profile
169+
}

0 commit comments

Comments
 (0)