Search in sources :

Example 1 with ScriptTrait

use of net.citizensnpcs.trait.ScriptTrait in project Citizens2 by CitizensDev.

the class NPCCommands method script.

@Command(aliases = { "npc" }, usage = "script --add [files] --remove [files]", desc = "Controls an NPC's scripts", modifiers = { "script" }, min = 1, max = 1, permission = "citizens.npc.script")
public void script(CommandContext args, CommandSender sender, NPC npc) {
    ScriptTrait trait = npc.getTrait(ScriptTrait.class);
    if (args.hasValueFlag("add")) {
        List<String> files = new ArrayList<String>();
        for (String file : args.getFlag("add").split(",")) {
            if (!trait.validateFile(file)) {
                Messaging.sendErrorTr(sender, Messages.INVALID_SCRIPT_FILE, file);
                return;
            }
            files.add(file);
        }
        trait.addScripts(files);
    }
    if (args.hasValueFlag("remove")) {
        trait.removeScripts(Arrays.asList(args.getFlag("remove").split(",")));
    }
    Messaging.sendTr(sender, Messages.CURRENT_SCRIPTS, npc.getName(), Joiner.on("]],[[ ").join(trait.getScripts()));
}
Also used : ScriptTrait(net.citizensnpcs.trait.ScriptTrait) ArrayList(java.util.ArrayList) Command(net.citizensnpcs.api.command.Command)

Aggregations

ArrayList (java.util.ArrayList)1 Command (net.citizensnpcs.api.command.Command)1 ScriptTrait (net.citizensnpcs.trait.ScriptTrait)1