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,22 +5,40 @@ import org.bukkit.TreeSpecies;
import org.bukkit.block.BlockFace;
/**
* Represents the different types of Trees.
* Represents the different types of Tree block that face a direction.
*
* @see Material.LOG
* @see Material.LOG_2
*/
public class Tree extends MaterialData {
public class Tree extends Wood {
protected static final Material DEFAULT_TYPE = Material.LOG;
protected static final BlockFace DEFAULT_DIRECTION = BlockFace.UP;
/**
* Constructs a tree block.
*/
public Tree() {
super(Material.LOG);
this(DEFAULT_TYPE, DEFAULT_SPECIES, DEFAULT_DIRECTION);
}
/**
* Constructs a tree block of the given tree species.
*
* @param species the species of the tree block
*/
public Tree(TreeSpecies species) {
this();
setSpecies(species);
this(DEFAULT_TYPE, species, DEFAULT_DIRECTION);
}
/**
* Constructs a tree block of the given tree species, and facing the given
* direction.
*
* @param species the species of the tree block
* @param dir the direction the tree block is facing
*/
public Tree(TreeSpecies species, BlockFace dir) {
this();
setSpecies(species);
setDirection(dir);
this(DEFAULT_TYPE, species, dir);
}
/**
@@ -32,8 +50,36 @@ public class Tree extends MaterialData {
super(type);
}
/**
* Constructs a tree block of the given type.
*
* @param type the type of tree block
*/
public Tree(final Material type) {
super(type);
this(type, DEFAULT_SPECIES, DEFAULT_DIRECTION);
}
/**
* Constructs a tree block of the given type and tree species.
*
* @param type the type of tree block
* @param species the species of the tree block
*/
public Tree(final Material type, TreeSpecies species) {
this(type, species, DEFAULT_DIRECTION);
}
/**
* Constructs a tree block of the given type and tree species, and facing
* the given direction.
*
* @param type the type of tree block
* @param species the species of the tree block
* @param dir the direction the tree block is facing
*/
public Tree(final Material type, TreeSpecies species, BlockFace dir) {
super(type, species);
setDirection(dir);
}
/**
@@ -56,35 +102,18 @@ public class Tree 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()));
}
/**
* Get direction of the log
*
* @return one of:
* <ul>
* <li>BlockFace.TOP for upright (default)
* <li>BlockFace.NORTH (east-west)
* <li>BlockFace.WEST (north-south)
* <li>BlockFace.SELF (directionless)
* </ul>
* <ul>
* <li>BlockFace.TOP for upright (default)
* <li>BlockFace.NORTH (east-west)
* <li>BlockFace.WEST (north-south)
* <li>BlockFace.SELF (directionless)
* </ul>
*/
@SuppressWarnings("deprecation")
public BlockFace getDirection() {
switch ((getData() >> 2) & 0x3) {
case 0: // Up-down
@@ -98,11 +127,13 @@ public class Tree extends MaterialData {
return BlockFace.SELF;
}
}
/**
* Set direction of the log
*
* @param dir - direction of end of log (BlockFace.SELF for no direction)
*/
@SuppressWarnings("deprecation")
public void setDirection(BlockFace dir) {
int dat;
switch (dir) {
@@ -113,17 +144,17 @@ public class Tree extends MaterialData {
break;
case WEST:
case EAST:
dat = 1;
dat = 4; // 1<<2
break;
case NORTH:
case SOUTH:
dat = 2;
dat = 8; // 2<<2
break;
case SELF:
dat = 3;
dat = 12; // 3<<2
break;
}
setData((byte) ((getData() & 0x3) | (dat << 2)));
setData((byte) ((getData() & 0x3) | dat));
}
@Override