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 @@ -161,7 +160,18 @@ public static void registermainProperties() {
if (NMSHandler.getVersion().isAtLeast(NMSVersion.v1_13)) {
PropertyParser.registerProperty(MaterialAge.class, MaterialTag.class);
PropertyParser.registerProperty(MaterialAttached.class, MaterialTag.class);
PropertyParser.registerProperty(MaterialBedSide.class, MaterialTag.class);
PropertyParser.registerProperty(MaterialBrewingStandBottles.class, MaterialTag.class);
PropertyParser.registerProperty(MaterialBubbleColumnDrag.class, MaterialTag.class);
PropertyParser.registerProperty(MaterialCakeBites.class, MaterialTag.class);
PropertyParser.registerProperty(MaterialChestType.class, MaterialTag.class);
PropertyParser.registerProperty(MaterialCommandBlockConditional.class, MaterialTag.class);
PropertyParser.registerProperty(MaterialComparatorMode.class, MaterialTag.class);
PropertyParser.registerProperty(MaterialDaylightDetectorInverted.class, MaterialTag.class);
PropertyParser.registerProperty(MaterialDirectional.class, MaterialTag.class);
PropertyParser.registerProperty(MaterialDispenserTriggered.class, MaterialTag.class);
PropertyParser.registerProperty(MaterialDoorHinge.class, MaterialTag.class);
PropertyParser.registerProperty(MaterialEndPortalFrameEye.class, MaterialTag.class);
PropertyParser.registerProperty(MaterialHalf.class, MaterialTag.class);
PropertyParser.registerProperty(MaterialSlab.class, MaterialTag.class);
PropertyParser.registerProperty(MaterialLeaves.class, MaterialTag.class);
Expand All @@ -177,6 +187,11 @@ public static void registermainProperties() {
PropertyParser.registerProperty(MaterialSwitchFace.class, MaterialTag.class);
PropertyParser.registerProperty(MaterialWaterlogged.class, MaterialTag.class);
}
if (NMSHandler.getVersion().isAtLeast(NMSVersion.v1_14)) {
PropertyParser.registerProperty(MaterialBambooLeaves.class, MaterialTag.class);
PropertyParser.registerProperty(MaterialBellAttachment.class, MaterialTag.class);
PropertyParser.registerProperty(MaterialCampfireSignal.class, MaterialTag.class);
}

// register core TradeTag properties
PropertyParser.registerProperty(TradeHasXp.class, TradeTag.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,14 @@ public ObjectTag getObjectAttribute(Attribute attribute) {
}

// <--[tag]
// @attribute <MaterialTag.maximum_level>
// @attribute <MaterialTag.max_level>
// @returns ElementTag(Number)
// @group properties
// @description
// Returns the maximum level for a levelable material (like water, lava, and Cauldrons), or a cake.
// NOTE: For cake materials, you may also use <MaterialTag.max_bites>.
// -->
if (attribute.startsWith("maximum_level")) {
if (attribute.startsWith("max_level") || attribute.startsWith("maximum_level")) {
return new ElementTag(getMax()).getObjectAttribute(attribute.fulfill(1));
}

Expand All @@ -68,6 +69,7 @@ public ObjectTag getObjectAttribute(Attribute attribute) {
// @group properties
// @description
// Returns the current level for a levelable material (like water, lava, and Cauldrons), or a cake.
// NOTE: For cake materials, you may also use <MaterialTag.bites>.
// -->
if (attribute.startsWith("level")) {
return new ElementTag(getCurrent()).getObjectAttribute(attribute.fulfill(1));
Expand Down Expand Up @@ -112,7 +114,10 @@ public void setCurrent(int level) {

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

@Override
Expand All @@ -131,7 +136,7 @@ public void adjust(Mechanism mechanism) {
// Sets the current level for a levelable material (like water, lava, and Cauldrons), or a cake.
// @tags
// <MaterialTag.level>
// <MaterialTag.maximum_level>
// <MaterialTag.max_level>
// -->
if (mechanism.matches("level") && mechanism.requireInteger()) {
int level = mechanism.getValue().asInt();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
package dev.unizen.denizen.objects.properties.material;

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.tags.Attribute;
import org.bukkit.block.data.type.Bamboo;

public class MaterialBambooLeaves implements Property {

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

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

public static final String[] handledTags = new String[] {
"bamboo_leaves"
};

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


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

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

private MaterialTag material;

private Bamboo getBamboo() {
return (Bamboo) material.getModernData().data;
}

private String getLeaves() {
return getBamboo().getLeaves().name();
}

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

@Override
public String getPropertyString() {
return getBamboo().getLeaves() != Bamboo.Leaves.NONE ? getLeaves() : null;
}

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

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

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

// <--[tag]
// @attribute <MaterialTag.bamboo_leaves>
// @returns ElementTag
// @mechanism MaterialTag.bamboo_leaves
// @group properties
// @description
// Returns the size of the leaves on this material, if the material is a bamboo block.
// Can be NONE, SMALL, or LARGE.
// -->
if (attribute.startsWith("bamboo_leaves")) {
return new ElementTag(getLeaves()).getAttribute(attribute.fulfill(1));
}

return null;
}

@Override
public void adjust(Mechanism mechanism) {

// <--[mechanism]
// @object MaterialTag
// @name bamboo_leaves
// @input ElementTag
// @description
// Sets the size of the leaves on this bamboo material.
// Can be NONE, SMALL, or LARGE.
// @tags
// <MaterialTag.bamboo_leaves>
// -->
if (mechanism.matches("bamboo_leaves") && mechanism.requireEnum(false, Bamboo.Leaves.values())) {
getBamboo().setLeaves(Bamboo.Leaves.valueOf(mechanism.getValue().asString().toUpperCase()));
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
package dev.unizen.denizen.objects.properties.material;

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.tags.Attribute;
import org.bukkit.block.data.type.Bed;

public class MaterialBedSide implements Property {

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

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

public static final String[] handledTags = new String[] {
"bed_side", "occupied"
};

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


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

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

private MaterialTag material;

private Bed getBed() {
return (Bed) material.getModernData().data;
}

private String getSide() {
return getBed().getPart().name();
}

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

@Override
public String getPropertyString() {
return getSide();
}

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

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

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

// <--[tag]
// @attribute <MaterialTag.bed_side>
// @returns ElementTag
// @mechanism MaterialTag.bed_side
// @group properties
// @description
// If the material is a bed, returns which side of the bed it is.
// Can be either HEAD or FOOT.
// -->
if (attribute.startsWith("bed_side")) {
return new ElementTag(getSide()).getAttribute(attribute.fulfill(1));
}

// <--[tag]
// @attribute <MaterialTag.occupied>
// @returns ElementTag(Boolean)
// @group properties
// @description
// If the material is a bed, returns whether it is occupied.
// -->
if (attribute.startsWith("occupied")) {
return new ElementTag(getBed().isOccupied()).getAttribute(attribute.fulfill(1));
}

return null;
}

@Override
public void adjust(Mechanism mechanism) {

// <--[mechanism]
// @object MaterialTag
// @name bed_side
// @input ElementTag
// @description
// If the material is a bed, sets which side of the bed the material is.
// @tags
// <MaterialTag.bed_side>
// -->
if (mechanism.matches("bed_side") && mechanism.requireEnum(false, Bed.Part.values())) {
getBed().setPart(Bed.Part.valueOf(mechanism.getValue().asString().toUpperCase()));
}
}
}
Loading