Skip to content
Open
Show file tree
Hide file tree
Changes from 2 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
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import at.hannibal2.skyhanni.config.FeatureToggle
import at.hannibal2.skyhanni.config.core.config.Position
import at.hannibal2.skyhanni.config.features.crimsonisle.ashfang.AshfangConfig
import at.hannibal2.skyhanni.features.nether.VanquisherWaypointShare

Check warning on line 6 in src/main/java/at/hannibal2/skyhanni/config/features/crimsonisle/CrimsonIsleConfig.kt

View workflow job for this annotation

GitHub Actions / Run detekt

detekt.formatting.NoUnusedImports

Unused import
import com.google.gson.annotations.Expose
import io.github.notenoughupdates.moulconfig.annotations.Accordion
import io.github.notenoughupdates.moulconfig.annotations.Category
Expand Down Expand Up @@ -94,4 +95,10 @@
@ConfigOption(name = "Magma Boss Phase", desc = "Show the current phase of the Magma Boss.")
@ConfigEditorBoolean
var magmaBossDisplay: Boolean = false

@Expose
@ConfigOption(name = "Vanquisher Waypoint", desc = "Vanquisher Waypoint Settings")
@Accordion
var vanquisherSharing = VanquisherWaypointShareConfig()

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package at.hannibal2.skyhanni.config.features.crimsonisle

import at.hannibal2.skyhanni.config.FeatureToggle
import com.google.gson.annotations.Expose
import io.github.notenoughupdates.moulconfig.annotations.ConfigEditorBoolean
import io.github.notenoughupdates.moulconfig.annotations.ConfigEditorKeybind
import io.github.notenoughupdates.moulconfig.annotations.ConfigOption
import org.lwjgl.glfw.GLFW

