Skip to content

Commit

Permalink
Remove useless stuff in updateAttributes
Browse files Browse the repository at this point in the history
  • Loading branch information
SamB440 committed Jul 19, 2024
1 parent a23200d commit eacfad2
Showing 1 changed file with 21 additions and 53 deletions.
74 changes: 21 additions & 53 deletions src/main/java/ac/grim/grimac/utils/latency/CompensatedEntities.java
Original file line number Diff line number Diff line change
Expand Up @@ -108,72 +108,40 @@ public Integer getPotionLevelForPlayer(PotionType type) {

public void updateAttributes(int entityID, List<WrapperPlayServerUpdateAttributes.Property> objects) {
if (entityID == player.entityID) {
// Check for sprinting attribute. Note that this value can desync: https://bugs.mojang.com/browse/MC-69459
for (WrapperPlayServerUpdateAttributes.Property snapshotWrapper : objects) {
final Attribute attribute = snapshotWrapper.getAttribute();
if (attribute == Attributes.GENERIC_MOVEMENT_SPEED) {
boolean found = false;
List<WrapperPlayServerUpdateAttributes.PropertyModifier> modifiers = snapshotWrapper.getModifiers();
for (WrapperPlayServerUpdateAttributes.PropertyModifier modifier : modifiers) {
final ResourceLocation name = modifier.getName();
if (name.getKey().equals(SPRINTING_MODIFIER_UUID.toString()) || name.getKey().equals("sprinting")) {
found = true;
break;
}
if (attribute != Attributes.GENERIC_MOVEMENT_SPEED) continue;

boolean found = false;
List<WrapperPlayServerUpdateAttributes.PropertyModifier> modifiers = snapshotWrapper.getModifiers();
for (WrapperPlayServerUpdateAttributes.PropertyModifier modifier : modifiers) {
final ResourceLocation name = modifier.getName();
if (name.getKey().equals(SPRINTING_MODIFIER_UUID.toString()) || name.getKey().equals("sprinting")) {
found = true;
break;
}

// The server can set the player's sprinting attribute
hasSprintingAttributeEnabled = found;
player.compensatedEntities.getSelf().getAttribute(Attributes.GENERIC_MOVEMENT_SPEED).get().with(snapshotWrapper);
continue;
}

final Optional<ValuedAttribute> valuedAttribute = player.compensatedEntities.getSelf().getAttribute(attribute);
if (!valuedAttribute.isPresent()) {
// Not an attribute we want to track
continue;
}

valuedAttribute.get().with(snapshotWrapper);
// The server can set the player's sprinting attribute
hasSprintingAttributeEnabled = found;
break;
}
return;
}

PacketEntity entity = player.compensatedEntities.getEntity(entityID);
if (entity == null) return;

if (player.getClientVersion().isNewerThanOrEquals(ClientVersion.V_1_20_5)) {
for (WrapperPlayServerUpdateAttributes.Property snapshotWrapper : objects) {
final Attribute attribute = snapshotWrapper.getAttribute();
final Optional<ValuedAttribute> valuedAttribute = entity.getAttribute(attribute);
if (!valuedAttribute.isPresent()) {
// Not an attribute we want to track
continue;
}

valuedAttribute.get().with(snapshotWrapper);
}
}

if (entity instanceof PacketEntityHorse) {
for (WrapperPlayServerUpdateAttributes.Property snapshotWrapper : objects) {
if (snapshotWrapper.getAttribute() == null) continue;
if (snapshotWrapper.getKey().toUpperCase().contains("MOVEMENT")) {
entity.getAttribute(Attributes.GENERIC_MOVEMENT_SPEED).get().with(snapshotWrapper);
}

if (snapshotWrapper.getKey().toUpperCase().contains("JUMP")) {
entity.getAttribute(Attributes.GENERIC_JUMP_STRENGTH).get().with(snapshotWrapper);
}
for (WrapperPlayServerUpdateAttributes.Property snapshotWrapper : objects) {
final Attribute attribute = snapshotWrapper.getAttribute();
if (attribute == null) continue; // TODO: Warn if this happens? Either modded server or bug in packetevents.
final Optional<ValuedAttribute> valuedAttribute = entity.getAttribute(attribute);
if (!valuedAttribute.isPresent()) {
// Not an attribute we want to track
continue;
}
}

if (entity instanceof PacketEntityRideable) {
for (WrapperPlayServerUpdateAttributes.Property snapshotWrapper : objects) {
if (snapshotWrapper.getAttribute() == null) continue;
if (snapshotWrapper.getKey().toUpperCase().contains("MOVEMENT")) {
entity.getAttribute(Attributes.GENERIC_MOVEMENT_SPEED).get().with(snapshotWrapper);
}
}
valuedAttribute.get().with(snapshotWrapper);
}
}

Expand Down

0 comments on commit eacfad2

Please sign in to comment.