| 1 | /*
|
| 2 | * This file is part of the Combatant Client distribution.
|
| 3 | * Copyright (c) 2026 pivosos2007.
|
| 4 | *
|
| 5 | * Licensed under the GNU General Public License v3.0.
|
| 6 | */
|
| 7 |
|
| 8 | package combatant.client.features.module.modules.misc;
|
| 9 |
|
| 10 | import net.minecraft.network.chat.Component;
|
| 11 | import combatant.client.config.values.BooleanValue;
|
| 12 | import combatant.client.config.values.SetValue;
|
| 13 | import combatant.client.features.gui.clickgui.settings.TextListSetting;
|
| 14 | import combatant.client.features.module.Module;
|
| 15 | import combatant.client.features.module.ModuleCategory;
|
| 16 | import combatant.client.features.module.ModuleInfo;
|
| 17 |
|
| 18 | import java.util.Locale;
|
| 19 | import java.util.Set;
|
| 20 |
|
| 21 | //todo Description
|
| 22 | @ModuleInfo(
|
| 23 | id = "message_filter",
|
| 24 | displayName = "MessageFilter",
|
| 25 | category = ModuleCategory.MISC
|
| 26 | )
|
| 27 | public class MessageFilter extends Module {
|
| 28 |
|
| 29 | private static final String SETTING_FILTER_CHAT = "filter_chat";
|
| 30 | private static final String SETTING_FILTER_HUD = "filter_hud";
|
| 31 | private static final String SETTING_CHAT_FILTERS = "chat_filters";
|
| 32 | private static final String SETTING_HUD_FILTERS = "hud_filters";
|
| 33 |
|
| 34 | private final BooleanValue chatEnabled = bool("filter_chat", SETTING_FILTER_CHAT, false);
|
| 35 |
|
| 36 | private final SetValue chatFilters = textList("chat_filters", SETTING_CHAT_FILTERS, TextListSetting.PickerMode.TEXT);
|
| 37 |
|
| 38 | private final BooleanValue hudEnabled = bool("filter_hud", SETTING_FILTER_HUD, false);
|
| 39 |
|
| 40 | private final SetValue hudFilters = textList("hud_filters", SETTING_HUD_FILTERS, TextListSetting.PickerMode.TEXT);
|
| 41 |
|
| 42 | public boolean shouldHideChat(Component message) {
|
| 43 | return isEnabled() && chatEnabled.get() && matches(message, chatFilters.get());
|
| 44 | }
|
| 45 |
|
| 46 | public boolean shouldHideHud(Component message) {
|
| 47 | return isEnabled() && hudEnabled.get() && matches(message, hudFilters.get());
|
| 48 | }
|
| 49 |
|
| 50 | private boolean matches(Component message, Set<String> patterns) {
|
| 51 | if (patterns.isEmpty() || message == null) return false;
|
| 52 | String body = message.getString().toLowerCase(Locale.ROOT);
|
| 53 | for (String pat : patterns) {
|
| 54 | if (pat == null) continue;
|
| 55 | String needle = pat.trim().toLowerCase(Locale.ROOT);
|
| 56 | if (needle.isEmpty()) continue;
|
| 57 | if (body.contains(needle)) return true;
|
| 58 | }
|
| 59 | return false;
|
| 60 | }
|
| 61 | }
|
| 62 |
|