Skip to content

Commit 87ffa56

Browse files
committed
Remove scores on 1.20.3 clients (closes #41)
1 parent 8c86668 commit 87ffa56

File tree

3 files changed

+18
-17
lines changed

3 files changed

+18
-17
lines changed

README.md

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,10 @@
44
[![Maven Central](https://img.shields.io/maven-central/v/fr.mrmicky/fastboard.svg?label=Maven%20Central)](https://central.sonatype.com/artifact/fr.mrmicky/fastboard)
55
[![Discord](https://img.shields.io/discord/390919659874156560.svg?colorB=5865f2&label=Discord&logo=discord&logoColor=white)](https://discord.gg/q9UwaBT)
66

7-
Lightweight packet-based scoreboard API for Bukkit plugins, with 1.7.10 to 1.20 support.
7+
Lightweight packet-based scoreboard API for Bukkit plugins, with 1.7.10 to 1.20.x support.
88

9-
⚠️ To use FastBoard on a 1.8 server, the server must be on 1.8.8.
9+
> [!IMPORTANT]
10+
> To use FastBoard on a 1.8 server, the server must be on 1.8.8.
1011
1112
## Features
1213

@@ -20,6 +21,7 @@ Lightweight packet-based scoreboard API for Bukkit plugins, with 1.7.10 to 1.20
2021
* Supports up to 30 characters per line on 1.12.2 and below
2122
* No character limit on 1.13 and higher
2223
* Supports hex colors on 1.16 and higher
24+
* No scoreboard scores on 1.20.3 and higher
2325
* [Adventure](https://github.com/KyoriPowered/adventure) components support
2426

2527
## Installation
@@ -57,12 +59,13 @@ Lightweight packet-based scoreboard API for Bukkit plugins, with 1.7.10 to 1.20
5759
<dependency>
5860
<groupId>fr.mrmicky</groupId>
5961
<artifactId>fastboard</artifactId>
60-
<version>2.0.1</version>
62+
<version>2.0.2</version>
6163
</dependency>
6264
</dependencies>
6365
```
6466

65-
When using Maven, make sure to build directly with Maven and not with your IDE configuration (on IntelliJ IDEA: in the `Maven` tab on the right, in `Lifecycle`, use `package`).
67+
> [!NOTE]
68+
> When using Maven, make sure to build directly with Maven and not with your IDE configuration (on IntelliJ IDEA: in the `Maven` tab on the right, in `Lifecycle`, use `package`).
6669
6770
### Gradle
6871

@@ -76,7 +79,7 @@ repositories {
7679
}
7780
7881
dependencies {
79-
implementation 'fr.mrmicky:fastboard:2.0.1'
82+
implementation 'fr.mrmicky:fastboard:2.0.2'
8083
}
8184
8285
shadowJar {

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
<groupId>fr.mrmicky</groupId>
88
<artifactId>fastboard</artifactId>
9-
<version>2.0.1</version>
9+
<version>2.0.2</version>
1010

1111
<name>FastBoard</name>
1212
<description>Lightweight packet-based scoreboard API for Bukkit plugins.</description>

src/main/java/fr/mrmicky/fastboard/FastBoardBase.java

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -32,15 +32,7 @@
3232
import java.lang.reflect.Field;
3333
import java.lang.reflect.Method;
3434
import java.lang.reflect.Modifier;
35-
import java.util.ArrayList;
36-
import java.util.Arrays;
37-
import java.util.Collection;
38-
import java.util.Collections;
39-
import java.util.HashMap;
40-
import java.util.List;
41-
import java.util.Map;
42-
import java.util.Objects;
43-
import java.util.Optional;
35+
import java.util.*;
4436
import java.util.concurrent.ThreadLocalRandom;
4537
import java.util.stream.Stream;
4638

@@ -51,7 +43,7 @@
5143
* The project is on <a href="https://github.com/MrMicky-FR/FastBoard">GitHub</a>.
5244
*
5345
* @author MrMicky
54-
* @version 2.0.1
46+
* @version 2.0.2
5547
*/
5648
public abstract class FastBoardBase<T> {
5749

@@ -78,6 +70,7 @@ public abstract class FastBoardBase<T> {
7870
private static final Class<?> DISPLAY_SLOT_TYPE;
7971
private static final Class<?> ENUM_SB_HEALTH_DISPLAY;
8072
private static final Class<?> ENUM_SB_ACTION;
73+
private static final Object BLANK_NUMBER_FORMAT;
8174
private static final Object SIDEBAR_DISPLAY_SLOT;
8275
private static final Object ENUM_SB_HEALTH_DISPLAY_INTEGER;
8376
private static final Object ENUM_SB_ACTION_CHANGE;
@@ -132,13 +125,17 @@ public abstract class FastBoardBase<T> {
132125
Optional<Class<?>> numberFormat = FastReflection.nmsOptionalClass("network.chat.numbers", "NumberFormat");
133126
MethodHandle packetSbSetScore;
134127
MethodHandle packetSbResetScore = null;
128+
Object blankNumberFormat = null;
135129

136130
if (numberFormat.isPresent()) { // 1.20.3
131+
Class<?> blankFormatClass = FastReflection.nmsClass("network.chat.numbers", "BlankFormat");
137132
Class<?> resetScoreClass = FastReflection.nmsClass(gameProtocolPackage, "ClientboundResetScorePacket");
138133
MethodType setScoreType = MethodType.methodType(void.class, String.class, String.class, int.class, CHAT_COMPONENT_CLASS, numberFormat.get());
139134
MethodType removeScoreType = MethodType.methodType(void.class, String.class, String.class);
135+
Optional<Field> blankField = Arrays.stream(blankFormatClass.getFields()).filter(f -> f.getType() == blankFormatClass).findAny();
140136
packetSbSetScore = lookup.findConstructor(packetSbScoreClass, setScoreType);
141137
packetSbResetScore = lookup.findConstructor(resetScoreClass, removeScoreType);
138+
blankNumberFormat = blankField.isPresent() ? blankField.get().get(null) : null;
142139
} else if (VersionType.V1_17.isHigherOrEqual()) {
143140
Class<?> enumSbAction = FastReflection.nmsClass("server", "ScoreboardServer$Action");
144141
MethodType scoreType = MethodType.methodType(void.class, enumSbAction, String.class, String.class, int.class);
@@ -151,6 +148,7 @@ public abstract class FastBoardBase<T> {
151148
PACKET_SB_RESET_SCORE = packetSbResetScore;
152149
PACKET_SB_TEAM = FastReflection.findPacketConstructor(packetSbTeamClass, lookup);
153150
PACKET_SB_SERIALIZABLE_TEAM = sbTeamClass == null ? null : FastReflection.findPacketConstructor(sbTeamClass, lookup);
151+
BLANK_NUMBER_FORMAT = blankNumberFormat;
154152

155153
for (Class<?> clazz : Arrays.asList(packetSbObjClass, packetSbDisplayObjClass, packetSbScoreClass, packetSbTeamClass, sbTeamClass)) {
156154
if (clazz == null) {
@@ -530,7 +528,7 @@ private void sendModernScorePacket(int score, ScoreboardAction action) throws Th
530528
return;
531529
}
532530

533-
sendPacket(PACKET_SB_SET_SCORE.invoke(objName, this.id, score, null, null));
531+
sendPacket(PACKET_SB_SET_SCORE.invoke(objName, this.id, score, null, BLANK_NUMBER_FORMAT));
534532
}
535533

536534
protected void sendTeamPacket(int score, TeamMode mode) throws Throwable {

0 commit comments

Comments
 (0)