2025-12-17 18:41:31 +09:00
|
|
|
package com.beemer.essentials.nickname
|
|
|
|
|
|
2025-12-29 15:13:37 +09:00
|
|
|
import com.beemer.essentials.util.MessageUtils
|
2025-12-17 18:41:31 +09:00
|
|
|
import com.mojang.brigadier.arguments.StringArgumentType
|
|
|
|
|
import net.minecraft.commands.Commands
|
|
|
|
|
import net.minecraft.server.level.ServerPlayer
|
|
|
|
|
import net.neoforged.bus.api.SubscribeEvent
|
|
|
|
|
import net.neoforged.neoforge.event.RegisterCommandsEvent
|
|
|
|
|
|
2025-12-23 10:07:50 +09:00
|
|
|
/** 닉네임 명령어 /닉네임 변경 <닉네임> /닉네임 초기화 */
|
2025-12-17 18:41:31 +09:00
|
|
|
object NicknameCommand {
|
2025-12-23 10:07:50 +09:00
|
|
|
@SubscribeEvent
|
|
|
|
|
fun onRegisterCommands(event: RegisterCommandsEvent) {
|
|
|
|
|
// 한글 명령어
|
|
|
|
|
event.dispatcher.register(
|
|
|
|
|
Commands.literal("닉네임")
|
|
|
|
|
.then(
|
|
|
|
|
Commands.literal("변경")
|
|
|
|
|
.then(
|
|
|
|
|
Commands.argument(
|
|
|
|
|
"닉네임",
|
|
|
|
|
StringArgumentType
|
|
|
|
|
.greedyString()
|
|
|
|
|
)
|
|
|
|
|
.executes { context ->
|
|
|
|
|
val player =
|
|
|
|
|
context.source
|
|
|
|
|
.entity as?
|
|
|
|
|
ServerPlayer
|
|
|
|
|
?: return@executes 0
|
|
|
|
|
val nickname =
|
|
|
|
|
StringArgumentType
|
|
|
|
|
.getString(
|
|
|
|
|
context,
|
|
|
|
|
"닉네임"
|
|
|
|
|
)
|
|
|
|
|
.trim()
|
|
|
|
|
executeSet(player, nickname)
|
|
|
|
|
}
|
|
|
|
|
)
|
|
|
|
|
)
|
|
|
|
|
.then(
|
|
|
|
|
Commands.literal("초기화").executes { context ->
|
|
|
|
|
val player =
|
|
|
|
|
context.source.entity as? ServerPlayer
|
|
|
|
|
?: return@executes 0
|
|
|
|
|
executeReset(player)
|
|
|
|
|
}
|
|
|
|
|
)
|
2025-12-17 18:41:31 +09:00
|
|
|
)
|
2025-12-23 10:07:50 +09:00
|
|
|
|
|
|
|
|
// 영어 명령어
|
|
|
|
|
event.dispatcher.register(
|
|
|
|
|
Commands.literal("nickname")
|
|
|
|
|
.then(
|
|
|
|
|
Commands.literal("set")
|
|
|
|
|
.then(
|
|
|
|
|
Commands.argument(
|
|
|
|
|
"name",
|
|
|
|
|
StringArgumentType
|
|
|
|
|
.greedyString()
|
|
|
|
|
)
|
|
|
|
|
.executes { context ->
|
|
|
|
|
val player =
|
|
|
|
|
context.source
|
|
|
|
|
.entity as?
|
|
|
|
|
ServerPlayer
|
|
|
|
|
?: return@executes 0
|
|
|
|
|
val nickname =
|
|
|
|
|
StringArgumentType
|
|
|
|
|
.getString(
|
|
|
|
|
context,
|
|
|
|
|
"name"
|
|
|
|
|
)
|
|
|
|
|
.trim()
|
|
|
|
|
executeSet(player, nickname)
|
|
|
|
|
}
|
|
|
|
|
)
|
|
|
|
|
)
|
|
|
|
|
.then(
|
|
|
|
|
Commands.literal("reset").executes { context ->
|
|
|
|
|
val player =
|
|
|
|
|
context.source.entity as? ServerPlayer
|
|
|
|
|
?: return@executes 0
|
|
|
|
|
executeReset(player)
|
|
|
|
|
}
|
|
|
|
|
)
|
2025-12-17 18:41:31 +09:00
|
|
|
)
|
2025-12-23 10:07:50 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private fun executeSet(player: ServerPlayer, nickname: String): Int {
|
|
|
|
|
// 유효성 검사: 길이
|
|
|
|
|
if (nickname.length < 2 || nickname.length > 16) {
|
2025-12-29 15:13:37 +09:00
|
|
|
MessageUtils.sendError(player, "닉네임은 2~16자 사이여야 합니다.")
|
2025-12-23 10:07:50 +09:00
|
|
|
return 0
|
|
|
|
|
}
|
|
|
|
|
|
2025-12-30 19:26:10 +09:00
|
|
|
// 유효성 검사: 현재 닉네임과 동일
|
|
|
|
|
val currentNickname = NicknameDataStore.getNickname(player.uuid)
|
|
|
|
|
if (currentNickname == nickname) {
|
|
|
|
|
MessageUtils.sendError(player, "현재 사용 중인 닉네임과 동일합니다.")
|
|
|
|
|
return 0
|
|
|
|
|
}
|
|
|
|
|
|
2025-12-23 10:07:50 +09:00
|
|
|
// 유효성 검사: 중복
|
|
|
|
|
if (NicknameDataStore.isNicknameTaken(nickname, player.uuid)) {
|
2025-12-29 15:13:37 +09:00
|
|
|
MessageUtils.sendError(player, "이미 사용 중인 닉네임입니다.")
|
2025-12-23 10:07:50 +09:00
|
|
|
return 0
|
|
|
|
|
}
|
|
|
|
|
|
2025-12-29 15:13:37 +09:00
|
|
|
// 닉네임 저장 및 적용
|
2025-12-23 10:07:50 +09:00
|
|
|
NicknameDataStore.setNickname(player.uuid, player.gameProfile.name, nickname)
|
|
|
|
|
NicknameManager.applyNickname(player, nickname)
|
|
|
|
|
|
2025-12-29 15:13:37 +09:00
|
|
|
MessageUtils.sendSuccess(player, "닉네임이 {$nickname}(으)로 변경되었습니다.")
|
2025-12-23 10:07:50 +09:00
|
|
|
return 1
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private fun executeReset(player: ServerPlayer): Int {
|
|
|
|
|
if (!NicknameDataStore.hasNickname(player.uuid)) {
|
2025-12-29 15:13:37 +09:00
|
|
|
MessageUtils.sendError(player, "설정된 닉네임이 없습니다.")
|
2025-12-23 10:07:50 +09:00
|
|
|
return 0
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
NicknameDataStore.removeNickname(player.uuid)
|
|
|
|
|
NicknameManager.removeNickname(player)
|
|
|
|
|
|
2025-12-29 15:13:37 +09:00
|
|
|
MessageUtils.sendSuccess(player, "닉네임이 초기화되었습니다.")
|
2025-12-23 10:07:50 +09:00
|
|
|
return 1
|
2025-12-17 18:41:31 +09:00
|
|
|
}
|
|
|
|
|
}
|