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()));
}
Aggregations