diff options
author | ShanaSplatoon <132563986+ShanaSplatoon@users.noreply.github.com> | 2023-05-07 17:05:45 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-05-07 17:05:45 +0200 |
commit | 88ada6aa82c8672b81ca4c30d74296c451a3f26e (patch) | |
tree | 9e42b081df4dc7e658f42bd0549034ee9b5bdcd8 /src/main/java/at/hannibal2 | |
parent | 23c8e2ad407d1889cdb4af38c64f0155f33bb105 (diff) | |
download | skyhanni-88ada6aa82c8672b81ca4c30d74296c451a3f26e.tar.gz skyhanni-88ada6aa82c8672b81ca4c30d74296c451a3f26e.tar.bz2 skyhanni-88ada6aa82c8672b81ca4c30d74296c451a3f26e.zip |
Added Inquis Share (#95)
Co-authored-by: hannibal2 <24389977+hannibal00212@users.noreply.github.com>
Diffstat (limited to 'src/main/java/at/hannibal2')
9 files changed, 311 insertions, 40 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt b/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt index 081e6a5b0..a5dab1a48 100644 --- a/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt +++ b/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt @@ -22,10 +22,7 @@ import at.hannibal2.skyhanni.features.chat.playerchat.PlayerChatModifier import at.hannibal2.skyhanni.features.commands.WikiCommand import at.hannibal2.skyhanni.features.damageindicator.DamageIndicatorManager import at.hannibal2.skyhanni.features.dungeon.* -import at.hannibal2.skyhanni.features.event.diana.BurrowWarpHelper -import at.hannibal2.skyhanni.features.event.diana.GriffinBurrowHelper -import at.hannibal2.skyhanni.features.event.diana.GriffinBurrowParticleFinder -import at.hannibal2.skyhanni.features.event.diana.SoopyGuessBurrow +import at.hannibal2.skyhanni.features.event.diana.* import at.hannibal2.skyhanni.features.fishing.* import at.hannibal2.skyhanni.features.garden.* import at.hannibal2.skyhanni.features.garden.composter.ComposterDisplay @@ -200,7 +197,7 @@ class SkyHanniMod { loadModule(StatsTuning()) loadModule(NonGodPotEffectDisplay()) loadModule(SoopyGuessBurrow()) - loadModule(GriffinBurrowHelper()) + loadModule(GriffinBurrowHelper) loadModule(GriffinBurrowParticleFinder()) loadModule(BurrowWarpHelper()) loadModule(CollectionCounter()) @@ -267,6 +264,7 @@ class SkyHanniMod { loadModule(MovementSpeedDisplay()) loadModule(ChumBucketHider()) loadModule(GardenRecentTeleportPadsDisplay()) + loadModule(InquisitorWaypointShare) init() diff --git a/src/main/java/at/hannibal2/skyhanni/config/commands/Commands.kt b/src/main/java/at/hannibal2/skyhanni/config/commands/Commands.kt index 2ecdb2d98..985692b57 100644 --- a/src/main/java/at/hannibal2/skyhanni/config/commands/Commands.kt +++ b/src/main/java/at/hannibal2/skyhanni/config/commands/Commands.kt @@ -8,6 +8,7 @@ import at.hannibal2.skyhanni.data.GuiEditManager import at.hannibal2.skyhanni.features.bingo.BingoCardDisplay import at.hannibal2.skyhanni.features.bingo.BingoNextStepHelper import at.hannibal2.skyhanni.features.event.diana.BurrowWarpHelper +import at.hannibal2.skyhanni.features.event.diana.InquisitorWaypointShare import at.hannibal2.skyhanni.features.garden.GardenAPI import at.hannibal2.skyhanni.features.garden.GardenCropTimeCommand import at.hannibal2.skyhanni.features.garden.composter.ComposterOverlay @@ -67,6 +68,7 @@ object Commands { registerCommand("shclearminiondata") { MinionFeatures.clearMinionData() } registerCommand("shtestbingo") { TestBingo.toggle() } registerCommand("shtestmessage") { TestChatCommand.command(it) } + registerCommand("shshareinquis") { InquisitorWaypointShare.sendInquisitor() } } private fun registerCommand(name: String, function: (Array<String>) -> Unit) { diff --git a/src/main/java/at/hannibal2/skyhanni/config/features/Diana.java b/src/main/java/at/hannibal2/skyhanni/config/features/Diana.java index 578586bcb..d193aa872 100644 --- a/src/main/java/at/hannibal2/skyhanni/config/features/Diana.java +++ b/src/main/java/at/hannibal2/skyhanni/config/features/Diana.java @@ -1,9 +1,7 @@ package at.hannibal2.skyhanni.config.features; import com.google.gson.annotations.Expose; -import io.github.moulberry.moulconfig.annotations.ConfigEditorBoolean; -import io.github.moulberry.moulconfig.annotations.ConfigEditorKeybind; -import io.github.moulberry.moulconfig.annotations.ConfigOption; +import io.github.moulberry.moulconfig.annotations.*; import org.lwjgl.input.Keyboard; public class Diana { @@ -33,4 +31,28 @@ public class Diana { @ConfigEditorKeybind(defaultKey = Keyboard.KEY_NONE) public int keyBindWarp = Keyboard.KEY_NONE; + @Expose + @ConfigOption(name = "Inquisitor Waypoint Sharing", desc = "") + @Accordion + @ConfigAccordionId(id = 9) + public InquisitorSharing inquisitorSharing = new InquisitorSharing(); + + public static class InquisitorSharing { + + @Expose + @ConfigOption(name = "Enabled", desc = "Shares your Inquisitor and receiving other Inquisitors via Party Chat.") + @ConfigEditorBoolean + public boolean enabled = true; + + @Expose + @ConfigOption(name = "Focus", desc = "Hide other waypoints when your party finds a inquisitor.") + @ConfigEditorBoolean + public boolean focusInquisitor = false; + + @Expose + @ConfigOption(name = "Share Key", desc = "Press this key to share your Inquisitor Waypoint.") + @ConfigEditorKeybind(defaultKey = Keyboard.KEY_NONE) + public int keyBindShare = Keyboard.KEY_Y; + } + } diff --git a/src/main/java/at/hannibal2/skyhanni/events/DamageIndicatorDetectedEvent.kt b/src/main/java/at/hannibal2/skyhanni/events/DamageIndicatorDetectedEvent.kt new file mode 100644 index 000000000..2203ab724 --- /dev/null +++ b/src/main/java/at/hannibal2/skyhanni/events/DamageIndicatorDetectedEvent.kt @@ -0,0 +1,5 @@ +package at.hannibal2.skyhanni.events + +import at.hannibal2.skyhanni.features.damageindicator.EntityData + +class DamageIndicatorDetectedEvent(val entityData: EntityData) : LorenzEvent()
\ No newline at end of file diff --git a/src/main/java/at/hannibal2/skyhanni/features/damageindicator/DamageIndicatorManager.kt b/src/main/java/at/hannibal2/skyhanni/features/damageindicator/DamageIndicatorManager.kt index 93886069c..0b7f14f2f 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/damageindicator/DamageIndicatorManager.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/damageindicator/DamageIndicatorManager.kt @@ -3,6 +3,7 @@ package at.hannibal2.skyhanni.features.damageindicator import at.hannibal2.skyhanni.SkyHanniMod import at.hannibal2.skyhanni.data.ScoreboardData import at.hannibal2.skyhanni.events.BossHealthChangeEvent +import at.hannibal2.skyhanni.events.DamageIndicatorDetectedEvent import at.hannibal2.skyhanni.events.DamageIndicatorFinalBossEvent import at.hannibal2.skyhanni.events.LorenzChatEvent import at.hannibal2.skyhanni.features.dungeon.DungeonData @@ -342,6 +343,7 @@ class DamageIndicatorManager { val lastHealth = data[entity.uniqueID]!!.lastHealth checkDamage(entityData, health, lastHealth) tickDamage(entityData.damageCounter) + BossHealthChangeEvent(entityData, lastHealth, health, maxHealth).postAndCatch() } entityData.lastHealth = health @@ -355,6 +357,7 @@ class DamageIndicatorManager { entityData.timeLastTick = System.currentTimeMillis() data[entity.uniqueID] = entityData + } catch (e: Throwable) { e.printStackTrace() } @@ -710,15 +713,19 @@ class DamageIndicatorManager { private fun grabData(entity: EntityLivingBase): EntityData? { if (data.contains(entity.uniqueID)) return data[entity.uniqueID] + val entityResult = mobFinder?.tryAdd(entity) ?: return null - return EntityData( - entity, - entityResult.ignoreBlocks, - entityResult.delayedStart, - entityResult.finalDungeonBoss, - entityResult.bossType, - foundTime = System.currentTimeMillis() + + val entityData = EntityData( + entity, + entityResult.ignoreBlocks, + entityResult.delayedStart, + entityResult.finalDungeonBoss, + entityResult.bossType, + foundTime = System.currentTimeMillis() ) + DamageIndicatorDetectedEvent(entityData).postAndCatch() + return entityData } private fun checkFinalBoss(finalBoss: Boolean, id: Int) { diff --git a/src/main/java/at/hannibal2/skyhanni/features/event/diana/GriffinBurrowHelper.kt b/src/main/java/at/hannibal2/skyhanni/features/event/diana/GriffinBurrowHelper.kt index 65ce760aa..3e427bb4b 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/event/diana/GriffinBurrowHelper.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/event/diana/GriffinBurrowHelper.kt @@ -20,11 +20,13 @@ import net.minecraftforge.client.event.RenderWorldLastEvent import net.minecraftforge.event.world.WorldEvent import net.minecraftforge.fml.common.eventhandler.SubscribeEvent -class GriffinBurrowHelper { +object GriffinBurrowHelper { + private val config get() = SkyHanniMod.feature.diana private var guessLocation: LorenzVec? = null + private var targetLocation: LorenzVec? = null private var particleBurrows = mapOf<LorenzVec, BurrowType>() - private var animationLocation: LorenzVec? = null + var animationLocation: LorenzVec? = null private var lastDug: LorenzVec? = null private var teleportedLocation: LorenzVec? = null private var lastGuessTime = 0L @@ -38,12 +40,17 @@ class GriffinBurrowHelper { } lastGuessTime = System.currentTimeMillis() - if (SkyHanniMod.feature.diana.burrowNearestWarp) { - BurrowWarpHelper.shouldUseWarps(event.guessLocation) - } - guessLocation = event.guessLocation - if (SkyHanniMod.feature.diana.burrowsNearbyDetection) { + setTargetLocation(event.guessLocation) + } + + fun setTargetLocation(location: LorenzVec) { + targetLocation = location + + if (config.burrowNearestWarp) { + BurrowWarpHelper.shouldUseWarps(location) + } + if (config.burrowsNearbyDetection) { checkRemoveGuess(false) } } @@ -53,7 +60,7 @@ class GriffinBurrowHelper { EntityMovementData.addToTrack(Minecraft.getMinecraft().thePlayer) particleBurrows = particleBurrows.editCopy { this[event.burrowLocation] = event.type } - if (SkyHanniMod.feature.diana.burrowsNearbyDetection) { + if (config.burrowsNearbyDetection) { checkRemoveGuess(true) } } @@ -99,6 +106,7 @@ class GriffinBurrowHelper { @SubscribeEvent fun onWorldChange(event: WorldEvent.Load) { guessLocation = null + targetLocation = null animationLocation = null lastDug = null particleBurrows = particleBurrows.editCopy { clear() } @@ -132,22 +140,38 @@ class GriffinBurrowHelper { sendTip(event) val playerLocation = LocationUtils.playerLocation() - if (SkyHanniMod.feature.diana.burrowsNearbyDetection) { + for ((playerName, location) in InquisitorWaypointShare.waypoints) { + event.drawColor(location, LorenzColor.LIGHT_PURPLE) + val distance = location.distance(playerLocation) + if (distance > 10) { + val formattedDistance = LorenzUtils.formatInteger(distance.toInt()) + event.drawDynamicText(location.add(0, 1, 0), "§d§lInquisitor §e${formattedDistance}m", 1.7) + } else { + event.drawDynamicText(location.add(0, 1, 0), "§d§lInquisitor", 1.7) + } + if (distance < 5) { + InquisitorWaypointShare.maybeRemove(playerName) + } + event.drawDynamicText(location.add(0, 1, 0), "§eFrom §b$playerName", 1.6, yOff = 9f) + } + + if (InquisitorWaypointShare.waypoints.isNotEmpty()) { + if (SkyHanniMod.feature.diana.inquisitorSharing.focusInquisitor) { + return + } + } + + if (config.burrowsNearbyDetection) { for (burrow in particleBurrows) { val location = burrow.key val distance = location.distance(playerLocation) val burrowType = burrow.value -// if (distance < 30) { event.drawColor(location, burrowType.color, distance > 10) -// } event.drawDynamicText(location.add(0, 1, 0), burrowType.text, 1.5) -// if (distance < 10) { -// event.drawString(location.add(0.5, 1.5, 0.5), burrowType.text, true) -// } } } - if (SkyHanniMod.feature.diana.burrowsSoopyGuess) { + if (config.burrowsSoopyGuess) { guessLocation?.let { val guessLocation = findBlock(it) val distance = guessLocation.distance(playerLocation) @@ -167,14 +191,14 @@ class GriffinBurrowHelper { if (BurrowWarpHelper.currentWarp != null) { BurrowWarpHelper.currentWarp = null - if (SkyHanniMod.feature.diana.burrowNearestWarp) { + if (config.burrowNearestWarp) { animationLocation = it return } } } - if (SkyHanniMod.feature.diana.burrowNearestWarp) { + if (config.burrowNearestWarp) { BurrowWarpHelper.currentWarp?.let { warp -> animationLocation?.let { event.drawColor(it.add(0.0, 1.0, 0.0), LorenzColor.AQUA) @@ -185,7 +209,7 @@ class GriffinBurrowHelper { } } } - if (SkyHanniMod.feature.diana.burrowSmoothTransition) { + if (config.burrowSmoothTransition) { animationLocation?.let { event.drawColor(it, LorenzColor.WHITE) animationLocation = moveAnimation(it, event) @@ -195,10 +219,10 @@ class GriffinBurrowHelper { private fun moveAnimation(animation: LorenzVec, event: RenderWorldLastEvent): LorenzVec? { val list = mutableListOf<LorenzVec>() - if (SkyHanniMod.feature.diana.burrowsNearbyDetection) { + if (config.burrowsNearbyDetection) { list.addAll(particleBurrows.keys) } - guessLocation?.let { + targetLocation?.let { val loc = findBlock(it) if (loc.y > 200) { list.add(LorenzVec(loc.x, LocationUtils.playerLocation().y, loc.z)) diff --git a/src/main/java/at/hannibal2/skyhanni/features/event/diana/InquisitorWaypointShare.kt b/src/main/java/at/hannibal2/skyhanni/features/event/diana/InquisitorWaypointShare.kt new file mode 100644 index 000000000..c223cf386 --- /dev/null +++ b/src/main/java/at/hannibal2/skyhanni/features/event/diana/InquisitorWaypointShare.kt @@ -0,0 +1,199 @@ +package at.hannibal2.skyhanni.features.event.diana + + +import at.hannibal2.skyhanni.SkyHanniMod +import at.hannibal2.skyhanni.data.IslandType +import at.hannibal2.skyhanni.data.TitleUtils +import at.hannibal2.skyhanni.events.BossHealthChangeEvent +import at.hannibal2.skyhanni.events.DamageIndicatorDetectedEvent +import at.hannibal2.skyhanni.events.LorenzChatEvent +import at.hannibal2.skyhanni.events.PacketEvent +import at.hannibal2.skyhanni.features.damageindicator.BossType +import at.hannibal2.skyhanni.features.damageindicator.DamageIndicatorManager +import at.hannibal2.skyhanni.utils.* +import at.hannibal2.skyhanni.utils.LorenzUtils.editCopy +import at.hannibal2.skyhanni.utils.StringUtils.cleanPlayerName +import at.hannibal2.skyhanni.utils.StringUtils.matchMatcher +import io.github.moulberry.moulconfig.internal.KeybindHelper +import net.minecraft.client.Minecraft +import net.minecraft.network.play.server.S02PacketChat +import net.minecraftforge.event.world.WorldEvent +import net.minecraftforge.fml.common.eventhandler.EventPriority +import net.minecraftforge.fml.common.eventhandler.SubscribeEvent +import net.minecraftforge.fml.common.gameevent.InputEvent +import org.lwjgl.input.Keyboard + +object InquisitorWaypointShare { + private val config get() = SkyHanniMod.feature.diana.inquisitorSharing + private val partyPattern = "§9Party §8> (?<playerName>.*)§f: §rx: (?<x>.*), y: (?<y>.*), z: (?<z>.*)".toPattern() + private val diedPattern = "§9Party §8> (?<playerName>.*)§f: §rInquisitor dead!".toPattern() + + private var time = 0L + private var testTime = 0L + private var lastTestMessage = "" + private var inquisitor = -1 + private var lastShareTime = 0L + + var waypoints = mapOf<String, LorenzVec>() + + @SubscribeEvent + fun onWorldChange(event: WorldEvent.Load) { + waypoints = waypoints.editCopy { clear() } + } + + @SubscribeEvent + fun onChatMessage(event: LorenzChatEvent) { + if (!isEnabled()) return + val message = event.message + // TODO use inquisitor +// if (message.endsWith("§r§eYou dug out §r§2a Minotaur§r§e!")) { + if (message.endsWith("§r§eYou dug out §r§2a Minos Champion§r§e!")) { + time = System.currentTimeMillis() + LorenzUtils.debug("found Champion/Inquisitor") + } + if (message.contains("§eYou dug out")) { + testTime = System.currentTimeMillis() + lastTestMessage = message + } + } + + @SubscribeEvent + fun onDamageIndicatorDetected(event: DamageIndicatorDetectedEvent) { + if (!isEnabled()) return + val bossType = event.entityData.bossType + // TODO use inquisitor +// if (bossType == BossType.MINOTAUR) { + if (bossType == BossType.MINOS_INQUISITOR) { + val diff = System.currentTimeMillis() - time + LorenzUtils.debug("diff: $diff") + if (diff > 100 || diff < 0) { + val testDiff = System.currentTimeMillis() - testTime + if (testDiff > 100 || testDiff < 0) { + LorenzUtils.debug("testDiff: $diff") + return + } else { + LorenzUtils.debug("wrong Inquisitor message!") + println("lastTestMessage: '$lastTestMessage'") + + } + } + val keyName = KeybindHelper.getKeyName(config.keyBindShare) + val message = + "§e[SkyHanni] §l§bYou found a Inquisitor! Press §l§chere §l§bor §c$keyName to share the location!" + LorenzUtils.clickableChat(message, "shshareinquis") + inquisitor = event.entityData.entity.entityId + } + } + + @SubscribeEvent + fun onBossHealthChange(event: BossHealthChangeEvent) { + if (event.health <= 0) { + val entityData = event.entityData + val bossType = entityData.bossType + // TODO use inquisitor +// if (bossType == BossType.MINOTAUR) { + if (bossType == BossType.MINOS_INQUISITOR) { + sendDeath() + } + } + } + + @SubscribeEvent + fun onKeyBindPressed(event: InputEvent.KeyInputEvent) { + if (!isEnabled()) return + if (!Keyboard.getEventKeyState()) return + val key = if (Keyboard.getEventKey() == 0) Keyboard.getEventCharacter().code + 256 else Keyboard.getEventKey() + if (config.keyBindShare == key) { + sendInquisitor() + } + } + + private fun sendDeath() { + if (!isEnabled()) return + if (lastShareTime + 5000 > System.currentTimeMillis()) return + lastShareTime = System.currentTimeMillis() + + if (inquisitor == -1) { + LorenzUtils.debug("Inquisitor is already null!") + return + } + inquisitor = -1 + LorenzUtils.sendCommandToServer("pc Inquisitor dead!") + } + + fun sendInquisitor() { + if (!isEnabled()) return + if (lastShareTime + 5000 > System.currentTimeMillis()) return + lastShareTime = System.currentTimeMillis() + + if (inquisitor == -1) { + LorenzUtils.chat("§c[SkyHanni] No Inquisitor Found!") + return + } + + val inquisitor = Minecraft.getMinecraft().theWorld.getEntityByID(inquisitor) + if (inquisitor == null) { + LorenzUtils.chat("§cInquisitor out of range!") + return + } + + if (inquisitor.isDead) { + LorenzUtils.chat("§cInquisitor is ded") + return + } + val location = inquisitor.getLorenzVec() + val x = location.x.toInt() + val y = location.y.toInt() + val z = location.z.toInt() + LorenzUtils.sendCommandToServer("pc x: $x, y: $y, z: $z ") + } + + @SubscribeEvent(priority = EventPriority.LOW, receiveCanceled = true) + fun onFirstChatEvent(event: PacketEvent.ReceiveEvent) { + if (!isEnabled()) return + val packet = event.packet + if (packet !is S02PacketChat) return + val messageComponent = packet.chatComponent + + val message = LorenzUtils.stripVanillaMessage(messageComponent.formattedText) + if (packet.type.toInt() != 0) return + + partyPattern.matchMatcher(message) { + val playerName = group("playerName") + val x = group("x").trim().toInt() + val y = group("y").trim().toInt() + val z = group("z").trim().toInt() + val location = LorenzVec(x, y, z) + + val cleanName = playerName.cleanPlayerName() + if (!waypoints.containsKey(cleanName)) { + LorenzUtils.chat("§e[SkyHanni] $playerName §l§efound an inquisitor at §l§c$x $y $z!") + if (cleanName != LorenzUtils.getPlayerName()) { + TitleUtils.sendTitle("§dINQUISITOR §efrom §b$cleanName", 5_000) + SoundUtils.playBeepSound() + } + } + waypoints = waypoints.editCopy { this[cleanName] = location } + if (config.focusInquisitor) { + GriffinBurrowHelper.setTargetLocation(location.add(0, 1, 0)) + GriffinBurrowHelper.animationLocation = LocationUtils.playerLocation() + } + + event.isCanceled = true + } + diedPattern.matchMatcher(message) { + val playerName = group("playerName").cleanPlayerName() + waypoints = waypoints.editCopy { remove(playerName) } + LorenzUtils.debug("Inquisitor died from '$playerName'") + } + } + + fun isEnabled() = LorenzUtils.inSkyBlock && LorenzUtils.skyBlockIsland == IslandType.HUB && config.enabled + + fun maybeRemove(playerName: String) { + if (!DamageIndicatorManager.isBossSpawned(BossType.MINOTAUR)) { + waypoints = waypoints.editCopy { remove(playerName) } + LorenzUtils.chat("§e[SkyHanni] Inquisitor from $playerName not found, deleting.") + } + } +} diff --git a/src/main/java/at/hannibal2/skyhanni/utils/LorenzUtils.kt b/src/main/java/at/hannibal2/skyhanni/utils/LorenzUtils.kt index 4a67184f2..df636e0ae 100644 --- a/src/main/java/at/hannibal2/skyhanni/utils/LorenzUtils.kt +++ b/src/main/java/at/hannibal2/skyhanni/utils/LorenzUtils.kt @@ -234,13 +234,17 @@ object LorenzUtils { return this } - private var lastCommandSent = 0L + private var lastMessageSent = 0L fun sendCommandToServer(command: String) { - if (System.currentTimeMillis() > lastCommandSent + 2_000) { - lastCommandSent = System.currentTimeMillis() + sendMessageToServer("/$command") + } + + fun sendMessageToServer(message: String) { + if (System.currentTimeMillis() > lastMessageSent + 2_000) { + lastMessageSent = System.currentTimeMillis() val thePlayer = Minecraft.getMinecraft().thePlayer - thePlayer.sendChatMessage("/$command") + thePlayer.sendChatMessage(message) } } diff --git a/src/main/java/at/hannibal2/skyhanni/utils/StringUtils.kt b/src/main/java/at/hannibal2/skyhanni/utils/StringUtils.kt index 06187da3c..b13dbc59a 100644 --- a/src/main/java/at/hannibal2/skyhanni/utils/StringUtils.kt +++ b/src/main/java/at/hannibal2/skyhanni/utils/StringUtils.kt @@ -57,9 +57,19 @@ object StringUtils { fun String.matchRegex(@Language("RegExp") regex: String): Boolean = regex.toRegex().matches(this) - private fun String.removeAtBeginning(text: String): String = if (this.startsWith(text)) substring(text.length) else this + private fun String.removeAtBeginning(text: String): String = + if (this.startsWith(text)) substring(text.length) else this // TODO find better name for this method inline fun <T> Pattern.matchMatcher(text: String, consumer: Matcher.() -> T) = matcher(text).let { if (it.matches()) consumer(it) else null } + + fun String.cleanPlayerName(): String { + val split = split(" ") + return if (split.size > 1) { + split[1].removeColor() + } else { + split[0].removeColor() + } + } } |