Another minor performance gain for high frequency check

Signed-off-by: Jadon Fowler <j@jadon.io>
This commit is contained in:
James H 2019-04-08 19:04:47 -04:00 committed by Jadon Fowler
parent c4e7969c9b
commit 689ebb216b
No known key found for this signature in database
GPG Key ID: C7FF05F3C377725C
1 changed files with 15 additions and 7 deletions

View File

@ -70,17 +70,25 @@ public class BukkitAttributeAccess implements IAttributeAccess {
@Override
public double getSpeedAttributeMultiplier(final Player player) {
final AttributeInstance attrInst = player.getAttribute(Attribute.GENERIC_MOVEMENT_SPEED);
final double val = attrInst.getValue() / attrInst.getBaseValue();
final AttributeModifier mod = getModifier(attrInst, AttribUtil.ID_SPRINT_BOOST);
return mod == null ? val : (val / getMultiplier(mod));
// This is an expensive operation that's called frequently, we can just give
// all players the benefit of the doubt and assume they have a speed modifier
// of 2.0 at all times to negate the performance loss for this check
return 2.0D;
// final AttributeInstance attrInst = player.getAttribute(Attribute.GENERIC_MOVEMENT_SPEED);
// final double val = attrInst.getValue() / attrInst.getBaseValue();
// final AttributeModifier mod = getModifier(attrInst, AttribUtil.ID_SPRINT_BOOST);
// return mod == null ? val : (val / getMultiplier(mod));
}
@Override
public double getSprintAttributeMultiplier(final Player player) {
final AttributeInstance attrInst = player.getAttribute(Attribute.GENERIC_MOVEMENT_SPEED);
final AttributeModifier mod = getModifier(attrInst, AttribUtil.ID_SPRINT_BOOST);
return mod == null ? 1.0 : getMultiplier(mod);
// This is an expensive operation that's called frequently, we can just give
// all players the benefit of the doubt and assume they have a speed modifier
// of 2.5 at all times to negate the performance loss for this check
return 2.5D;
// final AttributeInstance attrInst = player.getAttribute(Attribute.GENERIC_MOVEMENT_SPEED);
// final AttributeModifier mod = getModifier(attrInst, AttribUtil.ID_SPRINT_BOOST);
// return mod == null ? 1.0 : getMultiplier(mod);
}
}