stop using deprecated entity data types for components
This commit is contained in:
parent
702fa3c74e
commit
f933f17e45
5 changed files with 16 additions and 18 deletions
|
@ -125,7 +125,7 @@ public class ZNpcsPlus {
|
|||
MojangSkinCache skinCache = new MojangSkinCache(configManager);
|
||||
EntityPropertyRegistryImpl propertyRegistry = new EntityPropertyRegistryImpl(skinCache, configManager);
|
||||
PacketFactory packetFactory = setupPacketFactory(scheduler, propertyRegistry, configManager);
|
||||
propertyRegistry.registerTypes(packetFactory);
|
||||
propertyRegistry.registerTypes(packetFactory, textSerializer);
|
||||
|
||||
ActionRegistry actionRegistry = new ActionRegistry();
|
||||
NpcTypeRegistryImpl typeRegistry = new NpcTypeRegistryImpl();
|
||||
|
|
|
@ -21,6 +21,7 @@ import lol.pyr.znpcsplus.entity.serializers.*;
|
|||
import lol.pyr.znpcsplus.packets.PacketFactory;
|
||||
import lol.pyr.znpcsplus.skin.cache.MojangSkinCache;
|
||||
import lol.pyr.znpcsplus.util.*;
|
||||
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
|
||||
import org.bukkit.Color;
|
||||
import org.bukkit.DyeColor;
|
||||
|
||||
|
@ -106,7 +107,7 @@ public class EntityPropertyRegistryImpl implements EntityPropertyRegistry {
|
|||
*/
|
||||
}
|
||||
|
||||
public void registerTypes(PacketFactory packetFactory) {
|
||||
public void registerTypes(PacketFactory packetFactory, LegacyComponentSerializer textSerializer) {
|
||||
ServerVersion ver = PacketEvents.getAPI().getServerManager().getVersion();
|
||||
boolean legacyBooleans = ver.isOlderThan(ServerVersion.V_1_9);
|
||||
boolean legacyNames = ver.isOlderThan(ServerVersion.V_1_9);
|
||||
|
@ -119,7 +120,7 @@ public class EntityPropertyRegistryImpl implements EntityPropertyRegistry {
|
|||
register(new EquipmentProperty(packetFactory, "hand", EquipmentSlot.MAIN_HAND));
|
||||
register(new EquipmentProperty(packetFactory, "offhand", EquipmentSlot.OFF_HAND));
|
||||
|
||||
register(new NameProperty(legacyNames, optionalComponents));
|
||||
register(new NameProperty(textSerializer, legacyNames, optionalComponents));
|
||||
register(new DummyProperty<>("display_name", String.class));
|
||||
register(new DinnerboneProperty(legacyNames, optionalComponents));
|
||||
|
||||
|
|
|
@ -19,11 +19,9 @@ public class DinnerboneProperty extends EntityPropertyImpl<Boolean> {
|
|||
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);
|
||||
Object serialized = legacy ? AdventureSerializer.getLegacyGsonSerializer().serialize(name) : name;
|
||||
this.serialized = optional ? Optional.of(serialized) : serialized;
|
||||
this.type = optional ? EntityDataTypes.OPTIONAL_COMPONENT : EntityDataTypes.STRING;
|
||||
this.type = optional ? EntityDataTypes.OPTIONAL_ADV_COMPONENT : EntityDataTypes.STRING;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -7,17 +7,20 @@ import lol.pyr.znpcsplus.entity.EntityPropertyImpl;
|
|||
import lol.pyr.znpcsplus.entity.PacketEntity;
|
||||
import lol.pyr.znpcsplus.util.PapiUtil;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
|
||||
public class NameProperty extends EntityPropertyImpl<Component> {
|
||||
private final LegacyComponentSerializer legacySerializer;
|
||||
private final boolean legacy;
|
||||
private final boolean optional;
|
||||
|
||||
public NameProperty(boolean legacy, boolean optional) {
|
||||
public NameProperty(LegacyComponentSerializer legacySerializer, boolean legacy, boolean optional) {
|
||||
super("name", null, Component.class);
|
||||
this.legacySerializer = legacySerializer;
|
||||
|
||||
this.legacy = legacy;
|
||||
this.optional = optional;
|
||||
|
@ -27,12 +30,10 @@ public class NameProperty extends EntityPropertyImpl<Component> {
|
|||
public void apply(Player player, PacketEntity entity, boolean isSpawned, Map<Integer, EntityData> properties) {
|
||||
Component value = entity.getProperty(this);
|
||||
if (value != null) {
|
||||
String serialized = legacy ?
|
||||
AdventureSerializer.getLegacyGsonSerializer().serialize(value) :
|
||||
AdventureSerializer.getGsonSerializer().serialize(value);
|
||||
serialized = PapiUtil.set(player, serialized);
|
||||
if (optional) properties.put(2, newEntityData(2, EntityDataTypes.OPTIONAL_COMPONENT, Optional.of(serialized)));
|
||||
else properties.put(2, newEntityData(2, EntityDataTypes.STRING, serialized));
|
||||
value = PapiUtil.set(legacySerializer, player, value);
|
||||
Object serialized = legacy ? AdventureSerializer.getLegacyGsonSerializer().serialize(value) : value;
|
||||
if (optional) properties.put(2, new EntityData(2, EntityDataTypes.OPTIONAL_ADV_COMPONENT, Optional.of(serialized)));
|
||||
else properties.put(2, new EntityData(2, EntityDataTypes.STRING, serialized));
|
||||
}
|
||||
|
||||
if (legacy) properties.put(3, newEntityData(3, EntityDataTypes.BYTE, (byte) (value != null ? 1 : 0)));
|
||||
|
|
|
@ -24,11 +24,9 @@ public class RabbitTypeProperty extends EntityPropertyImpl<RabbitType> {
|
|||
this.index = index;
|
||||
this.legacyBooleans = legacyBooleans;
|
||||
Component name = Component.text("Toast");
|
||||
String serialized = legacyNames ?
|
||||
AdventureSerializer.getLegacyGsonSerializer().serialize(name) :
|
||||
AdventureSerializer.getGsonSerializer().serialize(name);
|
||||
Object serialized = legacyNames ? AdventureSerializer.getLegacyGsonSerializer().serialize(name) : name;
|
||||
this.serialized = optional ? Optional.of(serialized) : serialized;
|
||||
this.type = optional ? EntityDataTypes.OPTIONAL_COMPONENT : EntityDataTypes.STRING;
|
||||
this.type = optional ? EntityDataTypes.OPTIONAL_ADV_COMPONENT : EntityDataTypes.STRING;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
Loading…
Reference in a new issue