aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/de/hype/bbsentials/mixins/ClientCommandSourceMixin.java
blob: edbe487f3b81473e4f7dd3573682b92cef24db40 (plain)
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
package de.hype.bbsentials.mixins;

import com.google.common.collect.Lists;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.network.ClientCommandSource;
import net.minecraft.client.network.ClientPlayNetworkHandler;
import net.minecraft.client.network.PlayerListEntry;
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Overwrite;
import org.spongepowered.asm.mixin.Shadow;

import java.util.Collection;
import java.util.Iterator;
import java.util.List;

@Environment(EnvType.CLIENT)
@Mixin(ClientCommandSource.class)
public abstract class ClientCommandSourceMixin {
    @Shadow
    private final ClientPlayNetworkHandler networkHandler;
    private final MinecraftClient client;
    @Final
    private List<PlayerListEntry> playerList;

    /**
     * @return Collection of player names.
     * @author HacktheTime
     * @reason Remove hypixels dummy players from the list.
     * Overwrites the getPlayerNames() method with the new implementation.
     * This method returns a collection of player names from the playerList.
     * This method is now also used by server-side commands.
     */
    @Overwrite
    public Collection<String> getPlayerNames() {
        List<String> list = Lists.newArrayList();
        Iterator var2 = this.networkHandler.getPlayerList().iterator();

        while (var2.hasNext()) {
            PlayerListEntry playerListEntry = (PlayerListEntry) var2.next();
            String playerName = playerListEntry.getProfile().getName();
            if (!playerName.startsWith("!")) {
                list.add(playerName);
            }
        }

        return list;
    }

    public ClientCommandSourceMixin(ClientPlayNetworkHandler networkHandler) {
        this.networkHandler = networkHandler;
        this.client = MinecraftClient.getInstance();
    }
}