Coder Social home page Coder Social logo

thenullicorn / nedit Goto Github PK

View Code? Open in Web Editor NEW
25.0 1.0 5.0 617 KB

A simple, lightweight NBT parsing library

Home Page: https://nedit.docs.nullicorn.me

License: MIT License

Java 97.87% Kotlin 2.13%
nbt nbt-library hypixel nbt-parser nbt-api nedit

nedit's Introduction

Nedit

Nedit is a simple, lightweight NBT parsing library with support for plain, gzipped, and base64 encoded NBT data. One usage of this library is for parsing SkyBlock inventory data returned from the Hypixel API (more info here).

Installation

Maven

Add the following inside your <dependencies></dependencies> block:

<dependency>
    <groupId>me.nullicorn</groupId>
    <artifactId>Nedit</artifactId>
    <version>2.2.0</version>
</dependency>

Gradle

Kotlin DSL

In your build.gradle.kts's dependencies {} block, add the following dependency:

implementation("me.nullicorn:Nedit:2.2.0")

Groovy DSL

In your build.gradle's dependencies {} block, add the following dependency:

implementation 'me.nullicorn:Nedit:2.2.0'

Usage

To parse NBT data, Nedit provides you with the NBTReader class, which can be used like so:

NBTCompound result = NBTReader.readBase64("CgALaGVsbG8gd29ybGQIAARuYW1lAAlCYW5hbnJhbWEA");
System.out.println("Full Result:  " + result);

// Full Result:  {hello world:{name:"Bananrama"}}

NBT compounds are essentially just maps of strings to values. Because of this, NBTCompound extends java.util.Map, and you can use any normal mapping functions to retireve and modify data within the compound.

NBTCompound also provides a layer of null-safety when accessing deeply-nested fields whose parent objects may be null. Accessors for primitives (int, boolean, float, etc) and Strings also accept a default value in case the requested field isn't found.

Example (extending the previous one):

System.out.println("Name: " + result.getString("hello world.name", "(Not Found!)"));

// Name: Bananrama

Like with getString(key, defaultValue), NBTCompound also has methods for getting integers, floats, lists, nested compounds, and any other NBT datatype.

The "key" parameter of these methods is simply a dot-separated path to a field. This allows for developers to easily access deeply nested fields without having to check for null at each level. Some examples of this format include:

  • "user.id"
  • "hello world.name" (notice it may include spaces)
  • "message.channel.server.creator"
  • "player.stats.wins"

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.