add explicit property remove command
This commit is contained in:
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.ActionEditCommand;
|
||||||
import lol.pyr.znpcsplus.commands.action.ActionListCommand;
|
import lol.pyr.znpcsplus.commands.action.ActionListCommand;
|
||||||
import lol.pyr.znpcsplus.commands.hologram.*;
|
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.ImportCommand;
|
||||||
import lol.pyr.znpcsplus.commands.storage.LoadAllCommand;
|
import lol.pyr.znpcsplus.commands.storage.LoadAllCommand;
|
||||||
import lol.pyr.znpcsplus.commands.storage.SaveAllCommand;
|
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("skin", new SkinCommand(skinCache, npcRegistry, typeRegistry, propertyRegistry))
|
||||||
.addSubcommand("delete", new DeleteCommand(npcRegistry, adventure))
|
.addSubcommand("delete", new DeleteCommand(npcRegistry, adventure))
|
||||||
.addSubcommand("move", new MoveCommand(npcRegistry))
|
.addSubcommand("move", new MoveCommand(npcRegistry))
|
||||||
.addSubcommand("property", new PropertyCommand(npcRegistry))
|
|
||||||
.addSubcommand("teleport", new TeleportCommand(npcRegistry))
|
.addSubcommand("teleport", new TeleportCommand(npcRegistry))
|
||||||
.addSubcommand("list", new ListCommand(npcRegistry))
|
.addSubcommand("list", new ListCommand(npcRegistry))
|
||||||
.addSubcommand("near", new NearCommand(npcRegistry))
|
.addSubcommand("near", new NearCommand(npcRegistry))
|
||||||
.addSubcommand("type", new TypeCommand(npcRegistry, typeRegistry))
|
.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("storage", new MultiCommand(loadHelpMessage("storage"))
|
||||||
.addSubcommand("save", new SaveAllCommand(npcRegistry))
|
.addSubcommand("save", new SaveAllCommand(npcRegistry))
|
||||||
.addSubcommand("reload", new LoadAllCommand(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 com.github.retrooper.packetevents.protocol.item.ItemStack;
|
||||||
import io.github.retrooper.packetevents.util.SpigotConversionUtil;
|
import io.github.retrooper.packetevents.util.SpigotConversionUtil;
|
||||||
|
@ -19,16 +19,16 @@ import org.bukkit.Color;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class PropertyCommand implements CommandHandler {
|
public class PropertySetCommand implements CommandHandler {
|
||||||
private final NpcRegistryImpl npcRegistry;
|
private final NpcRegistryImpl npcRegistry;
|
||||||
|
|
||||||
public PropertyCommand(NpcRegistryImpl npcRegistry) {
|
public PropertySetCommand(NpcRegistryImpl npcRegistry) {
|
||||||
this.npcRegistry = npcRegistry;
|
this.npcRegistry = npcRegistry;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run(CommandContext context) throws CommandExecutionException {
|
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);
|
NpcEntryImpl entry = context.parse(NpcEntryImpl.class);
|
||||||
NpcImpl npc = entry.getNpc();
|
NpcImpl npc = entry.getNpc();
|
||||||
EntityPropertyImpl<?> property = context.parse(EntityPropertyImpl.class);
|
EntityPropertyImpl<?> property = context.parse(EntityPropertyImpl.class);
|
7
plugin/src/main/resources/help-messages/property.txt
Normal file
7
plugin/src/main/resources/help-messages/property.txt
Normal file
|
@ -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 move <id>
|
||||||
<gold>* <yellow>/npc teleport <id>
|
<gold>* <yellow>/npc teleport <id>
|
||||||
|
|
||||||
<gold>* <yellow>/npc property <id> <property> <value>
|
|
||||||
<gold>* <yellow>/npc skin <id> <type> <args>
|
<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 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 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>
|
<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>
|
||||||
|
|
Loading…
Reference in a new issue