Skip to content

Commit

Permalink
Fix ToggleSpecificAds
Browse files Browse the repository at this point in the history
  • Loading branch information
udu3324 committed May 23, 2024
1 parent 2506bc9 commit 6b21a67
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 14 deletions.
2 changes: 2 additions & 0 deletions src/main/java/com/udu3324/poinpow/mixin/ActionbarMixin.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.udu3324.poinpow.mixin;

import com.udu3324.poinpow.utils.BlockMinehutAds;
import net.minecraft.client.gui.hud.InGameHud;
import net.minecraft.text.Text;
import org.spongepowered.asm.mixin.Mixin;
Expand All @@ -16,5 +17,6 @@ private void onActionBarSet(Text message, boolean tinted, CallbackInfo ci) {
if (text.equals("eee")) {
ci.cancel();
}
BlockMinehutAds.checkActionbar(text, ci);
}
}
19 changes: 19 additions & 0 deletions src/main/java/com/udu3324/poinpow/mixin/BossbarMixin.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package com.udu3324.poinpow.mixin;

import com.udu3324.poinpow.utils.BlockMinehutAds;
import net.minecraft.client.gui.DrawContext;
import net.minecraft.client.gui.hud.BossBarHud;
import net.minecraft.entity.boss.BossBar;
import net.minecraft.util.Identifier;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;

@Mixin(BossBarHud.class)
public class BossbarMixin {
@Inject(method = "renderBossBar", at = @At("HEAD"), cancellable = true)
public static void onBossbarRender(DrawContext context, int x, int y, BossBar bossBar, int width, Identifier[] textures, Identifier[] notchedTextures, CallbackInfo ci) {
BlockMinehutAds.checkBossbar(bossBar, ci);
}
}
2 changes: 1 addition & 1 deletion src/main/java/com/udu3324/poinpow/mixin/ChatMixin.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ private void onMessage(Text message, MessageSignatureData signature, MessageIndi

if (BlockFreeCredits.check(chat, ci)) return;

if (BlockMinehutAds.check(chat, ci)) return;
if (BlockMinehutAds.checkChat(chat, ci)) return;

if (BlockRaids.check(chat, ci)) return;

Expand Down
6 changes: 4 additions & 2 deletions src/main/java/com/udu3324/poinpow/utils/BlockLobbyAds.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,11 @@ public static Boolean check(String chat, CallbackInfo ci) {

//if it's not a suspected ad, return
if (!(pattern.matcher(chat).find() || chat.contains(": /join"))) return false;

System.out.println("suspect " + pattern.matcher(chat).find() + " " + chat.contains(": /join"));
//since it's an ad, check the rank if its allowed
if (!ToggleSpecificAds.checkRank(chat)) return false;
boolean yeah = ToggleSpecificAds.checkRank(chat);
System.out.println("yeah = " + yeah);
if (yeah) return false;

System.out.println("Blocked: " + chat);
ci.cancel();
Expand Down
19 changes: 17 additions & 2 deletions src/main/java/com/udu3324/poinpow/utils/BlockMinehutAds.java
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
package com.udu3324.poinpow.utils;

import com.udu3324.poinpow.Poinpow;
import net.minecraft.entity.boss.BossBar;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;

import java.util.concurrent.atomic.AtomicBoolean;
import java.util.regex.Pattern;

public class BlockMinehutAds {
public static String name = "block_minehut_ads";
public static String description = "Blocks ads made by minehut that sometimes shows up in free sub-servers.";
public static String description = "Blocks ads made by minehut that sometimes shows up in free sub-servers, and clean the bossbar and actionbar.";
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) {
public static Boolean checkChat(String chat, CallbackInfo ci) {
// return false if toggled off
if (!toggled.get()) return false;

Expand All @@ -27,4 +28,18 @@ public static Boolean check(String chat, CallbackInfo ci) {

return pattern.matcher(chat).find();
}

public static void checkActionbar(String actionbar, CallbackInfo ci) {
//text when hovering over map ads in lobby
if (actionbar.contains("[Billboard]")) {
ci.cancel();
}
}

public static void checkBossbar(BossBar bossbar, CallbackInfo ci) {
//text when hovering over map ads in lobby
if (bossbar.getName().getString().contains("[Billboard]")) {
ci.cancel();
}
}
}
22 changes: 13 additions & 9 deletions src/main/java/com/udu3324/poinpow/utils/ToggleSpecificAds.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import com.udu3324.poinpow.commands.Commands;
import net.fabricmc.fabric.api.client.command.v2.FabricClientCommandSource;
import com.mojang.brigadier.Command;
import net.minecraft.text.ClickEvent;
import net.minecraft.text.Text;
import net.minecraft.util.Formatting;

Expand All @@ -18,25 +19,26 @@ public class ToggleSpecificAds {
public static boolean legend = false;
public static boolean patron = false;

//return true if a rank that is toggled is matched
public static boolean checkRank(String chat) {
String rank = chat.substring(0, chat.indexOf(":"));

//return true if none are activated
if (!(defaultRank || vip || vipPlus || pro || legend || patron))
return true;

return false;
System.out.println("rank is " + rank);
//check for if the rank portion contains it
if (rank.contains("[VIP]") && vip) {
return false;
return true;
} else if (rank.contains("[VIP+]") && vipPlus) {
return false;
return true;
} else if (rank.contains("[PRO]") && pro) {
return false;
return true;
} else if (rank.contains("[LEGEND]") && legend) {
return false;
return true;
} else if (rank.contains("[PATRON]") && patron) {
return false;
} else return !defaultRank;
return true;
} else return defaultRank;
}

public static int toggle(FabricClientCommandSource source, String rank) {
Expand Down Expand Up @@ -87,7 +89,9 @@ public static int description(FabricClientCommandSource source) {

//show the command's description
source.sendFeedback(Text.literal(description));
source.sendFeedback(Text.literal("Default: " + defaultRank + "\nVIP: " + vip + "\nVIP+: " + vipPlus + "\nPro: " + pro + "\nLegend: " + legend + "\nPatron: " + patron).styled(style -> style.withColor(Formatting.GRAY)));
source.sendFeedback(Text.literal("Default: " + defaultRank + "\nVIP: " + vip + "\nVIP+: " + vipPlus + "\nPro: " + pro + "\nLegend: " + legend + "\nPatron: " + patron).styled(style -> style
.withColor(Formatting.GRAY)
.withClickEvent(new ClickEvent(ClickEvent.Action.SUGGEST_COMMAND, "/poinpow " + ToggleSpecificAds.name + " "))));

Commands.running = false;
return Command.SINGLE_SUCCESS;
Expand Down

0 comments on commit 6b21a67

Please sign in to comment.