From 29b24255042e07c9df25d393dfdafa9f3d049895 Mon Sep 17 00:00:00 2001 From: mcmonkey4eva Date: Sun, 15 Dec 2013 22:14:05 -0800 Subject: [PATCH] add ItemSkullskin property For human_skull (skull_item)'s Now they won't lose their owner --- .../net/aufdemrand/denizen/objects/dItem.java | 54 +++++++----- .../aufdemrand/denizen/objects/dMaterial.java | 1 - .../properties/Item/ItemDurability.java | 1 - .../properties/Item/ItemSkullskin.java | 87 +++++++++++++++++++ .../objects/properties/PropertyParser.java | 1 + 5 files changed, 121 insertions(+), 23 deletions(-) create mode 100644 src/main/java/net/aufdemrand/denizen/objects/properties/Item/ItemSkullskin.java diff --git a/src/main/java/net/aufdemrand/denizen/objects/dItem.java b/src/main/java/net/aufdemrand/denizen/objects/dItem.java index 931ce38d6e..7cc8c5c5ea 100644 --- a/src/main/java/net/aufdemrand/denizen/objects/dItem.java +++ b/src/main/java/net/aufdemrand/denizen/objects/dItem.java @@ -2,8 +2,7 @@ import net.aufdemrand.denizen.objects.notable.Notable; import net.aufdemrand.denizen.objects.notable.NotableManager; -import net.aufdemrand.denizen.objects.properties.Item.ItemDisplayname; -import net.aufdemrand.denizen.objects.properties.Item.ItemDurability; +import net.aufdemrand.denizen.objects.properties.Item.*; import net.aufdemrand.denizen.objects.properties.Property; import net.aufdemrand.denizen.objects.properties.PropertyParser; import net.aufdemrand.denizen.scripts.ScriptRegistry; @@ -529,6 +528,16 @@ public String getAttribute(Attribute attribute) { return new Element(ItemDurability.describes(this)) .getAttribute(attribute.fulfill(1)); + // <--[tag] + // @attribute + // @returns Element(Boolean) + // @description + // Returns whether the item has lore set on it. + // --> + if (attribute.startsWith("has_lore")) + return new Element(ItemLore.describes(this)) + .getAttribute(attribute.fulfill(1)); + // <--[tag] // @attribute // @returns Element @@ -595,24 +604,7 @@ public String getAttribute(Attribute attribute) { .getAttribute(attribute.fulfill(1)); } - // <--[tag] - // @attribute - // @returns Element - // @description - // Returns the name of the player whose skin a skull item uses. - // Note: Item must be a 'skull_item' with a skin. - // --> - if (attribute.startsWith("skin")) { - if (getItemStack().getType() == Material.SKULL_ITEM) { - SkullMeta skullInfo = (SkullMeta) getItemStack().getItemMeta(); - - if (skullInfo.hasOwner()) { - return new Element(skullInfo.getOwner()) - .getAttribute(attribute.fulfill(1)); - } - } - } - + // TODO: Property for Book info if (attribute.startsWith("book")) { if (getItemStack().getType() == Material.WRITTEN_BOOK) { attribute.fulfill(1); @@ -808,12 +800,32 @@ public void adjust(Mechanism mechanism) { // // --> if (mechanism.matches("durability") && mechanism.requireInteger()) { - if (isRepairable()) + if (ItemDurability.describes(this)) item.setDurability((short)value.asInt()); else dB.echoError("Material '" + getMaterial().identify().replace("m@", "") + "' is not repairable."); } + // <--[mechanism] + // @object dItem + // @name skull_skin + // @input Element + // @description + // Changes the durability of damageable items. + // @tags + // + // + // --> + if (mechanism.matches("skull_skin")) { + if (ItemSkullskin.describes(this)) { + SkullMeta meta = (SkullMeta) item.getItemMeta(); + meta.setOwner(value.asString()); + item.setItemMeta(meta); + } + else + dB.echoError("Material '" + getMaterial().identify().replace("m@", "") + "' cannot hold a skin."); + } + if (!mechanism.fulfilled()) mechanism.reportInvalid(); diff --git a/src/main/java/net/aufdemrand/denizen/objects/dMaterial.java b/src/main/java/net/aufdemrand/denizen/objects/dMaterial.java index ce8323dde7..865dc3e97d 100644 --- a/src/main/java/net/aufdemrand/denizen/objects/dMaterial.java +++ b/src/main/java/net/aufdemrand/denizen/objects/dMaterial.java @@ -285,7 +285,6 @@ public static enum dMaterials { WHITE_WOOL, ORANGE_WOOL, MAGENTA_WOOL, LIGHT_BLU public final static dMaterial SKELETON_SKULL = new dMaterial(Material.SKULL_ITEM, 0).forceIdentifyAs("SKELETON_SKULL"); public final static dMaterial WITHERSKELETON_SKULL = new dMaterial(Material.SKULL_ITEM, 1).forceIdentifyAs("WITHERSKELETON_SKULL"); public final static dMaterial ZOMBIE_SKULL = new dMaterial(Material.SKULL_ITEM, 2).forceIdentifyAs("ZOMBIE_SKULL"); - // TODO: Human skull skin property public final static dMaterial HUMAN_SKULL = new dMaterial(Material.SKULL_ITEM, 3).forceIdentifyAs("HUMAN_SKULL"); public final static dMaterial CREEPER_SKULL = new dMaterial(Material.SKULL_ITEM, 4).forceIdentifyAs("CREEPER_SKULL"); diff --git a/src/main/java/net/aufdemrand/denizen/objects/properties/Item/ItemDurability.java b/src/main/java/net/aufdemrand/denizen/objects/properties/Item/ItemDurability.java index a3dc44b773..7b4cebd9b9 100644 --- a/src/main/java/net/aufdemrand/denizen/objects/properties/Item/ItemDurability.java +++ b/src/main/java/net/aufdemrand/denizen/objects/properties/Item/ItemDurability.java @@ -6,7 +6,6 @@ import net.aufdemrand.denizen.objects.dObject; import net.aufdemrand.denizen.objects.properties.Property; import net.aufdemrand.denizen.tags.Attribute; -import org.bukkit.inventory.meta.Repairable; public class ItemDurability implements Property { diff --git a/src/main/java/net/aufdemrand/denizen/objects/properties/Item/ItemSkullskin.java b/src/main/java/net/aufdemrand/denizen/objects/properties/Item/ItemSkullskin.java new file mode 100644 index 0000000000..326aa76751 --- /dev/null +++ b/src/main/java/net/aufdemrand/denizen/objects/properties/Item/ItemSkullskin.java @@ -0,0 +1,87 @@ +package net.aufdemrand.denizen.objects.properties.Item; + + +import net.aufdemrand.denizen.objects.Element; +import net.aufdemrand.denizen.objects.dItem; +import net.aufdemrand.denizen.objects.dObject; +import net.aufdemrand.denizen.objects.properties.Property; +import net.aufdemrand.denizen.tags.Attribute; +import net.aufdemrand.denizen.utilities.debugging.dB; +import org.bukkit.Material; +import org.bukkit.inventory.meta.SkullMeta; + +public class ItemSkullskin implements Property { + + public static boolean describes(dObject item) { + return item instanceof dItem + && ((dItem) item).getItemStack().getType() == Material.SKULL_ITEM + && ((dItem) item).getItemStack().getData().getData() == 3; + } + + public static ItemSkullskin getFrom(dObject _item) { + if (!describes(_item)) return null; + else return new ItemSkullskin((dItem)_item); + } + + + private ItemSkullskin(dItem _item) { + item = _item; + } + + dItem item; + + @Override + public String getAttribute(Attribute attribute) { + + if (attribute == null) return "null"; + + // <--[tag] + // @attribute + // @returns Element + // @description + // Returns the name of the player whose skin a skull item uses. + // Note: Item must be a 'skull_item' with a skin. + // --> + if (attribute.startsWith("skin")) { + if (item.getItemStack().hasItemMeta() + && item.getItemStack().getItemMeta() instanceof SkullMeta + && ((SkullMeta)item.getItemStack().getItemMeta()).hasOwner()) + return new Element(((SkullMeta)item.getItemStack().getItemMeta()).getOwner()) + .getAttribute(attribute.fulfill(1)); + else + dB.echoError("This skull_item does not have a skin set!"); + } + + // <--[tag] + // @attribute + // @returns Element(Boolean) + // @description + // Returns whether the item has a custom skin set. + // (Only for human 'skull_item's) + // --> + if (attribute.startsWith("has_skin")) + return new Element(item.getItemStack().hasItemMeta() + && item.getItemStack().getItemMeta() instanceof SkullMeta + && ((SkullMeta)item.getItemStack().getItemMeta()).hasOwner()) + .getAttribute(attribute.fulfill(1)); + + + return null; + } + + + @Override + public String getPropertyString() { + if (item.getItemStack().hasItemMeta() + && item.getItemStack().getItemMeta() instanceof SkullMeta + && ((SkullMeta)item.getItemStack().getItemMeta()).hasOwner()) + return ((SkullMeta)item.getItemStack().getItemMeta()).getOwner(); + else + return null; + } + + @Override + public String getPropertyId() { + return "skull_skin"; + } +} diff --git a/src/main/java/net/aufdemrand/denizen/objects/properties/PropertyParser.java b/src/main/java/net/aufdemrand/denizen/objects/properties/PropertyParser.java index 2e4a6a9f39..e0be4257f9 100644 --- a/src/main/java/net/aufdemrand/denizen/objects/properties/PropertyParser.java +++ b/src/main/java/net/aufdemrand/denizen/objects/properties/PropertyParser.java @@ -39,6 +39,7 @@ public PropertyParser() { registerProperty(ItemLore.class, dItem.class); registerProperty(ItemQuantity.class, dItem.class); registerProperty(ItemDurability.class, dItem.class); + registerProperty(ItemSkullskin.class, dItem.class); }