aboutsummaryrefslogblamecommitdiff
path: root/src/main/java/org/chrisoft/trashyaddon/commands/EntityHighlightCommand.java
blob: c29dfa4420ea227c2a8f3da0629cd97a1044dd86 (plain) (tree)
















































































                                                                                                                      
package org.chrisoft.trashyaddon.commands;

import meteordevelopment.meteorclient.commands.Command;
import meteordevelopment.meteorclient.utils.render.color.Color;
import net.minecraft.command.CommandSource;
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
import net.minecraft.entity.Entity;
import org.chrisoft.trashyaddon.commands.argument.CEntityArgumentType;
import org.chrisoft.trashyaddon.commands.argument.ColorCodeArgumentType;

import java.util.HashMap;
import java.util.List;
import java.util.UUID;

import static com.mojang.brigadier.Command.SINGLE_SUCCESS;
import static meteordevelopment.meteorclient.MeteorClient.mc;

/*
Usage:
eh <target selector> set <color>  :  Highlight targeted entities with specified color
eh <target selector> remove       :  Remove highlight from targeted entities
eh clear                          :  Remove highlight from all entities
Note: This command pulls settings from your ESP module.
 */

public class EntityHighlightCommand extends Command {
    private final static HashMap<UUID, Color> entityColors = new HashMap<>();

    public static void clearColors() { entityColors.clear(); }
    public static void setEntityColor(Entity e, Color c) {
        entityColors.put(e.getUuid(), c);
    }
    public static void setEntityColors(List<? extends Entity> entities, Color c) {
        for (Entity e : entities)
            setEntityColor(e, c);
    }
    public static void removeEntityColor(Entity e) {
        entityColors.remove(e.getUuid());
    }
    public static void removeEntityColors(List<? extends Entity> entities) {
        for (Entity e : entities)
            removeEntityColor(e);
    }
    public static Color getEntityColor(Entity e) {
        return entityColors.get(e.getUuid());
    }

    public EntityHighlightCommand() {
        super("eh", "Highlight selected entities.");
    }

    @Override
    public void build(LiteralArgumentBuilder<CommandSource> builder) {
        builder.then(
            argument("match", CEntityArgumentType.entities()).then(
                literal("set").then(
                    argument("color", ColorCodeArgumentType.colorCode()).executes(ctx -> {
                        CEntitySelector es = ctx.getArgument("match", CEntitySelector.class);
                        List<? extends Entity> entities = es.getClientSideEntityMatches(mc.world, mc.player.getPos());
                        setEntityColors(entities, ctx.getArgument("color", Color.class));
                        info("Successfully set highlight for " + entities.size() + " entity(ies).");
                        return SINGLE_SUCCESS;
                    }
                ))).then(
                literal("remove").executes(ctx -> {
                    CEntitySelector es = ctx.getArgument("match", CEntitySelector.class);
                    List<? extends Entity> entities = es.getClientSideEntityMatches(mc.world, mc.player.getPos());
                    removeEntityColors(entities);
                    info("Successfully removed highlight for " + entities.size() + " entity(ies).");
                    return SINGLE_SUCCESS;
                })
            )
        ).then(
            literal("clear").executes(ctx -> {
                clearColors();
                info("Successfully removed highlight for all entities.");
                return SINGLE_SUCCESS;
            })
        );
    }
}