Skip to content

Commit

Permalink
update enchanted golden apple property for 1.13
Browse files Browse the repository at this point in the history
closes #1897
  • Loading branch information
mcmonkey4eva committed Jan 25, 2019
1 parent b80001d commit 1ff92f7
Showing 1 changed file with 16 additions and 1 deletion.
@@ -1,5 +1,7 @@
package net.aufdemrand.denizen.objects.properties.item;

import net.aufdemrand.denizen.nms.NMSHandler;
import net.aufdemrand.denizen.nms.NMSVersion;
import net.aufdemrand.denizen.objects.dItem;
import net.aufdemrand.denizencore.objects.Element;
import net.aufdemrand.denizencore.objects.Mechanism;
Expand All @@ -12,7 +14,8 @@ public class ItemApple implements Property {

public static boolean describes(dObject item) {
return item instanceof dItem
&& (((dItem) item).getItemStack().getType() == Material.GOLDEN_APPLE);
&& ((((dItem) item).getItemStack().getType() == Material.GOLDEN_APPLE)
|| (NMSHandler.getVersion().isAtLeast(NMSVersion.v1_13_R2) && ((dItem) item).getItemStack().getType() == Material.ENCHANTED_GOLDEN_APPLE));
}

public static ItemApple getFrom(dObject _item) {
Expand Down Expand Up @@ -53,8 +56,13 @@ public String getAttribute(Attribute attribute) {
// @mechanism dItem.apple_enchanted
// @description
// Returns whether a golden apple item is enchanted.
// NOTE: In 1.13+, enchanted golden apples are now a separate Material type, making this tag no longer required.
// -->
if (attribute.startsWith("apple_enchanted")) {
if (NMSHandler.getVersion().isAtLeast(NMSVersion.v1_13_R2)) {
return new Element(item.getItemStack().getType() == Material.ENCHANTED_GOLDEN_APPLE)
.getAttribute(attribute.fulfill(1));
}
return new Element(item.getItemStack().getDurability() == 1)
.getAttribute(attribute.fulfill(1));
}
Expand All @@ -65,6 +73,9 @@ public String getAttribute(Attribute attribute) {

@Override
public String getPropertyString() {
if (NMSHandler.getVersion().isAtLeast(NMSVersion.v1_13_R2)) {
return null;
}
if (item.getItemStack().getDurability() == 1) {
return "true";
}
Expand All @@ -87,11 +98,15 @@ public void adjust(Mechanism mechanism) {
// @input Element(Boolean)
// @description
// Changes whether a golden apple is enchanted.
// NOTE: In 1.13+, enchanted golden apples are now a separate Material type, making this mechanism no longer required.
// @tags
// <i@item.apple_enchanted>
// -->

if (mechanism.matches("apple_enchanted") && mechanism.requireBoolean()) {
if (NMSHandler.getVersion().isAtLeast(NMSVersion.v1_13_R2)) {
item.getItemStack().setType(mechanism.getValue().asBoolean() ? Material.ENCHANTED_GOLDEN_APPLE : Material.GOLDEN_APPLE);
}
item.getItemStack().setDurability((short) (mechanism.getValue().asBoolean() ? 1 : 0));
}
}
Expand Down

0 comments on commit 1ff92f7

Please sign in to comment.