implement dinnerbone property
This commit is contained in:
parent
fb95965ae6
commit
1dfb5ae541
3 changed files with 44 additions and 9 deletions
|
@ -232,7 +232,11 @@ public class EntityPropertyRegistryImpl implements EntityPropertyRegistry {
|
|||
register(new EquipmentProperty(packetFactory, "hand", EquipmentSlot.MAIN_HAND));
|
||||
register(new EquipmentProperty(packetFactory, "offhand", EquipmentSlot.OFF_HAND));
|
||||
|
||||
register(new NameProperty());
|
||||
boolean legacyName = ver.isOlderThan(ServerVersion.V_1_9);
|
||||
boolean optionalComponent = ver.isNewerThanOrEquals(ServerVersion.V_1_13);
|
||||
register(new NameProperty(legacyName, optionalComponent));
|
||||
register(new DinnerboneProperty(legacyName, optionalComponent));
|
||||
|
||||
register(new DummyProperty<>("look", false));
|
||||
register(new DummyProperty<>("skin", SkinDescriptor.class, false));
|
||||
|
||||
|
@ -253,6 +257,7 @@ public class EntityPropertyRegistryImpl implements EntityPropertyRegistry {
|
|||
register(new SimpleBitsetProperty("arms", armorStandIndex, 0x04));
|
||||
register(new SimpleBitsetProperty("base_plate", armorStandIndex, 0x08, true));
|
||||
linkProperties("small", "arms", "base_plate");
|
||||
|
||||
}
|
||||
|
||||
private void registerSerializer(PropertySerializer<?> serializer) {
|
||||
|
|
|
@ -0,0 +1,33 @@
|
|||
package lol.pyr.znpcsplus.entity.properties;
|
||||
|
||||
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.entity.EntityPropertyImpl;
|
||||
import lol.pyr.znpcsplus.entity.PacketEntity;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
|
||||
public class DinnerboneProperty extends EntityPropertyImpl<Boolean> {
|
||||
private final Object serialized;
|
||||
private final EntityDataType<?> type;
|
||||
|
||||
public DinnerboneProperty(boolean legacy, boolean optional) {
|
||||
super("dinnerbone", false, Boolean.class);
|
||||
Component name = Component.text("Dinnerbone");
|
||||
String serialized = legacy ?
|
||||
AdventureSerializer.getLegacyGsonSerializer().serialize(name) :
|
||||
AdventureSerializer.getGsonSerializer().serialize(name);
|
||||
this.serialized = optional ? Optional.of(serialized) : serialized;
|
||||
this.type = optional ? EntityDataTypes.OPTIONAL_COMPONENT : EntityDataTypes.STRING;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void apply(Player player, PacketEntity entity, boolean isSpawned, Map<Integer, EntityData> properties) {
|
||||
properties.put(2, new EntityData(2, type, entity.getProperty(this) ? serialized : null));
|
||||
}
|
||||
}
|
|
@ -1,7 +1,5 @@
|
|||
package lol.pyr.znpcsplus.entity.properties;
|
||||
|
||||
import com.github.retrooper.packetevents.PacketEvents;
|
||||
import com.github.retrooper.packetevents.manager.server.ServerVersion;
|
||||
import com.github.retrooper.packetevents.protocol.entity.data.EntityData;
|
||||
import com.github.retrooper.packetevents.protocol.entity.data.EntityDataTypes;
|
||||
import com.github.retrooper.packetevents.util.adventure.AdventureSerializer;
|
||||
|
@ -15,14 +13,13 @@ import java.util.Optional;
|
|||
|
||||
public class NameProperty extends EntityPropertyImpl<Component> {
|
||||
private final boolean legacy;
|
||||
private final boolean optionalComponent;
|
||||
private final boolean optional;
|
||||
|
||||
public NameProperty() {
|
||||
public NameProperty(boolean legacy, boolean optional) {
|
||||
super("name", null, Component.class);
|
||||
|
||||
ServerVersion version = PacketEvents.getAPI().getServerManager().getVersion();
|
||||
legacy = version.isOlderThan(ServerVersion.V_1_9);
|
||||
optionalComponent = version.isNewerThanOrEquals(ServerVersion.V_1_13);
|
||||
this.legacy = legacy;
|
||||
this.optional = optional;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -32,7 +29,7 @@ public class NameProperty extends EntityPropertyImpl<Component> {
|
|||
String serialized = legacy ?
|
||||
AdventureSerializer.getLegacyGsonSerializer().serialize(value) :
|
||||
AdventureSerializer.getGsonSerializer().serialize(value);
|
||||
if (optionalComponent) properties.put(2, newEntityData(2, EntityDataTypes.OPTIONAL_COMPONENT, Optional.of(serialized)));
|
||||
if (optional) properties.put(2, newEntityData(2, EntityDataTypes.OPTIONAL_COMPONENT, Optional.of(serialized)));
|
||||
else properties.put(2, newEntityData(2, EntityDataTypes.STRING, serialized));
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue