Coder Social home page Coder Social logo

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"

nedit's People

Contributors

greenjon902 avatar puregero avatar thenullicorn avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

nedit's Issues

PET NBT's have extra backslash

"ExtraAttributes": {
	"petInfo": "{\"type\":\"MITHRIL_GOLEM\",\"active\":false,\"exp\":3.961572138967391E7,\"tier\":\"LEGENDARY\",\"hideInfo\":false,\"heldItem\":\"PET_ITEM_SPOOKY_CUPCAKE\",\"candyUsed\":2,\"uuid\":\"7f7c90ba-8e02-4ea7-a840-92f2f6dffdf5\"}",

PET NBT's have problem. They have extra backslash.

Dungeon Item Stars => §6?

This is example data which i edit to JSON manually on Notepad++. Can you solve this please? Dungeon Star is looking like question mark.

{
	"i": {
		"id": "301s",
		"Count": "1b",
		"tag": {
			"ench": "{lvl:3s,id:8s}",
			"Unbreakable": "1b",
			"HideFlags": "254",
			"display": {
				"Lore": [
					"§7Gear Score: §d796 §8(2791)",
					"§7Strength: §c+35 §9(Ancient +35) §8(+131.25)",
					"§7Crit Chance: §c+15% §9(Ancient +15%) §8(+22.5%)",
					"§7Crit Damage: §c+33% §9(Ancient +33%) §8(+123.75%)",
					"",
					"§7Health: §a+287 HP §e(+60 HP) §9(Ancient +7 HP) §8(+1,076.25 HP)",
					"§7Defense: §a+117 §e(+30) §9(Ancient +7) §8(+438.75)",
					"§7Intelligence: §a+275 §9(Ancient +25) §8(+1,031.25)",
					"",
					"§9§d§lLast Stand V, §9Depth Strider III",
					"§9Feather Falling X, §9Growth V",
					"§9Protection V, §9Rejuvenate V",
					"",
					"§6Full Set Bonus: Witherborn",
					"§7Spawns a wither minion every",
					"§7§e30 §7seconds up to a maximum",
					"§7§a1 §7wither. Your withers will",
					"§7travel to and explode on nearby",
					"§7enemies.",
					"",
					"§7Reduces the damage you take from",
					"§7withers by §c10%§7.",
					"",
					"§9Ancient Bonus",
					"§7Grants §a+1 §9? Crit Damage",
					"§9§7per §cCatacombs §7level.",
					"",
					"§d§l§ka§r §d§l§d§lMYTHIC DUNGEON BOOTS §d§l§ka"
				],
				"color": "1889508",
				"Name": "§dAncient Storm's Boots §6?§6?§6?§6?§6?"
			},
			"ExtraAttributes": {
				"rarity_upgrades": "1",
				"hot_potato_count": "15",
				"color": "28:212:228",
				"modifier": "ancient",
				"dungeon_item_level": "5",
				"originTag": "WISE_WITHER_BOOTS",
				"id": "WISE_WITHER_BOOTS",
				"enchantments": {
					"depth_strider": "3",
					"ultimate_last_stand": "5",
					"feather_falling": "10",
					"rejuvenate": "5",
					"protection": "5",
					"growth": "5"
				},
				"uuid": "836ecb04-ba3a-4ffc-8970-ae0db159cc9f",
				"timestamp": "12/19/20 8:45 AM"
			}
		},
		"Damage": "0s"
	}
}

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.