Navigation

    Highlight Code Light/Dark
  • index
  • next |
  • previous |
  • Sponge 2.1-SNAPSHOT documentation »
  • Creating a Plugin »
  • Configuring Your Plugin »

Table Of Contents

  • Creating a Server
    • Getting Started
      • Installing Java
      • Migrating to Sponge
      • Choosing an Implementation
        • Sponge Coremod
        • SpongeVanilla
        • Glowstone
      • Installing Sponge
      • Creating a Launch Script
      • Port Forwarding
      • Configuring Sponge
        • Introduction to HOCON
        • JSON Syntax
        • global.conf
        • server.properties
    • Server Management
      • Managing the Whitelist
      • Managing Bans
      • Managing Permissions
      • Installing Plugins
    • Becoming an Expert Spongineer
      • Commands
      • Troubleshooting
      • Log Files
  • Preparing for Development
    • Installing the JDK
    • Installing an IDE
    • Installing a Text Editor
    • Installing Git
  • Creating a Plugin
    • Setting Up Your Workspace
      • Setting Up IntelliJ IDEA
      • Setting Up Eclipse
      • Setting Up NetBeans
      • Adding Sponge API Dependencies
    • Best Practices
    • Plugin Templates
    • Creating Your Main Plugin Class
    • Plugin Lifecycle
    • Logging and Debugging
    • Working with Text
      • Creating Text
      • The Pagination Service
    • Creating Commands
      • Building a Command
      • Argument Parsing
      • Child Commands
      • The Command Service
      • Low-Level Command API
    • Working with Events
    • The Data API
      • Using Keys
      • Data Manipulators
      • Transactions
    • Working with Blocks
      • Concepts
      • Accessing Blocks
      • Modifying Blocks
      • Working with Tile Entities
    • Working with Entities
      • Spawning an Entity
    • Working with Items
    • Configuring Your Plugin
      • Configuration Loaders
      • Configuration Nodes
      • Navigating Through Nodes
      • Giving Nodes Value
    • Dependency Injection
    • Using the Scheduler
    • Working with Databases
    • Working with the Permissions API
    • Working with Services
    • Using the Plugin Manager
    • Plugin Debugging and Hotswapping
    • Message Sinks
    • Tutorials
  • Contributing to Sponge
    • Contribution Guidelines
    • API Development
      • Git Workflow for SpongeAPI
    • Implementation Development
      • Debugging Sponge Within the IDE
      • Mixins
      • Git Workflow for Sponge implementations
    • SpongeDocs Writing
    • Porting Sponge to Other Platforms
  • About the Sponge Project
    • Introduction
    • Frequently Asked Questions
    • Plans for the Future
    • License
    • Forum Posting Guidelines
    • Forum & IRC Rules
    • Staff
    • Sponge Glossary
    • Art Assets
    • The History of Sponge
  • Download

Navigating Through Nodes¶

Note

The following discussion about paths uses a period (.) as a separator character. This is not always the character used, but it is a common way of denoting the next node in a path.

Let’s discuss how node paths work first. They’re just like file paths, a collection of nodes, separated by a single character, leading to the final child node that holds a value, whether that value be a normal value, a list, or simply another node. As an example, config.blockCheats.enabled is a path, leading to the node enabled, under blockCheats, which is under config. In a configuration file, this would appear like so:

config {
    blockCheats {
        enabled=value
    }
}

Moving Around¶

Tip

To make node retrieval easier (and to give less load on the system), it is advised to store a reference to the root node of your configuration file. This allows you to always be able to get the node using the full path, and avoids using the getPath() method, which is said to be a little intensive by official documentation.

Let’s start off by defining our root node again. We’ll be using a blank node to write on.

ConfigurationNode rootNode = loader.createEmptyNode(ConfigurationOptions.defaults());

The method to get a node from a node is the getNode(Object...) method. Note that Object... type for the parameter, as this means you cannot simply just give it a path like config.blockCheats.enabled. Doing so results in a config file like this:

config.blockCheats.enabled=value

... which is not the organized intended result we’re looking for. Instead, what you -can- do is split the path by the separator character so it ends up as separate arguments.

rootNode.getNode("config", "blockCheats", "enabled");

With that line of code, it should give us a ConfigurationNode object representative of the child node at the path of config.blockCheats.enabled. At that point, it is up to you what you want to do with it.

© Copyright 2014-2015, Sponge Contributors. Created using Sphinx 1.2.