Skip to content

Commit

Permalink
reformat
Browse files Browse the repository at this point in the history
  • Loading branch information
MeiNanziiii committed Jan 15, 2025
1 parent 11923a1 commit d468b83
Show file tree
Hide file tree
Showing 9 changed files with 23 additions and 33 deletions.
9 changes: 5 additions & 4 deletions src/main/kotlin/ua/mei/minekord/Minekord.kt
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,7 @@ object Minekord : ModInitializer {
}

ServerMessageEvents.CHAT_MESSAGE.register { message, sender, type ->
ChatMessageEvent.EVENT.invoker()
.message(message.content, MessageSender(sender.gameProfile.name, sender.avatarUrl))
ChatMessageEvent.EVENT.invoker().message(message.content, MessageSender(sender.gameProfile.name, sender.avatarUrl))
}
ServerMessageEvents.COMMAND_MESSAGE.register { message, source, parameters ->
if (source.isExecutedByPlayer) {
Expand All @@ -63,8 +62,10 @@ object Minekord : ModInitializer {
MessageSender(source.player!!.gameProfile.name, source.player!!.avatarUrl)
)
} else {
ChatMessageEvent.EVENT.invoker()
.message(message.content, MessageSender(Chat.Webhook.webhookName, Chat.Webhook.webhookAvatar))
ChatMessageEvent.EVENT.invoker().message(
message.content,
MessageSender(Chat.Webhook.webhookName, Chat.Webhook.webhookAvatar)
)
}
}
ServerLifecycleEvents.SERVER_STARTING.register(IPCache)
Expand Down
6 changes: 1 addition & 5 deletions src/main/kotlin/ua/mei/minekord/MinekordCommands.kt
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,7 @@ import net.minecraft.text.Text
import ua.mei.minekord.config.MinekordConfig

object MinekordCommands : CommandRegistrationCallback {
override fun register(
dispatcher: CommandDispatcher<ServerCommandSource>,
access: CommandRegistryAccess,
environment: CommandManager.RegistrationEnvironment
) {
override fun register(dispatcher: CommandDispatcher<ServerCommandSource>, access: CommandRegistryAccess, environment: CommandManager.RegistrationEnvironment) {
dispatcher.register(
literal<ServerCommandSource>("minekord")
.requires(Permissions.require("minekord.main", 4))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,7 @@ class IPCheckExtension : MinekordExtension() {

MinekordBot.launch {
try {
val member: Member = MinekordBot.guild.members.firstOrNull {
it.effectiveName == name && it.roleIds.map { it.value }.containsAll(Auth.requiredRoles)
} ?: return@launch
val member: Member = MinekordBot.guild.members.firstOrNull { it.effectiveName == name && it.roleIds.map { it.value }.containsAll(Auth.requiredRoles) } ?: return@launch

member.getDmChannelOrNull()?.createMessage {
embed {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ class MessagesExtension : MinekordExtension() {
val sender: Member = event.member ?: return@action

var content: Text = if (Chat.convertMarkdown) {
MinecraftSerializer.INSTANCE.serialize(message.content, MinekordBot.minecraftOptions)
MinecraftSerializer.INSTANCE
.serialize(message.content, MinekordBot.minecraftOptions)
.native(server.registryManager)
} else {
message.content.literal()
Expand All @@ -51,8 +52,7 @@ class MessagesExtension : MinekordExtension() {
).native(server.registryManager)

val reply: Text = Chat.Minecraft.replyFormat.toText(server) {
"sender" to (message.referencedMessage!!.author?.effectiveName
?: message.referencedMessage!!.data.author.username).literal()
"sender" to (message.referencedMessage!!.author?.effectiveName ?: message.referencedMessage!!.data.author.username).literal()
"message" to replyContent
"summary" to replyContent.string.summary().literal()
}
Expand Down
11 changes: 5 additions & 6 deletions src/main/kotlin/ua/mei/minekord/event/AdvancementGrantEvent.kt
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,12 @@ fun interface AdvancementGrantEvent {
fun grant(player: ServerPlayerEntity, advancement: Advancement)

companion object {
val EVENT: Event<AdvancementGrantEvent> =
EventFactory.createArrayBacked(AdvancementGrantEvent::class.java) { listeners ->
AdvancementGrantEvent { player, advancement ->
listeners.forEach { listener ->
listener.grant(player, advancement)
}
val EVENT: Event<AdvancementGrantEvent> = EventFactory.createArrayBacked(AdvancementGrantEvent::class.java) { listeners ->
AdvancementGrantEvent { player, advancement ->
listeners.forEach { listener ->
listener.grant(player, advancement)
}
}
}
}
}
5 changes: 1 addition & 4 deletions src/main/kotlin/ua/mei/minekord/util/Extensions.kt
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,7 @@ fun String.summary(): String {

fun GameProfile.texture(): String {
return try {
JsonParser.parseString(
Base64.getDecoder().decode(this.properties.get("textures").firstOrNull()?.value ?: "")
.toString(Charsets.UTF_8)
)
JsonParser.parseString(Base64.getDecoder().decode(this.properties.get("textures").firstOrNull()?.value ?: "").toString(Charsets.UTF_8))
.asJsonObject
.getAsJsonObject("textures")
.getAsJsonObject("SKIN")
Expand Down
5 changes: 1 addition & 4 deletions src/main/kotlin/ua/mei/minekord/util/LuckPermsUtils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,7 @@ object LuckPermsUtils {

suspend fun syncPlayer(nickname: String) {
if (!MinekordConfig.LuckPerms.roles.isEmpty() && FabricLoader.getInstance().isModLoaded("luckperms")) {
val member: Member = MinekordBot.guild.members.firstOrNull {
it.effectiveName == nickname && it.roleIds.map { it.value }
.containsAll(MinekordConfig.Auth.requiredRoles)
} ?: return
val member: Member = MinekordBot.guild.members.firstOrNull { it.effectiveName == nickname && it.roleIds.map { it.value }.containsAll(MinekordConfig.Auth.requiredRoles) } ?: return

val lp: LuckPerms = LuckPermsProvider.get()
val user: User = lp.userManager.getUser(nickname) ?: return
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,11 @@ object MinekordMinecraftRenderer : DefaultMinecraftRenderer() {
return runBlocking {
val role: Role? = MinekordBot.guild.getRoleOrNull(id.asSnowflake)
val name: String = role?.name ?: "unknown-role"
val color: TextColor =
if (role != null && Chat.Minecraft.coloredRoles) TextColor.color(role.color.rgb) else Colors.mention
val color: TextColor = if (role != null && Chat.Minecraft.coloredRoles) {
TextColor.color(role.color.rgb)
} else {
Colors.mention
}

component.append("@$name".adventure().color(color))
}
Expand Down
3 changes: 1 addition & 2 deletions src/main/kotlin/ua/mei/minekord/util/SerializerUtils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@ object SerializerUtils {
val pingRegex: Regex = Regex("@(\\S{1,32})")

suspend fun convertMentions(message: String): String {
val members: Map<String, Member> =
MinekordBot.guild.members.toList().associateBy { it.effectiveName.lowercase() }
val members: Map<String, Member> = MinekordBot.guild.members.toList().associateBy { it.effectiveName.lowercase() }

return pingRegex.replace(message) { matchResult ->
val effectiveName = matchResult.groupValues[1].lowercase()
Expand Down

0 comments on commit d468b83

Please sign in to comment.