diff --git a/src/main/java/com/udu3324/poinpow/Config.java b/src/main/java/com/udu3324/poinpow/Config.java index 1af9556..4b6fa0c 100644 --- a/src/main/java/com/udu3324/poinpow/Config.java +++ b/src/main/java/com/udu3324/poinpow/Config.java @@ -224,6 +224,7 @@ public static void create() { BlockFreeCredits.toggled.set(Boolean.parseBoolean(getValueFromConfig(BlockFreeCredits.name))); BlockLobbyMapAds.toggled.set(Boolean.parseBoolean(getValueFromConfig(BlockLobbyMapAds.name))); HubCommandBack.toggled.set(Boolean.parseBoolean(getValueFromConfig(HubCommandBack.name))); + BlockRaids.toggled.set(Boolean.parseBoolean(getValueFromConfig(HubCommandBack.name))); } } } catch (IOException e) { @@ -245,6 +246,7 @@ private static void writeDefaultConfig() throws IOException { w.write(BlockFreeCredits.name + ": true" + System.lineSeparator()); w.write(BlockLobbyMapAds.name + ": true" + System.lineSeparator()); w.write(HubCommandBack.name + ": true" + System.lineSeparator()); + w.write(BlockRaids.name + ": true" + System.lineSeparator()); w.write(System.lineSeparator()); w.write("# Each line below is regex for ChatPhraseFilter to use." + System.lineSeparator()); w.write("/join"); diff --git a/src/main/java/com/udu3324/poinpow/commands/Commands.java b/src/main/java/com/udu3324/poinpow/commands/Commands.java index 67de93c..15a723d 100644 --- a/src/main/java/com/udu3324/poinpow/commands/Commands.java +++ b/src/main/java/com/udu3324/poinpow/commands/Commands.java @@ -68,6 +68,11 @@ public static void register(CommandDispatcher dispatc .executes(ctx -> description(ctx.getSource(), HubCommandBack.name, HubCommandBack.description, HubCommandBack.toggled)) .then(literal("true").executes(ctx -> toggle(ctx.getSource(), HubCommandBack.name, HubCommandBack.toggled, true))) .then(literal("false").executes(ctx -> toggle(ctx.getSource(), HubCommandBack.name, HubCommandBack.toggled, false)))) + + .then(literal(BlockRaids.name) + .executes(ctx -> description(ctx.getSource(), BlockRaids.name, BlockRaids.description, BlockRaids.toggled)) + .then(literal("true").executes(ctx -> toggle(ctx.getSource(), BlockRaids.name, BlockRaids.toggled, true))) + .then(literal("false").executes(ctx -> toggle(ctx.getSource(), BlockRaids.name, BlockRaids.toggled, false)))) ); } diff --git a/src/main/java/com/udu3324/poinpow/utils/BlockRaids.java b/src/main/java/com/udu3324/poinpow/utils/BlockRaids.java new file mode 100644 index 0000000..60f946f --- /dev/null +++ b/src/main/java/com/udu3324/poinpow/utils/BlockRaids.java @@ -0,0 +1,31 @@ +package com.udu3324.poinpow.utils; + +import com.udu3324.poinpow.Poinpow; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; + +import java.util.concurrent.atomic.AtomicBoolean; +import java.util.regex.Pattern; + +public class BlockRaids { + public static String name = "block_raids"; + public static String description = "Blocks the raid alerts shown in lobby."; + public static AtomicBoolean toggled = new AtomicBoolean(true); + + final static Pattern pattern = Pattern.compile("Minehut \\| Raid starts in [0-9]+ Seconds!"); + final static Pattern pattern2 = Pattern.compile("Minehut \\| A new raid is ready! Enter the green circle to begin\\."); + + public static Boolean check(String chat, CallbackInfo ci) { + // return false if toggled off + if (!toggled.get()) return false; + + // return if not on minehut + if (!Poinpow.onMinehut) return false; + + if (pattern.matcher(chat).find() || pattern2.matcher(chat).find()) { + Poinpow.log.info("Blocked: " + chat); + ci.cancel(); + } + + return pattern.matcher(chat).find(); + } +}