Only send entity metadata if dirty

This commit is contained in:
fullwall 2022-12-10 14:59:27 +08:00
parent 2034ca6bf0
commit dffccdd2d4
2 changed files with 15 additions and 12 deletions

View File

@ -136,7 +136,7 @@ class ProfileFetchThread implements Runnable {
public void onProfileLookupFailed(GameProfile profile, Exception e) {
if (Messaging.isDebugging()) {
Messaging.debug(
"Profile lookup for player '" + profile.getName() + "' failed2: " + getExceptionMsg(e));
"Profile lookup for player '" + profile.getName() + "' failed: " + getExceptionMsg(e));
Messaging.debug(Throwables.getStackTraceAsString(e));
}
@ -167,7 +167,7 @@ class ProfileFetchThread implements Runnable {
request.setResult(NMS.fillProfileProperties(profile, true), ProfileFetchResult.SUCCESS);
} catch (Throwable e) {
if (Messaging.isDebugging()) {
Messaging.debug("Profile lookup for player '" + profile.getName() + "' failed: "
Messaging.debug("Filling profile lookup for player '" + profile.getName() + "' failed: "
+ getExceptionMsg(e) + " " + isTooManyRequests(e));
Messaging.debug(Throwables.getStackTraceAsString(e));
}

View File

@ -23,8 +23,7 @@ public class PlayerAnimationImpl {
switch (animation) {
case SNEAK:
player.getBukkitEntity().setSneaking(true);
sendPacketNearby(new ClientboundSetEntityDataPacket(player.getId(), player.getEntityData().packDirty()),
player, radius);
sendEntityData(radius, player);
break;
case START_ELYTRA:
player.startFallFlying();
@ -34,27 +33,24 @@ public class PlayerAnimationImpl {
break;
case START_USE_MAINHAND_ITEM:
player.startUsingItem(InteractionHand.MAIN_HAND);
sendPacketNearby(new ClientboundSetEntityDataPacket(player.getId(), player.getEntityData().packDirty()),
player, radius);
sendEntityData(radius, player);
break;
case START_USE_OFFHAND_ITEM:
player.startUsingItem(InteractionHand.OFF_HAND);
sendPacketNearby(new ClientboundSetEntityDataPacket(player.getId(), player.getEntityData().packDirty()),
player, radius);
sendEntityData(radius, player);
break;
case STOP_SNEAKING:
player.getBukkitEntity().setSneaking(false);
sendPacketNearby(new ClientboundSetEntityDataPacket(player.getId(), player.getEntityData().packDirty()),
player, radius);
sendEntityData(radius, player);
break;
case STOP_USE_ITEM:
player.stopUsingItem();
sendPacketNearby(new ClientboundSetEntityDataPacket(player.getId(), player.getEntityData().packDirty()),
player, radius);
sendEntityData(radius, player);
break;
default:
throw new UnsupportedOperationException();
}
}
protected static void playDefaultAnimation(ServerPlayer player, int radius, int code) {
@ -62,6 +58,13 @@ public class PlayerAnimationImpl {
sendPacketNearby(packet, player, radius);
}
private static void sendEntityData(int radius, final ServerPlayer player) {
if (!player.getEntityData().isDirty())
return;
sendPacketNearby(new ClientboundSetEntityDataPacket(player.getId(), player.getEntityData().packDirty()), player,
radius);
}
protected static void sendPacketNearby(Packet<?> packet, ServerPlayer player, int radius) {
NMSImpl.sendPacketNearby(player.getBukkitEntity(), player.getBukkitEntity().getLocation(), packet, radius);
}