use of org.bukkit.material.MaterialData in project Glowstone by GlowstoneMC.
the class BlockButton method blockInteract.
@Override
public boolean blockInteract(GlowPlayer player, GlowBlock block, BlockFace face, Vector clickedLoc) {
GlowBlockState state = block.getState();
MaterialData data = state.getData();
if (!(data instanceof Button)) {
warnMaterialData(Button.class, data);
return false;
}
Button button = (Button) data;
if (button.isPowered()) {
return true;
}
button.setPowered(true);
state.update();
extraUpdate(block);
// todo: switch to block scheduling system when one is available
new BukkitRunnable() {
@Override
public void run() {
button.setPowered(false);
state.update();
if (block.getType() == Material.WOOD_BUTTON || block.getType() == Material.STONE_BUTTON) {
extraUpdate(block);
block.getWorld().playSound(block.getLocation(), block.getType() == Material.WOOD_BUTTON ? Sound.BLOCK_WOOD_BUTTON_CLICK_OFF : Sound.BLOCK_STONE_BUTTON_CLICK_OFF, 0.3f, 0.5f);
}
}
}.runTaskLater(null, block.getType() == Material.STONE_BUTTON ? 20 : 30);
return true;
}
use of org.bukkit.material.MaterialData in project Glowstone by GlowstoneMC.
the class BlockBanner method placeBlock.
@Override
public void placeBlock(GlowPlayer player, GlowBlockState state, BlockFace face, ItemStack holding, Vector clickedLoc) {
super.placeBlock(player, state, face, holding, clickedLoc);
MaterialData data = state.getData();
if (!(data instanceof Banner)) {
warnMaterialData(Banner.class, data);
return;
}
Banner banner = (Banner) data;
if (banner.isWallBanner()) {
banner.setFacingDirection(face);
} else {
banner.setFacingDirection(player.getFacing().getOppositeFace());
}
}
use of org.bukkit.material.MaterialData in project Glowstone by GlowstoneMC.
the class BlockBed method getHead.
/**
* Returns the head of a bed given one of its blocks.
*
* @param block part of the bed
* @return The head of the bed
*/
public static GlowBlock getHead(GlowBlock block) {
MaterialData data = block.getState().getData();
if (!(data instanceof Bed)) {
return null;
}
Bed bed = (Bed) data;
if (bed.isHeadOfBed()) {
return block;
} else {
return block.getRelative(bed.getFacing());
}
}
use of org.bukkit.material.MaterialData in project Glowstone by GlowstoneMC.
the class BlockBed method afterPlace.
@Override
public void afterPlace(GlowPlayer player, GlowBlock block, ItemStack holding, GlowBlockState oldState) {
if (block.getType() == Material.BED_BLOCK) {
BlockFace direction = ((Bed) block.getState().getData()).getFacing();
GlowBlock headBlock = block.getRelative(direction);
headBlock.setType(Material.BED_BLOCK);
GlowBlockState headBlockState = headBlock.getState();
MaterialData data = headBlockState.getData();
((Bed) data).setHeadOfBed(true);
((Bed) data).setFacingDirection(direction);
headBlockState.setData(data);
headBlockState.update(true);
}
}
use of org.bukkit.material.MaterialData in project Glowstone by GlowstoneMC.
the class BlockBed method getFoot.
/**
* Returns the foot of a bed given one of its blocks.
*
* @param block part of the bed
* @return The foot of the bed
*/
public static GlowBlock getFoot(GlowBlock block) {
MaterialData data = block.getState().getData();
if (!(data instanceof Bed)) {
return null;
}
Bed bed = (Bed) data;
if (bed.isHeadOfBed()) {
return block.getRelative(bed.getFacing().getOppositeFace());
} else {
return block;
}
}
Aggregations