I am making a Spigot plugin where I need to store the player’s items in a json file. However, the resulting json file shows "tags":{"isWand":{"typeId":3,"empty":false}.....
in the NBT tags part. JSONObject only took the type of the element and whether it is empty or not instead of the actual value of the element.
This is the code where I converted the tags to a JSONObject.
Map<String,Object> map = new HashMap<>();
map.put("name",this.Name);
map.put("amount",this.amount);
map.put("data",this.data);
map.put("damage",this.damage);
map.put("rarity",this.rarity);
map.put("id",this.materialId);
JSONArray arr = new JSONArray(this.lore);
Map<String,Object> nbt = new HashMap<>();
for(String i:this.tags.keySet()){
nbt.put(i,this.tags.get(i));
}
nbt.remove("display");
System.out.println("e "+nbt);
JSONObject n = new JSONObject(nbt);
JSONObject ret = new JSONObject(map);
ret.put("lore",arr);
ret.put("tags",n);
return ret;
This is the map nbt before I convert it to a JSONObject: {isWand=1, damage=15, Upgrades=[0,0,0,0,0,0,0,], spellIndex=2, Mana=3910, StoredSpells=[2,2,2,2,2,2,2,0,2,], SpellSlots=7, CooldownReduce=0.5f, MaxMana=4000, manaSteal=50, class=0, Power=4, CurSpell=2}
I’ve tried to put everything into a new empty JSONObject, but that just turns every element into a string.
This thing is not happening with the JSONObject ret, which is perfectly converted over, and I am clueless as to why. Also, the JSONArray works fine, it is just that one NBT JSONObject that gets messed up.
Does anyone have any idea why this happens and how to fix this?
nods 6325 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.