Search in sources :

Example 1 with NPCConditionalActions

use of mc.dragons.core.gameobject.npc.NPCConditionalActions in project DragonsOnline by UniverseCraft.

the class NPCCommand method manageBehavior.

private void manageBehavior(CommandSender sender, String[] args) {
    NPCClass npcClass = lookupNPCClass(sender, args[0]);
    if (npcClass == null)
        return;
    if (args.length == 2) {
        displayBehavior(sender, args);
        return;
    }
    NPCTrigger trigger = NPCTrigger.valueOf(args[2]);
    NPCConditionalActions behaviorsLocal = npcClass.getConditionalActions(trigger);
    NPCConditionalActions parsedBehaviors = npcClass.getConditionalActions(trigger);
    Document conditionals = npcClass.getStorageAccess().getDocument().get("conditionals", Document.class);
    List<Document> behaviors = conditionals.getList(trigger.toString(), Document.class);
    Document base = Document.parse(npcClass.getData().toJson());
    boolean changed = false;
    if (args[3].equalsIgnoreCase("add")) {
        changed = addBehavior(sender, behaviors, conditionals, trigger, npcClass, parsedBehaviors);
    } else if (args[3].equalsIgnoreCase("remove")) {
        changed = removeBehavior(sender, args, behaviors, conditionals, trigger, npcClass, parsedBehaviors);
    } else {
        changed = manageBehavior(sender, args, behaviors, conditionals, trigger, npcClass, behaviorsLocal);
    }
    if (changed) {
        AUDIT_LOG.saveEntry(npcClass, user(sender), base, "Updated behaviors");
    }
}
Also used : NPCClass(mc.dragons.core.gameobject.npc.NPCClass) NPCConditionalActions(mc.dragons.core.gameobject.npc.NPCConditionalActions) NPCTrigger(mc.dragons.core.gameobject.npc.NPCConditionalActions.NPCTrigger) Document(org.bson.Document)

Aggregations

NPCClass (mc.dragons.core.gameobject.npc.NPCClass)1 NPCConditionalActions (mc.dragons.core.gameobject.npc.NPCConditionalActions)1 NPCTrigger (mc.dragons.core.gameobject.npc.NPCConditionalActions.NPCTrigger)1 Document (org.bson.Document)1