From 615b1a9f3fcb7156438f8dac4dd9bd7eec8886be Mon Sep 17 00:00:00 2001 From: Bukkit/Spigot Date: Thu, 16 Jun 2011 15:45:50 -0700 Subject: [PATCH] Added setters to applicable MaterialData classes. By: sunkid --- .../main/java/org/bukkit/material/Bed.java | 10 ++- .../main/java/org/bukkit/material/Coal.java | 1 - .../main/java/org/bukkit/material/Crops.java | 1 - .../org/bukkit/material/DetectorRail.java | 4 ++ .../java/org/bukkit/material/Dispenser.java | 2 - .../main/java/org/bukkit/material/Door.java | 63 ++++++++++++++++++- .../org/bukkit/material/ExtendedRails.java | 13 ++++ .../java/org/bukkit/material/Furnace.java | 2 - .../bukkit/material/FurnaceAndDispenser.java | 1 - .../main/java/org/bukkit/material/Leaves.java | 1 - .../main/java/org/bukkit/material/Lever.java | 8 +++ .../java/org/bukkit/material/Pumpkin.java | 2 - .../main/java/org/bukkit/material/Rails.java | 45 +++++++++++++ .../SimpleAttachableMaterialData.java | 2 - .../main/java/org/bukkit/material/Stairs.java | 2 - .../main/java/org/bukkit/material/Step.java | 1 - .../main/java/org/bukkit/material/Tree.java | 1 - 17 files changed, 139 insertions(+), 20 deletions(-) diff --git a/paper-api/src/main/java/org/bukkit/material/Bed.java b/paper-api/src/main/java/org/bukkit/material/Bed.java index 48ff8ed7e9..fd81685ee2 100644 --- a/paper-api/src/main/java/org/bukkit/material/Bed.java +++ b/paper-api/src/main/java/org/bukkit/material/Bed.java @@ -5,8 +5,6 @@ import org.bukkit.block.BlockFace; /** * Represents a bed. - * - * @author sunkid */ public class Bed extends MaterialData implements Directional { @@ -51,6 +49,14 @@ public class Bed extends MaterialData implements Directional { return (getData() & 0x8) == 0x8; } + /** + * Configure this to be either the head or the foot of the bed + * @param isHeadOfBed + */ + public void setHeadOfBed(boolean isHeadOfBed) { + setData((byte) (isHeadOfBed ? (getData() | 0x8) : (getData() & ~0x8))); + } + /** * Set which direction the head of the bed is facing. Note that this will * only affect one of the two blocks the bed is made of. diff --git a/paper-api/src/main/java/org/bukkit/material/Coal.java b/paper-api/src/main/java/org/bukkit/material/Coal.java index 5c5f1fc229..43dfd93bc7 100644 --- a/paper-api/src/main/java/org/bukkit/material/Coal.java +++ b/paper-api/src/main/java/org/bukkit/material/Coal.java @@ -5,7 +5,6 @@ import org.bukkit.Material; /** * Represents the different types of coals. - * @author sunkid */ public class Coal extends MaterialData { public Coal() { diff --git a/paper-api/src/main/java/org/bukkit/material/Crops.java b/paper-api/src/main/java/org/bukkit/material/Crops.java index 4ff9c2c111..c477dcec52 100644 --- a/paper-api/src/main/java/org/bukkit/material/Crops.java +++ b/paper-api/src/main/java/org/bukkit/material/Crops.java @@ -5,7 +5,6 @@ import org.bukkit.Material; /** * Represents the different types of crops. - * @author sunkid */ public class Crops extends MaterialData { public Crops() { diff --git a/paper-api/src/main/java/org/bukkit/material/DetectorRail.java b/paper-api/src/main/java/org/bukkit/material/DetectorRail.java index 83bc768a1f..a32317c77b 100644 --- a/paper-api/src/main/java/org/bukkit/material/DetectorRail.java +++ b/paper-api/src/main/java/org/bukkit/material/DetectorRail.java @@ -29,4 +29,8 @@ public class DetectorRail extends ExtendedRails implements PressureSensor { public boolean isPressed() { return (getData() & 0x8) == 0x8; } + + public void setPressed(boolean isPressed) { + setData((byte) (isPressed ? (getData() | 0x8) : (getData() & ~0x8))); + } } diff --git a/paper-api/src/main/java/org/bukkit/material/Dispenser.java b/paper-api/src/main/java/org/bukkit/material/Dispenser.java index 790e71d6b5..9931450ff4 100644 --- a/paper-api/src/main/java/org/bukkit/material/Dispenser.java +++ b/paper-api/src/main/java/org/bukkit/material/Dispenser.java @@ -5,8 +5,6 @@ import org.bukkit.block.BlockFace; /** * Represents a dispenser. - * - * @author sunkid */ public class Dispenser extends FurnaceAndDispenser { diff --git a/paper-api/src/main/java/org/bukkit/material/Door.java b/paper-api/src/main/java/org/bukkit/material/Door.java index 92aa041264..40ee1e3a15 100644 --- a/paper-api/src/main/java/org/bukkit/material/Door.java +++ b/paper-api/src/main/java/org/bukkit/material/Door.java @@ -5,9 +5,8 @@ import org.bukkit.block.BlockFace; /** * Represents a door. - * @author sunkid */ -public class Door extends MaterialData { +public class Door extends MaterialData implements Directional { public Door() { super(Material.WOODEN_DOOR); } @@ -36,6 +35,14 @@ public class Door extends MaterialData { return ((getData() & 0x4) == 0x4); } + /** + * Configure this door to be either open or closed; + * @param isOpen + */ + public void setOpen(boolean isOpen) { + setData((byte) (isOpen ? (getData() | 0x4) : (getData() & ~0x4))); + } + /** * @return whether this is the top half of the door */ @@ -43,6 +50,14 @@ public class Door extends MaterialData { return ((getData() & 0x8) == 0x8); } + /** + * Configure this part of the door to be either the top or the bottom half; + * @param isTopHalf + */ + public void setTopHalf(boolean isTopHalf) { + setData((byte) (isTopHalf ? (getData() | 0x8) : (getData() & ~0x8))); + } + /** * @return the location of the hinges */ @@ -64,4 +79,48 @@ public class Door extends MaterialData { public String toString() { return (isTopHalf() ? "TOP" : "BOTTOM") + " half of " + (isOpen() ? "an OPEN " : "a CLOSED ") + super.toString() + " with hinges " + getHingeCorner(); } + + /** + * Set the direction that this door should is facing. + * @param face the direction + */ + public void setFacingDirection(BlockFace face) { + byte data = (byte) (getData() & 0x12); + switch (face) { + case EAST: + data |= 0x1; + break; + + case SOUTH: + data |= 0x2; + break; + + case WEST: + data |= 0x3; + break; + } + setData(data); + } + + /** + * Get the direction that this door is facing. + * @return the direction + */ + public BlockFace getFacing() { + byte data = (byte) (getData() & 0x3); + switch (data) { + case 0: + return BlockFace.NORTH; + + case 1: + return BlockFace.EAST; + + case 2: + return BlockFace.SOUTH; + + case 3: + return BlockFace.WEST; + } + return null; // shouldn't happen + } } diff --git a/paper-api/src/main/java/org/bukkit/material/ExtendedRails.java b/paper-api/src/main/java/org/bukkit/material/ExtendedRails.java index 3cabf06f0b..a86a44ffe9 100644 --- a/paper-api/src/main/java/org/bukkit/material/ExtendedRails.java +++ b/paper-api/src/main/java/org/bukkit/material/ExtendedRails.java @@ -1,6 +1,7 @@ package org.bukkit.material; import org.bukkit.Material; +import org.bukkit.block.BlockFace; /** * This is the superclass for the {@link DetectorRail} and {@link PoweredRail} classes @@ -31,4 +32,16 @@ public class ExtendedRails extends Rails { protected byte getConvertedData() { return (byte) (getData() & 0x7); } + + @Override + public void setDirection(BlockFace face, boolean isOnSlope) { + boolean extraBitSet = (getData() & 0x8) == 0x8; + + if (face != BlockFace.NORTH && face != BlockFace.SOUTH && face != BlockFace.EAST && face != BlockFace.WEST) { + throw new IllegalArgumentException("Detector rails and powered rails cannot be set on a curve!"); + } + + super.setDirection(face, isOnSlope); + setData((byte) (extraBitSet ? (getData() | 0x8) : (getData() & ~0x8))); + } } diff --git a/paper-api/src/main/java/org/bukkit/material/Furnace.java b/paper-api/src/main/java/org/bukkit/material/Furnace.java index 4fad7c55f8..b80fe53aac 100644 --- a/paper-api/src/main/java/org/bukkit/material/Furnace.java +++ b/paper-api/src/main/java/org/bukkit/material/Furnace.java @@ -5,8 +5,6 @@ import org.bukkit.block.BlockFace; /** * Represents a furnace. - * - * @author sunkid */ public class Furnace extends FurnaceAndDispenser { diff --git a/paper-api/src/main/java/org/bukkit/material/FurnaceAndDispenser.java b/paper-api/src/main/java/org/bukkit/material/FurnaceAndDispenser.java index 08d7e4c77d..9505fb70fa 100644 --- a/paper-api/src/main/java/org/bukkit/material/FurnaceAndDispenser.java +++ b/paper-api/src/main/java/org/bukkit/material/FurnaceAndDispenser.java @@ -5,7 +5,6 @@ import org.bukkit.block.BlockFace; /** * Represents a furnace or a dispenser. - * @author sunkid */ public class FurnaceAndDispenser extends MaterialData implements Directional { public FurnaceAndDispenser(final int type) { diff --git a/paper-api/src/main/java/org/bukkit/material/Leaves.java b/paper-api/src/main/java/org/bukkit/material/Leaves.java index e57b6847ff..8b8e0d7005 100644 --- a/paper-api/src/main/java/org/bukkit/material/Leaves.java +++ b/paper-api/src/main/java/org/bukkit/material/Leaves.java @@ -5,7 +5,6 @@ import org.bukkit.TreeSpecies; /** * Represents the different types of leaves. - * @author sunkid */ public class Leaves extends MaterialData { public Leaves() { diff --git a/paper-api/src/main/java/org/bukkit/material/Lever.java b/paper-api/src/main/java/org/bukkit/material/Lever.java index a543c27d82..6101fa4ef3 100644 --- a/paper-api/src/main/java/org/bukkit/material/Lever.java +++ b/paper-api/src/main/java/org/bukkit/material/Lever.java @@ -37,6 +37,14 @@ public class Lever extends SimpleAttachableMaterialData implements Redstone { return (getData() & 0x8) == 0x8; } + /** + * Set this lever to be powered or not. + * @param isPowered whether the lever should be powered or not + */ + public void setPowered(boolean isPowered) { + setData((byte) (isPowered ? (getData() | 0x8) : (getData() & ~0x8))); + } + /** * Gets the face that this block is attached on * diff --git a/paper-api/src/main/java/org/bukkit/material/Pumpkin.java b/paper-api/src/main/java/org/bukkit/material/Pumpkin.java index b5993863f7..4e08becfce 100644 --- a/paper-api/src/main/java/org/bukkit/material/Pumpkin.java +++ b/paper-api/src/main/java/org/bukkit/material/Pumpkin.java @@ -5,8 +5,6 @@ import org.bukkit.block.BlockFace; /** * Represents a pumpkin. - * - * @author sunkid */ public class Pumpkin extends MaterialData implements Directional { 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 db2953280f..3d6a959ee2 100644 --- a/paper-api/src/main/java/org/bukkit/material/Rails.java +++ b/paper-api/src/main/java/org/bukkit/material/Rails.java @@ -102,4 +102,49 @@ public class Rails extends MaterialData { protected byte getConvertedData() { return getData(); } + + /** + * Set the direction of these tracks
+ * Note that tracks are bidirectional and that the direction + * returned is the ascending direction if the track is set on a + * slope. If it is set as a curve, the corner of the track should + * be supplied. + * @param face the direction the track should be facing + * @param isOnSlope whether or not the track should be on a slope + */ + public void setDirection(BlockFace face, boolean isOnSlope) { + switch (face) { + case SOUTH: + setData((byte) (isOnSlope ? 0x2 : 0x1)); + break; + + case NORTH: + setData((byte) (isOnSlope ? 0x3 : 0x1)); + break; + + case EAST: + setData((byte) (isOnSlope ? 0x4 : 0x0)); + break; + + case WEST: + setData((byte) (isOnSlope ? 0x5 : 0x0)); + break; + + case NORTH_EAST: + setData((byte) 0x6); + break; + + case SOUTH_EAST: + setData((byte) 0x7); + break; + + case SOUTH_WEST: + setData((byte) 0x8); + break; + + case NORTH_WEST: + setData((byte) 0x9); + break; + } + } } diff --git a/paper-api/src/main/java/org/bukkit/material/SimpleAttachableMaterialData.java b/paper-api/src/main/java/org/bukkit/material/SimpleAttachableMaterialData.java index 265816bd2a..ec5778f040 100644 --- a/paper-api/src/main/java/org/bukkit/material/SimpleAttachableMaterialData.java +++ b/paper-api/src/main/java/org/bukkit/material/SimpleAttachableMaterialData.java @@ -5,8 +5,6 @@ import org.bukkit.block.BlockFace; /** * Simple utility class for attachable MaterialData subclasses - * @author sunkid - * */ public abstract class SimpleAttachableMaterialData extends MaterialData implements Attachable { diff --git a/paper-api/src/main/java/org/bukkit/material/Stairs.java b/paper-api/src/main/java/org/bukkit/material/Stairs.java index d1c7b9676e..f7e249cfc9 100644 --- a/paper-api/src/main/java/org/bukkit/material/Stairs.java +++ b/paper-api/src/main/java/org/bukkit/material/Stairs.java @@ -5,8 +5,6 @@ import org.bukkit.block.BlockFace; /** * Represents stairs. - * - * @author sunkid */ public class Stairs extends MaterialData implements Directional { diff --git a/paper-api/src/main/java/org/bukkit/material/Step.java b/paper-api/src/main/java/org/bukkit/material/Step.java index c57f0c3f7e..ddcb70b371 100644 --- a/paper-api/src/main/java/org/bukkit/material/Step.java +++ b/paper-api/src/main/java/org/bukkit/material/Step.java @@ -6,7 +6,6 @@ import org.bukkit.Material; /** * Represents the different types of steps. - * @author sunkid */ public class Step extends MaterialData { private static HashSet stepTypes = new HashSet(); diff --git a/paper-api/src/main/java/org/bukkit/material/Tree.java b/paper-api/src/main/java/org/bukkit/material/Tree.java index 22ac386f5f..1d4f0b551d 100644 --- a/paper-api/src/main/java/org/bukkit/material/Tree.java +++ b/paper-api/src/main/java/org/bukkit/material/Tree.java @@ -5,7 +5,6 @@ import org.bukkit.TreeSpecies; /** * Represents the different types of Trees. - * @author sunkid */ public class Tree extends MaterialData { public Tree() {