use of net.aufdemrand.denizencore.objects.TagRunnable in project Denizen-For-Bukkit by DenizenScript.
the class dMaterial method getAttribute.
@Override
public String getAttribute(Attribute attribute) {
if (attribute == null) {
return null;
}
// TODO: Scrap getAttribute, make this functionality a core system
String attrLow = CoreUtilities.toLowerCase(attribute.getAttributeWithoutContext(1));
TagRunnable tr = registeredTags.get(attrLow);
if (tr != null) {
if (!tr.name.equals(attrLow)) {
net.aufdemrand.denizencore.utilities.debugging.dB.echoError(attribute.getScriptEntry() != null ? attribute.getScriptEntry().getResidingQueue() : null, "Using deprecated form of tag '" + tr.name + "': '" + attrLow + "'.");
}
return tr.run(attribute, this);
}
// Iterate through this object's properties' attributes
for (Property property : PropertyParser.getProperties(this)) {
String returned = property.getAttribute(attribute);
if (returned != null) {
return returned;
}
}
return new Element(identify()).getAttribute(attribute.fulfill(0));
}
use of net.aufdemrand.denizencore.objects.TagRunnable in project Denizen-For-Bukkit by DenizenScript.
the class dMaterial method registerTags.
public static void registerTags() {
// <--[tag]
// @attribute <m@material.has_gravity>
// @returns Element(Boolean)
// @description
// Returns whether the material is affected by gravity.
// -->
registerTag("has_gravity", new TagRunnable() {
@Override
public String run(Attribute attribute, dObject object) {
return new Element(((dMaterial) object).material.hasGravity()).getAttribute(attribute.fulfill(1));
}
});
// <--[tag]
// @attribute <m@material.id>
// @returns Element(Number)
// @description
// Returns the material's ID.
// -->
registerTag("id", new TagRunnable() {
@Override
public String run(Attribute attribute, dObject object) {
return new Element(((dMaterial) object).material.getId()).getAttribute(attribute.fulfill(1));
}
});
// <--[tag]
// @attribute <m@material.is_block>
// @returns Element(Boolean)
// @description
// Returns whether the material is a placeable block.
// -->
registerTag("is_block", new TagRunnable() {
@Override
public String run(Attribute attribute, dObject object) {
return new Element(((dMaterial) object).material.isBlock()).getAttribute(attribute.fulfill(1));
}
});
// <--[tag]
// @attribute <m@material.is_burnable>
// @returns Element(Boolean)
// @description
// Returns whether the material is a block that can burn away.
// -->
registerTag("is_burnable", new TagRunnable() {
@Override
public String run(Attribute attribute, dObject object) {
return new Element(((dMaterial) object).material.isBurnable()).getAttribute(attribute.fulfill(1));
}
});
// <--[tag]
// @attribute <m@material.is_edible>
// @returns Element(Boolean)
// @description
// Returns whether the material is edible.
// -->
registerTag("is_edible", new TagRunnable() {
@Override
public String run(Attribute attribute, dObject object) {
return new Element(((dMaterial) object).material.isEdible()).getAttribute(attribute.fulfill(1));
}
});
// <--[tag]
// @attribute <m@material.is_flammable>
// @returns Element(Boolean)
// @description
// Returns whether the material is a block that can catch fire.
// -->
registerTag("is_flammable", new TagRunnable() {
@Override
public String run(Attribute attribute, dObject object) {
return new Element(((dMaterial) object).material.isFlammable()).getAttribute(attribute.fulfill(1));
}
});
// <--[tag]
// @attribute <m@material.is_occluding>
// @returns Element(Boolean)
// @description
// Returns whether the material is a block that completely blocks vision.
// -->
registerTag("is_occluding", new TagRunnable() {
@Override
public String run(Attribute attribute, dObject object) {
return new Element(((dMaterial) object).material.isOccluding()).getAttribute(attribute.fulfill(1));
}
});
// <--[tag]
// @attribute <m@material.is_record>
// @returns Element(Boolean)
// @description
// Returns whether the material is a playable music disc.
// -->
registerTag("is_record", new TagRunnable() {
@Override
public String run(Attribute attribute, dObject object) {
return new Element(((dMaterial) object).material.isRecord()).getAttribute(attribute.fulfill(1));
}
});
// <--[tag]
// @attribute <m@material.is_solid>
// @returns Element(Boolean)
// @description
// Returns whether the material is a block that is solid (cannot be walked through).
// -->
registerTag("is_solid", new TagRunnable() {
@Override
public String run(Attribute attribute, dObject object) {
return new Element(!NMSHandler.getInstance().getBlockHelper().isSafeBlock(((dMaterial) object).material)).getAttribute(attribute.fulfill(1));
}
});
// <--[tag]
// @attribute <m@material.is_transparent>
// @returns Element(Boolean)
// @description
// Returns whether the material is a block that does not block any light.
// -->
registerTag("is_transparent", new TagRunnable() {
@Override
public String run(Attribute attribute, dObject object) {
return new Element(((dMaterial) object).material.isTransparent()).getAttribute(attribute.fulfill(1));
}
});
// <--[tag]
// @attribute <m@material.max_durability>
// @returns Element(Number)
// @description
// Returns the maximum durability of this material.
// -->
registerTag("max_durability", new TagRunnable() {
@Override
public String run(Attribute attribute, dObject object) {
return new Element(((dMaterial) object).material.getMaxDurability()).getAttribute(attribute.fulfill(1));
}
});
// <--[tag]
// @attribute <m@material.max_stack_size>
// @returns Element(Number)
// @description
// Returns the maximum amount of this material that can be held in a stack.
// -->
registerTag("max_stack_size", new TagRunnable() {
@Override
public String run(Attribute attribute, dObject object) {
return new Element(((dMaterial) object).material.getMaxStackSize()).getAttribute(attribute.fulfill(1));
}
});
// <--[tag]
// @attribute <m@material.is_made_of[<material>]>
// @returns Element(Boolean)
// @description
// Returns true if the material is a variety of the specified material.
// Example: <m@red_wool.is_made_of[m@wool]> will return true.
// -->
registerTag("is_made_of", new TagRunnable() {
@Override
public String run(Attribute attribute, dObject object) {
dMaterial compared = dMaterial.valueOf(attribute.getContext(1));
if (compared == null) {
return Element.FALSE.getAttribute(attribute.fulfill(1));
} else {
return new Element(((dMaterial) object).material == compared.getMaterial()).getAttribute(attribute.fulfill(1));
}
}
});
// <--[tag]
// @attribute <m@material.bukkit_enum>
// @returns Element
// @description
// Returns the bukkit Material enum value. For example: <m@birch_sapling.bukkit_enum>
// will return 'sapling'
// -->
registerTag("bukkit_enum", new TagRunnable() {
@Override
public String run(Attribute attribute, dObject object) {
return new Element(((dMaterial) object).material.name()).getAttribute(attribute.fulfill(1));
}
});
// <--[tag]
// @attribute <m@material.name>
// @returns Element
// @description
// Returns the name of the material.
// -->
registerTag("name", new TagRunnable() {
@Override
public String run(Attribute attribute, dObject object) {
return new Element(((dMaterial) object).forcedIdentity != null ? ((dMaterial) object).forcedIdentityLow : CoreUtilities.toLowerCase(((dMaterial) object).material.name())).getAttribute(attribute.fulfill(1));
}
});
// <--[tag]
// @attribute <m@material.full>
// @returns Element
// @description
// Returns the material's full identification.
// -->
registerTag("full", new TagRunnable() {
@Override
public String run(Attribute attribute, dObject object) {
if (((dMaterial) object).hasData()) {
return new Element(((dMaterial) object).identifyFull()).getAttribute(attribute.fulfill(1));
} else {
return new Element(((dMaterial) object).identify()).getAttribute(attribute.fulfill(1));
}
}
});
// <--[tag]
// @attribute <m@material.data>
// @returns Element(Number)
// @description
// Returns the bukkit Material data value. For example: <m@red_clay.data>
// will return '14'. Note: This kind of 'material identification' has been deprecated
// by bukkit and should be used sparingly.
// -->
registerTag("data", new TagRunnable() {
@Override
public String run(Attribute attribute, dObject object) {
return new Element(((dMaterial) object).getData()).getAttribute(attribute.fulfill(1));
}
});
// <--[tag]
// @attribute <m@material.item>
// @returns dItem
// @description
// Returns an item of the material.
// -->
registerTag("item", new TagRunnable() {
@Override
public String run(Attribute attribute, dObject object) {
return new dItem(((dMaterial) object), 1).getAttribute(attribute.fulfill(1));
}
});
// <--[tag]
// @attribute <m@material.type>
// @returns Element
// @description
// Always returns 'Material' for dMaterial objects. All objects fetchable by the Object Fetcher will return the
// type of object that is fulfilling this attribute.
// -->
registerTag("type", new TagRunnable() {
@Override
public String run(Attribute attribute, dObject object) {
return new Element("Material").getAttribute(attribute.fulfill(1));
}
});
}
Aggregations