2025-12-17 18:41:31 +09:00
|
|
|
package com.beemer.essentials.command
|
|
|
|
|
|
|
|
|
|
import com.beemer.essentials.config.PlayerConfig
|
|
|
|
|
import com.beemer.essentials.config.SpawnConfig
|
|
|
|
|
import com.beemer.essentials.data.Location
|
|
|
|
|
import com.beemer.essentials.util.CommandUtils
|
|
|
|
|
import com.beemer.essentials.util.DimensionUtils
|
2025-12-29 15:13:37 +09:00
|
|
|
import com.beemer.essentials.util.MessageUtils
|
2025-12-30 19:40:36 +09:00
|
|
|
import com.beemer.essentials.util.SoundUtils
|
2025-12-17 18:41:31 +09:00
|
|
|
import net.minecraft.commands.Commands
|
|
|
|
|
import net.neoforged.bus.api.SubscribeEvent
|
|
|
|
|
import net.neoforged.neoforge.event.RegisterCommandsEvent
|
|
|
|
|
|
|
|
|
|
object SpawnCommand {
|
2025-12-29 15:13:37 +09:00
|
|
|
@SubscribeEvent
|
|
|
|
|
fun onRegisterCommands(event: RegisterCommandsEvent) {
|
|
|
|
|
listOf("setspawn", "스폰설정").forEach { command ->
|
|
|
|
|
event.dispatcher.register(
|
|
|
|
|
Commands.literal(command).executes { context ->
|
|
|
|
|
val player =
|
|
|
|
|
CommandUtils.getPlayerOrSendFailure(context.source)
|
|
|
|
|
?: return@executes 0
|
2025-12-17 18:41:31 +09:00
|
|
|
|
2025-12-29 15:13:37 +09:00
|
|
|
val exactPos = player.position()
|
|
|
|
|
val blockPos = player.blockPosition()
|
|
|
|
|
val dimension =
|
|
|
|
|
player.level().dimension().location().toString()
|
|
|
|
|
val biome =
|
|
|
|
|
player.level()
|
|
|
|
|
.getBiome(blockPos)
|
|
|
|
|
.unwrapKey()
|
|
|
|
|
.map { it.location().toString() }
|
|
|
|
|
.orElse("minecraft:plains")
|
2025-12-17 18:41:31 +09:00
|
|
|
|
2025-12-29 15:13:37 +09:00
|
|
|
val location =
|
|
|
|
|
Location(
|
|
|
|
|
dimension = dimension,
|
|
|
|
|
biome = biome,
|
|
|
|
|
x = exactPos.x,
|
|
|
|
|
y = exactPos.y,
|
|
|
|
|
z = exactPos.z
|
|
|
|
|
)
|
2025-12-17 18:41:31 +09:00
|
|
|
|
2025-12-29 15:13:37 +09:00
|
|
|
SpawnConfig.setCustomSpawn(location)
|
|
|
|
|
MessageUtils.sendSuccess(player, "스폰 지점이 현재 위치로 설정되었습니다.")
|
|
|
|
|
1
|
2025-12-18 21:47:11 +09:00
|
|
|
}
|
|
|
|
|
)
|
2025-12-29 15:13:37 +09:00
|
|
|
}
|
2025-12-17 18:41:31 +09:00
|
|
|
|
2025-12-29 15:13:37 +09:00
|
|
|
listOf("spawn", "스폰", "넴주").forEach { command ->
|
|
|
|
|
event.dispatcher.register(
|
|
|
|
|
Commands.literal(command).executes { context ->
|
|
|
|
|
val player =
|
|
|
|
|
CommandUtils.getPlayerOrSendFailure(context.source)
|
|
|
|
|
?: return@executes 0
|
2025-12-17 18:41:31 +09:00
|
|
|
|
2025-12-29 15:13:37 +09:00
|
|
|
val target =
|
|
|
|
|
SpawnConfig.getCustomSpawn()
|
|
|
|
|
?: SpawnConfig.getDefaultSpawn()
|
2025-12-17 18:41:31 +09:00
|
|
|
|
2025-12-29 15:13:37 +09:00
|
|
|
target?.let { t ->
|
|
|
|
|
val level =
|
|
|
|
|
DimensionUtils.getLevelById(
|
|
|
|
|
player.server,
|
|
|
|
|
t.dimension
|
|
|
|
|
)
|
2025-12-17 18:41:31 +09:00
|
|
|
|
2025-12-29 15:13:37 +09:00
|
|
|
level?.let { l ->
|
|
|
|
|
val exactPos = player.position()
|
|
|
|
|
val blockPos = player.blockPosition()
|
|
|
|
|
val currentDimension =
|
|
|
|
|
player.level()
|
|
|
|
|
.dimension()
|
|
|
|
|
.location()
|
|
|
|
|
.toString()
|
|
|
|
|
val currentBiome =
|
|
|
|
|
player.level()
|
|
|
|
|
.getBiome(blockPos)
|
|
|
|
|
.unwrapKey()
|
|
|
|
|
.map {
|
|
|
|
|
it.location()
|
|
|
|
|
.toString()
|
|
|
|
|
}
|
|
|
|
|
.orElse("minecraft:plains")
|
2025-12-17 18:41:31 +09:00
|
|
|
|
2025-12-29 15:13:37 +09:00
|
|
|
val currentLocation =
|
|
|
|
|
Location(
|
|
|
|
|
dimension =
|
|
|
|
|
currentDimension,
|
|
|
|
|
biome = currentBiome,
|
|
|
|
|
x = exactPos.x,
|
|
|
|
|
y = exactPos.y,
|
|
|
|
|
z = exactPos.z
|
|
|
|
|
)
|
2025-12-17 18:41:31 +09:00
|
|
|
|
2025-12-29 15:13:37 +09:00
|
|
|
PlayerConfig.recordLastLocation(
|
|
|
|
|
player,
|
|
|
|
|
currentLocation
|
|
|
|
|
)
|
|
|
|
|
player.teleportTo(
|
|
|
|
|
l,
|
|
|
|
|
t.x,
|
|
|
|
|
t.y,
|
|
|
|
|
t.z,
|
|
|
|
|
player.yRot,
|
|
|
|
|
player.xRot
|
|
|
|
|
)
|
2025-12-30 19:26:10 +09:00
|
|
|
// 텔레포트 사운드 재생
|
2025-12-30 19:40:36 +09:00
|
|
|
SoundUtils.playTeleport(player)
|
2025-12-29 15:13:37 +09:00
|
|
|
MessageUtils.sendSuccess(
|
|
|
|
|
player,
|
|
|
|
|
"스폰으로 이동했습니다."
|
|
|
|
|
)
|
|
|
|
|
}
|
2025-12-18 21:47:11 +09:00
|
|
|
}
|
2025-12-29 15:13:37 +09:00
|
|
|
1
|
|
|
|
|
}
|
|
|
|
|
)
|
|
|
|
|
}
|
2025-12-17 18:41:31 +09:00
|
|
|
|
2025-12-29 15:13:37 +09:00
|
|
|
listOf("delspawn", "스폰삭제").forEach { command ->
|
|
|
|
|
event.dispatcher.register(
|
|
|
|
|
Commands.literal(command).executes { context ->
|
|
|
|
|
val player =
|
|
|
|
|
CommandUtils.getPlayerOrSendFailure(context.source)
|
|
|
|
|
?: return@executes 0
|
2025-12-17 18:41:31 +09:00
|
|
|
|
2025-12-29 15:13:37 +09:00
|
|
|
SpawnConfig.removeCustomSpawn()
|
|
|
|
|
MessageUtils.sendInfo(player, "스폰 지점이 기본 스폰 지점으로 변경되었습니다.")
|
|
|
|
|
1
|
2025-12-18 21:47:11 +09:00
|
|
|
}
|
|
|
|
|
)
|
2025-12-29 15:13:37 +09:00
|
|
|
}
|
2025-12-17 18:41:31 +09:00
|
|
|
}
|
2025-12-18 21:47:11 +09:00
|
|
|
}
|