Skip to content

Commit

Permalink
improve enchantments property
Browse files Browse the repository at this point in the history
  • Loading branch information
mcmonkey4eva committed Feb 8, 2019
1 parent ea22f2b commit 67d3bec
Showing 1 changed file with 8 additions and 6 deletions.
Expand Up @@ -53,8 +53,6 @@ public String getAttribute(Attribute attribute) {
return null;
}

Set<Map.Entry<Enchantment, Integer>> enchantments = GetEnchantments();

// <--[tag]
// @attribute <i@item.is_enchanted>
// @returns Element(Boolean)
Expand All @@ -64,7 +62,7 @@ public String getAttribute(Attribute attribute) {
// Returns whether the item has any enchantments.
// -->
if (attribute.startsWith("is_enchanted")) {
return new Element(enchantments.size() > 0)
return new Element(getEnchantments().size() > 0)
.getAttribute(attribute.fulfill(1));
}

Expand All @@ -78,6 +76,7 @@ public String getAttribute(Attribute attribute) {
// In the format of ENCHANTMENT,LEVEL - For example: DAMAGE_ALL,3
// -->
if (attribute.startsWith("enchantments.with_levels")) {
Set<Map.Entry<Enchantment, Integer>> enchantments = getEnchantments();
if (enchantments.size() > 0) {
List<String> enchants = new ArrayList<String>();
for (Map.Entry<Enchantment, Integer> enchantment : enchantments) {
Expand All @@ -97,6 +96,7 @@ public String getAttribute(Attribute attribute) {
// Returns a list of enchantments on the item, showing only the level.
// -->
if (attribute.startsWith("enchantments.levels")) {
Set<Map.Entry<Enchantment, Integer>> enchantments = getEnchantments();
if (enchantments.size() > 0) {
List<String> enchants = new ArrayList<String>();
for (Map.Entry<Enchantment, Integer> enchantment : enchantments) {
Expand All @@ -117,6 +117,7 @@ public String getAttribute(Attribute attribute) {
// -->
if (attribute.startsWith("enchantments.level")
&& attribute.hasContext(2)) {
Set<Map.Entry<Enchantment, Integer>> enchantments = getEnchantments();
if (enchantments.size() > 0) {
for (Map.Entry<Enchantment, Integer> enchantment : enchantments) {
if (enchantment.getKey().getName().equalsIgnoreCase(attribute.getContext(2))) {
Expand All @@ -138,6 +139,7 @@ public String getAttribute(Attribute attribute) {
// Returns a list of enchantments on the item.
// -->
if (attribute.startsWith("enchantments")) {
Set<Map.Entry<Enchantment, Integer>> enchantments = getEnchantments();
if (enchantments.size() > 0) {
List<String> enchants = new ArrayList<String>();
for (Map.Entry<Enchantment, Integer> enchantment : enchantments) {
Expand All @@ -151,20 +153,20 @@ public String getAttribute(Attribute attribute) {
return null;
}

public Set<Map.Entry<Enchantment, Integer>> GetEnchantments() {
public Set<Map.Entry<Enchantment, Integer>> getEnchantments() {
if (item.getItemStack().getEnchantments().size() > 0) {
return item.getItemStack().getEnchantments().entrySet();
}
else if (item.getItemStack().hasItemMeta() && item.getItemStack().getItemMeta() instanceof EnchantmentStorageMeta) {
return ((EnchantmentStorageMeta) item.getItemStack().getItemMeta()).getStoredEnchants().entrySet();
}
return new HashSet<Map.Entry<Enchantment, Integer>>();
return new HashSet<>();
}


@Override
public String getPropertyString() {
Set<Map.Entry<Enchantment, Integer>> enchants = GetEnchantments();
Set<Map.Entry<Enchantment, Integer>> enchants = getEnchantments();
if (enchants.size() > 0) {
StringBuilder returnable = new StringBuilder();
for (Map.Entry<Enchantment, Integer> enchantment : enchants) {
Expand Down

0 comments on commit 67d3bec

Please sign in to comment.