class VanquisherWaypointShareConfig {
//Share vanquisher spawns
@Expose
@ConfigOption(name = "Enabled", desc = "Share your Vanquisher spawns and receive other Vanquisher spawns via Party Chat")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
@ConfigOption(name = "Enabled", desc = "Share your Vanquisher spawns and receive other Vanquisher spawns via Party Chat")
@ConfigOption(name = "Enabled", desc = "Share your Vanquisher spawns and receive other Vanquisher spawns via Party Chat.")

@ConfigEditorBoolean
@FeatureToggle
var enabled: Boolean = true

//Instant share w/o keybind
@Expose
@ConfigOption(name = "Instant Share", desc = "Instantly share your Vanquisher spawns via Party Chat")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
@ConfigOption(name = "Instant Share", desc = "Instantly share your Vanquisher spawns via Party Chat")
@ConfigOption(name = "Instant Share", desc = "Instantly share your Vanquisher spawns via Party Chat.")

@ConfigEditorBoolean
var instantShare: Boolean = true

//Manually share with keybind
@Expose
@ConfigOption(name = "Keybind Share", desc = "Manually share your Vanquisher spawns with a keybind")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
@ConfigOption(name = "Keybind Share", desc = "Manually share your Vanquisher spawns with a keybind")
@ConfigOption(name = "Keybind Share", desc = "Manually share your Vanquisher spawns with a keybind.")

@ConfigEditorKeybind(defaultKey = GLFW.GLFW_KEY_Y)
var keybindSharing: Int = GLFW.GLFW_KEY_Y

//Read global chat to recognize non-party members' Vanquisher spawns
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove the chat gpt comments

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thos are my comments ;[

@Expose
@ConfigOption(name = "Read Global Chat", desc = "Register Vanquisher spawns from All Chat and Party Chat")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
@ConfigOption(name = "Read Global Chat", desc = "Register Vanquisher spawns from All Chat and Party Chat")
@ConfigOption(name = "Read Global Chat", desc = "Register Vanquisher spawns from All Chat and Party Chat.")

@ConfigEditorBoolean
var readGlobalChat: Boolean = false
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,232 @@
package at.hannibal2.skyhanni.features.nether

import at.hannibal2.skyhanni.SkyHanniMod
import at.hannibal2.skyhanni.api.event.HandleEvent
import at.hannibal2.skyhanni.data.IslandType
import at.hannibal2.skyhanni.data.title.TitleManager
import at.hannibal2.skyhanni.events.SecondPassedEvent
import at.hannibal2.skyhanni.events.chat.SkyHanniChatEvent
import at.hannibal2.skyhanni.events.entity.EntityHealthUpdateEvent
import at.hannibal2.skyhanni.events.minecraft.KeyPressEvent
import at.hannibal2.skyhanni.skyhannimodule.SkyHanniModule
import at.hannibal2.skyhanni.utils.ChatUtils
import at.hannibal2.skyhanni.utils.HypixelCommands
import at.hannibal2.skyhanni.utils.KeyboardManager
import at.hannibal2.skyhanni.utils.LorenzVec
import at.hannibal2.skyhanni.utils.RegexUtils.hasGroup
import at.hannibal2.skyhanni.utils.RegexUtils.matchMatcher
import at.hannibal2.skyhanni.utils.RegexUtils.matchMatchers
import at.hannibal2.skyhanni.utils.RegexUtils.matches
import at.hannibal2.skyhanni.utils.SimpleTimeMark
import at.hannibal2.skyhanni.utils.StringUtils.cleanPlayerName
import at.hannibal2.skyhanni.utils.compat.deceased
import at.hannibal2.skyhanni.utils.getLorenzVec
import at.hannibal2.skyhanni.utils.repopatterns.RepoPattern
import net.minecraft.client.Minecraft
import java.util.concurrent.ConcurrentHashMap
import java.util.regex.Matcher
import kotlin.time.Duration.Companion.seconds
import at.hannibal2.skyhanni.events.minecraft.WorldChangeEvent
import at.hannibal2.skyhanni.events.entity.EntityEnterWorldEvent
import net.minecraft.world.entity.LivingEntity
import net.minecraft.client.player.RemotePlayer
import net.minecraft.world.entity.Entity
import at.hannibal2.skyhanni.utils.EntityUtils
import at.hannibal2.skyhanni.utils.LocationUtils.distanceToPlayer


@SkyHanniModule
object VanquisherWaypointShare {

private val config get() = SkyHanniMod.feature.crimsonIsle.vanquisherSharing
private val patternGroup = RepoPattern.group("vanquisher.waypoint")

@Suppress("MaxLineLength")
private val vanquisherSharedPattern by patternGroup.list(

Check warning on line 45 in src/main/java/at/hannibal2/skyhanni/features/nether/VanquisherWaypointShare.kt

View workflow job for this annotation

GitHub Actions / Run detekt

detekt.RepoRules.RepoPatternRegexTestMissing

Repo pattern `vanquisherSharedPattern` must have a regex test.
"coords",
"(?<party>§9Party §8> )?(?<playerName>.+)§f: (?<x>[^ ]+): (?<y>[^ ]+): (?<z>[^ ]+): | Vanquisher"
)

private val vanquisherDiedPattern by patternGroup.pattern(

Check warning on line 50 in src/main/java/at/hannibal2/skyhanni/features/nether/VanquisherWaypointShare.kt

View workflow job for this annotation

GitHub Actions / Run detekt

detekt.RepoRules.RepoPatternRegexTestMissing

Repo pattern `vanquisherDiedPattern` must have a regex test.
"died",
"(?<party>§9Party §8> )?(?<playerName>.*)§f: §rVanquisher dead!",
)
private val vanquisherSpawnedPattern by patternGroup.pattern(

Check warning on line 54 in src/main/java/at/hannibal2/skyhanni/features/nether/VanquisherWaypointShare.kt

View workflow job for this annotation

GitHub Actions / Run detekt

detekt.RepoRules.RepoPatternRegexTestMissing

Repo pattern `vanquisherSpawnedPattern` must have a regex test.
"spawned",
".*§aA §r§cVanquisher §r§ais spawning nearby!"
)
Comment on lines 51 to 73
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove colour codes


private var myVanquisherId = -1

private var lastShareTime = SimpleTimeMark.farPast()

private val vanquisherNearby = ConcurrentHashMap<Int, Entity>()

private val sharedWaypoints = ConcurrentHashMap<String, SharedVanquisher>()

val waypoints: Map<String, SharedVanquisher> get() = sharedWaypoints

class SharedVanquisher(
val fromPlayer: String,
val playerName: String,
val location: LorenzVec,
val spawnTime: SimpleTimeMark,
)

private fun foundVanquisher(entityId: Int) {
lastShareTime = SimpleTimeMark.farPast()
myVanquisherId = entityId

if(config.instantShare){

Check warning on line 80 in src/main/java/at/hannibal2/skyhanni/features/nether/VanquisherWaypointShare.kt

View workflow job for this annotation

GitHub Actions / Run detekt

detekt.formatting.SpacingAroundKeyword

Missing spacing after "if"
sendVanquisher()
} else {
val keyName = KeyboardManager.getKeyName(config.keybindSharing)
val message = "You found a Vanquisher! Click §l§chere §l§bor press §c$keyName to share!"
ChatUtils.clickableChat(message, onClick = ::sendVanquisher, hover = "§eClick to share!", oneTimeClick = true)
}
}

private fun sendVanquisher() {
if(!isEnabled()) return

Check warning on line 90 in src/main/java/at/hannibal2/skyhanni/features/nether/VanquisherWaypointShare.kt

View workflow job for this annotation

GitHub Actions / Run detekt

detekt.formatting.SpacingAroundKeyword

Missing spacing after "if"
if(lastShareTime.passedSince() < 5.seconds) return

Check warning on line 91 in src/main/java/at/hannibal2/skyhanni/features/nether/VanquisherWaypointShare.kt

View workflow job for this annotation

GitHub Actions / Run detekt

detekt.formatting.SpacingAroundKeyword

Missing spacing after "if"
lastShareTime = SimpleTimeMark.now()

if (myVanquisherId == -1) {
val closestId = vanquisherNearby.values.minByOrNull { it.distanceToPlayer() }
if(closestId != null) {myVanquisherId = closestId.id}

Check warning on line 96 in src/main/java/at/hannibal2/skyhanni/features/nether/VanquisherWaypointShare.kt

View workflow job for this annotation

GitHub Actions / Run detekt

detekt.formatting.SpacingAroundKeyword

Missing spacing after "if"
ChatUtils.chat("§cNo Vanquisher found to share!")
return
}

val entity = vanquisherNearby[myVanquisherId] ?: EntityUtils.getEntityByID(myVanquisherId)

if(entity == null || entity.deceased) {

Check warning on line 103 in src/main/java/at/hannibal2/skyhanni/features/nether/VanquisherWaypointShare.kt

View workflow job for this annotation

GitHub Actions / Run detekt

detekt.formatting.SpacingAroundKeyword

Missing spacing after "if"
sendVanquisherDeath()
return
}

val location = entity.getLorenzVec()
val x = location.x.toInt()
val y = location.y.toInt()
val z = location.z.toInt()

HypixelCommands.partyChat("x: $x, y: $y, z: $z | Vanquisher")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does this check if you are a party

}

private fun sendVanquisherDeath() {
if(!isEnabled()) return

Check warning on line 117 in src/main/java/at/hannibal2/skyhanni/features/nether/VanquisherWaypointShare.kt

View workflow job for this annotation

GitHub Actions / Run detekt

detekt.formatting.SpacingAroundKeyword

Missing spacing after "if"
if(lastShareTime.passedSince() < 2.seconds) return
if(myVanquisherId == -1) return

myVanquisherId = -1
HypixelCommands.partyChat("Vanquisher dead!")
}

private fun isEnabled() = config.enabled

private fun Matcher.block(): Boolean = !hasGroup("party") && !config.readGlobalChat

private fun Matcher.detectFromChat(): Boolean {
if(block()) return false
val playerName = group("playerName")
val x = group("x").trim().toDoubleOrNull() ?: return false
val y = group("y").trim().toDoubleOrNull() ?: return false
val z = group("z").trim().toDoubleOrNull() ?: return false
val location = LorenzVec(x,y,z)

val name = playerName.cleanPlayerName()
val playerDisplayName = playerName.cleanPlayerName(displayName = true)

if(!waypoints.containsKey(name)){
ChatUtils.chat("$playerDisplayName §l§efound a Vanquisher at §l§c${x.toInt()} ${y.toInt()} ${z.toInt()}!")
TitleManager.sendTitle("§dVanquisher §efrom §b$playerDisplayName")
}
sharedWaypoints[name] = SharedVanquisher(name, playerDisplayName, location, SimpleTimeMark.now())
return true
}

@HandleEvent
fun whenChangeWorld(event: WorldChangeEvent) {
sharedWaypoints.clear()
vanquisherNearby.clear()
myVanquisherId = -1
}

@HandleEvent
fun keyPressEvent(event: KeyPressEvent){
if(!isEnabled()) return
if(Minecraft.getInstance().screen != null) return
if(event.keyCode == config.keybindSharing) sendVanquisher()
}

@HandleEvent
fun checkVanquisherHealth(event: EntityHealthUpdateEvent){
if(!isEnabled()) return
if(event.health > 0) return

val entityId = event.entity.id
if(entityId == myVanquisherId){
sendVanquisherDeath()
}
vanquisherNearby.remove(entityId)
}

@HandleEvent
fun checkSecondPassed(event: SecondPassedEvent) {
if(!isEnabled()) return

sharedWaypoints.values.removeIf{it.spawnTime.passedSince() > 60.seconds}

if(event.repeatSeconds(3)) {
vanquisherNearby.values.removeIf{it.deceased || !it.isAlive}
}
}

@HandleEvent(onlyOnIsland = IslandType.CRIMSON_ISLE, receiveCancelled = true)
fun readChat(event: SkyHanniChatEvent.Allow) {
if(!isEnabled()) return
val message = event.message
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use cleanMessage instead


if(vanquisherSpawnedPattern.matches(message)){
if(myVanquisherId == -1) {
val closestId = vanquisherNearby.values.minByOrNull {
it.distanceToPlayer()
}
if(closestId != null) {foundVanquisher(closestId.id)}
}
}

vanquisherSharedPattern.matchMatchers(message){
if(!detectFromChat()) return@matchMatchers
event.blockedReason = "vanquisher_waypoint"
}

vanquisherDiedPattern.matchMatcher(message){
if(block()) return
val simpleName = group("playerName")
val name = simpleName.cleanPlayerName()
sharedWaypoints.remove(name)
}
}

@HandleEvent
fun onRawEntityJoin(event: EntityEnterWorldEvent<Entity>) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you can change Entity to the one you need (armour stand im guessing?)

if (!isEnabled()) return
val entity = event.entity
if (entity !is LivingEntity) return
if (entity is RemotePlayer) return
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

and then you can remove this


if (entity.name.string.equals("Wither", ignoreCase = true) ||
entity.name.string.contains("Vanquisher", ignoreCase = true)) {

vanquisherNearby[entity.id] = entity

val player = Minecraft.getInstance().player ?: return
if(entity.distanceTo(player) < 15.0){
if(myVanquisherId != entity.id){
foundVanquisher(entity.id)
}
}
}
}
}
Loading