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

Modernized Properties Part 1 #2661

Draft
wants to merge 7 commits into
base: dev
Choose a base branch
from
Draft
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,53 +2,82 @@

import com.denizenscript.denizen.objects.MaterialTag;
import com.denizenscript.denizencore.objects.Mechanism;
import com.denizenscript.denizencore.objects.ObjectTag;
import com.denizenscript.denizencore.objects.core.ListTag;
import com.denizenscript.denizencore.objects.properties.Property;
import com.denizenscript.denizencore.objects.properties.PropertyParser;
import com.denizenscript.denizencore.utilities.CoreUtilities;
import org.bukkit.block.BlockFace;
import org.bukkit.block.data.*;
import org.bukkit.block.data.BlockData;
import org.bukkit.block.data.type.RedstoneWire;
import org.bukkit.block.data.type.Wall;

public class MaterialSides implements Property {
public class MaterialSides extends MaterialProperty<ListTag> {

// <--[property]
// @object MaterialTag
// @name sides
// @input ListTag
// @description
// Controls the list of heights for a wall block, or connections for a redstone wire, in order North|East|South|West|Vertical.
// For wall blocks: For n/e/s/w, can be "tall", "low", or "none". For vertical, can be "tall" or "none".
// For redstone wires: For n/e/s/w, can be "none", "side", or "up". No vertical.
// -->

public static boolean describes(MaterialTag material) {
BlockData data = material.getModernData();
return data instanceof Wall || data instanceof RedstoneWire;
}

public static boolean describes(ObjectTag material) {
if (!(material instanceof MaterialTag)) {
return false;
}
MaterialTag mat = (MaterialTag) material;
if (!mat.hasModernData()) {
return false;
}
BlockData data = mat.getModernData();
if (!(data instanceof Wall) && !(data instanceof RedstoneWire)) {
return false;
}
return true;
MaterialTag material;

@Override
public ListTag getPropertyValue() {
return getSidesList();
}

public static MaterialSides getFrom(ObjectTag _material) {
if (!describes(_material)) {
return null;
}
else {
return new MaterialSides((MaterialTag) _material);
}
@Override
public String getPropertyId() {
return "sides";
}

public static final String[] handledMechs = new String[] {
"sides", "heights"
};
@Override
public void setPropertyValue(ListTag list, Mechanism mechanism) {

public MaterialSides(MaterialTag _material) {
material = _material;
// <--[mechanism]
// @object MaterialTag
// @name heights
// @input ElementTag
// @deprecated Use 'sides'
// @description
// Deprecated in favor of <@link property MaterialTag.sides>
// @tags
// <MaterialTag.heights>
// -->
if (isWall()) {
if (list.size() != 5) {
mechanism.echoError("Invalid sides list, size must be 5.");
return;
}
Wall wall = getWall();
wall.setHeight(BlockFace.NORTH, Wall.Height.valueOf(list.get(0).toUpperCase()));
wall.setHeight(BlockFace.EAST, Wall.Height.valueOf(list.get(1).toUpperCase()));
wall.setHeight(BlockFace.SOUTH, Wall.Height.valueOf(list.get(2).toUpperCase()));
wall.setHeight(BlockFace.WEST, Wall.Height.valueOf(list.get(3).toUpperCase()));
wall.setUp(CoreUtilities.toLowerCase(list.get(4)).equals("tall"));
}
else if (isWire()) {
if (list.size() != 4) {
mechanism.echoError("Invalid sides list, size must be 4.");
return;
}
RedstoneWire wire = getWire();
wire.setFace(BlockFace.NORTH, RedstoneWire.Connection.valueOf(list.get(0).toUpperCase()));
wire.setFace(BlockFace.EAST, RedstoneWire.Connection.valueOf(list.get(1).toUpperCase()));
wire.setFace(BlockFace.SOUTH, RedstoneWire.Connection.valueOf(list.get(2).toUpperCase()));
wire.setFace(BlockFace.WEST, RedstoneWire.Connection.valueOf(list.get(3).toUpperCase()));
}
}

MaterialTag material;

public static void register() {
autoRegister("sides", MaterialSides.class, ListTag.class, true, "heights");

// <--[tag]
// @attribute <MaterialTag.heights>
Expand All @@ -57,21 +86,8 @@ public static void register() {
// @group properties
// @deprecated Use 'sides'
// @description
// Deprecated in favor of <@link tag MaterialTag.sides>
// Deprecated in favor of <@link property MaterialTag.sides>
// -->
// <--[tag]
// @attribute <MaterialTag.sides>
// @returns ListTag
// @mechanism MaterialTag.sides
// @group properties
// @description
// Returns the list of heights for a wall block, or connections for a redstone wire, in order North|East|South|West|Vertical.
// For wall blocks: For n/e/s/w, can be "tall", "low", or "none". For vertical, can be "tall" or "none".
// For redstone wires: For n/e/s/w, can be "none", "side", or "up". No vertical.
// -->
PropertyParser.registerStaticTag(MaterialSides.class, ListTag.class, "sides", (attribute, material) -> {
return material.getSidesList();
}, "heights");
}

public boolean isWall() {
Expand Down Expand Up @@ -109,66 +125,4 @@ else if (isWire()) {
}
return list;
}

@Override
public String getPropertyString() {
return getSidesList().identify();
}

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

@Override
public void adjust(Mechanism mechanism) {

// <--[mechanism]
// @object MaterialTag
// @name heights
// @input ElementTag
// @deprecated Use 'sides'
// @description
// Deprecated in favor of <@link mechanism MaterialTag.sides>
// @tags
// <MaterialTag.heights>
// -->
// <--[mechanism]
// @object MaterialTag
// @name sides
// @input ElementTag
// @description
// Sets the list of heights for a wall block, or connections for a redstone wire, in order North|East|South|West|Vertical.
// For wall blocks: For n/e/s/w, can be "tall", "low", or "none". For vertical, can be "tall" or "none".
// For redstone wires: For n/e/s/w, can be "none", "side", or "up". No vertical.
// @tags
// <MaterialTag.sides>
// -->
if ((mechanism.matches("sides") || mechanism.matches("heights")) && mechanism.requireObject(ListTag.class)) {
ListTag list = mechanism.valueAsType(ListTag.class);
if (isWall()) {
if (list.size() != 5) {
mechanism.echoError("Invalid sides list, size must be 5.");
return;
}
Wall wall = getWall();
wall.setHeight(BlockFace.NORTH, Wall.Height.valueOf(list.get(0).toUpperCase()));
wall.setHeight(BlockFace.EAST, Wall.Height.valueOf(list.get(1).toUpperCase()));
wall.setHeight(BlockFace.SOUTH, Wall.Height.valueOf(list.get(2).toUpperCase()));
wall.setHeight(BlockFace.WEST, Wall.Height.valueOf(list.get(3).toUpperCase()));
wall.setUp(CoreUtilities.toLowerCase(list.get(4)).equals("tall"));
}
else if (isWire()) {
if (list.size() != 4) {
mechanism.echoError("Invalid sides list, size must be 4.");
return;
}
RedstoneWire wire = getWire();
wire.setFace(BlockFace.NORTH, RedstoneWire.Connection.valueOf(list.get(0).toUpperCase()));
wire.setFace(BlockFace.EAST, RedstoneWire.Connection.valueOf(list.get(1).toUpperCase()));
wire.setFace(BlockFace.SOUTH, RedstoneWire.Connection.valueOf(list.get(2).toUpperCase()));
wire.setFace(BlockFace.WEST, RedstoneWire.Connection.valueOf(list.get(3).toUpperCase()));
}
}
}
}
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.Snowable;

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

public static boolean describes(ObjectTag material) {
return material instanceof MaterialTag
&& ((MaterialTag) material).hasModernData()
&& ((MaterialTag) material).getModernData() instanceof Snowable;
}
// <--[tag]
// @object MaterialTag
// @name snowy
// @input ElementTag(Boolean)
// @description
// Controls whether this material is covered in snow.
// -->

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

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

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

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

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

// <--[tag]
// @attribute <MaterialTag.snowy>
// @returns ElementTag(Boolean)
// @mechanism MaterialTag.snowy
// @group properties
// @description
// Returns whether this material is covered in snow or not.
// -->
PropertyParser.registerStaticTag(MaterialSnowable.class, ElementTag.class, "snowy", (attribute, material) -> {
return new ElementTag(material.isSnowy());
});
public static void register() {
autoRegister("snowy", MaterialSnowable.class, ElementTag.class, true);
}

public Snowable getSnowable() {
Expand All @@ -57,31 +51,4 @@ public Snowable getSnowable() {
public boolean isSnowy() {
return getSnowable().isSnowy();
}

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

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

@Override
public void adjust(Mechanism mechanism) {

// <--[mechanism]
// @object MaterialTag
// @name snowy
// @input ElementTag(Boolean)
// @description
// Sets this material to be covered in snow, or not.
// @tags
// <MaterialTag.snowy>
// -->
if (mechanism.matches("snowy") && mechanism.requireBoolean()) {
getSnowable().setSnowy(mechanism.getValue().asBoolean());
}
}
}
Loading