package org.apollo.game.model.entity.attr;

import com.google.common.primitives.Longs;

/**
 * An {@link Attribute} with a numerical value.
 *
 * @author Major
 */
public final class NumericalAttribute extends Attribute<Number> {

	/**
	 * Gets the {@link AttributeType} of number this attribute is.
	 *
	 * @param value The value of this attribute.
	 * @return The type.
	 */
	private static AttributeType typeOf(Number value) {
		return value instanceof Double ? AttributeType.DOUBLE : AttributeType.LONG;
	}

	/**
	 * Creates the number attribute.
	 *
	 * @param value The value of this attribute.
	 */
	public NumericalAttribute(Number value) {
		super(typeOf(value), value);
	}

	@Override
	public byte[] encode() {
		long encoded = type == AttributeType.DOUBLE ? Double.doubleToLongBits((double) value) : (long) value;
		return Longs.toByteArray(encoded);
	}

	@Override
	public String toString() {
		return type == AttributeType.DOUBLE ? Double.toString((double) value) : Long.toString((long) value);
	}

}
@@ -790,38 +790,48 @@
 its(
-(
+value.
 double
-) v
+V
 alue
+()
 ) : 
-(
+value.
 long
-) v
+V
 alue
+()
 ;%0A%09%09
@@ -968,22 +968,27 @@
 ing(
-(
+value.
 double
-) v
+V
 alue
+()
 ) : 
@@ -1005,20 +1005,25 @@
 ing(
-(
+value.
 long
-) v
+V
 alue
+()
 );%0A%09

Fix numerical attribute encoding