Skip to content

Commit

Permalink
Merge pull request #15 from udu3324/t
Browse files Browse the repository at this point in the history
merge features
  • Loading branch information
udu3324 authored Jul 29, 2023
2 parents 31f0800 + a4cba09 commit 7badf1f
Show file tree
Hide file tree
Showing 14 changed files with 308 additions and 103 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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 Expand Up @@ -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).
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).
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.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
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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
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
Loading

0 comments on commit 7badf1f

Please sign in to comment.