partial implementation of target npc property

This commit is contained in:
D3v1s0m 2023-09-10 15:26:47 +05:30
parent ddbdd8f78c
commit 1010a18e71
No known key found for this signature in database
GPG Key ID: FA1F770C7B1D40C1
4 changed files with 55 additions and 1 deletions

@ -113,6 +113,10 @@ public class PropertySetCommand implements CommandHandler {
valueName = String.valueOf(value); valueName = String.valueOf(value);
} }
} }
else if (type == NpcEntryImpl.class) {
value = context.parse(type);
valueName = value == null ? "NONE" : ((NpcEntryImpl) value).getId();
}
else { else {
value = context.parse(type); value = context.parse(type);
valueName = String.valueOf(value); valueName = String.valueOf(value);

@ -0,0 +1,29 @@
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 lol.pyr.znpcsplus.npc.NpcEntryImpl;
import org.bukkit.entity.Player;
import java.util.Map;
public class TargetNpcProperty extends EntityPropertyImpl<NpcEntryImpl> {
private final int index;
public TargetNpcProperty(String name, int index, NpcEntryImpl defaultValue) {
super(name, defaultValue, NpcEntryImpl.class);
this.index = index;
}
@Override
public void apply(Player player, PacketEntity entity, boolean isSpawned, Map<Integer, EntityData> properties) {
NpcEntryImpl value = entity.getProperty(this);
if (value == null) return;
if (value.getNpc().getEntity().getEntityId() == entity.getEntityId()) return;
if (value.getNpc().isVisibleTo(player)) {
properties.put(index, newEntityData(index, EntityDataTypes.INT, value.getNpc().getEntity().getEntityId()));
}
}
}

@ -0,0 +1,21 @@
package lol.pyr.znpcsplus.entity.serializers;
import lol.pyr.znpcsplus.entity.PropertySerializer;
import lol.pyr.znpcsplus.npc.NpcEntryImpl;
public class TargetNpcPropertySerializer implements PropertySerializer<NpcEntryImpl> {
@Override
public String serialize(NpcEntryImpl property) {
return property.getId();
}
@Override
public NpcEntryImpl deserialize(String property) {
return null; // TODO: find a way to do this
}
@Override
public Class<NpcEntryImpl> getTypeClass() {
return NpcEntryImpl.class;
}
}

@ -329,7 +329,7 @@ public class NpcTypeRegistryImpl implements NpcTypeRegistry {
register(builder(p, "frog", EntityTypes.FROG) register(builder(p, "frog", EntityTypes.FROG)
.setHologramOffset(-1.475) .setHologramOffset(-1.475)
.addProperties("frog_variant")); .addProperties("frog_variant", "frog_target_npc"));
register(builder(p, "tadpole", EntityTypes.TADPOLE) register(builder(p, "tadpole", EntityTypes.TADPOLE)
.setHologramOffset(-1.675)); .setHologramOffset(-1.675));