Skip to content

Commit

Permalink
Added Notifications.VisualRange setting, added TimerUtil
Browse files Browse the repository at this point in the history
  • Loading branch information
ya-ilya committed Aug 26, 2023
1 parent 5f1f42f commit f3b16df
Show file tree
Hide file tree
Showing 9 changed files with 100 additions and 19 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.progreso.client.accessors

import net.minecraft.entity.LivingEntity
import net.minecraft.entity.player.PlayerEntity
import net.minecraft.network.packet.c2s.play.ChatMessageC2SPacket
import net.minecraft.network.packet.s2c.play.EntityStatusS2CPacket
Expand All @@ -8,7 +9,7 @@ import org.progreso.api.managers.CommandManager
import org.progreso.api.managers.ModuleManager
import org.progreso.client.Client
import org.progreso.client.Client.Companion.mc
import org.progreso.client.events.entity.PlayerDeathEvent
import org.progreso.client.events.entity.EntityDeathEvent
import org.progreso.client.events.eventListener
import org.progreso.client.events.input.CharEvent
import org.progreso.client.events.input.KeyEvent
Expand Down Expand Up @@ -60,9 +61,9 @@ object EventAccessor : EventAccessor {
}

safeEventListener<TickEvent> { _ ->
for (player in mc.world.players) {
if (player.deathTime > 0 || player.health <= 0) {
Client.EVENT_BUS.post(PlayerDeathEvent(player))
for (entity in mc.world.entities.filterIsInstance<LivingEntity>()) {
if (entity.deathTime > 0 || entity.health <= 0) {
Client.EVENT_BUS.post(EntityDeathEvent(entity))
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package org.progreso.client.events.entity

import net.minecraft.entity.Entity
import org.progreso.api.event.Event

data class EntityDeathEvent(val entity: Entity) : Event()

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package org.progreso.client.managers

import net.minecraft.entity.player.PlayerEntity
import org.progreso.api.Api
import org.progreso.client.events.entity.PlayerDeathEvent
import org.progreso.client.events.entity.EntityDeathEvent
import org.progreso.client.events.eventListener
import org.progreso.client.events.player.TotemPopEvent
import java.util.concurrent.ConcurrentHashMap
Expand All @@ -21,8 +21,10 @@ object CombatManager {
}
}

eventListener<PlayerDeathEvent> {
pops.remove(it.player)
eventListener<EntityDeathEvent> { event ->
if (event.entity is PlayerEntity) {
pops.remove(event.entity)
}
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,27 @@
package org.progreso.client.modules.client

import net.minecraft.entity.player.PlayerEntity
import net.minecraft.util.Formatting
import org.progreso.api.Api
import org.progreso.api.event.events.ModuleEvent
import org.progreso.api.managers.FriendManager
import org.progreso.api.module.AbstractModule
import org.progreso.client.Client.Companion.mc
import org.progreso.client.events.entity.PlayerDeathEvent
import org.progreso.client.events.entity.EntityDeathEvent
import org.progreso.client.events.misc.TickEvent
import org.progreso.client.events.player.TotemPopEvent
import org.progreso.client.events.safeEventListener
import org.progreso.client.managers.CombatManager
import org.progreso.client.util.client.TimerUtil

@AbstractModule.AutoRegister
object Notifications : AbstractModule() {
private val modules by setting("Modules", true)
private val pops by setting("Pops", true)
private val visualRange by setting("VisualRange", false)

private val visualRangeTimer = TimerUtil.createTimer(TimerUtil.TimeUnit.Second)
private val visualRangePlayers = mutableSetOf<PlayerEntity>()

init {
safeEventListener<ModuleEvent.Toggle> { event ->
Expand All @@ -40,14 +48,47 @@ object Notifications : AbstractModule() {
}
}

safeEventListener<PlayerDeathEvent> { event ->
if (!pops) return@safeEventListener
safeEventListener<EntityDeathEvent> { event ->
if (!pops || event.entity !is PlayerEntity) return@safeEventListener

Api.CHAT.infoLocalized(
"module.notifications.death_message",
event.player.name.string,
CombatManager[event.player] ?: return@safeEventListener
event.entity.name.string,
CombatManager[event.entity] ?: return@safeEventListener
)
}

safeEventListener<TickEvent> { _ ->
if (!visualRange || !visualRangeTimer.tick(1L)) return@safeEventListener

val players = mc.world.players.toHashSet()

for (player in players) {
if (player == mc.player || FriendManager.isFriend(player.name.string)) continue

if (visualRangePlayers.add(player)) {
Api.CHAT.infoLocalized(
"module.notifications.visualrange_enter_message",
player.name.string
)
}
}

for (player in visualRangePlayers.toHashSet()) {
if (!players.contains(player)) {
visualRangePlayers.remove(player)

Api.CHAT.infoLocalized(
"module.notifications.visualrange_leave_message",
player.name.string
)
}
}
}

onDisable {
visualRangeTimer.reset()
visualRangePlayers.clear()
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ object Criticals : AbstractModule() {
eventListener<PacketEvent.Send<*>> { event ->
if (event.packet !is PlayerInteractEntityC2SPacket) return@eventListener
if (onlyKillAura && !KillAura.enabled) return@eventListener
if (mc.world.getBlockState(mc.player.blockPos).block == Blocks.COBWEB) return@eventListener
if (!mc.player.isOnGround || mc.world.getBlockState(mc.player.blockPos).block == Blocks.COBWEB) return@eventListener

val x = mc.player.x
val y = mc.player.y
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package org.progreso.client.util.client

object TimerUtil {
fun createTimer(unit: TimeUnit): Timer {
return Timer(unit)
}

class Timer(val unit: TimeUnit) {
private val currentTime get() = System.currentTimeMillis()

var time = currentTime; private set

fun tick(number: Long): Boolean {
return (currentTime - time > number * unit.milliseconds).also {
if (it) reset()
}
}

fun skip(number: Long) {
time = currentTime - number * unit.milliseconds
}

fun reset() {
time = currentTime
}
}

enum class TimeUnit(val milliseconds: Long) {
Millisecond(1),
Second(1000),
Tick(50)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@
"module.notifications.module_message": "[Notifications] %s%s",
"module.notifications.pop_message": "[Notifications] %s has popped %d totems",
"module.notifications.death_message": "[Notifications] %s died after popping %d totems",
"module.notifications.visualrange_enter_message": "[Notifications] %s entered to visual range",
"module.notifications.visualrange_leave_message": "[Notifications] %s left visual range",

"gui.alts.title": "Alts",
"gui.alts.title.create_alt": "Create Alt",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@
"module.notifications.module_message": "[Notifications] %s%s",
"module.notifications.pop_message": "[Notifications] %s потреял %d тотемов",
"module.notifications.death_message": "[Notifications] %s умер после %d тотемов",
"module.notifications.visualrange_enter_message": "[Notifications] %s вошел в зону видимости",
"module.notifications.visualrange_leave_message": "[Notifications] %s покинул зону видимости",

"gui.alts.title": "Альты",
"gui.alts.title.create_alt": "Создать альт",
Expand Down

0 comments on commit f3b16df

Please sign in to comment.