Skip to content

Commit e8be3b9

Browse files
committed
fix(api): Always fire bossBarNameChanged
Developers use the GlobalTranslator to insert updated content in the resulting component sent to end users, so we shouldn't be checking this component. The only side effect would be that people who constantly call `name` would have packets repeatedly sent out, which feels like a them problem.
1 parent 1b8f5e4 commit e8be3b9

File tree

2 files changed

+5
-6
lines changed

2 files changed

+5
-6
lines changed

api/src/main/java/net/kyori/adventure/bossbar/BossBarImpl.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
import java.util.Collections;
2727
import java.util.EnumSet;
2828
import java.util.List;
29-
import java.util.Objects;
3029
import java.util.Optional;
3130
import java.util.Set;
3231
import java.util.concurrent.CopyOnWriteArrayList;
@@ -92,12 +91,12 @@ private ImplementationAccessor() {
9291

9392
@Override
9493
public @NotNull BossBar name(final @NotNull Component newName) {
94+
// We do not check if the new name equals the old name here as the GlobalTranslator
95+
// may produce a different resulting component for the end user.
9596
requireNonNull(newName, "name");
9697
final Component oldName = this.name;
97-
if (!Objects.equals(newName, oldName)) {
98-
this.name = newName;
99-
this.forEachListener(listener -> listener.bossBarNameChanged(this, oldName, newName));
100-
}
98+
this.name = newName;
99+
this.forEachListener(listener -> listener.bossBarNameChanged(this, oldName, newName));
101100
return this;
102101
}
103102

api/src/test/java/net/kyori/adventure/bossbar/BossBarTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ void testName() {
8989
assertEquals(1, this.name.get());
9090

9191
assertEquals(Component.text("B"), this.bar.name(Component.text("B")).name());
92-
assertEquals(1, this.name.get()); // value has not changed, should not have incremented
92+
assertEquals(2, this.name.get()); // value has not changed, but we want this to have incremented
9393
}
9494

9595
@Test

0 commit comments

Comments
 (0)