Coder Social home page Coder Social logo

mcmoonlakedev / moonlakenbt Goto Github PK

View Code? Open in Web Editor NEW
3.0 2.0 1.0 49 KB

Minecraft MoonLake NBT Lib

License: GNU General Public License v3.0

Java 100.00%
minecraft-moonlake moonlake minecraft minecraft-nbt library api minecraft-api gplv3 nbt

moonlakenbt's People

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

ammarx

moonlakenbt's Issues

Getting only a specific field data

I have to basically read the Minecraft servers.dat file, which is located in the .minecraft folder.
I was able to get the following output

{ip:"dev.tagcraftmc.com",name:"Minecraft Server",icon:"big text here"}
{ip:"play.network.com",name:"Minecraft Server"}
{ip:"123",name:"Minecraft Server"}

using:

try {
    File file = new File("C:\\Users\\ammar\\AppData\\Roaming\\.minecraft\\servers.dat");
    NBTTagCompound root = NBTUtil.readFile(file, false);
    System.out.println("read: " + root);
    for (NBTBase servers : root.getList("servers")) {
        System.out.println(servers);
    }
} catch (IOException e) {
    e.printStackTrace();
}

However I wanted to ask, is there a way I can get IPs only to print?

P.S. I recently found your project and I have to say, this is totally amazing!

odd behavior of writing NBT data

I have a function which writes to the servers.dat file in the minecraft directory:

static void testWrite() {
        
        System.out.println("WRITE TEST");
        NBTTagCompound root = new NBTTagCompound();
        NBTTagList<NBTTagCompound> server = new NBTTagList<>("servers");
        NBTTagCompound data = new NBTTagCompound();
        data.setString("name", "name1");
        data.setString("ip", "dev.tagcraftmc.com");
        server.add(data);
        server.add(data);
        
        data.setString("name", "name2");
        data.setString("ip", "dev.tagcraftmc.com");
        server.add(data);
        root.put(server);
        System.out.println(root.toString());
        try {
            NBTUtil.writeFile(root, new File("C:\\Users\\ammar\\AppData\\Roaming\\.minecraft\\servers.dat"), false);
        } catch (IOException e) {
            e.printStackTrace();
        }
}

The expected out should be:
{servers:[0:{ip:"dev.tagcraftmc.com",name:"name1"},1:{ip:"dev.tagcraftmc.com",name:"name1"},2:{ip:"dev.tagcraftmc.com",name:"name2"}]}

While I seem to be getting:
{servers:[0:{ip:"dev.tagcraftmc.com",name:"name2"},1:{ip:"dev.tagcraftmc.com",name:"name2"},2:{ip:"dev.tagcraftmc.com",name:"name2"}]}

It seems like the new data is replacing all the old data. Am I doing something wrong over here or is this a bug?

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.