Skip to content
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 @@ -16,7 +16,6 @@
import com.denizenscript.denizencore.objects.core.ListTag;
import com.denizenscript.denizencore.objects.core.QueueTag;
import com.denizenscript.denizencore.objects.core.ScriptTag;
import com.denizenscript.denizencore.objects.properties.Property;
import com.denizenscript.denizencore.objects.properties.PropertyParser;
import dev.unizen.denizen.objects.properties.entity.*;
import dev.unizen.denizen.objects.properties.material.*;
Expand Down Expand Up @@ -167,15 +166,22 @@ public static void registermainProperties() {
PropertyParser.registerProperty(MaterialLeaves.class, MaterialTag.class);
PropertyParser.registerProperty(MaterialLevel.class, MaterialTag.class);
PropertyParser.registerProperty(MaterialLightable.class, MaterialTag.class);
PropertyParser.registerProperty(MaterialMultipleFacing.class, MaterialTag.class);
PropertyParser.registerProperty(MaterialOpen.class, MaterialTag.class);
PropertyParser.registerProperty(MaterialOrientation.class, MaterialTag.class);
PropertyParser.registerProperty(MaterialRailShape.class, MaterialTag.class);
PropertyParser.registerProperty(MaterialRedstonePower.class, MaterialTag.class);
PropertyParser.registerProperty(MaterialRotation.class, MaterialTag.class);
PropertyParser.registerProperty(MaterialSnowy.class, MaterialTag.class);
PropertyParser.registerProperty(MaterialRepeaterDelay.class, MaterialTag.class);
PropertyParser.registerProperty(MaterialSaplingStage.class, MaterialTag.class);
PropertyParser.registerProperty(MaterialSeaPickles.class, MaterialTag.class);
PropertyParser.registerProperty(MaterialSnowLayers.class, MaterialTag.class);
PropertyParser.registerProperty(MaterialStairsShape.class, MaterialTag.class);
PropertyParser.registerProperty(MaterialStructureBlockMode.class, MaterialTag.class);
PropertyParser.registerProperty(MaterialSwitchFace.class, MaterialTag.class);
PropertyParser.registerProperty(MaterialWaterlogged.class, MaterialTag.class);
PropertyParser.registerProperty(MaterialTntUnstable.class, MaterialTag.class);
PropertyParser.registerProperty(MaterialTripwireDisarmed.class, MaterialTag.class);
PropertyParser.registerProperty(MaterialTurtleEggsAmount.class, MaterialTag.class);
PropertyParser.registerProperty(MaterialTurtleEggsHatch.class, MaterialTag.class);
}
if (NMSHandler.getVersion().isAtLeast(NMSVersion.v1_14)) {
PropertyParser.registerProperty(MaterialScaffoldingBottom.class,MaterialTag.class);
PropertyParser.registerProperty(MaterialScaffoldingDistanceToBottom.class, MaterialTag.class);
}

// register core TradeTag properties
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
package dev.unizen.denizen.objects.properties.material;

import com.denizenscript.denizen.objects.MaterialTag;
import com.denizenscript.denizen.utilities.debugging.Debug;
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.block.data.type.Repeater;

