-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ed03850
commit 682ac8f
Showing
4 changed files
with
71 additions
and
0 deletions.
There are no files selected for viewing
62 changes: 62 additions & 0 deletions
62
src/main/kotlin/dev/exceptionteam/sakura/features/modules/impl/misc/EventNotifier.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
package dev.exceptionteam.sakura.features.modules.impl.misc | ||
|
||
import dev.exceptionteam.sakura.events.NonNullContext | ||
import dev.exceptionteam.sakura.events.impl.PacketEvents | ||
import dev.exceptionteam.sakura.events.nonNullListener | ||
import dev.exceptionteam.sakura.features.modules.Category | ||
import dev.exceptionteam.sakura.features.modules.Module | ||
import dev.exceptionteam.sakura.features.modules.impl.client.Language | ||
import dev.exceptionteam.sakura.utils.ingame.ChatUtils | ||
import net.minecraft.client.multiplayer.PlayerInfo | ||
import net.minecraft.network.protocol.game.ClientboundPlayerInfoRemovePacket | ||
import net.minecraft.network.protocol.game.ClientboundPlayerInfoUpdatePacket | ||
|
||
object EventNotifier: Module( | ||
name = "event-notifier", | ||
category = Category.MISC | ||
) { | ||
private val playerJoin by setting("player-join", true) | ||
private val playerLeave by setting("player-leave", true) | ||
|
||
init { | ||
nonNullListener<PacketEvents.Receive> { it -> | ||
if (it.packet is ClientboundPlayerInfoUpdatePacket && playerJoin) { | ||
val packet: ClientboundPlayerInfoUpdatePacket = it.packet | ||
if (!packet.actions().contains(ClientboundPlayerInfoUpdatePacket.Action.ADD_PLAYER)) return@nonNullListener | ||
sendJoinMessage(packet) | ||
} | ||
if (it.packet is ClientboundPlayerInfoRemovePacket && playerLeave) { | ||
val packet: ClientboundPlayerInfoRemovePacket = it.packet | ||
sendLeaveMessage(packet) | ||
} | ||
} | ||
} | ||
|
||
private fun sendJoinMessage(packet: ClientboundPlayerInfoUpdatePacket) { | ||
for (entry in packet.entries()) { | ||
val player = entry.profile ?: continue | ||
when (Language.language) { | ||
Language.Languages.EN_US -> { | ||
ChatUtils.sendMessage("Player ${player.name} joined!") | ||
} | ||
Language.Languages.ZH_CN -> { | ||
ChatUtils.sendMessage("玩家 ${player.name} 加入了伺服器!") | ||
} | ||
} | ||
} | ||
} | ||
|
||
private fun NonNullContext.sendLeaveMessage(packet: ClientboundPlayerInfoRemovePacket) { | ||
for (uuid in packet.profileIds) { | ||
val leave: PlayerInfo = connection.getPlayerInfo(uuid) ?: continue | ||
when (Language.language) { | ||
Language.Languages.EN_US -> { | ||
ChatUtils.sendMessage("Player ${leave.profile.name} leaved!") | ||
} | ||
Language.Languages.ZH_CN -> { | ||
ChatUtils.sendMessage("Player ${leave.profile.name} 离开了伺服器!") | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -46,6 +46,7 @@ object ModuleManager { | |
PacketEat, | ||
Disabler, | ||
FakePlayer, | ||
EventNotifier, | ||
|
||
// Render | ||
NameTags, | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters