Search in sources :

Example 1 with CommandConfigurable

use of net.citizensnpcs.api.command.CommandConfigurable in project Citizens2 by CitizensDev.

the class TraitCommands method configure.

@Command(aliases = { "traitc", "trc" }, usage = "[trait name] (flags)", desc = "Configures a trait", modifiers = { "*" }, min = 1, flags = "*", permission = "citizens.npc.trait-configure")
public void configure(CommandContext args, CommandSender sender, NPC npc) throws CommandException {
    String traitName = args.getString(0);
    if (!sender.hasPermission("citizens.npc.trait-configure." + traitName) && !sender.hasPermission("citizens.npc.trait-configure.*"))
        throw new NoPermissionsException();
    Class<? extends Trait> clazz = CitizensAPI.getTraitFactory().getTraitClass(args.getString(0));
    if (clazz == null)
        throw new CommandException(Messages.TRAIT_NOT_FOUND);
    if (!CommandConfigurable.class.isAssignableFrom(clazz))
        throw new CommandException(Messages.TRAIT_NOT_CONFIGURABLE);
    if (!npc.hasTrait(clazz))
        throw new CommandException(Messages.TRAIT_NOT_FOUND_ON_NPC);
    CommandConfigurable trait = (CommandConfigurable) npc.getTrait(clazz);
    trait.configure(args);
}
Also used : NoPermissionsException(net.citizensnpcs.api.command.exception.NoPermissionsException) CommandException(net.citizensnpcs.api.command.exception.CommandException) CommandConfigurable(net.citizensnpcs.api.command.CommandConfigurable) Command(net.citizensnpcs.api.command.Command)

Aggregations

Command (net.citizensnpcs.api.command.Command)1 CommandConfigurable (net.citizensnpcs.api.command.CommandConfigurable)1 CommandException (net.citizensnpcs.api.command.exception.CommandException)1 NoPermissionsException (net.citizensnpcs.api.command.exception.NoPermissionsException)1