-
Notifications
You must be signed in to change notification settings - Fork 0
File Module
mega12345mega edited this page Jul 26, 2025
·
2 revisions
This module allows you to read and write to a .db file programmatically.
File file = new File("stuff.db");
boolean newDatabase = !file.exists();
try (NBTDatabase database = new NBTDatabase(file)) { // Opens a database, creating a new one if it doesn't exist
if (newDatabase) {
database.getConfigManager().setMaxNbtSize(Integer.MAX_VALUE);
}
long newEntryId = database.addEntry("New Entry", Files.readAllBytes(...), Entry.Type.ITEM, 123, UUID.fromString(...), "username", true);
database.editEntry(newEntryId, Optional.empty(), Optional.empty(), Optional.empty(), Optional.empty(), Optional.empty(), Optional.empty("new username"), Optional.empty());
Entry newEntry = database.getEntry(newEntryId);
List<Entry> entries = database.getEntries(new EntryFilter().filterByType(Entry.Type.ITEM), new EntryView().setOrder(EntryView.Order.NAME));
database.removeEntry(entries.get(0).getId());
database.addTag("New Tag", 0xFFAA00);
database.editTag("New Tag", Optional.of("Renamed Tag"), Optional.empty());
database.addTagToEntry(newEntryId, "Renamed Tag");
database.removeTagFromEntry(entries.get(1).getId(), "Old Tag");
database.removeTag("Old Tag");
}
Modify the config with NBTDatabase#getConfigManager(). You can get a copy of the config values in a Config with ConfigManager#getConfig(), but to save changes you will have to call ConfigManager#setConfig(Config). You can also modify specific options directly (such as ConfigManager#setMaxNbtSize(int)). Here are all of the options:
- max_nbt_size (default = 1048576): The maximum size of an entry's NBT, in bytes (checks against the supplied data, not the compressed data; if an entry only fits when compressed, make sure to compress it before passing it into
NBTDatabase#addEntryorNBTDatabase#editEntry) - max_num_results (default = 100): The maximum number of entries that can be returned by
NBTDatabase#getEntries