From 6dab56d69696ab0d35b3d9946c88479e10868e21 Mon Sep 17 00:00:00 2001 From: SeRaid <77941535+SeRaid743@users.noreply.github.com> Date: Thu, 16 May 2024 18:16:40 +1200 Subject: [PATCH] copy playtime --- .../java/at/hannibal2/skyhanni/SkyHanniMod.kt | 2 ++ .../skyhanni/features/misc/CopyPlaytime.kt | 36 +++++++++++++++++++ 2 files changed, 38 insertions(+) create mode 100644 src/main/java/at/hannibal2/skyhanni/features/misc/CopyPlaytime.kt diff --git a/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt b/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt index 4ae9ed824981..d691ac539b96 100644 --- a/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt +++ b/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt @@ -325,6 +325,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 @@ -937,6 +938,7 @@ class SkyHanniMod { loadModule(ColdOverlay()) loadModule(QuiverDisplay()) loadModule(QuiverWarning()) + loadModule(CopyPlaytime) init() diff --git a/src/main/java/at/hannibal2/skyhanni/features/misc/CopyPlaytime.kt b/src/main/java/at/hannibal2/skyhanni/features/misc/CopyPlaytime.kt new file mode 100644 index 000000000000..3949a82636b8 --- /dev/null +++ b/src/main/java/at/hannibal2/skyhanni/features/misc/CopyPlaytime.kt @@ -0,0 +1,36 @@ +package at.hannibal2.skyhanni.features.misc + +import at.hannibal2.skyhanni.events.GuiContainerEvent +import at.hannibal2.skyhanni.events.LorenzToolTipEvent +import at.hannibal2.skyhanni.utils.ClipboardUtils +import at.hannibal2.skyhanni.utils.InventoryUtils +import at.hannibal2.skyhanni.utils.ItemUtils.getLore +import at.hannibal2.skyhanni.utils.LorenzUtils +import at.hannibal2.skyhanni.utils.StringUtils.removeColor +import net.minecraftforge.fml.common.eventhandler.SubscribeEvent + +object CopyPlaytime { + + @SubscribeEvent + fun onTooltip(event: LorenzToolTipEvent) { + if (InventoryUtils.openInventoryName() != "Detailed /playtime") return + if (event.slot.slotNumber != 4) return + + event.toolTip.add("") + event.toolTip.add("§7[§b§lClick to Copy§7]") + } + + @SubscribeEvent + fun onSlotClicked(event: GuiContainerEvent.SlotClickEvent) { + if (InventoryUtils.openInventoryName() != "Detailed /playtime") return + if (event.slotId != 4) return + + val text = event.item?.getLore()?.toMutableList() ?: return + + if (event.clickedButton == 0) { + event.isCanceled = true + text.add(0, "${LorenzUtils.getPlayerName()}'s Playtime Stats") + ClipboardUtils.copyToClipboard(text.joinToString("\n") { it.removeColor() }) + } + } +}