Skip to content

Commit

Permalink
Add /logexception for debugging
Browse files Browse the repository at this point in the history
  • Loading branch information
anastarawneh committed Jan 13, 2024
1 parent 27012ef commit de5c422
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
package me.anastarawneh.mccinametagmod;

import me.anastarawneh.mccinametagmod.command.LogExceptionCommand;
import me.anastarawneh.mccinametagmod.config.Config;
import me.anastarawneh.mccinametagmod.util.Game;
import me.shedaniel.autoconfig.AutoConfig;
import me.shedaniel.autoconfig.serializer.Toml4jConfigSerializer;
import net.fabricmc.api.ModInitializer;
import net.minecraft.client.MinecraftClient;
import net.minecraft.text.MutableText;
import net.minecraft.text.Text;
import net.minecraft.text.TextColor;
import net.minecraft.util.Formatting;
import org.apache.logging.log4j.LogManager;
Expand All @@ -14,6 +17,7 @@
public class MCCINametagMod implements ModInitializer {
public static final String MODID = "mccinametagmod";
public static final Logger LOGGER = LogManager.getLogger();
public static final MutableText MESSAGE_PREFIX = Text.literal(Formatting.GRAY + "[" + Formatting.GREEN + "MCCINametagMod" + Formatting.GRAY + "] " + Formatting.RESET);
public static String TEAM = "";
public static String RANK = "";
public static TextColor COLOR = TextColor.fromFormatting(Formatting.DARK_GRAY);
Expand All @@ -22,10 +26,14 @@ public class MCCINametagMod implements ModInitializer {
public static String STAGE = "";
public static String PHASE_TYPE = "";

public static Exception LATEST_EXCEPTION = null;

@Override
public void onInitialize() {
AutoConfig.register(Config.class, Toml4jConfigSerializer::new);
LOGGER.info("Hello there");

LogExceptionCommand.register();
}

public static Config getConfig() {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package me.anastarawneh.mccinametagmod.command;

import com.mojang.brigadier.context.CommandContext;
import me.anastarawneh.mccinametagmod.MCCINametagMod;
import net.fabricmc.fabric.api.client.command.v2.ClientCommandRegistrationCallback;
import net.fabricmc.fabric.api.client.command.v2.FabricClientCommandSource;

import static net.fabricmc.fabric.api.client.command.v2.ClientCommandManager.literal;

public class LogExceptionCommand {
public static void register() {
ClientCommandRegistrationCallback.EVENT.register((dispatcher, registryAccess) -> dispatcher.register(literal("logexception")
.executes(LogExceptionCommand::execute)));
}

static int execute(CommandContext<FabricClientCommandSource> context) {
if (MCCINametagMod.LATEST_EXCEPTION == null) {
context.getSource().sendFeedback(MCCINametagMod.MESSAGE_PREFIX.copy().append("Nothing to debug."));
return 1;
}
MCCINametagMod.LOGGER.error("Logging latest exception:");
MCCINametagMod.LOGGER.throwing(MCCINametagMod.LATEST_EXCEPTION);
context.getSource().sendFeedback(MCCINametagMod.MESSAGE_PREFIX.copy().append("Logged the latest exception."));
MCCINametagMod.LATEST_EXCEPTION = null;
return 1;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -484,6 +484,7 @@ else if (game == Game.DYNABALL) {
} catch (Exception ex) {
topLabel = Text.literal(playerName).setStyle(Style.EMPTY.withColor(Formatting.GRAY));
bottomLabel = Text.literal("Error.").setStyle(Style.EMPTY.withColor(Formatting.DARK_RED));
MCCINametagMod.LATEST_EXCEPTION = ex;
}

double d = this.dispatcher.getSquaredDistanceToCamera(entity);
Expand Down

0 comments on commit de5c422

Please sign in to comment.