aboutsummaryrefslogtreecommitdiffhomepage
path: root/patch-remap/mache-vineflower/net/minecraft/server/commands/ListPlayersCommand.java.patch
blob: f1123c53ed36f15998fdee74d2f1d659b9ac7f89 (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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
--- a/net/minecraft/server/commands/ListPlayersCommand.java
+++ b/net/minecraft/server/commands/ListPlayersCommand.java
@@ -1,11 +1,10 @@
 package net.minecraft.server.commands;
 
 import com.mojang.brigadier.CommandDispatcher;
-import com.mojang.brigadier.context.CommandContext;
+import com.mojang.brigadier.builder.LiteralArgumentBuilder;
 import java.util.List;
 import java.util.function.Function;
 import net.minecraft.commands.CommandSourceStack;
-import net.minecraft.commands.Commands;
 import net.minecraft.network.chat.Component;
 import net.minecraft.network.chat.ComponentUtils;
 import net.minecraft.server.level.ServerPlayer;
@@ -13,12 +12,15 @@
 import net.minecraft.world.entity.player.Player;
 
 public class ListPlayersCommand {
+
+    public ListPlayersCommand() {}
+
     public static void register(CommandDispatcher<CommandSourceStack> dispatcher) {
-        dispatcher.register(
-            Commands.literal("list")
-                .executes(context -> listPlayers(context.getSource()))
-                .then(Commands.literal("uuids").executes(context -> listPlayersWithUuids(context.getSource())))
-        );
+        dispatcher.register((LiteralArgumentBuilder) ((LiteralArgumentBuilder) net.minecraft.commands.Commands.literal("list").executes((commandcontext) -> {
+            return listPlayers((CommandSourceStack) commandcontext.getSource());
+        })).then(net.minecraft.commands.Commands.literal("uuids").executes((commandcontext) -> {
+            return listPlayersWithUuids((CommandSourceStack) commandcontext.getSource());
+        })));
     }
 
     private static int listPlayers(CommandSourceStack source) {
@@ -26,16 +28,26 @@
     }
 
     private static int listPlayersWithUuids(CommandSourceStack source) {
-        return format(
-            source, player -> Component.translatable("commands.list.nameAndId", player.getName(), Component.translationArg(player.getGameProfile().getId()))
-        );
+        return format(source, (entityplayer) -> {
+            return Component.translatable("commands.list.nameAndId", entityplayer.getName(), Component.translationArg(entityplayer.getGameProfile().getId()));
+        });
     }
 
     private static int format(CommandSourceStack source, Function<ServerPlayer, Component> nameExtractor) {
-        PlayerList playerList = source.getServer().getPlayerList();
-        List<ServerPlayer> players = playerList.getPlayers();
-        Component component = ComponentUtils.formatList(players, nameExtractor);
-        source.sendSuccess(() -> Component.translatable("commands.list.players", players.size(), playerList.getMaxPlayers(), component), false);
-        return players.size();
+        PlayerList playerlist = source.getServer().getPlayerList();
+        // CraftBukkit start
+        List<ServerPlayer> players = playerlist.getPlayers();
+        if (source.getBukkitSender() instanceof org.bukkit.entity.Player) {
+            org.bukkit.entity.Player sender = (org.bukkit.entity.Player) source.getBukkitSender();
+            players = players.stream().filter((ep) -> sender.canSee(ep.getBukkitEntity())).collect(java.util.stream.Collectors.toList());
+        }
+        List<ServerPlayer> list = players;
+        // CraftBukkit end
+        Component ichatbasecomponent = ComponentUtils.formatList(list, nameExtractor);
+
+        source.sendSuccess(() -> {
+            return Component.translatable("commands.list.players", list.size(), playerlist.getMaxPlayers(), ichatbasecomponent);
+        }, false);
+        return list.size();
     }
 }