From 78b885cb3a144ba8002989cef75b9c413c9f0c7f Mon Sep 17 00:00:00 2001 From: ASangarin Date: Sat, 1 Aug 2020 23:04:54 +0200 Subject: [PATCH] Custom tags can now be booleans, ints, strings or string lists. --- .../net/Indyuce/mmoitems/stat/NBTTags.java | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/src/main/java/net/Indyuce/mmoitems/stat/NBTTags.java b/src/main/java/net/Indyuce/mmoitems/stat/NBTTags.java index 6067dc97..13c278fc 100644 --- a/src/main/java/net/Indyuce/mmoitems/stat/NBTTags.java +++ b/src/main/java/net/Indyuce/mmoitems/stat/NBTTags.java @@ -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 entries = new ArrayList<>(); + for(String s : input.replace("[", "").replace("]", "").split("\\,")) + entries.add(s.replace("\"", "")); + return (List) entries; + } + return (String) input; + } }