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.note,mode,locked Property Modernization #2663

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,52 +2,46 @@

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

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

public static boolean describes(ObjectTag material) {
return material instanceof MaterialTag
&& ((MaterialTag) material).hasModernData()
&& ((MaterialTag) material).getModernData() instanceof Repeater;
}
// <--[property]
// @object MaterialTag
// @name is_locked
// @input ElementTag(Boolean)
// @description
// Controls whether this redstone repeater material is locked.
// -->

public static MaterialLocked getFrom(ObjectTag _material) {
if (!describes(_material)) {
return null;
}
else {
return new MaterialLocked((MaterialTag) _material);
}
public static boolean describes(MaterialTag material) {
BlockData data = material.getModernData();
return data instanceof Repeater;
}

public static final String[] handledMechs = new String[] {
"is_locked"
};
MaterialTag material;

public MaterialLocked(MaterialTag _material) {
material = _material;
@Override
public ElementTag getPropertyValue() {
return new ElementTag(isLocked());
}

MaterialTag material;
@Override
public String getPropertyId() {
return "is_locked";
}

public static void register() {
@Override
public void setPropertyValue(ElementTag value, Mechanism mechanism) {
if (mechanism.requireBoolean()) {
getRepeater().setLocked(value.asBoolean());
}
}

// <--[tag]
// @attribute <MaterialTag.is_locked>
// @returns ElementTag(Boolean)
// @mechanism MaterialTag.is_locked
// @group properties
// @description
// Returns whether this redstone repeater material is locked.
// -->
PropertyParser.registerStaticTag(MaterialLocked.class, ElementTag.class, "is_locked", (attribute, material) -> {
return new ElementTag(material.isLocked());
});
public static void register() {
autoRegister("is_locked", MaterialLocked.class, ElementTag.class, true);
}

public Repeater getRepeater() {
Expand All @@ -57,31 +51,4 @@ public Repeater getRepeater() {
public boolean isLocked() {
return getRepeater().isLocked();
}

@Override
public String getPropertyString() {
return String.valueOf(isLocked());
}

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

@Override
public void adjust(Mechanism mechanism) {

// <--[mechanism]
// @object MaterialTag
// @name is_locked
// @input ElementTag(Boolean)
// @description
// Sets this redstone repeater material to be locked.
// @tags
// <MaterialTag.is_locked>
// -->
if (mechanism.matches("is_locked") && mechanism.requireBoolean()) {
getRepeater().setLocked(mechanism.getValue().asBoolean());
}
}
}
Loading