25
25
26
26
package org .geysermc .geyser .translator .protocol .bedrock ;
27
27
28
- import org .cloudburstmc .protocol .bedrock .data .AttributeData ;
29
28
import org .cloudburstmc .protocol .bedrock .packet .NetworkStackLatencyPacket ;
30
- import org .cloudburstmc .protocol .bedrock .packet .UpdateAttributesPacket ;
31
- import org .geysermc .geyser .entity .attribute .GeyserAttributeType ;
32
29
import org .geysermc .geyser .session .GeyserSession ;
33
30
import org .geysermc .geyser .translator .protocol .PacketTranslator ;
34
31
import org .geysermc .geyser .translator .protocol .Translator ;
35
- import org .geysermc .geyser .util .InventoryUtils ;
36
- import org .geysermc .mcprotocollib .protocol .packet .common .serverbound .ServerboundKeepAlivePacket ;
37
-
38
- import java .util .Collections ;
39
- import java .util .concurrent .TimeUnit ;
40
32
41
33
/**
42
34
* Used to send the forwarded keep alive packet back to the server
@@ -46,47 +38,18 @@ public class BedrockNetworkStackLatencyTranslator extends PacketTranslator<Netwo
46
38
47
39
@ Override
48
40
public void translate (GeyserSession session , NetworkStackLatencyPacket packet ) {
49
- // negative timestamps are used as hack to fix the url image loading bug
50
- if (packet .getTimestamp () >= 0 ) {
51
- if (session .getGeyser ().getConfig ().isForwardPlayerPing ()) {
52
- // use our cached value because
53
- // a) bedrock can be inaccurate with the value returned
54
- // b) playstation replies with a different magnitude than other platforms
55
- // c) 1.20.10 and later reply with a different magnitude
56
- Long keepAliveId = session .getKeepAliveCache ().poll ();
57
- if (keepAliveId == null ) {
58
- session .getGeyser ().getLogger ().debug ("Received a latency packet that we don't have a KeepAlive for: " + packet );
59
- return ;
60
- }
61
-
62
- ServerboundKeepAlivePacket keepAlivePacket = new ServerboundKeepAlivePacket (keepAliveId );
63
- session .sendDownstreamPacket (keepAlivePacket );
64
- }
41
+ // We should receive these packets in the same order they were sent
42
+ final Runnable latencyPing = session .getLatencyPingCache ().poll ();
43
+ if (latencyPing == null ) {
44
+ session .getGeyser ().getLogger ().debug ("Received a latency packet that we don't have a ping for: " + packet );
65
45
return ;
66
46
}
67
47
68
- if (session .getPendingOrCurrentBedrockInventoryId () != -1 ) {
69
- InventoryUtils .openPendingInventory (session );
70
- } else {
71
- session .scheduleInEventLoop (() -> {
72
- // Hack to fix the url image loading bug
73
- UpdateAttributesPacket attributesPacket = new UpdateAttributesPacket ();
74
- attributesPacket .setRuntimeEntityId (session .getPlayerEntity ().getGeyserId ());
75
-
76
- AttributeData attribute = session .getPlayerEntity ().getAttributes ().get (GeyserAttributeType .EXPERIENCE_LEVEL );
77
- if (attribute != null ) {
78
- attributesPacket .setAttributes (Collections .singletonList (attribute ));
79
- } else {
80
- attributesPacket .setAttributes (Collections .singletonList (GeyserAttributeType .EXPERIENCE_LEVEL .getAttribute (0 )));
81
- }
82
-
83
- session .sendUpstreamPacket (attributesPacket );
84
- }, 500 , TimeUnit .MILLISECONDS );
85
- }
48
+ latencyPing .run ();
86
49
}
87
50
88
51
@ Override
89
52
public boolean shouldExecuteInEventLoop () {
90
- return false ;
53
+ return true ;
91
54
}
92
55
}
0 commit comments