use of org.bukkit.block.BlockFace in project Minigames by AddstarMC.
the class ScoreboardDisplay method load.
@SuppressWarnings("deprecation")
public static ScoreboardDisplay load(Minigame minigame, ConfigurationSection section) {
int width = section.getInt("width");
int height = section.getInt("height");
Location location = MinigameUtils.loadShortLocation(section.getConfigurationSection("location"));
BlockFace facing = BlockFace.valueOf(section.getString("dir"));
// from invalid world
if (location == null) {
return null;
}
ScoreboardDisplay display = new ScoreboardDisplay(minigame, width, height, location, facing);
display.setOrder(ScoreboardOrder.valueOf(section.getString("order")));
// Convert type to new stat
if (section.contains("type")) {
ScoreboardType type = ScoreboardType.valueOf(section.getString("type"));
switch(type) {
case BEST_KILLS:
display.setStat(MinigameStats.Kills, StatValueField.Max);
break;
case BEST_SCORE:
display.setStat(MinigameStats.Score, StatValueField.Max);
break;
case COMPLETIONS:
display.setStat(MinigameStats.Wins, StatValueField.Total);
break;
case FAILURES:
display.setStat(MinigameStats.Losses, StatValueField.Total);
break;
case LEAST_DEATHS:
display.setStat(MinigameStats.Deaths, StatValueField.Min);
break;
case LEAST_REVERTS:
display.setStat(MinigameStats.Reverts, StatValueField.Min);
break;
case LEAST_TIME:
display.setStat(MinigameStats.CompletionTime, StatValueField.Min);
break;
case TOTAL_DEATHS:
display.setStat(MinigameStats.Deaths, StatValueField.Total);
break;
case TOTAL_KILLS:
display.setStat(MinigameStats.Kills, StatValueField.Total);
break;
case TOTAL_REVERTS:
display.setStat(MinigameStats.Reverts, StatValueField.Total);
break;
case TOTAL_SCORE:
display.setStat(MinigameStats.Score, StatValueField.Total);
break;
case TOTAL_TIME:
display.setStat(MinigameStats.CompletionTime, StatValueField.Total);
break;
default:
break;
}
section.set("type", null);
// Load stat
} else {
MinigameStat stat = MinigameStats.getStat(section.getString("stat", "wins"));
StatValueField field = StatValueField.valueOf(section.getString("field", "Total"));
display.setStat(stat, field);
}
Block block = location.getBlock();
block.setMetadata("MGScoreboardSign", new FixedMetadataValue(Minigames.plugin, true));
block.setMetadata("Minigame", new FixedMetadataValue(Minigames.plugin, minigame));
return display;
}
use of org.bukkit.block.BlockFace in project Minigames by AddstarMC.
the class ScoreboardDisplay method getSignBlocks.
private List<Block> getSignBlocks(boolean onlySigns) {
// Find the horizontal direction (going across the the signs, left to right)
BlockFace horizontal;
switch(facing) {
case NORTH:
horizontal = BlockFace.WEST;
break;
case SOUTH:
horizontal = BlockFace.EAST;
break;
case WEST:
horizontal = BlockFace.SOUTH;
break;
case EAST:
horizontal = BlockFace.NORTH;
break;
default:
throw new AssertionError("Invalid facing " + facing);
}
List<Block> blocks = Lists.newArrayListWithCapacity(width * height);
// Find the corner that is the top left part of the scoreboard
Location min = rootBlock.clone();
min.add(-horizontal.getModX() * (width / 2), -1, -horizontal.getModZ() * (width / 2));
// Grab each sign of the scoreboards in order
Block block = min.getBlock();
for (int y = 0; y < height; ++y) {
Block start = block;
for (int x = 0; x < width; ++x) {
// Only add signs
if (block.getType() == Material.WALL_SIGN || (!onlySigns && block.getType() == Material.AIR)) {
blocks.add(block);
}
block = block.getRelative(horizontal);
}
block = start.getRelative(BlockFace.DOWN);
}
return blocks;
}
use of org.bukkit.block.BlockFace in project Minigames by AddstarMC.
the class RecorderData method addBlock.
public BlockData addBlock(BlockState block, MinigamePlayer modifier) {
BlockData bdata = new BlockData(block, modifier);
String sloc = String.valueOf(bdata.getLocation().getBlockX()) + ":" + bdata.getLocation().getBlockY() + ":" + bdata.getLocation().getBlockZ();
if (!blockdata.containsKey(sloc)) {
if (block.getType() == Material.CHEST) {
Chest chest = (Chest) block;
if (chest.getInventory().getSize() > 27) {
Location loc = block.getLocation().clone();
boolean isRight = false;
BlockFace dir = ((org.bukkit.material.Chest) chest.getData()).getFacing();
BlockData secondChest = null;
//West = -z; East = +z; North = +x; South = -x;
if (dir == BlockFace.NORTH) {
loc.setX(loc.getX() + 1);
if (loc.getBlock().getType() == Material.CHEST) {
isRight = true;
}
secondChest = addBlock(loc.getBlock().getState(), modifier);
} else if (dir == BlockFace.SOUTH) {
loc.setX(loc.getX() - 1);
if (loc.getBlock().getType() == Material.CHEST) {
isRight = true;
}
secondChest = addBlock(loc.getBlock().getState(), modifier);
} else if (dir == BlockFace.WEST) {
loc.setZ(loc.getZ() - 1);
if (loc.getBlock().getType() == Material.CHEST) {
isRight = true;
}
secondChest = addBlock(loc.getBlock().getState(), modifier);
} else if (dir == BlockFace.EAST) {
loc.setZ(loc.getZ() + 1);
if (loc.getBlock().getType() == Material.CHEST) {
isRight = true;
}
secondChest = addBlock(loc.getBlock().getState(), modifier);
}
if (!isRight) {
ItemStack[] items = new ItemStack[chest.getInventory().getContents().length];
for (int i = 0; i < items.length; i++) {
if (chest.getInventory().getContents()[i] != null)
items[i] = chest.getInventory().getContents()[i].clone();
}
bdata.setItems(items);
if (minigame.isRandomizeChests())
bdata.randomizeContents(minigame.getMinChestRandom(), minigame.getMaxChestRandom());
} else {
if (secondChest.getItems() == null) {
ItemStack[] items = new ItemStack[chest.getInventory().getContents().length];
for (int i = 0; i < items.length; i++) {
if (chest.getInventory().getContents()[i] != null)
items[i] = chest.getInventory().getContents()[i].clone();
}
secondChest.setItems(items);
if (minigame.isRandomizeChests())
secondChest.randomizeContents(minigame.getMinChestRandom(), minigame.getMaxChestRandom());
}
}
} else {
ItemStack[] items = new ItemStack[chest.getInventory().getContents().length];
for (int i = 0; i < items.length; i++) {
if (chest.getInventory().getContents()[i] != null)
items[i] = chest.getInventory().getContents()[i].clone();
}
bdata.setItems(items);
if (minigame.isRandomizeChests())
bdata.randomizeContents(minigame.getMinChestRandom(), minigame.getMaxChestRandom());
}
} else if (block instanceof InventoryHolder) {
InventoryHolder inv = (InventoryHolder) block;
ItemStack[] items = new ItemStack[inv.getInventory().getContents().length];
for (int i = 0; i < items.length; i++) {
if (inv.getInventory().getContents()[i] != null)
items[i] = inv.getInventory().getContents()[i].clone();
}
bdata.setItems(items);
} else if (block.getType() == Material.FLOWER_POT) {
bdata.setSpecialData("contents", block.getData());
}
blockdata.put(sloc, bdata);
return bdata;
} else {
if (block.getType() != Material.CHEST || !blockdata.get(sloc).hasRandomized())
blockdata.get(sloc).setModifier(modifier);
return blockdata.get(sloc);
}
}
use of org.bukkit.block.BlockFace in project Glowstone by GlowstoneMC.
the class BlockChest 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 Chest) {
Chest chest = (Chest) data;
GlowBlock chestBlock = state.getBlock();
BlockFace normalFacing = getOppositeBlockFace(player.getLocation(), false);
Collection<BlockFace> attachedChests = searchChests(chestBlock);
if (attachedChests.isEmpty()) {
chest.setFacingDirection(normalFacing);
state.setData(chest);
return;
} else if (attachedChests.size() > 1) {
GlowServer.logger.warning("Chest placed near two other chests!");
return;
}
BlockFace otherPart = attachedChests.iterator().next();
GlowBlock otherPartBlock = chestBlock.getRelative(otherPart);
if (getAttachedChest(otherPartBlock) != null) {
GlowServer.logger.warning("Chest placed near already attached chest!");
return;
}
BlockState otherPartState = otherPartBlock.getState();
MaterialData otherPartData = otherPartState.getData();
if (otherPartData instanceof Chest) {
Chest otherChest = (Chest) otherPartData;
BlockFace facing = getFacingDirection(normalFacing, otherChest.getFacing(), otherPart, player);
chest.setFacingDirection(facing);
state.setData(chest);
otherChest.setFacingDirection(facing);
otherPartState.setData(otherChest);
otherPartState.update();
} else {
warnMaterialData(Chest.class, otherPartData);
}
} else {
warnMaterialData(Chest.class, data);
}
}
use of org.bukkit.block.BlockFace in project Glowstone by GlowstoneMC.
the class BlockButton method extraUpdate.
private void extraUpdate(GlowBlock block) {
Button button = (Button) block.getState().getData();
ItemTable itemTable = ItemTable.instance();
GlowBlock target = block.getRelative(button.getAttachedFace());
if (target.getType().isSolid()) {
for (BlockFace face2 : ADJACENT) {
GlowBlock target2 = target.getRelative(face2);
BlockType notifyType = itemTable.getBlock(target2.getTypeId());
if (notifyType != null) {
if (target2.getFace(block) == null) {
notifyType.onNearBlockChanged(target2, BlockFace.SELF, block, block.getType(), block.getData(), block.getType(), block.getData());
}
notifyType.onRedstoneUpdate(target2);
}
}
}
}
Aggregations