diff --git a/paper-api/src/main/java/org/bukkit/Material.java b/paper-api/src/main/java/org/bukkit/Material.java index 9e5d640dad..a3d0d298de 100644 --- a/paper-api/src/main/java/org/bukkit/Material.java +++ b/paper-api/src/main/java/org/bukkit/Material.java @@ -18,7 +18,7 @@ public enum Material { DIRT(3), COBBLESTONE(4), WOOD(5), - SAPLING(6, MaterialData.class), + SAPLING(6, Tree.class), BEDROCK(7), WATER(8, MaterialData.class), STATIONARY_WATER(9, MaterialData.class), @@ -39,8 +39,8 @@ public enum Material { SANDSTONE(24), NOTE_BLOCK(25), BED_BLOCK(26, Bed.class), - POWERED_RAIL(27), - DETECTOR_RAIL(28), + POWERED_RAIL(27, PoweredRail.class), + DETECTOR_RAIL(28, DetectorRail.class), WEB(30), WOOL(35, Wool.class), YELLOW_FLOWER(37), diff --git a/paper-api/src/main/java/org/bukkit/material/DetectorRail.java b/paper-api/src/main/java/org/bukkit/material/DetectorRail.java new file mode 100644 index 0000000000..83bc768a1f --- /dev/null +++ b/paper-api/src/main/java/org/bukkit/material/DetectorRail.java @@ -0,0 +1,32 @@ +package org.bukkit.material; + +import org.bukkit.Material; + +/** + * Represents a detector rail + */ +public class DetectorRail extends ExtendedRails implements PressureSensor { + public DetectorRail() { + super(Material.DETECTOR_RAIL); + } + + public DetectorRail(final int type) { + super(type); + } + + public DetectorRail(final Material type) { + super(type); + } + + public DetectorRail(final int type, final byte data) { + super(type, data); + } + + public DetectorRail(final Material type, final byte data) { + super(type, data); + } + + public boolean isPressed() { + return (getData() & 0x8) == 0x8; + } +} diff --git a/paper-api/src/main/java/org/bukkit/material/ExtendedRails.java b/paper-api/src/main/java/org/bukkit/material/ExtendedRails.java new file mode 100644 index 0000000000..3cabf06f0b --- /dev/null +++ b/paper-api/src/main/java/org/bukkit/material/ExtendedRails.java @@ -0,0 +1,34 @@ +package org.bukkit.material; + +import org.bukkit.Material; + +/** + * This is the superclass for the {@link DetectorRail} and {@link PoweredRail} classes + */ +public class ExtendedRails extends Rails { + public ExtendedRails(final int type) { + super(type); + } + + public ExtendedRails(final Material type) { + super(type); + } + + public ExtendedRails(final int type, final byte data) { + super(type, data); + } + + public ExtendedRails(final Material type, final byte data) { + super(type, data); + } + + @Override + public boolean isCurve() { + return false; + } + + @Override + protected byte getConvertedData() { + return (byte) (getData() & 0x7); + } +} diff --git a/paper-api/src/main/java/org/bukkit/material/PoweredRail.java b/paper-api/src/main/java/org/bukkit/material/PoweredRail.java new file mode 100644 index 0000000000..27c19c890d --- /dev/null +++ b/paper-api/src/main/java/org/bukkit/material/PoweredRail.java @@ -0,0 +1,40 @@ +package org.bukkit.material; + +import org.bukkit.Material; + +/** + * Represents a powered rail + */ +public class PoweredRail extends ExtendedRails implements Redstone { + public PoweredRail() { + super(Material.POWERED_RAIL); + } + + public PoweredRail(final int type) { + super(type); + } + + public PoweredRail(final Material type) { + super(type); + } + + public PoweredRail(final int type, final byte data) { + super(type, data); + } + + public PoweredRail(final Material type, final byte data) { + super(type, data); + } + + public boolean isPowered() { + return (getData() & 0x8) == 0x8; + } + + /** + * Set whether this PoweredRail should be powered or not. + * @param isPowered whether or not the rail is powered + */ + public void setPowered(boolean isPowered) { + setData((byte) (isPowered ? (getData() | 0x8) : (getData() & ~0x8))); + } +} diff --git a/paper-api/src/main/java/org/bukkit/material/PressurePlate.java b/paper-api/src/main/java/org/bukkit/material/PressurePlate.java index bdcf0aa67b..c0ec55fabc 100644 --- a/paper-api/src/main/java/org/bukkit/material/PressurePlate.java +++ b/paper-api/src/main/java/org/bukkit/material/PressurePlate.java @@ -4,14 +4,12 @@ import org.bukkit.Material; /** * Represents a pressure plate - * @author CelticMinstrel - * */ -public class PressurePlate extends MaterialData { +public class PressurePlate extends MaterialData implements PressureSensor { public PressurePlate() { super(Material.WOOD_PLATE); } - + public PressurePlate(int type) { super(type); } diff --git a/paper-api/src/main/java/org/bukkit/material/PressureSensor.java b/paper-api/src/main/java/org/bukkit/material/PressureSensor.java new file mode 100644 index 0000000000..de20bd39c5 --- /dev/null +++ b/paper-api/src/main/java/org/bukkit/material/PressureSensor.java @@ -0,0 +1,5 @@ +package org.bukkit.material; + +public interface PressureSensor { + public boolean isPressed(); +} diff --git a/paper-api/src/main/java/org/bukkit/material/Rails.java b/paper-api/src/main/java/org/bukkit/material/Rails.java index d58d8fc606..d5e975213c 100644 --- a/paper-api/src/main/java/org/bukkit/material/Rails.java +++ b/paper-api/src/main/java/org/bukkit/material/Rails.java @@ -5,15 +5,13 @@ import org.bukkit.block.BlockFace; /** * Represents minecart rails. - * - * @author sunkid */ public class Rails extends MaterialData { public Rails() { super(Material.RAILS); } - + public Rails(final int type) { super(type); } @@ -34,7 +32,7 @@ public class Rails extends MaterialData { * @return the whether this track is set on a slope */ public boolean isOnSlope() { - byte d = getData(); + byte d = getConvertedData(); return (d == 0x2 || d == 0x3 || d == 0x4 || d == 0x5); } @@ -42,7 +40,7 @@ public class Rails extends MaterialData { * @return the whether this track is set as a curve */ public boolean isCurve() { - byte d = getData(); + byte d = getConvertedData(); return (d == 0x6 || d == 0x7 || d == 0x8 || d == 0x9); } @@ -54,7 +52,7 @@ public class Rails extends MaterialData { * returned. */ public BlockFace getDirection() { - byte d = getData(); + byte d = getConvertedData(); switch (d) { case 0x0: default: @@ -79,9 +77,17 @@ public class Rails extends MaterialData { return BlockFace.NORTH_WEST; } } - + @Override public String toString() { return super.toString() + " facing " + getDirection() + (isCurve() ? " on a curve" : (isOnSlope() ? " on a slope" : "")); } + + /** + * Return the data without the extended properties used by {@link PoweredRail} and {@link DetectorRail}. Overridden in {@link ExtendedRails} + * @return the data without the extended part + */ + protected byte getConvertedData() { + return getData(); + } }