Skip to content

Commit

Permalink
add chat prefix and convenience component extensions
Browse files Browse the repository at this point in the history
  • Loading branch information
btwonion committed Aug 25, 2024
1 parent a1699f6 commit 5addbe9
Show file tree
Hide file tree
Showing 6 changed files with 71 additions and 16 deletions.
42 changes: 42 additions & 0 deletions src/main/kotlin/dev/nyon/skylper/extensions/Component.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package dev.nyon.skylper.extensions

import net.minecraft.ChatFormatting
import net.minecraft.network.chat.Component
import net.minecraft.network.chat.MutableComponent
import java.awt.Color

val skylperPrefix: Component = Component.empty().also {
val skylperString = "skylper"
val startColor = Color(0xFFB500)
val endColor = Color(0xB91C2A)

val stepSize = 1.0 / skylperString.length

skylperString.forEachIndexed { index, char ->
val percent = stepSize * index
val inversePercent: Double = 1.0 - percent
val color = Color(
(startColor.red * percent + endColor.red * inversePercent).toInt(),
(startColor.green * percent + endColor.green * inversePercent).toInt(),
(startColor.blue * percent + endColor.blue * inversePercent).toInt()
)

it += Component.literal(char.toString())
.withColor(color.red * 65536 + color.green * 256 + color.blue)
.withStyle(ChatFormatting.BOLD)
}

it += Component.literal(" ")
}

fun chatTranslatable(key: String, vararg arguments: Any): Component {
return skylperPrefix + Component.translatable(key, *arguments)
}

operator fun Component.plus(other: Component): Component {
return this.copy().append(other)
}

operator fun MutableComponent.plusAssign(other: Component) {
this.append(other)
}
14 changes: 12 additions & 2 deletions src/main/kotlin/dev/nyon/skylper/skyblock/Command.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@ import com.mojang.brigadier.builder.LiteralArgumentBuilder
import dev.nyon.konfig.config.saveConfig
import dev.nyon.skylper.config.config
import dev.nyon.skylper.config.screen.createYaclScreen
import dev.nyon.skylper.extensions.chatTranslatable
import dev.nyon.skylper.extensions.command.arg
import dev.nyon.skylper.extensions.command.arguments.ClientBlockPosArgument
import dev.nyon.skylper.extensions.command.executeAsync
import dev.nyon.skylper.extensions.command.sub
import dev.nyon.skylper.extensions.skylperPrefix
import dev.nyon.skylper.minecraft
import dev.nyon.skylper.skyblock.data.api.CrystalHollowsLocationApi
import dev.nyon.skylper.skyblock.data.online.OnlineData
Expand Down Expand Up @@ -51,7 +53,7 @@ fun registerRootCommand() {
}

context.source.sendFeedback(
Component.translatable(
chatTranslatable(
"chat.skylper.hollows.command.waypoint_created", specific.displayName
)
)
Expand All @@ -72,7 +74,7 @@ fun registerRootCommand() {

CrystalHollowsLocationApi.waypoints.removeAll { it.specific == specific }
context.source.sendFeedback(
Component.translatable(
chatTranslatable(
"chat.skylper.hollows.command.waypoint_deleted", specific.displayName
)
)
Expand Down Expand Up @@ -100,6 +102,14 @@ fun registerRootCommand() {
}
}
}

root.sub("debug") { debug ->
debug.sub("prefix") { prefix ->
prefix.executeAsync {
it.source.sendFeedback(skylperPrefix)
}
}
}
})
})
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package dev.nyon.skylper.skyblock.cooldowns

import dev.nyon.skylper.config.config
import dev.nyon.skylper.extensions.chatTranslatable
import dev.nyon.skylper.extensions.event.MessageEvent
import dev.nyon.skylper.extensions.event.SkyblockEnterEvent
import dev.nyon.skylper.extensions.event.SkylperEvent
Expand Down Expand Up @@ -87,8 +88,7 @@ object MiningCooldown : Cooldown {
}

private fun noAbilitySelectedNotice() {
minecraft.player?.sendSystemMessage(Component.translatable("chat.skylper.hollows.pickaxe_cooldown.not_found")
.withStyle { it.withColor(ChatFormatting.RED) })
minecraft.player?.sendSystemMessage(chatTranslatable("chat.skylper.hollows.pickaxe_cooldown.not_found"))
}

