make EntityData value types guaranteed safe at compile time using generics
This commit is contained in:
parent
3714bafbb4
commit
f6f861a652
5 changed files with 18 additions and 15 deletions
|
@ -11,6 +11,6 @@ public class V1_10MetadataFactory extends V1_9MetadataFactory {
|
|||
|
||||
@Override
|
||||
public EntityData noGravity() {
|
||||
return new EntityData(5, EntityDataTypes.BOOLEAN, true);
|
||||
return newEntityData(5, EntityDataTypes.BOOLEAN, true);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -13,8 +13,8 @@ public class V1_13MetadataFactory extends V1_10MetadataFactory {
|
|||
@Override
|
||||
public Collection<EntityData> name(Component name) {
|
||||
return ListUtil.immutableList(
|
||||
new EntityData(2, EntityDataTypes.OPTIONAL_COMPONENT, Optional.of(AdventureSerializer.getGsonSerializer().serialize(name))),
|
||||
new EntityData(3, EntityDataTypes.BOOLEAN, true)
|
||||
newEntityData(2, EntityDataTypes.OPTIONAL_COMPONENT, Optional.of(AdventureSerializer.getGsonSerializer().serialize(name))),
|
||||
newEntityData(3, EntityDataTypes.BOOLEAN, true)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,10 +3,8 @@ package lol.pyr.znpcsplus.metadata;
|
|||
import com.github.retrooper.packetevents.protocol.entity.data.EntityData;
|
||||
|
||||
public class V1_15MetadataFactory extends V1_14MetadataFactory {
|
||||
|
||||
@Override
|
||||
public EntityData cape(boolean enabled) {
|
||||
return createCape(16, enabled);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package lol.pyr.znpcsplus.metadata;
|
||||
|
||||
import com.github.retrooper.packetevents.protocol.entity.data.EntityData;
|
||||
import com.github.retrooper.packetevents.protocol.entity.data.EntityDataType;
|
||||
import com.github.retrooper.packetevents.protocol.entity.data.EntityDataTypes;
|
||||
import com.github.retrooper.packetevents.util.adventure.AdventureSerializer;
|
||||
import lol.pyr.znpcsplus.util.list.ListUtil;
|
||||
|
@ -21,14 +22,14 @@ public class V1_8MetadataFactory implements MetadataFactory {
|
|||
|
||||
@Override
|
||||
public EntityData effects(boolean onFire, boolean glowing, boolean invisible) {
|
||||
return new EntityData(0, EntityDataTypes.BYTE, (byte) ((onFire ? 0x01 : 0) | (invisible ? 0x20 : 0)));
|
||||
return newEntityData(0, EntityDataTypes.BYTE, (byte) ((onFire ? 0x01 : 0) | (invisible ? 0x20 : 0)));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<EntityData> name(Component name) {
|
||||
return ListUtil.immutableList(
|
||||
new EntityData(2, EntityDataTypes.STRING, AdventureSerializer.getGsonSerializer().serialize(name)),
|
||||
new EntityData(3, EntityDataTypes.BYTE, (byte) 1)
|
||||
newEntityData(2, EntityDataTypes.STRING, AdventureSerializer.getGsonSerializer().serialize(name)),
|
||||
newEntityData(3, EntityDataTypes.BYTE, (byte) 1)
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -39,14 +40,18 @@ public class V1_8MetadataFactory implements MetadataFactory {
|
|||
|
||||
@Override
|
||||
public EntityData silent(boolean enabled) {
|
||||
return new EntityData(4, EntityDataTypes.BYTE, (byte) (enabled ? 1 : 0));
|
||||
return newEntityData(4, EntityDataTypes.BYTE, (byte) (enabled ? 1 : 0));
|
||||
}
|
||||
|
||||
protected EntityData createSkinLayers(int index, boolean enabled) {
|
||||
return new EntityData(index, EntityDataTypes.BYTE, enabled ? Byte.MAX_VALUE : (byte) 0);
|
||||
return newEntityData(index, EntityDataTypes.BYTE, enabled ? Byte.MAX_VALUE : (byte) 0);
|
||||
}
|
||||
|
||||
protected EntityData createCape(int index, boolean enabled) {
|
||||
return new EntityData(index, EntityDataTypes.BYTE, (byte) (enabled ? 1 : 0));
|
||||
return newEntityData(index, EntityDataTypes.BYTE, (byte) (enabled ? 1 : 0));
|
||||
}
|
||||
|
||||
protected <T> EntityData newEntityData(int index, EntityDataType<T> type, T value) {
|
||||
return new EntityData(index, type, value);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -21,19 +21,19 @@ public class V1_9MetadataFactory extends V1_8MetadataFactory {
|
|||
|
||||
@Override
|
||||
public EntityData effects(boolean onFire, boolean glowing, boolean invisible) {
|
||||
return new EntityData(0, EntityDataTypes.BYTE, (byte) ((onFire ? 0x01 : 0) | (invisible ? 0x20 : 0) | (glowing ? 0x40 : 0)));
|
||||
return newEntityData(0, EntityDataTypes.BYTE, (byte) ((onFire ? 0x01 : 0) | (invisible ? 0x20 : 0) | (glowing ? 0x40 : 0)));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<EntityData> name(Component name) {
|
||||
return ListUtil.immutableList(
|
||||
new EntityData(2, EntityDataTypes.STRING, AdventureSerializer.getGsonSerializer().serialize(name)),
|
||||
new EntityData(3, EntityDataTypes.BOOLEAN, true)
|
||||
newEntityData(2, EntityDataTypes.STRING, AdventureSerializer.getGsonSerializer().serialize(name)),
|
||||
newEntityData(3, EntityDataTypes.BOOLEAN, true)
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public EntityData silent(boolean enabled) {
|
||||
return new EntityData(4, EntityDataTypes.BOOLEAN, enabled);
|
||||
return newEntityData(4, EntityDataTypes.BOOLEAN, enabled);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue