diff --git a/README.md b/README.md index 0377610..3df9e37 100644 --- a/README.md +++ b/README.md @@ -31,6 +31,7 @@ - **Better Baritone Build** - Add some improvements to the baritone build command - Can refill items from any storage block + - Please use [this fork of baritone](https://github.com/Omega172/baritone-staircase) which fixes staircase building and carpet issues - I recommend to use this with [Litematica Printer](https://github.com/aleksilassila/litematica-printer) or [Meteor Litematica Printer](https://github.com/kkllffaa/meteor-litematica-printer) - Vide tutorial on how to use it [here](https://youtu.be/mpK_ld8JH34) diff --git a/gradle.properties b/gradle.properties index b881f20..37dfd46 100644 --- a/gradle.properties +++ b/gradle.properties @@ -2,7 +2,7 @@ org.gradle.jvmargs=-Xmx2G org.gradle.configuration-cache=true # Mod Global Properties -mod_version=1.1.1 +mod_version=1.1.2 maven_group=xyz.omegaware archives_base_name=OmegaWare Addons 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/hud/OnlineTSRMembersHUD.java b/src/main/java/xyz/omegaware/addon/hud/OnlineTSRMembersHUD.java index 3d31a32..1163f9a 100644 --- a/src/main/java/xyz/omegaware/addon/hud/OnlineTSRMembersHUD.java +++ b/src/main/java/xyz/omegaware/addon/hud/OnlineTSRMembersHUD.java @@ -56,12 +56,12 @@ public User(String name, String[] mcNames, String rank) { new User("Slay", new String[]{"slay_dev"}, "Admin"), new User("crystal", new String[]{""}, "Admin"), new User("monstro", new String[]{""}, "Admin"), - new User("Pietty", new String[]{"j26"}, "Admin"), + new User("Pietty", new String[]{"Pietty"}, "Admin"), new User("Omega", new String[]{"LostEmotions", "LostFriendships", "WomenAreScary", "ElectricCallboy"}, "OmegaWare"), new User("Hastur", new String[]{"TheKingHastur", "chmoka90 "}, "Member"), - new User("J26V5", new String[]{""}, "Member"), + new User("J26V5", new String[]{"J26V5"}, "Member"), new User("pyro", new String[]{""}, "Member"), - new User("Slyyy", new String[]{""}, "Member"), + new User("Slyyy", new String[]{"TwoFresh4Yea"}, "Member"), new User("_kingdom_warrior_", new String[]{"kingdom_warrior"}, "Member"), new User("cerejo2", new String[]{"cerejo2", "cerejo222", "cerejo_2"}, "Member"), new User("Emily", new String[]{""}, "Member"), diff --git a/src/main/java/xyz/omegaware/addon/modules/BetterBaritoneBuild.java b/src/main/java/xyz/omegaware/addon/modules/BetterBaritoneBuild.java index 36d492c..bc336fa 100644 --- a/src/main/java/xyz/omegaware/addon/modules/BetterBaritoneBuild.java +++ b/src/main/java/xyz/omegaware/addon/modules/BetterBaritoneBuild.java @@ -10,27 +10,25 @@ import meteordevelopment.meteorclient.events.entity.player.InteractBlockEvent; import meteordevelopment.meteorclient.events.game.ReceiveMessageEvent; import meteordevelopment.meteorclient.events.packets.InventoryEvent; +import meteordevelopment.meteorclient.events.render.Render3DEvent; import meteordevelopment.meteorclient.events.world.ServerConnectEndEvent; import meteordevelopment.meteorclient.events.world.TickEvent; import meteordevelopment.meteorclient.gui.GuiTheme; import meteordevelopment.meteorclient.gui.widgets.WWidget; import meteordevelopment.meteorclient.gui.widgets.containers.WHorizontalList; import meteordevelopment.meteorclient.gui.widgets.containers.WVerticalList; -import meteordevelopment.meteorclient.gui.widgets.input.WTextBox; import meteordevelopment.meteorclient.gui.widgets.pressable.WButton; import meteordevelopment.meteorclient.pathing.BaritoneUtils; -import meteordevelopment.meteorclient.settings.BoolSetting; -import meteordevelopment.meteorclient.settings.IntSetting; -import meteordevelopment.meteorclient.settings.Setting; -import meteordevelopment.meteorclient.settings.SettingGroup; +import meteordevelopment.meteorclient.renderer.ShapeMode; +import meteordevelopment.meteorclient.settings.*; import meteordevelopment.meteorclient.systems.modules.Module; import meteordevelopment.meteorclient.systems.modules.Modules; 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; import meteordevelopment.orbit.EventHandler; import net.minecraft.block.entity.*; import net.minecraft.client.MinecraftClient; @@ -47,8 +45,8 @@ import net.minecraft.util.math.Direction; import net.minecraft.util.math.Vec3d; import xyz.omegaware.addon.OmegawareAddons; +import xyz.omegaware.addon.utils.Logger; -import javax.annotation.Nullable; import java.io.File; import java.io.FileWriter; import java.io.Writer; @@ -58,12 +56,13 @@ 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(); private final SettingGroup sgGeneral = this.settings.getDefaultGroup(); + private final SettingGroup sgRender = this.settings.createGroup("Render"); private final Setting storageLinkMode = sgGeneral.add(new BoolSetting.Builder() .name("storage-link-mode") @@ -72,6 +71,69 @@ public BetterBaritoneBuild() { .build() ); + private final Setting ignoreY = sgGeneral.add(new BoolSetting.Builder() + .name("baritone-ignore-y") + .description("If enabled, the Y coordinate will be ignored when navigating to a block.") + .defaultValue(false) + .build() + ); + + private final Setting homeIfStuck = sgGeneral.add(new BoolSetting.Builder() + .name("home-if-stuck") + .description("If enabled, Baritone will return set home point if it gets stuck while building.") + .defaultValue(false) + .build() + ); + + private final Setting homeIfStuckTimeout = sgGeneral.add(new IntSetting.Builder() + .name("home-if-stuck-timeout") + .description("The timeout in seconds before Baritone returns to the home point if it gets stuck.") + .defaultValue(15) + .min(1) + .sliderRange(5, 120) + .visible(homeIfStuck::get) + .build() + ); + + private final Setting highlightLinkedStorages = sgRender.add(new BoolSetting.Builder() + .name("highlight-linked-storages") + .description("If enabled, linked storages will be highlighted with a box.") + .defaultValue(true) + .build() + ); + + private final Setting invertHighlight = sgRender.add(new BoolSetting.Builder() + .name("invert-highlight") + .description("If enabled, the highlight will be inverted (i.e. highlighted blocks will not be highlighted).") + .defaultValue(false) + .visible(highlightLinkedStorages::get) + .build() + ); + + private final Setting shapeMode = sgRender.add(new EnumSetting.Builder() + .name("shape-mode") + .description("How the shapes are rendered.") + .defaultValue(ShapeMode.Both) + .visible(this::isActive) + .build() + ); + + private final Setting sideColor = sgRender.add(new ColorSetting.Builder() + .name("side-color") + .description("The side color of the rendering.") + .defaultValue(new SettingColor(0, 255, 255, 40)) + .visible(() -> shapeMode.get().sides()) + .build() + ); + + private final Setting lineColor = sgRender.add(new ColorSetting.Builder() + .name("line-color") + .description("The line color of the rendering.") + .defaultValue(new SettingColor(0, 255, 255, 255)) + .visible(() -> shapeMode.get().lines()) + .build() + ); + private final Setting disconnectOnDone = sgGeneral.add(new BoolSetting.Builder() .name("disconnect-on-done") .description("If enabled, the module will disconnect you from the server when it is done.") @@ -120,7 +182,6 @@ public LinkedStorage(BlockPos blockPos, List inventory) { } private final List linkedStorages = new ArrayList<>(); - private static class Event { public boolean bWaitOnPath; public Runnable callback; @@ -150,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; } @@ -163,8 +222,40 @@ public void onActivate() { itemsToFetch.clear(); loadLinkedStorages(); + loadHome(); } + @EventHandler + private void onRender(Render3DEvent event) { + if (!isActive() || mc.world == null || !highlightLinkedStorages.get()) return; + + if (!invertHighlight.get()) { + for (LinkedStorage linkedStorage : linkedStorages) { + if (linkedStorage == null || linkedStorage.blockPos == null || !mc.world.isPosLoaded(linkedStorage.blockPos)) + continue; + + event.renderer.box(linkedStorage.blockPos, sideColor.get(), lineColor.get(), shapeMode.get(), 0); + } + } else { + for (BlockEntity blockEntity : Utils.blockEntities()) { + if (!(blockEntity instanceof ShulkerBoxBlockEntity || blockEntity instanceof ChestBlockEntity || blockEntity instanceof BarrelBlockEntity || blockEntity instanceof EnderChestBlockEntity)) + continue; + + BlockPos pos = blockEntity.getPos(); + if (mc.world.isPosLoaded(pos)) { + boolean isLinked = linkedStorages.stream().anyMatch(storage -> storage.blockPos.equals(pos)); + if (!isLinked) { + event.renderer.box(pos, sideColor.get(), lineColor.get(), shapeMode.get(), 0); + } + } + } + } + } + + private BlockPos home = null; + private int ticksStuck = 0; + private BlockPos lastBlockPos = null; + @Override public WWidget getWidget(GuiTheme theme) { WVerticalList list = theme.verticalList(); @@ -172,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)); - - 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))); + 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()))); - ChatUtils.sendMsg(msg); + Logger.info("Linked Storages:\n%s", sb.toString()); }; hList.add(printBtn); @@ -185,10 +274,24 @@ 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); + WButton setHomeBtn = theme.button("Set Home"); + setHomeBtn.action = () -> { + if (mc.player == null || mc.world == null) return; + + home = mc.player.getBlockPos(); + ticksStuck = 0; + lastBlockPos = null; + + saveHome(); + + 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); + return list; } @@ -207,7 +310,66 @@ private void onTickPre(TickEvent.Pre event) { updateLinkedStorages(); eventQueue.remove(queuedEvent); - }; + } + + @EventHandler + 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()) { + 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 + return; + } + + if (home == null) { + // Yell at the player to set a home point + 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; + } + + if (buildCommand.isEmpty()) return; + + if (lastBlockPos == null) { + lastBlockPos = mc.player.getBlockPos(); + return; + } + + if (lastBlockPos.equals(mc.player.getBlockPos())) { + ticksStuck++; + } else { + ticksStuck = 0; + lastBlockPos = mc.player.getBlockPos(); // Update the last block position if the player has moved + return; + } + + if (debugMode.get()) { + 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) { + Logger.error("Baritone is stuck, returning to home point..."); + + ticksStuck = 0; // Reset the stuck counter + lastBlockPos = mc.player.getBlockPos(); // Update the last block position + + eventQueue.clear(); + itemsToFetch.clear(); + + baritone.getPathingBehavior().cancelEverything(); + + eventQueue.add(new Event(false, () -> baritone.getCustomGoalProcess().setGoalAndPath(new GoalGetToBlock(home)))); + + if (!buildCommand.isEmpty()) { + eventQueue.add(new Event(true, () -> baritone.getCommandManager().execute(buildCommand))); + } + } + } @EventHandler private void onMessageReceive(ReceiveMessageEvent event) { @@ -216,7 +378,7 @@ private void onMessageReceive(ReceiveMessageEvent event) { if (msg == null || msg.isEmpty()) return; msg = msg.toLowerCase().trim(); - if (!msg.contains("[baritone]")) return; + if (!msg.contains("[baritone]") || msg.contains("omegaware")) return; int index = msg.indexOf("[baritone]"); msg = msg.substring(index+10).trim(); // Remove the "[Baritone]" part @@ -239,21 +401,51 @@ private void onMessageReceive(ReceiveMessageEvent event) { Identifier identifier = Identifier.of(blockName); Item item = Registries.ITEM.get(identifier).asItem(); - if (item == null && debugMode.get()) { - ChatUtils.sendMsg(OmegawareAddons.PREFIX.copy() - .append(Text.literal("Item not found: ").formatted(Formatting.RED)) - .append(Text.literal(blockName).formatted(Formatting.WHITE))); + if (item == null) { + 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()) { + Logger.warn("Item already in queue: %s%s", Formatting.WHITE, item.getName().getString()); + } return; } - pathToItemLocation(item, stacks+extraStacks.get()); + LinkedStorage linkedStorage = findItem(item); + if (linkedStorage == null) { + 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); + if (autoReconnect.isActive()) { + autoReconnect.toggle(); + } + + 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 + + ClientPlayNetworkHandler networkHandler = mc.getNetworkHandler(); + if (networkHandler != null) { + networkHandler.getConnection().disconnect(text); + } + } + + return; + } + + itemsToFetch.add(new StorageItem(item, stacks + extraStacks.get(), linkedStorage)); + + pathToLinkedStorage(item, linkedStorage); return; } 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()) { @@ -262,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(); @@ -270,27 +462,24 @@ private void onMessageReceive(ReceiveMessageEvent event) { networkHandler.getConnection().disconnect(text); } } - event.cancel(); return; } msg = msg.substring(2).trim(); // Remove the "> " part - if (msg.startsWith("build")) { + 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); } - event.cancel(); return; } if (msg.startsWith("stop") || msg.startsWith("cancel")) { - buildCommand = msg; + buildCommand = ""; eventQueue.clear(); itemsToFetch.clear(); - event.cancel(); + + Logger.info("Stop received."); } } @@ -311,59 +500,61 @@ private void onInventory(InventoryEvent event) { if (!isActive() || mc.player == null || mc.world == null || mc.currentScreen == null) return; if (!itemsToFetch.isEmpty()) { - 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))); - } - moveSlots(storageItem, mc.player.currentScreenHandler, SlotUtils.MAIN_END); - }); - }); + 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()); + Logger.info(msg); + } + moveSlots(storageItem, mc.player.currentScreenHandler); + })); } if (lastBlockInteractPos == null) return; + BlockEntity blockEntity = mc.world.getBlockEntity(lastBlockInteractPos); + if (blockEntity == null) return; - if (storageLinkMode.get()) { - BlockEntity blockEntity = mc.world.getBlockEntity(lastBlockInteractPos); - if (blockEntity == null) return; + for (LinkedStorage linkedStorage : linkedStorages) { + if (linkedStorage.blockPos.equals(lastBlockInteractPos)) { + lastBlockInteractPos = null; + linkedStorages.remove(linkedStorage); - 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(); + } - LinkedStorage newStorage = indexStorage(mc.player.currentScreenHandler, blockEntity.getPos()); - if (newStorage != null) { - linkedStorages.add(newStorage); - saveLinkedStorages(); - } + return; + } + } - 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()); } } @@ -410,6 +601,7 @@ private void saveLinkedStorages() { private void loadLinkedStorages() { File configFile = OmegawareAddons.GetConfigFile("better-build", "linked_storages.json"); if (!configFile.exists()) { + //noinspection LoggingSimilarMessage OmegawareAddons.LOG.warn("{} not found!", configFile.toPath()); return; } @@ -452,6 +644,45 @@ private void loadLinkedStorages() { } } + private void saveHome() { + File configFile = OmegawareAddons.GetConfigFile("better-build", "home.json"); + + try { + //noinspection ResultOfMethodCallIgnored + configFile.getParentFile().mkdirs(); + + Writer writer = new FileWriter(configFile); + JsonObject payload = new JsonObject(); + + if (home != null) { + payload.addProperty("home", home.asLong()); + } + + writer.append(payload.toString()); + writer.close(); + } catch (Exception ignored) { + OmegawareAddons.LOG.info("Failed to save home to {}", configFile.toPath()); + } + } + + private void loadHome() { + File configFile = OmegawareAddons.GetConfigFile("better-build", "home.json"); + if (!configFile.exists()) { + OmegawareAddons.LOG.warn("{} not found!", configFile.toPath()); + return; + } + + try { + String content = Files.readString(configFile.toPath()); + JsonObject payload = GSON.fromJson(content, JsonObject.class); + if (payload.has("home")) { + home = BlockPos.fromLong(payload.get("home").getAsLong()); + } + } catch (Exception e) { + OmegawareAddons.LOG.error("Failed to load home from {}: {}", configFile.toPath(), e.getMessage()); + } + } + private void updateLinkedStorages() { if (mc.world == null || linkedStorages.isEmpty()) return; @@ -484,16 +715,23 @@ 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()); + - baritone.getCustomGoalProcess().setGoalAndPath(new GoalGetToBlock(blockPos)); + if (!ignoreY.get()) { + baritone.getCustomGoalProcess().setGoalAndPath(new GoalGetToBlock(blockPos)); + } else baritone.getCustomGoalProcess().setGoalAndPath(new GoalGetToBlock(blockPos.withY(mc.player.getBlockY()))); } private LinkedStorage findItem(Item item) { + // Sort the linked storages by distance to the player + if (mc.player == null || mc.world == null) return null; + linkedStorages.sort((a, b) -> { + double distanceA = a.blockPos.getSquaredDistance(mc.player.getBlockPos()); + double distanceB = b.blockPos.getSquaredDistance(mc.player.getBlockPos()); + return Double.compare(distanceA, distanceB); + }); + // Iterate through the linked storages and check if the item is present in any of them for (LinkedStorage linkedStorage : linkedStorages) { for (ItemStack stack : linkedStorage.inventory) { if (stack.getItem() == item) { @@ -505,56 +743,12 @@ private LinkedStorage findItem(Item item) { return null; } - private static class FindResult { - public boolean found; - public LinkedStorage linkedStorage; - - public FindResult(boolean found, LinkedStorage linkedStorage) { - this.found = found; - this.linkedStorage = linkedStorage; - } - } - - private void pathToItemLocation(Item item, @Nullable Integer stacks) { + private void pathToLinkedStorage(Item item, LinkedStorage linkedStorage) { if (mc.player == null || mc.interactionManager == null) return; - if (stacks == null) stacks = 1; // Default to 1 stack if not specified - - 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.info("%sNavigating to storage containing:%s %s", Formatting.GREEN, Formatting.WHITE, item.getName().getString()); - if (disconnectOnError.get()) { - AutoReconnect autoReconnect = Modules.get().get(meteordevelopment.meteorclient.systems.modules.misc.AutoReconnect.class); - if (autoReconnect.isActive()) { - autoReconnect.toggle(); - } - - String prefix = OmegawareAddons.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 - - ClientPlayNetworkHandler networkHandler = mc.getNetworkHandler(); - if (networkHandler != null) { - networkHandler.getConnection().disconnect(text); - } - } - - 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))); - - itemsToFetch.add(new StorageItem(item, stacks, linkedStorage)); - - eventQueue.add(new Event(true, () -> { - pathToPos(linkedStorage.blockPos); - })); + eventQueue.add(new Event(true, () -> pathToPos(linkedStorage.blockPos))); eventQueue.add(new Event(true, () -> { mc.setScreen(null); // Close any open screens to ensure that we can interact with the storage block @@ -568,13 +762,13 @@ private void pathToItemLocation(Item item, @Nullable Integer stacks) { })); } - private void moveSlots(StorageItem storageItem, ScreenHandler handler, int end) { + private void moveSlots(StorageItem storageItem, ScreenHandler handler) { if (mc.player == null) return; boolean initial = true; int count = 0; List grabbedItems = new ArrayList<>(); - for (int i = 0; i < end; i++) { + for (int i = 0; i < SlotUtils.MAIN_END; i++) { if (!handler.getSlot(i).hasStack()) continue; int sleep; @@ -597,26 +791,34 @@ private void moveSlots(StorageItem storageItem, ScreenHandler handler, int end) grabbedItems.add(item); - count++; - InvUtils.shiftClick().slotId(i); - LinkedStorage linkedStorage = storageItem.linkedStorage; linkedStorages.remove(linkedStorage); - linkedStorage.inventory.remove(handler.getSlot(i).getStack()); + int finalI = i; + linkedStorage.inventory.removeIf(itemStack -> itemStack.equals(handler.getSlot(finalI).getStack())); linkedStorages.add(linkedStorage); saveLinkedStorages(); + count++; + InvUtils.shiftClick().slotId(i); + if (count >= storageItem.stacks) { break; } } - itemsToFetch.removeIf(element -> grabbedItems.contains(element.item)); + itemsToFetch.remove(storageItem); - if (!buildCommand.isEmpty()) { - eventQueue.add(new Event(true, () -> { - baritone.getCommandManager().execute(buildCommand); - })); + storageItem.stacks = storageItem.stacks - count; + itemsToFetch.add(storageItem); + + int finalCount = count; + itemsToFetch.removeIf(element -> grabbedItems.contains(element.item) && finalCount >= element.stacks); + + if (!itemsToFetch.isEmpty()) { + eventQueue.clear(); + itemsToFetch.forEach(element -> pathToLinkedStorage(element.item, element.linkedStorage)); + } else if (!buildCommand.isEmpty()) { + eventQueue.add(new Event(true, () -> baritone.getCommandManager().execute(buildCommand))); } } } 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 a252da6..3ebdf16 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 +// } +// } +}