Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MaterialTag.shape,power,persistent Property Modernization #2662

Open
wants to merge 4 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,82 +2,47 @@

import com.denizenscript.denizen.objects.MaterialTag;
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.objects.properties.PropertyParser;
import org.bukkit.block.data.BlockData;
import org.bukkit.block.data.type.Leaves;

public class MaterialPersistent implements Property {
public class MaterialPersistent extends MaterialProperty<ElementTag> {

public static boolean describes(ObjectTag material) {
return material instanceof MaterialTag
&& ((MaterialTag) material).hasModernData()
&& ((MaterialTag) material).getModernData() instanceof Leaves;
}
// <--[property]
// @object MaterialTag
// @name persistent
// @input ElementTag(Boolean)
// @description
// Controls whether this block will decay from being too far away from a tree.
// -->

public static MaterialPersistent getFrom(ObjectTag _material) {
if (!describes(_material)) {
return null;
}
else {
return new MaterialPersistent((MaterialTag) _material);
}
}

public static final String[] handledMechs = new String[] {
"persistent"
};

public MaterialPersistent(MaterialTag _material) {
material = _material;
public static boolean describes(MaterialTag material) {
BlockData data = material.getModernData();
return data instanceof Leaves;
}

MaterialTag material;

public static void register() {

// <--[tag]
// @attribute <MaterialTag.persistent>
// @returns ElementTag(Boolean)
// @mechanism MaterialTag.persistent
// @group properties
// @description
// Returns whether this block will decay from being too far away from a tree.
// -->
PropertyParser.registerStaticTag(MaterialPersistent.class, ElementTag.class, "persistent", (attribute, material) -> {
return new ElementTag(material.getLeaves().isPersistent());
});
}

public Leaves getLeaves() {
return (Leaves) material.getModernData();
@Override
public String getPropertyId() {
return "persistent";
}

@Override
public String getPropertyString() {
return String.valueOf(getLeaves().isPersistent());
public ElementTag getPropertyValue() {
return new ElementTag(getLeaves().isPersistent());
}

@Override
public String getPropertyId() {
return "persistent";
public void setPropertyValue(ElementTag value, Mechanism mechanism) {
getLeaves().setPersistent(value.asBoolean());
}

@Override
public void adjust(Mechanism mechanism) {
public static void register() {
autoRegister("persistent", MaterialPersistent.class, ElementTag.class, true);
}

// <--[mechanism]
// @object MaterialTag
// @name persistent
// @input ElementTag(Boolean)
// @description
// Sets leaves blocks to ignore decay, or to obey it.
// @tags
// <MaterialTag.persistent>
// -->
if (mechanism.matches("persistent") && mechanism.requireBoolean()) {
getLeaves().setPersistent(mechanism.getValue().asBoolean());
}
public Leaves getLeaves() {
return (Leaves) material.getModernData();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,90 +2,41 @@

import com.denizenscript.denizen.objects.MaterialTag;
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.objects.properties.PropertyParser;
import org.bukkit.block.data.AnaloguePowerable;
import org.bukkit.block.data.BlockData;

public class MaterialPower implements Property {
public class MaterialPower extends MaterialProperty<ElementTag> {

public static boolean describes(ObjectTag material) {
return material instanceof MaterialTag
&& ((MaterialTag) material).hasModernData()
&& ((MaterialTag) material).getModernData() instanceof AnaloguePowerable;
}
// <--[property]
// @object MaterialTag
// @name power
// @input ElementTag(Number)
// @description
// Controls the redstone power level of an analogue-powerable block.
// -->

public static MaterialPower getFrom(ObjectTag _material) {
if (!describes(_material)) {
return null;
}
else {
return new MaterialPower((MaterialTag) _material);
}
}

public static final String[] handledMechs = new String[] {
"power"
};

public MaterialPower(MaterialTag _material) {
material = _material;
public static boolean describes(MaterialTag material) {
BlockData data = material.getModernData();
return data instanceof AnaloguePowerable;
}

MaterialTag material;

public static void register() {

// <--[tag]
// @attribute <MaterialTag.power>
// @returns ElementTag(Number)
// @mechanism MaterialTag.power
// @group properties
// @description
// Returns the redstone power level of an analogue-powerable block.
// -->
PropertyParser.registerStaticTag(MaterialPower.class, ElementTag.class, "power", (attribute, material) -> {
return new ElementTag(((AnaloguePowerable) material.material.getModernData()).getPower());
});

// <--[tag]
// @attribute <MaterialTag.max_power>
// @returns ElementTag(Number)
// @mechanism MaterialTag.power
// @group properties
// @description
// Returns the maximum redstone power an analogue-powerable block can have.
// -->
PropertyParser.registerStaticTag(MaterialPower.class, ElementTag.class, "max_power", (attribute, material) -> {
return new ElementTag(((AnaloguePowerable) material.material.getModernData()).getMaximumPower());
});
}

@Override
public String getPropertyString() {
return String.valueOf(((AnaloguePowerable) material.getModernData()).getPower());
}

@Override
public String getPropertyId() {
return "power";
}

@Override
public void adjust(Mechanism mechanism) {
public ElementTag getPropertyValue() {
return new ElementTag(((AnaloguePowerable) material.getModernData()).getPower());
}

// <--[mechanism]
// @object MaterialTag
// @name power
// @input ElementTag(Number)
// @description
// Sets the redstone power level of an analogue-powerable block.
// @tags
// <MaterialTag.power>
// <MaterialTag.max_power>
// -->
if (mechanism.matches("power") && mechanism.requireInteger()) {
@Override
public void setPropertyValue(ElementTag value, Mechanism mechanism) {
if (mechanism.requireInteger()) {
int power = mechanism.getValue().asInt();
AnaloguePowerable powerable = (AnaloguePowerable) material.getModernData();
if (power < 0 || power > powerable.getMaximumPower()) {
Expand All @@ -95,4 +46,20 @@ public void adjust(Mechanism mechanism) {
powerable.setPower(power);
}
}

public static void register() {
autoRegister("power", MaterialPower.class, ElementTag.class, true);

// <--[tag]
// @attribute <MaterialTag.max_power>
// @returns ElementTag(Number)
// @mechanism MaterialTag.power
// @group properties
// @description
// Returns the maximum redstone power an analogue-powerable block can have.
// -->
PropertyParser.registerStaticTag(MaterialPower.class, ElementTag.class, "max_power", (attribute, material) -> {
return new ElementTag(((AnaloguePowerable) material.material.getModernData()).getMaximumPower());
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,84 +2,50 @@

import com.denizenscript.denizen.objects.MaterialTag;
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.objects.properties.PropertyParser;
import org.bukkit.block.data.BlockData;
import org.bukkit.block.data.type.Stairs;

public class MaterialShape implements Property {
public class MaterialShape extends MaterialProperty<ElementTag> {

public static boolean describes(ObjectTag material) {
return material instanceof MaterialTag
&& ((MaterialTag) material).hasModernData()
&& ((MaterialTag) material).getModernData() instanceof Stairs;
}

public static MaterialShape getFrom(ObjectTag _material) {
if (!describes(_material)) {
return null;
}
else {
return new MaterialShape((MaterialTag) _material);
}
}

public static final String[] handledMechs = new String[] {
"shape"
};
// <--[property]
// @object MaterialTag
// @name shape
// @input ElementTag
// @description
// Controls the shape of a block.
// For stairs, the corner shape can be INNER_LEFT, INNER_RIGHT, OUTER_LEFT, OUTER_RIGHT, or STRAIGHT.
// -->

public MaterialShape(MaterialTag _material) {
material = _material;
public static boolean describes(MaterialTag material) {
BlockData data = material.getModernData();
return data instanceof Stairs;
}

MaterialTag material;

public static void register() {

// <--[tag]
// @attribute <MaterialTag.shape>
// @returns ElementTag
// @mechanism MaterialTag.shape
// @group properties
// @description
// Returns the shape of a block.
// For stairs, output is the corner shape as INNER_LEFT, INNER_RIGHT, OUTER_LEFT, OUTER_RIGHT, or STRAIGHT.
// -->
PropertyParser.registerStaticTag(MaterialShape.class, ElementTag.class, "shape", (attribute, material) -> {
return new ElementTag(material.getStairs().getShape());
});
}

public Stairs getStairs() {
return (Stairs) material.getModernData();
@Override
public String getPropertyId() {
return "shape";
}

@Override
public String getPropertyString() {
return getStairs().getShape().name();
public ElementTag getPropertyValue() {
return new ElementTag(getStairs().getShape());
}

@Override
public String getPropertyId() {
return "shape";
public void setPropertyValue(ElementTag value, Mechanism mechanism) {
if (mechanism.requireEnum(Stairs.Shape.class)) {
getStairs().setShape(Stairs.Shape.valueOf(value.asString().toUpperCase()));
}
}

@Override
public void adjust(Mechanism mechanism) {
public static void register() {
autoRegister("shape", MaterialShape.class, ElementTag.class, true);
}

// <--[mechanism]
// @object MaterialTag
// @name shape
// @input ElementTag
// @description
// Sets the shape of a block.
// For stairs, input is the corner shape as INNER_LEFT, INNER_RIGHT, OUTER_LEFT, OUTER_RIGHT, or STRAIGHT.
// @tags
// <MaterialTag.shape>
// -->
if (mechanism.matches("shape") && mechanism.requireEnum(Stairs.Shape.class)) {
getStairs().setShape(Stairs.Shape.valueOf(mechanism.getValue().asString().toUpperCase()));
}
public Stairs getStairs() {
return (Stairs) material.getModernData();
}
}