mirror of
https://gitlab.com/phoenix-dvpmt/mmoitems.git
synced 2025-01-03 06:37:47 +01:00
Custom tags can now be booleans, ints, strings or string lists.
This commit is contained in:
parent
be44a8cbc5
commit
78b885cb3a
@ -110,7 +110,7 @@ public class NBTTags extends ItemStat {
|
||||
((StringListData) data).getList().forEach(tag -> {
|
||||
array.add(tag);
|
||||
|
||||
item.addItemTag(new ItemTag(tag.substring(0, tag.indexOf(' ')), tag.substring(tag.indexOf(' ') + 1)));
|
||||
item.addItemTag(new ItemTag(tag.substring(0, tag.indexOf(' ')), calculateObjectType(tag.substring(tag.indexOf(' ') + 1))));
|
||||
});
|
||||
item.addItemTag(new ItemTag("MMOITEMS_NBTTAGS", array.toString()));
|
||||
}
|
||||
@ -121,4 +121,20 @@ public class NBTTags extends ItemStat {
|
||||
mmoitem.setData(ItemStat.NBT_TAGS,
|
||||
new StringListData(new JsonParser().parse(mmoitem.getNBT().getString("MMOITEMS_NBTTAGS")).getAsJsonArray()));
|
||||
}
|
||||
|
||||
public Object calculateObjectType(String input) {
|
||||
if(input.equalsIgnoreCase("true")) return (Boolean) true;
|
||||
if(input.equalsIgnoreCase("false")) return (Boolean) false;
|
||||
try {
|
||||
int value = Integer.parseInt(input);
|
||||
return (Integer) value;
|
||||
} catch(NumberFormatException e) {}
|
||||
if(input.contains("[") && input.contains("]")) {
|
||||
List<String> entries = new ArrayList<>();
|
||||
for(String s : input.replace("[", "").replace("]", "").split("\\,"))
|
||||
entries.add(s.replace("\"", ""));
|
||||
return (List<?>) entries;
|
||||
}
|
||||
return (String) input;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user