Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
For human_skull (skull_item)'s Now they won't lose their owner
- Loading branch information
1 parent
9a9a672
commit 29b2425
Showing
5 changed files
with
121 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
87 changes: 87 additions & 0 deletions
87
src/main/java/net/aufdemrand/denizen/objects/properties/Item/ItemSkullskin.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 <i@item.skin> | ||
// @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 <i@item.has_skin> | ||
// @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"; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters