partial implementation of target npc property
This commit is contained in:
parent
ddbdd8f78c
commit
1010a18e71
4 changed files with 55 additions and 1 deletions
|
@ -113,6 +113,10 @@ public class PropertySetCommand implements CommandHandler {
|
|||
valueName = String.valueOf(value);
|
||||
}
|
||||
}
|
||||
else if (type == NpcEntryImpl.class) {
|
||||
value = context.parse(type);
|
||||
valueName = value == null ? "NONE" : ((NpcEntryImpl) value).getId();
|
||||
}
|
||||
else {
|
||||
value = context.parse(type);
|
||||
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)
|
||||
.setHologramOffset(-1.475)
|
||||
.addProperties("frog_variant"));
|
||||
.addProperties("frog_variant", "frog_target_npc"));
|
||||
|
||||
register(builder(p, "tadpole", EntityTypes.TADPOLE)
|
||||
.setHologramOffset(-1.675));
|
||||
|
|
Loading…
Reference in a new issue