Skip to content

Commit

Permalink
Don't send meta packets during syncing
Browse files Browse the repository at this point in the history
  • Loading branch information
MATRIX-feather committed Dec 14, 2023
1 parent d634984 commit 19499d8
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,6 @@ public List<PacketContainer> buildSpawnPackets(Player player, DisplayParameters
packets.add(PacketContainer.fromPacket(equipmentPacket));

var watcher = parameters.getWatcher();
watcher.sync();
packets.add(buildFullMetaPacket(player, watcher));

for (PacketContainer packet : packets)
Expand Down Expand Up @@ -143,6 +142,8 @@ public PacketContainer buildDiffMetaPacket(Player player, SingleWatcher watcher)

public PacketContainer buildFullMetaPacket(Player player, SingleWatcher watcher)
{
watcher.sync();

var metaPacket = new PacketContainer(PacketType.Play.Server.ENTITY_METADATA);
metaPacket.getIntegers().write(0, player.getEntityId());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,9 @@ public void write(int index, Object value)
dirtySingles.put(single, value);

onTrackerWrite(index, prev, value);
sendPacketToAffectedPlayers(packetFactory.buildDiffMetaPacket(getBindingPlayer(), this));

if (!syncing)
sendPacketToAffectedPlayers(packetFactory.buildDiffMetaPacket(getBindingPlayer(), this));
}

@Resolved(shouldSolveImmediately = true)
Expand Down Expand Up @@ -204,10 +206,25 @@ public Map<SingleValue<?>, Object> getDirty()

//endregion Value Registry

private boolean syncing;

public void sync()
{
syncing = true;

dirtySingles.clear();
doSync();

try
{
doSync();
}
catch (Throwable t)
{
logger.warn("Error occurred while syncing watcher: " + t.getMessage());
t.printStackTrace();
}

syncing = false;
}

protected void doSync()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ private void onMetaPacket(ClientboundSetEntityDataPacket packet, PacketEvent pac
return;

//取得来源玩家的伪装后的Meta,发送给目标玩家
watcher.sync();
packetEvent.setPacket(getFactory().buildFullMetaPacket(sourcePlayer, watcher));
}

Expand Down

0 comments on commit 19499d8

Please sign in to comment.