Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature: click on playtime item to copy #1807

Merged
merged 5 commits into from
May 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,7 @@ import at.hannibal2.skyhanni.features.misc.BrewingStandOverlay
import at.hannibal2.skyhanni.features.misc.ButtonOnPause
import at.hannibal2.skyhanni.features.misc.CollectionTracker
import at.hannibal2.skyhanni.features.misc.ContributorManager
import at.hannibal2.skyhanni.features.misc.CopyPlaytime
import at.hannibal2.skyhanni.features.misc.CurrentPetDisplay
import at.hannibal2.skyhanni.features.misc.CustomTextBox
import at.hannibal2.skyhanni.features.misc.ExpOrbsOnGroundHider
Expand Down Expand Up @@ -932,7 +933,8 @@ class SkyHanniMod {
loadModule(MaxPurseItems())
loadModule(SuperCraftFeatures)
loadModule(InfernoMinionFeatures())
loadModule(LimboPlaytime())
loadModule(LimboPlaytime)
loadModule(CopyPlaytime)
loadModule(RareDropMessages())
loadModule(CraftMaterialsFromBazaar())
loadModule(DungeonShadowAssassinNotification())
Expand Down
41 changes: 41 additions & 0 deletions src/main/java/at/hannibal2/skyhanni/features/misc/CopyPlaytime.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package at.hannibal2.skyhanni.features.misc

import at.hannibal2.skyhanni.data.HypixelData
import at.hannibal2.skyhanni.events.GuiContainerEvent
import at.hannibal2.skyhanni.events.LorenzToolTipEvent
import at.hannibal2.skyhanni.features.misc.limbo.LimboPlaytime
import at.hannibal2.skyhanni.utils.ChatUtils
import at.hannibal2.skyhanni.utils.ClipboardUtils
import at.hannibal2.skyhanni.utils.InventoryUtils
import at.hannibal2.skyhanni.utils.LorenzUtils
import at.hannibal2.skyhanni.utils.StringUtils.firstLetterUppercase
import at.hannibal2.skyhanni.utils.StringUtils.removeColor
import net.minecraftforge.fml.common.eventhandler.EventPriority
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent

object CopyPlaytime {
@SubscribeEvent(priority = EventPriority.LOWEST)
fun onTooltip(event: LorenzToolTipEvent) {
if (InventoryUtils.openInventoryName() != "Detailed /playtime") return
if (event.slot.slotNumber != 4) return

event.toolTip.add("")
event.toolTip.add("§eClick to Copy!")
}

@SubscribeEvent
fun onSlotClicked(event: GuiContainerEvent.SlotClickEvent) {
if (InventoryUtils.openInventoryName() != "Detailed /playtime") return
if (event.slotId != 4) return
if (event.clickedButton != 0) return

event.cancel()
val text = LimboPlaytime.tooltipPlaytime.dropLast(2).toMutableList()

val profile = HypixelData.profileName.firstLetterUppercase()
text.add(0, "${LorenzUtils.getPlayerName()}'s - $profile Playtime Stats")

ClipboardUtils.copyToClipboard(text.joinToString("\n") { it.removeColor() })
ChatUtils.chat("Copied playtime stats into clipboard.")
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import net.minecraft.item.ItemStack
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent
import kotlin.time.Duration.Companion.seconds

class LimboPlaytime {
object LimboPlaytime {
private lateinit var modifiedList: MutableList<String>
private var setMinutes = false
private val patternGroup = RepoPattern.group("misc.limbo.tooltip")
Expand All @@ -31,6 +31,8 @@ class LimboPlaytime {
"§5§o§b([\\d.,]+) hours.+\$"
)

var tooltipPlaytime = mutableListOf<String>()

private var wholeMinutes = 0
private var hoursString: String = ""

Expand Down Expand Up @@ -161,6 +163,8 @@ class LimboPlaytime {
toolTip.addAll(modifiedList)
}
toolTip.addAll(lastList)

tooltipPlaytime = toolTip
}

private fun findFloatDecimalPlace(input: Float): Int {
Expand Down
Loading