implement silent property (untested)

This commit is contained in:
Pyrbu 2023-08-05 20:49:48 +02:00
parent 6eff7a3b6c
commit f3d5e3f3a8
2 changed files with 32 additions and 3 deletions

@ -1,5 +1,7 @@
package lol.pyr.znpcsplus.entity; package lol.pyr.znpcsplus.entity;
import com.github.retrooper.packetevents.PacketEvents;
import com.github.retrooper.packetevents.manager.server.ServerVersion;
import com.github.retrooper.packetevents.protocol.player.EquipmentSlot; import com.github.retrooper.packetevents.protocol.player.EquipmentSlot;
import lol.pyr.znpcsplus.api.entity.EntityProperty; import lol.pyr.znpcsplus.api.entity.EntityProperty;
import lol.pyr.znpcsplus.api.entity.EntityPropertyRegistry; import lol.pyr.znpcsplus.api.entity.EntityPropertyRegistry;
@ -55,9 +57,6 @@ public class EntityPropertyRegistryImpl implements EntityPropertyRegistry {
registerEnumSerializer(VillagerProfession.class); registerEnumSerializer(VillagerProfession.class);
registerEnumSerializer(VillagerLevel.class); registerEnumSerializer(VillagerLevel.class);
/* /*
registerType("silent", false);
registerType("name", Component.class);
registerType("look", false);
registerType("dinnerbone", false); registerType("dinnerbone", false);
registerType("using_item", false); // TODO: fix it for 1.8 and add new property to use offhand item and riptide animation registerType("using_item", false); // TODO: fix it for 1.8 and add new property to use offhand item and riptide animation
@ -228,6 +227,8 @@ public class EntityPropertyRegistryImpl implements EntityPropertyRegistry {
} }
public void registerTypes(PacketFactory packetFactory) { public void registerTypes(PacketFactory packetFactory) {
ServerVersion ver = PacketEvents.getAPI().getServerManager().getVersion();
register(new EquipmentProperty(packetFactory, "helmet", EquipmentSlot.HELMET)); register(new EquipmentProperty(packetFactory, "helmet", EquipmentSlot.HELMET));
register(new EquipmentProperty(packetFactory, "chestplate", EquipmentSlot.CHEST_PLATE)); register(new EquipmentProperty(packetFactory, "chestplate", EquipmentSlot.CHEST_PLATE));
register(new EquipmentProperty(packetFactory, "leggings", EquipmentSlot.LEGGINGS)); register(new EquipmentProperty(packetFactory, "leggings", EquipmentSlot.LEGGINGS));
@ -243,6 +244,8 @@ public class EntityPropertyRegistryImpl implements EntityPropertyRegistry {
register(new EffectsProperty("fire", 0x01)); register(new EffectsProperty("fire", 0x01));
register(new EffectsProperty("invisible", 0x20)); register(new EffectsProperty("invisible", 0x20));
linkProperties("glow", "fire", "invisible"); linkProperties("glow", "fire", "invisible");
register(new SimpleBooleanProperty("silent", 4, false, ver.isOlderThan(ServerVersion.V_1_9)));
} }
private void registerSerializer(PropertySerializer<?> serializer) { private void registerSerializer(PropertySerializer<?> serializer) {

@ -0,0 +1,26 @@
package lol.pyr.znpcsplus.entity.properties;
import com.github.retrooper.packetevents.protocol.entity.data.EntityData;
import com.github.retrooper.packetevents.protocol.entity.data.EntityDataTypes;
import lol.pyr.znpcsplus.entity.EntityPropertyImpl;
import lol.pyr.znpcsplus.entity.PacketEntity;
import org.bukkit.entity.Player;
import java.util.Map;
public class SimpleBooleanProperty extends EntityPropertyImpl<Boolean> {
private final int index;
private final boolean legacy;
public SimpleBooleanProperty(String name, int index, boolean defaultValue, boolean legacy) {
super(name, defaultValue, Boolean.class);
this.index = index;
this.legacy = legacy;
}
@Override
public void apply(Player player, PacketEntity entity, boolean isSpawned, Map<Integer, EntityData> properties) {
if (legacy) properties.put(index, new EntityData(index, EntityDataTypes.BYTE, (entity.getProperty(this) ? 1 : 0)));
else properties.put(index, new EntityData(index, EntityDataTypes.BOOLEAN, entity.getProperty(this)));
}
}