Skip to content

Commit

Permalink
chore: added StringMapValue to config system
Browse files Browse the repository at this point in the history
  • Loading branch information
desht committed Jul 19, 2024
1 parent 8d2f161 commit 8ea9402
Showing 1 changed file with 37 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package dev.ftb.mods.ftblibrary.snbt.config;

import dev.ftb.mods.ftblibrary.snbt.SNBTCompoundTag;
import org.jetbrains.annotations.Nullable;

import java.util.HashMap;
import java.util.Map;

public class StringMapValue extends BaseValue<Map<String, String>> {
public StringMapValue(@Nullable SNBTConfig c, String n, Map<String, String> def) {
super(c, n, def);
super.set(new HashMap<>(def));
}

@Override
public void write(SNBTCompoundTag tag) {
Map<String, String> map = get();
SNBTCompoundTag mapTag = new SNBTCompoundTag();

for (Map.Entry<String, String> entry : map.entrySet()) {
mapTag.putString(entry.getKey(), entry.getValue());
}

tag.put(key, mapTag);
}

@Override
public void read(SNBTCompoundTag tag) {
Map<String, String> map = new HashMap<>();

for (String key : tag.getAllKeys()) {
map.put(key, tag.getString(key));
}

set(map);
}
}

0 comments on commit 8ea9402

Please sign in to comment.