Package ch.njol.skript.config

Examples of ch.njol.skript.config.Node


        }
       
        final Variations variations = new Variations();
        int num = 0;
        for (final String an : aliasNodes) {
          final Node node = aliasConfig.getMainNode().get(an);
          SkriptLogger.setNode(node);
          if (node == null) {
            Skript.error(m_section_not_found.toString(an));
            continue;
          }
          if (!(node instanceof SectionNode)) {
            Skript.error(m_not_a_section.toString(an));
            continue;
          }
          int i = 0;
          for (final Node n : (SectionNode) node) {
            if (n instanceof EntryNode) {
              i += addAliases(((EntryNode) n).getKey(), ((EntryNode) n).getValue(), variations);
            } else if (n instanceof SectionNode) {
              final String key = n.getKey();
              if (key == null) {
                assert false;
                continue;
              }
              if (!(key.startsWith("{") && key.endsWith("}"))) {
                Skript.error(m_unexpected_non_variation_section.toString());
                continue;
              }
              final HashMap<String, ItemType> vs = new HashMap<String, ItemType>();
              for (final Node a : (SectionNode) n) {
                if (a instanceof SectionNode) {
                  Skript.error(m_unexpected_section.toString());
                  continue;
                } else if (!(a instanceof EntryNode)) {
                  continue;
                }
                final boolean noDefault = ((EntryNode) a).getValue().isEmpty() && ((EntryNode) a).getKey().equalsIgnoreCase("{default}");
                final ItemType t = noDefault ? null : parseAlias(((EntryNode) a).getValue());
                if (t != null || noDefault)
                  vs.put(Noun.normalizePluralMarkers(((EntryNode) a).getKey()), t);
              }
              variations.put(key.substring(1, key.length() - 1), vs);
            }
          }
          if (Skript.logVeryHigh())
            Skript.info(m_loaded_x_aliases_from.toString(i, node.getKey()));
          num += i;
        }
        SkriptLogger.setNode(null);
       
        if (Skript.logNormal())
View Full Code Here


    assert used : message + from;
  }
 
  @Override
  public String toString() {
    final Node n = node;
    if (n == null || level.intValue() < Level.WARNING.intValue())
      return message;
    final Config c = n.getConfig();
    return message + from + " (" + c.getFileName() + ", line " + n.getLine() + ": " + n.save().trim() + "')";
  }
