From e162cd526c387d9fe196ebdbdb243e478bba0038 Mon Sep 17 00:00:00 2001 From: Camotoy <20743703+Camotoy@users.noreply.github.com> Date: Tue, 6 Jul 2021 18:09:01 -0400 Subject: [PATCH] Micro-optimizations in player entity code --- .../connector/entity/player/PlayerEntity.java | 12 ++++-------- .../connector/entity/player/SkullPlayerEntity.java | 2 +- 2 files changed, 5 insertions(+), 9 deletions(-) diff --git a/connector/src/main/java/org/geysermc/connector/entity/player/PlayerEntity.java b/connector/src/main/java/org/geysermc/connector/entity/player/PlayerEntity.java index 3cda303cd..4f3cc5748 100644 --- a/connector/src/main/java/org/geysermc/connector/entity/player/PlayerEntity.java +++ b/connector/src/main/java/org/geysermc/connector/entity/player/PlayerEntity.java @@ -55,10 +55,7 @@ import org.geysermc.connector.scoreboard.Team; import org.geysermc.connector.utils.AttributeUtils; import org.geysermc.connector.network.translators.chat.MessageTranslator; -import java.util.ArrayList; -import java.util.List; -import java.util.Map; -import java.util.UUID; +import java.util.*; import java.util.concurrent.TimeUnit; @Getter @Setter @@ -95,7 +92,7 @@ public class PlayerEntity extends LivingEntity { addPlayerPacket.setUsername(username); addPlayerPacket.setRuntimeEntityId(geyserId); addPlayerPacket.setUniqueEntityId(geyserId); - addPlayerPacket.setPosition(position.clone().sub(0, EntityType.PLAYER.getOffset(), 0)); + addPlayerPacket.setPosition(position.sub(0, EntityType.PLAYER.getOffset(), 0)); addPlayerPacket.setRotation(getBedrockRotation()); addPlayerPacket.setMotion(motion); addPlayerPacket.setHand(hand); @@ -277,10 +274,9 @@ public class PlayerEntity extends LivingEntity { if (entityMetadata.getId() == 15) { UpdateAttributesPacket attributesPacket = new UpdateAttributesPacket(); attributesPacket.setRuntimeEntityId(geyserId); - List attributes = new ArrayList<>(); // Setting to a higher maximum since plugins/datapacks can probably extend the Bedrock soft limit - attributes.add(new AttributeData("minecraft:absorption", 0.0f, 1024f, (float) entityMetadata.getValue(), 0.0f)); - attributesPacket.setAttributes(attributes); + attributesPacket.setAttributes(Collections.singletonList( + new AttributeData("minecraft:absorption", 0.0f, 1024f, (float) entityMetadata.getValue(), 0.0f))); session.sendUpstreamPacket(attributesPacket); } diff --git a/connector/src/main/java/org/geysermc/connector/entity/player/SkullPlayerEntity.java b/connector/src/main/java/org/geysermc/connector/entity/player/SkullPlayerEntity.java index d12a6c528..333726cab 100644 --- a/connector/src/main/java/org/geysermc/connector/entity/player/SkullPlayerEntity.java +++ b/connector/src/main/java/org/geysermc/connector/entity/player/SkullPlayerEntity.java @@ -75,7 +75,7 @@ public class SkullPlayerEntity extends PlayerEntity { addPlayerPacket.setUsername(getUsername()); addPlayerPacket.setRuntimeEntityId(geyserId); addPlayerPacket.setUniqueEntityId(geyserId); - addPlayerPacket.setPosition(position.clone().sub(0, EntityType.PLAYER.getOffset(), 0)); + addPlayerPacket.setPosition(position.sub(0, EntityType.PLAYER.getOffset(), 0)); addPlayerPacket.setRotation(getBedrockRotation()); addPlayerPacket.setMotion(motion); addPlayerPacket.setHand(hand);