Package ch.njol.skript.config

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


          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

      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

            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

   
    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

TOP

Related Classes of ch.njol.skript.config.SectionNode

Copyright © 2018 www.massapicom. 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.