Skip to content

Commit

Permalink
Merge pull request #33 from udu3324/master
Browse files Browse the repository at this point in the history
update
  • Loading branch information
udu3324 authored Jun 21, 2024
2 parents 92fe037 + 8ac2601 commit 1cc4832
Show file tree
Hide file tree
Showing 16 changed files with 360 additions and 56 deletions.
14 changes: 14 additions & 0 deletions .github/FUNDING.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# These are supported funding model platforms

github: # Replace with up to 4 GitHub Sponsors-enabled usernames e.g., [user1, user2]
patreon: # Replace with a single Patreon username
open_collective: # Replace with a single Open Collective username
ko_fi: udu3324
tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel
community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry
liberapay: # Replace with a single Liberapay username
issuehunt: # Replace with a single IssueHunt username
lfx_crowdfunding: # Replace with a single LFX Crowdfunding project-name e.g., cloud-foundry
polar: # Replace with a single Polar username
buy_me_a_coffee: # Replace with a single Buy Me a Coffee username
custom: # Replace with up to 4 custom sponsorship URLs e.g., ['link1', 'link2']
4 changes: 2 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
matrix:
# Use these Java versions
java: [
17, # Current Java LTS & minimum supported by Minecraft
21, # Current Java LTS & minimum supported by Minecraft
]
# and run on both Linux and Windows
os: [ubuntu-22.04, windows-2022]
Expand All @@ -33,7 +33,7 @@ jobs:
- name: build
run: ./gradlew build
- name: capture build artifacts
if: ${{ runner.os == 'Linux' && matrix.java == '17' }} # Only upload artifacts built from latest java on one OS
if: ${{ runner.os == 'Linux' && matrix.java == '21' }} # Only upload artifacts built from latest java on one OS
uses: actions/upload-artifact@v3
with:
name: Artifacts
Expand Down
62 changes: 33 additions & 29 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,40 +1,44 @@

