Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
import meteordevelopment.meteorclient.utils.misc.Version;
import meteordevelopment.meteorclient.utils.misc.input.KeyAction;
import meteordevelopment.meteorclient.utils.misc.input.KeyBinds;
import meteordevelopment.meteorclient.utils.misc.text.MeteorTranslatableTextComponent;
import meteordevelopment.meteorclient.utils.misc.text.MeteorTranslatableTextContent;
import meteordevelopment.meteorclient.utils.network.OnlinePlayers;
import meteordevelopment.orbit.EventBus;
import meteordevelopment.orbit.EventHandler;
Expand Down Expand Up @@ -201,10 +201,10 @@ public static Identifier identifier(String path) {
}

public static MutableText translatable(String key, Object... args) {
return MutableText.of(new MeteorTranslatableTextComponent(key, args));
return MutableText.of(new MeteorTranslatableTextContent(key, args));
}

public static MutableText translatable(String key, String fallback, Object... args) {
return MutableText.of(new MeteorTranslatableTextComponent(key, fallback, args));
return MutableText.of(new MeteorTranslatableTextContent(key, fallback, args));
}
}
35 changes: 18 additions & 17 deletions src/main/java/meteordevelopment/meteorclient/commands/Command.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,8 @@
import com.mojang.brigadier.builder.RequiredArgumentBuilder;
import meteordevelopment.meteorclient.MeteorClient;
import meteordevelopment.meteorclient.systems.config.Config;
import meteordevelopment.meteorclient.utils.Utils;
import meteordevelopment.meteorclient.utils.misc.MeteorTranslations;
import meteordevelopment.meteorclient.utils.player.ChatUtils;
import meteordevelopment.meteorclient.utils.misc.text.MessageBuilder;
import meteordevelopment.meteorclient.utils.misc.text.MessageKind;
import net.minecraft.client.MinecraftClient;
import net.minecraft.command.CommandRegistryAccess;
import net.minecraft.command.CommandSource;
Expand All @@ -30,13 +29,11 @@ public abstract class Command {
protected static final MinecraftClient mc = MeteorClient.mc;

private final String name;
private final String title;
private final List<String> aliases;
public final String translationKey;

public Command(String name, String... aliases) {
this.name = name;
this.title = Utils.nameToTitle(name);
this.aliases = List.of(aliases);
this.translationKey = "command." + name;
}
Expand Down Expand Up @@ -85,24 +82,24 @@ public String toString(String... args) {
return base.toString();
}

public void info(Text message) {
ChatUtils.forceNextPrefixClass(getClass());
ChatUtils.sendMsg(title, message);
public MessageBuilder info(Text message) {
return MessageBuilder.create().setSource(this).setTranslationContext(this.translationKey)
.body(message).setKind(MessageKind.Info);
}

public void info(String message, Object... args) {
ChatUtils.forceNextPrefixClass(getClass());
ChatUtils.infoPrefix(title, MeteorTranslations.translate(translationKey + ".info." + message, message, args));
public MessageBuilder info(String message, Object... args) {
return MessageBuilder.create().setSource(this).setTranslationContext(this.translationKey)
.body(message, args).setKind(MessageKind.Info);
}

public void warning(String message, Object... args) {
ChatUtils.forceNextPrefixClass(getClass());
ChatUtils.warningPrefix(title, MeteorTranslations.translate(translationKey + ".warning." + message, message, args));
public MessageBuilder warning(String message, Object... args) {
return MessageBuilder.create().setSource(this).setTranslationContext(this.translationKey)
.body(message, args).setKind(MessageKind.Warning);
}

public void error(String message, Object... args) {
ChatUtils.forceNextPrefixClass(getClass());
ChatUtils.errorPrefix(title, MeteorTranslations.translate(translationKey + ".error." + message, message, args));
public MessageBuilder error(String message, Object... args) {
return MessageBuilder.create().setSource(this).setTranslationContext(this.translationKey)
.body(message, args).setKind(MessageKind.Error);
}

public MutableText translatable(String string, Object... args) {
Expand All @@ -112,4 +109,8 @@ public MutableText translatable(String string, Object... args) {
public MutableText translatable(String string, String fallback, Object... args) {
return MeteorClient.translatable(translationKey + "." + string, fallback, args);
}

public MutableText getTitle() {
return MeteorClient.translatable(translationKey);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@ public void build(LiteralArgumentBuilder<CommandSource> builder) {
Module module = context.getArgument("module", Module.class);
Modules.get().setModuleToBind(module);
Modules.get().awaitKeyRelease();
module.info("Press a key to bind the module to.");

this.info("press_key").prefix(module.getTitleText()).send();

return SINGLE_SUCCESS;
}));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import meteordevelopment.meteorclient.commands.Command;
import meteordevelopment.meteorclient.systems.modules.Module;
import meteordevelopment.meteorclient.systems.modules.Modules;
import meteordevelopment.meteorclient.utils.player.ChatUtils;
import meteordevelopment.meteorclient.utils.misc.text.MessageBuilder;
import net.minecraft.command.CommandSource;
import net.minecraft.text.HoverEvent;
import net.minecraft.text.MutableText;
Expand All @@ -31,7 +31,7 @@ public void build(LiteralArgumentBuilder<CommandSource> builder) {
.filter(module -> module.keybind.isSet())
.toList();

ChatUtils.info("--- Bound Modules ((highlight)%d(default)) ---", modules.size());
this.info("bound_modules", MessageBuilder.highlight(modules.size())).send();

for (Module module : modules) {
HoverEvent hoverEvent = new HoverEvent.ShowText(getTooltip(module));
Expand All @@ -47,7 +47,7 @@ public void build(LiteralArgumentBuilder<CommandSource> builder) {
key.setStyle(key.getStyle().withHoverEvent(hoverEvent));
text.append(key.formatted(Formatting.GRAY));

ChatUtils.sendMsg(text);
this.info(text).send();
}

return SINGLE_SUCCESS;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import meteordevelopment.meteorclient.commands.Command;
import meteordevelopment.meteorclient.commands.Commands;
import meteordevelopment.meteorclient.systems.config.Config;
import meteordevelopment.meteorclient.utils.Utils;
import meteordevelopment.meteorclient.utils.misc.text.MessageBuilder;
import meteordevelopment.meteorclient.utils.player.ChatUtils;
import net.minecraft.command.CommandSource;
import net.minecraft.text.ClickEvent;
Expand All @@ -26,21 +26,21 @@ public CommandsCommand() {
@Override
public void build(LiteralArgumentBuilder<CommandSource> builder) {
builder.executes(context -> {
ChatUtils.info("--- Commands ((highlight)%d(default)) ---", Commands.COMMANDS.size());
this.info("commands", MessageBuilder.highlight(Commands.COMMANDS.size())).send();

MutableText commands = Text.literal("");
MutableText commands = Text.empty();
Commands.COMMANDS.forEach(command -> commands.append(getCommandText(command)));
ChatUtils.sendMsg(commands);
this.info(commands).send();

return SINGLE_SUCCESS;
});
}

private MutableText getCommandText(Command command) {
// Hover tooltip
MutableText tooltip = Text.literal("");
MutableText tooltip = Text.empty();

tooltip.append(Text.literal(Utils.nameToTitle(command.getName())).formatted(Formatting.BLUE, Formatting.BOLD)).append("\n");
tooltip.append(command.getTitle().formatted(Formatting.BLUE, Formatting.BOLD)).append("\n");

MutableText aliases = Text.literal(Config.get().prefix.get() + command.getName());
if (!command.getAliases().isEmpty()) {
Expand All @@ -56,7 +56,7 @@ private MutableText getCommandText(Command command) {
tooltip.append(command.translatable("description")).formatted(Formatting.WHITE);

// Text
MutableText text = Text.literal(Utils.nameToTitle(command.getName()));
MutableText text = command.getTitle();
if (command != Commands.COMMANDS.getLast())
text.append(Text.literal(", ").formatted(Formatting.GRAY));
text.setStyle(text
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import com.mojang.brigadier.arguments.IntegerArgumentType;
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
import com.mojang.brigadier.exceptions.SimpleCommandExceptionType;
import meteordevelopment.meteorclient.MeteorClient;
import meteordevelopment.meteorclient.commands.Command;
import meteordevelopment.meteorclient.systems.modules.Modules;
import meteordevelopment.meteorclient.systems.modules.movement.NoFall;
Expand All @@ -18,7 +19,7 @@
import net.minecraft.util.math.Vec3d;

public class DamageCommand extends Command {
private final static SimpleCommandExceptionType INVULNERABLE = new SimpleCommandExceptionType(Text.literal("You are invulnerable."));
private final static SimpleCommandExceptionType INVULNERABLE = new SimpleCommandExceptionType(MeteorClient.translatable("command.damage.exception.invulnerable"));

public DamageCommand() {
super("damage", "dmg");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public DisconnectCommand() {
@Override
public void build(LiteralArgumentBuilder<CommandSource> builder) {
builder.executes(context -> {
mc.player.networkHandler.onDisconnect(new DisconnectS2CPacket(translatable("disconnection_message", Formatting.GRAY, Formatting.BLUE, Formatting.GRAY)));
mc.player.networkHandler.onDisconnect(new DisconnectS2CPacket(translatable("disconnection_message", this.getTitle().formatted(Formatting.BLUE)).formatted(Formatting.GRAY)));
return SINGLE_SUCCESS;
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@
import net.minecraft.item.Items;

public class DropCommand extends Command {
private static final SimpleCommandExceptionType NOT_SPECTATOR = new SimpleCommandExceptionType(MeteorClient.translatable("meteor.command.drop.exception.not_spectator"));
private static final SimpleCommandExceptionType NO_SUCH_ITEM = new SimpleCommandExceptionType(MeteorClient.translatable("meteor.command.drop.exception.no_such_item"));
private static final SimpleCommandExceptionType NOT_SPECTATOR = new SimpleCommandExceptionType(MeteorClient.translatable("command.drop.exception.not_spectator"));
private static final SimpleCommandExceptionType NO_SUCH_ITEM = new SimpleCommandExceptionType(MeteorClient.translatable("command.drop.exception.no_such_item"));

public DropCommand() {
super("drop");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@
import java.util.function.ToIntFunction;

public class EnchantCommand extends Command {
private static final SimpleCommandExceptionType NOT_IN_CREATIVE = new SimpleCommandExceptionType(MeteorClient.translatable("meteor.command.enchant.exception.not_in_creative"));
private static final SimpleCommandExceptionType NOT_HOLDING_ITEM = new SimpleCommandExceptionType(MeteorClient.translatable("meteor.command.enchant.exception.not_holding_item"));
private static final SimpleCommandExceptionType NOT_IN_CREATIVE = new SimpleCommandExceptionType(MeteorClient.translatable("command.enchant.exception.not_in_creative"));
private static final SimpleCommandExceptionType NOT_HOLDING_ITEM = new SimpleCommandExceptionType(MeteorClient.translatable("command.enchant.exception.not_holding_item"));

public EnchantCommand() {
super("enchant");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import meteordevelopment.meteorclient.systems.modules.player.FakePlayer;
import meteordevelopment.meteorclient.utils.entity.fakeplayer.FakePlayerEntity;
import meteordevelopment.meteorclient.utils.entity.fakeplayer.FakePlayerManager;
import meteordevelopment.meteorclient.utils.misc.text.MessageBuilder;
import net.minecraft.command.CommandSource;

public class FakePlayerCommand extends Command {
Expand Down Expand Up @@ -42,12 +43,12 @@ public void build(LiteralArgumentBuilder<CommandSource> builder) {
.executes(context -> {
FakePlayerEntity fp = FakePlayerArgumentType.get(context);
if (fp == null || !FakePlayerManager.contains(fp)) {
error("not_found");
this.error("not_found").send();
return SINGLE_SUCCESS;
}

FakePlayerManager.remove(fp);
info("removed", fp.getName().getString());
this.info("removed", MessageBuilder.highlight(fp)).send();

return SINGLE_SUCCESS;
})
Expand All @@ -63,8 +64,8 @@ public void build(LiteralArgumentBuilder<CommandSource> builder) {

builder.then(literal("list")
.executes(context -> {
info("--- Fake Players ((highlight)%s(default)) ---", FakePlayerManager.count());
FakePlayerManager.forEach(fp -> info("(highlight)%s".formatted(fp.getName().getString())));
this.info("fake_players", MessageBuilder.highlight(FakePlayerManager.count())).send();
FakePlayerManager.forEach(fp -> this.info(MessageBuilder.highlight(fp)).send());
return SINGLE_SUCCESS;
})
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,8 @@
import meteordevelopment.meteorclient.commands.arguments.PlayerListEntryArgumentType;
import meteordevelopment.meteorclient.systems.friends.Friend;
import meteordevelopment.meteorclient.systems.friends.Friends;
import meteordevelopment.meteorclient.utils.player.ChatUtils;
import meteordevelopment.meteorclient.utils.misc.text.MessageBuilder;
import net.minecraft.command.CommandSource;
import net.minecraft.util.Formatting;

public class FriendsCommand extends Command {
public FriendsCommand() {
Expand All @@ -30,9 +29,9 @@ public void build(LiteralArgumentBuilder<CommandSource> builder) {
Friend friend = new Friend(profile.name(), profile.id());

if (Friends.get().add(friend)) {
ChatUtils.sendMsg(friend.hashCode(), Formatting.GRAY, "Added (highlight)%s (default)to friends.".formatted(friend.getName()));
this.info("added", friend.getName()).setId(friend.hashCode()).send();
}
else error("Already friends with that player.");
else error("already_friends");

return SINGLE_SUCCESS;
})
Expand All @@ -44,25 +43,24 @@ public void build(LiteralArgumentBuilder<CommandSource> builder) {
.executes(context -> {
Friend friend = FriendArgumentType.get(context);
if (friend == null) {
error("Not friends with that player.");
this.error("not_friends").send();
return SINGLE_SUCCESS;
}

if (Friends.get().remove(friend)) {
ChatUtils.sendMsg(friend.hashCode(), Formatting.GRAY, "Removed (highlight)%s (default)from friends.".formatted(friend.getName()));
this.info("removed", friend.getName()).setId(friend.hashCode()).send();
}
else error("Failed to remove that friend.");
else this.error("failed").send();

return SINGLE_SUCCESS;
})
)
);

builder.then(literal("list").executes(context -> {
info("--- Friends ((highlight)%s(default)) ---", Friends.get().count());
Friends.get().forEach(friend -> ChatUtils.info("(highlight)%s".formatted(friend.getName())));
return SINGLE_SUCCESS;
})
);
this.info("friends", MessageBuilder.highlight(Friends.get().count())).send();
Friends.get().forEach(friend -> this.info(MessageBuilder.highlight(friend.getName())).send());
return SINGLE_SUCCESS;
}));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
import net.minecraft.network.packet.c2s.play.CreativeInventoryActionC2SPacket;

public class GiveCommand extends Command {
private final static SimpleCommandExceptionType NOT_IN_CREATIVE = new SimpleCommandExceptionType(MeteorClient.translatable("meteor.command.give.exception.not_in_creative"));
private final static SimpleCommandExceptionType NO_SPACE = new SimpleCommandExceptionType(MeteorClient.translatable("meteor.command.give.exception.no_space"));
private final static SimpleCommandExceptionType NOT_IN_CREATIVE = new SimpleCommandExceptionType(MeteorClient.translatable("command.give.exception.not_in_creative"));
private final static SimpleCommandExceptionType NO_SPACE = new SimpleCommandExceptionType(MeteorClient.translatable("command.give.exception.no_space"));

public GiveCommand() {
super("give");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,11 @@
import meteordevelopment.meteorclient.commands.Command;
import meteordevelopment.meteorclient.events.world.TickEvent;
import meteordevelopment.meteorclient.mixin.KeyBindingAccessor;
import meteordevelopment.meteorclient.utils.misc.text.MessageBuilder;
import meteordevelopment.orbit.EventHandler;
import net.minecraft.client.option.KeyBinding;
import net.minecraft.client.resource.language.I18n;
import net.minecraft.command.CommandSource;
import net.minecraft.text.Text;

import java.util.ArrayList;
import java.util.List;
Expand Down Expand Up @@ -80,32 +81,38 @@ public void build(LiteralArgumentBuilder<CommandSource> builder) {
}

builder.then(literal("clear").executes(ctx -> {
if (activeHandlers.isEmpty()) warning("no_handlers");
if (activeHandlers.isEmpty()) this.warning("no_handlers").send();
else {
info("cleared_handlers");
this.info("cleared_handlers").send();
activeHandlers.forEach(MeteorClient.EVENT_BUS::unsubscribe);
activeHandlers.clear();
}
return SINGLE_SUCCESS;
}));

builder.then(literal("list").executes(ctx -> {
if (activeHandlers.isEmpty()) warning("no_handlers");
if (activeHandlers.isEmpty()) this.warning("no_handlers").send();
else {
info("");
this.info("active_handlers").send();
for (int i = 0; i < activeHandlers.size(); i++) {
KeypressHandler handler = activeHandlers.get(i);
info("keypress_handler", i, I18n.translate(handler.key.getId()), handler.ticks, handler.totalTicks);
this.info(
"keypress_handler",
MessageBuilder.highlight(i),
MessageBuilder.highlight(Text.translatable(handler.key.getId())),
MessageBuilder.highlight(handler.ticks),
MessageBuilder.highlight(handler.key.getId())
).send();
}
}
return SINGLE_SUCCESS;
}));

builder.then(literal("remove").then(argument("index", IntegerArgumentType.integer(0)).executes(ctx -> {
int index = IntegerArgumentType.getInteger(ctx, "index");
if (index >= activeHandlers.size()) warning("out_of_range");
if (index >= activeHandlers.size()) this.warning("out_of_range").send();
else {
info("removed_handler");
this.info("removed_handler").send();
MeteorClient.EVENT_BUS.unsubscribe(activeHandlers.get(index));
activeHandlers.remove(index);
}
Expand Down
Loading
Loading