mcmoonlakedev / moonlakenbt Goto Github PK
View Code? Open in Web Editor NEWMinecraft MoonLake NBT Lib
License: GNU General Public License v3.0
Minecraft MoonLake NBT Lib
License: GNU General Public License v3.0
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!
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?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.