![Mod Banner](https://github.com/udu3324/Poinpow/blob/master/src/main/resources/assets/poinpow/banner.png?raw=true)

![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://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)
![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://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)

# 📘 Features
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).

- **AutoSkipBarrier** - Automatically skip the ads when joining minehut or free servers.
- **HubCommandBack** - Adds back the hub command.
- **BlockMinehutAds** - Blocks ads from minehut that are sent in free servers `Example: [Minehut] boost your server speed!!!`
- **ChatPhraseFilter** - Filters and blocks messages in chat based on a regex list.
- **BlockLobbyAds** - Blocks player made ads in the lobby. `Example: [Ad] NintendoOS: /join fishwind join my server for op yes`
- **BlockFreeCredits** - Blocks the vote messages encouraging to vote for free credits.
- **BlockLobbyWelcome** - Blocks the lobby join message that sometimes has an ad in it.
- **BlockLobbyMapAds** - Removes the humungous map art that advertises things in lobby.
- **BlockRaids** - Blocks the raid messages in hub.
- **ToggleSpecificAds** - Extends BlockLobbyAds to toggle which ranks can advertise.
- **BlockChestAds** - Removes the ads inside the compass server listing in hub.
- **ServerLookup** - A command to see details about a minehut server. (by [BuggyAl](https://github.com/BuggyAl))

![](https://cdn.modrinth.com/data/zmUzIoT1/images/aaa8cda2723de8979014cde22db46d34c8160553.png)
Skipping ads **automatically** with AutoSkipBarrier **(extremely fast)**

![](https://cdn.modrinth.com/data/zmUzIoT1/images/c49843c5f4e7412df0c53670e94f3434eb4c4238.png)
Poinpow is a fabric mod that adds **amazing features** and **makes the player experience 103% better**. (QoL) Features that Minehut locks behind a paywall (ex: removing ads, muting chat, etc.) are in Poinpow.

| Features | Command |
|:------------------|:-------------------------------------------------------------------------------------------------------|
| AutoSkipBarrier | Automatically skips the transition ads when joining minehut/free servers. |
| BlockLobbyAds | Blocks player made ads in the lobby. |
| ToggleSpecificAds | Extends the functionality of BlockLobbyAds to block certain ads based on ranks. |
| ChatPhraseFilter | Filters and blocks messages in chat based on a regex list. |
| ServerLookup | A command to see details about a minehut server. Contributed by [BuggyAl](https://github.com/BuggyAl). |
| MuteLobbyChat | A command that mutes Minehut's lobby, only allowing `/msg`, joins, and some other stuff. |
| HubCommandBack | Adds back the `/hub` command. It redirects the command `/hub` to `/mh` when necessary. |
| BlockChestAds | Removes the ads inside the compass server listing in hub. |
| BlockLobbyMapAds | Removes the humungous map art that advertises things in lobby. |
| BlockLobbyWelcome | Blocks the lobby join message that sometimes has an ad in it. |
| BlockRaids | Blocks the raid messages in hub. |
| BlockFreeCredits | Blocks the vote messages encouraging to vote for free credits. |
| BlockMinehutAds | Blocks ads from Minehut that are sent in free servers. |


![screenshot of me using AutoSkipBarrier](https://cdn.modrinth.com/data/zmUzIoT1/images/aaa8cda2723de8979014cde22db46d34c8160553.png)
Skipping ads **automatically** with AutoSkipBarrier **(extremely fast)**
![screenshot of me using BlockLobbyAds and BlockLobbyMapAds](https://cdn.modrinth.com/data/zmUzIoT1/images/c49843c5f4e7412df0c53670e94f3434eb4c4238.png)
Example of **BlockLobbyAds** (blocks ads made by player) and **BlockLobbyMapAds**. It clears up chat a lot and blocks those awful map ads.

![](https://cdn.modrinth.com/data/zmUzIoT1/images/75745e7d81968d0ad369493ab3174f0d2a605517.png)
/poinpow - An **intractable/clickable** help command that easily allows the toggling of features.

## 💾 How to Install
![commands of poinpow](https://cdn.modrinth.com/data/zmUzIoT1/images/75745e7d81968d0ad369493ab3174f0d2a605517.png)
/poinpow - An **intractable/clickable** help command that easily allows the toggling of features. (image may be outdated)

## 💾 How to Install the Mod
1. Make sure you have **[Fabric](https://fabricmc.net/use/installer/)** installed in your mc launcher
2. Download the latest release of **Poinpow** [here](https://github.com/udu3324/poinpow/releases)
3. Download the latest release of **Fabric API** [here](https://modrinth.com/mod/fabric-api/versions)
Expand All @@ -50,7 +54,7 @@ If you want to **contribute to the code** or **make the jar yourself**, you can
3. Open a terminal and cd to the folder
4. Run `gradlew build` or `.\gradlew build` depending on your system os
5. Done! The jar should be in `/build/libs`
6. (optional) Open up the folder in your IDE (intellij recommended) to look at the code and contribute to it if you want :>
6. (optional) Open up the folder in your IDE (intellij recommended) to look at the code and contribute to it if you want to. Run `.\gradlew runClient` to run the mod directly in your IDE.

## 🧾 Is it Against the Rules?
**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
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ org.gradle.parallel=true
loader_version=0.15.11

# Mod Properties
mod_version = 1.7
mod_version = 1.7.1
maven_group = com.udu3324
archives_base_name = poinpow

Expand Down
3 changes: 3 additions & 0 deletions src/main/java/com/udu3324/poinpow/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,8 @@ public static void create() {
BlockRaids.toggled.set(Boolean.parseBoolean(getValueFromConfig(HubCommandBack.name)));
BlockChestAds.toggled.set(Boolean.parseBoolean(getValueFromConfig(BlockChestAds.name)));

MuteLobbyChat.toggled = Boolean.parseBoolean(getValueFromConfig(MuteLobbyChat.name));

defaultRank = Boolean.parseBoolean(getValueFromConfig(name + "_default"));
vip = Boolean.parseBoolean(getValueFromConfig(name + "_vip"));
vipPlus = Boolean.parseBoolean(getValueFromConfig(name + "_vipPlus"));
Expand Down Expand Up @@ -268,6 +270,7 @@ private static void writeDefaultConfig() throws IOException {
w.write(HubCommandBack.name + ": true" + System.lineSeparator());
w.write(BlockRaids.name + ": true" + System.lineSeparator());
w.write(BlockChestAds.name + ": true" + System.lineSeparator());
w.write(MuteLobbyChat.name + ": false" + System.lineSeparator());

w.write(name + "_default: false" + System.lineSeparator());
w.write(name + "_vip: false" + System.lineSeparator());
Expand Down
67 changes: 67 additions & 0 deletions src/main/java/com/udu3324/poinpow/api/Minecraft.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
package com.udu3324.poinpow.api;

import com.udu3324.poinpow.Poinpow;

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.HashMap;
import java.util.Map;

public class Minecraft {
public static Map<String, String> uuidOfPlayers = new HashMap<>();

//this gets a player's uuid from their ign
public static String getUUID(String ign) {
try {
//check if player's uuid has already been cached
if (uuidOfPlayers.containsKey(ign)) {
//Poinpow.log.info("ign {} cached with uuid {}", uuid, playerRank.get(ign));
return uuidOfPlayers.get(ign);
}

URL apiURL = new URL("https://api.mojang.com/users/profiles/minecraft/" + ign);
HttpURLConnection connection = (HttpURLConnection) apiURL.openConnection();
connection.setRequestMethod("GET");

if (connection.getResponseCode() != HttpURLConnection.HTTP_OK) {
Poinpow.log.error("Player ({}) not found! ({})", ign, connection.getResponseCode());
return null;
}

BufferedReader in = new BufferedReader(new InputStreamReader(connection.getInputStream()));
String inputLine;
StringBuilder response = new StringBuilder();
while ((inputLine = in.readLine()) != null) {
response.append(inputLine);
}

String json = response.toString().replaceAll(" ", "");

connection.disconnect();

//parse uuid
int start = json.indexOf("id\":\"") + 5;
int end = json.indexOf("\",\"", start);

json = json.substring(start, end);

uuidOfPlayers.put(ign, json);

return json;
} catch (Exception e) {
Poinpow.log.error("Response to minecraft api was unsuccessful. Player ign: {} - {}", ign, e);
return null;
}
}

public static String insertUUIDDashes(String uuid) {
StringBuilder sb = new StringBuilder(uuid);
sb.insert(8, "-");
sb.insert(13, "-");
sb.insert(18, "-");
sb.insert(23, "-");
return sb.toString();
}
}
69 changes: 68 additions & 1 deletion src/main/java/com/udu3324/poinpow/api/Minehut.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,52 @@
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import com.udu3324.poinpow.Poinpow;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.network.ClientPlayerEntity;
import net.minecraft.scoreboard.Scoreboard;
import net.minecraft.scoreboard.ScoreboardObjective;
import net.minecraft.text.Text;
import net.minecraft.util.Formatting;

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;

public class Minehut {
public static Map<String, String> playerRank = new HashMap<>();

public static Boolean inLobby() {
if (MinecraftClient.getInstance().player == null) return null;

// check for scoreboard
Scoreboard scoreboard = MinecraftClient.getInstance().player.getScoreboard();
ArrayList<String> scores = new ArrayList<>();
for (ScoreboardObjective objective : scoreboard.getObjectives()) {
scores.add(objective.getDisplayName().toString());
}

return scores.toString().toLowerCase().contains("minehut");
}

//(BuggyAl) this gets information about a server in json
public static JsonObject getServer(ClientPlayerEntity player, String serverName) {
try {
URL apiURL = new URL("https://api.minehut.com/server/" + serverName + "?byName=true");
HttpURLConnection connection = (HttpURLConnection) apiURL.openConnection();
connection.setRequestMethod("GET");

if (connection.getResponseCode() != HttpURLConnection.HTTP_OK) {
if (connection.getResponseCode() == 500) {
player.sendMessage(Text.literal("Server not found! (" + connection.getResponseCode() + ")").styled(style -> style
.withColor(Formatting.RED)));
return null;
} else if (connection.getResponseCode() != HttpURLConnection.HTTP_OK) { // bruh
player.sendMessage(Text.literal("Server not found! API may be down. (" + connection.getResponseCode() + ")").styled(style -> style
.withColor(Formatting.RED)));
return null;
}

JsonObject obj = JsonParser.parseReader(new InputStreamReader(connection.getInputStream())).getAsJsonObject().get("server").getAsJsonObject();
Expand All @@ -36,4 +62,45 @@ public static JsonObject getServer(ClientPlayerEntity player, String serverName)
return null;
}
}

//this gets a player's mh rank through their uuid, has to have dashes in
public static String getRank(String uuid) {
try {
//check if rank of player already has been cached
if (playerRank.containsKey(uuid)) {
//Poinpow.log.info("uuid {} cached with rank {}", uuid, playerRank.get(uuid));
return playerRank.get(uuid);
}

URL apiURL = new URL("https://api.minehut.com/cosmetics/profile/" + uuid);
HttpURLConnection connection = (HttpURLConnection) apiURL.openConnection();
connection.setRequestMethod("GET");

if (connection.getResponseCode() != HttpURLConnection.HTTP_OK) {
Poinpow.log.error("Player ({}) not found! ({})", uuid, connection.getResponseCode());
return null;
}

BufferedReader in = new BufferedReader(new InputStreamReader(connection.getInputStream()));

String json;
json = in.readLine();

in.close();

connection.disconnect();

//parse rank
int start = json.indexOf("rank\":\"") + 7;
int end = json.indexOf("\",\"", start);

String rank = json.substring(start, end);
playerRank.put(uuid, rank);

return rank;
} catch (Exception e) {
Poinpow.log.error("Response to minehut api was unsuccessful. Player uuid: {} {}", uuid, e);
return null;
}
}
}
8 changes: 8 additions & 0 deletions src/main/java/com/udu3324/poinpow/commands/Commands.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ public class Commands {
//register poinpow commands in the mc brigadier
public static void register(CommandDispatcher<FabricClientCommandSource> dispatcher) {
ServerLookup.registerCommand(dispatcher);
MuteLobbyChat.registerCommand(dispatcher);

dispatcher.register(literal("poinpow")
.executes(ctx -> help(ctx.getSource()))
Expand Down Expand Up @@ -193,6 +194,13 @@ private static int help(FabricClientCommandSource source) {
.withColor(Formatting.DARK_GRAY)
));

//toggle lobby chat
source.sendFeedback(Text.literal("[" + MuteLobbyChat.toggled + "] " + MuteLobbyChat.name).styled(style -> style
.withHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, Text.literal(MuteLobbyChat.description + "\n\nClick to Toggle")))
.withClickEvent(new ClickEvent(ClickEvent.Action.SUGGEST_COMMAND, "/" + MuteLobbyChat.name))
.withColor(Formatting.DARK_GRAY)
));

//chat phrase filter
source.sendFeedback(Text.literal("/poinpow " + ChatPhraseFilter.name + " <true/false/list/add/remove>").styled(style -> style
.withHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, Text.literal(ChatPhraseFilter.description + "\n\nClick to change")))
Expand Down
19 changes: 18 additions & 1 deletion src/main/java/com/udu3324/poinpow/mixin/ChatMixin.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package com.udu3324.poinpow.mixin;

import com.udu3324.poinpow.api.Minehut;
import com.udu3324.poinpow.commands.Commands;
import com.udu3324.poinpow.utils.*;
import net.minecraft.client.gui.DrawContext;
import net.minecraft.client.gui.hud.ChatHud;
import net.minecraft.client.gui.hud.MessageIndicator;
import net.minecraft.network.message.MessageSignatureData;
Expand All @@ -13,13 +15,23 @@

@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)
@Inject(method = "Lnet/minecraft/client/gui/hud/ChatHud;addMessage(Lnet/minecraft/text/Text;Lnet/minecraft/network/message/MessageSignatureData;Lnet/minecraft/client/gui/hud/MessageIndicator;)V", at = @At("HEAD"), cancellable = true)
private void onMessage(Text message, MessageSignatureData signature, MessageIndicator indicator, CallbackInfo ci) {
String chat = message.getString();

//don't allow blockers to run while help command is running
if (Commands.running) return;

//if lobby chat is toggled, don't run checks
if (MuteLobbyChat.toggled) {
// if they're in lobby & the message isn't allowed, cancel.
Boolean inLobby = Minehut.inLobby();
if (inLobby != null && inLobby && !MuteLobbyChat.isAllowed(chat)) {
ci.cancel();
return;
}
}

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

if (BlockLobbyAds.check(chat, ci)) return;
Expand All @@ -32,4 +44,9 @@ private void onMessage(Text message, MessageSignatureData signature, MessageIndi

ChatPhraseFilter.check(chat, ci);
}

@Inject(method = "Lnet/minecraft/client/gui/hud/ChatHud;render(Lnet/minecraft/client/gui/DrawContext;IIIZ)V", at = @At("RETURN"), cancellable = true)
private void onRender(DrawContext context, int currentTick, int mouseX, int mouseY, boolean focused, CallbackInfo ci) {
MuteLobbyChat.check();
}
}
Loading

0 comments on commit 1cc4832

Please sign in to comment.