public class MaterialRepeaterDelay implements Property {

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

public static MaterialRepeaterDelay getFrom(ObjectTag material) {
if (!describes(material)) {
return null;
}
return new MaterialRepeaterDelay((MaterialTag) material);
}

public static final String[] handledTags = new String[] {
"delay", "max_delay", "min_delay"
};

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


///////////////////
// Instance Fields and Methods
/////////////

private MaterialRepeaterDelay(MaterialTag material) {
this.material = material;
}

private MaterialTag material;

private Repeater getRepeater() {
return (Repeater) material.getModernData().data;
}

private int getDelay() {
return getRepeater().getDelay();
}

private int getMaxDelay() {
return getRepeater().getMaximumDelay();
}

private int getMinDelay() {
return getRepeater().getMinimumDelay();
}

/////////
// Property Methods
///////

@Override
public String getPropertyString() {
return getDelay() != getMinDelay() ? String.valueOf(getDelay()) : null;
}

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

///////////
// ObjectTag Attributes
////////

@Override
public String getAttribute(Attribute attribute) {
if (attribute == null) {
return null;
}

// <--[tag]
// @attribute <MaterialTag.max_delay>
// @returns ElementTag(Number)
// @group properties
// @description
// Returns the maximum delay the redstone repeater material can have.
// -->
if (attribute.startsWith("max_delay")) {
return new ElementTag(getMaxDelay()).getAttribute(attribute.fulfill(1));
}

// <--[tag]
// @attribute <MaterialTag.min_delay>
// @returns ElementTag(Number)
// @group properties
// @description
// Returns the minimum delay the redstone repeater material can have.
// -->
if (attribute.startsWith("min_delay")) {
return new ElementTag(getMinDelay()).getAttribute(attribute.fulfill(1));
}

// <--[tag]
// @attribute <MaterialTag.delay>
// @returns ElementTag(Number)
// @mechanism MaterialTag.delay
// @group properties
// @description
// Returns the delay the redstone repeater material currently has.
// -->
if (attribute.startsWith("delay")) {
return new ElementTag(getDelay()).getAttribute(attribute.fulfill(1));
}

return null;
}

@Override
public void adjust(Mechanism mechanism) {

// <--[mechanism]
// @object MaterialTag
// @name delay
// @input ElementTag(Number)
// @description
// Sets the delay of the redstone repeater material.
// @tags
// <MaterialTag.delay>
// <MaterialTag.min_delay>
// <MaterialTag.max_delay>
// -->
if (mechanism.matches("delay") && mechanism.requireInteger()) {
int delay = mechanism.getValue().asInt();
if (delay < getMinDelay() || delay > getMaxDelay()) {
Debug.echoError("Invalid delay specified! Must be between '" + getMinDelay() + "' and '" + getMaxDelay() + "'!");
return;
}
getRepeater().setDelay(delay);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
package dev.unizen.denizen.objects.properties.material;

import com.denizenscript.denizen.objects.MaterialTag;
import com.denizenscript.denizen.utilities.debugging.Debug;
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.block.data.type.Sapling;

public class MaterialSaplingStage implements Property {

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

public static MaterialSaplingStage getFrom(ObjectTag material) {
if (!describes(material)) {
return null;
}
return new MaterialSaplingStage((MaterialTag) material);
}

public static final String[] handledTags = new String[] {
"growth_stage", "max_growth_stage"
};

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


///////////////////
// Instance Fields and Methods
/////////////

private MaterialSaplingStage(MaterialTag material) {
this.material = material;
}

private MaterialTag material;

private Sapling getSapling() {
return (Sapling) material.getModernData().data;
}

private int getStage() {
return getSapling().getStage();
}

private int getMaxStage() {
return getSapling().getMaximumStage();
}

/////////
// Property Methods
///////

@Override
public String getPropertyString() {
return getStage() != 0 ? String.valueOf(getStage()) : null;
}

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

///////////
// ObjectTag Attributes
////////

@Override
public String getAttribute(Attribute attribute) {
if (attribute == null) {
return null;
}

// <--[tag]
// @attribute <MaterialTag.max_growth_stage>
// @returns ElementTag(Number)
// @group properties
// @description
// Returns the maximum growth stage of the sapling or bamboo material.
// Once the material's growth stage reaches this number, the material will attempt to grow into a tree as its next stage.
// -->
if (attribute.startsWith("max_growth_stage")) {
return new ElementTag(getMaxStage()).getAttribute(attribute.fulfill(1));
}

// <--[tag]
// @attribute <MaterialTag.growth_stage>
// @returns ElementTag(Number)
// @mechanism MaterialTag.growth_stage
// @group properties
// @description
// Returns the growth stage of the sapling or bamboo material.
// -->
if (attribute.startsWith("growth_stage")) {
return new ElementTag(getStage()).getAttribute(attribute.fulfill(1));
}

return null;
}

@Override
public void adjust(Mechanism mechanism) {

// <--[mechanism]
// @object MaterialTag
// @name growth_stage
// @input ElementTag(Number)
// @description
// Sets the growth stage of the sapling or bamboo material.
// @tags
// <MaterialTag.growth_stage>
// <MaterialTag.max_growth_stage>
// -->
if (mechanism.matches("growth_stage") && mechanism.requireInteger()) {
int stage = mechanism.getValue().asInt();
if (stage < 0 || stage > getMaxStage()) {
Debug.echoError("The growth stage must be between '0' and '" + getMaxStage() + "'!");
return;
}
getSapling().setStage(stage);
}
}
}
Loading