fix name serialization on 1.9-1.12
This commit is contained in:
parent
993127ed85
commit
18693df7cc
3 changed files with 12 additions and 7 deletions
|
@ -7,6 +7,7 @@ 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 net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.Map;
|
||||
|
@ -19,7 +20,8 @@ public class DinnerboneProperty extends EntityPropertyImpl<Boolean> {
|
|||
public DinnerboneProperty(boolean legacy, boolean optional) {
|
||||
super("dinnerbone", false, Boolean.class);
|
||||
Component name = Component.text("Dinnerbone");
|
||||
Object serialized = legacy ? AdventureSerializer.getLegacyGsonSerializer().serialize(name) : name;
|
||||
Object serialized = legacy ? AdventureSerializer.getLegacyGsonSerializer().serialize(name) :
|
||||
optional ? name : LegacyComponentSerializer.legacySection().serialize(name);
|
||||
this.serialized = optional ? Optional.of(serialized) : serialized;
|
||||
this.type = optional ? EntityDataTypes.OPTIONAL_ADV_COMPONENT : EntityDataTypes.STRING;
|
||||
}
|
||||
|
|
|
@ -15,14 +15,14 @@ import java.util.Optional;
|
|||
|
||||
public class NameProperty extends EntityPropertyImpl<Component> {
|
||||
private final LegacyComponentSerializer legacySerializer;
|
||||
private final boolean legacy;
|
||||
private final boolean legacySerialization;
|
||||
private final boolean optional;
|
||||
|
||||
public NameProperty(LegacyComponentSerializer legacySerializer, boolean legacy, boolean optional) {
|
||||
public NameProperty(LegacyComponentSerializer legacySerializer, boolean legacySerialization, boolean optional) {
|
||||
super("name", null, Component.class);
|
||||
this.legacySerializer = legacySerializer;
|
||||
|
||||
this.legacy = legacy;
|
||||
this.legacySerialization = legacySerialization;
|
||||
this.optional = optional;
|
||||
}
|
||||
|
||||
|
@ -31,12 +31,13 @@ public class NameProperty extends EntityPropertyImpl<Component> {
|
|||
Component value = entity.getProperty(this);
|
||||
if (value != null) {
|
||||
value = PapiUtil.set(legacySerializer, player, value);
|
||||
Object serialized = legacy ? AdventureSerializer.getLegacyGsonSerializer().serialize(value) : value;
|
||||
Object serialized = legacySerialization ? AdventureSerializer.getLegacyGsonSerializer().serialize(value) :
|
||||
optional ? value : LegacyComponentSerializer.legacySection().serialize(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)));
|
||||
if (legacySerialization) properties.put(3, newEntityData(3, EntityDataTypes.BYTE, (byte) (value != null ? 1 : 0)));
|
||||
else properties.put(3, newEntityData(3, EntityDataTypes.BOOLEAN, value != null));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,6 +8,7 @@ import lol.pyr.znpcsplus.entity.EntityPropertyImpl;
|
|||
import lol.pyr.znpcsplus.entity.PacketEntity;
|
||||
import lol.pyr.znpcsplus.util.RabbitType;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.Map;
|
||||
|
@ -24,7 +25,8 @@ public class RabbitTypeProperty extends EntityPropertyImpl<RabbitType> {
|
|||
this.index = index;
|
||||
this.legacyBooleans = legacyBooleans;
|
||||
Component name = Component.text("Toast");
|
||||
Object serialized = legacyNames ? AdventureSerializer.getLegacyGsonSerializer().serialize(name) : name;
|
||||
Object serialized = legacyNames ? AdventureSerializer.getLegacyGsonSerializer().serialize(name) :
|
||||
optional ? name : LegacyComponentSerializer.legacySection().serialize(name);
|
||||
this.serialized = optional ? Optional.of(serialized) : serialized;
|
||||
this.type = optional ? EntityDataTypes.OPTIONAL_ADV_COMPONENT : EntityDataTypes.STRING;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue