Skip to content

Commit

Permalink
add ItemTag property book_generation
Browse files Browse the repository at this point in the history
  • Loading branch information
mcmonkey4eva committed Dec 10, 2020
1 parent 8c6c3d4 commit e2d9402
Show file tree
Hide file tree
Showing 4 changed files with 103 additions and 2 deletions.
Expand Up @@ -104,6 +104,7 @@ public static void registermainProperties() {
PropertyParser.registerProperty(ItemBaseColor.class, ItemTag.class);
PropertyParser.registerProperty(ItemBlockMaterial.class, ItemTag.class);
PropertyParser.registerProperty(ItemBook.class, ItemTag.class);
PropertyParser.registerProperty(ItemBookGeneration.class, ItemTag.class);
PropertyParser.registerProperty(ItemDisplayname.class, ItemTag.class);
PropertyParser.registerProperty(ItemDurability.class, ItemTag.class);
PropertyParser.registerProperty(ItemCanDestroy.class, ItemTag.class);
Expand Down
@@ -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);
}

}
}
Expand Up @@ -14,7 +14,7 @@
public class ItemHidden implements Property {

public static boolean describes(ObjectTag item) {
// All items can have flags
// All items can have hides
return item instanceof ItemTag && ((ItemTag) item).getItemStack().getType() != Material.AIR;
}

Expand Down
Expand Up @@ -134,7 +134,7 @@ public InventoryCommand() {
//
// @Usage
// Use to set a temporary flag on the player's held item.
// - inventory flag slot:<player.held_item_slot> flag my_target:<player.cursor_on> duration:1d
// - inventory flag slot:<player.held_item_slot> my_target:<player.cursor_on> duration:1d
// -->

private enum Action {OPEN, CLOSE, COPY, MOVE, SWAP, ADD, REMOVE, SET, KEEP, EXCLUDE, FILL, CLEAR, UPDATE, ADJUST, FLAG}
Expand Down

0 comments on commit e2d9402

Please sign in to comment.