aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/org/chrisoft/trashyaddon/commands/EntityHighlightCommand.java
blob: c29dfa4420ea227c2a8f3da0629cd97a1044dd86 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
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;
            })
        );
    }
}