From 17eaea99b8e0f5fc30153c6fcde830e453be414e Mon Sep 17 00:00:00 2001 From: hannibal2 <24389977+hannibal00212@users.noreply.github.com> Date: Mon, 24 Jul 2023 15:37:08 +0200 Subject: moved PatcherBeacon to inner class --- src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt | 2 +- .../skyhanni/data/PatcherCoordinatesClass.kt | 5 -- .../features/misc/PatcherSendCoordinates.kt | 73 ++++++++++++++++++++++ .../misc/PatcherSendCoordinatesHighlight.kt | 72 --------------------- 4 files changed, 74 insertions(+), 78 deletions(-) delete mode 100644 src/main/java/at/hannibal2/skyhanni/data/PatcherCoordinatesClass.kt create mode 100644 src/main/java/at/hannibal2/skyhanni/features/misc/PatcherSendCoordinates.kt delete mode 100644 src/main/java/at/hannibal2/skyhanni/features/misc/PatcherSendCoordinatesHighlight.kt (limited to 'src/main/java') diff --git a/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt b/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt index 7e30efd80..3e7bf6e43 100644 --- a/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt +++ b/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt @@ -284,7 +284,7 @@ class SkyHanniMod { loadModule(GardenComposterInventoryFeatures()) loadModule(MinionCollectLogic()) loadModule(PasteIntoSigns()) - loadModule(PatcherSendCoordinatesHighlight()) + loadModule(PatcherSendCoordinates()) loadModule(EstimatedItemValue) loadModule(EstimatedWardrobePrice()) loadModule(ComposterInventoryNumbers()) diff --git a/src/main/java/at/hannibal2/skyhanni/data/PatcherCoordinatesClass.kt b/src/main/java/at/hannibal2/skyhanni/data/PatcherCoordinatesClass.kt deleted file mode 100644 index d90600df8..000000000 --- a/src/main/java/at/hannibal2/skyhanni/data/PatcherCoordinatesClass.kt +++ /dev/null @@ -1,5 +0,0 @@ -package at.hannibal2.skyhanni.data - -import at.hannibal2.skyhanni.utils.LorenzVec - -data class PatcherBeacon(val location: LorenzVec, val name: String, val time: Long) \ No newline at end of file diff --git a/src/main/java/at/hannibal2/skyhanni/features/misc/PatcherSendCoordinates.kt b/src/main/java/at/hannibal2/skyhanni/features/misc/PatcherSendCoordinates.kt new file mode 100644 index 000000000..514a883b4 --- /dev/null +++ b/src/main/java/at/hannibal2/skyhanni/features/misc/PatcherSendCoordinates.kt @@ -0,0 +1,73 @@ +package at.hannibal2.skyhanni.features.misc + +import at.hannibal2.skyhanni.SkyHanniMod +import at.hannibal2.skyhanni.events.LorenzChatEvent +import at.hannibal2.skyhanni.events.LorenzTickEvent +import at.hannibal2.skyhanni.test.GriffinUtils.drawWaypointFilled +import at.hannibal2.skyhanni.utils.LocationUtils +import at.hannibal2.skyhanni.utils.LorenzColor +import at.hannibal2.skyhanni.utils.LorenzLogger +import at.hannibal2.skyhanni.utils.LorenzVec +import at.hannibal2.skyhanni.utils.RenderUtils.drawColor +import at.hannibal2.skyhanni.utils.RenderUtils.drawString +import at.hannibal2.skyhanni.utils.StringUtils.matchMatcher +import at.hannibal2.skyhanni.utils.StringUtils.removeColor +import net.minecraftforge.client.event.RenderWorldLastEvent +import net.minecraftforge.event.world.WorldEvent +import net.minecraftforge.fml.common.eventhandler.EventPriority +import net.minecraftforge.fml.common.eventhandler.SubscribeEvent + +class PatcherSendCoordinates { + + private val patcherBeacon = mutableListOf() + private val logger = LorenzLogger("misc/patchercoords") + private val pattern = "(?.*): x: (?.*), y: (?.*), z: (?.*)".toPattern() + + + @SubscribeEvent + fun onPatcherCoordinates(event: LorenzChatEvent) { + if (!SkyHanniMod.feature.misc.patcherSendCoordWaypoint) return + + val message = event.message.removeColor() + pattern.matchMatcher(message) { + val playerName = group("playerName").split(" ").last() + val x = group("x").toInt() + val y = group("y").toInt() + val z = group("z").toInt() + patcherBeacon.add(PatcherBeacon(LorenzVec(x, y, z), playerName, System.currentTimeMillis() / 1000)) + logger.log("got patcher coords and username") + } + } + + @SubscribeEvent(priority = EventPriority.HIGH) + fun onWorldRender(event: RenderWorldLastEvent) { + if (!SkyHanniMod.feature.misc.patcherSendCoordWaypoint) return + + for (beacon in patcherBeacon) { + val location = beacon.location + event.drawColor(location, LorenzColor.DARK_GREEN, alpha = 1f) + event.drawWaypointFilled(location, LorenzColor.GREEN.toColor(), true, true) + event.drawString(location.add(0.5, 0.5, 0.5), beacon.name, true, LorenzColor.DARK_BLUE.toColor()) + } + } + + @SubscribeEvent + fun onEnterWaypoint(event: LorenzTickEvent) { + if (!event.isMod(10)) return + + val location = LocationUtils.playerLocation() + // removed patcher beacon! + patcherBeacon.removeIf { System.currentTimeMillis() / 1000 > it.time + 5 && location.distanceIgnoreY(it.location) < 5 } + + // removed patcher beacon after time! + patcherBeacon.removeIf { System.currentTimeMillis() / 1000 > it.time + 60 } + } + + @SubscribeEvent + fun onWorldChange(event: WorldEvent.Load) { + patcherBeacon.clear() + logger.log("Reset everything (world change)") + } + + data class PatcherBeacon(val location: LorenzVec, val name: String, val time: Long) +} \ No newline at end of file diff --git a/src/main/java/at/hannibal2/skyhanni/features/misc/PatcherSendCoordinatesHighlight.kt b/src/main/java/at/hannibal2/skyhanni/features/misc/PatcherSendCoordinatesHighlight.kt deleted file mode 100644 index 5e82e51f2..000000000 --- a/src/main/java/at/hannibal2/skyhanni/features/misc/PatcherSendCoordinatesHighlight.kt +++ /dev/null @@ -1,72 +0,0 @@ -package at.hannibal2.skyhanni.features.misc - -import at.hannibal2.skyhanni.SkyHanniMod -import at.hannibal2.skyhanni.data.PatcherBeacon -import at.hannibal2.skyhanni.events.LorenzChatEvent -import at.hannibal2.skyhanni.events.LorenzTickEvent -import at.hannibal2.skyhanni.test.GriffinUtils.drawWaypointFilled -import at.hannibal2.skyhanni.utils.LocationUtils -import at.hannibal2.skyhanni.utils.LorenzColor -import at.hannibal2.skyhanni.utils.LorenzLogger -import at.hannibal2.skyhanni.utils.LorenzVec -import at.hannibal2.skyhanni.utils.RenderUtils.drawColor -import at.hannibal2.skyhanni.utils.RenderUtils.drawString -import at.hannibal2.skyhanni.utils.StringUtils.matchMatcher -import at.hannibal2.skyhanni.utils.StringUtils.removeColor -import net.minecraftforge.client.event.RenderWorldLastEvent -import net.minecraftforge.event.world.WorldEvent -import net.minecraftforge.fml.common.eventhandler.EventPriority -import net.minecraftforge.fml.common.eventhandler.SubscribeEvent - -class PatcherSendCoordinatesHighlight { - - private val patcherBeacon = mutableListOf() - private val logger = LorenzLogger("misc/patchercoords") - private val pattern = "(?.*): x: (?.*), y: (?.*), z: (?.*)".toPattern() - - - @SubscribeEvent - fun onPatcherCoordinates(event: LorenzChatEvent) { - if (!SkyHanniMod.feature.misc.patcherSendCoordWaypoint) return - - val message = event.message.removeColor() - pattern.matchMatcher(message) { - val playerName = group("playerName").split(" ").last() - val x = group("x").toInt() - val y = group("y").toInt() - val z = group("z").toInt() - patcherBeacon.add(PatcherBeacon(LorenzVec(x, y, z), playerName, System.currentTimeMillis() / 1000)) - logger.log("got patcher coords and username") - } - } - - @SubscribeEvent(priority = EventPriority.HIGH) - fun onWorldRender(event: RenderWorldLastEvent) { - if (!SkyHanniMod.feature.misc.patcherSendCoordWaypoint) return - - for (beacon in patcherBeacon) { - val location = beacon.location - event.drawColor(location, LorenzColor.DARK_GREEN, alpha = 1f) - event.drawWaypointFilled(location, LorenzColor.GREEN.toColor(), true, true) - event.drawString(location.add(0.5, 0.5, 0.5), beacon.name, true, LorenzColor.DARK_BLUE.toColor()) - } - } - - @SubscribeEvent - fun onEnterWaypoint(event: LorenzTickEvent) { - if (!event.isMod(10)) return - - val location = LocationUtils.playerLocation() - // removed patcher beacon! - patcherBeacon.removeIf { System.currentTimeMillis() / 1000 > it.time + 5 && location.distanceIgnoreY(it.location) < 5 } - - // removed patcher beacon after time! - patcherBeacon.removeIf { System.currentTimeMillis() / 1000 > it.time + 60 } - } - - @SubscribeEvent - fun onWorldChange(event: WorldEvent.Load) { - patcherBeacon.clear() - logger.log("Reset everything (world change)") - } -} \ No newline at end of file -- cgit