use of org.bukkit.material.Directional in project BKCommonLib by bergerhealer.
the class BlockUtil method setFacing.
/**
* Sets the facing direction of a Directional block
*
* @param block to set
* @param facing direction to set to
*/
public static void setFacing(org.bukkit.block.Block block, BlockFace facing) {
MaterialData data = getData(block);
if (data != null && data instanceof Directional) {
((Directional) data).setFacingDirection(facing);
setData(block, data, true);
}
}
use of org.bukkit.material.Directional in project Minigames by AddstarMC.
the class ScoreboardSign method signCreate.
@Override
public boolean signCreate(SignChangeEvent event) {
Sign sign = (Sign) event.getBlock().getState();
if (sign.getType() != Material.OAK_WALL_SIGN) {
event.getPlayer().sendMessage(ChatColor.RED + "Scoreboards must be placed on a wall!");
return false;
}
// Parse minigame
Minigame minigame;
if (plugin.getMinigameManager().hasMinigame(event.getLine(2))) {
minigame = plugin.getMinigameManager().getMinigame(event.getLine(2));
} else {
event.getPlayer().sendMessage(ChatColor.RED + "No Minigame found by the name " + event.getLine(2));
return false;
}
// Parse size
int width;
int height;
if (event.getLine(3).isEmpty()) {
width = ScoreboardDisplay.defaultWidth;
height = ScoreboardDisplay.defaultHeight;
} else if (event.getLine(3).matches("[0-9]+x[0-9]+")) {
String[] parts = event.getLine(3).split("x");
width = Integer.parseInt(parts[0]);
height = Integer.parseInt(parts[1]);
} else {
event.getPlayer().sendMessage(ChatColor.RED + "Invalid size. Requires nothing or (width)x(height) eg. 3x3");
return false;
}
// So we dont have to deal with even size scoreboards
if (width % 2 == 0) {
event.getPlayer().sendMessage(ChatColor.RED + "Length must not be an even number!");
return false;
}
BlockFace facing = ((Directional) sign.getData()).getFacing();
// Add our display
ScoreboardDisplay display = new ScoreboardDisplay(minigame, width, height, event.getBlock().getLocation(), facing);
display.placeSigns();
minigame.getScoreboardData().addDisplay(display);
// Reformat this sign for the next part
event.setLine(1, ChatColor.GREEN + "Scoreboard");
event.setLine(2, minigame.getName(false));
event.getBlock().setMetadata("Minigame", new FixedMetadataValue(plugin, minigame));
return true;
}
use of org.bukkit.material.Directional in project Minigames by AddstarMC.
the class SwapBlockAction method executeRegionAction.
@Override
public void executeRegionAction(MinigamePlayer player, Region region) {
debug(player, region);
for (int y = region.getFirstPoint().getBlockY(); y <= region.getSecondPoint().getBlockY(); y++) {
for (int x = region.getFirstPoint().getBlockX(); x <= region.getSecondPoint().getBlockX(); x++) {
for (int z = region.getFirstPoint().getBlockZ(); z <= region.getSecondPoint().getBlockZ(); z++) {
Block block = region.getFirstPoint().getWorld().getBlockAt(x, y, z);
if (block.getBlockData().getMaterial() == matchType.getFlag().getMaterial()) {
if (matchData.getFlag() && block.getBlockData() != matchType.getFlag()) {
continue;
}
// Block matches, now replace it
BlockData newBlockData;
BlockFace facing = null;
if (toData.getFlag()) {
// Replace data
newBlockData = toType.getFlag();
} else {
// just create a new instance of the Materials default blockdata
newBlockData = toType.getFlag().getMaterial().createBlockData();
}
if (keepAttachment.getFlag()) {
// Keep attachments if possible
BlockData data = block.getBlockData();
if (data instanceof Directional) {
facing = ((Directional) data).getFacing();
}
}
if (newBlockData instanceof Directional)
((Directional) newBlockData).setFacingDirection(facing);
// Update block type
block.setBlockData(newBlockData);
}
}
}
}
}
Aggregations