SPIGOT-1389: Fixed issues with setting tree species by expanding API

By: ryanbennitt <ryanbennitt@googlemail.com>
This commit is contained in:
Bukkit/Spigot
2016-03-01 08:30:03 +11:00
parent 96968d5bb4
commit f2fcb9f8bd
7 changed files with 697 additions and 94 deletions

View File

@@ -5,11 +5,39 @@ import org.bukkit.TreeSpecies;
/**
* Represents the different types of wooden steps.
*
* @see Material.WOOD_STEP
*/
public class WoodenStep extends MaterialData {
public class WoodenStep extends Wood {
protected static final Material DEFAULT_TYPE = Material.WOOD_STEP;
protected static final boolean DEFAULT_INVERTED = false;
/**
* Constructs a wooden step.
*/
public WoodenStep() {
super(Material.WOOD_STEP);
this(DEFAULT_SPECIES, DEFAULT_INVERTED);
}
/**
* Constructs a wooden step of the given tree species.
*
* @param species the species of the wooden step
*/
public WoodenStep(TreeSpecies species) {
this(species, DEFAULT_INVERTED);
}
/**
* Constructs a wooden step of the given type and tree species, either
* inverted or not.
*
* @param species the species of the wooden step
* @param inv true the step is at the top of the block
*/
public WoodenStep(final TreeSpecies species, boolean inv) {
super(DEFAULT_TYPE, species);
setInverted(inv);
}
/**
@@ -21,17 +49,6 @@ public class WoodenStep extends MaterialData {
super(type);
}
public WoodenStep(TreeSpecies species) {
this();
setSpecies(species);
}
public WoodenStep(TreeSpecies species, boolean inv) {
this();
setSpecies(species);
setInverted(inv);
}
/**
* @param type the raw type id
* @param data the raw data value
@@ -52,39 +69,23 @@ public class WoodenStep extends MaterialData {
super(type, data);
}
/**
* Gets the current species of this tree
*
* @return TreeSpecies of this tree
*/
public TreeSpecies getSpecies() {
return TreeSpecies.getByData((byte) (getData() & 0x3));
}
/**
* Sets the species of this tree
*
* @param species New species of this tree
*/
public void setSpecies(TreeSpecies species) {
setData((byte) ((getData() & 0xC) | species.getData()));
}
/**
* Test if step is inverted
*
* @return true if inverted (top half), false if normal (bottom half)
*/
@SuppressWarnings("deprecation")
public boolean isInverted() {
return ((getData() & 0x8) != 0);
}
/**
* Set step inverted state
*
* @param inv - true if step is inverted (top half), false if step is
* normal (bottom half)
* @param inv - true if step is inverted (top half), false if step is normal
* (bottom half)
*/
@SuppressWarnings("deprecation")
public void setInverted(boolean inv) {
int dat = getData() & 0x7;
if (inv) {
@@ -92,7 +93,7 @@ public class WoodenStep extends MaterialData {
}
setData((byte) dat);
}
@Override
public WoodenStep clone() {
return (WoodenStep) super.clone();
@@ -100,6 +101,6 @@ public class WoodenStep extends MaterialData {
@Override
public String toString() {
return super.toString() + " " + getSpecies() + (isInverted()?" inverted":"");
return super.toString() + " " + getSpecies() + (isInverted() ? " inverted" : "");
}
}