93 lines
4.2 KiB
Kotlin
93 lines
4.2 KiB
Kotlin
|
|
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
|
||
|
|
import net.minecraft.ChatFormatting
|
||
|
|
import net.minecraft.commands.Commands
|
||
|
|
import net.minecraft.network.chat.Component
|
||
|
|
import net.neoforged.bus.api.SubscribeEvent
|
||
|
|
import net.neoforged.neoforge.event.RegisterCommandsEvent
|
||
|
|
|
||
|
|
object SpawnCommand {
|
||
|
|
@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
|
||
|
|
|
||
|
|
val playerLocation = player.blockPosition()
|
||
|
|
val dimensionId = player.level().dimension().location().toString()
|
||
|
|
val biomeId = player.level().getBiome(playerLocation)
|
||
|
|
.unwrapKey()
|
||
|
|
.map { it.location().toString() }
|
||
|
|
.orElse("minecraft:plains")
|
||
|
|
|
||
|
|
val location = Location(
|
||
|
|
dimension = dimensionId,
|
||
|
|
biome = biomeId,
|
||
|
|
x = playerLocation.x.toDouble(),
|
||
|
|
y = playerLocation.y.toDouble(),
|
||
|
|
z = playerLocation.z.toDouble()
|
||
|
|
)
|
||
|
|
|
||
|
|
SpawnConfig.setCustomSpawn(location)
|
||
|
|
|
||
|
|
player.sendSystemMessage(Component.literal("스폰 지점이 현재 위치로 설정되었습니다.").withStyle { it.withColor(ChatFormatting.GOLD) })
|
||
|
|
1
|
||
|
|
}
|
||
|
|
)
|
||
|
|
}
|
||
|
|
|
||
|
|
listOf("spawn", "스폰", "넴주").forEach { command ->
|
||
|
|
event.dispatcher.register(
|
||
|
|
Commands.literal(command).executes { context ->
|
||
|
|
val player = CommandUtils.getPlayerOrSendFailure(context.source) ?: return@executes 0
|
||
|
|
|
||
|
|
val target = SpawnConfig.getCustomSpawn() ?: SpawnConfig.getDefaultSpawn()
|
||
|
|
|
||
|
|
target?.let { t ->
|
||
|
|
val level = DimensionUtils.getLevelById(player.server, t.dimension)
|
||
|
|
|
||
|
|
level?.let { l ->
|
||
|
|
val currentPos = player.blockPosition()
|
||
|
|
val currentDimension = player.level().dimension().location().toString()
|
||
|
|
val currentBiome = player.level().getBiome(currentPos)
|
||
|
|
.unwrapKey()
|
||
|
|
.map { it.location().toString() }
|
||
|
|
.orElse("minecraft:plains")
|
||
|
|
|
||
|
|
val currentLocation = Location(
|
||
|
|
dimension = currentDimension,
|
||
|
|
biome = currentBiome,
|
||
|
|
x = currentPos.x.toDouble(),
|
||
|
|
y = currentPos.y.toDouble(),
|
||
|
|
z = currentPos.z.toDouble()
|
||
|
|
)
|
||
|
|
|
||
|
|
PlayerConfig.recordLastLocation(player, currentLocation)
|
||
|
|
player.teleportTo(l, t.x, t.y, t.z, player.yRot, player.xRot)
|
||
|
|
player.sendSystemMessage(Component.literal("스폰으로 이동했습니다.").withStyle { it.withColor(ChatFormatting.GOLD) })
|
||
|
|
}
|
||
|
|
}
|
||
|
|
1
|
||
|
|
}
|
||
|
|
)
|
||
|
|
}
|
||
|
|
|
||
|
|
listOf("delspawn", "스폰삭제").forEach { command ->
|
||
|
|
event.dispatcher.register(
|
||
|
|
Commands.literal(command).executes { context ->
|
||
|
|
val player = CommandUtils.getPlayerOrSendFailure(context.source) ?: return@executes 0
|
||
|
|
|
||
|
|
SpawnConfig.removeCustomSpawn()
|
||
|
|
player.sendSystemMessage(Component.literal("스폰 지점이 기본 스폰 지점으로 변경되었습니다.").withStyle { it.withColor(ChatFormatting.GOLD) })
|
||
|
|
1
|
||
|
|
}
|
||
|
|
)
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|