Search in sources :

Example 1 with AttributeType

use of org.apollo.game.model.entity.attr.AttributeType in project apollo by apollo-rsps.

the class BinaryPlayerSerializer method readAttributes.

/**
 * Reads the player's {@link Attribute}s.
 *
 * @param in The input stream.
 * @return The {@link Map} of attribute names to attributes.
 * @throws IOException If there is an error reading from the stream.
 */
private Map<String, Attribute<?>> readAttributes(DataInputStream in) throws IOException {
    int count = in.readInt();
    Map<String, Attribute<?>> attributes = new HashMap<>(count);
    for (int times = 0; times < count; times++) {
        String name = StreamUtil.readString(in);
        AttributeType type = AttributeType.valueOf(in.read());
        Attribute<?> attribute;
        switch(type) {
            case BOOLEAN:
                attribute = new BooleanAttribute(in.read() == 1);
                break;
            case DOUBLE:
                attribute = new NumericalAttribute(in.readDouble());
                break;
            case LONG:
                attribute = new NumericalAttribute(in.readLong());
                break;
            case STRING:
            case SYMBOL:
                attribute = new StringAttribute(StreamUtil.readString(in), type == AttributeType.SYMBOL);
                break;
            default:
                throw new IllegalArgumentException("Undefined attribute type: " + type + ".");
        }
        attributes.put(name, attribute);
    }
    return attributes;
}
Also used : BooleanAttribute(org.apollo.game.model.entity.attr.BooleanAttribute) NumericalAttribute(org.apollo.game.model.entity.attr.NumericalAttribute) BooleanAttribute(org.apollo.game.model.entity.attr.BooleanAttribute) Attribute(org.apollo.game.model.entity.attr.Attribute) StringAttribute(org.apollo.game.model.entity.attr.StringAttribute) HashMap(java.util.HashMap) AttributeType(org.apollo.game.model.entity.attr.AttributeType) NumericalAttribute(org.apollo.game.model.entity.attr.NumericalAttribute) StringAttribute(org.apollo.game.model.entity.attr.StringAttribute)

Aggregations

HashMap (java.util.HashMap)1 Attribute (org.apollo.game.model.entity.attr.Attribute)1 AttributeType (org.apollo.game.model.entity.attr.AttributeType)1 BooleanAttribute (org.apollo.game.model.entity.attr.BooleanAttribute)1 NumericalAttribute (org.apollo.game.model.entity.attr.NumericalAttribute)1 StringAttribute (org.apollo.game.model.entity.attr.StringAttribute)1