add explicit property remove command

This commit is contained in:
Pyrbu 2023-06-28 00:31:47 +02:00
parent d572053304
commit 6dab7a13db
5 changed files with 60 additions and 7 deletions

@ -20,6 +20,8 @@ import lol.pyr.znpcsplus.commands.action.ActionDeleteCommand;
import lol.pyr.znpcsplus.commands.action.ActionEditCommand;
import lol.pyr.znpcsplus.commands.action.ActionListCommand;
import lol.pyr.znpcsplus.commands.hologram.*;
import lol.pyr.znpcsplus.commands.property.PropertyRemoveCommand;
import lol.pyr.znpcsplus.commands.property.PropertySetCommand;
import lol.pyr.znpcsplus.commands.storage.ImportCommand;
import lol.pyr.znpcsplus.commands.storage.LoadAllCommand;
import lol.pyr.znpcsplus.commands.storage.SaveAllCommand;
@ -283,11 +285,13 @@ public class ZNpcsPlus extends JavaPlugin {
.addSubcommand("skin", new SkinCommand(skinCache, npcRegistry, typeRegistry, propertyRegistry))
.addSubcommand("delete", new DeleteCommand(npcRegistry, adventure))
.addSubcommand("move", new MoveCommand(npcRegistry))
.addSubcommand("property", new PropertyCommand(npcRegistry))
.addSubcommand("teleport", new TeleportCommand(npcRegistry))
.addSubcommand("list", new ListCommand(npcRegistry))
.addSubcommand("near", new NearCommand(npcRegistry))
.addSubcommand("type", new TypeCommand(npcRegistry, typeRegistry))
.addSubcommand("property", new MultiCommand(loadHelpMessage("property"))
.addSubcommand("set", new PropertySetCommand(npcRegistry))
.addSubcommand("remove", new PropertyRemoveCommand(npcRegistry)))
.addSubcommand("storage", new MultiCommand(loadHelpMessage("storage"))
.addSubcommand("save", new SaveAllCommand(npcRegistry))
.addSubcommand("reload", new LoadAllCommand(npcRegistry))

@ -0,0 +1,42 @@
package lol.pyr.znpcsplus.commands.property;
import lol.pyr.director.adventure.command.CommandContext;
import lol.pyr.director.adventure.command.CommandHandler;
import lol.pyr.director.common.command.CommandExecutionException;
import lol.pyr.znpcsplus.api.entity.EntityProperty;
import lol.pyr.znpcsplus.entity.EntityPropertyImpl;
import lol.pyr.znpcsplus.npc.NpcEntryImpl;
import lol.pyr.znpcsplus.npc.NpcImpl;
import lol.pyr.znpcsplus.npc.NpcRegistryImpl;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.format.NamedTextColor;
import java.util.Collections;
import java.util.List;
public class PropertyRemoveCommand implements CommandHandler {
private final NpcRegistryImpl npcRegistry;
public PropertyRemoveCommand(NpcRegistryImpl npcRegistry) {
this.npcRegistry = npcRegistry;
}
@Override
public void run(CommandContext context) throws CommandExecutionException {
context.setUsage(context.getLabel() + " property remove <id> <property>");
NpcEntryImpl entry = context.parse(NpcEntryImpl.class);
NpcImpl npc = entry.getNpc();
EntityPropertyImpl<?> property = context.parse(EntityPropertyImpl.class);
if (!npc.hasProperty(property)) context.halt(Component.text("This npc doesn't have the " + property.getName() + " property set", NamedTextColor.RED));
npc.removeProperty(property);
context.send(Component.text("Removed property " + property.getName() + " from NPC " + entry.getId(), NamedTextColor.GREEN));
}
@Override
public List<String> 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().map(EntityProperty::getName));
return Collections.emptyList();
}
}

@ -1,4 +1,4 @@
package lol.pyr.znpcsplus.commands;
package lol.pyr.znpcsplus.commands.property;
import com.github.retrooper.packetevents.protocol.item.ItemStack;
import io.github.retrooper.packetevents.util.SpigotConversionUtil;
@ -19,16 +19,16 @@ import org.bukkit.Color;
import java.util.Collections;
import java.util.List;
public class PropertyCommand implements CommandHandler {
public class PropertySetCommand implements CommandHandler {
private final NpcRegistryImpl npcRegistry;
public PropertyCommand(NpcRegistryImpl npcRegistry) {
public PropertySetCommand(NpcRegistryImpl npcRegistry) {
this.npcRegistry = npcRegistry;
}
@Override
public void run(CommandContext context) throws CommandExecutionException {
context.setUsage(context.getLabel() + " property <id> <property> <value>");
context.setUsage(context.getLabel() + " property set <id> <property> <value>");
NpcEntryImpl entry = context.parse(NpcEntryImpl.class);
NpcImpl npc = entry.getNpc();
EntityPropertyImpl<?> property = context.parse(EntityPropertyImpl.class);
@ -70,7 +70,7 @@ public class PropertyCommand implements CommandHandler {
public List<String> 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().getType().getAllowedProperties().stream().map(EntityProperty::getName));
.getNpc().getType().getAllowedProperties().stream().map(EntityProperty::getName));
if (context.argSize() >= 3) {
EntityPropertyImpl<?> property = context.suggestionParse(1, EntityPropertyImpl.class);
Class<?> type = property.getType();

@ -0,0 +1,7 @@
<gold>ZNPCsPlus <yellow>v${version} <red><click:run_command:/npc><hover:show_text:'<red>Click to view the main help message'>[BACK]</hover></click></red>
<gray>Hover over any command more info
<gold>* <yellow>/npc property set <id> <property> <value>
<gold>* <yellow>/npc property remove <id> <property>

@ -12,9 +12,9 @@
<gold>* <yellow>/npc move <id>
<gold>* <yellow>/npc teleport <id>
<gold>* <yellow>/npc property <id> <property> <value>
<gold>* <yellow>/npc skin <id> <type> <args>
<gold>* <yellow><click:run_command:/npc property><hover:show_text:'<gray>Npc property commands<br>Click to view full list'>/npc property help</hover></click>
<gold>* <yellow><click:run_command:/npc holo><hover:show_text:'<gray>Npc hologram commands<br>Click to view full list'>/npc holo help</hover></click>
<gold>* <yellow><click:run_command:/npc action><hover:show_text:'<gray>Player interaction commands<br>Click to view full list'>/npc action help</hover></click>
<gold>* <yellow><click:run_command:/npc storage><hover:show_text:'<gray>Npc data storage commands<br>Click to view full list'>/npc storage help</hover></click>