mirror of
https://github.com/2006-Scape/apollo.git
synced 2026-07-06 00:38:18 +00:00
Merge pull request #167 from ryleykimmel/issue165
Fix String attribute encoding delimiter
This commit is contained in:
@@ -42,6 +42,17 @@ public final class AttributeDefinition<T> {
|
||||
return new AttributeDefinition<>(defaultValue, persistence, AttributeType.LONG);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates an AttributeDefinition for a {@code long}.
|
||||
*
|
||||
* @param defaultValue The default value of the definition.
|
||||
* @param persistence The {@link AttributePersistence} of the definition.
|
||||
* @return The AttributeDefinition.
|
||||
*/
|
||||
public static AttributeDefinition<Long> forLong(long defaultValue, AttributePersistence persistence) {
|
||||
return new AttributeDefinition<>(defaultValue, persistence, AttributeType.LONG);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates an AttributeDefinition for a String.
|
||||
*
|
||||
|
||||
@@ -113,7 +113,7 @@ public final class AttributeMap {
|
||||
private <T> Attribute<?> createAttribute(T value, AttributeType type) {
|
||||
switch (type) {
|
||||
case LONG:
|
||||
return new NumericalAttribute((Long) value);
|
||||
return new NumericalAttribute(((Number) value).longValue());
|
||||
case DOUBLE:
|
||||
return new NumericalAttribute((Double) value);
|
||||
case STRING:
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package org.apollo.game.model.entity.attr;
|
||||
|
||||
import java.nio.charset.Charset;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.Arrays;
|
||||
|
||||
/**
|
||||
@@ -31,11 +31,11 @@ public final class StringAttribute extends Attribute<String> {
|
||||
|
||||
@Override
|
||||
public byte[] encode() {
|
||||
byte[] bytes = value.getBytes(Charset.forName("UTF-8"));
|
||||
byte[] bytes = value.getBytes(StandardCharsets.UTF_8);
|
||||
int length = bytes.length;
|
||||
|
||||
bytes = Arrays.copyOf(bytes, length + 1);
|
||||
bytes[length - 1] = 0;
|
||||
bytes[length] = 0;
|
||||
return bytes;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user