Skip to content

Commit

Permalink
Remove scores on 1.20.3 clients (closes #41)
Browse files Browse the repository at this point in the history
  • Loading branch information
MrMicky-FR committed Dec 7, 2023
1 parent 8c86668 commit 87ffa56
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 17 deletions.
13 changes: 8 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@
[![Maven Central](https://img.shields.io/maven-central/v/fr.mrmicky/fastboard.svg?label=Maven%20Central)](https://central.sonatype.com/artifact/fr.mrmicky/fastboard)
[![Discord](https://img.shields.io/discord/390919659874156560.svg?colorB=5865f2&label=Discord&logo=discord&logoColor=white)](https://discord.gg/q9UwaBT)

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

⚠️ To use FastBoard on a 1.8 server, the server must be on 1.8.8.
> [!IMPORTANT]
> To use FastBoard on a 1.8 server, the server must be on 1.8.8.
## Features

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

## Installation
Expand Down Expand Up @@ -57,12 +59,13 @@ Lightweight packet-based scoreboard API for Bukkit plugins, with 1.7.10 to 1.20
<dependency>
<groupId>fr.mrmicky</groupId>
<artifactId>fastboard</artifactId>
<version>2.0.1</version>
<version>2.0.2</version>
</dependency>
</dependencies>
```

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`).
> [!NOTE]
> 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`).
### Gradle

Expand All @@ -76,7 +79,7 @@ repositories {
}
dependencies {
implementation 'fr.mrmicky:fastboard:2.0.1'
implementation 'fr.mrmicky:fastboard:2.0.2'
}
shadowJar {
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>fr.mrmicky</groupId>
<artifactId>fastboard</artifactId>
<version>2.0.1</version>
<version>2.0.2</version>

<name>FastBoard</name>
<description>Lightweight packet-based scoreboard API for Bukkit plugins.</description>
Expand Down
20 changes: 9 additions & 11 deletions src/main/java/fr/mrmicky/fastboard/FastBoardBase.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,7 @@
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Optional;
import java.util.*;
import java.util.concurrent.ThreadLocalRandom;
import java.util.stream.Stream;

Expand All @@ -51,7 +43,7 @@
* The project is on <a href="https://github.com/MrMicky-FR/FastBoard">GitHub</a>.
*
* @author MrMicky
* @version 2.0.1
* @version 2.0.2
*/
public abstract class FastBoardBase<T> {

Expand All @@ -78,6 +70,7 @@ public abstract class FastBoardBase<T> {
private static final Class<?> DISPLAY_SLOT_TYPE;
private static final Class<?> ENUM_SB_HEALTH_DISPLAY;
private static final Class<?> ENUM_SB_ACTION;
private static final Object BLANK_NUMBER_FORMAT;
private static final Object SIDEBAR_DISPLAY_SLOT;
private static final Object ENUM_SB_HEALTH_DISPLAY_INTEGER;
private static final Object ENUM_SB_ACTION_CHANGE;
Expand Down Expand Up @@ -132,13 +125,17 @@ public abstract class FastBoardBase<T> {
Optional<Class<?>> numberFormat = FastReflection.nmsOptionalClass("network.chat.numbers", "NumberFormat");
MethodHandle packetSbSetScore;
MethodHandle packetSbResetScore = null;
Object blankNumberFormat = null;

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

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

sendPacket(PACKET_SB_SET_SCORE.invoke(objName, this.id, score, null, null));
sendPacket(PACKET_SB_SET_SCORE.invoke(objName, this.id, score, null, BLANK_NUMBER_FORMAT));
}

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

0 comments on commit 87ffa56

Please sign in to comment.