Skip to content

Commit

Permalink
Block raid messages shown in lobby
Browse files Browse the repository at this point in the history
  • Loading branch information
udu3324 committed Jan 27, 2024
1 parent 76db76e commit 7cd8709
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/main/java/com/udu3324/poinpow/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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");
Expand Down
5 changes: 5 additions & 0 deletions src/main/java/com/udu3324/poinpow/commands/Commands.java
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,11 @@ public static void register(CommandDispatcher<FabricClientCommandSource> 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))))
);
}

Expand Down
31 changes: 31 additions & 0 deletions src/main/java/com/udu3324/poinpow/utils/BlockRaids.java
Original file line number Diff line number Diff line change
@@ -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();
}
}

0 comments on commit 7cd8709

Please sign in to comment.