diff --git a/plugin/src/main/java/net/aufdemrand/denizen/objects/dMaterial.java b/plugin/src/main/java/net/aufdemrand/denizen/objects/dMaterial.java index 2fb56c5510..db2bba0715 100644 --- a/plugin/src/main/java/net/aufdemrand/denizen/objects/dMaterial.java +++ b/plugin/src/main/java/net/aufdemrand/denizen/objects/dMaterial.java @@ -505,6 +505,23 @@ public String run(Attribute attribute, dObject object) { } }); + // <--[tag] + // @attribute + // @returns Element(Boolean) + // @group properties + // @description + // Returns whether the material is a is_directional material. + // When this returns true, <@link tag m@material.direction>, <@link tag m@material.valid_directions>, + // and <@link mechanism dMaterial.direction> are accessible. + // --> + registerTag("is_bisected", new TagRunnable() { + @Override + public String run(Attribute attribute, dObject object) { + return new Element(MaterialHalf.describes(object)) + .getAttribute(attribute.fulfill(1)); + } + }); + // <--[tag] // @attribute // @returns Element(Boolean) diff --git a/plugin/src/main/java/net/aufdemrand/denizen/objects/properties/PropertyRegistry.java b/plugin/src/main/java/net/aufdemrand/denizen/objects/properties/PropertyRegistry.java index 6f6b85d570..d99ab3b4e4 100644 --- a/plugin/src/main/java/net/aufdemrand/denizen/objects/properties/PropertyRegistry.java +++ b/plugin/src/main/java/net/aufdemrand/denizen/objects/properties/PropertyRegistry.java @@ -13,9 +13,7 @@ import net.aufdemrand.denizen.objects.properties.inventory.InventorySize; import net.aufdemrand.denizen.objects.properties.inventory.InventoryTitle; import net.aufdemrand.denizen.objects.properties.item.*; -import net.aufdemrand.denizen.objects.properties.material.MaterialAge; -import net.aufdemrand.denizen.objects.properties.material.MaterialHalf; -import net.aufdemrand.denizen.objects.properties.material.MaterialLevel; +import net.aufdemrand.denizen.objects.properties.material.*; import net.aufdemrand.denizen.objects.properties.trade.*; import net.aufdemrand.denizencore.objects.Element; import net.aufdemrand.denizencore.objects.dList; @@ -132,6 +130,7 @@ public static void registermainProperties() { // register core dMaterial properties if (NMSHandler.getVersion().isAtLeast(NMSVersion.v1_13_R2)) { PropertyParser.registerProperty(MaterialAge.class, dMaterial.class); + PropertyParser.registerProperty(MaterialDirectional.class, dMaterial.class); PropertyParser.registerProperty(MaterialHalf.class, dMaterial.class); PropertyParser.registerProperty(MaterialLevel.class, dMaterial.class); } diff --git a/plugin/src/main/java/net/aufdemrand/denizen/objects/properties/material/MaterialDirectional.java b/plugin/src/main/java/net/aufdemrand/denizen/objects/properties/material/MaterialDirectional.java new file mode 100644 index 0000000000..986f303d90 --- /dev/null +++ b/plugin/src/main/java/net/aufdemrand/denizen/objects/properties/material/MaterialDirectional.java @@ -0,0 +1,120 @@ +package net.aufdemrand.denizen.objects.properties.material; + +import net.aufdemrand.denizen.objects.dMaterial; +import net.aufdemrand.denizencore.objects.Element; +import net.aufdemrand.denizencore.objects.Mechanism; +import net.aufdemrand.denizencore.objects.dList; +import net.aufdemrand.denizencore.objects.dObject; +import net.aufdemrand.denizencore.objects.properties.Property; +import net.aufdemrand.denizencore.tags.Attribute; +import org.bukkit.block.BlockFace; +import org.bukkit.block.data.Directional; + +public class MaterialDirectional implements Property { + + public static boolean describes(dObject material) { + return material instanceof dMaterial + && ((dMaterial) material).hasModernData() + && ((dMaterial) material).getModernData().data instanceof Directional; + } + + public static MaterialDirectional getFrom(dObject _material) { + if (!describes(_material)) { + return null; + } + else { + return new MaterialDirectional((dMaterial) _material); + } + } + + public static final String[] handledTags = new String[] { + "direction", "valid_directions" + }; + + public static final String[] handledMechs = new String[] { + "direction" + }; + + + private MaterialDirectional(dMaterial _material) { + material = _material; + } + + dMaterial material; + + @Override + public String getAttribute(Attribute attribute) { + + if (attribute == null) { + return null; + } + + // <--[tag] + // @attribute + // @returns Element + // @mechanism dMaterial.direction + // @group properties + // @description + // Returns a list of directions that are valid for a directional material. + // See also <@link tag m@matereial.direction> + // --> + if (attribute.startsWith("valid_directions")) { + dList toReturn = new dList(); + for (BlockFace face : getDirectional().getFaces()) { + toReturn.add(face.name()); + } + return toReturn.getAttribute(attribute.fulfill(1)); + } + + // <--[tag] + // @attribute + // @returns Element + // @mechanism dMaterial.direction + // @group properties + // @description + // Returns the current facing direction for a directional material (like a door or a bed). + // Output is a direction name like "NORTH". + // --> + if (attribute.startsWith("direction")) { + return new Element(getDirectional().getFacing().name()).getAttribute(attribute.fulfill(1)); + } + + return null; + } + + public Directional getDirectional() { + return (Directional) material.getModernData().data; + } + + public BlockFace getDirection() { + return getDirectional().getFacing(); + } + + @Override + public String getPropertyString() { + return getDirectional().getFacing().name(); + } + + @Override + public String getPropertyId() { + return "direction"; + } + + @Override + public void adjust(Mechanism mechanism) { + + // <--[mechanism] + // @object dMaterial + // @name direction + // @input Element + // @description + // Sets the current facing direction for a directional material (like a door or a bed). + // @tags + // + // + // --> + if (mechanism.matches("direction") && mechanism.requireEnum(false, BlockFace.values())) { + getDirectional().setFacing(BlockFace.valueOf(mechanism.getValue().asString().toUpperCase())); + } + } +}