View Full Code Here

                  sender.sendMessage("file creation failed. bad filename?");
                }
              }
            }
          } else if (p.first.equals("s") || p.first.equals("select")) {
            final Node n = node.getNode(p.second);
            if (n == null)
              sender.sendMessage("invalid node in '" + p.second + "'");
            else
              node = n;
          } else if (p.first.equals("save")) {
            save = true;
          } else if (p.first.equals("a") || p.first.equals("accept")) {
            answered = true;
            answer = true;
            continue;
          } else if (p.first.matches("v+")) {
            v = Verbosity.values()[Math.max(p.first.length(), Verbosity.values().length - 1)];
          }
          answered = false;// --a will only skip the question(s) of the next option or the main action if it's the last option.
          answer = false;
        }
       
        // --- ACTIONS ---
       
        if (action != null) {
          if (action.equals("e") || action.equals("enable")
              || action.equals("d") || action.equals("disable")) {
            final boolean enable = action.startsWith("e");
            final String prefix = (enable ? "en" : "dis");
            if (node.getParent() == null) {
              if (enable ^ !config.isEnabled()) {
                sender.sendMessage("file is already " + prefix + "abled");
                return;
              }
              if (!answered)
                sender.sendMessage(prefix + "abling the file will rename the file on the disk. Do you want to continue?");
              if (waitForAnswer()) {
                if (config.setEnabled(enable)) {
                  sender.sendMessage("file " + prefix + "abled");
                } else {
                  if (new File(config.getFile(), enable ? config.getFileName().substring(1) : "-" + config.getFileName()).exists()) {
                    sender.sendMessage("could not " + prefix + "able the file because a file with that name already exists");
                  } else {
                    sender.sendMessage("could not " + prefix + "able the file.");
                  }
                }
              }
            } else {
              if (node instanceof EntryNode) {
                node.rename(node.getName().startsWith("-") ? node.getName().substring(1) : "-" + node.getName());
                sender.sendMessage("node " + prefix + "abled");
              }
            }
          } else if (action.equals("s") || action.equals("save")) {
            save = true;
          } else if (action.equals("a") || action.equals("add")
              || action.equals("n") || action.equals("new")) {
            final String[] params = actionParams.split(":", 2);
            if (params.length < 2) {
              sender.sendMessage("usage: /s n key:value|group:");
              return;
            }
            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")) {
            if (actionParams.isEmpty()) {
              sender.sendMessage("usage: /s r new name");
              return;
            }
            final String oldname = node.getName();
            node.rename(actionParams);
            sender.sendMessage("renamed " + oldname + " to " + node.getName());
          } else if (action.equals("d") || action.equals("delete")) {
            if (!answered)
              sender.sendMessage("do you really want to delete this node?");
            if (waitForAnswer()) {
              node.delete();
            }
          } else if (action.equals("m") || action.equals("move")) {
            if (actionParams.isEmpty()) {
              sender.sendMessage("usage: /s m +move down|-move up|index to insert after|parent node");
            }
            if (actionParams.matches("-[0-9]+")) {
              node.getParent().moveDelta(Integer.parseInt(actionParams));
            } else if (actionParams.matches("\\+[0-9]+")) {
              node.getParent().moveDelta(Integer.parseInt(actionParams.substring(1)));
            } else if (actionParams.matches("[0-9]+")) {
              node.getParent().move(Integer.parseInt(actionParams));
            } else {
              final Node n = node.getNode(actionParams, true);
              if (n == null) {
                sender.sendMessage("invalid path");
                return;
              }
              if (!(n instanceof SectionNode)) {
                node.move((SectionNode) n);
              } else {
                node.move(n.getParent());
                node.move(n.getParent().getNodeList().indexOf(n) + 1);
              }
            }
          } else if (action.equals("l") || action.equals("list")) {
            if (!(node instanceof SectionNode)) {
              sender.sendMessage("selected node is not a section, switching to parent node");
              node = node.getParent();
            }
            int page = 1;
            try {
              page = Math.min((int) Math.ceil(((SectionNode) node).getNodeList().size() / CommandHandler.linesPerPage), Math.max(1, Integer.parseInt(actionParams)));
            } catch (final NumberFormatException e) {}
            sender.sendMessage("&8== subnodes of "
                + node.getName()
                + " (page "
                + page
                + " of "
                + Math.ceil((((SectionNode) node).getNodeList().size() - (v.compareTo(Verbosity.HIGH) >= 0 ? ((SectionNode) node).getNumVoidNodes() : 0))
                    / CommandHandler.linesPerPage) + ")");
            int j = 0;
            for (int i = (page - 1) * CommandHandler.linesPerPage; j < CommandHandler.linesPerPage; i++) {
              final Node n = ((SectionNode) node).getNodeList().get(i);
              if (v.compareTo(Verbosity.HIGH) >= 0 && n instanceof VoidNode) {
                continue;
              }
              j++;
              String s;
              if (n.isVoid()) {
                s = n.getOrig();
              } else {
                s = n.getName();
                if (v.compareTo(Verbosity.NORMAL) >= 0) {
                  if (node instanceof EntryNode)
                    s += ": " + ((EntryNode) n).getValue();
                  else if (node instanceof SectionNode)
                    s += " [" + ((SectionNode) n).getNodeList().size() + " subnodes]";
View Full Code Here

    assert storages.isEmpty();
   
    final Config c = SkriptConfig.getConfig();
    if (c == null)
      throw new SkriptAPIException("Cannot load variables before the config");
    final Node databases = c.getMainNode().get("databases");
    if (databases == null || !(databases instanceof SectionNode)) {
      Skript.error("The config is missing the required 'databases' section that defines where the variables are saved");
      return false;
    }
   
View Full Code Here

TOP

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

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.