Search in sources :

Example 1 with GameMessageS2CPacket

use of net.minecraft.network.packet.s2c.play.GameMessageS2CPacket in project BleachHack by BleachDrinker420.

the class BetterChat method onPacketRead.

@BleachSubscribe
public void onPacketRead(EventPacket.Read event) {
    if (event.getPacket() instanceof GameMessageS2CPacket) {
        GameMessageS2CPacket packet = (GameMessageS2CPacket) event.getPacket();
        if (packet.getLocation() == MessageType.GAME_INFO)
            return;
        Text message = packet.getMessage().shallowCopy();
        if (getSetting(6).asToggle().getState()) {
            message = Texts.forEachWord(message, (string, style) -> {
                String stripped = Formatting.strip(string);
                if (stripped.matches("['\u00a1-\u00f5]+\u00ff[0-~]+")) {
                    String decrypted = decrypt(stripped);
                    if (decrypted != null) {
                        return new LiteralText("<").styled(s -> s.withColor(BleachHack.watermark.getColor1())).append(new LiteralText(decrypted).styled(s -> s.withColor(0xffffff).withHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new LiteralText(string).setStyle(style))))).append(new LiteralText(">").styled(s -> s.withColor(BleachHack.watermark.getColor2())));
                    }
                }
                return null;
            });
        }
        if (!filterPatterns.isEmpty() && getSetting(4).asToggle().getState()) {
            int mode = getSetting(4).asToggle().getChild(0).asMode().getMode();
            if (mode == 0) {
                for (Pattern pattern : filterPatterns) {
                    message = Texts.replaceAll(message, pattern, (string, style) -> new LiteralText(StringUtils.repeat('|', string.length() * 2)).styled(s -> s.withColor(Formatting.GRAY).withHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new LiteralText(string).setStyle(style)))));
                }
            } else {
                for (Pattern pat : filterPatterns) {
                    if (pat.matcher(message.getString()).find()) {
                        if (mode == 1) {
                            Text messageCopy = message.shallowCopy();
                            message = new LiteralText("\u00a77Blocked Message").styled(style -> style.withHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, messageCopy)));
                            break;
                        } else {
                            event.setCancelled(true);
                            return;
                        }
                    }
                }
            }
        }
        if (getSetting(3).asToggle().getState()) {
            DateTimeFormatter formatter = getSetting(3).asToggle().getChild(0).asToggle().getState() ? DateTimeFormatter.ofPattern("HH:mm:ss") : DateTimeFormatter.ofPattern("HH:mm");
            message = new LiteralText("\u00a78[\u00a77" + LocalDateTime.now().format(formatter) + "\u00a78] ").append(message);
        }
        if (!message.equals(packet.getMessage())) {
            packet.message = message;
        }
    }
}
Also used : JsonParseException(com.google.gson.JsonParseException) BleachSubscribe(org.bleachhack.eventbus.BleachSubscribe) LiteralText(net.minecraft.text.LiteralText) java.util(java.util) ChatMessageC2SPacket(net.minecraft.network.packet.c2s.play.ChatMessageC2SPacket) ModuleCategory(org.bleachhack.module.ModuleCategory) MessageType(net.minecraft.network.MessageType) Command(org.bleachhack.command.Command) LocalDateTime(java.time.LocalDateTime) Hashing(com.google.common.hash.Hashing) ArrayUtils(org.apache.commons.lang3.ArrayUtils) BleachFileHelper(org.bleachhack.util.io.BleachFileHelper) HoverEvent(net.minecraft.text.HoverEvent) StringUtils(org.apache.commons.lang3.StringUtils) JsonElement(com.google.gson.JsonElement) SettingMode(org.bleachhack.setting.module.SettingMode) ThreadLocalRandom(java.util.concurrent.ThreadLocalRandom) CharMap(org.bleachhack.module.mods.BetterChat.CustomFont.CharMap) BleachLogger(org.bleachhack.util.BleachLogger) Ascii85(com.github.fzakaria.ascii85.Ascii85) EventPacket(org.bleachhack.event.events.EventPacket) GameMessageS2CPacket(net.minecraft.network.packet.s2c.play.GameMessageS2CPacket) Texts(org.bleachhack.util.Texts) PatternSyntaxException(java.util.regex.PatternSyntaxException) BleachHack(org.bleachhack.BleachHack) StandardCharsets(java.nio.charset.StandardCharsets) Module(org.bleachhack.module.Module) Formatting(net.minecraft.util.Formatting) DateTimeFormatter(java.time.format.DateTimeFormatter) Entry(java.util.Map.Entry) Text(net.minecraft.text.Text) SettingToggle(org.bleachhack.setting.module.SettingToggle) Pattern(java.util.regex.Pattern) HoverEvent(net.minecraft.text.HoverEvent) Pattern(java.util.regex.Pattern) GameMessageS2CPacket(net.minecraft.network.packet.s2c.play.GameMessageS2CPacket) LiteralText(net.minecraft.text.LiteralText) Text(net.minecraft.text.Text) DateTimeFormatter(java.time.format.DateTimeFormatter) LiteralText(net.minecraft.text.LiteralText) BleachSubscribe(org.bleachhack.eventbus.BleachSubscribe)

