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);
|
MojangSkinCache skinCache = new MojangSkinCache(configManager);
|
||||||
EntityPropertyRegistryImpl propertyRegistry = new EntityPropertyRegistryImpl(skinCache, configManager);
|
EntityPropertyRegistryImpl propertyRegistry = new EntityPropertyRegistryImpl(skinCache, configManager);
|
||||||
PacketFactory packetFactory = setupPacketFactory(scheduler, propertyRegistry, configManager);
|
PacketFactory packetFactory = setupPacketFactory(scheduler, propertyRegistry, configManager);
|
||||||
propertyRegistry.registerTypes(packetFactory);
|
propertyRegistry.registerTypes(packetFactory, textSerializer);
|
||||||
|
|
||||||
ActionRegistry actionRegistry = new ActionRegistry();
|
ActionRegistry actionRegistry = new ActionRegistry();
|
||||||
NpcTypeRegistryImpl typeRegistry = new NpcTypeRegistryImpl();
|
NpcTypeRegistryImpl typeRegistry = new NpcTypeRegistryImpl();
|
||||||
|
|
|
@ -21,6 +21,7 @@ import lol.pyr.znpcsplus.entity.serializers.*;
|
||||||
import lol.pyr.znpcsplus.packets.PacketFactory;
|
import lol.pyr.znpcsplus.packets.PacketFactory;
|
||||||
import lol.pyr.znpcsplus.skin.cache.MojangSkinCache;
|
import lol.pyr.znpcsplus.skin.cache.MojangSkinCache;
|
||||||
import lol.pyr.znpcsplus.util.*;
|
import lol.pyr.znpcsplus.util.*;
|
||||||
|
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
|
||||||
import org.bukkit.Color;
|
import org.bukkit.Color;
|
||||||
import org.bukkit.DyeColor;
|
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();
|
ServerVersion ver = PacketEvents.getAPI().getServerManager().getVersion();
|
||||||
boolean legacyBooleans = ver.isOlderThan(ServerVersion.V_1_9);
|
boolean legacyBooleans = ver.isOlderThan(ServerVersion.V_1_9);
|
||||||
boolean legacyNames = 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, "hand", EquipmentSlot.MAIN_HAND));
|
||||||
register(new EquipmentProperty(packetFactory, "offhand", EquipmentSlot.OFF_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 DummyProperty<>("display_name", String.class));
|
||||||
register(new DinnerboneProperty(legacyNames, optionalComponents));
|
register(new DinnerboneProperty(legacyNames, optionalComponents));
|
||||||
|
|
||||||
|
|
|
@ -19,11 +19,9 @@ public class DinnerboneProperty extends EntityPropertyImpl<Boolean> {
|
||||||
public DinnerboneProperty(boolean legacy, boolean optional) {
|
public DinnerboneProperty(boolean legacy, boolean optional) {
|
||||||
super("dinnerbone", false, Boolean.class);
|
super("dinnerbone", false, Boolean.class);
|
||||||
Component name = Component.text("Dinnerbone");
|
Component name = Component.text("Dinnerbone");
|
||||||
String serialized = legacy ?
|
Object serialized = legacy ? AdventureSerializer.getLegacyGsonSerializer().serialize(name) : name;
|
||||||
AdventureSerializer.getLegacyGsonSerializer().serialize(name) :
|
|
||||||
AdventureSerializer.getGsonSerializer().serialize(name);
|
|
||||||
this.serialized = optional ? Optional.of(serialized) : serialized;
|
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
|
@Override
|
||||||
|
|
|
@ -7,17 +7,20 @@ import lol.pyr.znpcsplus.entity.EntityPropertyImpl;
|
||||||
import lol.pyr.znpcsplus.entity.PacketEntity;
|
import lol.pyr.znpcsplus.entity.PacketEntity;
|
||||||
import lol.pyr.znpcsplus.util.PapiUtil;
|
import lol.pyr.znpcsplus.util.PapiUtil;
|
||||||
import net.kyori.adventure.text.Component;
|
import net.kyori.adventure.text.Component;
|
||||||
|
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
|
||||||
public class NameProperty extends EntityPropertyImpl<Component> {
|
public class NameProperty extends EntityPropertyImpl<Component> {
|
||||||
|
private final LegacyComponentSerializer legacySerializer;
|
||||||
private final boolean legacy;
|
private final boolean legacy;
|
||||||
private final boolean optional;
|
private final boolean optional;
|
||||||
|
|
||||||
public NameProperty(boolean legacy, boolean optional) {
|
public NameProperty(LegacyComponentSerializer legacySerializer, boolean legacy, boolean optional) {
|
||||||
super("name", null, Component.class);
|
super("name", null, Component.class);
|
||||||
|
this.legacySerializer = legacySerializer;
|
||||||
|
|
||||||
this.legacy = legacy;
|
this.legacy = legacy;
|
||||||
this.optional = optional;
|
this.optional = optional;
|
||||||
|
@ -27,11 +30,9 @@ public class NameProperty extends EntityPropertyImpl<Component> {
|
||||||
public void apply(Player player, PacketEntity entity, boolean isSpawned, Map<Integer, EntityData> properties) {
|
public void apply(Player player, PacketEntity entity, boolean isSpawned, Map<Integer, EntityData> properties) {
|
||||||
Component value = entity.getProperty(this);
|
Component value = entity.getProperty(this);
|
||||||
if (value != null) {
|
if (value != null) {
|
||||||
String serialized = legacy ?
|
value = PapiUtil.set(legacySerializer, player, value);
|
||||||
AdventureSerializer.getLegacyGsonSerializer().serialize(value) :
|
Object serialized = legacy ? AdventureSerializer.getLegacyGsonSerializer().serialize(value) : value;
|
||||||
AdventureSerializer.getGsonSerializer().serialize(value);
|
if (optional) properties.put(2, new EntityData(2, EntityDataTypes.OPTIONAL_ADV_COMPONENT, Optional.of(serialized)));
|
||||||
serialized = PapiUtil.set(player, serialized);
|
|
||||||
if (optional) properties.put(2, newEntityData(2, EntityDataTypes.OPTIONAL_COMPONENT, Optional.of(serialized)));
|
|
||||||
else properties.put(2, new EntityData(2, EntityDataTypes.STRING, serialized));
|
else properties.put(2, new EntityData(2, EntityDataTypes.STRING, serialized));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -24,11 +24,9 @@ public class RabbitTypeProperty extends EntityPropertyImpl<RabbitType> {
|
||||||
this.index = index;
|
this.index = index;
|
||||||
this.legacyBooleans = legacyBooleans;
|
this.legacyBooleans = legacyBooleans;
|
||||||
Component name = Component.text("Toast");
|
Component name = Component.text("Toast");
|
||||||
String serialized = legacyNames ?
|
Object serialized = legacyNames ? AdventureSerializer.getLegacyGsonSerializer().serialize(name) : name;
|
||||||
AdventureSerializer.getLegacyGsonSerializer().serialize(name) :
|
|
||||||
AdventureSerializer.getGsonSerializer().serialize(name);
|
|
||||||
this.serialized = optional ? Optional.of(serialized) : serialized;
|
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
|
@Override
|
||||||
|
|
Loading…
Reference in a new issue