diff --git a/README.md b/README.md index 845a20a..a835cad 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,7 @@ ![License](https://img.shields.io/github/license/udu3324/poinpow) ![Latest Releases](https://img.shields.io/github/v/release/udu3324/Poinpow) ![Github Downloads](https://img.shields.io/github/downloads/udu3324/poinpow/total) -![Modrinth Downloads](https://modrinth-utils.vercel.app/api/badge/downloads?id=zmUzIoT1) +![Modrinth Downloads](https://img.shields.io/badge/dynamic/json?color=1bd96a&label=modrinth&query=downloads&suffix=%20downloads&url=https%3A%2F%2Fapi.modrinth.com%2Fv2%2Fproject%2Fpoinpow) ![Mod loader: Fabric](https://img.shields.io/badge/modloader-Fabric-decea6?style=round) ![Requires](https://img.shields.io/badge/requires-Fabric%20API-dece5a?style=round) [![Discord Server](https://img.shields.io/badge/Official%20Discord%20Server-7289DA?style=round&logo=discord&logoColor=white)](https://discord.gg/NXm9tJvyBT) @@ -13,9 +13,9 @@ Poinpow adds **utilities/features** that **make the player experience 102% better**. If you catch a bug, create an issue in the repo or send it to me in this [discord server](https://discord.gg/NXm9tJvyBT). - **BlockMinehutAds** - Blocks ads from minehut that are sent in free servers | `Example: [Minehut] boost your server speed!!! go to this link!!!` +- **ChatPhraseFilter** - Store a user made list of regex and filter lobby`Example: /poinpow chat_phrase_filter "join my server"` - **BlockLobbyAds** - Blocks player made ads in the lobby | `Example: [Ad] NintendoOS: /join fishwind join my server for op yes` - **AutoSkipBarrier** - Automatically skip the ads when joining minehut or free servers -- **RemoveLobbyRanks** - Removes ranks from players in lobby, and generalize colors - **BlockFreeCredits** - Blocks the vote messages encouraging free credits | `Example: [Minehut] PuppiesAreNice just got free credits by voting via /vote` - **BlockLobbyWelcome** - Blocks the lobby join message that sometimes has an ad in it - **BlockLobbyMapAds** - Removes the humungous map art that advertises things in lobby. @@ -54,4 +54,4 @@ If you want to **contribute to the code** or **make the jar yourself**, you can **No.** I read the rules, and it doesn't break any. Unless..... "Minehut reserves the right to suspend or refuse service for users and servers at any time at their discretion." bruh ## 💚 How to Contribute -You can contribute by starring the repo, reporting issues, and creating pull requests. You can also send feedback in the [discord server](https://discord.gg/NXm9tJvyBT). \ No newline at end of file +You can contribute by starring the repo, reporting issues, and creating pull requests. You can also send feedback in the [discord server](https://discord.gg/NXm9tJvyBT). diff --git a/gradle.properties b/gradle.properties index a36e844..c13f049 100644 --- a/gradle.properties +++ b/gradle.properties @@ -4,14 +4,14 @@ org.gradle.parallel=true # Fabric Properties # check these on https://fabricmc.net/develop - minecraft_version=1.19.4 - yarn_mappings=1.19.4+build.1 - loader_version=0.14.17 + minecraft_version=1.20.1 + yarn_mappings=1.20.1+build.9 + loader_version=0.14.21 # Mod Properties - mod_version = 1.2.4 + mod_version = 1.2.5 maven_group = com.udu3324 archives_base_name = poinpow # Dependencies - fabric_version=0.76.0+1.19.4 + fabric_version=0.85.0+1.20.1 \ No newline at end of file diff --git a/src/main/java/com/udu3324/poinpow/Config.java b/src/main/java/com/udu3324/poinpow/Config.java index cc8010f..3566b59 100644 --- a/src/main/java/com/udu3324/poinpow/Config.java +++ b/src/main/java/com/udu3324/poinpow/Config.java @@ -10,6 +10,7 @@ import java.io.FileWriter; import java.io.IOException; import java.util.ArrayList; +import java.util.regex.Pattern; public class Config { public static File configFile = new File(FabricLoader.getInstance().getConfigDir().toString() + File.separator + "poinpow.cfg"); @@ -63,16 +64,12 @@ public static String getValueFromConfig(String value) { //example: setValueFromConfig("api-key", "thisIsTheApiKey") public static void setValueFromConfig(String value, String data) { try { - // get the lines in the config (arraylist) - BufferedReader bufferedReader = new BufferedReader(new FileReader(configFile)); - - ArrayList lines = new ArrayList<>(); + ArrayList lines = getConfig(); - String l; - while ((l = bufferedReader.readLine()) != null) { - lines.add(l); + if (lines == null) { + System.out.println("Problem reading poinpow config!!! Error!!!"); + return; } - bufferedReader.close(); // modify the values in the config for (int i = 0; i < lines.size(); i++) { @@ -84,6 +81,7 @@ public static void setValueFromConfig(String value, String data) { if (value.equals(line.substring(0, line.indexOf(":")))) { // it's the line being modified lines.set(i, value + ": " + data); + break; } } } @@ -102,6 +100,106 @@ public static void setValueFromConfig(String value, String data) { } } + // + public static ArrayList getListOfRegex() { + try { + ArrayList lines = getConfig(); + + if (lines == null) { + System.out.println("Problem reading poinpow config!!! Error!!!"); + return null; + } + + //config is out of date! reset + if (!lines.contains("# Each line below is regex for ChatPhraseFilter to use.")) { + Poinpow.log.info("bad!!! missing regex for chat phrase filter"); + delete(); + create(); + return null; + } + + ArrayList linesOfRegex = new ArrayList<>(); + + //after the regex comment, put everything else in the array + int commentLocation = lines.indexOf("# Each line below is regex for ChatPhraseFilter to use.") + 1; + for (int i = commentLocation; i < lines.size(); i++) { + if (!lines.get(i).isEmpty()) { + String edit = lines.get(i).replace("\n", ""); + linesOfRegex.add(Pattern.compile(edit)); + } + } + + if (linesOfRegex.size() == 0) return null; + + return linesOfRegex; + } catch (Exception e) { + Poinpow.log.info("Problem reading file. " + e); + return null; + } + } + + public static void addRegex(String regex) { + try { + FileWriter writer = new FileWriter(configFile, true); + + writer.write("\n" + regex); + writer.close(); + } catch (IOException e) { + e.printStackTrace(); + } + } + + public static void removeRegex(String regex) { + try { + ArrayList lines = getConfig(); + + if (lines == null) { + System.out.println("Problem reading poinpow config!!! Error!!!"); + return; + } + + // modify the values in the config + for (int i = 0; i < lines.size(); i++) { + if (lines.get(i).equals(regex)) { + lines.remove(i); + break; + } + } + + //overwrite the rest + FileWriter writer = new FileWriter(configFile); + + //write array back to new file + for (String line : lines) { + writer.write(line + System.lineSeparator()); + } + + writer.close(); + } catch (IOException e) { + e.printStackTrace(); + } + } + + //get the lines in the config + private static ArrayList getConfig() { + try { + BufferedReader bufferedReader = new BufferedReader(new FileReader(configFile)); + ArrayList lines = new ArrayList<>(); + + String l; + + while ((l = bufferedReader.readLine()) != null) { + lines.add(l); + } + bufferedReader.close(); + + return lines; + } catch (IOException e) { + e.printStackTrace(); + return null; + } + } + public static void delete() { if (configFile.delete()) Poinpow.log.info("Config file has been successfully deleted."); @@ -116,13 +214,16 @@ public static void create() { w.write("# Poinpow v" + version + " by udu3324 | Config" + System.lineSeparator()); w.write("# Hey! I suggest you use the in-game commands instead of editing the config directly." + System.lineSeparator()); w.write(System.lineSeparator()); - w.write(RemoveLobbyRanks.name + ": false" + System.lineSeparator()); w.write(AutoSkipBarrier.name + ": true" + System.lineSeparator()); + w.write(ChatPhraseFilter.name + ": true" + System.lineSeparator()); w.write(BlockLobbyWelcome.name + ": true" + System.lineSeparator()); w.write(BlockLobbyAds.name + ": true" + System.lineSeparator()); w.write(BlockMinehutAds.name + ": true" + System.lineSeparator()); w.write(BlockFreeCredits.name + ": true" + System.lineSeparator()); w.write(BlockLobbyMapAds.name + ": true" + System.lineSeparator()); + w.write(System.lineSeparator()); + w.write("# Each line below is regex for ChatPhraseFilter to use." + System.lineSeparator()); + w.write("/join"); w.close(); Poinpow.log.info("New config created."); @@ -139,8 +240,8 @@ public static void create() { create(); } else { //set values from config since its good - RemoveLobbyRanks.toggled.set(Boolean.parseBoolean(getValueFromConfig(RemoveLobbyRanks.name))); AutoSkipBarrier.toggled.set(Boolean.parseBoolean(getValueFromConfig(AutoSkipBarrier.name))); + ChatPhraseFilter.toggled.set(Boolean.parseBoolean(getValueFromConfig(ChatPhraseFilter.name))); BlockLobbyWelcome.toggled.set(Boolean.parseBoolean(getValueFromConfig(BlockLobbyWelcome.name))); BlockLobbyAds.toggled.set(Boolean.parseBoolean(getValueFromConfig(BlockLobbyAds.name))); BlockMinehutAds.toggled.set(Boolean.parseBoolean(getValueFromConfig(BlockMinehutAds.name))); diff --git a/src/main/java/com/udu3324/poinpow/commands/Commands.java b/src/main/java/com/udu3324/poinpow/commands/Commands.java index 58654eb..4289be6 100644 --- a/src/main/java/com/udu3324/poinpow/commands/Commands.java +++ b/src/main/java/com/udu3324/poinpow/commands/Commands.java @@ -2,6 +2,7 @@ import com.mojang.brigadier.Command; import com.mojang.brigadier.CommandDispatcher; +import com.mojang.brigadier.arguments.StringArgumentType; import com.udu3324.poinpow.Config; import com.udu3324.poinpow.utils.*; import net.fabricmc.fabric.api.client.command.v2.FabricClientCommandSource; @@ -12,6 +13,7 @@ import java.util.concurrent.atomic.AtomicBoolean; +import static net.fabricmc.fabric.api.client.command.v2.ClientCommandManager.argument; import static net.fabricmc.fabric.api.client.command.v2.ClientCommandManager.literal; public class Commands { @@ -22,16 +24,19 @@ public static void register(CommandDispatcher dispatc dispatcher.register(literal("poinpow") .executes(ctx -> help(ctx.getSource())) - .then(literal(RemoveLobbyRanks.name) - .executes(ctx -> description(ctx.getSource(), RemoveLobbyRanks.name, RemoveLobbyRanks.description, RemoveLobbyRanks.toggled)) - .then(literal("true").executes(ctx -> toggle(ctx.getSource(), RemoveLobbyRanks.name, RemoveLobbyRanks.toggled, true))) - .then(literal("false").executes(ctx -> toggle(ctx.getSource(), RemoveLobbyRanks.name, RemoveLobbyRanks.toggled, false)))) - .then(literal(AutoSkipBarrier.name) .executes(ctx -> description(ctx.getSource(), AutoSkipBarrier.name, AutoSkipBarrier.description, AutoSkipBarrier.toggled)) .then(literal("true").executes(ctx -> toggle(ctx.getSource(), AutoSkipBarrier.name, AutoSkipBarrier.toggled, true))) .then(literal("false").executes(ctx -> toggle(ctx.getSource(), AutoSkipBarrier.name, AutoSkipBarrier.toggled, false)))) + .then(literal(ChatPhraseFilter.name) + .executes(ctx -> description(ctx.getSource(), ChatPhraseFilter.name, ChatPhraseFilter.description, ChatPhraseFilter.toggled)) + .then(literal("add").then(argument("regex", StringArgumentType.string()).executes(ChatPhraseFilter::add))) + .then(literal("remove").then(argument("regex", StringArgumentType.string()).executes(ChatPhraseFilter::remove))) + .then(literal("list").executes(ctx -> ChatPhraseFilter.list(ctx.getSource()))) + .then(literal("true").executes(ctx -> toggle(ctx.getSource(), ChatPhraseFilter.name, ChatPhraseFilter.toggled, true))) + .then(literal("false").executes(ctx -> toggle(ctx.getSource(), ChatPhraseFilter.name, ChatPhraseFilter.toggled, false)))) + .then(literal(BlockLobbyWelcome.name) .executes(ctx -> description(ctx.getSource(), BlockLobbyWelcome.name, BlockLobbyWelcome.description, BlockLobbyWelcome.toggled)) .then(literal("true").executes(ctx -> toggle(ctx.getSource(), BlockLobbyWelcome.name, BlockLobbyWelcome.toggled, true))) @@ -109,13 +114,6 @@ private static int help(FabricClientCommandSource source) { .withUnderline(true) )); - //remove lobby ranks - source.sendFeedback(Text.literal("[toggled|" + RemoveLobbyRanks.toggled + "] " + RemoveLobbyRanks.name + " (click 2 toggle)").styled(style -> style - .withHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, Text.literal(RemoveLobbyRanks.description + "\n\nClick to Toggle"))) - .withClickEvent(new ClickEvent(ClickEvent.Action.SUGGEST_COMMAND, "/poinpow " + RemoveLobbyRanks.name + " " + !RemoveLobbyRanks.toggled.get())) - .withColor(Formatting.DARK_GRAY) - )); - //auto skip barrier source.sendFeedback(Text.literal("[toggled|" + AutoSkipBarrier.toggled + "] " + AutoSkipBarrier.name).styled(style -> style .withHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, Text.literal(AutoSkipBarrier.description + "\n\nClick to Toggle"))) @@ -123,6 +121,13 @@ private static int help(FabricClientCommandSource source) { .withColor(Formatting.DARK_GRAY) )); + //auto skip barrier + source.sendFeedback(Text.literal("[toggled|" + ChatPhraseFilter.toggled + "] " + ChatPhraseFilter.name).styled(style -> style + .withHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, Text.literal(ChatPhraseFilter.description + "\n\nClick to Toggle"))) + .withClickEvent(new ClickEvent(ClickEvent.Action.SUGGEST_COMMAND, "/poinpow " + ChatPhraseFilter.name + " " + !ChatPhraseFilter.toggled.get())) + .withColor(Formatting.DARK_GRAY) + )); + //block lobby welcome source.sendFeedback(Text.literal("[toggled|" + BlockLobbyWelcome.toggled + "] " + BlockLobbyWelcome.name).styled(style -> style .withHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, Text.literal(BlockLobbyWelcome.description + "\n\nClick to Toggle"))) diff --git a/src/main/java/com/udu3324/poinpow/mixin/ChatMixin.java b/src/main/java/com/udu3324/poinpow/mixin/ChatMixin.java index eeee026..696121b 100644 --- a/src/main/java/com/udu3324/poinpow/mixin/ChatMixin.java +++ b/src/main/java/com/udu3324/poinpow/mixin/ChatMixin.java @@ -10,6 +10,7 @@ import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; + @Mixin(ChatHud.class) public class ChatMixin { @Inject(method = "addMessage(Lnet/minecraft/text/Text;Lnet/minecraft/network/message/MessageSignatureData;Lnet/minecraft/client/gui/hud/MessageIndicator;)V", at = @At("HEAD"), cancellable = true) @@ -27,7 +28,6 @@ private void onMessage(Text message, MessageSignatureData signature, MessageIndi if (BlockMinehutAds.check(chat, ci)) return; - //this should be left always at the bottom - RemoveLobbyRanks.check(chat, ci); + ChatPhraseFilter.check(chat, ci); } } diff --git a/src/main/java/com/udu3324/poinpow/utils/AutoSkipBarrier.java b/src/main/java/com/udu3324/poinpow/utils/AutoSkipBarrier.java index dbe972f..9603fb1 100644 --- a/src/main/java/com/udu3324/poinpow/utils/AutoSkipBarrier.java +++ b/src/main/java/com/udu3324/poinpow/utils/AutoSkipBarrier.java @@ -30,7 +30,7 @@ public static void rename() { if (client.player == null) return; if (client.interactionManager == null) return; - + ItemStack items; for (int itemIterator = 0; itemIterator < 9; itemIterator++) { items = client.player.getInventory().getStack(itemIterator); diff --git a/src/main/java/com/udu3324/poinpow/utils/BlockFreeCredits.java b/src/main/java/com/udu3324/poinpow/utils/BlockFreeCredits.java index c6e451c..d25b810 100644 --- a/src/main/java/com/udu3324/poinpow/utils/BlockFreeCredits.java +++ b/src/main/java/com/udu3324/poinpow/utils/BlockFreeCredits.java @@ -11,6 +11,8 @@ public class BlockFreeCredits { public static String description = "Blocks minehut encouraging /vote when other players do it."; public static AtomicBoolean toggled = new AtomicBoolean(true); + final static Pattern pattern = Pattern.compile("^\\[Minehut] [a-zA-Z0-9_.]{1,16} just got free credits by voting via /vote$"); + public static Boolean check(String chat, CallbackInfo ci) { // return false if toggled off if (!toggled.get()) return false; @@ -18,8 +20,6 @@ public static Boolean check(String chat, CallbackInfo ci) { // return if not on minehut if (!Poinpow.onMinehut) return false; - Pattern pattern = Pattern.compile("^\\[Minehut] [a-zA-Z0-9_.]{1,16} just got free credits by voting via /vote$"); - if (pattern.matcher(chat).find()) { Poinpow.log.info("Blocked: " + chat); ci.cancel(); diff --git a/src/main/java/com/udu3324/poinpow/utils/BlockLobbyAds.java b/src/main/java/com/udu3324/poinpow/utils/BlockLobbyAds.java index a92e3e4..f2e1a58 100644 --- a/src/main/java/com/udu3324/poinpow/utils/BlockLobbyAds.java +++ b/src/main/java/com/udu3324/poinpow/utils/BlockLobbyAds.java @@ -11,6 +11,8 @@ public class BlockLobbyAds { public static String description = "Blocks ads made by players in the lobby."; public static AtomicBoolean toggled = new AtomicBoolean(true); + final static Pattern pattern = Pattern.compile("\\[AD]"); + public static Boolean check(String chat, CallbackInfo ci) { // return false if toggled off if (!toggled.get()) return false; @@ -18,8 +20,6 @@ public static Boolean check(String chat, CallbackInfo ci) { // return if not on minehut if (!Poinpow.onMinehut) return false; - Pattern pattern = Pattern.compile("\\[AD]"); - if (pattern.matcher(chat).find() || chat.contains(": /join")) { Poinpow.log.info("Blocked: " + chat); ci.cancel(); diff --git a/src/main/java/com/udu3324/poinpow/utils/BlockLobbyMapAds.java b/src/main/java/com/udu3324/poinpow/utils/BlockLobbyMapAds.java index 2a6f805..33fe3ea 100644 --- a/src/main/java/com/udu3324/poinpow/utils/BlockLobbyMapAds.java +++ b/src/main/java/com/udu3324/poinpow/utils/BlockLobbyMapAds.java @@ -42,7 +42,7 @@ public static void block(Entity entity) { if (!itemFrame.containsMap()) return; - Poinpow.log.info("Blocked: Lobby Map Ad (" + itemFrame.getBlockX() + ", " + itemFrame.getBlockY() + ", " + itemFrame.getBlockZ() + ")"); + //Poinpow.log.info("Blocked: Lobby Map Ad (" + itemFrame.getBlockX() + ", " + itemFrame.getBlockY() + ", " + itemFrame.getBlockZ() + ")"); itemFrame.setHeldItemStack(item); itemFrame.setRotation(1); diff --git a/src/main/java/com/udu3324/poinpow/utils/BlockLobbyWelcome.java b/src/main/java/com/udu3324/poinpow/utils/BlockLobbyWelcome.java index 7d7e60a..b7aa420 100644 --- a/src/main/java/com/udu3324/poinpow/utils/BlockLobbyWelcome.java +++ b/src/main/java/com/udu3324/poinpow/utils/BlockLobbyWelcome.java @@ -1,8 +1,12 @@ package com.udu3324.poinpow.utils; import com.udu3324.poinpow.Poinpow; +import net.minecraft.client.MinecraftClient; +import net.minecraft.scoreboard.Scoreboard; +import net.minecraft.scoreboard.ScoreboardObjective; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; +import java.util.ArrayList; import java.util.concurrent.atomic.AtomicBoolean; import java.util.regex.Pattern; @@ -13,6 +17,9 @@ public class BlockLobbyWelcome { public static int limit = 0; private static Boolean ignoreChat = false; + + final static Pattern pattern = Pattern.compile("^Welcome back, [a-zA-Z0-9_.]{1,16}$"); + public static Boolean check(String chat, CallbackInfo ci) { // return false if toggled off if (!toggled.get()) return false; @@ -20,6 +27,17 @@ public static Boolean check(String chat, CallbackInfo ci) { // return if not on minehut if (!Poinpow.onMinehut) return false; + if (MinecraftClient.getInstance().player == null) return false; + + // check for scoreboard + Scoreboard scoreboard = MinecraftClient.getInstance().player.getScoreboard(); + ArrayList scores = new ArrayList<>(); + for (ScoreboardObjective objective : scoreboard.getObjectives()) { + scores.add(objective.getDisplayName().toString()); + } + + if (!scores.toString().toLowerCase().contains("minehut")) return false; + boolean blocked = false; if (ignoreChat) { @@ -36,8 +54,6 @@ public static Boolean check(String chat, CallbackInfo ci) { } } - Pattern pattern = Pattern.compile("^Welcome back, [a-zA-Z0-9_.]{1,16}$"); - if (pattern.matcher(chat).find()) { ignoreChat = true; blocked = true; diff --git a/src/main/java/com/udu3324/poinpow/utils/BlockMinehutAds.java b/src/main/java/com/udu3324/poinpow/utils/BlockMinehutAds.java index 182f0d7..997263e 100644 --- a/src/main/java/com/udu3324/poinpow/utils/BlockMinehutAds.java +++ b/src/main/java/com/udu3324/poinpow/utils/BlockMinehutAds.java @@ -11,6 +11,8 @@ public class BlockMinehutAds { public static String description = "Blocks ads made by minehut that show up before joining servers & ads in free sub-servers."; public static AtomicBoolean toggled = new AtomicBoolean(true); + final static Pattern pattern = Pattern.compile("^(\\n\\n|/n/n)\\[Minehut].*(\\n\\n|/n/n)$"); + public static Boolean check(String chat, CallbackInfo ci) { // return false if toggled off if (!toggled.get()) return false; @@ -18,10 +20,7 @@ public static Boolean check(String chat, CallbackInfo ci) { // return if not on minehut if (!Poinpow.onMinehut) return false; - Pattern pattern1 = Pattern.compile("^(\\n\\n|/n/n)\\[Minehut].*(\\n\\n|/n/n)$"); - Pattern pattern2 = Pattern.compile("^Welcome to Minehut! Start your Free Minecraft server now!"); - - if (pattern1.matcher(chat).find() || pattern2.matcher(chat).find()) { + if (pattern.matcher(chat).find()) { Poinpow.log.info("Blocked: " + chat); ci.cancel(); diff --git a/src/main/java/com/udu3324/poinpow/utils/ChatPhraseFilter.java b/src/main/java/com/udu3324/poinpow/utils/ChatPhraseFilter.java new file mode 100644 index 0000000..5b5544d --- /dev/null +++ b/src/main/java/com/udu3324/poinpow/utils/ChatPhraseFilter.java @@ -0,0 +1,142 @@ +package com.udu3324.poinpow.utils; + +import com.mojang.brigadier.Command; +import com.mojang.brigadier.arguments.StringArgumentType; +import com.mojang.brigadier.context.CommandContext; +import com.udu3324.poinpow.Config; +import com.udu3324.poinpow.Poinpow; +import com.udu3324.poinpow.commands.Commands; +import net.fabricmc.fabric.api.client.command.v2.FabricClientCommandSource; +import net.minecraft.client.MinecraftClient; +import net.minecraft.scoreboard.Scoreboard; +import net.minecraft.scoreboard.ScoreboardObjective; +import net.minecraft.text.ClickEvent; +import net.minecraft.text.Text; +import net.minecraft.util.Formatting; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; + +import java.util.ArrayList; +import java.util.concurrent.atomic.AtomicBoolean; +import java.util.regex.Pattern; + +public class ChatPhraseFilter { + public static String name = "chat_phrase_filter"; + public static String description = "This filters out messages in lobby that match the regex. Go to https://regex101.com to create some."; + public static AtomicBoolean toggled = new AtomicBoolean(true); + + public static ArrayList list = Config.getListOfRegex(); + + public static void check(String chat, CallbackInfo ci) { + // return false if toggled off + if (!toggled.get()) return; + + // return if not on minehut + if (!Poinpow.onMinehut) return; + + // return if there's nothing in the list + if (list == null || list.size() == 0) { + System.out.println("!!!!!!!!!! nothing in list"); + return; + } + + if (MinecraftClient.getInstance().player == null) return; + + // check for scoreboard + Scoreboard scoreboard = MinecraftClient.getInstance().player.getScoreboard(); + ArrayList scores = new ArrayList<>(); + for (ScoreboardObjective objective : scoreboard.getObjectives()) { + scores.add(objective.getDisplayName().toString()); + } + + if (!scores.toString().toLowerCase().contains("minehut")) return; + + for (Pattern p : list) { + if (p.matcher(chat).find()) { + Poinpow.log.info("Filtered: " + chat); + ci.cancel(); + return; + } + } + } + + public static int add(CommandContext context) { + Commands.running = true; + String input = StringArgumentType.getString(context, "regex"); + + //check if regex already exists + for (Pattern p : list) { + if (p.toString().equals(input)) { + context.getSource().sendFeedback(Text.literal("The regex you provided is already in the filter.").styled(style -> style.withColor(Formatting.RED))); + Commands.running = false; + return Command.SINGLE_SUCCESS; + } + } + + context.getSource().sendFeedback(Text.literal("\nAdded the regex below to ChatPhraseFilter").styled(style -> style.withColor(Formatting.GREEN))); + context.getSource().sendFeedback(Text.literal(input + "\n").styled(style -> style.withColor(Formatting.GOLD))); + + System.out.println("addRegex(): " + input); + + Config.addRegex(input); + list.add(Pattern.compile(input)); + + Commands.running = false; + return Command.SINGLE_SUCCESS; + } + + public static int remove(CommandContext context) { + Commands.running = true; + String input = StringArgumentType.getString(context, "regex"); + + //check if regex already exists + for (Pattern p : list) { + if (p.toString().equals(input)) { + System.out.println("removeRegex(): " + input); + + Config.removeRegex(input); + System.out.println("please!! " + list.remove(p)); + //list.remove(p); + + context.getSource().sendFeedback(Text.literal("Successfully removed \"" + input + "\" from the filter.").styled(style -> style.withColor(Formatting.GREEN))); + + Commands.running = false; + return Command.SINGLE_SUCCESS; + } + } + + context.getSource().sendFeedback(Text.literal("Couldn't find \"" + input + "\" in the list of regex! \nDo \"/poinpow " + name + " list\" to see a clickable list to remove regex.").styled(style -> style + .withClickEvent(new ClickEvent(ClickEvent.Action.SUGGEST_COMMAND, "/poinpow " + name + " list")) + .withUnderline(true) + .withColor(Formatting.RED) + )); + + Commands.running = false; + return Command.SINGLE_SUCCESS; + } + + public static int list(FabricClientCommandSource source) { + Commands.running = true; + + //first check if list has nothing in it + if (list == null || list.size() == 0) { + source.sendFeedback(Text.literal("\nThere is no regex in ChatPhraseFilter.").styled(style -> style.withColor(Formatting.BLUE))); + Commands.running = false; + return Command.SINGLE_SUCCESS; + } + + //show the list + source.sendFeedback(Text.literal("\nHere's the list of regex in ChatPhraseFilter.").styled(style -> style.withColor(Formatting.GREEN))); + + for (Pattern p : list) { + source.sendFeedback(Text.literal(p.toString()).styled(style -> style + .withClickEvent(new ClickEvent(ClickEvent.Action.SUGGEST_COMMAND, "/poinpow " + name + " remove " + "\"" + p + "\"")) + .withColor(Formatting.GOLD) + )); + } + + source.sendFeedback(Text.literal("Click on the text to remove it from the filter.\n").styled(style -> style.withColor(Formatting.RED))); + + Commands.running = false; + return Command.SINGLE_SUCCESS; + } +} diff --git a/src/main/java/com/udu3324/poinpow/utils/RemoveLobbyRanks.java b/src/main/java/com/udu3324/poinpow/utils/RemoveLobbyRanks.java deleted file mode 100644 index 6887fca..0000000 --- a/src/main/java/com/udu3324/poinpow/utils/RemoveLobbyRanks.java +++ /dev/null @@ -1,58 +0,0 @@ -package com.udu3324.poinpow.utils; - -import com.udu3324.poinpow.Poinpow; -import net.minecraft.client.MinecraftClient; -import net.minecraft.text.Text; -import net.minecraft.util.Formatting; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; - -import java.util.concurrent.atomic.AtomicBoolean; -import java.util.regex.Pattern; - -public class RemoveLobbyRanks { - public static String name = "remove_lobby_ranks"; - public static String description = "Remove ranks from players and generalize chat color in the MH lobby."; - public static AtomicBoolean toggled = new AtomicBoolean(false); - private static Boolean running = true; - - public static void check(String chat, CallbackInfo ci) { - // return false if toggled off - if (!toggled.get()) return; - - // return if not on minehut - if (!Poinpow.onMinehut) return; - - //ranked users joining - Pattern join = Pattern.compile("^(\\[(PRO|VIP|LEGEND|PATRON)] )[a-zA-Z0-9_.]{1,16} joined your lobby.$"); - if (join.matcher(chat).find()) { - Poinpow.log.info("Blocked: " + chat); - ci.cancel(); - return; - } - - //ranked users messaging - Pattern rankedMsg = Pattern.compile("^(\\[(PRO|VIP|LEGEND|PATRON)] )[a-zA-Z0-9_.]{1,16}: "); - if (rankedMsg.matcher(chat).find()) { - Poinpow.log.info("Original: " + chat); - ci.cancel(); - - //remove the rank prefix - if (chat.contains("]")) - chat = chat.substring(chat.indexOf("]") + 2); - - //send it to client - MinecraftClient.getInstance().inGameHud.getChatHud().addMessage(Text.literal(chat)); - return; - } - - //normal users chatting - Pattern normalMsg = Pattern.compile("^[a-zA-Z0-9_.]{1,16}: "); - if (normalMsg.matcher(chat).find() && running) { - ci.cancel(); - - running = false; - MinecraftClient.getInstance().inGameHud.getChatHud().addMessage(Text.literal(chat).styled(style -> style.withColor(Formatting.WHITE))); - running = true; - } - } -} diff --git a/src/main/resources/fabric.mod.json b/src/main/resources/fabric.mod.json index 05a3a6d..affa99c 100644 --- a/src/main/resources/fabric.mod.json +++ b/src/main/resources/fabric.mod.json @@ -29,7 +29,7 @@ "depends": { "fabricloader": ">=0.14.10", "fabric-api": "*", - "minecraft": "~1.19", + "minecraft": "~1.20", "java": ">=17" }, "suggests": {