Example 2 with GameMessageS2CPacket

use of net.minecraft.network.packet.s2c.play.GameMessageS2CPacket in project pingspam by BasiqueEvangelist.

the class PingLogic method pingOnlinePlayer.

public static void pingOnlinePlayer(ServerPlayerEntity player, Text message, MessageType type, UUID senderUUID) {
    SoundEvent pingSound = PlayerUtils.getPingSound(player);
    if (pingSound != null) {
        player.playSound(pingSound, SoundCategory.PLAYERS, 1.0F, 1.0F);
    }
    List<Text> unreadPings = PlayerUtils.getUnreadPingsFor(player);
    while (unreadPings.size() >= 100) {
        unreadPings.remove(0);
    }
    unreadPings.add(message);
    Text pingMessage = message.shallowCopy().formatted(Formatting.AQUA);
    player.networkHandler.sendPacket(new GameMessageS2CPacket(pingMessage, type, senderUUID));
}
Also used : SoundEvent(net.minecraft.sound.SoundEvent) GameMessageS2CPacket(net.minecraft.network.packet.s2c.play.GameMessageS2CPacket) LiteralText(net.minecraft.text.LiteralText) Text(net.minecraft.text.Text)

Example 3 with GameMessageS2CPacket

use of net.minecraft.network.packet.s2c.play.GameMessageS2CPacket in project pingspam by BasiqueEvangelist.

the class PlayerManagerMixin method onMessageBroadcasted.

@Redirect(method = "broadcastChatMessage", at = @At(value = "INVOKE", target = "Lnet/minecraft/server/PlayerManager;sendToAll(Lnet/minecraft/network/Packet;)V"))
public void onMessageBroadcasted(PlayerManager playerManager, Packet<?> packet) {
    GameMessageS2CPacketAccessor access = (GameMessageS2CPacketAccessor) packet;
    PingLogic.ProcessedPing result = PingLogic.processPings(playerManager, access.pingspam$getMessage(), access.pingspam$getLocation(), access.pingspam$getSenderUuid());
    if (result.pingSucceeded && result.sender != null) {
        if (!result.pingedPlayers.getOnlinePlayers().contains(result.sender)) {
            result.sender.networkHandler.sendPacket(new GameMessageS2CPacket(access.pingspam$getMessage().shallowCopy().formatted(Formatting.GOLD), access.pingspam$getLocation(), access.pingspam$getSenderUuid()));
            result.pingedPlayers.add(result.sender);
        }
    }
    for (ServerPlayerEntity player : players) {
        if (!result.pingedPlayers.getOnlinePlayers().contains(player))
            player.networkHandler.sendPacket(packet);
    }
}
Also used : GameMessageS2CPacket(net.minecraft.network.packet.s2c.play.GameMessageS2CPacket) ServerPlayerEntity(net.minecraft.server.network.ServerPlayerEntity) PingLogic(me.basiqueevangelist.pingspam.utils.PingLogic) Redirect(org.spongepowered.asm.mixin.injection.Redirect)

Aggregations

GameMessageS2CPacket (net.minecraft.network.packet.s2c.play.GameMessageS2CPacket)3 LiteralText (net.minecraft.text.LiteralText)2 Text (net.minecraft.text.Text)2 Ascii85 (com.github.fzakaria.ascii85.Ascii85)1 Hashing (com.google.common.hash.Hashing)1 JsonElement (com.google.gson.JsonElement)1 JsonParseException (com.google.gson.JsonParseException)1 StandardCharsets (java.nio.charset.StandardCharsets)1 LocalDateTime (java.time.LocalDateTime)1 DateTimeFormatter (java.time.format.DateTimeFormatter)1 java.util (java.util)1 Entry (java.util.Map.Entry)1 ThreadLocalRandom (java.util.concurrent.ThreadLocalRandom)1 Pattern (java.util.regex.Pattern)1 PatternSyntaxException (java.util.regex.PatternSyntaxException)1 PingLogic (me.basiqueevangelist.pingspam.utils.PingLogic)1 MessageType (net.minecraft.network.MessageType)1 ChatMessageC2SPacket (net.minecraft.network.packet.c2s.play.ChatMessageC2SPacket)1 ServerPlayerEntity (net.minecraft.server.network.ServerPlayerEntity)1 SoundEvent (net.minecraft.sound.SoundEvent)1