diff --git a/plugin/src/main/java/lol/pyr/znpcsplus/commands/property/PropertyRemoveCommand.java b/plugin/src/main/java/lol/pyr/znpcsplus/commands/property/PropertyRemoveCommand.java index b517d74..88b6ff1 100644 --- a/plugin/src/main/java/lol/pyr/znpcsplus/commands/property/PropertyRemoveCommand.java +++ b/plugin/src/main/java/lol/pyr/znpcsplus/commands/property/PropertyRemoveCommand.java @@ -37,7 +37,7 @@ public class PropertyRemoveCommand implements CommandHandler { public List suggest(CommandContext context) throws CommandExecutionException { if (context.argSize() == 1) return context.suggestCollection(npcRegistry.getModifiableIds()); if (context.argSize() == 2) return context.suggestStream(context.suggestionParse(0, NpcEntryImpl.class) - .getNpc().getAppliedProperties().stream().filter(EntityProperty::isPlayerModifiable).map(EntityProperty::getName)); + .getNpc().getAllProperties().stream().filter(EntityProperty::isPlayerModifiable).map(EntityProperty::getName)); return Collections.emptyList(); } } diff --git a/plugin/src/main/java/lol/pyr/znpcsplus/npc/NpcImpl.java b/plugin/src/main/java/lol/pyr/znpcsplus/npc/NpcImpl.java index fb17ad4..8ee3a58 100644 --- a/plugin/src/main/java/lol/pyr/znpcsplus/npc/NpcImpl.java +++ b/plugin/src/main/java/lol/pyr/znpcsplus/npc/NpcImpl.java @@ -20,6 +20,7 @@ import org.bukkit.World; import org.bukkit.entity.Player; import java.util.*; +import java.util.stream.Collectors; public class NpcImpl extends Viewable implements Npc { private final PacketFactory packetFactory; @@ -163,9 +164,13 @@ public class NpcImpl extends Viewable implements Npc { setProperty((EntityPropertyImpl) property, (T) value); } + public Set> getAllProperties() { + return Collections.unmodifiableSet(propertyMap.keySet()); + } + @Override public Set> getAppliedProperties() { - return Collections.unmodifiableSet(propertyMap.keySet()); + return Collections.unmodifiableSet(propertyMap.keySet()).stream().filter(type::isAllowedProperty).collect(Collectors.toSet()); } public List getActions() { diff --git a/plugin/src/main/java/lol/pyr/znpcsplus/npc/NpcTypeImpl.java b/plugin/src/main/java/lol/pyr/znpcsplus/npc/NpcTypeImpl.java index 56cbd06..f072bd6 100644 --- a/plugin/src/main/java/lol/pyr/znpcsplus/npc/NpcTypeImpl.java +++ b/plugin/src/main/java/lol/pyr/znpcsplus/npc/NpcTypeImpl.java @@ -50,6 +50,10 @@ public class NpcTypeImpl implements NpcType { } } + public boolean isAllowedProperty(EntityPropertyImpl entityProperty) { + return !entityProperty.isPlayerModifiable() || allowedProperties.contains(entityProperty); + } + protected static final class Builder { private final static Logger logger = Logger.getLogger("NpcTypeBuilder"); diff --git a/plugin/src/main/java/lol/pyr/znpcsplus/storage/yaml/YamlStorage.java b/plugin/src/main/java/lol/pyr/znpcsplus/storage/yaml/YamlStorage.java index 7c676b4..0ce9aef 100644 --- a/plugin/src/main/java/lol/pyr/znpcsplus/storage/yaml/YamlStorage.java +++ b/plugin/src/main/java/lol/pyr/znpcsplus/storage/yaml/YamlStorage.java @@ -111,7 +111,7 @@ public class YamlStorage implements NpcStorage { config.set("location", serializeLocation(npc.getLocation())); config.set("type", npc.getType().getName()); - for (EntityProperty property : npc.getAppliedProperties()) try { + for (EntityProperty property : npc.getAllProperties()) try { PropertySerializer serializer = propertyRegistry.getSerializer(((EntityPropertyImpl) property).getType()); if (serializer == null) { Bukkit.getLogger().log(Level.WARNING, "Unknown serializer for property '" + property.getName() + "' for npc '" + entry.getId() + "'. skipping ...");