Clear bossbars & entity attributes on server switching (#4278)

* This ensures bossbars are cleared on server switch. Additionally, this clears the EntityCache - which should resolve issues around air supply/hearts persisting visually.

* - Also reset attributes on server switch, aswell as air
This commit is contained in:
chris 2023-11-08 00:23:56 +01:00 committed by GitHub
parent 06663bcafd
commit aa899af908
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 26 additions and 5 deletions

View file

@ -254,4 +254,17 @@ public class SessionPlayerEntity extends PlayerEntity {
public UUID getTabListUuid() { public UUID getTabListUuid() {
return session.getAuthData().uuid(); return session.getAuthData().uuid();
} }
public void resetMetadata() {
// Reset all metadata to their default values
// This is used when a player respawns
this.initializeMetadata();
// Reset air
this.resetAir();
}
public void resetAir() {
this.setAirSupply(getMaxAir());
}
} }

View file

@ -162,4 +162,9 @@ public class EntityCache {
public List<Tickable> getTickableEntities() { public List<Tickable> getTickableEntities() {
return tickableEntities; return tickableEntities;
} }
public void removeAllBossBars() {
bossBars.values().forEach(BossBar::removeBossBar);
bossBars.clear();
}
} }

View file

@ -64,12 +64,17 @@ public class JavaLoginTranslator extends PacketTranslator<ClientboundLoginPacket
DimensionUtils.switchDimension(session, fakeDim); DimensionUtils.switchDimension(session, fakeDim);
session.getWorldCache().removeScoreboard(); session.getWorldCache().removeScoreboard();
// Remove all bossbars
session.getEntityCache().removeAllBossBars();
// Remove extra hearts, hunger, etc.
entity.getAttributes().clear();
entity.resetMetadata();
} }
session.setWorldName(spawnInfo.getWorldName()); session.setWorldName(spawnInfo.getWorldName());
session.setLevels(packet.getWorldNames()); session.setLevels(packet.getWorldNames());
session.setGameMode(spawnInfo.getGameMode()); session.setGameMode(spawnInfo.getGameMode());
String newDimension = spawnInfo.getDimension(); String newDimension = spawnInfo.getDimension();
boolean needsSpawnPacket = !session.isSentSpawnPacket(); boolean needsSpawnPacket = !session.isSentSpawnPacket();
@ -81,9 +86,7 @@ public class JavaLoginTranslator extends PacketTranslator<ClientboundLoginPacket
// It is now safe to send these packets // It is now safe to send these packets
session.getUpstream().sendPostStartGamePackets(); session.getUpstream().sendPostStartGamePackets();
} } else {
if (!needsSpawnPacket) {
SetPlayerGameTypePacket playerGameTypePacket = new SetPlayerGameTypePacket(); SetPlayerGameTypePacket playerGameTypePacket = new SetPlayerGameTypePacket();
playerGameTypePacket.setGamemode(EntityUtils.toBedrockGamemode(spawnInfo.getGameMode()).ordinal()); playerGameTypePacket.setGamemode(EntityUtils.toBedrockGamemode(spawnInfo.getGameMode()).ordinal());
session.sendUpstreamPacket(playerGameTypePacket); session.sendUpstreamPacket(playerGameTypePacket);