Permalink
Browse files

Added ItemFlag support to ItemSyntax.

  • Loading branch information...
me4502 committed Mar 3, 2017
1 parent b8e02fa commit 5cf82d64b5086aff6ff62b4e274e55a74d7b17b3
Showing with 16 additions and 0 deletions.
  1. +16 −0 src/main/java/com/sk89q/craftbook/util/ItemSyntax.java
@@ -8,6 +8,7 @@
import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.enchantments.Enchantment;
+import org.bukkit.inventory.ItemFlag;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.*;
import org.bukkit.material.MaterialData;
@@ -17,6 +18,7 @@
import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
+import java.util.Arrays;
import java.util.List;
import java.util.Map.Entry;
import java.util.concurrent.TimeUnit;
@@ -75,6 +77,15 @@ public static String getStringFromItem(ItemStack item) {
if (meta.isUnbreakable()) {
builder.append("/unbreakable:true");
}
+ List<String> flags = new ArrayList<String>();
+ for (ItemFlag flag : ItemFlag.values()) {
+ if (meta.hasItemFlag(flag)) {
+ flags.add(flag.name());
+ }
+ }
+ if (!flags.isEmpty()) {
+ builder.append("/flags:").append(StringUtils.join(flags, ","));
+ }
if (meta instanceof SkullMeta) {
if(((SkullMeta) meta).hasOwner())
@@ -221,6 +232,11 @@ else if(bits[0].equalsIgnoreCase("color") && meta instanceof LeatherArmorMeta) {
} else if (bits[0].equalsIgnoreCase("unbreakable")) {
boolean unbreakable = Boolean.parseBoolean(bits[1]);
meta.setUnbreakable(unbreakable);
+ } else if (bits[0].equalsIgnoreCase("flags")) {
+ List<String> flags = Arrays.asList(COMMA_PATTERN.split(bits[1]));
+ for (String flag : flags) {
+ meta.addItemFlags(ItemFlag.valueOf(flag));
+ }
}
}
rVal.setItemMeta(meta);

0 comments on commit 5cf82d6

Please sign in to comment.