2828import static org .geysermc .geyser .scoreboard .network .util .AssertUtils .assertNextPacketType ;
2929import static org .geysermc .geyser .scoreboard .network .util .GeyserMockContextScoreboard .mockContextScoreboard ;
3030import static org .junit .jupiter .api .Assertions .assertDoesNotThrow ;
31+ import static org .junit .jupiter .api .Assertions .assertEquals ;
3132
3233import org .cloudburstmc .protocol .bedrock .packet .AddEntityPacket ;
3334import org .cloudburstmc .protocol .bedrock .packet .RemoveEntityPacket ;
35+ import org .geysermc .geyser .entity .type .living .monster .EnderDragonPartEntity ;
36+ import org .geysermc .geyser .session .cache .EntityCache ;
3437import org .geysermc .geyser .translator .protocol .java .entity .JavaRemoveEntitiesTranslator ;
3538import org .geysermc .geyser .translator .protocol .java .entity .spawn .JavaAddExperienceOrbTranslator ;
3639import org .geysermc .mcprotocollib .protocol .packet .ingame .clientbound .entity .ClientboundRemoveEntitiesPacket ;
3740import org .geysermc .mcprotocollib .protocol .packet .ingame .clientbound .entity .spawn .ClientboundAddExperienceOrbPacket ;
3841import org .junit .jupiter .api .Test ;
3942
40- public class TeamIdentifierTest {
43+ /**
44+ * Tests that don't fit in a larger system (e.g. sidebar objective) that were reported on GitHub
45+ */
46+ public class ScoreboardIssueTests {
47+ /**
48+ * Test for <a href="https://github.com/GeyserMC/Geyser/issues/5075">#5075</a>
49+ */
4150 @ Test
4251 void entityWithoutUuid () {
4352 // experience orbs are the only known entities without an uuid, see Entity#teamIdentifier for more info
@@ -50,6 +59,10 @@ void entityWithoutUuid() {
5059 // because the entity would be registered and deregistered to the scoreboard.
5160 assertDoesNotThrow (() -> {
5261 context .translate (addExperienceOrbTranslator , new ClientboundAddExperienceOrbPacket (2 , 0 , 0 , 0 , 1 ));
62+
63+ String displayName = context .mockOrSpy (EntityCache .class ).getEntityByJavaId (2 ).getDisplayName ();
64+ assertEquals ("entity.minecraft.experience_orb" , displayName );
65+
5366 context .translate (removeEntitiesTranslator , new ClientboundRemoveEntitiesPacket (new int [] { 2 }));
5467 });
5568
@@ -58,4 +71,23 @@ void entityWithoutUuid() {
5871 assertNextPacketType (context , RemoveEntityPacket .class );
5972 });
6073 }
74+
75+ /**
76+ * Test for <a href="https://github.com/GeyserMC/Geyser/issues/5078">#5078</a>
77+ */
78+ @ Test
79+ void entityWithoutType () {
80+ // dragon entity parts are an entity in Geyser, but do not have an entity type
81+ mockContextScoreboard (context -> {
82+ // EntityUtils#translatedEntityName used to not take null EntityType's into account,
83+ // so it used to throw an exception
84+ assertDoesNotThrow (() -> {
85+ // dragon entity parts are not spawned using a packet, so we manually create an instance
86+ var dragonHeadPart = new EnderDragonPartEntity (context .session (), 2 , 2 , 1 , 1 );
87+
88+ String displayName = dragonHeadPart .getDisplayName ();
89+ assertEquals ("entity.unregistered_sadface" , displayName );
90+ });
91+ });
92+ }
6193}
0 commit comments