Examples of SectionNode


Examples of ch.njol.skript.config.SectionNode

          boolean forceUpdate = false;
         
          if (mc.getMainNode().get("database") != null) { // old database layout
            forceUpdate = true;
            try {
              final SectionNode oldDB = (SectionNode) mc.getMainNode().get("database");
              assert oldDB != null;
              final SectionNode newDBs = (SectionNode) newConfig.getMainNode().get(databases.key);
              assert newDBs != null;
              final SectionNode newDB = (SectionNode) newDBs.get("database 1");
              assert newDB != null;
             
              newDB.setValues(oldDB);
             
              // '.db' was dynamically added before
              final String file = newDB.getValue("file");
              assert file != null;
              if (!file.endsWith(".db"))
                newDB.set("file", file + ".db");
             
              final SectionNode def = (SectionNode) newDBs.get("default");
              assert def != null;
              def.set("backup interval", "" + mc.get("variables backup interval"));
            } catch (final Exception e) {
              Skript.error("An error occurred while trying to update the config's database section.");
              Skript.error("You'll have to update the config yourself:");
              Skript.error("Open the new config.sk as well as the created backup, and move the 'database' section from the backup to the start of the 'databases' section");
              Skript.error("of the new config (i.e. the line 'databases:' should be directly above 'database:'), and add a tab in front of every line that you just copied.");
View Full Code Here

Examples of ch.njol.skript.config.SectionNode

          if (!(cnode instanceof SectionNode)) {
            Skript.error("invalid line - all code has to be put into triggers");
            continue;
          }
         
          final SectionNode node = ((SectionNode) cnode);
          String event = node.getKey();
          if (event == null)
            continue;
         
          if (event.equalsIgnoreCase("aliases")) {
            node.convertToEntries(0, "=");
            for (final Node n : node) {
              if (!(n instanceof EntryNode)) {
                Skript.error("invalid line in aliases section");
                continue;
              }
              final ItemType t = Aliases.parseAlias(((EntryNode) n).getValue());
              if (t == null)
                continue;
              currentAliases.put(((EntryNode) n).getKey().toLowerCase(), t);
            }
            continue;
          } else if (event.equalsIgnoreCase("options")) {
            node.convertToEntries(0);
            for (final Node n : node) {
              if (!(n instanceof EntryNode)) {
                Skript.error("invalid line in options");
                continue;
              }
              currentOptions.put(((EntryNode) n).getKey(), ((EntryNode) n).getValue());
            }
            continue;
          } else if (event.equalsIgnoreCase("variables")) {
            // TODO allow to make these override existing variables
            node.convertToEntries(0, "=");
            for (final Node n : node) {
              if (!(n instanceof EntryNode)) {
                Skript.error("Invalid line in variables section");
                continue;
              }
              String name = ((EntryNode) n).getKey().toLowerCase(Locale.ENGLISH);
              if (name.startsWith("{") && name.endsWith("}"))
                name = "" + name.substring(1, name.length() - 1);
              final String var = name;
              name = StringUtils.replaceAll(name, "%(.+)?%", new Callback<String, Matcher>() {
                @Override
                @Nullable
                public String run(final Matcher m) {
                  if (m.group(1).contains("{") || m.group(1).contains("}") || m.group(1).contains("%")) {
                    Skript.error("'" + var + "' is not a valid name for a default variable");
                    return null;
                  }
                  final ClassInfo<?> ci = Classes.getClassInfoFromUserInput("" + m.group(1));
                  if (ci == null) {
                    Skript.error("Can't understand the type '" + m.group(1) + "'");
                    return null;
                  }
                  return "<" + ci.getCodeName() + ">";
                }
              });
              if (name == null) {
                continue;
              } else if (name.contains("%")) {
                Skript.error("Invalid use of percent signs in variable name");
                continue;
              }
              if (Variables.getVariable(name, null, false) != null)
                continue;
              Object o;
              final ParseLogHandler log = SkriptLogger.startParseLogHandler();
              try {
                o = Classes.parseSimple(((EntryNode) n).getValue(), Object.class, ParseContext.SCRIPT);
                if (o == null) {
                  log.printError("Can't understand the value '" + ((EntryNode) n).getValue() + "'");
                  continue;
                }
                log.printLog();
              } finally {
                log.stop();
              }
              @SuppressWarnings("null")
              final ClassInfo<?> ci = Classes.getSuperClassInfo(o.getClass());
              if (ci.getSerializer() == null) {
                Skript.error("Can't save '" + ((EntryNode) n).getValue() + "' in a variable");
                continue;
              } else if (ci.getSerializeAs() != null) {
                final ClassInfo<?> as = Classes.getExactClassInfo(ci.getSerializeAs());
                if (as == null) {
                  assert false : ci;
                  continue;
                }
                o = Converters.convert(o, as.getC());
                if (o == null) {
                  Skript.error("Can't save '" + ((EntryNode) n).getValue() + "' in a variable");
                  continue;
                }
              }
              Variables.setVariable(name, o, null, false);
            }
            continue;
          }
         
          if (!SkriptParser.validateLine(event))
            continue;
         
          if (event.toLowerCase().startsWith("command ")) {
           
            setCurrentEvent("command", CommandEvent.class);
           
            final ScriptCommand c = Commands.loadCommand(node);
            if (c != null) {
              numCommands++;
//              script.commands.add(c);
            }
           
            deleteCurrentEvent();
           
            continue;
          } else if (event.toLowerCase().startsWith("function ")) {
           
            setCurrentEvent("function", FunctionEvent.class);
           
            final Function<?> func = Functions.loadFunction(node);
            if (func != null) {
              numFunctions++;
            }
           
            deleteCurrentEvent();
           
            continue;
          }
         
          if (Skript.logVeryHigh() && !Skript.debug())
            Skript.info("loading trigger '" + event + "'");
         
          if (StringUtils.startsWithIgnoreCase(event, "on "))
            event = "" + event.substring("on ".length());
         
          event = replaceOptions(event);
         
          final NonNullPair<SkriptEventInfo<?>, SkriptEvent> parsedEvent = SkriptParser.parseEvent(event, "can't understand this event: '" + node.getKey() + "'");
          if (parsedEvent == null)
            continue;
         
          if (Skript.debug() || node.debug())
            Skript.debug(event + " (" + parsedEvent.getSecond().toString(null, true) + "):");
         
          setCurrentEvent("" + parsedEvent.getFirst().getName().toLowerCase(Locale.ENGLISH), parsedEvent.getFirst().events);
          final Trigger trigger;
          try {
View Full Code Here

Examples of ch.njol.skript.config.SectionNode

      aliases.set(0, aliases.get(0).substring(1));
    else if (aliases.get(0).isEmpty())
      aliases = new ArrayList<String>(0);
    final String permission = ScriptLoader.replaceOptions(node.get("permission", ""));
    final String permissionMessage = ScriptLoader.replaceOptions(node.get("permission message", ""));
    final SectionNode trigger = (SectionNode) node.get("trigger");
    if (trigger == null)
      return null;
    final String[] by = ScriptLoader.replaceOptions(node.get("executable by", "console,players")).split("\\s*,\\s*|\\s+(and|or)\\s+");
    int executableBy = 0;
    for (final String b : by) {
View Full Code Here

Examples of ch.njol.skript.config.SectionNode

            if (!(node instanceof SectionNode)) {
              sender.sendMessage("adding node to parent of selected node.");
              node = node.getParent();
            }
            if (params[1].isEmpty()) {
              ((SectionNode) node).getNodeList().add(node = new SectionNode(params[0], (SectionNode) node));
            } else {
              ((SectionNode) node).getNodeList().add(node = new EntryNode(params[0], params[1], (SectionNode) node));
            }
            sender.sendMessage("created & selected " + params[0]);
          } else if (action.equals("r") || action.equals("rename")) {
View Full Code Here

Examples of ch.njol.skript.config.SectionNode

   
    try {
      boolean successful = true;
      for (final Node node : (SectionNode) databases) {
        if (node instanceof SectionNode) {
          final SectionNode n = (SectionNode) node;
          final String type = n.getValue("type");
          if (type == null) {
            Skript.error("Missing entry 'type' in database definition");
            successful = false;
            continue;
          }
         
          final String name = n.getKey();
          assert name != null;
          final VariablesStorage s;
          if (type.equalsIgnoreCase("csv") || type.equalsIgnoreCase("file") || type.equalsIgnoreCase("flatfile")) {
            s = new FlatFileStorage(name);
          } else if (type.equalsIgnoreCase("mysql")) {
View Full Code Here

Examples of org.olat.ims.qti.editor.tree.SectionNode

        // fetch new object
        if (cmd.equals(CMD_TOOLS_ADD_SECTION)) {
          Section newSection = QTIEditHelper.createSection(getTranslator());
          Item newItem = QTIEditHelper.createSCItem(getTranslator());
          newSection.getItems().add(newItem);
          SectionNode scNode = new SectionNode(newSection, qtiPackage);
          ItemNode itemNode = new ItemNode(newItem, qtiPackage);
          scNode.addChild(itemNode);
          insertObject = scNode;
        } else if (cmd.equals(CMD_TOOLS_ADD_SINGLECHOICE)) insertObject = new ItemNode(QTIEditHelper.createSCItem(getTranslator()), qtiPackage);
        else if (cmd.equals(CMD_TOOLS_ADD_MULTIPLECHOICE)) insertObject = new ItemNode(QTIEditHelper.createMCItem(getTranslator()), qtiPackage);
        else if (cmd.equals(CMD_TOOLS_ADD_KPRIM)) insertObject = new ItemNode(QTIEditHelper.createKPRIMItem(getTranslator()), qtiPackage);
        else if (cmd.equals(CMD_TOOLS_ADD_FIB)) insertObject = new ItemNode(QTIEditHelper.createFIBItem(getTranslator()), qtiPackage);
View Full Code Here

Examples of org.olat.ims.qti.editor.tree.SectionNode

              Memento mem = (Memento) history.get(key);
              result.append("---+ Changes in test " + formatVariable(startedWithTitle) + ":");
              result.append(an.createChangeMessage(mem));
            }
          } else if (node instanceof SectionNode) {
            SectionNode sn = (SectionNode) node;
            String tmpKey = ((Section) sn.getUnderlyingQTIObject()).getIdent();
            String key = tmpKey + "/null/null/null";
            if (history.containsKey(key)) {
              // some section only data changed
              Memento mem = (Memento) history.get(key);
              result.append("\n---++ Section " + formatVariable(sn.getAltText()) + " changes:");
              result.append(sn.createChangeMessage(mem));
            }
          } else if (node instanceof ItemNode) {
            ItemNode in = (ItemNode) node;
            SectionNode sn = (SectionNode) in.getParent();
            String parentSectkey = ((Section) ((SectionNode) in.getParent()).getUnderlyingQTIObject()).getIdent();
            Item item = (Item) in.getUnderlyingQTIObject();
            Question question = item.getQuestion();
            String itemKey = item.getIdent();
            String prefixKey = "null/" + itemKey;
            String questionIdent = question != null ? question.getQuestion().getId() : "null";
            String key = prefixKey + "/" + questionIdent + "/null";
            StringBuilder changeMessage = new StringBuilder();
            boolean hasChanges = false;

            if (!itemMap.containsKey(itemKey)) {
              Memento questMem = null;
              Memento respMem = null;
              if (history.containsKey(key)) {
                // question changed!
                questMem = (Memento) history.get(key);
                hasChanges = true;
              }
              // if(!hasChanges){
              // check if a response changed
              // new prefix for responses
              prefixKey += "/null/";
              // list contains org.olat.ims.qti.editor.beecom.objects.Response
              List responses = question != null ? question.getResponses() : null;
              if (responses != null && responses.size() > 0) {
                // check for changes in each response
                for (Iterator iter = responses.iterator(); iter.hasNext();) {
                  Response resp = (Response) iter.next();
                  if (history.containsKey(prefixKey + resp.getIdent())) {
                    // this response changed!
                    Memento tmpMem = (Memento) history.get(prefixKey + resp.getIdent());
                    if (respMem != null) {
                      respMem = respMem.getTimestamp() > tmpMem.getTimestamp() ? tmpMem : respMem;
                    } else {
                      hasChanges = true;
                      respMem = tmpMem;
                    }
                  }
                }
              }
              // }
              // output message
              if (hasChanges) {
                Memento mem = null;
                if (questMem != null && respMem != null) {
                  // use the earlier memento
                  mem = questMem.getTimestamp() > respMem.getTimestamp() ? respMem : questMem;
                } else if (questMem != null) {
                  mem = questMem;
                } else if (respMem != null) {
                  mem = respMem;
                }
                changeMessage.append(in.createChangeMessage(mem));
                itemMap.put(itemKey, itemKey);
                if (!parentSectkey.equals(sectionKey)) {
                  // either this item belongs to a new section or no section
                  // is active
                  result.append("\n---++ Section " + formatVariable(sn.getAltText()) + " changes:");
                  result.append("\n").append(changeMessage);
                  sectionKey = parentSectkey;
                } else {
                  result.append("\n").append(changeMessage);
                }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.