diff --git a/src/main/java/xyz/omegaware/addon/OmegawareAddons.java b/src/main/java/xyz/omegaware/addon/OmegawareAddons.java index 97443c9..1eecd05 100644 --- a/src/main/java/xyz/omegaware/addon/OmegawareAddons.java +++ b/src/main/java/xyz/omegaware/addon/OmegawareAddons.java @@ -7,10 +7,6 @@ import meteordevelopment.meteorclient.utils.Utils; import net.fabricmc.loader.api.FabricLoader; import net.fabricmc.loader.api.metadata.ModMetadata; -import net.minecraft.client.MinecraftClient; -import net.minecraft.client.network.ServerInfo; -import net.minecraft.text.Text; -import net.minecraft.util.Formatting; import xyz.omegaware.addon.commands.LinkCommand; import xyz.omegaware.addon.commands.ShulkerQueueCommand; import xyz.omegaware.addon.hud.OnlineTSRMembersHUD; @@ -30,37 +26,12 @@ public class OmegawareAddons extends MeteorAddon { public static ModMetadata MOD_META; public static final Logger LOG = LogUtils.getLogger(); public static final Category CATEGORY = new Category("OmegaWare"); - @SuppressWarnings("unused") public static final HudGroup HUD_GROUP = new HudGroup("OmegaWare"); public static File GetConfigFile(String key, String filename) { return new File(new File(new File(new File(MeteorClient.FOLDER, "omegaware"), key), Utils.getFileWorldName()), filename); } - public static String getCurrentServerAddress() { - ServerInfo server = MinecraftClient.getInstance().getCurrentServerEntry(); - if (server == null) { - return "singleplayer"; - } - - if (server.address == null || server.address.isEmpty()) { - return "unknown"; - } - - return MinecraftClient.getInstance().getCurrentServerEntry().address; - } - - @SuppressWarnings("BooleanMethodIsAlwaysInverted") - public static boolean is6B6T() { - String serverAddress = getCurrentServerAddress(); - return serverAddress.contains("6b6t.org"); - } - - public static final Text PREFIX = Text.empty() - .append(Text.literal("[").formatted(Formatting.WHITE)) - .append(Text.literal("OmegaWare").formatted(Formatting.AQUA)) - .append(Text.literal("] ").formatted(Formatting.WHITE)); - @Override public void onInitialize() { LOG.info("Initializing OmegaWare Addons"); @@ -71,10 +42,13 @@ public void onInitialize() { Modules.get().add(new TPAAutomationModule()); Modules.get().add(new BeaconRangeModule()); Modules.get().add(new ChatFilterModule()); - //Modules.get().add(new TSRKitBotModule()); // Commented out because it is not ready yet Modules.get().add(new ItemFrameDupeModule()); Modules.get().add(new BetterStashFinderModule()); + if (FabricLoader.getInstance().isDevelopmentEnvironment()) { + Modules.get().add(new TSRKitBotModule()); // Is not ready yet + } + if (BaritoneUtils.IS_AVAILABLE) { Modules.get().add(new BetterBaritoneBuild()); } diff --git a/src/main/java/xyz/omegaware/addon/commands/LinkCommand.java b/src/main/java/xyz/omegaware/addon/commands/LinkCommand.java index aef7533..859e581 100644 --- a/src/main/java/xyz/omegaware/addon/commands/LinkCommand.java +++ b/src/main/java/xyz/omegaware/addon/commands/LinkCommand.java @@ -1,6 +1,5 @@ package xyz.omegaware.addon.commands; - import com.mojang.brigadier.arguments.StringArgumentType; import com.mojang.brigadier.builder.LiteralArgumentBuilder; import meteordevelopment.meteorclient.commands.Command; diff --git a/src/main/java/xyz/omegaware/addon/commands/ShulkerQueueCommand.java b/src/main/java/xyz/omegaware/addon/commands/ShulkerQueueCommand.java index 5260440..97feb78 100644 --- a/src/main/java/xyz/omegaware/addon/commands/ShulkerQueueCommand.java +++ b/src/main/java/xyz/omegaware/addon/commands/ShulkerQueueCommand.java @@ -2,13 +2,11 @@ import com.mojang.brigadier.builder.LiteralArgumentBuilder; import meteordevelopment.meteorclient.commands.Command; -import meteordevelopment.meteorclient.utils.player.ChatUtils; import net.minecraft.command.CommandSource; import net.minecraft.item.ItemStack; -import net.minecraft.text.Text; import net.minecraft.util.Formatting; -import xyz.omegaware.addon.OmegawareAddons; import xyz.omegaware.addon.modules.ItemFrameDupeModule; +import xyz.omegaware.addon.utils.Logger; public class ShulkerQueueCommand extends Command { public ShulkerQueueCommand() { @@ -19,96 +17,56 @@ public ShulkerQueueCommand() { public void build(LiteralArgumentBuilder builder) { builder.then(literal("add").executes(context -> { if (mc.player == null) { - Text msg = OmegawareAddons.PREFIX.copy() - .append(Text.literal("Error: ").formatted(Formatting.RED)) - .append(Text.literal("Player was somehow null").formatted(Formatting.WHITE)); - ChatUtils.sendMsg(msg); - + Logger.error("Player was somehow null"); return SINGLE_SUCCESS; } ItemStack stack = mc.player.getMainHandStack(); if (stack.isEmpty()) { - Text msg = OmegawareAddons.PREFIX.copy() - .append(Text.literal("Error: ").formatted(Formatting.RED)) - .append(Text.literal("You must hold an item in your main hand").formatted(Formatting.WHITE)); - ChatUtils.sendMsg(msg); - + Logger.error("You must hold an item in your main hand"); return SINGLE_SUCCESS; } ItemFrameDupeModule.shulkerQueue.add(stack.copy()); - Text msg = OmegawareAddons.PREFIX.copy() - .append(Text.literal("Added ").formatted(Formatting.GREEN)) - .append(stack.toHoverableText()) - .append(Text.literal(" to the shulker queue").formatted(Formatting.WHITE)); - ChatUtils.sendMsg(msg); + Logger.info("%sAdded %s to the shulker queue", Formatting.GREEN, stack.toHoverableText()); return SINGLE_SUCCESS; })); builder.then(literal("remove").executes(context -> { if (mc.player == null) { - Text msg = OmegawareAddons.PREFIX.copy() - .append(Text.literal("Error: ").formatted(Formatting.RED)) - .append(Text.literal("Player was somehow null").formatted(Formatting.WHITE)); - ChatUtils.sendMsg(msg); - + Logger.error("Player was somehow null"); return SINGLE_SUCCESS; } ItemStack stack = mc.player.getMainHandStack(); if (stack.isEmpty()) { - Text msg = OmegawareAddons.PREFIX.copy() - .append(Text.literal("Error: ").formatted(Formatting.RED)) - .append(Text.literal("You must hold an item in your main hand").formatted(Formatting.WHITE)); - ChatUtils.sendMsg(msg); - + Logger.error("You must hold an item in your main hand"); return SINGLE_SUCCESS; } if (!ItemFrameDupeModule.shulkerQueue.contains(stack.copy())) { - Text msg = OmegawareAddons.PREFIX.copy() - .append(Text.literal("Error: ").formatted(Formatting.RED)) - .append(Text.literal("Item is not in the shulker queue").formatted(Formatting.WHITE)); - ChatUtils.sendMsg(msg); - + Logger.error("Item is not in the shulker queue"); return SINGLE_SUCCESS; } ItemFrameDupeModule.shulkerQueue.remove(stack.copy()); - Text msg = OmegawareAddons.PREFIX.copy() - .append(Text.literal("Removed ").formatted(Formatting.RED)) - .append(stack.toHoverableText()) - .append(Text.literal(" from the shulker queue").formatted(Formatting.WHITE)); - ChatUtils.sendMsg(msg); - + Logger.info("%sRemoved%s %s from the shulker queue", Formatting.RED, Formatting.WHITE ,stack.toHoverableText()); return SINGLE_SUCCESS; })); builder.then(literal("list").executes(context -> { if (mc.player == null) { - Text msg = OmegawareAddons.PREFIX.copy() - .append(Text.literal("Error: ").formatted(Formatting.RED)) - .append(Text.literal("Player was somehow null").formatted(Formatting.WHITE)); - ChatUtils.sendMsg(msg); - + Logger.error("Player was somehow null"); return SINGLE_SUCCESS; } if (ItemFrameDupeModule.shulkerQueue.isEmpty()) { - Text msg = OmegawareAddons.PREFIX.copy() - .append(Text.literal("Shulker queue is empty").formatted(Formatting.WHITE)); - ChatUtils.sendMsg(msg); + Logger.info("Shulker queue is empty"); } else { - Text msg = OmegawareAddons.PREFIX.copy() - .append(Text.literal("Shulker queue: ").formatted(Formatting.YELLOW)); - ChatUtils.sendMsg(msg); - - ItemFrameDupeModule.shulkerQueue.forEach(itemStack -> { - Text itemText = itemStack.toHoverableText(); - ChatUtils.sendMsg(itemText); - }); + StringBuilder sb = new StringBuilder("Shulker queue: "); + ItemFrameDupeModule.shulkerQueue.forEach(itemStack -> sb.append(itemStack.toHoverableText().getString()).append("\n")); + Logger.info(sb.toString()); } return SINGLE_SUCCESS; @@ -116,19 +74,14 @@ public void build(LiteralArgumentBuilder builder) { builder.then(literal("clear").executes(context -> { if (mc.player == null) { - Text msg = OmegawareAddons.PREFIX.copy() - .append(Text.literal("Error: ").formatted(Formatting.RED)) - .append(Text.literal("Player was somehow null").formatted(Formatting.WHITE)); - ChatUtils.sendMsg(msg); + Logger.error("Player was somehow null"); return SINGLE_SUCCESS; } ItemFrameDupeModule.shulkerQueue.clear(); - Text msg = OmegawareAddons.PREFIX.copy() - .append(Text.literal("Cleared the shulker queue").formatted(Formatting.WHITE)); - ChatUtils.sendMsg(msg); + Logger.info("Cleared the shulker queue"); return SINGLE_SUCCESS; })); diff --git a/src/main/java/xyz/omegaware/addon/modules/BetterBaritoneBuild.java b/src/main/java/xyz/omegaware/addon/modules/BetterBaritoneBuild.java index 8b8411d..bc336fa 100644 --- a/src/main/java/xyz/omegaware/addon/modules/BetterBaritoneBuild.java +++ b/src/main/java/xyz/omegaware/addon/modules/BetterBaritoneBuild.java @@ -26,7 +26,6 @@ import meteordevelopment.meteorclient.systems.modules.misc.AutoReconnect; import meteordevelopment.meteorclient.utils.Utils; import meteordevelopment.meteorclient.utils.network.MeteorExecutor; -import meteordevelopment.meteorclient.utils.player.ChatUtils; import meteordevelopment.meteorclient.utils.player.InvUtils; import meteordevelopment.meteorclient.utils.player.SlotUtils; import meteordevelopment.meteorclient.utils.render.color.SettingColor; @@ -46,6 +45,7 @@ import net.minecraft.util.math.Direction; import net.minecraft.util.math.Vec3d; import xyz.omegaware.addon.OmegawareAddons; +import xyz.omegaware.addon.utils.Logger; import java.io.File; import java.io.FileWriter; @@ -56,7 +56,7 @@ public class BetterBaritoneBuild extends Module { public BetterBaritoneBuild() { - super(OmegawareAddons.CATEGORY, "Better Baritone Build", "Enable this module to enhance Baritone's building capabilities with linked storage and item fetching features."); + super(OmegawareAddons.CATEGORY, "better-baritone-build", "Enable this module to enhance Baritone's building capabilities with linked storage and item fetching features."); } private static final Gson GSON = new GsonBuilder().setPrettyPrinting().create(); @@ -211,10 +211,8 @@ public StorageItem(Item item, Integer stacks, LinkedStorage linkedStorage) { @Override public void onActivate() { if (!BaritoneUtils.IS_AVAILABLE) { - ChatUtils.sendMsg(OmegawareAddons.PREFIX.copy() - .append(Text.literal("Error: ").formatted(Formatting.RED)) - .append(Text.literal("Baritone is not available!").formatted(Formatting.WHITE))); - this.toggle(); + Logger.error("Baritone is not available!"); + toggle(); return; } @@ -265,12 +263,10 @@ public WWidget getWidget(GuiTheme theme) { WButton printBtn = theme.button("Print Linked Storages"); printBtn.action = () -> { - MutableText msg = OmegawareAddons.PREFIX.copy() - .append(Text.literal("Linked Storages: ").formatted(Formatting.GREEN)); + StringBuilder sb = new StringBuilder(); + linkedStorages.forEach(linkedStorage -> sb.append(String.format("X=%s, Y=%s, Z=%s\n", linkedStorage.blockPos.getX(), linkedStorage.blockPos.getY(), linkedStorage.blockPos.getZ()))); - linkedStorages.forEach(linkedStorage -> msg.append(Text.literal(String.format("X=%s, Y=%s, Z=%s\n", linkedStorage.blockPos.getX(), linkedStorage.blockPos.getY(), linkedStorage.blockPos.getZ())).formatted(Formatting.WHITE))); - - ChatUtils.sendMsg(msg); + Logger.info("Linked Storages:\n%s", sb.toString()); }; hList.add(printBtn); @@ -278,7 +274,7 @@ public WWidget getWidget(GuiTheme theme) { clearBtn.action = () -> { linkedStorages.clear(); saveLinkedStorages(); - ChatUtils.sendMsg(OmegawareAddons.PREFIX.copy().append(Text.literal("Linked Storages cleared!").formatted(Formatting.GREEN))); + Logger.info("Linked Storages cleared!"); }; hList.add(clearBtn); @@ -292,9 +288,7 @@ public WWidget getWidget(GuiTheme theme) { saveHome(); - ChatUtils.sendMsg(OmegawareAddons.PREFIX.copy() - .append(Text.literal("Home point set to: ").formatted(Formatting.GREEN)) - .append(Text.literal(String.format("X=%s, Y=%s, Z=%s", home.getX(), home.getY(), home.getZ())).formatted(Formatting.WHITE))); + Logger.info("%sHome point set to:%s X=%s, Y=%s, Z=%s", Formatting.GREEN, Formatting.WHITE, home.getX(), home.getY(), home.getZ()); }; hList.add(setHomeBtn); @@ -323,8 +317,7 @@ private void onTickPost(TickEvent.Post event) { if (!isActive() || mc.world == null || mc.player == null || !homeIfStuck.get()) return; if (mc.player.getBlockPos().equals(home)) { if (debugMode.get()) { - ChatUtils.sendMsg(OmegawareAddons.PREFIX.copy() - .append(Text.literal("Player is at home point.").formatted(Formatting.GREEN))); + Logger.info("%sPlayer is at home point.", Formatting.GREEN); } ticksStuck = 0; // Reset the stuck counter if the player is at home lastBlockPos = null; // Reset the last block position @@ -333,8 +326,7 @@ private void onTickPost(TickEvent.Post event) { if (home == null) { // Yell at the player to set a home point - ChatUtils.sendMsg(OmegawareAddons.PREFIX.copy() - .append(Text.literal("Please set a home point using the \"Set Home\" button!").formatted(Formatting.RED))); + Logger.error("Please set a home point using the \"Set Home\" button!"); homeIfStuck.set(false); // Disable the setting if no home point is set return; } @@ -355,18 +347,13 @@ private void onTickPost(TickEvent.Post event) { } if (debugMode.get()) { - ChatUtils.sendMsg(OmegawareAddons.PREFIX.copy() - .append(Text.literal("Baritone is stuck, ticks: ").formatted(Formatting.RED)) - .append(Text.literal(String.valueOf(ticksStuck)).formatted(Formatting.WHITE))); - - ChatUtils.sendMsg(OmegawareAddons.PREFIX.copy() - .append(Text.literal(String.format("Should return home: %s", ticksStuck >= homeIfStuckTimeout.get() * 20))).formatted(Formatting.GREEN)); + Logger.warn("Baritone is stuck, ticks: %d", ticksStuck); + Logger.info("Should return home: %b", ticksStuck >= homeIfStuckTimeout.get() * 20); } // 1 second = 20 ticks if (ticksStuck >= homeIfStuckTimeout.get() * 20) { - ChatUtils.sendMsg(OmegawareAddons.PREFIX.copy() - .append(Text.literal("Baritone is stuck, returning to home point...").formatted(Formatting.RED))); + Logger.error("Baritone is stuck, returning to home point..."); ticksStuck = 0; // Reset the stuck counter lastBlockPos = mc.player.getBlockPos(); // Update the last block position @@ -415,28 +402,20 @@ private void onMessageReceive(ReceiveMessageEvent event) { Item item = Registries.ITEM.get(identifier).asItem(); if (item == null) { - if (debugMode.get()) { - ChatUtils.sendMsg(OmegawareAddons.PREFIX.copy() - .append(Text.literal("Item not found: ").formatted(Formatting.RED)) - .append(Text.literal(blockName).formatted(Formatting.WHITE))); - } + if (debugMode.get()) Logger.error("Item not found: %s%s", Formatting.WHITE, blockName); return; } if (itemsToFetch.stream().anyMatch(storageItem -> storageItem.item.equals(item))) { if (debugMode.get()) { - ChatUtils.sendMsg(OmegawareAddons.PREFIX.copy() - .append(Text.literal("Item already in queue: ").formatted(Formatting.YELLOW)) - .append(Text.literal(item.getName().getString()).formatted(Formatting.WHITE))); + Logger.warn("Item already in queue: %s%s", Formatting.WHITE, item.getName().getString()); } return; } LinkedStorage linkedStorage = findItem(item); if (linkedStorage == null) { - ChatUtils.sendMsg(OmegawareAddons.PREFIX.copy() - .append(Text.literal("No linked storage contains the item: ").formatted(Formatting.RED)) - .append(Text.literal(item.getName().getString()).formatted(Formatting.WHITE))); + Logger.error("No linked storage contains the item: %s%s", Formatting.WHITE, item.getName().getString()); if (disconnectOnError.get()) { AutoReconnect autoReconnect = Modules.get().get(meteordevelopment.meteorclient.systems.modules.misc.AutoReconnect.class); @@ -444,7 +423,7 @@ private void onMessageReceive(ReceiveMessageEvent event) { autoReconnect.toggle(); } - String prefix = OmegawareAddons.PREFIX.getString(); + String prefix = Logger.PREFIX.getString(); MutableText text = Text.literal(String.format("%s%s%s%s %s", Formatting.GRAY, Formatting.BLUE, prefix.substring(0, prefix.length() - 1), Formatting.GRAY, Formatting.RED) + String.format("No linked storage contains the item: %s\n", item.getName().getString())); disconnectOnError.set(false); // Disable the setting to prevent infinite disconnects @@ -466,8 +445,7 @@ private void onMessageReceive(ReceiveMessageEvent event) { if (msg.contains("done building")) { if (debugMode.get()) { - ChatUtils.sendMsg(OmegawareAddons.PREFIX.copy() - .append(Text.literal("Baritone has finished building!").formatted(Formatting.GREEN))); + Logger.info("Baritone has finished building!"); } if (disconnectOnDone.get()) { @@ -476,7 +454,7 @@ private void onMessageReceive(ReceiveMessageEvent event) { autoReconnect.toggle(); } - String prefix = OmegawareAddons.PREFIX.getString(); + String prefix = Logger.PREFIX.getString(); MutableText text = Text.literal(String.format("%s%s%s%s %s", Formatting.GRAY, Formatting.BLUE, prefix.substring(0, prefix.length() - 1), Formatting.GRAY, Formatting.RED) + "Baritone has finished building!"); ClientPlayNetworkHandler networkHandler = mc.getNetworkHandler(); @@ -491,9 +469,7 @@ private void onMessageReceive(ReceiveMessageEvent event) { if (msg.startsWith("build") || msg.startsWith("litematica")) { buildCommand = msg; if (debugMode.get()) { - ChatUtils.sendMsg(OmegawareAddons.PREFIX.copy() - .append(Text.literal("Build command captured: ").formatted(Formatting.GREEN)) - .append(Text.literal(buildCommand).formatted(Formatting.WHITE))); + Logger.info("Build command captured: %s%s", Formatting.WHITE, buildCommand); } return; } @@ -503,8 +479,7 @@ private void onMessageReceive(ReceiveMessageEvent event) { eventQueue.clear(); itemsToFetch.clear(); - ChatUtils.sendMsg(OmegawareAddons.PREFIX.copy() - .append(Text.literal("Stop received.").formatted(Formatting.GREEN))); + Logger.info("Stop received."); } } @@ -528,7 +503,7 @@ private void onInventory(InventoryEvent event) { itemsToFetch.forEach(storageItem -> MeteorExecutor.execute(() -> { if (debugMode.get()) { String msg = String.format("Fetching %s stacks of %s from linked storage at X=%s, Y=%s, Z=%s", storageItem.stacks, storageItem.item.getName().getString(), storageItem.linkedStorage.blockPos.getX(), storageItem.linkedStorage.blockPos.getY(), storageItem.linkedStorage.blockPos.getZ()); - ChatUtils.sendMsg(OmegawareAddons.PREFIX.copy().append(Text.literal(msg).formatted(Formatting.GREEN))); + Logger.info(msg); } moveSlots(storageItem, mc.player.currentScreenHandler); })); @@ -553,43 +528,33 @@ private void onInventory(InventoryEvent event) { } } - if (storageLinkMode.get()) { - if (blockEntity instanceof ShulkerBoxBlockEntity || blockEntity instanceof ChestBlockEntity || blockEntity instanceof BarrelBlockEntity || blockEntity instanceof EnderChestBlockEntity) { - for (LinkedStorage linkedStorage : linkedStorages) { - if (linkedStorage.blockPos.equals(lastBlockInteractPos)) { - lastBlockInteractPos = null; - linkedStorages.remove(linkedStorage); - - LinkedStorage newStorage = indexStorage(mc.player.currentScreenHandler, blockEntity.getPos()); - if (newStorage != null) { - linkedStorages.add(newStorage); - saveLinkedStorages(); - } - - return; - } - } - lastBlockInteractPos = null; + if (!storageLinkMode.get()) return; + if (blockEntity instanceof ShulkerBoxBlockEntity || blockEntity instanceof ChestBlockEntity || blockEntity instanceof BarrelBlockEntity || blockEntity instanceof EnderChestBlockEntity) { + for (LinkedStorage linkedStorage : linkedStorages) { + if (linkedStorage.blockPos.equals(lastBlockInteractPos)) { + lastBlockInteractPos = null; + linkedStorages.remove(linkedStorage); - LinkedStorage linkedStorage = indexStorage(mc.player.currentScreenHandler, blockEntity.getPos()); - if (linkedStorage == null) return; + LinkedStorage newStorage = indexStorage(mc.player.currentScreenHandler, blockEntity.getPos()); + if (newStorage == null) return; - if (linkedStorage.inventory.isEmpty()) { - if (debugMode.get()) { - ChatUtils.sendMsg(OmegawareAddons.PREFIX.copy() - .append(Text.literal("No items found in the linked storage!").formatted(Formatting.RED))); - } - return; + linkedStorages.add(newStorage); + saveLinkedStorages(); } - linkedStorages.add(linkedStorage); - saveLinkedStorages(); + } + lastBlockInteractPos = null; + LinkedStorage linkedStorage = indexStorage(mc.player.currentScreenHandler, blockEntity.getPos()); + if (linkedStorage == null) return; - MutableText msg = OmegawareAddons.PREFIX.copy() - .append(Text.literal("Better Baritone Build: ").formatted(Formatting.GREEN)) - .append(Text.literal(String.format("Linked Storage located at X=%s, Y=%s, Z=%s", blockEntity.getPos().getX(), blockEntity.getPos().getY(), blockEntity.getPos().getZ())).formatted(Formatting.WHITE)); - ChatUtils.sendMsg(msg); + if (linkedStorage.inventory.isEmpty()) { + if (debugMode.get()) Logger.error("No items found in the linked storage!"); + return; } + linkedStorages.add(linkedStorage); + saveLinkedStorages(); + + Logger.info("Linked Storage located at X=%s, Y=%s, Z=%s", blockEntity.getPos().getX(), blockEntity.getPos().getY(), blockEntity.getPos().getZ()); } } @@ -750,11 +715,8 @@ private LinkedStorage indexStorage(ScreenHandler screenHandler, BlockPos blockPo private void pathToPos(BlockPos blockPos) { if (mc.player == null || mc.world == null) return; - if (debugMode.get()) { - ChatUtils.sendMsg(OmegawareAddons.PREFIX.copy() - .append(Text.literal("Navigating to: ").formatted(Formatting.GREEN)) - .append(Text.literal(String.format("X=%s, Y=%s, Z=%s", blockPos.getX(), blockPos.getY(), blockPos.getZ())).formatted(Formatting.WHITE))); - } + if (debugMode.get()) Logger.info("%sNavigating to:%s X=%s, Y=%s, Z=%s", Formatting.GREEN, Formatting.WHITE, blockPos.getX(), blockPos.getY(), blockPos.getZ()); + if (!ignoreY.get()) { baritone.getCustomGoalProcess().setGoalAndPath(new GoalGetToBlock(blockPos)); @@ -784,9 +746,7 @@ private LinkedStorage findItem(Item item) { private void pathToLinkedStorage(Item item, LinkedStorage linkedStorage) { if (mc.player == null || mc.interactionManager == null) return; - ChatUtils.sendMsg(OmegawareAddons.PREFIX.copy() - .append(Text.literal("Navigating to storage containing: ").formatted(Formatting.GREEN)) - .append(Text.literal(item.getName().getString()).formatted(Formatting.WHITE))); + Logger.info("%sNavigating to storage containing:%s %s", Formatting.GREEN, Formatting.WHITE, item.getName().getString()); eventQueue.add(new Event(true, () -> pathToPos(linkedStorage.blockPos))); diff --git a/src/main/java/xyz/omegaware/addon/modules/BetterStashFinderModule.java b/src/main/java/xyz/omegaware/addon/modules/BetterStashFinderModule.java index ca4a7c9..a45e47a 100644 --- a/src/main/java/xyz/omegaware/addon/modules/BetterStashFinderModule.java +++ b/src/main/java/xyz/omegaware/addon/modules/BetterStashFinderModule.java @@ -1,6 +1,5 @@ package xyz.omegaware.addon.modules; - import com.google.common.reflect.TypeToken; import com.google.gson.Gson; import com.google.gson.GsonBuilder; @@ -29,6 +28,7 @@ import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.ChunkPos; import xyz.omegaware.addon.OmegawareAddons; +import xyz.omegaware.addon.utils.Logger; import java.io.*; import java.util.ArrayList; @@ -149,7 +149,7 @@ private void onChunkData(ChunkDataEvent event) { autoReconnect.toggle(); } - String prefix = OmegawareAddons.PREFIX.getString(); + String prefix = Logger.PREFIX.getString(); MutableText text = Text.literal(String.format("%s%s%s%s %s", Formatting.GRAY, Formatting.BLUE, prefix.substring(0, prefix.length() - 1), Formatting.GRAY, Formatting.RED) + String.format("Found stash at %s, %s.", chunk.x, chunk.z)).append("\n"); disconnectOnStashFound.set(false); // Disable the setting to prevent infinite disconnects diff --git a/src/main/java/xyz/omegaware/addon/modules/ChatFilterModule.java b/src/main/java/xyz/omegaware/addon/modules/ChatFilterModule.java index d2e3543..111c362 100644 --- a/src/main/java/xyz/omegaware/addon/modules/ChatFilterModule.java +++ b/src/main/java/xyz/omegaware/addon/modules/ChatFilterModule.java @@ -8,13 +8,13 @@ import meteordevelopment.meteorclient.gui.widgets.containers.WVerticalList; import meteordevelopment.meteorclient.gui.widgets.pressable.WButton; import meteordevelopment.meteorclient.settings.*; -import meteordevelopment.meteorclient.utils.player.ChatUtils; import net.minecraft.text.Text; import net.minecraft.util.Formatting; import xyz.omegaware.addon.OmegawareAddons; import meteordevelopment.meteorclient.events.game.ReceiveMessageEvent; import meteordevelopment.meteorclient.systems.modules.Module; import meteordevelopment.orbit.EventHandler; +import xyz.omegaware.addon.utils.Logger; import java.io.File; import java.io.FileWriter; @@ -23,6 +23,8 @@ import java.nio.file.Files; import java.util.List; +import static xyz.omegaware.addon.utils.ServerCheck.isNot6B6T; + public class ChatFilterModule extends Module { public ChatFilterModule() { super(OmegawareAddons.CATEGORY, "6B6T-chat-filter", "This module filters chat messages based on selected criteria."); @@ -140,10 +142,9 @@ public void loadFilteredCount() { @Override public void onActivate() { - if (!OmegawareAddons.is6B6T()) { - ChatUtils.sendMsg(OmegawareAddons.PREFIX.copy() - .append(Text.literal("The 6B6T Chat Filter module is only intended for use on 6b6t.").formatted(Formatting.RED))); - this.toggle(); + if (isNot6B6T()) { + Logger.error("%s is only intended for use on 6b6t.", name.replace("-", " ")); + toggle(); return; } @@ -225,10 +226,7 @@ public WWidget getWidget(GuiTheme theme) { WButton btn = theme.button("Print number of filtered messages"); btn.action = () -> { - Text msg = OmegawareAddons.PREFIX.copy() - .append(Text.literal("Total Filtered Messages: ").formatted(Formatting.GREEN)) - .append(Text.literal(filteredCount.toString()).formatted(Formatting.WHITE)); - ChatUtils.sendMsg(msg); + Logger.info("%sTotal Filtered Messages: %s%d", Formatting.GREEN, Formatting.WHITE, filteredCount); }; hList.add(btn); diff --git a/src/main/java/xyz/omegaware/addon/modules/ItemFrameDupeModule.java b/src/main/java/xyz/omegaware/addon/modules/ItemFrameDupeModule.java index 427a6b2..7343d1f 100644 --- a/src/main/java/xyz/omegaware/addon/modules/ItemFrameDupeModule.java +++ b/src/main/java/xyz/omegaware/addon/modules/ItemFrameDupeModule.java @@ -6,7 +6,6 @@ import meteordevelopment.meteorclient.settings.Setting; import meteordevelopment.meteorclient.settings.SettingGroup; import meteordevelopment.meteorclient.systems.modules.Module; -import meteordevelopment.meteorclient.utils.player.ChatUtils; import meteordevelopment.meteorclient.utils.player.FindItemResult; import meteordevelopment.meteorclient.utils.player.InvUtils; import meteordevelopment.orbit.EventHandler; @@ -15,8 +14,6 @@ import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.item.Items; -import net.minecraft.text.Text; -import net.minecraft.util.Formatting; import net.minecraft.util.Hand; import net.minecraft.util.hit.BlockHitResult; import net.minecraft.util.math.BlockPos; @@ -26,10 +23,13 @@ import net.minecraft.world.GameMode; import org.jetbrains.annotations.NotNull; import xyz.omegaware.addon.OmegawareAddons; +import xyz.omegaware.addon.utils.Logger; import java.util.ArrayList; import java.util.List; +import static xyz.omegaware.addon.utils.ServerCheck.isNot6B6T; + // Shamelessly taken from https://github.com/kybe236/rusher-auto-item-frame-dupe/ public class ItemFrameDupeModule extends Module { public ItemFrameDupeModule() { @@ -115,10 +115,9 @@ public ItemFrameDupeModule() { @Override public void onActivate() { - if (!OmegawareAddons.is6B6T()) { - ChatUtils.sendMsg(OmegawareAddons.PREFIX.copy() - .append(Text.literal("The 6B6T Item Frame Dupe module is only intended for use on 6b6t.").formatted(Formatting.RED))); - this.toggle(); + if (isNot6B6T()) { + Logger.error("%s is only intended for use on 6b6t.", name.replace("-", " ")); + toggle(); } } diff --git a/src/main/java/xyz/omegaware/addon/modules/TPAAutomationModule.java b/src/main/java/xyz/omegaware/addon/modules/TPAAutomationModule.java index f4e9539..f14b15e 100644 --- a/src/main/java/xyz/omegaware/addon/modules/TPAAutomationModule.java +++ b/src/main/java/xyz/omegaware/addon/modules/TPAAutomationModule.java @@ -3,18 +3,20 @@ import meteordevelopment.meteorclient.settings.*; import meteordevelopment.meteorclient.systems.friends.Friends; import meteordevelopment.meteorclient.utils.player.ChatUtils; -import net.minecraft.text.Text; import net.minecraft.util.Formatting; import xyz.omegaware.addon.OmegawareAddons; import meteordevelopment.meteorclient.events.game.ReceiveMessageEvent; import meteordevelopment.meteorclient.systems.modules.Module; import meteordevelopment.orbit.EventHandler; +import xyz.omegaware.addon.utils.Logger; import java.util.List; import java.util.Set; import java.util.regex.Matcher; import java.util.regex.Pattern; +import static xyz.omegaware.addon.utils.ServerCheck.isNot6B6T; + public class TPAAutomationModule extends Module { public TPAAutomationModule() { super(OmegawareAddons.CATEGORY, "TPA-automations", "A module that automatically accepts or denies teleport requests based on a list of approved players."); @@ -96,10 +98,9 @@ public TPAAutomationModule() { @Override public void onActivate() { - if (!OmegawareAddons.is6B6T()) { - ChatUtils.sendMsg(OmegawareAddons.PREFIX.copy() - .append(Text.literal("The TPA Automations module is only intended for use on 6b6t.").formatted(Formatting.RED))); - this.toggle(); + if (isNot6B6T()) { + Logger.error("%s is only intended for use on 6b6t.", name.replace("-", " ")); + toggle(); } } @@ -134,38 +135,19 @@ private void onMessageReceive(ReceiveMessageEvent event) { String username = matcher.group(1); - if (printTpaDetected.get()) { - Text tpaDetected = OmegawareAddons.PREFIX.copy() - .append(Text.literal("TPA Detected: ").formatted(Formatting.RED)) - .append(Text.literal(username).formatted(Formatting.WHITE)) - .append(Text.literal("!").formatted(Formatting.WHITE)); - - ChatUtils.sendMsg(tpaDetected); - } - - Text accepted = OmegawareAddons.PREFIX.copy() - .append(Text.literal("Auto-Accepted: ").formatted(Formatting.GREEN)) - .append(Text.literal(username).formatted(Formatting.WHITE)) - .append(Text.literal("!").formatted(Formatting.WHITE)); - - Text ignored = OmegawareAddons.PREFIX.copy() - .append(Text.literal("Ignored: ").formatted(Formatting.RED)) - .append(Text.literal(username).formatted(Formatting.WHITE)) - .append(Text.literal("!").formatted(Formatting.WHITE)); + if (printTpaDetected.get()) Logger.info("%sTPA Detected:%s %s!", Formatting.RED, Formatting.WHITE, username); if (approvedUsers.get().contains(username) || (acceptFriends.get() && Friends.get().get(username) != null) || (acceptTSRBots.get() && TSR_KIT_BOT_USERS.contains(username))) { ChatUtils.sendPlayerMsg("/tpy " + username); - if (printTpaAccepted.get()) ChatUtils.sendMsg(accepted); + if (printTpaAccepted.get()) Logger.info("%sAuto Accepted:%s %s!", Formatting.GREEN, Formatting.WHITE, username); } else if (autoDeny.get()){ ChatUtils.sendPlayerMsg("/tpn " + username); - if (printTpaIgnored.get()) ChatUtils.sendMsg(ignored); + if (printTpaIgnored.get()) Logger.info("%sIgnored:%s %s!", Formatting.RED, Formatting.WHITE, username); } - if (filterTpaMessages.get() && printTpaDetected.get()) { - event.cancel(); - } + if (filterTpaMessages.get() && printTpaDetected.get()) event.cancel(); } } diff --git a/src/main/java/xyz/omegaware/addon/modules/TSRKitBotModule.java b/src/main/java/xyz/omegaware/addon/modules/TSRKitBotModule.java index 84ebc15..b65de65 100644 --- a/src/main/java/xyz/omegaware/addon/modules/TSRKitBotModule.java +++ b/src/main/java/xyz/omegaware/addon/modules/TSRKitBotModule.java @@ -14,16 +14,17 @@ import meteordevelopment.meteorclient.settings.SettingGroup; import meteordevelopment.meteorclient.systems.modules.Module; import meteordevelopment.meteorclient.utils.network.Http; -import meteordevelopment.meteorclient.utils.player.ChatUtils; import net.minecraft.client.MinecraftClient; -import net.minecraft.text.Text; import net.minecraft.util.Formatting; import xyz.omegaware.addon.OmegawareAddons; +import xyz.omegaware.addon.utils.Logger; import java.io.*; import java.net.http.HttpResponse; import java.nio.file.Files; +import static xyz.omegaware.addon.utils.ServerCheck.isNot6B6T; + public class TSRKitBotModule extends Module { public TSRKitBotModule() { super(OmegawareAddons.CATEGORY, "TSR-Clan-KitBot-API", "Make kit requests to the TSR Clan KitBot API."); @@ -192,10 +193,7 @@ public static boolean getIsLinked(String... code) { if (apiKey != null && !apiKey.isEmpty()) return true; if (DiscordIPC.getUser() == null) { - Text msg = OmegawareAddons.PREFIX.copy() - .append(Text.literal("Error: ").formatted(Formatting.RED)) - .append(Text.literal("You must have the Discord Presence module enabled").formatted(Formatting.WHITE)); - ChatUtils.sendMsg(msg); + Logger.error("You must have the Discord Presence module enabled"); return false; } @@ -213,44 +211,28 @@ public static boolean getIsLinked(String... code) { if (response.statusCode() == 200) { String message = response.body().get("message").getAsString(); if (message != null && message.equals("Retrieval code sent to your Discord DMs.")) { - Text msg = OmegawareAddons.PREFIX.copy() - .append(Text.literal("Message: ").formatted(Formatting.GREEN)) - .append(Text.literal(message).formatted(Formatting.WHITE)) - .append(Text.literal("Grab the code and use the command .auth ").formatted(Formatting.WHITE)); - ChatUtils.sendMsg(msg); + Logger.info("%sMessage: %s%sGrab the code and use the command .auth ", Formatting.GREEN, Formatting.WHITE, message); return false; } // print api key to chat if (response.body().has("api_key")) { apiKey = response.body().get("api_key").getAsString(); - Text msg = OmegawareAddons.PREFIX.copy() - .append(Text.literal("Set API Key: ").formatted(Formatting.GREEN)) - .append(Text.literal(apiKey).formatted(Formatting.WHITE)); - ChatUtils.sendMsg(msg); + Logger.info("%sSet API Key:%s %s", Formatting.GREEN, Formatting.WHITE, apiKey); saveApiKey(apiKey); } else { - Text msg = OmegawareAddons.PREFIX.copy() - .append(Text.literal("Error: ").formatted(Formatting.RED)) - .append(Text.literal("API Key not found.").formatted(Formatting.WHITE)); - ChatUtils.sendMsg(msg); + Logger.error("API Key not found."); } return apiKey != null && !apiKey.isEmpty(); } else { if (response.body() == null) { - Text msg = OmegawareAddons.PREFIX.copy() - .append(Text.literal("Error: ").formatted(Formatting.RED)) - .append(Text.literal("No response from server.").formatted(Formatting.WHITE)); - ChatUtils.sendMsg(msg); + Logger.error("No response from server."); return false; } - Text msg = OmegawareAddons.PREFIX.copy() - .append(Text.literal("Error: ").formatted(Formatting.RED)) - .append(Text.literal(response.body().get("error").getAsString()).formatted(Formatting.WHITE)); - ChatUtils.sendMsg(msg); + Logger.error("%s", response.body().get("error").getAsString()); return false; } } @@ -268,9 +250,7 @@ private static void conditionallyPrintOrders(String... statusFlag) { if (response.statusCode() == 200) { JsonArray orders = response.body().getAsJsonArray("orders"); if (orders.isEmpty()) { - Text msg = OmegawareAddons.PREFIX.copy() - .append(Text.literal("No order history.").formatted(Formatting.GREEN)); - ChatUtils.sendMsg(msg); + Logger.info("%sNo order history.", Formatting.GREEN); return; } @@ -294,33 +274,17 @@ private static void conditionallyPrintOrders(String... statusFlag) { } if (!isValidStatus) continue; - Text msg = OmegawareAddons.PREFIX.copy() - .append(Text.literal("Order ID: ").formatted(Formatting.GREEN)) - .append(Text.literal(orderId).formatted(Formatting.WHITE)) - .append(Text.literal("\n | ").formatted(Formatting.WHITE)) - .append(Text.literal("Status: ").formatted(Formatting.GREEN)) - .append(Text.literal(status).formatted(Formatting.WHITE)) - .append(Text.literal("\n | ").formatted(Formatting.WHITE)) - .append(Text.literal("Request Type: ").formatted(Formatting.GREEN)) - .append(Text.literal(requestType).formatted(Formatting.WHITE)) - .append(Text.literal("\n | ").formatted(Formatting.WHITE)) - .append(Text.literal("Quantity: ").formatted(Formatting.GREEN)) - .append(Text.literal(quantity).formatted(Formatting.WHITE)); - ChatUtils.sendMsg(msg); + Logger.info("%sOrder ID:%s %s\n | %sStatus:%s %s\n | %sRequest Type:%s %s\n | %sQuantity:%s %s", + Formatting.GREEN, Formatting.WHITE, orderId, Formatting.GREEN, Formatting.WHITE, status, + Formatting.GREEN, Formatting.WHITE, requestType, Formatting.GREEN, Formatting.WHITE, quantity); } } else { if (response.body() == null) { - Text msg = OmegawareAddons.PREFIX.copy() - .append(Text.literal("Error: ").formatted(Formatting.RED)) - .append(Text.literal("No response from server.").formatted(Formatting.WHITE)); - ChatUtils.sendMsg(msg); + Logger.error("No response from server."); return; } - Text msg = OmegawareAddons.PREFIX.copy() - .append(Text.literal("Error: ").formatted(Formatting.RED)) - .append(Text.literal(response.body().get("error").getAsString()).formatted(Formatting.WHITE)); - ChatUtils.sendMsg(msg); + Logger.error("%s", response.body().get("error").getAsString()); } } @@ -328,10 +292,9 @@ private static void conditionallyPrintOrders(String... statusFlag) { @Override public void onActivate() { - if (!OmegawareAddons.is6B6T()) { - ChatUtils.sendMsg(OmegawareAddons.PREFIX.copy() - .append(Text.literal("The TSR Clan KitBot API module is only intended for use on 6b6t.").formatted(Formatting.RED))); - this.toggle(); + if (isNot6B6T()) { + Logger.error("%s is only intended for use on 6b6t.", name.replace("-", " ")); + toggle(); return; } @@ -358,23 +321,14 @@ public WWidget getWidget(GuiTheme theme) { HttpResponse response = request.sendJsonResponse(JsonObject.class); if (response.statusCode() == 200) { - Text msg = OmegawareAddons.PREFIX.copy() - .append(Text.literal("Balance: ").formatted(Formatting.GREEN)) - .append(Text.literal(response.body().get("credits").getAsString()).formatted(Formatting.WHITE)); - ChatUtils.sendMsg(msg); + Logger.info("%sBalance:%s %s ",Formatting.GREEN, Formatting.WHITE, response.body().get("credits").getAsString()); } else { if (response.body() == null) { - Text msg = OmegawareAddons.PREFIX.copy() - .append(Text.literal("Error: ").formatted(Formatting.RED)) - .append(Text.literal("No response from server.").formatted(Formatting.WHITE)); - ChatUtils.sendMsg(msg); + Logger.error("No response from server."); return; } - Text msg = OmegawareAddons.PREFIX.copy() - .append(Text.literal("Error: ").formatted(Formatting.RED)) - .append(Text.literal(response.body().get("error").getAsString()).formatted(Formatting.WHITE)); - ChatUtils.sendMsg(msg); + Logger.error("%s", response.body().get("error").getAsString()); } }; hList.add(getBalanceButton); @@ -392,29 +346,17 @@ public WWidget getWidget(GuiTheme theme) { if (response.statusCode() == 200) { if (response.body().has("message")) { - Text msg = OmegawareAddons.PREFIX.copy() - .append(Text.literal("Message: ").formatted(Formatting.GREEN)) - .append(Text.literal(response.body().get("message").getAsString()).formatted(Formatting.WHITE)); - ChatUtils.sendMsg(msg); + Logger.info("%sMessage:%s %s", Formatting.WHITE, Formatting.GREEN, response.body().get("message").getAsString()); } else { - Text msg = OmegawareAddons.PREFIX.copy() - .append(Text.literal("Queue Position: ").formatted(Formatting.GREEN)) - .append(Text.literal(response.body().get("position").getAsString()).formatted(Formatting.WHITE)); - ChatUtils.sendMsg(msg); + Logger.info("%sQueue Position:%s %s", Formatting.GREEN, Formatting.WHITE, response.body().get("position").getAsString()); } } else { if (response.body() == null) { - Text msg = OmegawareAddons.PREFIX.copy() - .append(Text.literal("Error: ").formatted(Formatting.RED)) - .append(Text.literal("No response from server.").formatted(Formatting.WHITE)); - ChatUtils.sendMsg(msg); + Logger.error("No response from server."); return; } - Text msg = OmegawareAddons.PREFIX.copy() - .append(Text.literal("Error: ").formatted(Formatting.RED)) - .append(Text.literal(response.body().get("error").getAsString()).formatted(Formatting.WHITE)); - ChatUtils.sendMsg(msg); + Logger.error("%s", response.body().get("error").getAsString()); } }; hList.add(getQueuePositionButton); @@ -428,18 +370,12 @@ public WWidget getWidget(GuiTheme theme) { if (!getIsLinked()) return; int kitTotal = pvpKit.get() + cpvpKit.get() + refillKit.get() + griefKit.get() + hunterKit.get() + mapartKit.get() + highwayKit.get() + redstoneKit.get() + buildKit.get() + build2Kit.get() + build3Kit.get() + build4Kit.get() + build5Kit.get() + build6Kit.get() + toolsKit.get() + totemKit.get() + censoredKit.get(); if (kitTotal > 27) { - Text msg = OmegawareAddons.PREFIX.copy() - .append(Text.literal("Error: ").formatted(Formatting.RED)) - .append(Text.literal("You can only order a maximum of 27 kits.").formatted(Formatting.WHITE)); - ChatUtils.sendMsg(msg); + Logger.error("You can only order a maximum of 27 kits."); return; } - if (kitTotal == 0 || kitTotal < 0) { - Text msg = OmegawareAddons.PREFIX.copy() - .append(Text.literal("Error: ").formatted(Formatting.RED)) - .append(Text.literal("You must select at least 1 kit.").formatted(Formatting.WHITE)); - ChatUtils.sendMsg(msg); + if (kitTotal <= 0 ) { + Logger.error("You must select at least 1 kit."); return; } @@ -595,39 +531,21 @@ public WWidget getWidget(GuiTheme theme) { HttpResponse response = request.sendJsonResponse(JsonObject.class); if (response.statusCode() == 200) { if (response.body().has("message")) { - Text msg = OmegawareAddons.PREFIX.copy() - .append(Text.literal("Message: ").formatted(Formatting.GREEN)) - .append(Text.literal(response.body().get("message").getAsString()).formatted(Formatting.WHITE)); - ChatUtils.sendMsg(msg); + Logger.info("%sMessage:%s %s", Formatting.GREEN, Formatting.WHITE,response.body().get("message").getAsString()); return; } else if (response.body().has("error")) { - Text msg = OmegawareAddons.PREFIX.copy() - .append(Text.literal("Error: ").formatted(Formatting.RED)) - .append(Text.literal(response.body().get("error").getAsString()).formatted(Formatting.WHITE)); - ChatUtils.sendMsg(msg); + Logger.error("%s", response.body().get("error").getAsString()); return; } - Text msg = OmegawareAddons.PREFIX.copy() - .append(Text.literal("Order Placed: ").formatted(Formatting.GREEN)) - .append(Text.literal(response.body().get("order_id").getAsString()).formatted(Formatting.WHITE)) - .append(Text.literal(" | ").formatted(Formatting.WHITE)) - .append(Text.literal("Priority: ").formatted(Formatting.GREEN)) - .append(Text.literal(response.body().get("priority").getAsString()).formatted(Formatting.WHITE)); - ChatUtils.sendMsg(msg); + Logger.info("%sOrder Placed:%s %s | %sPriority:%s %s", Formatting.GREEN, Formatting.WHITE, response.body().get("order_id").getAsString(), Formatting.GREEN, Formatting.WHITE, response.body().get("priority").getAsString()); } else { if (response.body() == null) { - Text msg = OmegawareAddons.PREFIX.copy() - .append(Text.literal("Error: ").formatted(Formatting.RED)) - .append(Text.literal("No response from server.").formatted(Formatting.WHITE)); - ChatUtils.sendMsg(msg); + Logger.error("No response from server."); return; } - Text msg = OmegawareAddons.PREFIX.copy() - .append(Text.literal("Error: ").formatted(Formatting.RED)) - .append(Text.literal(response.body().get("error").getAsString()).formatted(Formatting.WHITE)); - ChatUtils.sendMsg(msg); + Logger.error("%s", Formatting.WHITE, response.body().get("error").getAsString()); } }; hList2.add(orderButton); @@ -662,23 +580,14 @@ public WWidget getWidget(GuiTheme theme) { HttpResponse response = request.sendJsonResponse(JsonObject.class); if (response.statusCode() == 200) { - Text msg = OmegawareAddons.PREFIX.copy() - .append(Text.literal("Cancel All Orders: ").formatted(Formatting.GREEN)) - .append(Text.literal(response.body().get("message").getAsString()).formatted(Formatting.WHITE)); - ChatUtils.sendMsg(msg); + Logger.info("%sCancel All Orders:%s %s", Formatting.GREEN, Formatting.WHITE, response.body().get("message").getAsString()); } else { if (response.body() == null) { - Text msg = OmegawareAddons.PREFIX.copy() - .append(Text.literal("Error: ").formatted(Formatting.RED)) - .append(Text.literal("No response from server.").formatted(Formatting.WHITE)); - ChatUtils.sendMsg(msg); + Logger.error("No response from server."); return; } - Text msg = OmegawareAddons.PREFIX.copy() - .append(Text.literal("Error: ").formatted(Formatting.RED)) - .append(Text.literal(response.body().get("error").getAsString()).formatted(Formatting.WHITE)); - ChatUtils.sendMsg(msg); + Logger.error("%s", Formatting.WHITE, response.body().get("error").getAsString()); } }; hList3.add(cancelAllButton); @@ -692,18 +601,12 @@ public WWidget getWidget(GuiTheme theme) { if (!getIsLinked()) return; if (textBox.get().isEmpty()) { - Text msg = OmegawareAddons.PREFIX.copy() - .append(Text.literal("Error: ").formatted(Formatting.RED)) - .append(Text.literal("Please enter an order ID.").formatted(Formatting.WHITE)); - ChatUtils.sendMsg(msg); + Logger.error("Please enter an order ID."); return; } if (!textBox.get().matches("\\d+")) { - Text msg = OmegawareAddons.PREFIX.copy() - .append(Text.literal("Error: ").formatted(Formatting.RED)) - .append(Text.literal("Order ID must be a number.").formatted(Formatting.WHITE)); - ChatUtils.sendMsg(msg); + Logger.error("Order ID must be a number."); return; } @@ -718,23 +621,14 @@ public WWidget getWidget(GuiTheme theme) { HttpResponse response = request.sendJsonResponse(JsonObject.class); if (response.statusCode() == 200) { - Text msg = OmegawareAddons.PREFIX.copy() - .append(Text.literal("Order Cancelled: ").formatted(Formatting.GREEN)) - .append(Text.literal(response.body().get("order_id").getAsString()).formatted(Formatting.WHITE)); - ChatUtils.sendMsg(msg); + Logger.info("%sOrder Cancelled:%s %s", Formatting.GREEN, Formatting.WHITE, response.body().get("order_id").getAsString()); } else { if (response.body() == null) { - Text msg = OmegawareAddons.PREFIX.copy() - .append(Text.literal("Error: ").formatted(Formatting.RED)) - .append(Text.literal("No response from server.").formatted(Formatting.WHITE)); - ChatUtils.sendMsg(msg); + Logger.error("No response from server"); return; } - Text msg = OmegawareAddons.PREFIX.copy() - .append(Text.literal("Error: ").formatted(Formatting.RED)) - .append(Text.literal(response.body().get("error").getAsString()).formatted(Formatting.WHITE)); - ChatUtils.sendMsg(msg); + Logger.error("%s", response.body().get("error").getAsString()); } }; hList3.add(cancelButton); @@ -756,26 +650,17 @@ public WWidget getWidget(GuiTheme theme) { if (!getIsLinked()) return; if (amountTextBox.get().isEmpty() || targetTextBox.get().isEmpty()) { - Text msg = OmegawareAddons.PREFIX.copy() - .append(Text.literal("Error: ").formatted(Formatting.RED)) - .append(Text.literal("Please enter an amount and a target Discord ID.").formatted(Formatting.WHITE)); - ChatUtils.sendMsg(msg); + Logger.error("Please enter an amount and a target Discord ID."); return; } if (!amountTextBox.get().matches("\\d+")) { - Text msg = OmegawareAddons.PREFIX.copy() - .append(Text.literal("Error: ").formatted(Formatting.RED)) - .append(Text.literal("Amount must be a number.").formatted(Formatting.WHITE)); - ChatUtils.sendMsg(msg); + Logger.error("Amount must be a number."); return; } if (Integer.parseInt(amountTextBox.get()) <= 0) { - Text msg = OmegawareAddons.PREFIX.copy() - .append(Text.literal("Error: ").formatted(Formatting.RED)) - .append(Text.literal("Amount must be at least 1").formatted(Formatting.WHITE)); - ChatUtils.sendMsg(msg); + Logger.error("Amount must be at least 1"); return; } @@ -794,33 +679,20 @@ public WWidget getWidget(GuiTheme theme) { if (response.statusCode() == 200) { if (response.body().has("error")) { - Text msg = OmegawareAddons.PREFIX.copy() - .append(Text.literal("Error: ").formatted(Formatting.RED)) - .append(Text.literal(response.body().get("error").getAsString()).formatted(Formatting.WHITE)); - ChatUtils.sendMsg(msg); + Logger.error("%s", response.body().get("error").getAsString()); return; } - Text msg = OmegawareAddons.PREFIX.copy() - .append(Text.literal("Tokens Sent: ").formatted(Formatting.GREEN)) - .append(Text.literal(response.body().get("message").getAsString()).formatted(Formatting.WHITE)) - .append(Text.literal(" | ").formatted(Formatting.WHITE)) - .append(Text.literal("New Balance: ").formatted(Formatting.GREEN)) - .append(Text.literal(response.body().get("from_balance").getAsString()).formatted(Formatting.WHITE)); - ChatUtils.sendMsg(msg); + Logger.info("%sTokens Sent:%s %s | %sNew Balance:%s %s", + Formatting.GREEN, Formatting.WHITE, response.body().get("message").getAsString(), + Formatting.GREEN, Formatting.WHITE, response.body().get("from_balance").getAsString()); } else { if (response.body() == null) { - Text msg = OmegawareAddons.PREFIX.copy() - .append(Text.literal("Error: ").formatted(Formatting.RED)) - .append(Text.literal("No response from server.").formatted(Formatting.WHITE)); - ChatUtils.sendMsg(msg); + Logger.error("No response from server."); return; } - Text msg = OmegawareAddons.PREFIX.copy() - .append(Text.literal("Error: ").formatted(Formatting.RED)) - .append(Text.literal(response.body().get("error").getAsString()).formatted(Formatting.WHITE)); - ChatUtils.sendMsg(msg); + Logger.error("%s", response.body().get("error").getAsString()); } }; hList4.add(sendTokensButton); diff --git a/src/main/java/xyz/omegaware/addon/utils/Logger.java b/src/main/java/xyz/omegaware/addon/utils/Logger.java new file mode 100644 index 0000000..3a5ba96 --- /dev/null +++ b/src/main/java/xyz/omegaware/addon/utils/Logger.java @@ -0,0 +1,58 @@ +package xyz.omegaware.addon.utils; + +import meteordevelopment.meteorclient.utils.player.ChatUtils; +import net.minecraft.text.Text; +import net.minecraft.util.Formatting; + +public class Logger { + + public static final Text PREFIX = Text.empty() + .append(Text.literal("[").formatted(Formatting.WHITE)) + .append(Text.literal("OmegaWare").formatted(Formatting.AQUA)) + .append(Text.literal("] ").formatted(Formatting.WHITE)); + + private static final Text WARN = Text.empty() + .append(Text.literal("[").formatted(Formatting.WHITE)) + .append(Text.literal("WARNING").formatted(Formatting.YELLOW)) + .append(Text.literal("] ").formatted(Formatting.WHITE)); + + private static final Text ERROR = Text.empty() + .append(Text.literal("[").formatted(Formatting.WHITE)) + .append(Text.literal("ERROR").formatted(Formatting.RED)) + .append(Text.literal("] ").formatted(Formatting.WHITE)); + + /** + * Sends a message to the chat with the given format string and arguments, prefixed with the OmegaWare prefix. + *
+     * Example:
+     * Logger.info("Found %d %sdiamonds!", 10, Formatting.AQUA);
+     * 
+ */ + public static void info(String message, Object... args) { + ChatUtils.sendMsg(PREFIX.copy().append(Text.literal(String.format(message, args)))); + } + + /** + * Sends a warning message to the chat with the given format string and arguments, prefixed with the OmegaWare prefix. + * The message will be yellow in color. + *
+     * Example:
+     * Logger.warn(%d %sdiamonds went missing", 5, Formatting.AQUA);
+     * 
+ */ + public static void warn(String message, Object... args) { + ChatUtils.sendMsg(PREFIX.copy().append(WARN).append(Text.literal(String.format(message, args))).formatted(Formatting.YELLOW)); + } + + /** + * Sends an error message to the chat with the given format string and arguments, prefixed with the OmegaWare prefix. + * The message will be red. + *
+     * Example:
+     * Logger.error("those %d %sdiamonds turned out to be fake", 5, Formatting.AQUA);
+     * 
+ */ + public static void error(String message, Object... args) { + ChatUtils.sendMsg(PREFIX.copy().append(ERROR).append(Text.literal(String.format(message, args))).formatted(Formatting.RED)); + } +} diff --git a/src/main/java/xyz/omegaware/addon/utils/ServerCheck.java b/src/main/java/xyz/omegaware/addon/utils/ServerCheck.java new file mode 100644 index 0000000..398394a --- /dev/null +++ b/src/main/java/xyz/omegaware/addon/utils/ServerCheck.java @@ -0,0 +1,24 @@ +package xyz.omegaware.addon.utils; + +import net.fabricmc.loader.api.FabricLoader; +import net.minecraft.client.network.ServerInfo; +import static meteordevelopment.meteorclient.MeteorClient.mc; + +public class ServerCheck { + + public static boolean isNot6B6T() { + if (FabricLoader.getInstance().isDevelopmentEnvironment()) return false; // Bypass check in dev environment + if (mc.isIntegratedServerRunning()) return true; + ServerInfo server = mc.getCurrentServerEntry(); + if (server == null) return false; + return !server.address.endsWith("6b6t.org"); + } + +// Idk how to turn off the module from here +// public static void checkIf6B6T() { +// if (isNot6B6T()) { +// Logger.error("%s is only intended for use on 6b6t.org."); +// // toggle off the module +// } +// } +}