Skip to content

Commit 1d4d332

Browse files
authored
Merge pull request #27 from SLNE-Development/feat/survival-server
feat: add player queueing functionality for survival server
2 parents 3c94dc5 + 7f36eef commit 1d4d332

4 files changed

Lines changed: 89 additions & 37 deletions

File tree

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
kotlin.code.style=official
22
kotlin.stdlib.default.dependency=false
33
org.gradle.parallel=true
4-
version=1.21.11-3.0.8-SNAPSHOT
4+
version=1.21.11-3.0.9-SNAPSHOT

gradle/libs.versions.toml

Lines changed: 0 additions & 5 deletions
This file was deleted.

src/main/kotlin/dev/slne/surf/lobby/hook/npc/SurfNpcHook.kt

Lines changed: 48 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ import dev.slne.surf.npc.api.event.NpcCollisionEvent
1515
import dev.slne.surf.npc.api.event.NpcInteractEvent
1616
import dev.slne.surf.npc.api.npc.Npc
1717
import dev.slne.surf.npc.api.npc.rotation.NpcRotationType
18-
import dev.slne.surf.npc.api.surfNpcApi
1918
import dev.slne.surf.queue.api.queue
2019
import dev.slne.surf.surfapi.core.api.font.toSmallCaps
2120
import dev.slne.surf.surfapi.core.api.messages.adventure.clickOpensUrl
@@ -51,22 +50,6 @@ object SurfNpcHook {
5150
plugin.logger.info("Successfully loaded surf-npc integration.")
5251
}
5352

54-
fun reload() {
55-
surfNpcApi.deleteNpc(survivalNpc)
56-
surfNpcApi.deleteNpc(eventNpc)
57-
surfNpcApi.deleteNpc(spawnRulesNpc)
58-
surfNpcApi.deleteNpc(spawnSurvivalNpc)
59-
surfNpcApi.deleteNpc(spawnEventNpc)
60-
surfNpcApi.deleteNpc(shopNpc)
61-
62-
createSurvivalNpc()
63-
createEventNpc()
64-
createSpawnRulesNpc()
65-
createSpawnSurvivalNpc()
66-
createSpawnEventNpc()
67-
createSpawnShopNpc()
68-
}
69-
7053
private fun createSurvivalNpc() {
7154
survivalNpc = npc {
7255
displayName = {
@@ -80,16 +63,7 @@ object SurfNpcHook {
8063
rotationType = NpcRotationType.FIXED
8164

8265
withEventHandler<NpcInteractEvent> {
83-
it.player.sendText {
84-
spacer("[")
85-
note("Nepomuk")
86-
spacer("]")
87-
appendSpace()
88-
error("Ich konnte noch keine Verbindung zum Planeten \"Survival\" herstellen...")
89-
}
90-
it.player.playSound(true) {
91-
type(Sound.UI_CARTOGRAPHY_TABLE_TAKE_RESULT)
92-
}
66+
queueToSurvivalServer(it.player)
9367
}
9468
}
9569
}
@@ -277,6 +251,53 @@ object SurfNpcHook {
277251
} ?: error("Event server with name ${lobbyConfig.eventServerName} not found")
278252
}
279253

254+
private fun queueToSurvivalServer(player: Player) {
255+
surfCoreApi.getServerByName(lobbyConfig.survivalServerName)
256+
?.let { server ->
257+
plugin.launch {
258+
if (player.hasPermission(PermissionRegistry.QUEUE_BYPASS)) {
259+
player.sendText {
260+
appendInfoPrefix()
261+
info("Du hast die Warteschlange umgangen und wirst nun mit dem Survival Server verbunden...")
262+
}
263+
val status = surfCoreApi.sendPlayerAwaiting(player.surfPlayer, server)
264+
265+
if (status.isSuccessful()) {
266+
player.sendText {
267+
appendSuccessPrefix()
268+
success("Du wurdest erfolgreich zum Survival Server teleportiert.")
269+
}
270+
} else {
271+
player.sendText {
272+
appendErrorPrefix()
273+
error("Es gab ein Problem beim Teleportieren zum Survival Server: ${status.status}")
274+
status.velocityMessage?.let {
275+
error(": ")
276+
append(it)
277+
}
278+
}
279+
}
280+
281+
return@launch
282+
}
283+
284+
val success = server.queue().enqueue(player.uniqueId)
285+
286+
if (success) {
287+
player.sendText {
288+
appendSuccessPrefix()
289+
success("Du wurdest in die Warteschlange für den Survival Server eingereiht.")
290+
}
291+
} else {
292+
player.sendText {
293+
appendErrorPrefix()
294+
error("Du bist bereits in einer Warteschlange!")
295+
}
296+
}
297+
}
298+
} ?: error("Survival server with name ${lobbyConfig.survivalServerName} not found")
299+
}
300+
280301
private lateinit var syncTask: ScheduledTask
281302

282303
fun startSyncTask() {

src/main/kotlin/dev/slne/surf/lobby/inventory/impl/NavigatorInventory.kt

Lines changed: 40 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -202,11 +202,47 @@ private val cosmeticsItem = plugin.getInvisibleItem().apply {
202202
}
203203
}
204204

205-
private val survivalServerItem = plugin.getInvisibleItem().apply {
206-
displayName {
207-
primary("Survival Server")
205+
private val survivalServerItem
206+
get() = plugin.getInvisibleItem().apply {
207+
displayName {
208+
primary("Survival Server")
209+
}
210+
211+
buildLore {
212+
emptyLine()
213+
line {
214+
note("Status:".toSmallCaps())
215+
}
216+
line {
217+
when (surfCoreApi.getServerByName(lobbyConfig.survivalServerName)?.state) {
218+
SurfServerState.RUNNING -> {
219+
success("Der Survival Server ist erreichbar")
220+
}
221+
222+
else -> {
223+
error("Der Survival Server ist derzeit nicht erreichbar")
224+
}
225+
}
226+
}
227+
if (surfCoreApi.getServerByName(lobbyConfig.survivalServerName)?.state == SurfServerState.RUNNING) {
228+
emptyLine()
229+
line {
230+
note("Spieler:".toSmallCaps())
231+
}
232+
233+
line {
234+
val playerCount =
235+
surfCoreApi.getServerByName(lobbyConfig.survivalServerName)
236+
?.getPlayerCount()
237+
?: -1
238+
val maxPlayers =
239+
surfCoreApi.getServerByName(lobbyConfig.survivalServerName)?.maxPlayers
240+
?: -1
241+
info("$playerCount / $maxPlayers Spieler online")
242+
}
243+
}
244+
}
208245
}
209-
}
210246

211247
private val eventServerItem
212248
get() = plugin.getInvisibleItem().apply {

0 commit comments

Comments
 (0)