Skip to content

Commit 4fb291c

Browse files
committed
Convert client brands & mods metadata to be a count-based system
1 parent 3a749e7 commit 4fb291c

File tree

15 files changed

+61
-48
lines changed

15 files changed

+61
-48
lines changed

bukkit/src/main/java/com/lunarclient/apollo/listener/ApolloMetadataListener.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,9 @@ private void registerBrandListener() {
9494

9595
private void collectBrand(String brand) {
9696
BukkitMetadataManager manager = (BukkitMetadataManager) ApolloManager.getMetadataManager();
97-
manager.getClientBrands().add(brand);
97+
Map<String, Integer> brands = manager.getClientBrands();
98+
99+
brands.put(brand, brands.getOrDefault(brand, 0) + 1);
98100
}
99101

100102
}

bukkit/src/main/java/com/lunarclient/apollo/metadata/BukkitMetadata.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525

2626
import com.lunarclient.apollo.stats.metadata.PlatformMetadata;
2727
import java.util.Map;
28-
import java.util.Set;
2928
import lombok.Builder;
3029
import lombok.ToString;
3130

@@ -41,11 +40,12 @@ public class BukkitMetadata extends PlatformMetadata {
4140
/**
4241
* Tracks client brands sent by the players.
4342
*
44-
* <p>A {@link Set} of {@link String} client brands.</p>
43+
* <p>Represents a {@link Map} of {@link String} client brand as a key
44+
* and {@link Integer} count of how many times that brand has been reported.</p>
4545
*
4646
* @since 1.1.9
4747
*/
48-
private final Set<String> clientBrands;
48+
private final Map<String, Integer> clientBrands;
4949

5050
/**
5151
* Tracks the total number of resource pack status events received.

bukkit/src/main/java/com/lunarclient/apollo/metadata/BukkitMetadataManager.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,7 @@
2626
import com.lunarclient.apollo.stats.metadata.ApolloMetadataManager;
2727
import com.lunarclient.apollo.stats.metadata.PlatformMetadata;
2828
import java.util.HashMap;
29-
import java.util.HashSet;
3029
import java.util.Map;
31-
import java.util.Set;
3230
import lombok.Getter;
3331

3432
/**
@@ -39,13 +37,13 @@
3937
@Getter
4038
public class BukkitMetadataManager implements ApolloMetadataManager {
4139

42-
private final Set<String> clientBrands = new HashSet<>();
40+
private final Map<String, Integer> clientBrands = new HashMap<>();
4341
private final Map<String, Integer> resourcePackStatuses = new HashMap<>();
4442

4543
@Override
4644
public PlatformMetadata extract() {
4745
return BukkitMetadata.builder()
48-
.clientBrands(new HashSet<>(this.clientBrands))
46+
.clientBrands(new HashMap<>(this.clientBrands))
4947
.resourcePackStatuses(new HashMap<>(this.resourcePackStatuses))
5048
.build();
5149
}

bungee/src/main/java/com/lunarclient/apollo/listener/ApolloMetadataListener.java

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
import java.io.DataInputStream;
3333
import java.io.IOException;
3434
import java.net.InetSocketAddress;
35+
import java.util.Map;
3536
import net.md_5.bungee.api.ProxyServer;
3637
import net.md_5.bungee.api.connection.PendingConnection;
3738
import net.md_5.bungee.api.connection.ProxiedPlayer;
@@ -129,7 +130,9 @@ public void onPreLogin(PreLoginEvent event) {
129130

130131
private void collectBrand(String brand) {
131132
BungeeMetadataManager manager = (BungeeMetadataManager) ApolloManager.getMetadataManager();
132-
manager.getClientBrands().add(brand);
133+
Map<String, Integer> brands = manager.getClientBrands();
134+
135+
brands.put(brand, brands.getOrDefault(brand, 0) + 1);
133136
}
134137

135138
private void handleFml(byte[] data) {
@@ -142,14 +145,16 @@ private void handleFml(byte[] data) {
142145
return;
143146
}
144147

145-
int count = ByteBufUtil.readVarInt(in);
148+
BungeeMetadataManager manager = (BungeeMetadataManager) ApolloManager.getMetadataManager();
149+
Map<String, Integer> mods = manager.getMods();
146150

151+
int count = ByteBufUtil.readVarInt(in);
147152
for (int i = 0; i < count; i++) {
148153
String modId = ByteBufUtil.readString(in);
149154
String version = ByteBufUtil.readString(in);
155+
String key = modId + ":" + version;
150156

151-
BungeeMetadataManager manager = (BungeeMetadataManager) ApolloManager.getMetadataManager();
152-
manager.getMods().put(modId, version);
157+
mods.put(key, mods.getOrDefault(key, 0) + 1);
153158
}
154159
} catch (Exception ignored) {
155160
}

bungee/src/main/java/com/lunarclient/apollo/metadata/BungeeMetadata.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,21 +41,22 @@ public class BungeeMetadata extends PlatformMetadata {
4141
/**
4242
* Tracks client brands sent by the players.
4343
*
44-
* <p>A {@link Set} of {@link String} client brands.</p>
44+
* <p>Represents a {@link Map} of {@link String} client brand as a key
45+
* and {@link Integer} count of how many times that brand has been reported.</p>
4546
*
4647
* @since 1.1.9
4748
*/
48-
private final Set<String> clientBrands;
49+
private final Map<String, Integer> clientBrands;
4950

5051
/**
5152
* Tracks forge mods sent with the forge handshake.
5253
*
53-
* <p>A {@link Map} of {@link String} mod id
54-
* as a key and {@link String} version as value.</p>
54+
* <p>A {@link Map} of {@link String} mod info in the format: <code>id:version</code>
55+
* as a key and {@link Integer} count of how many times that mod has been reported.</p>
5556
*
5657
* @since 1.1.9
5758
*/
58-
private final Map<String, String> mods;
59+
private final Map<String, Integer> mods;
5960

6061
/**
6162
* Tracks the server IP and port the player used to connect.

bungee/src/main/java/com/lunarclient/apollo/metadata/BungeeMetadataManager.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,14 +39,14 @@
3939
@Getter
4040
public class BungeeMetadataManager implements ApolloMetadataManager {
4141

42-
private final Set<String> clientBrands = new HashSet<>();
43-
private final Map<String, String> mods = new HashMap<>();
42+
private final Map<String, Integer> clientBrands = new HashMap<>();
43+
private final Map<String, Integer> mods = new HashMap<>();
4444
private final Set<String> serverAddress = new HashSet<>();
4545

4646
@Override
4747
public PlatformMetadata extract() {
4848
return BungeeMetadata.builder()
49-
.clientBrands(new HashSet<>(this.clientBrands))
49+
.clientBrands(new HashMap<>(this.clientBrands))
5050
.mods(new HashMap<>(this.mods))
5151
.serverAddress(new HashSet<>(this.serverAddress))
5252
.build();

folia/src/main/java/com/lunarclient/apollo/listener/ApolloMetadataListener.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,9 @@ private void onPlayerJoin(PlayerJoinEvent event) {
7070
}
7171

7272
FoliaMetadataManager manager = (FoliaMetadataManager) ApolloManager.getMetadataManager();
73-
manager.getClientBrands().add(brand);
73+
Map<String, Integer> brands = manager.getClientBrands();
74+
75+
brands.put(brand, brands.getOrDefault(brand, 0) + 1);
7476
}, 20L * 3);
7577
}
7678

folia/src/main/java/com/lunarclient/apollo/metadata/FoliaMetadata.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525

2626
import com.lunarclient.apollo.stats.metadata.PlatformMetadata;
2727
import java.util.Map;
28-
import java.util.Set;
2928
import lombok.Builder;
3029
import lombok.ToString;
3130

@@ -41,11 +40,12 @@ public class FoliaMetadata extends PlatformMetadata {
4140
/**
4241
* Tracks client brands sent by the players.
4342
*
44-
* <p>A {@link Set} of {@link String} client brands.</p>
43+
* <p>Represents a {@link Map} of {@link String} client brand as a key
44+
* and {@link Integer} count of how many times that brand has been reported.</p>
4545
*
4646
* @since 1.1.9
4747
*/
48-
private final Set<String> clientBrands;
48+
private final Map<String, Integer> clientBrands;
4949

5050
/**
5151
* Tracks the total number of resource pack status events received.

folia/src/main/java/com/lunarclient/apollo/metadata/FoliaMetadataManager.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,7 @@
2626
import com.lunarclient.apollo.stats.metadata.ApolloMetadataManager;
2727
import com.lunarclient.apollo.stats.metadata.PlatformMetadata;
2828
import java.util.HashMap;
29-
import java.util.HashSet;
3029
import java.util.Map;
31-
import java.util.Set;
3230
import java.util.concurrent.ConcurrentHashMap;
3331
import lombok.Getter;
3432

@@ -40,13 +38,13 @@
4038
@Getter
4139
public class FoliaMetadataManager implements ApolloMetadataManager {
4240

43-
private final Set<String> clientBrands = ConcurrentHashMap.newKeySet();
41+
private final Map<String, Integer> clientBrands = new ConcurrentHashMap<>();
4442
private final Map<String, Integer> resourcePackStatuses = new ConcurrentHashMap<>();
4543

4644
@Override
4745
public PlatformMetadata extract() {
4846
return FoliaMetadata.builder()
49-
.clientBrands(new HashSet<>(this.clientBrands))
47+
.clientBrands(new HashMap<>(this.clientBrands))
5048
.resourcePackStatuses(new HashMap<>(this.resourcePackStatuses))
5149
.build();
5250
}

minestom/src/main/java/com/lunarclient/apollo/listener/ApolloMetadataListener.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,11 @@ private void onPlayerPluginMessage(PlayerPluginMessageEvent event) {
6767
}
6868

6969
ByteBuffer buffer = ByteBuffer.wrap(event.getMessage());
70+
String brand = ByteBufUtil.readString(buffer);
7071
MinestomMetadataManager manager = (MinestomMetadataManager) ApolloManager.getMetadataManager();
71-
manager.getClientBrands().add(ByteBufUtil.readString(buffer));
72+
Map<String, Integer> brands = manager.getClientBrands();
73+
74+
brands.put(brand, brands.getOrDefault(brand, 0) + 1);
7275
}
7376

7477
}

0 commit comments

Comments
 (0)