make property suggestions work

This commit is contained in:
Pyrbu 2023-05-11 07:14:39 +01:00
parent d9486acbd2
commit 74af9522ae
2 changed files with 5 additions and 4 deletions

@ -28,7 +28,7 @@ dependencies {
implementation "com.github.retrooper.packetevents:spigot:2.0.0-SNAPSHOT" implementation "com.github.retrooper.packetevents:spigot:2.0.0-SNAPSHOT"
implementation "space.arim.dazzleconf:dazzleconf-ext-snakeyaml:1.2.1" implementation "space.arim.dazzleconf:dazzleconf-ext-snakeyaml:1.2.1"
implementation "lol.pyr:director-adventure:2.0.6" implementation "lol.pyr:director-adventure:2.0.7"
implementation project(":api") implementation project(":api")
} }

@ -8,6 +8,7 @@ import lol.pyr.znpcsplus.npc.NpcEntryImpl;
import lol.pyr.znpcsplus.npc.NpcImpl; import lol.pyr.znpcsplus.npc.NpcImpl;
import lol.pyr.znpcsplus.npc.NpcRegistryImpl; import lol.pyr.znpcsplus.npc.NpcRegistryImpl;
import net.kyori.adventure.text.Component; import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.format.NamedTextColor;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
@ -24,13 +25,13 @@ public class PropertiesCommand implements CommandHandler {
// TODO: implement all the parsers for the types used in EntityPropertyImpl // TODO: implement all the parsers for the types used in EntityPropertyImpl
Object value = context.parse(property.getType()); Object value = context.parse(property.getType());
npc.UNSAFE_setProperty(property, value); npc.UNSAFE_setProperty(property, value);
context.send(Component.text("Set property " + property.getName() + " for NPC " + entry.getId() + " to " + value.toString())); context.send(Component.text("Set property " + property.getName() + " for NPC " + entry.getId() + " to " + value.toString(), NamedTextColor.GREEN));
} }
@Override @Override
public List<String> suggest(CommandContext context) throws CommandExecutionException { public List<String> suggest(CommandContext context) throws CommandExecutionException {
if (context.argSize() == 1) return context.suggestCollection(NpcRegistryImpl.get().modifiableIds()); if (context.argSize() == 1) return context.suggestCollection(NpcRegistryImpl.get().modifiableIds());
if (context.argSize() == 2) return context.suggestStream(context.suggestionParse(1, NpcEntryImpl.class) if (context.argSize() == 2) return context.suggestStream(context.suggestionParse(0, NpcEntryImpl.class)
.getNpc().getType().getAllowedProperties().stream().map(EntityPropertyImpl::getName)); .getNpc().getType().getAllowedProperties().stream().map(EntityPropertyImpl::getName));
return Collections.emptyList(); return Collections.emptyList();
} }