Skip to content

Commit

Permalink
Merge pull request #25 from udu3324/master
Browse files Browse the repository at this point in the history
Add HubCommandBack
  • Loading branch information
udu3324 authored Dec 29, 2023
2 parents 28f1f4e + 76db76e commit 3a9b4b2
Show file tree
Hide file tree
Showing 7 changed files with 90 additions and 5 deletions.
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
# 📘 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).

- **HubCommandBack** - Adds back the hub (instead of /mh) command in servers that don't have it
- **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`
Expand All @@ -25,13 +26,13 @@ Skipping ads **automatically** with AutoSkipBarrier **(very fast)**

![](https://cdn.modrinth.com/data/zmUzIoT1/images/aaa8cda2723de8979014cde22db46d34c8160553.png)

Example of **Block Lobby Ads** (blocks /ad commands by player) and BlockLobbyMapAds. It clears up chat a lot and blocks those awful map ads.
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/c49843c5f4e7412df0c53670e94f3434eb4c4238.png)

/poinpow - **intractable/clickable** help command
/poinpow - An **intractable/clickable** help command that easily allows the toggling of certain features.

![](https://cdn.modrinth.com/data/zmUzIoT1/images/619e7e67d0165ede30130a569f68d224d7d6e445.png)
![](https://cdn.modrinth.com/data/zmUzIoT1/images/257cc486abee7e7f68aca9fb0c6d5fc2d8979cd5.png)

## 💾 How to Install
0. Make sure you have **[Fabric](https://fabricmc.net/use/installer/)** installed in your mc launcher
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.3

# Mod Properties
mod_version = 1.6.0
mod_version = 1.6.1
maven_group = com.udu3324
archives_base_name = poinpow

Expand Down
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 @@ -223,6 +223,7 @@ public static void create() {
BlockMinehutAds.toggled.set(Boolean.parseBoolean(getValueFromConfig(BlockMinehutAds.name)));
BlockFreeCredits.toggled.set(Boolean.parseBoolean(getValueFromConfig(BlockFreeCredits.name)));
BlockLobbyMapAds.toggled.set(Boolean.parseBoolean(getValueFromConfig(BlockLobbyMapAds.name)));
HubCommandBack.toggled.set(Boolean.parseBoolean(getValueFromConfig(HubCommandBack.name)));
}
}
} catch (IOException e) {
Expand All @@ -243,6 +244,7 @@ private static void writeDefaultConfig() throws IOException {
w.write(BlockMinehutAds.name + ": true" + System.lineSeparator());
w.write(BlockFreeCredits.name + ": true" + System.lineSeparator());
w.write(BlockLobbyMapAds.name + ": true" + System.lineSeparator());
w.write(HubCommandBack.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
12 changes: 12 additions & 0 deletions src/main/java/com/udu3324/poinpow/commands/Commands.java
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,11 @@ public static void register(CommandDispatcher<FabricClientCommandSource> dispatc
.executes(ctx -> description(ctx.getSource(), BlockLobbyMapAds.name, BlockLobbyMapAds.description, BlockLobbyMapAds.toggled))
.then(literal("true").executes(ctx -> toggle(ctx.getSource(), BlockLobbyMapAds.name, BlockLobbyMapAds.toggled, true)))
.then(literal("false").executes(ctx -> toggle(ctx.getSource(), BlockLobbyMapAds.name, BlockLobbyMapAds.toggled, false))))

.then(literal(HubCommandBack.name)
.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))))
);
}

Expand Down Expand Up @@ -165,6 +170,13 @@ private static int help(FabricClientCommandSource source) {
.withColor(Formatting.DARK_GRAY)
));

//hub command back
source.sendFeedback(Text.literal("[toggled|" + HubCommandBack.toggled + "] " + HubCommandBack.name).styled(style -> style
.withHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, Text.literal(HubCommandBack.description + "\n\nClick to Toggle")))
.withClickEvent(new ClickEvent(ClickEvent.Action.SUGGEST_COMMAND, "/poinpow " + HubCommandBack.name + " " + !HubCommandBack.toggled.get()))
.withColor(Formatting.DARK_GRAY)
));

//lookup server
source.sendFeedback(Text.literal("/" + ServerLookup.name + " <serverName>").styled(style -> style
.withHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, Text.literal(ServerLookup.description + "\n\nClick to lookup a server!")))
Expand Down
17 changes: 17 additions & 0 deletions src/main/java/com/udu3324/poinpow/mixin/ClientChatMixin.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.udu3324.poinpow.mixin;

import com.udu3324.poinpow.utils.HubCommandBack;
import net.minecraft.client.gui.screen.ChatScreen;
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.CallbackInfoReturnable;

@Mixin(ChatScreen.class)
public class ClientChatMixin {
@Inject(method = "sendMessage", at = @At("HEAD"), cancellable = true)

private void onSendMessage(String message, boolean addToHistory, CallbackInfoReturnable<Boolean> cir) {
HubCommandBack.scan(message, cir);
}
}
52 changes: 52 additions & 0 deletions src/main/java/com/udu3324/poinpow/utils/HubCommandBack.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package com.udu3324.poinpow.utils;

import com.mojang.brigadier.CommandDispatcher;
import com.mojang.brigadier.tree.CommandNode;
import com.udu3324.poinpow.Poinpow;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.network.ClientPlayNetworkHandler;
import net.minecraft.client.network.ClientPlayerEntity;
import net.minecraft.command.CommandSource;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;

import java.util.concurrent.atomic.AtomicBoolean;

public class HubCommandBack {
public static final String name = "hubCommandBack";
public static final String description = "Adds back the /hub command in sub-servers that don't have a hub.";

public static AtomicBoolean toggled = new AtomicBoolean(true);

public static void scan(String msg, CallbackInfoReturnable<Boolean> cir) {
// return if toggled off (no need for bool)
if (!toggled.get()) return;

// return if not on mh
if (!Poinpow.onMinehut) return;

// return if the message isn't the command
if (!msg.contains("/hub")) return;

// return if the sub-server already has /hub registered as a command
ClientPlayNetworkHandler clientPlayNetworkHandler = MinecraftClient.getInstance().getNetworkHandler();
if (clientPlayNetworkHandler == null) return;

CommandDispatcher<CommandSource> dispatcher = clientPlayNetworkHandler.getCommandDispatcher();
if (isCommandRegistered(dispatcher, "hub")) return;

// Prevent original message from sending
cir.setReturnValue(true);

ClientPlayerEntity player = MinecraftClient.getInstance().player;
if (player == null) return;

player.networkHandler.sendChatCommand("mh");
}

public static boolean isCommandRegistered(CommandDispatcher<CommandSource> dispatcher, String commandName) {
CommandNode<CommandSource> rootCommand = dispatcher.getRoot();

// Check if the command is present in the command tree
return rootCommand.getChild(commandName) != null;
}
}
3 changes: 2 additions & 1 deletion src/main/resources/poinpow.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
"MapartMixin"
],
"client": [
"ChatMixin"
"ChatMixin",
"ClientChatMixin"
],
"injectors": {
"defaultRequire": 1
Expand Down

0 comments on commit 3a9b4b2

Please sign in to comment.