aboutsummaryrefslogtreecommitdiffhomepage
path: root/patches/server/0689-Multiple-Entries-with-Scoreboards.patch
blob: a0934c6d89139bbfff083bebf83df1b8611f9bc2 (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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Cryptite <cryptite@gmail.com>
Date: Tue, 21 Sep 2021 18:17:33 -0500
Subject: [PATCH] Multiple Entries with Scoreboards


diff --git a/src/main/java/net/minecraft/network/protocol/game/ClientboundSetPlayerTeamPacket.java b/src/main/java/net/minecraft/network/protocol/game/ClientboundSetPlayerTeamPacket.java
index e9d03ebfbd02a46b0ba274be107e099cc24b59e3..c52b91f5a001924e7a15f246004b6dd294fa0aae 100644
--- a/src/main/java/net/minecraft/network/protocol/game/ClientboundSetPlayerTeamPacket.java
+++ b/src/main/java/net/minecraft/network/protocol/game/ClientboundSetPlayerTeamPacket.java
@@ -51,6 +51,12 @@ public class ClientboundSetPlayerTeamPacket implements Packet<ClientGamePacketLi
         );
     }
 
+    // Paper start - Multiple Entries with Scoreboards
+    public static ClientboundSetPlayerTeamPacket createMultiplePlayerPacket(PlayerTeam team, Collection<String> players, ClientboundSetPlayerTeamPacket.Action operation) {
+        return new ClientboundSetPlayerTeamPacket(team.getName(), operation == ClientboundSetPlayerTeamPacket.Action.ADD ? 3 : 4, Optional.empty(), players);
+    }
+    // Paper end - Multiple Entries with Scoreboards
+
     public ClientboundSetPlayerTeamPacket(FriendlyByteBuf buf) {
         this.name = buf.readUtf();
         this.method = buf.readByte();
diff --git a/src/main/java/net/minecraft/server/ServerScoreboard.java b/src/main/java/net/minecraft/server/ServerScoreboard.java
index c4904b358fc2f493e6a9572a84b8110a927da208..76d67d01388ecc1af6b43212e018edc678e84d72 100644
--- a/src/main/java/net/minecraft/server/ServerScoreboard.java
+++ b/src/main/java/net/minecraft/server/ServerScoreboard.java
@@ -104,6 +104,25 @@ public class ServerScoreboard extends Scoreboard {
         }
     }
 
+    // Paper start - Multiple Entries with Scoreboards
+    public boolean addPlayersToTeam(java.util.Collection<String> players, PlayerTeam team) {
+        boolean anyAdded = false;
+        for (String playerName : players) {
+            if (super.addPlayerToTeam(playerName, team)) {
+                anyAdded = true;
+            }
+        }
+
+        if (anyAdded) {
+            this.broadcastAll(ClientboundSetPlayerTeamPacket.createMultiplePlayerPacket(team, players, ClientboundSetPlayerTeamPacket.Action.ADD));
+            this.setDirty();
+            return true;
+        } else {
+            return false;
+        }
+    }
+    // Paper end - Multiple Entries with Scoreboards
+
     @Override
     public void removePlayerFromTeam(String scoreHolderName, PlayerTeam team) {
         super.removePlayerFromTeam(scoreHolderName, team);
@@ -111,6 +130,17 @@ public class ServerScoreboard extends Scoreboard {
         this.setDirty();
     }
 
+    // Paper start - Multiple Entries with Scoreboards
+    public void removePlayersFromTeam(java.util.Collection<String> players, PlayerTeam team) {
+        for (String playerName : players) {
+            super.removePlayerFromTeam(playerName, team);
+        }
+
+        this.broadcastAll(ClientboundSetPlayerTeamPacket.createMultiplePlayerPacket(team, players, ClientboundSetPlayerTeamPacket.Action.REMOVE));
+        this.setDirty();
+    }
+    // Paper end - Multiple Entries with Scoreboards
+
     @Override
     public void onObjectiveAdded(Objective objective) {
         super.onObjectiveAdded(objective);
diff --git a/src/main/java/org/bukkit/craftbukkit/scoreboard/CraftTeam.java b/src/main/java/org/bukkit/craftbukkit/scoreboard/CraftTeam.java
index 27219bf2f16aed64c78623d44c3cc84aa9f47065..2b335c750ce5f9ccc2651a8701497ca9b8f46704 100644
--- a/src/main/java/org/bukkit/craftbukkit/scoreboard/CraftTeam.java
+++ b/src/main/java/org/bukkit/craftbukkit/scoreboard/CraftTeam.java
@@ -229,6 +229,21 @@ final class CraftTeam extends CraftScoreboardComponent implements Team {
         scoreboard.board.addPlayerToTeam(entry, this.team);
     }
 
+    // Paper start - Multiple Entries with Scoreboards
+    @Override
+    public void addEntities(java.util.Collection<org.bukkit.entity.Entity> entities) throws IllegalStateException, IllegalArgumentException {
+        this.addEntries(entities.stream().map(entity -> ((org.bukkit.craftbukkit.entity.CraftEntity) entity).getHandle().getScoreboardName()).toList());
+    }
+
+    @Override
+    public void addEntries(java.util.Collection<String> entries) throws IllegalStateException, IllegalArgumentException {
+        Preconditions.checkArgument(entries != null, "Entries cannot be null");
+        CraftScoreboard scoreboard = this.checkState();
+
+        ((net.minecraft.server.ServerScoreboard) scoreboard.board).addPlayersToTeam(entries, this.team);
+    }
+    // Paper end - Multiple Entries with Scoreboards
+
     @Override
     public boolean removePlayer(OfflinePlayer player) {
         Preconditions.checkArgument(player != null, "OfflinePlayer cannot be null");
@@ -248,6 +263,28 @@ final class CraftTeam extends CraftScoreboardComponent implements Team {
         return true;
     }
 
+    // Paper start - Multiple Entries with Scoreboards
+    @Override
+    public boolean removeEntities(java.util.Collection<org.bukkit.entity.Entity> entities) throws IllegalStateException, IllegalArgumentException {
+        return this.removeEntries(entities.stream().map(entity -> ((org.bukkit.craftbukkit.entity.CraftEntity) entity).getHandle().getScoreboardName()).toList());
+    }
+
+    @Override
+    public boolean removeEntries(java.util.Collection<String> entries) throws IllegalStateException, IllegalArgumentException {
+        Preconditions.checkArgument(entries != null, "Entry cannot be null");
+        CraftScoreboard scoreboard = this.checkState();
+
+        for (String entry : entries) {
+            if (this.team.getPlayers().contains(entry)) {
+                ((net.minecraft.server.ServerScoreboard) scoreboard.board).removePlayersFromTeam(entries, this.team);
+                return true;
+            }
+        }
+
+        return false;
+    }
+    // Paper end - Multiple Entries with Scoreboards
+
     @Override
     public boolean hasPlayer(OfflinePlayer player) throws IllegalArgumentException, IllegalStateException {
         Preconditions.checkArgument(player != null, "OfflinePlayer cannot be null");