override fun getCooldownTime(): Duration? {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,12 @@ object CrystalHollowsChatLocation {
invokeEvent(LocatedHollowsStructureEvent(hollowsLocation))

minecraft.player?.sendSystemMessage(
Component.translatable(
"chat.skylper.hollows.locations.found", matchingSpecific.displayName.string, pos.x, pos.y, pos.z
chatTranslatable(
"chat.skylper.hollows.locations.found",
matchingSpecific.displayName.string,
pos.x,
pos.y,
pos.z
)
)
return
Expand All @@ -146,7 +150,7 @@ object CrystalHollowsChatLocation {
acc.append(new.withStyle(ChatFormatting.RED))
}

val finalComponent = Component.translatable("chat.skylper.hollows.locations.pick", locationsComponent)
val finalComponent = chatTranslatable("chat.skylper.hollows.locations.pick", locationsComponent)
minecraft.player?.sendSystemMessage(finalComponent)
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
package dev.nyon.skylper.skyblock.misc

import dev.nyon.skylper.config.config
import dev.nyon.skylper.extensions.chatTranslatable
import dev.nyon.skylper.extensions.event.LevelChangeEvent
import dev.nyon.skylper.extensions.event.MessageEvent
import dev.nyon.skylper.extensions.event.SkyblockQuitEvent
import dev.nyon.skylper.extensions.event.SkylperEvent
import dev.nyon.skylper.extensions.regex
import dev.nyon.skylper.extensions.singleGroup
import dev.nyon.skylper.minecraft
import net.minecraft.ChatFormatting
import net.minecraft.network.chat.Component

object LobbyRecognition {
private val joinedLobbies = mutableSetOf<String>()
Expand All @@ -36,7 +35,7 @@ object LobbyRecognition {
if (!config.misc.recognizeLobbies) return
if (!containsServerAlready) return
minecraft.player?.sendSystemMessage(
Component.translatable("chat.skylper.misc.lobby_recognition").withStyle(ChatFormatting.GRAY)
chatTranslatable("chat.skylper.misc.lobby_recognition")
)
}
}
12 changes: 6 additions & 6 deletions src/main/resources/assets/skylper/lang/en_us.json
Original file line number Diff line number Diff line change
Expand Up @@ -139,8 +139,8 @@
"menu.skylper.overlay.hollows.total_powder.gemstone": "Gemstone Powder",
"menu.skylper.overlay.hollows.total_powder.glacite": "Glacite Powder",
"menu.skylper.keybinding.location_screen": "Open Crystal Hollows Location screen",
"chat.skylper.hollows.locations.found": "[skylper] Found %d with the coordinates %d, %d, %d!",
"chat.skylper.hollows.locations.pick": "[skylper] Click the structure that this coordinates belongs to: %d",
"chat.skylper.hollows.locations.found": "Found %d with the coordinates %d, %d, %d!",
"chat.skylper.hollows.locations.pick": "Click the structure that this coordinates belong to: %d",
"chat.skylper.hollows.locations.nucleus": "Crystal Nucleus",
"chat.skylper.hollows.locations.precursor_city": "Precursor City",
"chat.skylper.hollows.locations.jungle_temple": "Jungle Temple",
Expand All @@ -153,8 +153,8 @@
"chat.skylper.hollows.locations.goblin_king": "King Yolkar",
"chat.skylper.hollows.locations.goblin_queen": "Goblin Queen's Den",
"chat.skylper.hollows.locations.khazad_dum": "Khazad Dûm",
"chat.skylper.hollows.command.waypoint_created": "[skylper] Successfully created waypoint for %d!",
"chat.skylper.hollows.command.waypoint_deleted": "[skylper] The waypoint %d was deleted successfully!",
"chat.skylper.hollows.pickaxe_cooldown.not_found": "[skylper] No Pickaxe Ability could be found. If this is an error, please open the Heart of the Mountain (/hotm) screen!",
"chat.skylper.misc.lobby_recognition": "[skylper] You've been in this lobby!"
"chat.skylper.hollows.command.waypoint_created": "Successfully created waypoint for %d!",
"chat.skylper.hollows.command.waypoint_deleted": "The waypoint %d was deleted successfully!",
"chat.skylper.hollows.pickaxe_cooldown.not_found": "No Pickaxe Ability could be found. If this is an error, please open the Heart of the Mountain (/hotm) screen!",
"chat.skylper.misc.lobby_recognition": "You've been in this lobby!"
}

0 comments on commit 5addbe9

Please sign in to comment.