From 4559e5ff05e19817a21ae49f1c0d8a97d273f6a1 Mon Sep 17 00:00:00 2001 From: Thunderblade73 <85900443+Thunderblade73@users.noreply.github.com> Date: Sat, 10 Feb 2024 00:24:52 +0100 Subject: Splitting many utils functions from LorenzUtils up into other classes: ChatUtils, CollectionUtils, ConditionalUtils. And code cleanup #978 --- .../skyhanni/test/CommandsSendToServerLogger.kt | 3 +- .../at/hannibal2/skyhanni/test/DebugCommand.kt | 5 ++- .../at/hannibal2/skyhanni/test/GriffinUtils.kt | 4 +- .../java/at/hannibal2/skyhanni/test/PacketTest.kt | 8 ++-- .../skyhanni/test/ParkourWaypointSaver.kt | 3 +- .../test/SkyHanniConfigSearchResetCommand.kt | 6 +-- .../skyhanni/test/SkyHanniDebugsAndTests.kt | 47 +++++++++++----------- .../java/at/hannibal2/skyhanni/test/TestBingo.kt | 5 ++- .../skyhanni/test/TestCopyBestiaryValues.kt | 3 +- .../skyhanni/test/TestCopyRngMeterValues.kt | 6 +-- .../at/hannibal2/skyhanni/test/TestExportTools.kt | 5 ++- .../java/at/hannibal2/skyhanni/test/WorldEdit.kt | 17 ++++---- .../skyhanni/test/command/CopyItemCommand.kt | 6 +-- .../test/command/CopyNearbyEntitiesCommand.kt | 8 ++-- .../test/command/CopyNearbyParticlesCommand.kt | 7 ++-- .../skyhanni/test/command/CopyScoreboardCommand.kt | 7 ++-- .../skyhanni/test/command/ErrorManager.kt | 11 ++--- .../skyhanni/test/command/TestChatCommand.kt | 9 +++-- .../skyhanni/test/hotswap/HotswapSupport.kt | 1 + .../skyhanni/test/hotswap/HotswapSupportHandle.kt | 1 + .../skyhanni/test/hotswap/HotswapSupportImpl.kt | 15 +++---- 21 files changed, 94 insertions(+), 83 deletions(-) (limited to 'src/main/java/at/hannibal2/skyhanni/test') diff --git a/src/main/java/at/hannibal2/skyhanni/test/CommandsSendToServerLogger.kt b/src/main/java/at/hannibal2/skyhanni/test/CommandsSendToServerLogger.kt index 25d876f7a..88ce05746 100644 --- a/src/main/java/at/hannibal2/skyhanni/test/CommandsSendToServerLogger.kt +++ b/src/main/java/at/hannibal2/skyhanni/test/CommandsSendToServerLogger.kt @@ -6,6 +6,7 @@ import net.minecraftforge.fml.common.eventhandler.SubscribeEvent class CommandsSendToServerLogger { companion object { + fun logCommandsToServer(command: String) { if (SkyHanniMod.feature.dev.debug.commandLogs) { Exception("command send to server: '$command'").printStackTrace() @@ -17,4 +18,4 @@ class CommandsSendToServerLogger { fun onConfigFix(event: ConfigUpdaterMigrator.ConfigFixEvent) { event.move(3, "dev.commandLogs", "dev.debug.commandLogs") } -} \ No newline at end of file +} diff --git a/src/main/java/at/hannibal2/skyhanni/test/DebugCommand.kt b/src/main/java/at/hannibal2/skyhanni/test/DebugCommand.kt index e2ff4dbb4..42f5a5c96 100644 --- a/src/main/java/at/hannibal2/skyhanni/test/DebugCommand.kt +++ b/src/main/java/at/hannibal2/skyhanni/test/DebugCommand.kt @@ -4,6 +4,7 @@ import at.hannibal2.skyhanni.SkyHanniMod import at.hannibal2.skyhanni.data.HypixelData import at.hannibal2.skyhanni.data.IslandType import at.hannibal2.skyhanni.events.DebugDataCollectEvent +import at.hannibal2.skyhanni.utils.ChatUtils import at.hannibal2.skyhanni.utils.LorenzUtils import at.hannibal2.skyhanni.utils.OSUtils import at.hannibal2.skyhanni.utils.StringUtils.equalsIgnoreColor @@ -13,7 +14,7 @@ object DebugCommand { fun command(args: Array) { if (args.size == 2 && args[0] == "profileName") { HypixelData.profileName = args[1].lowercase() - LorenzUtils.chat("§eManually set profileName to '${HypixelData.profileName}'") + ChatUtils.chat("§eManually set profileName to '${HypixelData.profileName}'") return } val list = mutableListOf() @@ -51,7 +52,7 @@ object DebugCommand { list.add("```") OSUtils.copyToClipboard(list.joinToString("\n")) - LorenzUtils.chat("§eCopied SkyHanni debug data in the clipboard.") + ChatUtils.chat("§eCopied SkyHanni debug data in the clipboard.") } private fun profileType(event: DebugDataCollectEvent) { diff --git a/src/main/java/at/hannibal2/skyhanni/test/GriffinUtils.kt b/src/main/java/at/hannibal2/skyhanni/test/GriffinUtils.kt index 525e9bc69..b957129cc 100644 --- a/src/main/java/at/hannibal2/skyhanni/test/GriffinUtils.kt +++ b/src/main/java/at/hannibal2/skyhanni/test/GriffinUtils.kt @@ -17,7 +17,7 @@ object GriffinUtils { beacon: Boolean = false, extraSize: Double = 0.0, extraSizeTopY: Double = extraSize, - extraSizeBottomY: Double = extraSize + extraSizeBottomY: Double = extraSize, ) { val (viewerX, viewerY, viewerZ) = RenderUtils.getViewerPos(partialTicks) val x = location.x - viewerX @@ -47,4 +47,4 @@ object GriffinUtils { GlStateManager.enableCull() } } -} \ No newline at end of file +} diff --git a/src/main/java/at/hannibal2/skyhanni/test/PacketTest.kt b/src/main/java/at/hannibal2/skyhanni/test/PacketTest.kt index 8ae9f0c5e..c9fecaf08 100644 --- a/src/main/java/at/hannibal2/skyhanni/test/PacketTest.kt +++ b/src/main/java/at/hannibal2/skyhanni/test/PacketTest.kt @@ -1,9 +1,9 @@ package at.hannibal2.skyhanni.test import at.hannibal2.skyhanni.events.PacketEvent +import at.hannibal2.skyhanni.utils.ChatUtils import at.hannibal2.skyhanni.utils.EntityUtils import at.hannibal2.skyhanni.utils.LocationUtils.distanceToPlayer -import at.hannibal2.skyhanni.utils.LorenzUtils import at.hannibal2.skyhanni.utils.LorenzUtils.round import at.hannibal2.skyhanni.utils.LorenzVec import at.hannibal2.skyhanni.utils.getLorenzVec @@ -33,11 +33,12 @@ import net.minecraftforge.fml.common.eventhandler.SubscribeEvent class PacketTest { companion object { + private var enabled = false fun toggle() { enabled = !enabled - LorenzUtils.chat("Packet test: $enabled") + ChatUtils.chat("Packet test: $enabled") } } @@ -68,7 +69,6 @@ class PacketTest { val packet = event.packet val packetName = packet.javaClass.simpleName - // Keep alive if (packetName == "S00PacketKeepAlive") return if (packetName == "C00PacketKeepAlive") return @@ -116,7 +116,6 @@ class PacketTest { // if (packetName == "S20PacketEntityProperties") return // if (packetName == "S1BPacketEntityAttach") return - val id = getEntityId(packet) val entity = getEntity(packet, id) val distance = getDistance(getLocation(packet, entity)) @@ -134,7 +133,6 @@ class PacketTest { return } - // if (packetName.contains("")) { // // } diff --git a/src/main/java/at/hannibal2/skyhanni/test/ParkourWaypointSaver.kt b/src/main/java/at/hannibal2/skyhanni/test/ParkourWaypointSaver.kt index 2574256cc..4ad8d51e6 100644 --- a/src/main/java/at/hannibal2/skyhanni/test/ParkourWaypointSaver.kt +++ b/src/main/java/at/hannibal2/skyhanni/test/ParkourWaypointSaver.kt @@ -17,6 +17,7 @@ import net.minecraftforge.fml.common.eventhandler.SubscribeEvent import kotlin.time.Duration.Companion.milliseconds class ParkourWaypointSaver { + private val config get() = SkyHanniMod.feature.dev.waypoint private var timeLastSaved = SimpleTimeMark.farPast() private var locations = mutableListOf() @@ -77,4 +78,4 @@ class ParkourWaypointSaver { } } } -} \ No newline at end of file +} diff --git a/src/main/java/at/hannibal2/skyhanni/test/SkyHanniConfigSearchResetCommand.kt b/src/main/java/at/hannibal2/skyhanni/test/SkyHanniConfigSearchResetCommand.kt index 4332a495a..8bfcbfd22 100644 --- a/src/main/java/at/hannibal2/skyhanni/test/SkyHanniConfigSearchResetCommand.kt +++ b/src/main/java/at/hannibal2/skyhanni/test/SkyHanniConfigSearchResetCommand.kt @@ -6,10 +6,10 @@ import at.hannibal2.skyhanni.config.Features import at.hannibal2.skyhanni.config.core.config.Position import at.hannibal2.skyhanni.data.ProfileStorageData import at.hannibal2.skyhanni.test.command.ErrorManager -import at.hannibal2.skyhanni.utils.LorenzUtils -import at.hannibal2.skyhanni.utils.LorenzUtils.makeAccessible +import at.hannibal2.skyhanni.utils.ChatUtils import at.hannibal2.skyhanni.utils.NumberUtil.addSeparators import at.hannibal2.skyhanni.utils.OSUtils +import at.hannibal2.skyhanni.utils.ReflectionUtils.makeAccessible import com.google.gson.JsonElement import io.github.moulberry.notenoughupdates.util.Shimmy import kotlinx.coroutines.launch @@ -23,7 +23,7 @@ object SkyHanniConfigSearchResetCommand { fun command(args: Array) { SkyHanniMod.coroutineScope.launch { - LorenzUtils.chat(runCommand(args), false) + ChatUtils.chat(runCommand(args), false) } lastCommand = args } diff --git a/src/main/java/at/hannibal2/skyhanni/test/SkyHanniDebugsAndTests.kt b/src/main/java/at/hannibal2/skyhanni/test/SkyHanniDebugsAndTests.kt index 799e096eb..ccb6b198e 100644 --- a/src/main/java/at/hannibal2/skyhanni/test/SkyHanniDebugsAndTests.kt +++ b/src/main/java/at/hannibal2/skyhanni/test/SkyHanniDebugsAndTests.kt @@ -16,6 +16,7 @@ import at.hannibal2.skyhanni.events.ReceiveParticleEvent import at.hannibal2.skyhanni.features.garden.GardenNextJacobContest import at.hannibal2.skyhanni.features.garden.visitor.GardenVisitorColorNames import at.hannibal2.skyhanni.test.GriffinUtils.drawWaypointFilled +import at.hannibal2.skyhanni.utils.ChatUtils import at.hannibal2.skyhanni.utils.InventoryUtils import at.hannibal2.skyhanni.utils.ItemUtils.getInternalName import at.hannibal2.skyhanni.utils.ItemUtils.getInternalNameOrNull @@ -28,13 +29,13 @@ import at.hannibal2.skyhanni.utils.LorenzColor import at.hannibal2.skyhanni.utils.LorenzDebug import at.hannibal2.skyhanni.utils.LorenzLogger import at.hannibal2.skyhanni.utils.LorenzUtils -import at.hannibal2.skyhanni.utils.LorenzUtils.makeAccessible import at.hannibal2.skyhanni.utils.LorenzVec import at.hannibal2.skyhanni.utils.NEUInternalName import at.hannibal2.skyhanni.utils.NEUItems import at.hannibal2.skyhanni.utils.NEUItems.getNpcPriceOrNull import at.hannibal2.skyhanni.utils.NumberUtil.addSeparators import at.hannibal2.skyhanni.utils.OSUtils +import at.hannibal2.skyhanni.utils.ReflectionUtils.makeAccessible import at.hannibal2.skyhanni.utils.RenderUtils.drawDynamicText import at.hannibal2.skyhanni.utils.RenderUtils.renderString import at.hannibal2.skyhanni.utils.RenderUtils.renderStringsAndItems @@ -53,6 +54,7 @@ import kotlin.time.Duration.Companion.seconds class SkyHanniDebugsAndTests { companion object { + private val config get() = SkyHanniMod.feature.dev private val debugConfig get() = config.debug var displayLine = "" @@ -93,14 +95,14 @@ class SkyHanniDebugsAndTests { if (args.isEmpty()) { testLocation = null - LorenzUtils.chat("reset test waypoint") + ChatUtils.chat("reset test waypoint") } val x = args[0].toDouble() val y = args[1].toDouble() val z = args[2].toDouble() testLocation = LorenzVec(x, y, z) - LorenzUtils.chat("set test waypoint") + ChatUtils.chat("set test waypoint") } fun testCommand(args: Array) { @@ -184,7 +186,7 @@ class SkyHanniDebugsAndTests { return } - LorenzUtils.clickableChat( + ChatUtils.clickableChat( "§cTHIS WILL RESET YOUR SkyHanni CONFIG! Click here to procceed.", "shconfigmanagerreset confirm", false @@ -209,7 +211,7 @@ class SkyHanniDebugsAndTests { // resetting the MoulConfigProcessor in use ConfigGuiManager.editor = null - LorenzUtils.chat("Reset the config manager!") + ChatUtils.chat("Reset the config manager!") }.start() } @@ -239,7 +241,7 @@ class SkyHanniDebugsAndTests { val internalName = NEUItems.getRawInternalName(itemName) list.add(NEUItems.getItemStack(internalName)) } catch (e: Error) { - LorenzUtils.debug("itemName '$itemName' is invalid for visitor '$name'") + ChatUtils.debug("itemName '$itemName' is invalid for visitor '$name'") errors++ } } @@ -251,9 +253,9 @@ class SkyHanniDebugsAndTests { bigList.add(list) displayList = bigList if (errors == 0) { - LorenzUtils.debug("Test garden visitor renderer: no errors") + ChatUtils.debug("Test garden visitor renderer: no errors") } else { - LorenzUtils.debug("Test garden visitor renderer: $errors errors") + ChatUtils.debug("Test garden visitor renderer: $errors errors") } } @@ -282,7 +284,7 @@ class SkyHanniDebugsAndTests { println("Skipped registering listener $simpleName") } } - LorenzUtils.chat("reloaded ${modules.size} listener classes.") + ChatUtils.chat("reloaded ${modules.size} listener classes.") } fun stopListeners() { @@ -293,22 +295,22 @@ class SkyHanniDebugsAndTests { MinecraftForge.EVENT_BUS.unregister(original) println("Unregistered listener $simpleName") } - LorenzUtils.chat("stopped ${modules.size} listener classes.") + ChatUtils.chat("stopped ${modules.size} listener classes.") } fun whereAmI() { if (LorenzUtils.inSkyBlock) { - LorenzUtils.chat("§eYou are currently in ${LorenzUtils.skyBlockIsland}.") + ChatUtils.chat("§eYou are currently in ${LorenzUtils.skyBlockIsland}.") return } - LorenzUtils.chat("§eYou are not in Skyblock.") + ChatUtils.chat("§eYou are not in Skyblock.") } private var lastManualContestDataUpdate = SimpleTimeMark.farPast() fun clearContestData() { if (lastManualContestDataUpdate.passedSince() < 30.seconds) { - LorenzUtils.userError("§cYou already cleared Jacob's Contest data recently!") + ChatUtils.userError("§cYou already cleared Jacob's Contest data recently!") return } lastManualContestDataUpdate = SimpleTimeMark.now() @@ -338,34 +340,34 @@ class SkyHanniDebugsAndTests { fun debugVersion() { val name = "SkyHanni ${SkyHanniMod.version}" - LorenzUtils.chat("§eYou are using $name") + ChatUtils.chat("§eYou are using $name") OSUtils.copyToClipboard(name) } fun copyItemInternalName() { val hand = InventoryUtils.getItemInHand() if (hand == null) { - LorenzUtils.userError("No item in hand!") + ChatUtils.userError("No item in hand!") return } val internalName = hand.getInternalNameOrNull() if (internalName == null) { - LorenzUtils.error("§cInternal name is null for item ${hand.name}") + ChatUtils.error("§cInternal name is null for item ${hand.name}") return } val rawInternalName = internalName.asString() OSUtils.copyToClipboard(rawInternalName) - LorenzUtils.chat("§eCopied internal name §7$rawInternalName §eto the clipboard!") + ChatUtils.chat("§eCopied internal name §7$rawInternalName §eto the clipboard!") } fun toggleRender() { globalRender = !globalRender if (globalRender) { - LorenzUtils.chat("§aEnabled global renderer!") + ChatUtils.chat("§aEnabled global renderer!") } else { - LorenzUtils.chat("§cDisabled global renderer! Run this command again to show SkyHanni rendering again.") + ChatUtils.chat("§cDisabled global renderer! Run this command again to show SkyHanni rendering again.") } } } @@ -379,7 +381,7 @@ class SkyHanniDebugsAndTests { val internalName = stack.getInternalNameOrNull() ?: return val rawInternalName = internalName.asString() OSUtils.copyToClipboard(rawInternalName) - LorenzUtils.chat("§eCopied internal name §7$rawInternalName §eto the clipboard!") + ChatUtils.chat("§eCopied internal name §7$rawInternalName §eto the clipboard!") } @SubscribeEvent @@ -390,7 +392,6 @@ class SkyHanniDebugsAndTests { val internalName = itemStack.getInternalName() if ((internalName == NEUInternalName.NONE) && !debugConfig.showEmptyNames) return event.toolTip.add("Internal Name: '${internalName.asString()}'") - } @SubscribeEvent @@ -435,7 +436,6 @@ class SkyHanniDebugsAndTests { @SubscribeEvent fun onChat(event: LorenzChatEvent) { - } @SubscribeEvent @@ -571,7 +571,7 @@ class SkyHanniDebugsAndTests { // if (soundName == "mob.zombie.infect") { // if (pitch == 1.968254f) { // if (volume == 0.3f) { -// LorenzUtils.chat("used ancestral spade!") +// ChatUtils.chat("used ancestral spade!") // return // } // } @@ -662,6 +662,5 @@ class SkyHanniDebugsAndTests { event.move(3, "dev.showItemRarity", "dev.debug.showItemRarity") event.move(3, "dev.copyInternalName", "dev.debug.copyInternalName") event.move(3, "dev.showNpcPrice", "dev.debug.showNpcPrice") - } } diff --git a/src/main/java/at/hannibal2/skyhanni/test/TestBingo.kt b/src/main/java/at/hannibal2/skyhanni/test/TestBingo.kt index 95832ac46..99418c607 100644 --- a/src/main/java/at/hannibal2/skyhanni/test/TestBingo.kt +++ b/src/main/java/at/hannibal2/skyhanni/test/TestBingo.kt @@ -1,12 +1,13 @@ package at.hannibal2.skyhanni.test -import at.hannibal2.skyhanni.utils.LorenzUtils +import at.hannibal2.skyhanni.utils.ChatUtils object TestBingo { + var testBingo = false fun toggle() { testBingo = !testBingo - LorenzUtils.chat("Test Bingo " + (if (testBingo) "enabled" else "disabled")) + ChatUtils.chat("Test Bingo " + (if (testBingo) "enabled" else "disabled")) } } diff --git a/src/main/java/at/hannibal2/skyhanni/test/TestCopyBestiaryValues.kt b/src/main/java/at/hannibal2/skyhanni/test/TestCopyBestiaryValues.kt index 24edae9cc..e418f6043 100644 --- a/src/main/java/at/hannibal2/skyhanni/test/TestCopyBestiaryValues.kt +++ b/src/main/java/at/hannibal2/skyhanni/test/TestCopyBestiaryValues.kt @@ -3,11 +3,11 @@ package at.hannibal2.skyhanni.test import at.hannibal2.skyhanni.SkyHanniMod import at.hannibal2.skyhanni.config.ConfigUpdaterMigrator import at.hannibal2.skyhanni.events.InventoryUpdatedEvent +import at.hannibal2.skyhanni.utils.CollectionUtils.nextAfter import at.hannibal2.skyhanni.utils.ItemUtils.getLore import at.hannibal2.skyhanni.utils.ItemUtils.getSkullOwner import at.hannibal2.skyhanni.utils.ItemUtils.getSkullTexture import at.hannibal2.skyhanni.utils.ItemUtils.name -import at.hannibal2.skyhanni.utils.LorenzUtils.nextAfter import at.hannibal2.skyhanni.utils.NumberUtil.formatNumber import at.hannibal2.skyhanni.utils.OSUtils import at.hannibal2.skyhanni.utils.StringUtils.matchMatcher @@ -21,6 +21,7 @@ import net.minecraftforge.fml.common.eventhandler.SubscribeEvent object TestCopyBestiaryValues { class BestiarityObject { + @Expose var name: String = "" diff --git a/src/main/java/at/hannibal2/skyhanni/test/TestCopyRngMeterValues.kt b/src/main/java/at/hannibal2/skyhanni/test/TestCopyRngMeterValues.kt index be659b25d..5ab1effb7 100644 --- a/src/main/java/at/hannibal2/skyhanni/test/TestCopyRngMeterValues.kt +++ b/src/main/java/at/hannibal2/skyhanni/test/TestCopyRngMeterValues.kt @@ -4,9 +4,9 @@ import at.hannibal2.skyhanni.SkyHanniMod import at.hannibal2.skyhanni.config.ConfigManager import at.hannibal2.skyhanni.config.ConfigUpdaterMigrator import at.hannibal2.skyhanni.events.InventoryFullyOpenedEvent +import at.hannibal2.skyhanni.utils.ChatUtils import at.hannibal2.skyhanni.utils.ItemUtils.getInternalName import at.hannibal2.skyhanni.utils.ItemUtils.getLore -import at.hannibal2.skyhanni.utils.LorenzUtils import at.hannibal2.skyhanni.utils.NEUInternalName import at.hannibal2.skyhanni.utils.NumberUtil.formatNumber import at.hannibal2.skyhanni.utils.OSUtils @@ -35,11 +35,11 @@ object TestCopyRngMeterValues { if (map.isEmpty()) return OSUtils.copyToClipboard(ConfigManager.gson.toJson(map)) - LorenzUtils.debug("${map.size} items saved to clipboard.") + ChatUtils.debug("${map.size} items saved to clipboard.") } @SubscribeEvent fun onConfigFix(event: ConfigUpdaterMigrator.ConfigFixEvent) { event.move(3, "dev.copyRngMeter", "dev.debug.copyRngMeter") } -} \ No newline at end of file +} diff --git a/src/main/java/at/hannibal2/skyhanni/test/TestExportTools.kt b/src/main/java/at/hannibal2/skyhanni/test/TestExportTools.kt index b7c1a6f4b..304d4646f 100644 --- a/src/main/java/at/hannibal2/skyhanni/test/TestExportTools.kt +++ b/src/main/java/at/hannibal2/skyhanni/test/TestExportTools.kt @@ -3,11 +3,11 @@ package at.hannibal2.skyhanni.test import at.hannibal2.skyhanni.SkyHanniMod import at.hannibal2.skyhanni.config.ConfigUpdaterMigrator import at.hannibal2.skyhanni.test.command.CopyItemCommand.copyItemToClipboard +import at.hannibal2.skyhanni.utils.ChatUtils import at.hannibal2.skyhanni.utils.ItemStackTypeAdapterFactory import at.hannibal2.skyhanni.utils.KSerializable import at.hannibal2.skyhanni.utils.KeyboardManager.isKeyHeld import at.hannibal2.skyhanni.utils.KotlinTypeAdapterFactory -import at.hannibal2.skyhanni.utils.LorenzUtils import at.hannibal2.skyhanni.utils.NBTTypeAdapter import at.hannibal2.skyhanni.utils.OSUtils import at.hannibal2.skyhanni.utils.fromJson @@ -22,6 +22,7 @@ import java.io.InputStreamReader import java.io.Reader object TestExportTools { + private val config get() = SkyHanniMod.feature.dev.debug val gson = GsonBuilder() @@ -61,7 +62,7 @@ object TestExportTools { } val json = toJson(Item, stack) OSUtils.copyToClipboard(json) - LorenzUtils.chat("Compressed item info copied into the clipboard!") + ChatUtils.chat("Compressed item info copied into the clipboard!") } inline fun getTestData(category: Key, name: String): T { diff --git a/src/main/java/at/hannibal2/skyhanni/test/WorldEdit.kt b/src/main/java/at/hannibal2/skyhanni/test/WorldEdit.kt index 26ac4d9a7..5e03464b7 100644 --- a/src/main/java/at/hannibal2/skyhanni/test/WorldEdit.kt +++ b/src/main/java/at/hannibal2/skyhanni/test/WorldEdit.kt @@ -5,9 +5,9 @@ import at.hannibal2.skyhanni.data.ClickType import at.hannibal2.skyhanni.events.BlockClickEvent import at.hannibal2.skyhanni.events.LorenzWorldChangeEvent import at.hannibal2.skyhanni.events.withAlpha +import at.hannibal2.skyhanni.utils.ChatUtils import at.hannibal2.skyhanni.utils.ClipboardUtils import at.hannibal2.skyhanni.utils.LocationUtils -import at.hannibal2.skyhanni.utils.LorenzUtils import at.hannibal2.skyhanni.utils.RenderUtils import at.hannibal2.skyhanni.utils.RenderUtils.expandBlock import at.hannibal2.skyhanni.utils.SkyBlockItemModifierUtils.getItemId @@ -18,6 +18,7 @@ import net.minecraftforge.fml.common.eventhandler.SubscribeEvent import java.awt.Color object WorldEdit { + private var leftPos = null as BlockPos? private var rightPos = null as BlockPos? @@ -97,37 +98,37 @@ object WorldEdit { fun command(it: Array) { if (!isEnabled()) { - LorenzUtils.userError("World Edit is disabled in the config. Enable it if you want to use it.") + ChatUtils.userError("World Edit is disabled in the config. Enable it if you want to use it.") return } when (it.firstOrNull()) { null, "help" -> { - LorenzUtils.chat("Use a wood axe and left/right click to select a region in the world. Then use /shworldedit copy or /shworldedit reset.") + ChatUtils.chat("Use a wood axe and left/right click to select a region in the world. Then use /shworldedit copy or /shworldedit reset.") } "copy" -> { copyToClipboard() - LorenzUtils.chat("Copied text to clipboard.") + ChatUtils.chat("Copied text to clipboard.") } "reset" -> { leftPos = null rightPos = null - LorenzUtils.chat("Reset selected region") + ChatUtils.chat("Reset selected region") } "left", "pos1" -> { leftPos = LocationUtils.playerLocation().toBlockPos() - LorenzUtils.chat("Set left pos.") + ChatUtils.chat("Set left pos.") } "right", "pos2" -> { leftPos = LocationUtils.playerLocation().toBlockPos() - LorenzUtils.chat("Set right pos.") + ChatUtils.chat("Set right pos.") } else -> { - LorenzUtils.chat("Unknown subcommand") + ChatUtils.chat("Unknown subcommand") } } } diff --git a/src/main/java/at/hannibal2/skyhanni/test/command/CopyItemCommand.kt b/src/main/java/at/hannibal2/skyhanni/test/command/CopyItemCommand.kt index 6a583b1e3..d038d7759 100644 --- a/src/main/java/at/hannibal2/skyhanni/test/command/CopyItemCommand.kt +++ b/src/main/java/at/hannibal2/skyhanni/test/command/CopyItemCommand.kt @@ -1,9 +1,9 @@ package at.hannibal2.skyhanni.test.command +import at.hannibal2.skyhanni.utils.ChatUtils import at.hannibal2.skyhanni.utils.InventoryUtils import at.hannibal2.skyhanni.utils.ItemUtils.getInternalName import at.hannibal2.skyhanni.utils.ItemUtils.getLore -import at.hannibal2.skyhanni.utils.LorenzUtils import at.hannibal2.skyhanni.utils.OSUtils import at.hannibal2.skyhanni.utils.SkyBlockItemModifierUtils.getMinecraftId import net.minecraft.item.ItemStack @@ -14,7 +14,7 @@ object CopyItemCommand { fun command() { val itemStack = InventoryUtils.getItemInHand() if (itemStack == null) { - LorenzUtils.userError("No item in hand!") + ChatUtils.userError("No item in hand!") return } copyItemToClipboard(itemStack) @@ -53,6 +53,6 @@ object CopyItemCommand { val string = resultList.joinToString("\n") OSUtils.copyToClipboard(string) - LorenzUtils.chat("Item info copied into the clipboard!") + ChatUtils.chat("Item info copied into the clipboard!") } } diff --git a/src/main/java/at/hannibal2/skyhanni/test/command/CopyNearbyEntitiesCommand.kt b/src/main/java/at/hannibal2/skyhanni/test/command/CopyNearbyEntitiesCommand.kt index dae69775a..5ba4447f2 100644 --- a/src/main/java/at/hannibal2/skyhanni/test/command/CopyNearbyEntitiesCommand.kt +++ b/src/main/java/at/hannibal2/skyhanni/test/command/CopyNearbyEntitiesCommand.kt @@ -1,5 +1,6 @@ package at.hannibal2.skyhanni.test.command +import at.hannibal2.skyhanni.utils.ChatUtils import at.hannibal2.skyhanni.utils.EntityUtils import at.hannibal2.skyhanni.utils.EntityUtils.getBlockInHand import at.hannibal2.skyhanni.utils.EntityUtils.getSkinTexture @@ -8,7 +9,6 @@ import at.hannibal2.skyhanni.utils.ItemUtils.getSkullTexture import at.hannibal2.skyhanni.utils.ItemUtils.isEnchanted import at.hannibal2.skyhanni.utils.ItemUtils.name import at.hannibal2.skyhanni.utils.LocationUtils -import at.hannibal2.skyhanni.utils.LorenzUtils import at.hannibal2.skyhanni.utils.LorenzUtils.baseMaxHealth import at.hannibal2.skyhanni.utils.OSUtils import at.hannibal2.skyhanni.utils.toLorenzVec @@ -45,7 +45,7 @@ object CopyNearbyEntitiesCommand { resultList.add("name: '" + entity.name + "'") resultList.add("displayName: '${displayName.formattedText}'") resultList.add("entityId: ${entity.entityId}") - resultList.add("uuid version: ${entity.uniqueID.version()} ${if(entity.uniqueID.version() != 4) "NPC " else ""}(${entity.uniqueID})") + resultList.add("uuid version: ${entity.uniqueID.version()} ${if (entity.uniqueID.version() != 4) "NPC " else ""}(${entity.uniqueID})") resultList.add("location data:") resultList.add("- vec: $vec") resultList.add("- distance: $distance") @@ -147,9 +147,9 @@ object CopyNearbyEntitiesCommand { if (counter != 0) { val string = resultList.joinToString("\n") OSUtils.copyToClipboard(string) - LorenzUtils.chat("$counter entities copied into the clipboard!") + ChatUtils.chat("$counter entities copied into the clipboard!") } else { - LorenzUtils.chat("No entities found in a search radius of $searchRadius!") + ChatUtils.chat("No entities found in a search radius of $searchRadius!") } } diff --git a/src/main/java/at/hannibal2/skyhanni/test/command/CopyNearbyParticlesCommand.kt b/src/main/java/at/hannibal2/skyhanni/test/command/CopyNearbyParticlesCommand.kt index 67b28f0aa..c76d7318f 100644 --- a/src/main/java/at/hannibal2/skyhanni/test/command/CopyNearbyParticlesCommand.kt +++ b/src/main/java/at/hannibal2/skyhanni/test/command/CopyNearbyParticlesCommand.kt @@ -1,8 +1,8 @@ package at.hannibal2.skyhanni.test.command import at.hannibal2.skyhanni.events.PacketEvent +import at.hannibal2.skyhanni.utils.ChatUtils import at.hannibal2.skyhanni.utils.LocationUtils -import at.hannibal2.skyhanni.utils.LorenzUtils import at.hannibal2.skyhanni.utils.LorenzUtils.round import at.hannibal2.skyhanni.utils.LorenzVec import at.hannibal2.skyhanni.utils.OSUtils @@ -13,6 +13,7 @@ import net.minecraftforge.fml.common.eventhandler.SubscribeEvent // Note: Each particle is copied anywhere between 1-3 times. Different each time. Shouldn't affect using this for debugging or developing object CopyNearbyParticlesCommand { + private var searchRadius = 0 private var saveNextTick = false private var searchTime: Long = 0 @@ -41,10 +42,10 @@ object CopyNearbyParticlesCommand { if (resultList.isEmpty() && tickTime == 0L) tickTime = System.currentTimeMillis() if (System.currentTimeMillis() > tickTime + 30) { - if (counter == 0) LorenzUtils.chat("No particles found nearby, try a larger search radius") else { + if (counter == 0) ChatUtils.chat("No particles found nearby, try a larger search radius") else { val string = resultList.joinToString("\n") OSUtils.copyToClipboard(string) - LorenzUtils.chat("$counter particles copied into the clipboard!") + ChatUtils.chat("$counter particles copied into the clipboard!") } saveNextTick = false return diff --git a/src/main/java/at/hannibal2/skyhanni/test/command/CopyScoreboardCommand.kt b/src/main/java/at/hannibal2/skyhanni/test/command/CopyScoreboardCommand.kt index b940d1948..e0750c5a1 100644 --- a/src/main/java/at/hannibal2/skyhanni/test/command/CopyScoreboardCommand.kt +++ b/src/main/java/at/hannibal2/skyhanni/test/command/CopyScoreboardCommand.kt @@ -1,12 +1,13 @@ package at.hannibal2.skyhanni.test.command import at.hannibal2.skyhanni.data.ScoreboardData -import at.hannibal2.skyhanni.utils.LorenzUtils -import at.hannibal2.skyhanni.utils.LorenzUtils.transformIf +import at.hannibal2.skyhanni.utils.ChatUtils +import at.hannibal2.skyhanni.utils.ConditionalUtils.transformIf import at.hannibal2.skyhanni.utils.OSUtils import at.hannibal2.skyhanni.utils.StringUtils.removeColor object CopyScoreboardCommand { + fun command(args: Array) { val resultList = mutableListOf() val noColor = args.size == 1 && args[0] == "true" @@ -21,6 +22,6 @@ object CopyScoreboardCommand { val string = resultList.joinToString("\n") OSUtils.copyToClipboard(string) - LorenzUtils.chat("Scoreboard copied into your clipboard!") + ChatUtils.chat("Scoreboard copied into your clipboard!") } } diff --git a/src/main/java/at/hannibal2/skyhanni/test/command/ErrorManager.kt b/src/main/java/at/hannibal2/skyhanni/test/command/ErrorManager.kt index 092800c10..ca9449419 100644 --- a/src/main/java/at/hannibal2/skyhanni/test/command/ErrorManager.kt +++ b/src/main/java/at/hannibal2/skyhanni/test/command/ErrorManager.kt @@ -1,8 +1,8 @@ package at.hannibal2.skyhanni.test.command import at.hannibal2.skyhanni.SkyHanniMod +import at.hannibal2.skyhanni.utils.ChatUtils import at.hannibal2.skyhanni.utils.KeyboardManager -import at.hannibal2.skyhanni.utils.LorenzUtils import at.hannibal2.skyhanni.utils.OSUtils import at.hannibal2.skyhanni.utils.StringUtils.removeColor import at.hannibal2.skyhanni.utils.TimeLimitedSet @@ -11,6 +11,7 @@ import java.util.UUID import kotlin.time.Duration.Companion.minutes object ErrorManager { + // random id -> error message private val errorMessages = mutableMapOf() private val fullErrorMessages = mutableMapOf() @@ -28,7 +29,7 @@ object ErrorManager { fun command(array: Array) { if (array.size != 1) { - LorenzUtils.userError("Use /shcopyerror ") + ChatUtils.userError("Use /shcopyerror ") return } @@ -40,7 +41,7 @@ object ErrorManager { errorMessages[id] } val name = if (fullErrorMessage) "Full error" else "Error" - LorenzUtils.chat(errorMessage?.let { + ChatUtils.chat(errorMessage?.let { OSUtils.copyToClipboard(it) "$name copied into the clipboard, please report it on the SkyHanni discord!" } ?: "Error id not found!") @@ -68,7 +69,7 @@ object ErrorManager { throwable: Throwable, message: String, ignoreErrorCache: Boolean, - vararg extraData: Pair + vararg extraData: Pair, ) { val error = Error(message, throwable) error.printStackTrace() @@ -93,7 +94,7 @@ object ErrorManager { fullErrorMessages[randomId] = "```\nSkyHanni ${SkyHanniMod.version}: $rawMessage\n(full stack trace)\n \n$fullStackTrace\n$extraDataString```" - LorenzUtils.clickableChat( + ChatUtils.clickableChat( "§c[SkyHanni-${SkyHanniMod.version}]: $message§c. Click here to copy the error into the clipboard.", "shcopyerror $randomId", false diff --git a/src/main/java/at/hannibal2/skyhanni/test/command/TestChatCommand.kt b/src/main/java/at/hannibal2/skyhanni/test/command/TestChatCommand.kt index a60b0f0d2..0f14c94fd 100644 --- a/src/main/java/at/hannibal2/skyhanni/test/command/TestChatCommand.kt +++ b/src/main/java/at/hannibal2/skyhanni/test/command/TestChatCommand.kt @@ -1,23 +1,24 @@ package at.hannibal2.skyhanni.test.command -import at.hannibal2.skyhanni.utils.LorenzUtils +import at.hannibal2.skyhanni.utils.ChatUtils import net.minecraft.util.ChatComponentText import net.minecraftforge.client.event.ClientChatReceivedEvent import net.minecraftforge.common.MinecraftForge object TestChatCommand { + fun command(args: Array) { if (args.isEmpty()) { - LorenzUtils.userError("Specify a chat message to test!") + ChatUtils.userError("Specify a chat message to test!") return } val hidden = args.last() == "-s" var rawMessage = args.toList().joinToString(" ") - if (!hidden) LorenzUtils.chat("Testing message: §7$rawMessage", prefixColor = "§a") + if (!hidden) ChatUtils.chat("Testing message: §7$rawMessage", prefixColor = "§a") if (hidden) rawMessage = rawMessage.replace(" -s", "") val formattedMessage = rawMessage.replace("&", "§") - LorenzUtils.chat(formattedMessage, false) + ChatUtils.chat(formattedMessage, false) MinecraftForge.EVENT_BUS.post(ClientChatReceivedEvent(0, ChatComponentText(formattedMessage))) } } diff --git a/src/main/java/at/hannibal2/skyhanni/test/hotswap/HotswapSupport.kt b/src/main/java/at/hannibal2/skyhanni/test/hotswap/HotswapSupport.kt index 87acab62d..447a6f5aa 100644 --- a/src/main/java/at/hannibal2/skyhanni/test/hotswap/HotswapSupport.kt +++ b/src/main/java/at/hannibal2/skyhanni/test/hotswap/HotswapSupport.kt @@ -3,6 +3,7 @@ package at.hannibal2.skyhanni.test.hotswap import java.util.function.Supplier object HotswapSupport { + private val isForgeSidePresent = runCatching { Class.forName("moe.nea.hotswapagentforge.forge.HotswapEvent") }.isSuccess private val obj = if (isForgeSidePresent) { diff --git a/src/main/java/at/hannibal2/skyhanni/test/hotswap/HotswapSupportHandle.kt b/src/main/java/at/hannibal2/skyhanni/test/hotswap/HotswapSupportHandle.kt index c006753a0..e0bb8470f 100644 --- a/src/main/java/at/hannibal2/skyhanni/test/hotswap/HotswapSupportHandle.kt +++ b/src/main/java/at/hannibal2/skyhanni/test/hotswap/HotswapSupportHandle.kt @@ -1,6 +1,7 @@ package at.hannibal2.skyhanni.test.hotswap interface HotswapSupportHandle { + fun load() fun isLoaded(): Boolean } diff --git a/src/main/java/at/hannibal2/skyhanni/test/hotswap/HotswapSupportImpl.kt b/src/main/java/at/hannibal2/skyhanni/test/hotswap/HotswapSupportImpl.kt index 044f5c817..45b81a1ab 100644 --- a/src/main/java/at/hannibal2/skyhanni/test/hotswap/HotswapSupportImpl.kt +++ b/src/main/java/at/hannibal2/skyhanni/test/hotswap/HotswapSupportImpl.kt @@ -1,9 +1,9 @@ package at.hannibal2.skyhanni.test.hotswap import at.hannibal2.skyhanni.SkyHanniMod -import at.hannibal2.skyhanni.utils.LorenzUtils -import at.hannibal2.skyhanni.utils.LorenzUtils.makeAccessible -import at.hannibal2.skyhanni.utils.LorenzUtils.removeFinal +import at.hannibal2.skyhanni.utils.ChatUtils +import at.hannibal2.skyhanni.utils.ReflectionUtils.makeAccessible +import at.hannibal2.skyhanni.utils.ReflectionUtils.removeFinal import moe.nea.hotswapagentforge.forge.ClassDefinitionEvent import moe.nea.hotswapagentforge.forge.HotswapEvent import moe.nea.hotswapagentforge.forge.HotswapFinishedEvent @@ -12,6 +12,7 @@ import net.minecraftforge.common.MinecraftForge import net.minecraftforge.fml.common.eventhandler.SubscribeEvent class HotswapSupportImpl : HotswapSupportHandle { + override fun load() { MinecraftForge.EVENT_BUS.register(this) println("Hotswap Client in Skyhanni loaded") @@ -22,7 +23,7 @@ class HotswapSupportImpl : HotswapSupportHandle { val instance = SkyHanniMod.modules.find { it.javaClass.name == event.fullyQualifiedName } ?: return val primaryConstructor = runCatching { instance.javaClass.getDeclaredConstructor() }.getOrNull() Minecraft.getMinecraft().addScheduledTask { - LorenzUtils.chat("Refreshing event subscriptions for module $instance!") + ChatUtils.chat("Refreshing event subscriptions for module $instance!") MinecraftForge.EVENT_BUS.unregister(instance) if (primaryConstructor == null) { MinecraftForge.EVENT_BUS.register(instance) @@ -30,13 +31,13 @@ class HotswapSupportImpl : HotswapSupportHandle { SkyHanniMod.modules.remove(instance) primaryConstructor.isAccessible = true val newInstance = primaryConstructor.newInstance() - LorenzUtils.chat("Reconstructing $instance -> $newInstance!") + ChatUtils.chat("Reconstructing $instance -> $newInstance!") val instanceField = runCatching { instance.javaClass.getDeclaredField("INSTANCE") }.getOrNull() ?.takeIf { it.type == instance.javaClass } ?.makeAccessible() ?.removeFinal() if (instanceField != null) { - LorenzUtils.chat("Reinjected static instance $newInstance!") + ChatUtils.chat("Reinjected static instance $newInstance!") instanceField.set(null, newInstance) } SkyHanniMod.modules.add(newInstance) @@ -47,7 +48,7 @@ class HotswapSupportImpl : HotswapSupportHandle { @SubscribeEvent fun onHotswapDetected(event: HotswapFinishedEvent) { - LorenzUtils.chat("Hotswap finished!") + ChatUtils.chat("Hotswap finished!") } override fun isLoaded(): Boolean { -- cgit