use of com.denizenscript.denizencore.objects.core.ElementTag in project Denizen-For-Bukkit by DenizenScript.
the class ItemBook method getBookMap.
public MapTag getBookMap() {
MapTag outMap = new MapTag();
BookMeta bookInfo = (BookMeta) item.getItemMeta();
if (item.getBukkitMaterial().equals(Material.WRITTEN_BOOK) && bookInfo.hasAuthor() && bookInfo.hasTitle()) {
outMap.putObject("author", new ElementTag(bookInfo.getAuthor(), true));
outMap.putObject("title", new ElementTag(bookInfo.getTitle(), true));
}
if (bookInfo.hasPages()) {
List<BaseComponent[]> pages = bookInfo.spigot().getPages();
ListTag pageList = new ListTag(pages.size());
for (BaseComponent[] page : pages) {
pageList.addObject(new ElementTag(FormattedTextHelper.stringify(page, ChatColor.BLACK), true));
}
outMap.putObject("pages", pageList);
}
return outMap;
}
use of com.denizenscript.denizencore.objects.core.ElementTag in project Denizen-For-Bukkit by DenizenScript.
the class ItemAttributeNBT method adjust.
@Override
public void adjust(Mechanism mechanism) {
if (mechanism.matches("nbt_attributes")) {
Deprecations.legacyAttributeProperties.warn(mechanism.context);
if (item.getMaterial().getMaterial() == Material.AIR) {
mechanism.echoError("Cannot apply NBT to AIR!");
return;
}
ListTag list = mechanism.valueAsType(ListTag.class);
ItemStack itemStack = item.getItemStack();
itemStack = CustomNBT.clearNBT(itemStack, CustomNBT.KEY_ATTRIBUTES);
for (String string : list) {
String[] split = string.split("/");
if (split.length != 4) {
mechanism.echoError("Invalid nbt_attributes input: must have 4 values per attribute.");
continue;
}
String attribute = EscapeTagBase.unEscape(split[0]);
String slot = EscapeTagBase.unEscape(split[1]);
int op = new ElementTag(split[2]).asInt();
double amt = new ElementTag(split[3]).asDouble();
itemStack = CustomNBT.addAttribute(itemStack, attribute, slot, op, amt);
}
item.setItemStack(itemStack);
}
}
use of com.denizenscript.denizencore.objects.core.ElementTag in project Denizen-For-Bukkit by DenizenScript.
the class ItemEnchantments method getObjectAttribute.
@Override
public ObjectTag getObjectAttribute(Attribute attribute) {
if (attribute == null) {
return null;
}
// -->
if (attribute.startsWith("is_enchanted")) {
return new ElementTag(getEnchantments().size() > 0).getObjectAttribute(attribute.fulfill(1));
}
if (attribute.startsWith("enchantments.with_levels")) {
Deprecations.itemEnchantmentTags.warn(attribute.context);
Set<Map.Entry<Enchantment, Integer>> enchantments = getEnchantments();
ListTag enchants = new ListTag();
for (Map.Entry<Enchantment, Integer> enchantment : enchantments) {
enchants.add(new EnchantmentTag(enchantment.getKey()).getCleanName() + "," + enchantment.getValue());
}
return enchants.getObjectAttribute(attribute.fulfill(2));
}
if (attribute.startsWith("enchantments.levels")) {
Deprecations.itemEnchantmentTags.warn(attribute.context);
Set<Map.Entry<Enchantment, Integer>> enchantments = getEnchantments();
ListTag enchants = new ListTag();
for (Map.Entry<Enchantment, Integer> enchantment : enchantments) {
enchants.add(String.valueOf(enchantment.getValue()));
}
return enchants.getObjectAttribute(attribute.fulfill(2));
}
if (attribute.startsWith("enchantments.level") && attribute.hasContext(2)) {
Deprecations.itemEnchantmentTags.warn(attribute.context);
Set<Map.Entry<Enchantment, Integer>> enchantments = getEnchantments();
if (enchantments.size() > 0) {
for (Map.Entry<Enchantment, Integer> enchantment : enchantments) {
if (enchantment.getKey().getName().equalsIgnoreCase(attribute.getContext(2)) || new EnchantmentTag(enchantment.getKey()).getCleanName().equalsIgnoreCase(attribute.getContext(2))) {
return new ElementTag(enchantment.getValue()).getObjectAttribute(attribute.fulfill(2));
}
}
}
return new ElementTag(0).getObjectAttribute(attribute.fulfill(2));
}
// -->
if (attribute.startsWith("enchantment_types")) {
Set<Map.Entry<Enchantment, Integer>> enchantments = getEnchantments();
ListTag enchants = new ListTag();
for (Map.Entry<Enchantment, Integer> enchantment : enchantments) {
enchants.addObject(new EnchantmentTag(enchantment.getKey()));
}
return enchants.getObjectAttribute(attribute.fulfill(1));
}
// -->
if (attribute.startsWith("enchantments")) {
Deprecations.itemEnchantmentsLegacy.warn(attribute.context);
Set<Map.Entry<Enchantment, Integer>> enchantments = getEnchantments();
ListTag enchants = new ListTag();
for (Map.Entry<Enchantment, Integer> enchantment : enchantments) {
enchants.add(new EnchantmentTag(enchantment.getKey()).getCleanName());
}
return enchants.getObjectAttribute(attribute.fulfill(1));
}
// -->
if (attribute.startsWith("enchantment_map")) {
return getEnchantmentMap().getObjectAttribute(attribute.fulfill(1));
}
return null;
}
use of com.denizenscript.denizencore.objects.core.ElementTag in project Denizen-For-Bukkit by DenizenScript.
the class ItemNBT method getObjectAttribute.
@Override
public ObjectTag getObjectAttribute(Attribute attribute) {
if (attribute == null) {
return null;
}
if (attribute.startsWith("has_nbt")) {
Deprecations.itemNbt.warn(attribute.context);
return new ElementTag(CustomNBT.hasCustomNBT(item.getItemStack(), attribute.getParam(), CustomNBT.KEY_DENIZEN)).getObjectAttribute(attribute.fulfill(1));
}
if (attribute.startsWith("nbt_keys")) {
Deprecations.itemNbt.warn(attribute.context);
return new ListTag(CustomNBT.listNBT(item.getItemStack(), CustomNBT.KEY_DENIZEN)).getObjectAttribute(attribute.fulfill(1));
}
if (attribute.matches("nbt")) {
Deprecations.itemNbt.warn(attribute.context);
if (!attribute.hasParam()) {
ListTag list = getNBTDataList();
if (list == null) {
return null;
}
return list.getObjectAttribute(attribute.fulfill(1));
}
String res = CustomNBT.getCustomNBT(item.getItemStack(), attribute.getParam(), CustomNBT.KEY_DENIZEN);
if (res == null) {
return null;
}
return new ElementTag(res).getObjectAttribute(attribute.fulfill(1));
}
return null;
}
use of com.denizenscript.denizencore.objects.core.ElementTag in project Denizen-For-Bukkit by DenizenScript.
the class ItemSpawnerRange method getObjectAttribute.
@Override
public ObjectTag getObjectAttribute(Attribute attribute) {
if (attribute == null) {
return null;
}
// -->
if (attribute.startsWith("spawner_range")) {
BlockStateMeta meta = (BlockStateMeta) item.getItemMeta();
CreatureSpawner state = (CreatureSpawner) meta.getBlockState();
return new ElementTag(state.getSpawnRange()).getObjectAttribute(attribute.fulfill(1));
}
return null;
}
Aggregations