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.leaf_size,instrument,hinge Property Modernization #2664

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,83 +2,49 @@

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.Door;

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

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

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

public static final String[] handledMechs = new String[] {
"hinge"
};
// <--[property]
// @object MaterialTag
// @name hinge
// @input ElementTag
// @description
// Controls a door's hinge side, either LEFT or RIGHT.
// -->

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

MaterialTag material;

public static void register() {

// <--[tag]
// @attribute <MaterialTag.hinge>
// @returns ElementTag
// @mechanism MaterialTag.hinge
// @group properties
// @description
// Returns a door's hinge side.
// Output is LEFT or RIGHT.
// -->
PropertyParser.registerStaticTag(MaterialHinge.class, ElementTag.class, "hinge", (attribute, material) -> {
return new ElementTag(material.getDoor().getHinge());
});
}

public Door getDoor() {
return (Door) material.getModernData();
@Override
public String getPropertyId() {
return "hinge";
}

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

@Override
public String getPropertyId() {
return "hinge";
public void setPropertyValue(ElementTag value, Mechanism mechanism) {
if (mechanism.requireEnum(Door.Hinge.class)) {
getDoor().setHinge(value.asEnum(Door.Hinge.class));
}
}

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

// <--[mechanism]
// @object MaterialTag
// @name hinge
// @input ElementTag
// @description
// Sets a door's hinge side to LEFT or RIGHT.
// @tags
// <MaterialTag.hinge>
// -->
if (mechanism.matches("hinge") && mechanism.requireEnum(Door.Hinge.class)) {
getDoor().setHinge(Door.Hinge.valueOf(mechanism.getValue().asString().toUpperCase()));
}
public Door getDoor() {
return (Door) material.getModernData();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,90 +2,52 @@

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.Instrument;
import org.bukkit.block.data.BlockData;
import org.bukkit.block.data.type.NoteBlock;

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

public static boolean describes(ObjectTag material) {
return material instanceof MaterialTag
&& ((MaterialTag) material).hasModernData()
&& ((MaterialTag) material).getModernData() instanceof NoteBlock;
}
// <--[property]
// @object MaterialTag
// @name instrument
// @input ElementTag
// @description
// Controls the name of the instrument played from this note block,
// see list at <@link url https://hub.spigotmc.org/javadocs/spigot/org/bukkit/Instrument.html>.
// For the instrument that a material *would* produce if below a noteblock <@link tag MaterialTag.produced_instrument>.
// -->

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

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

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

MaterialTag material;

public static void register() {

// <--[tag]
// @attribute <MaterialTag.instrument>
// @returns ElementTag
// @mechanism MaterialTag.instrument
// @group properties
// @description
// Returns the name of the instrument played from this note block,
// see list at <@link url https://hub.spigotmc.org/javadocs/spigot/org/bukkit/Instrument.html>.
// For the instrument that a material *would* produce if below a noteblock <@link tag MaterialTag.produced_instrument>.
// -->
PropertyParser.registerStaticTag(MaterialInstrument.class, ElementTag.class, "instrument", (attribute, material) -> {
return new ElementTag(material.getNoteBlock().getInstrument());
});
}

public NoteBlock getNoteBlock() {
return (NoteBlock) material.getModernData();
}

public void setInstrument(String instrument) {
getNoteBlock().setInstrument(Instrument.valueOf(instrument));
@Override
public String getPropertyId() {
return "instrument";
}

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

@Override
public String getPropertyId() {
return "instrument";
public void setPropertyValue(ElementTag value, Mechanism mechanism) {
if (mechanism.requireEnum(Instrument.class)) {
getNoteBlock().setInstrument(value.asEnum(Instrument.class));
}
}

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

// <--[mechanism]
// @object MaterialTag
// @name instrument
// @input ElementTag
// @description
// Sets the instrument played from this note block,
// for valid instruments see list at <@link url https://hub.spigotmc.org/javadocs/spigot/org/bukkit/Instrument.html>.
// @tags
// <MaterialTag.instrument>
// -->
if (mechanism.matches("instrument") && mechanism.requireEnum(Instrument.class)) {
setInstrument(mechanism.getValue().asString().toUpperCase());
}
public NoteBlock getNoteBlock() {
return (NoteBlock) material.getModernData();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,66 +2,31 @@

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.Bamboo;

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

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

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

public static final String[] handledMechs = new String[] {
"leaf_size"
};
// <--[property]
// @object MaterialTag
// @name leaf_size
// @input ElementTag
// @description
// Controls the size of the leaves for this bamboo block.
// Valid values are SMALL, LARGE, or NONE.
// -->

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

MaterialTag material;

public static void register() {

// <--[tag]
// @attribute <MaterialTag.leaf_size>
// @returns ElementTag
// @mechanism MaterialTag.leaf_size
// @group properties
// @description
// Returns the size of the leaves for this bamboo block.
// Output is SMALL, LARGE, or NONE.
// -->
PropertyParser.registerStaticTag(MaterialLeafSize.class, ElementTag.class, "leaf_size", (attribute, material) -> {
return new ElementTag(material.getBamboo().getLeaves());
});
}

public Bamboo getBamboo() {
return (Bamboo) material.getModernData();
}

public void setLeafSize(String size) {
getBamboo().setLeaves(Bamboo.Leaves.valueOf(size));
}

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

@Override
Expand All @@ -70,20 +35,17 @@ public String getPropertyId() {
}

@Override
public void adjust(Mechanism mechanism) {

// <--[mechanism]
// @object MaterialTag
// @name leaf_size
// @input ElementTag
// @description
// Sets the size of the leaves for this bamboo block.
// Valid input is SMALL, LARGE, or NONE.
// @tags
// <MaterialTag.leaf_size>
// -->
if (mechanism.matches("leaf_size") && mechanism.requireEnum(Bamboo.Leaves.class)) {
setLeafSize(mechanism.getValue().asString().toUpperCase());
public void setPropertyValue(ElementTag value, Mechanism mechanism) {
if (mechanism.requireEnum(Bamboo.Leaves.class)) {
getBamboo().setLeaves(value.asEnum(Bamboo.Leaves.class));
}
}

public static void register() {
autoRegister("leaf_size", MaterialLeafSize.class, ElementTag.class, false);
}

public Bamboo getBamboo() {
return (Bamboo) material.getModernData();
}
}