Add a comment field to mods
ADDTL; Edited the deserialization routine for mods to make it less prone to errors in the event a mod does not contain every field in the NBT data, ex. new comment field would have crashed the deserializer, causing it to skip past the mod or fully reset server settings.
This commit is contained in:
parent
82c3a8cbcb
commit
e2d64a2a9d
5 changed files with 1951 additions and 10 deletions
|
@ -10,6 +10,7 @@ class Mod {
|
|||
String mod_pak = "";
|
||||
String mod_hash = "";
|
||||
bool enabled = true;
|
||||
String comment = "";
|
||||
|
||||
bool newMod = false;
|
||||
UUID _id = UUID.ZERO;
|
||||
|
@ -27,7 +28,8 @@ class Mod {
|
|||
this.newMod = false,
|
||||
this.mod_pak = "Not Initialized",
|
||||
this.mod_hash = "",
|
||||
this.enabled = true});
|
||||
this.enabled = true,
|
||||
this.comment = ""});
|
||||
|
||||
CompoundTag serialize() {
|
||||
CompoundTag tag = CompoundTag();
|
||||
|
@ -35,6 +37,7 @@ class Mod {
|
|||
tag.put("id", LongTag.valueOf(mod_id));
|
||||
tag.put("pak", StringTag.valueOf(mod_pak));
|
||||
tag.put("hash", StringTag.valueOf(mod_hash));
|
||||
tag.put("comment", StringTag.valueOf(comment));
|
||||
NbtUtils.writeBoolean(tag, "enabled", enabled);
|
||||
|
||||
return tag;
|
||||
|
@ -43,11 +46,31 @@ class Mod {
|
|||
static Mod deserialize(CompoundTag tag) {
|
||||
CompoundTag ct = tag;
|
||||
|
||||
String modName = "undef";
|
||||
if (ct.containsKey("name")) modName = ct.get("name")!.asString();
|
||||
|
||||
int modID = 0;
|
||||
if (ct.containsKey("id")) modID = ct.get("id")!.asLong();
|
||||
|
||||
String pakFile = "Not yet initialized";
|
||||
if (ct.containsKey("pak")) pakFile = ct.get("pak")!.asString();
|
||||
|
||||
String hash = "1234ABCD";
|
||||
if (ct.containsKey("hash")) hash = ct.get("hash")!.asString();
|
||||
|
||||
bool enabled = true;
|
||||
if (ct.containsKey("enabled"))
|
||||
enabled = NbtUtils.readBoolean(tag, "enabled");
|
||||
|
||||
String comment = "";
|
||||
if (ct.containsKey("comment")) comment = ct.get("comment")!.asString();
|
||||
|
||||
return Mod(
|
||||
mod_name: ct.get("name")!.asString(),
|
||||
mod_id: ct.get("id")!.asLong(),
|
||||
mod_pak: ct.get("pak")!.asString(),
|
||||
mod_hash: ct.get("hash")!.asString(),
|
||||
enabled: NbtUtils.readBoolean(tag, "enabled"));
|
||||
mod_name: modName,
|
||||
mod_id: modID,
|
||||
mod_pak: pakFile,
|
||||
mod_hash: hash,
|
||||
enabled: enabled,
|
||||
comment: comment);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue