Skip to content

Commit

Permalink
Use formatting for getactiondump
Browse files Browse the repository at this point in the history
  • Loading branch information
GeorgeRNG committed Jun 14, 2023
1 parent ba3ff4d commit 11bf663
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 10 deletions.
8 changes: 8 additions & 0 deletions src/main/java/dev/dfonline/codeclient/OverlayManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import net.minecraft.text.Text;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

/**
Expand All @@ -22,6 +23,13 @@ public static void setOverlayText() {
setOverlayText(new ArrayList<>());
}

/**
* Clears and sets the overlay text.
*/
public static void setOverlayText(Text overlayText) {
setOverlayText(new ArrayList<>(Collections.singleton(overlayText)));
}

/**
* Clears and sets the overlay text.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,14 @@ public void init() {
public boolean onReceivePacket(Packet<?> packet) {
if(capturedData == null || isDone) return false;
if(packet instanceof GameMessageS2CPacket message) {
if(message.content().getString().startsWith("Error:")) {
isDone = true;
OverlayManager.setOverlayText(Text.literal("Couldn't start. Check you are on beta.").formatted(Formatting.RED));
OverlayManager.addOverlayText(Text.literal("Or, beta isn't working right now.").formatted(Formatting.RED));
OverlayManager.addOverlayText(Text.literal("Type").append(Text.literal(" /abort ").formatted(Formatting.GREEN)).append(Text.literal("to hide this.")).formatted(Formatting.LIGHT_PURPLE));

return true;
}
TextColor lastColor = null;
for(Text text : message.content().getSiblings()) {
TextColor color = text.getStyle().getColor();
Expand All @@ -57,23 +65,23 @@ public boolean onReceivePacket(Packet<?> packet) {
lines += 1;
length += content.length();
OverlayManager.setOverlayText();
OverlayManager.addOverlayText(Text.literal("§6GetActionDump:"));
OverlayManager.addOverlayText(Text.literal("§bSize: §a" + length));
OverlayManager.addOverlayText(Text.literal("§bLines: §a" + lines));
OverlayManager.addOverlayText(Text.literal("§bTime: §a" + ((float) (new Date().getTime() - startTime.getTime()) / 1000)));
OverlayManager.addOverlayText(Text.literal("GetActionDump:").formatted(Formatting.GOLD));
OverlayManager.addOverlayText(Text.literal("Size: ").formatted(Formatting.LIGHT_PURPLE).append(Text.literal(String.valueOf(length)).formatted(Formatting.GREEN)));
OverlayManager.addOverlayText(Text.literal("Lines: ").formatted(Formatting.LIGHT_PURPLE).append(Text.literal(String.valueOf(lines)).formatted(Formatting.GREEN)));
OverlayManager.addOverlayText(Text.literal("Time: ").formatted(Formatting.LIGHT_PURPLE).append(Text.literal(String.valueOf((float) (new Date().getTime() - startTime.getTime()) / 1000))).formatted(Formatting.GREEN));
if(Objects.equals(content, "}")) {
isDone = true;
OverlayManager.addOverlayText(Text.literal(""));
OverlayManager.addOverlayText(Text.literal("§dComplete!"));
OverlayManager.addOverlayText(Text.literal("§dType §a/abort §dto hide this."));
OverlayManager.addOverlayText(Text.literal("Complete!").formatted(Formatting.LIGHT_PURPLE));
OverlayManager.addOverlayText(Text.literal("Type").append(Text.literal(" /abort ").formatted(Formatting.GREEN)).append(Text.literal("to hide this.")).formatted(Formatting.LIGHT_PURPLE));
OverlayManager.addOverlayText(Text.literal(""));
try {
FileManager.writeFile("actiondump.json",capturedData.toString());
OverlayManager.addOverlayText(Text.literal("§dThere will now be a file in your Minecraft directory."));
OverlayManager.addOverlayText(Text.literal("§a" + FileManager.Path() + "\\actiondump.json"));
OverlayManager.addOverlayText(Text.literal("There will now be a file in your Minecraft directory.").formatted(Formatting.LIGHT_PURPLE));
OverlayManager.addOverlayText(Text.literal(FileManager.Path().resolve("actiondump").toString()).formatted(Formatting.GREEN));
} catch (IOException e) {
OverlayManager.addOverlayText(Text.literal("§cAn error occurred whilst writing to a file,"));
OverlayManager.addOverlayText(Text.literal("§cso instead it has been written to your console."));
OverlayManager.addOverlayText(Text.literal("An error occurred whilst writing to a file,").formatted(Formatting.RED));
OverlayManager.addOverlayText(Text.literal("so instead it has been written to your console.").formatted(Formatting.RED));
}
callback();
}
Expand Down

0 comments on commit 11bf663

Please sign in to comment.