Skip to content

Commit 669a76c

Browse files
authored
Empty player list on phase transition, despawn skulls, always reset weather (#4847)
* Empty player list on transition, despawn skulls * Always reset weather
1 parent 677a56c commit 669a76c

File tree

5 files changed

+76
-19
lines changed

5 files changed

+76
-19
lines changed

core/src/main/java/org/geysermc/geyser/session/cache/EntityCache.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,10 @@ public Collection<PlayerEntity> getAllPlayerEntities() {
141141
return playerEntities.values();
142142
}
143143

144+
public void removeAllPlayerEntities() {
145+
playerEntities.clear();
146+
}
147+
144148
public void addBossBar(UUID uuid, BossBar bossBar) {
145149
bossBars.put(uuid, bossBar);
146150
bossBar.addBossBar();

core/src/main/java/org/geysermc/geyser/session/cache/SkullCache.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,8 +243,16 @@ private void reassignSkullEntity(Skull skull) {
243243
}
244244

245245
public void clear() {
246+
for (Skull skull : skulls.values()) {
247+
if (skull.entity != null) {
248+
skull.entity.despawnEntity();
249+
}
250+
}
246251
skulls.clear();
247252
inRangeSkulls.clear();
253+
for (SkullPlayerEntity skull : unusedSkullEntities) {
254+
skull.despawnEntity();
255+
}
248256
unusedSkullEntities.clear();
249257
totalSkullEntities = 0;
250258
lastPlayerPosition = null;
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
/*
2+
* Copyright (c) 2024 GeyserMC. http://geysermc.org
3+
*
4+
* Permission is hereby granted, free of charge, to any person obtaining a copy
5+
* of this software and associated documentation files (the "Software"), to deal
6+
* in the Software without restriction, including without limitation the rights
7+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8+
* copies of the Software, and to permit persons to whom the Software is
9+
* furnished to do so, subject to the following conditions:
10+
*
11+
* The above copyright notice and this permission notice shall be included in
12+
* all copies or substantial portions of the Software.
13+
*
14+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20+
* THE SOFTWARE.
21+
*
22+
* @author GeyserMC
23+
* @link https://github.com/GeyserMC/Geyser
24+
*/
25+
26+
package org.geysermc.geyser.translator.protocol.java;
27+
28+
import org.cloudburstmc.protocol.bedrock.packet.PlayerListPacket;
29+
import org.geysermc.geyser.entity.type.player.PlayerEntity;
30+
import org.geysermc.geyser.session.GeyserSession;
31+
import org.geysermc.geyser.translator.protocol.PacketTranslator;
32+
import org.geysermc.geyser.translator.protocol.Translator;
33+
import org.geysermc.mcprotocollib.protocol.packet.configuration.clientbound.ClientboundFinishConfigurationPacket;
34+
35+
@Translator(packet = ClientboundFinishConfigurationPacket.class)
36+
public class JavaFinishConfigurationPacketTranslator extends PacketTranslator<ClientboundFinishConfigurationPacket> {
37+
38+
@Override
39+
public void translate(GeyserSession session, ClientboundFinishConfigurationPacket packet) {
40+
// Clear the player list, as on Java the player list is cleared after transitioning from config to play phase
41+
PlayerListPacket playerListPacket = new PlayerListPacket();
42+
playerListPacket.setAction(PlayerListPacket.Action.REMOVE);
43+
for (PlayerEntity otherEntity : session.getEntityCache().getAllPlayerEntities()) {
44+
playerListPacket.getEntries().add(new PlayerListPacket.Entry(otherEntity.getTabListUuid()));
45+
}
46+
session.sendUpstreamPacket(playerListPacket);
47+
session.getEntityCache().removeAllPlayerEntities();
48+
}
49+
}

core/src/main/java/org/geysermc/geyser/translator/protocol/java/JavaLoginTranslator.java

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -79,25 +79,6 @@ public void translate(GeyserSession session, ClientboundLoginPacket packet) {
7979
// Remove extra hearts, hunger, etc.
8080
entity.resetAttributes();
8181
entity.resetMetadata();
82-
83-
// Reset weather
84-
if (session.isRaining()) {
85-
LevelEventPacket stopRainPacket = new LevelEventPacket();
86-
stopRainPacket.setType(LevelEvent.STOP_RAINING);
87-
stopRainPacket.setData(0);
88-
stopRainPacket.setPosition(Vector3f.ZERO);
89-
session.sendUpstreamPacket(stopRainPacket);
90-
session.setRaining(false);
91-
}
92-
93-
if (session.isThunder()) {
94-
LevelEventPacket stopThunderPacket = new LevelEventPacket();
95-
stopThunderPacket.setType(LevelEvent.STOP_THUNDERSTORM);
96-
stopThunderPacket.setData(0);
97-
stopThunderPacket.setPosition(Vector3f.ZERO);
98-
session.sendUpstreamPacket(stopThunderPacket);
99-
session.setThunder(false);
100-
}
10182
}
10283

10384
session.setWorldName(spawnInfo.getWorldName());

core/src/main/java/org/geysermc/geyser/util/DimensionUtils.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727

2828
import org.cloudburstmc.math.vector.Vector3f;
2929
import org.cloudburstmc.math.vector.Vector3i;
30+
import org.cloudburstmc.protocol.bedrock.data.LevelEvent;
3031
import org.cloudburstmc.protocol.bedrock.data.PlayerActionType;
3132
import org.cloudburstmc.protocol.bedrock.packet.*;
3233
import org.geysermc.geyser.entity.type.Entity;
@@ -110,6 +111,20 @@ public static void switchDimension(GeyserSession session, int javaDimension) {
110111
// Effects are re-sent from server
111112
entityEffects.clear();
112113

114+
// Always reset weather, as it sometimes suddenly starts raining. See https://github.com/GeyserMC/Geyser/issues/3679
115+
LevelEventPacket stopRainPacket = new LevelEventPacket();
116+
stopRainPacket.setType(LevelEvent.STOP_RAINING);
117+
stopRainPacket.setData(0);
118+
stopRainPacket.setPosition(Vector3f.ZERO);
119+
session.sendUpstreamPacket(stopRainPacket);
120+
session.setRaining(false);
121+
LevelEventPacket stopThunderPacket = new LevelEventPacket();
122+
stopThunderPacket.setType(LevelEvent.STOP_THUNDERSTORM);
123+
stopThunderPacket.setData(0);
124+
stopThunderPacket.setPosition(Vector3f.ZERO);
125+
session.sendUpstreamPacket(stopThunderPacket);
126+
session.setThunder(false);
127+
113128
//let java server handle portal travel sound
114129
StopSoundPacket stopSoundPacket = new StopSoundPacket();
115130
stopSoundPacket.setStoppingAllSound(true);

0 commit comments

Comments
 (0)