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

Hide Scope Change Messages #107

Merged
merged 2 commits into from
Oct 5, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/main/java/dev/dfonline/codeclient/CodeClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,7 @@ private static void loadFeatures() {
feat(new ValueDetails());
feat(new ChatAutoEdit());
feat(new CPUDisplay());
feat(new MessageHiding());
}

/**
Expand Down
12 changes: 12 additions & 0 deletions src/main/java/dev/dfonline/codeclient/config/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ public class Config {
public boolean GiveUuidNameStrings = true;
public boolean CPUDisplay = true;
public CPUDisplayCorner CPUDisplayCornerOption = CPUDisplayCorner.TOP_LEFT;
public boolean HideScopeChangeMessages = true;

public Config() {
}
Expand Down Expand Up @@ -161,6 +162,7 @@ public void save() {
object.addProperty("GiveUuidNameStrings", GiveUuidNameStrings);
object.addProperty("CPUDisplay", CPUDisplay);
object.addProperty("CPUDisplayCorner", CPUDisplayCornerOption.name());
object.addProperty("HideScopeChangeMessages", HideScopeChangeMessages);
FileManager.writeConfig(object.toString());
} catch (Exception e) {
CodeClient.LOGGER.info("Couldn't save config: " + e);
Expand Down Expand Up @@ -670,6 +672,16 @@ public YetAnotherConfigLib getLibConfig() {
)
.controller(nodeOption -> () -> new EnumController<>(nodeOption, Config.CPUDisplayCorner.class))
.build())
.option(Option.createBuilder(Boolean.class)
.name(Text.translatable("codeclient.config.hide_scope_change_messages"))
.description(OptionDescription.of(Text.translatable("codeclient.config.hide_scope_change_messages.description")))
.binding(
true,
() -> HideScopeChangeMessages,
opt -> HideScopeChangeMessages = opt
)
.controller(TickBoxControllerBuilder::create)
.build())
//</editor-fold>
//<editor-fold desc="Action Viewer">
.group(OptionGroup.createBuilder()
Expand Down
28 changes: 28 additions & 0 deletions src/main/java/dev/dfonline/codeclient/dev/MessageHiding.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package dev.dfonline.codeclient.dev;

import dev.dfonline.codeclient.Feature;
import dev.dfonline.codeclient.config.Config;
import net.minecraft.network.packet.Packet;
import net.minecraft.network.packet.s2c.play.GameMessageS2CPacket;
import net.minecraft.text.Text;

import java.util.regex.Pattern;

public class MessageHiding extends Feature {

@Override
public boolean onReceivePacket(Packet<?> packet) {
if (packet instanceof GameMessageS2CPacket message) {
Text content = message.content();
String string = content.getString();

if (Config.getConfig().HideScopeChangeMessages) {
RedVortexDev marked this conversation as resolved.
Show resolved Hide resolved
Pattern pattern = Pattern.compile("^Scope set to (GAME|SAVE|LOCAL|LINE) \\((\\w ?)+\\)\\.$");
return pattern.matcher(string).matches();
}
}

return false;
}

}
2 changes: 2 additions & 0 deletions src/main/resources/assets/codeclient/lang/en_us.json
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,8 @@
"codeclient.config.cpu_display.description": "Whether to show the plot's CPU usage onscreen separate from the actionbar.",
"codeclient.config.cpu_display_corner.name": "On-Screen CPU Display Corner",
"codeclient.config.cpu_display_corner.description": "Which corner to place the on-screen CPU display.",
"codeclient.config.hide_scope_change_messages": "Hide Scope Change Messages",
"codeclient.config.hide_scope_change_messages.description": "Hides the message sent when changing a variable's scope.",
"codeclient.config.action_viewer": "Action Viewer",
"codeclient.config.action_viewer.description": "Display a tooltip that shows the code block's description.",
"codeclient.config.action_viewer.enable": "Enable Action Viewer",
Expand Down