-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add MuteLobbyChat and improve ToggleSpecificAds
- Loading branch information
Showing
10 changed files
with
167 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
83 changes: 83 additions & 0 deletions
83
src/main/java/com/udu3324/poinpow/utils/MuteLobbyChat.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
package com.udu3324.poinpow.utils; | ||
|
||
import com.mojang.brigadier.Command; | ||
import com.mojang.brigadier.CommandDispatcher; | ||
import com.udu3324.poinpow.Config; | ||
import com.udu3324.poinpow.api.Minehut; | ||
import com.udu3324.poinpow.commands.Commands; | ||
import net.fabricmc.fabric.api.client.command.v2.ClientCommandManager; | ||
import net.fabricmc.fabric.api.client.command.v2.FabricClientCommandSource; | ||
import net.minecraft.client.MinecraftClient; | ||
import net.minecraft.text.ClickEvent; | ||
import net.minecraft.text.Text; | ||
import net.minecraft.util.Formatting; | ||
|
||
public class MuteLobbyChat { | ||
public static String name = "muteLobbyChat"; | ||
public static String description = "This mutes the lobby chat if you don't want to see it."; | ||
|
||
public static boolean toggled = false; | ||
public static boolean canSendCheck = false; | ||
|
||
public static void registerCommand(CommandDispatcher<FabricClientCommandSource> dispatcher) { | ||
dispatcher.register(ClientCommandManager.literal(name).executes(ctx -> toggle(ctx.getSource()))); | ||
} | ||
|
||
private static int toggle(FabricClientCommandSource source) { | ||
Commands.running = true; | ||
|
||
//don't allow check as they already know | ||
canSendCheck = false; | ||
|
||
if (toggled) { | ||
source.sendFeedback(Text.literal("Lobby chat has been unmuted.").styled(style -> style | ||
.withColor(Formatting.RED))); | ||
|
||
toggled = false; | ||
} else { | ||
source.sendFeedback(Text.literal("Lobby chat has been muted.").styled(style -> style | ||
.withColor(Formatting.GREEN))); | ||
|
||
toggled = true; | ||
} | ||
|
||
Config.setValueFromConfig(name, String.valueOf(toggled)); | ||
|
||
Commands.running = false; | ||
return Command.SINGLE_SUCCESS; | ||
} | ||
|
||
public static boolean isAllowed(String chat) { | ||
if (MinecraftClient.getInstance().player == null || MinecraftClient.getInstance().player.getName().getLiteralString() == null) return false; | ||
|
||
//it is a /msg from someone | ||
if (chat.startsWith("To") || chat.startsWith("From")) { | ||
//it is a /msg from someone | ||
return true; | ||
} else if (!chat.contains(":")) { | ||
//misc message should be allowed | ||
return true; | ||
} else if (chat.toLowerCase().contains(MinecraftClient.getInstance().player.getName().getLiteralString().toLowerCase())) { | ||
//messages with the player's ign | ||
return true; | ||
} else { | ||
return false; | ||
} | ||
} | ||
|
||
//this is run when joining back into the lobby while it is muted. | ||
public static void check() { | ||
if (!canSendCheck) return; | ||
|
||
if (!toggled) return; | ||
|
||
Boolean inLobby = Minehut.inLobby(); | ||
if (inLobby != null && inLobby) { | ||
MinecraftClient.getInstance().inGameHud.getChatHud().addMessage(Text.literal("Lobby is currently muted by you. (click)").styled(style -> style | ||
.withClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/" + MuteLobbyChat.name)) | ||
.withColor(Formatting.DARK_GRAY))); | ||
} | ||
|
||
canSendCheck = false; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.