-
-
Notifications
You must be signed in to change notification settings - Fork 115
Added MossyCarpet to MaterialSides #2808
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
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,174 +1,125 @@ | ||
| package com.denizenscript.denizen.objects.properties.material; | ||
|
|
||
| import com.denizenscript.denizen.nms.NMSHandler; | ||
| import com.denizenscript.denizen.nms.NMSVersion; | ||
| 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.MossyCarpet; | ||
| import org.bukkit.block.data.type.RedstoneWire; | ||
| import org.bukkit.block.data.type.Wall; | ||
|
|
||
| public class MaterialSides implements Property { | ||
|
|
||
| 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; | ||
| } | ||
|
|
||
| public static MaterialSides getFrom(ObjectTag _material) { | ||
| if (!describes(_material)) { | ||
| return null; | ||
| } | ||
| else { | ||
| return new MaterialSides((MaterialTag) _material); | ||
| } | ||
| public class MaterialSides extends MaterialProperty<ListTag> { | ||
|
|
||
| // <--[property] | ||
| // @object MaterialTag | ||
| // @name sides | ||
| // @input ListTag | ||
| // @description | ||
| // Controls the heights for a wall block or mossy carpet, 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. | ||
| // For mossy carpets: For n/e/s/w, can be "tall", "low", or "none". Vertical controls the bottom, and can either be "true" or "false". | ||
| // --> | ||
|
|
||
| public static boolean describes(MaterialTag material) { | ||
| BlockData data = material.getModernData(); | ||
| return (data instanceof Wall | ||
| || data instanceof RedstoneWire | ||
| || (NMSHandler.getVersion().isAtLeast(NMSVersion.v1_21) && data instanceof MossyCarpet)); | ||
| } | ||
|
|
||
| public static final String[] handledMechs = new String[] { | ||
| "sides", "heights" | ||
| }; | ||
|
|
||
| public MaterialSides(MaterialTag _material) { | ||
| material = _material; | ||
| } | ||
|
|
||
| MaterialTag material; | ||
|
|
||
| public static void register() { | ||
|
|
||
| // <--[tag] | ||
| // @attribute <MaterialTag.heights> | ||
| // @returns ListTag | ||
| // @mechanism MaterialTag.heights | ||
| // @group properties | ||
| // @deprecated Use 'sides' | ||
| // @description | ||
| // Deprecated in favor of <@link tag 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() { | ||
| return material.getModernData() instanceof Wall; | ||
| } | ||
|
|
||
| public Wall getWall() { | ||
| return (Wall) material.getModernData(); | ||
| } | ||
|
|
||
| public boolean isWire() { | ||
| return material.getModernData() instanceof RedstoneWire; | ||
| } | ||
|
|
||
| public RedstoneWire getWire() { | ||
| return (RedstoneWire) material.getModernData(); | ||
| } | ||
|
|
||
| public ListTag getSidesList() { | ||
| @Override | ||
| public ListTag getPropertyValue() { | ||
| ListTag list = new ListTag(5); | ||
| if (isWall()) { | ||
| Wall wall = getWall(); | ||
| if (getBlockData() instanceof Wall wall) { | ||
| list.add(wall.getHeight(BlockFace.NORTH).name()); | ||
| list.add(wall.getHeight(BlockFace.EAST).name()); | ||
| list.add(wall.getHeight(BlockFace.SOUTH).name()); | ||
| list.add(wall.getHeight(BlockFace.WEST).name()); | ||
| list.add(wall.isUp() ? "TALL" : "NONE"); | ||
| } | ||
| else if (isWire()) { | ||
| RedstoneWire wire = getWire(); | ||
| else if (getBlockData() instanceof RedstoneWire wire) { | ||
| list.add(wire.getFace(BlockFace.NORTH).name()); | ||
| list.add(wire.getFace(BlockFace.EAST).name()); | ||
| list.add(wire.getFace(BlockFace.SOUTH).name()); | ||
| list.add(wire.getFace(BlockFace.WEST).name()); | ||
| } | ||
| else if (NMSHandler.getVersion().isAtLeast(NMSVersion.v1_21) && getBlockData() instanceof MossyCarpet carpet) { | ||
| list.add(carpet.getHeight(BlockFace.NORTH).name()); | ||
| list.add(carpet.getHeight(BlockFace.EAST).name()); | ||
| list.add(carpet.getHeight(BlockFace.SOUTH).name()); | ||
| list.add(carpet.getHeight(BlockFace.WEST).name()); | ||
| list.add(carpet.isBottom() ? "TRUE" : "FALSE"); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is |
||
| } | ||
| return list; | ||
| } | ||
|
|
||
| @Override | ||
| public String getPropertyString() { | ||
| return getSidesList().identify(); | ||
| public void setPropertyValue(ListTag list, Mechanism mechanism) { | ||
| if (getBlockData() instanceof Wall wall) { | ||
| if (list.size() != 5) { | ||
| mechanism.echoError("Invalid sides list, size must be 5."); | ||
| return; | ||
| } | ||
| wall.setHeight(BlockFace.NORTH, Wall.Height.valueOf(list.get(0).toUpperCase())); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Would be nice to update this as well, even just |
||
| 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(list.get(4).equalsIgnoreCase("tall")); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nitpick, but these can be |
||
| } | ||
| else if (getBlockData() instanceof RedstoneWire wire) { | ||
| if (list.size() != 4) { | ||
| mechanism.echoError("Invalid sides list, size must be 4."); | ||
| return; | ||
| } | ||
| 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())); | ||
| } | ||
| else if (NMSHandler.getVersion().isAtLeast(NMSVersion.v1_21) && getBlockData() instanceof MossyCarpet carpet) { | ||
| if (list.size() != 5) { | ||
| mechanism.echoError("Invalid sides list, size must be 5."); | ||
| return; | ||
| } | ||
| carpet.setHeight(BlockFace.NORTH, MossyCarpet.Height.valueOf(list.get(0).toUpperCase())); | ||
| carpet.setHeight(BlockFace.EAST, MossyCarpet.Height.valueOf(list.get(1).toUpperCase())); | ||
| carpet.setHeight(BlockFace.SOUTH, MossyCarpet.Height.valueOf(list.get(2).toUpperCase())); | ||
| carpet.setHeight(BlockFace.WEST, MossyCarpet.Height.valueOf(list.get(3).toUpperCase())); | ||
| carpet.setBottom(list.get(4).equalsIgnoreCase("true")); | ||
| } | ||
| } | ||
|
|
||
| @Override | ||
| public String getPropertyId() { | ||
| return "sides"; | ||
| } | ||
|
|
||
| @Override | ||
| public void adjust(Mechanism mechanism) { | ||
| // <--[tag] | ||
| // @attribute <MaterialTag.heights> | ||
| // @returns ListTag | ||
| // @mechanism MaterialTag.heights | ||
| // @group properties | ||
| // @deprecated Use 'sides' | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Start lowercase on these |
||
| // @description | ||
| // Deprecated in favor of <@link property MaterialTag.sides> | ||
| // --> | ||
|
|
||
| // <--[mechanism] | ||
| // @object MaterialTag | ||
| // @name heights | ||
| // @input ElementTag | ||
| // @deprecated Use 'sides' | ||
| // @description | ||
| // Deprecated in favor of <@link property MaterialTag.sides> | ||
| // @tags | ||
| // <MaterialTag.heights> | ||
| // --> | ||
|
|
||
| // <--[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())); | ||
| } | ||
| } | ||
| public static void register() { | ||
| autoRegister("sides", MaterialSides.class, ListTag.class, false, "heights"); | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is the bracket wrapping all of this not redundant?