Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

merge new features & changes #14

Merged
merged 13 commits into from
Jul 29, 2023
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
10 changes: 5 additions & 5 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ org.gradle.parallel=true

# Fabric Properties
# check these on https://fabricmc.net/develop
minecraft_version=1.20
yarn_mappings=1.20+build.1
loader_version=0.14.21
minecraft_version=1.20.1
yarn_mappings=1.20.1+build.9
loader_version=0.14.21

# Mod Properties
mod_version = 1.3.0
mod_version = 1.3.1
maven_group = com.udu3324
archives_base_name = poinpow

# Dependencies
fabric_version=0.83.0+1.20
fabric_version=0.85.0+1.20.1
121 changes: 111 additions & 10 deletions src/main/java/com/udu3324/poinpow/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down Expand Up @@ -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<String> lines = new ArrayList<>();
ArrayList<String> 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++) {
Expand All @@ -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;
}
}
}
Expand All @@ -102,6 +100,106 @@ public static void setValueFromConfig(String value, String data) {
}
}

//
public static ArrayList<Pattern> getListOfRegex() {
try {
ArrayList<String> 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<Pattern> 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<String> 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<String> getConfig() {
try {
BufferedReader bufferedReader = new BufferedReader(new FileReader(configFile));
ArrayList<String> 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.");
Expand All @@ -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.");
Expand All @@ -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)));
Expand Down
29 changes: 17 additions & 12 deletions src/main/java/com/udu3324/poinpow/commands/Commands.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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 {
Expand All @@ -22,16 +24,19 @@ public static void register(CommandDispatcher<FabricClientCommandSource> 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)))
Expand Down Expand Up @@ -109,20 +114,20 @@ 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")))
.withClickEvent(new ClickEvent(ClickEvent.Action.SUGGEST_COMMAND, "/poinpow " + AutoSkipBarrier.name + " " + !AutoSkipBarrier.toggled.get()))
.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")))
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/com/udu3324/poinpow/mixin/ChatMixin.java
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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);
}
}
4 changes: 2 additions & 2 deletions src/main/java/com/udu3324/poinpow/utils/BlockFreeCredits.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@ 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;

// 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();
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/com/udu3324/poinpow/utils/BlockLobbyAds.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@ 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;

// 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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
20 changes: 18 additions & 2 deletions src/main/java/com/udu3324/poinpow/utils/BlockLobbyWelcome.java
Original file line number Diff line number Diff line change
@@ -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;

Expand All @@ -13,13 +17,27 @@ 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;

// 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<String> 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) {
Expand All @@ -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;
Expand Down
Loading