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 @@ -162,21 +161,29 @@ public static void registermainProperties() {
PropertyParser.registerProperty(MaterialAge.class, MaterialTag.class);
PropertyParser.registerProperty(MaterialAttached.class, MaterialTag.class);
PropertyParser.registerProperty(MaterialDirectional.class, MaterialTag.class);
PropertyParser.registerProperty(MaterialFarmlandMoisture.class, MaterialTag.class);
PropertyParser.registerProperty(MaterialHalf.class, MaterialTag.class);
PropertyParser.registerProperty(MaterialSlab.class, MaterialTag.class);
PropertyParser.registerProperty(MaterialLeaves.class, MaterialTag.class);
PropertyParser.registerProperty(MaterialGateInStoneWall.class, MaterialTag.class);
PropertyParser.registerProperty(MaterialHopperEnabled.class, MaterialTag.class);
PropertyParser.registerProperty(MaterialJukeboxRecord.class, MaterialTag.class);
PropertyParser.registerProperty(MaterialLeavesDistance.class, MaterialTag.class);
PropertyParser.registerProperty(MaterialLeavesPersistence.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(MaterialNoteblockInstrument.class, MaterialTag.class);
PropertyParser.registerProperty(MaterialNoteblockNote.class, MaterialTag.class);
PropertyParser.registerProperty(MaterialPistonExtended.class, MaterialTag.class);
PropertyParser.registerProperty(MaterialPistonHeadRetracting.class, MaterialTag.class);
PropertyParser.registerProperty(MaterialPistonType.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(MaterialRedstoneConnection.class, MaterialTag.class);
PropertyParser.registerProperty(MaterialSwitchFace.class, MaterialTag.class);
PropertyParser.registerProperty(MaterialWaterlogged.class, MaterialTag.class);
}
if (NMSHandler.getVersion().isAtLeast(NMSVersion.v1_14)) {
PropertyParser.registerProperty(MaterialLanternHanging.class, MaterialTag.class);
PropertyParser.registerProperty(MaterialLecternBook.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
@@ -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.Farmland;

public class MaterialFarmlandMoisture implements Property {

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

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

public static final String[] handledTags = new String[] {
"moisture", "max_moisture"
};

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


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

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

private MaterialTag material;

private Farmland getFarmland() {
return (Farmland) material.getModernData().data;
}

private int getMoisture() {
return getFarmland().getMoisture();
}

private int getMaxMoisture() {
return getFarmland().getMoisture();
}

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

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

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

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

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

// <--[tag]
// @attribute <MaterialTag.max_moisture>
// @returns ElementTag(Number)
// @group properties
// @description
// Returns the maximum moisture level of the farmland material.
// -->
if (attribute.startsWith("max_moisture")) {
return new ElementTag(getMaxMoisture()).getAttribute(attribute.fulfill(1));
}

// <--[tag]
// @attribute <MaterialTag.moisture>
// @returns ElementTag(Number)
// @mechanism MaterialTag.moisture
// @group properties
// @description
// Returns the moisture level of the farmland material.
// -->
if (attribute.startsWith("moisture")) {
return new ElementTag(getMoisture()).getAttribute(attribute.fulfill(1));
}

return null;
}

@Override
public void adjust(Mechanism mechanism) {

// <--[mechanism]
// @object MaterialTag
// @name moisture
// @input ElementTag(Number)
// @description
// Sets the moisture level of the farmland material.
// Cannot be higher than the max moisture level.
// @tags
// <MaterialTag.moisture>
// <MaterialTag.max_moisture>
// -->
if (mechanism.matches("moisture") && mechanism.requireInteger()) {
int moisture = mechanism.getValue().asInt();
if (moisture < 0 || moisture > getMaxMoisture()) {
Debug.echoError("The moisture level must be between '0' and '" + getMaxMoisture() + "'!");
return;
}
getFarmland().setMoisture(moisture);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
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.Gate;

public class MaterialGateInStoneWall implements Property {

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

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

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

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


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

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

private MaterialTag material;

private Gate getGate() {
return (Gate) material.getModernData().data;
}

private boolean isInWall() {
return getGate().isInWall();
}

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

@Override
public String getPropertyString() {
return isInWall() ? "true" : null;
}

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

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

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

// <--[tag]
// @attribute <MaterialTag.in_stone_wall>
// @returns ElementTag(Boolean)
// @mechanism MaterialTag.in_stone_wall
// @group properties
// @description
// Returns whether this fence gate material is attached to a stone wall.
// -->
if (attribute.startsWith("in_stone_wall")) {
return new ElementTag(isInWall()).getAttribute(attribute.fulfill(1));
}

return null;
}

@Override
public void adjust(Mechanism mechanism) {

// <--[mechanism]
// @object MaterialTag
// @name in_stone_wall
// @input ElementTag(Boolean)
// @description
// Sets whether this fence gate material is attached to a stone wall.
// If true, then the material's texture is lowered.
// @tags
// <MaterialTag.in_stone_wall>
// -->
if (mechanism.matches("in_stone_wall") && mechanism.requireBoolean()) {
getGate().setInWall(mechanism.getValue().asBoolean());
}
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.denizenscript.denizen.objects.properties.material;
package dev.unizen.denizen.objects.properties.material;

import com.denizenscript.denizen.objects.MaterialTag;
import com.denizenscript.denizencore.objects.core.ElementTag;
Expand Down
Loading