diff --git a/src/main/java/com/laytonsmith/abstraction/Convertor.java b/src/main/java/com/laytonsmith/abstraction/Convertor.java index afeaea726..208ed02a7 100644 --- a/src/main/java/com/laytonsmith/abstraction/Convertor.java +++ b/src/main/java/com/laytonsmith/abstraction/Convertor.java @@ -269,4 +269,16 @@ public interface Convertor { * @return The username */ String GetUser(Environment env); + + /** + * Returns a Minecraft namespaced key object from a string. + * The key can only alphanumeric characters, dots, underscores, and dashes. + * A preceding namespace can be delimited with a single colon, which can also have forward slashes. + * Example: "path/commandhelper:my_tag". + * If no namespace is given, it will default to "commandhelper". + * + * @param key a string formatted key + * @return a key object + */ + MCNamespacedKey GetNamespacedKey(String key); } diff --git a/src/main/java/com/laytonsmith/abstraction/MCItemMeta.java b/src/main/java/com/laytonsmith/abstraction/MCItemMeta.java index 4dbb25ba2..0e23e54d6 100644 --- a/src/main/java/com/laytonsmith/abstraction/MCItemMeta.java +++ b/src/main/java/com/laytonsmith/abstraction/MCItemMeta.java @@ -128,4 +128,8 @@ public interface MCItemMeta extends AbstractionObject { List getAttributeModifiers(); void setAttributeModifiers(List modifiers); + + boolean hasCustomTags(); + + MCTagContainer getCustomTags(); } diff --git a/src/main/java/com/laytonsmith/abstraction/MCNamespacedKey.java b/src/main/java/com/laytonsmith/abstraction/MCNamespacedKey.java new file mode 100644 index 000000000..0f4b54d7a --- /dev/null +++ b/src/main/java/com/laytonsmith/abstraction/MCNamespacedKey.java @@ -0,0 +1,4 @@ +package com.laytonsmith.abstraction; + +public interface MCNamespacedKey extends AbstractionObject { +} diff --git a/src/main/java/com/laytonsmith/abstraction/MCTagContainer.java b/src/main/java/com/laytonsmith/abstraction/MCTagContainer.java new file mode 100644 index 000000000..a28f41a1d --- /dev/null +++ b/src/main/java/com/laytonsmith/abstraction/MCTagContainer.java @@ -0,0 +1,65 @@ +package com.laytonsmith.abstraction; + +import com.laytonsmith.abstraction.enums.MCTagType; + +import java.util.Set; + +/** + * Minecraft NBT containers that can be used to read and modify tags in supported game objects. + * This includes item meta, entities, block entities, chunks, worlds, etc. + */ +public interface MCTagContainer extends AbstractionObject { + + /** + * Returns whether the tag container does not contain any tags. + * @return whether container is empty + */ + boolean isEmpty(); + + /** + * Gets a set of namespaced keys for each tag that exists in this container. (e.g. "namespace:key") + * @return a set of keys + */ + Set getKeys(); + + /** + * Returns the tag type with the given key. + * MCTagType can be used to convert tags to and from MethodScript constructs. + * Returns null if a tag with that key does not exist. + * @param key the tag key + * @return the type for the tag + */ + MCTagType getType(MCNamespacedKey key); + + /** + * Returns the tag value with the given key and tag type. + * Returns null if a tag with that key and type does not exist. + * @param key the tag key + * @param type the tag type + * @return the value for the tag + */ + Object get(MCNamespacedKey key, MCTagType type); + + /** + * Sets the tag value with the given key and tag type. + * Throws an IllegalArgumentException if the type and value do not match. + * @param key the tag key + * @param type the tag type + * @param value the tag value + */ + void set(MCNamespacedKey key, MCTagType type, Object value); + + /** + * Deletes the tag with the given key from this container. + * @param key the tag key + */ + void remove(MCNamespacedKey key); + + /** + * Creates a new tag container from this container context. + * This can then be used to nest a tag container with the {@link #set} method. + * @return a new tag container + */ + MCTagContainer newContainer(); + +} diff --git a/src/main/java/com/laytonsmith/abstraction/bukkit/BukkitConvertor.java b/src/main/java/com/laytonsmith/abstraction/bukkit/BukkitConvertor.java index 437c93a57..c9b07e098 100644 --- a/src/main/java/com/laytonsmith/abstraction/bukkit/BukkitConvertor.java +++ b/src/main/java/com/laytonsmith/abstraction/bukkit/BukkitConvertor.java @@ -18,6 +18,7 @@ import com.laytonsmith.abstraction.MCItemStack; import com.laytonsmith.abstraction.MCLocation; import com.laytonsmith.abstraction.MCMetadataValue; +import com.laytonsmith.abstraction.MCNamespacedKey; import com.laytonsmith.abstraction.MCNote; import com.laytonsmith.abstraction.MCPattern; import com.laytonsmith.abstraction.MCPlugin; @@ -871,4 +872,9 @@ public String GetUser(Environment env) { return name; } } + + @Override + public MCNamespacedKey GetNamespacedKey(String key) { + return new BukkitMCNamespacedKey(NamespacedKey.fromString(key, CommandHelperPlugin.self)); + } } diff --git a/src/main/java/com/laytonsmith/abstraction/bukkit/BukkitMCItemMeta.java b/src/main/java/com/laytonsmith/abstraction/bukkit/BukkitMCItemMeta.java index 7e0eda67f..52f6bd9e4 100644 --- a/src/main/java/com/laytonsmith/abstraction/bukkit/BukkitMCItemMeta.java +++ b/src/main/java/com/laytonsmith/abstraction/bukkit/BukkitMCItemMeta.java @@ -6,6 +6,7 @@ import com.laytonsmith.abstraction.MCAttributeModifier; import com.laytonsmith.abstraction.MCEnchantment; import com.laytonsmith.abstraction.MCItemMeta; +import com.laytonsmith.abstraction.MCTagContainer; import com.laytonsmith.abstraction.blocks.MCBlockData; import com.laytonsmith.abstraction.blocks.MCMaterial; import com.laytonsmith.abstraction.bukkit.blocks.BukkitMCBlockData; @@ -225,4 +226,13 @@ public void setAttributeModifiers(List modifiers) { } im.setAttributeModifiers(map); } + + @Override + public boolean hasCustomTags() { + return !im.getPersistentDataContainer().isEmpty(); + } + + public MCTagContainer getCustomTags() { + return new BukkitMCTagContainer(im.getPersistentDataContainer()); + } } diff --git a/src/main/java/com/laytonsmith/abstraction/bukkit/BukkitMCNamespacedKey.java b/src/main/java/com/laytonsmith/abstraction/bukkit/BukkitMCNamespacedKey.java new file mode 100644 index 000000000..96db76225 --- /dev/null +++ b/src/main/java/com/laytonsmith/abstraction/bukkit/BukkitMCNamespacedKey.java @@ -0,0 +1,33 @@ +package com.laytonsmith.abstraction.bukkit; + +import com.laytonsmith.abstraction.MCNamespacedKey; +import org.bukkit.NamespacedKey; + +public class BukkitMCNamespacedKey implements MCNamespacedKey { + + NamespacedKey nsk; + + public BukkitMCNamespacedKey(NamespacedKey nsk) { + this.nsk = nsk; + } + + @Override + public Object getHandle() { + return this.nsk; + } + + @Override + public String toString() { + return this.nsk.toString(); + } + + @Override + public boolean equals(Object obj) { + return obj instanceof MCNamespacedKey && this.nsk.equals(((MCNamespacedKey) obj).getHandle()); + } + + @Override + public int hashCode() { + return this.nsk.hashCode(); + } +} diff --git a/src/main/java/com/laytonsmith/abstraction/bukkit/BukkitMCTagContainer.java b/src/main/java/com/laytonsmith/abstraction/bukkit/BukkitMCTagContainer.java new file mode 100644 index 000000000..495005322 --- /dev/null +++ b/src/main/java/com/laytonsmith/abstraction/bukkit/BukkitMCTagContainer.java @@ -0,0 +1,157 @@ +package com.laytonsmith.abstraction.bukkit; + +import com.laytonsmith.abstraction.MCNamespacedKey; +import com.laytonsmith.abstraction.MCTagContainer; +import com.laytonsmith.abstraction.enums.MCTagType; +import org.bukkit.NamespacedKey; +import org.bukkit.persistence.PersistentDataContainer; +import org.bukkit.persistence.PersistentDataType; + +import java.util.HashSet; +import java.util.Set; + +public class BukkitMCTagContainer implements MCTagContainer { + + PersistentDataContainer pdc; + + public BukkitMCTagContainer(PersistentDataContainer pdc) { + this.pdc = pdc; + } + + @Override + public MCTagContainer newContainer() { + return new BukkitMCTagContainer(this.pdc.getAdapterContext().newPersistentDataContainer()); + } + + @Override + public boolean isEmpty() { + return this.pdc.isEmpty(); + } + + @Override + public Set getKeys() { + Set keys = new HashSet<>(); + for(NamespacedKey key : this.pdc.getKeys()) { + keys.add(new BukkitMCNamespacedKey(key)); + } + return keys; + } + + @Override + public MCTagType getType(MCNamespacedKey key) { + NamespacedKey namespacedKey = (NamespacedKey) key.getHandle(); + // Check tag types in order of most frequently used + if(this.pdc.has(namespacedKey, PersistentDataType.STRING)) { + return MCTagType.STRING; + } else if(this.pdc.has(namespacedKey, PersistentDataType.INTEGER)) { + return MCTagType.INTEGER; + } else if(this.pdc.has(namespacedKey, PersistentDataType.BYTE)) { + return MCTagType.BYTE; + } else if(this.pdc.has(namespacedKey, PersistentDataType.DOUBLE)) { + return MCTagType.DOUBLE; + } else if(this.pdc.has(namespacedKey, PersistentDataType.LONG)) { + return MCTagType.LONG; + } else if(this.pdc.has(namespacedKey, PersistentDataType.FLOAT)) { + return MCTagType.FLOAT; + } else if(this.pdc.has(namespacedKey, PersistentDataType.TAG_CONTAINER)) { + return MCTagType.TAG_CONTAINER; + } else if(this.pdc.has(namespacedKey, PersistentDataType.BYTE_ARRAY)) { + return MCTagType.BYTE_ARRAY; + } else if(this.pdc.has(namespacedKey, PersistentDataType.SHORT)) { + return MCTagType.SHORT; + } else if(this.pdc.has(namespacedKey, PersistentDataType.INTEGER_ARRAY)) { + return MCTagType.INTEGER_ARRAY; + } else if(this.pdc.has(namespacedKey, PersistentDataType.LONG_ARRAY)) { + return MCTagType.LONG_ARRAY; + } else if(this.pdc.has(namespacedKey, PersistentDataType.TAG_CONTAINER_ARRAY)) { + return MCTagType.TAG_CONTAINER_ARRAY; + } + return null; + } + + @Override + public Object get(MCNamespacedKey key, MCTagType type) { + PersistentDataType bukkitType = GetPersistentDataType(type); + Object value = this.pdc.get((NamespacedKey) key.getHandle(), bukkitType); + if(value instanceof PersistentDataContainer) { + return new BukkitMCTagContainer((PersistentDataContainer) value); + } else if(value instanceof PersistentDataContainer[] concreteContainers) { + MCTagContainer[] abstractContainers = new MCTagContainer[concreteContainers.length]; + for(int i = 0; i < concreteContainers.length; i++) { + abstractContainers[i] = new BukkitMCTagContainer(concreteContainers[i]); + } + return abstractContainers; + } + return value; + } + + @Override + public void set(MCNamespacedKey key, MCTagType type, Object value) { + PersistentDataType bukkitType = GetPersistentDataType(type); + if(value instanceof MCTagContainer) { + value = ((MCTagContainer) value).getHandle(); + } else if(value instanceof MCTagContainer[] abstractContainers) { + PersistentDataContainer[] concreteContainers = new PersistentDataContainer[abstractContainers.length]; + for(int i = 0; i < abstractContainers.length; i++) { + concreteContainers[i] = (PersistentDataContainer) abstractContainers[i].getHandle(); + } + value = concreteContainers; + } + this.pdc.set((NamespacedKey) key.getHandle(), bukkitType, value); + } + + @Override + public void remove(MCNamespacedKey key) { + this.pdc.remove((NamespacedKey) key.getHandle()); + } + + private static PersistentDataType GetPersistentDataType(MCTagType type) { + switch(type) { + case BYTE: + return PersistentDataType.BYTE; + case BYTE_ARRAY: + return PersistentDataType.BYTE_ARRAY; + case DOUBLE: + return PersistentDataType.DOUBLE; + case FLOAT: + return PersistentDataType.FLOAT; + case INTEGER: + return PersistentDataType.INTEGER; + case INTEGER_ARRAY: + return PersistentDataType.INTEGER_ARRAY; + case LONG: + return PersistentDataType.LONG; + case LONG_ARRAY: + return PersistentDataType.LONG_ARRAY; + case SHORT: + return PersistentDataType.SHORT; + case STRING: + return PersistentDataType.STRING; + case TAG_CONTAINER: + return PersistentDataType.TAG_CONTAINER; + case TAG_CONTAINER_ARRAY: + return PersistentDataType.TAG_CONTAINER_ARRAY; + } + throw new IllegalArgumentException("Invalid persistent data type: " + type.name()); + } + + @Override + public Object getHandle() { + return this.pdc; + } + + @Override + public boolean equals(Object o) { + return o instanceof MCTagContainer && this.pdc.equals(((MCTagContainer) o).getHandle()); + } + + @Override + public int hashCode() { + return this.pdc.hashCode(); + } + + @Override + public String toString() { + return this.pdc.toString(); + } +} diff --git a/src/main/java/com/laytonsmith/abstraction/enums/MCTagType.java b/src/main/java/com/laytonsmith/abstraction/enums/MCTagType.java new file mode 100644 index 000000000..6d27e95ff --- /dev/null +++ b/src/main/java/com/laytonsmith/abstraction/enums/MCTagType.java @@ -0,0 +1,222 @@ +package com.laytonsmith.abstraction.enums; + +import com.laytonsmith.abstraction.MCNamespacedKey; +import com.laytonsmith.abstraction.MCTagContainer; +import com.laytonsmith.abstraction.StaticLayer; +import com.laytonsmith.core.ArgumentValidation; +import com.laytonsmith.core.constructs.CArray; +import com.laytonsmith.core.constructs.CDouble; +import com.laytonsmith.core.constructs.CInt; +import com.laytonsmith.core.constructs.CString; +import com.laytonsmith.core.constructs.Target; +import com.laytonsmith.core.exceptions.CRE.CRECastException; +import com.laytonsmith.core.exceptions.CRE.CREFormatException; +import com.laytonsmith.core.natives.interfaces.Mixed; + +import java.util.function.Function; + +/** + * Minecraft NBT types, with functions to convert to and from MethodScript constructs. + */ +public enum MCTagType { + BYTE( + (Mixed v) -> ArgumentValidation.getInt8(v, v.getTarget()), + (Byte v) -> new CInt(((Number) v).longValue(), Target.UNKNOWN)), + BYTE_ARRAY( + (Mixed v) -> { + CArray array = ArgumentValidation.getArray(v, v.getTarget()); + if(array.isAssociative()) { + throw new CRECastException("Expected byte array to not be associative.", v.getTarget()); + } + byte[] bytes = new byte[(int) array.size()]; + int i = 0; + for(Mixed m : array) { + bytes[i++] = ArgumentValidation.getInt8(m, m.getTarget()); + } + return bytes; + }, + (byte[] array) -> { + CArray r = new CArray(Target.UNKNOWN); + for(int i : array) { + r.push(new CInt(i, Target.UNKNOWN), Target.UNKNOWN); + } + return r; + }), + DOUBLE( + (Mixed v) -> ArgumentValidation.getDouble(v, v.getTarget()), + (Double v) -> new CDouble(v, Target.UNKNOWN)), + FLOAT( + (Mixed v) -> ArgumentValidation.getDouble32(v, v.getTarget()), + (Float v) -> new CDouble(v.doubleValue(), Target.UNKNOWN)), + INTEGER( + (Mixed v) -> ArgumentValidation.getInt32(v, v.getTarget()), + (Integer v) -> new CInt(((Number) v).longValue(), Target.UNKNOWN)), + INTEGER_ARRAY( + (Mixed v) -> { + CArray array = ArgumentValidation.getArray(v, v.getTarget()); + if(array.isAssociative()) { + throw new CRECastException("Expected integer array to not be associative.", v.getTarget()); + } + int[] ints = new int[(int) array.size()]; + int i = 0; + for(Mixed m : array) { + ints[i++] = ArgumentValidation.getInt32(m, m.getTarget()); + } + return ints; + }, + (int[] array) -> { + CArray r = new CArray(Target.UNKNOWN); + for(int i : array) { + r.push(new CInt(i, Target.UNKNOWN), Target.UNKNOWN); + } + return r; + }), + LONG( + (Mixed v) -> ArgumentValidation.getInt(v, v.getTarget()), + (Long v) -> new CInt(((Number) v).longValue(), Target.UNKNOWN)), + LONG_ARRAY( + (Mixed v) -> { + CArray array = ArgumentValidation.getArray(v, v.getTarget()); + if(array.isAssociative()) { + throw new CRECastException("Expected long array to not be associative.", v.getTarget()); + } + long[] longs = new long[(int) array.size()]; + int i = 0; + for(Mixed m : array) { + longs[i++] = ArgumentValidation.getInt(m, m.getTarget()); + } + return longs; + }, + (long[] array) -> { + CArray ret = new CArray(Target.UNKNOWN); + for(long i : array) { + ret.push(new CInt(i, Target.UNKNOWN), Target.UNKNOWN); + } + return ret; + }), + SHORT( + (Mixed v) -> ArgumentValidation.getInt16(v, v.getTarget()), + (Short v) -> new CInt(((Number) v).longValue(), Target.UNKNOWN)), + STRING( + (Mixed v) -> v.val(), + (String v) -> new CString(v, Target.UNKNOWN)), + TAG_CONTAINER( + (Mixed v) -> { + throw new UnsupportedOperationException(); + }, + (MCTagContainer v) -> { + throw new UnsupportedOperationException(); + }), + TAG_CONTAINER_ARRAY( + (Mixed v) -> { + throw new UnsupportedOperationException(); + }, + (MCTagContainer[] v) -> { + throw new UnsupportedOperationException(); + }); + + private final Function conversion; + private final Function construction; + + MCTagType(Function conversion, Function construction) { + this.conversion = conversion; + this.construction = construction; + } + + /** + * Returns a Java object from a MethodScript construct. + * Throws a ConfigRuntimeException if the value is not valid for this tag type. + * @param container the tag container context + * @param value MethodScript construct + * @return a Java object + */ + public Object convert(MCTagContainer container, Mixed value) { + if(this == TAG_CONTAINER) { + if(!value.isInstanceOf(CArray.TYPE)) { + throw new CREFormatException("Expected tag container to be an array.", value.getTarget()); + } + CArray containerArray = (CArray) value; + if(!containerArray.isAssociative()) { + throw new CREFormatException("Expected tag container array to be associative.", value.getTarget()); + } + for(String key : containerArray.stringKeySet()) { + Mixed possibleArray = containerArray.get(key, value.getTarget()); + if(!possibleArray.isInstanceOf(CArray.TYPE)) { + throw new CREFormatException("Expected tag entry to be an array.", possibleArray.getTarget()); + } + CArray entryArray = (CArray) possibleArray; + if(!entryArray.isAssociative()) { + throw new CREFormatException("Expected tag array to be associative.", entryArray.getTarget()); + } + Mixed entryType = entryArray.get("type", entryArray.getTarget()); + Mixed entryValue = entryArray.get("value", entryArray.getTarget()); + MCTagType tagType; + try { + tagType = MCTagType.valueOf(entryType.val()); + } catch (IllegalArgumentException ex) { + throw new CREFormatException("Tag type is not valid: " + entryType.val(), entryType.getTarget()); + } + Object tagValue; + if(tagType == MCTagType.TAG_CONTAINER) { + tagValue = tagType.convert(container.newContainer(), entryValue); + } else if(tagType == TAG_CONTAINER_ARRAY) { + tagValue = tagType.convert(container, entryValue); + } else { + tagValue = tagType.convert(container, entryValue); + } + try { + container.set(StaticLayer.GetConvertor().GetNamespacedKey(key), tagType, tagValue); + } catch (ClassCastException ex) { + throw new CREFormatException("Tag value does not match expected type.", entryValue.getTarget()); + } catch (IllegalArgumentException ex) { + throw new CREFormatException(ex.getMessage(), entryValue.getTarget()); + } + } + return container; + } else if(this == TAG_CONTAINER_ARRAY) { + if(!value.isInstanceOf(CArray.TYPE)) { + throw new CREFormatException("Expected tag container to be an array.", value.getTarget()); + } + CArray array = (CArray) value; + if(array.isAssociative()) { + throw new CREFormatException("Expected tag container array to not be associative.", array.getTarget()); + } + MCTagContainer[] containers = new MCTagContainer[(int) array.size()]; + int i = 0; + for(Mixed possibleContainer : array) { + containers[i++] = (MCTagContainer) TAG_CONTAINER.convert(container.newContainer(), possibleContainer); + } + return containers; + } + return conversion.apply(value); + } + + /** + * Returns a MethodScript construct from a Java object. + * Throws a ClassCastException if the value does not match this tag type. + * @param value a valid Java object + * @return a MethodScript construct + */ + public Mixed construct(Object value) throws ClassCastException { + if(this == TAG_CONTAINER) { + MCTagContainer container = (MCTagContainer) value; + CArray containerArray = CArray.GetAssociativeArray(Target.UNKNOWN); + for(MCNamespacedKey key : container.getKeys()) { + CArray entry = CArray.GetAssociativeArray(Target.UNKNOWN); + MCTagType type = container.getType(key); + entry.set("type", type.name(), Target.UNKNOWN); + entry.set("value", type.construct(container.get(key, type)), Target.UNKNOWN); + containerArray.set(key.toString(), entry, Target.UNKNOWN); + } + return containerArray; + } else if(this == TAG_CONTAINER_ARRAY) { + MCTagContainer[] containers = (MCTagContainer[]) value; + CArray array = new CArray(Target.UNKNOWN, containers.length); + for(MCTagContainer container : containers) { + array.push(TAG_CONTAINER.construct(container), Target.UNKNOWN); + } + return array; + } + return (Mixed) construction.apply(value); + } +} diff --git a/src/main/java/com/laytonsmith/core/ObjectGenerator.java b/src/main/java/com/laytonsmith/core/ObjectGenerator.java index 2ceede08b..30e5c7751 100644 --- a/src/main/java/com/laytonsmith/core/ObjectGenerator.java +++ b/src/main/java/com/laytonsmith/core/ObjectGenerator.java @@ -71,6 +71,7 @@ import com.laytonsmith.abstraction.enums.MCPotionEffectType; import com.laytonsmith.abstraction.enums.MCPotionType; import com.laytonsmith.abstraction.enums.MCRecipeType; +import com.laytonsmith.abstraction.enums.MCTagType; import com.laytonsmith.abstraction.enums.MCTrimMaterial; import com.laytonsmith.abstraction.enums.MCTrimPattern; import com.laytonsmith.core.constructs.CArray; @@ -465,6 +466,12 @@ public Construct itemMeta(MCItemStack is, Target t) { ma.set("modifiers", modifiers, t); } + if(meta.hasCustomTags()) { + ma.set("tags", MCTagType.TAG_CONTAINER.construct(meta.getCustomTags()), t); + } else { + ma.set("tags", CNull.NULL, t); + } + MCMaterial material = is.getType(); if(material.getMaxDurability() > 0) { // Damageable items only @@ -879,6 +886,15 @@ public MCItemMeta itemMeta(Mixed c, MCMaterial mat, Target t) throws ConfigRunti } } + if(ma.containsKey("tags")) { + Mixed tagArray = ma.get("tags", t); + if(tagArray instanceof CNull) { + // no custom tags + } else { + MCTagType.TAG_CONTAINER.convert(meta.getCustomTags(), tagArray); + } + } + // Damageable items only if(mat.getMaxDurability() > 0) { if(ma.containsKey("damage")) { diff --git a/src/main/java/com/laytonsmith/core/functions/ItemMeta.java b/src/main/java/com/laytonsmith/core/functions/ItemMeta.java index c385b7524..97d3ca240 100644 --- a/src/main/java/com/laytonsmith/core/functions/ItemMeta.java +++ b/src/main/java/com/laytonsmith/core/functions/ItemMeta.java @@ -20,6 +20,7 @@ import com.laytonsmith.abstraction.enums.MCItemFlag; import com.laytonsmith.abstraction.enums.MCPatternShape; import com.laytonsmith.abstraction.enums.MCPotionType; +import com.laytonsmith.abstraction.enums.MCTagType; import com.laytonsmith.abstraction.enums.MCTrimMaterial; import com.laytonsmith.abstraction.enums.MCTrimPattern; import com.laytonsmith.annotations.api; @@ -128,6 +129,7 @@ public String docs() { docs = docs.replace("%AXOLOTL_TYPES%", StringUtils.Join(MCAxolotlType.values(), ", ", ", or ", " or ")); docs = docs.replace("%TRIM_PATTERNS%", StringUtils.Join(MCTrimPattern.values(), ", ", ", or ", " or ")); docs = docs.replace("%TRIM_MATERIALS%", StringUtils.Join(MCTrimMaterial.values(), ", ", ", or ", " or ")); + docs = docs.replace("%TAG_TYPES%", StringUtils.Join(MCTagType.values(), ", ", ", or ", " or ")); return docs; } diff --git a/src/main/java/com/laytonsmith/tools/Interpreter.java b/src/main/java/com/laytonsmith/tools/Interpreter.java index 1159f4097..74e6d20bc 100644 --- a/src/main/java/com/laytonsmith/tools/Interpreter.java +++ b/src/main/java/com/laytonsmith/tools/Interpreter.java @@ -30,6 +30,7 @@ import com.laytonsmith.abstraction.MCItemStack; import com.laytonsmith.abstraction.MCLocation; import com.laytonsmith.abstraction.MCMetadataValue; +import com.laytonsmith.abstraction.MCNamespacedKey; import com.laytonsmith.abstraction.MCNote; import com.laytonsmith.abstraction.MCPattern; import com.laytonsmith.abstraction.MCPlugin; @@ -1291,6 +1292,11 @@ public MCPlugin GetPlugin() { public String GetUser(Environment env) { return System.getProperty("user.name"); } + + @Override + public MCNamespacedKey GetNamespacedKey(String key) { + throw new UnsupportedOperationException("This method is not supported from a shell."); + } } } diff --git a/src/main/resources/functionDocs/get_itemmeta b/src/main/resources/functionDocs/get_itemmeta index cc102ba3b..f485dde23 100644 --- a/src/main/resources/functionDocs/get_itemmeta +++ b/src/main/resources/functionDocs/get_itemmeta @@ -16,6 +16,7 @@ Below are the available fields in the item meta array. Fields can be null when t * '''flags''' : (array) Possible flags: ''%ITEM_FLAGS%''. * '''repair''' : (int) The cost to repair or combine this item in an anvil. * '''modifiers''' : (array) An array of attribute modifier arrays, each with keys: '''"attribute"''', '''"operation"''', '''"amount"''' (double), '''"uuid"''' (optional), '''"name"''' (optional), and '''"slot"''' (optional). Possible attributes: ''%ATTRIBUTES%''. Possible operations: ''%OPERATIONS%''. Possible slots: ''%SLOTS%''. +* '''tags''' : (array) An associative array of custom tags. A tag's key is namespaced (e.g. "commandhelper:mytag") and the value is an associative array containing the '''"type"''' and '''"value"''' of the tag. Possible types: ''%TAG_TYPES%''. |- | All Damageable Items | diff --git a/src/test/java/com/laytonsmith/testing/StaticTest.java b/src/test/java/com/laytonsmith/testing/StaticTest.java index c687ead99..15f25f5b9 100644 --- a/src/test/java/com/laytonsmith/testing/StaticTest.java +++ b/src/test/java/com/laytonsmith/testing/StaticTest.java @@ -21,6 +21,7 @@ import com.laytonsmith.abstraction.MCItemStack; import com.laytonsmith.abstraction.MCLocation; import com.laytonsmith.abstraction.MCMetadataValue; +import com.laytonsmith.abstraction.MCNamespacedKey; import com.laytonsmith.abstraction.MCNote; import com.laytonsmith.abstraction.MCPattern; import com.laytonsmith.abstraction.MCPlayer; @@ -890,6 +891,11 @@ public MCPlugin GetPlugin() { public String GetUser(Environment env) { return "testUser"; } + + @Override + public MCNamespacedKey GetNamespacedKey(String key) { + throw new UnsupportedOperationException("Not supported yet."); + } } public static class FakeServerMixin implements EventMixinInterface {