split name metadata to avoid creating unnecessary lists
This commit is contained in:
parent
d22a8152e0
commit
e5a62ed952
5 changed files with 22 additions and 34 deletions
|
@ -4,8 +4,6 @@ import com.github.retrooper.packetevents.protocol.entity.data.EntityData;
|
|||
import com.github.retrooper.packetevents.protocol.entity.pose.EntityPose;
|
||||
import net.kyori.adventure.text.Component;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
/**
|
||||
* 1.8 <a href="https://wiki.vg/index.php?title=Entity_metadata&oldid=7415">...</a>
|
||||
* 1.9 <a href="https://wiki.vg/index.php?title=Entity_metadata&oldid=7968">...</a>
|
||||
|
@ -23,7 +21,8 @@ public interface MetadataFactory {
|
|||
EntityData skinLayers(boolean cape, boolean jacket, boolean leftSleeve, boolean rightSleeve, boolean leftLeg, boolean rightLeg, boolean hat);
|
||||
EntityData effects(boolean onFire, boolean glowing, boolean invisible, boolean usingElytra);
|
||||
EntityData silent(boolean enabled);
|
||||
Collection<EntityData> name(Component name);
|
||||
EntityData name(Component name);
|
||||
EntityData nameShown();
|
||||
EntityData noGravity();
|
||||
EntityData pose(EntityPose pose);
|
||||
EntityData shaking(boolean enabled);
|
||||
|
|
|
@ -5,16 +5,12 @@ import com.github.retrooper.packetevents.protocol.entity.data.EntityDataTypes;
|
|||
import com.github.retrooper.packetevents.util.adventure.AdventureSerializer;
|
||||
import net.kyori.adventure.text.Component;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Optional;
|
||||
|
||||
public class V1_13MetadataFactory extends V1_11MetadataFactory {
|
||||
@Override
|
||||
public Collection<EntityData> name(Component name) {
|
||||
return list(
|
||||
newEntityData(2, EntityDataTypes.OPTIONAL_COMPONENT, Optional.of(AdventureSerializer.getGsonSerializer().serialize(name))),
|
||||
newEntityData(3, EntityDataTypes.BOOLEAN, true)
|
||||
);
|
||||
public EntityData name(Component name) {
|
||||
return newEntityData(2, EntityDataTypes.OPTIONAL_COMPONENT, Optional.of(AdventureSerializer.getGsonSerializer().serialize(name)));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -8,7 +8,6 @@ import com.github.retrooper.packetevents.util.adventure.AdventureSerializer;
|
|||
import net.kyori.adventure.text.Component;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
public class V1_8MetadataFactory implements MetadataFactory {
|
||||
|
@ -23,11 +22,13 @@ public class V1_8MetadataFactory implements MetadataFactory {
|
|||
}
|
||||
|
||||
@Override
|
||||
public Collection<EntityData> name(Component name) {
|
||||
return list(
|
||||
newEntityData(2, EntityDataTypes.STRING, AdventureSerializer.getLegacyGsonSerializer().serialize(name)),
|
||||
newEntityData(3, EntityDataTypes.BYTE, (byte) 1)
|
||||
);
|
||||
public EntityData name(Component name) {
|
||||
return newEntityData(2, EntityDataTypes.STRING, AdventureSerializer.getLegacyGsonSerializer().serialize(name));
|
||||
}
|
||||
|
||||
@Override
|
||||
public EntityData nameShown() {
|
||||
return newEntityData(3, EntityDataTypes.BYTE, (byte) 1);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -80,11 +81,4 @@ public class V1_8MetadataFactory implements MetadataFactory {
|
|||
protected <T> EntityData newEntityData(int index, EntityDataType<T> type, T value) {
|
||||
return new EntityData(index, type, value);
|
||||
}
|
||||
|
||||
@SafeVarargs
|
||||
protected final <T> List<T> list(T... items) {
|
||||
ArrayList<T> list = new ArrayList<>(items.length);
|
||||
for (int i = 0; i < items.length; i++) list.add(i, items[i]);
|
||||
return list;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,8 +5,6 @@ import com.github.retrooper.packetevents.protocol.entity.data.EntityDataTypes;
|
|||
import com.github.retrooper.packetevents.util.adventure.AdventureSerializer;
|
||||
import net.kyori.adventure.text.Component;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
public class V1_9MetadataFactory extends V1_8MetadataFactory {
|
||||
@Override
|
||||
public EntityData skinLayers(boolean cape, boolean jacket, boolean leftSleeve, boolean rightSleeve, boolean leftLeg, boolean rightLeg, boolean hat) {
|
||||
|
@ -24,11 +22,13 @@ public class V1_9MetadataFactory extends V1_8MetadataFactory {
|
|||
}
|
||||
|
||||
@Override
|
||||
public Collection<EntityData> name(Component name) {
|
||||
return list(
|
||||
newEntityData(2, EntityDataTypes.STRING, AdventureSerializer.getGsonSerializer().serialize(name)),
|
||||
newEntityData(3, EntityDataTypes.BOOLEAN, true)
|
||||
);
|
||||
public EntityData name(Component name) {
|
||||
return newEntityData(2, EntityDataTypes.STRING, AdventureSerializer.getGsonSerializer().serialize(name));
|
||||
}
|
||||
|
||||
@Override
|
||||
public EntityData nameShown() {
|
||||
return newEntityData(3, EntityDataTypes.BOOLEAN, true);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -145,7 +145,10 @@ public class V1_8PacketFactory implements PacketFactory {
|
|||
add(data, metadataFactory.usingItem(properties.getProperty(propertyRegistry.getByName("using_item", Boolean.class)), false, false));
|
||||
add(data, metadataFactory.potionColor(properties.getProperty(propertyRegistry.getByName("potion_color", Color.class)).asRGB()));
|
||||
add(data, metadataFactory.potionAmbient(properties.getProperty(propertyRegistry.getByName("potion_ambient", Boolean.class))));
|
||||
if (properties.hasProperty(propertyRegistry.getByName("name"))) addAll(data, metadataFactory.name(PapiUtil.set(player, properties.getProperty(propertyRegistry.getByName("name", Component.class)))));
|
||||
if (properties.hasProperty(propertyRegistry.getByName("name"))) {
|
||||
add(data, metadataFactory.name(PapiUtil.set(player, properties.getProperty(propertyRegistry.getByName("name", Component.class)))));
|
||||
add(data, metadataFactory.nameShown());
|
||||
}
|
||||
return data;
|
||||
}
|
||||
|
||||
|
@ -205,8 +208,4 @@ public class V1_8PacketFactory implements PacketFactory {
|
|||
protected void add(Map<Integer, EntityData> map, EntityData data) {
|
||||
map.put(data.getIndex(), data);
|
||||
}
|
||||
|
||||
protected void addAll(Map<Integer, EntityData> map, Collection<EntityData> data) {
|
||||
for (EntityData d : data) add(map, d);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue