Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add ItemTag property book_generation
- Loading branch information
1 parent
8c6c3d4
commit e2d9402
Showing
4 changed files
with
103 additions
and
2 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
100 changes: 100 additions & 0 deletions
100
...n/src/main/java/com/denizenscript/denizen/objects/properties/item/ItemBookGeneration.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,100 @@ | ||
package com.denizenscript.denizen.objects.properties.item; | ||
|
||
import com.denizenscript.denizen.objects.ItemTag; | ||
import com.denizenscript.denizencore.objects.Mechanism; | ||
import com.denizenscript.denizencore.objects.ObjectTag; | ||
import com.denizenscript.denizencore.objects.core.ElementTag; | ||
import com.denizenscript.denizencore.objects.properties.Property; | ||
import com.denizenscript.denizencore.tags.Attribute; | ||
import org.bukkit.Material; | ||
import org.bukkit.inventory.meta.BookMeta; | ||
|
||
public class ItemBookGeneration implements Property { | ||
|
||
public static boolean describes(ObjectTag item) { | ||
return item instanceof ItemTag && ((ItemTag) item).getItemStack().getType() == Material.WRITTEN_BOOK; | ||
} | ||
|
||
public static ItemBookGeneration getFrom(ObjectTag _item) { | ||
if (!describes(_item)) { | ||
return null; | ||
} | ||
else { | ||
return new ItemBookGeneration((ItemTag) _item); | ||
} | ||
} | ||
|
||
public static final String[] handledTags = new String[] { | ||
"book_generation" | ||
}; | ||
|
||
public static final String[] handledMechs = new String[] { | ||
"book_generation" | ||
}; | ||
|
||
private ItemBookGeneration(ItemTag _item) { | ||
item = _item; | ||
} | ||
|
||
ItemTag item; | ||
|
||
@Override | ||
public ObjectTag getObjectAttribute(Attribute attribute) { | ||
|
||
if (attribute == null) { | ||
return null; | ||
} | ||
|
||
// <--[tag] | ||
// @attribute <ItemTag.book_generation> | ||
// @returns ListTag | ||
// @mechanism ItemTag.book_generation | ||
// @group properties | ||
// @description | ||
// Returns the generation of the book (if any), as ORIGINAL, COPY_OF_ORIGINAL, COPY_OF_COPY, or TATTERED. | ||
// --> | ||
if (attribute.startsWith("book_generation")) { | ||
BookMeta meta = (BookMeta) item.getItemMeta(); | ||
if (!meta.hasGeneration()) { | ||
return null; | ||
} | ||
return new ElementTag(meta.getGeneration().name()).getObjectAttribute(attribute.fulfill(1)); | ||
} | ||
|
||
return null; | ||
} | ||
|
||
@Override | ||
public String getPropertyString() { | ||
BookMeta meta = (BookMeta) item.getItemMeta(); | ||
if (!meta.hasGeneration()) { | ||
return null; | ||
} | ||
return meta.getGeneration().name(); | ||
} | ||
|
||
@Override | ||
public String getPropertyId() { | ||
return "book_generation"; | ||
} | ||
|
||
@Override | ||
public void adjust(Mechanism mechanism) { | ||
|
||
// <--[mechanism] | ||
// @object ItemTag | ||
// @name book_generation | ||
// @input ListTag | ||
// @description | ||
// Sets the generation of the book (if any), as ORIGINAL, COPY_OF_ORIGINAL, COPY_OF_COPY, or TATTERED. | ||
// @tags | ||
// <ItemTag.book_generation> | ||
// --> | ||
if (mechanism.matches("book_generation") && mechanism.requireEnum(false, BookMeta.Generation.values())) { | ||
BookMeta meta = (BookMeta) item.getItemMeta(); | ||
meta.setGeneration(BookMeta.Generation.valueOf(mechanism.getValue().asString().toUpperCase())); | ||
item.setItemMeta(meta); | ||
} | ||
|
||
} | ||
} |
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