Java Code Examples for org.bukkit.block.Block#setData()
The following examples show how to use
org.bukkit.block.Block#setData() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: HillObjective.java From CardinalPGM with MIT License | 6 votes |
private void renderBlocks() { if (progress == null) return; byte color1 = capturingTeam != null ? MiscUtil.convertChatColorToDyeColor(capturingTeam.getColor()).getWoolData() : -1; byte color2 = team != null ? MiscUtil.convertChatColorToDyeColor(team.getColor()).getWoolData() : -1; Vector center = progress.getCenterBlock().getVector(); double x = center.getX(); double z = center.getZ(); double percent = Math.toRadians(getPercent() * 3.6); for(Block block : progress.getBlocks()) { if (!visualMaterials.evaluate(block).equals(FilterState.ALLOW)) continue; double dx = block.getX() - x; double dz = block.getZ() - z; double angle = Math.atan2(dz, dx); if(angle < 0) angle += 2 * Math.PI; byte color = angle < percent ? color1 : color2; if (color == -1) { Pair<Material,Byte> oldBlock = oldProgress.getBlockAt(new BlockVector(block.getLocation().position())); if (oldBlock.getLeft().equals(block.getType())) color = oldBlock.getRight(); } if (color != -1) block.setData(color); } }
Example 2
Source File: Blockdrops.java From CardinalPGM with MIT License | 6 votes |
@EventHandler(priority = EventPriority.MONITOR) public void onEntityExplode(EntityExplodeEvent event) { if (!event.isCancelled()) { Player player = TntTracker.getWhoPlaced(event.getEntity()) != null && Bukkit.getOfflinePlayer(TntTracker.getWhoPlaced(event.getEntity())).isOnline() ? Bukkit.getPlayer(TntTracker.getWhoPlaced(event.getEntity())) : null; if (player != null) { List<Block> toRemove = new ArrayList<>(); for (Block block : event.blockList()) { if (filter == null || filter.evaluate(player, block, event).equals(FilterState.ALLOW)) { if (region == null || region.contains(block.getLocation().toVector().add(new Vector(0.5, 0.5, 0.5)))) { for (ItemStack drop : this.drops) { GameHandler.getGameHandler().getMatchWorld().dropItemNaturally(block.getLocation(), drop); } if (this.experience != 0) { ExperienceOrb xp = GameHandler.getGameHandler().getMatchWorld().spawn(block.getLocation(), ExperienceOrb.class); xp.setExperience(this.experience); } toRemove.add(block); block.setType(replaceType); block.setData((byte) replaceDamage); } } } event.blockList().removeAll(toRemove); } } }
Example 3
Source File: ServerListener.java From ZombieEscape with GNU General Public License v2.0 | 6 votes |
/** * This is specific to my test server to prevent Crop trample. */ @EventHandler public void onTrample(PlayerInteractEvent e) { if (e.getClickedBlock() == null) { return; } if (e.getAction() == Action.PHYSICAL) { Block block = e.getClickedBlock(); Material material = block.getType(); if (material == Material.CROPS || material == Material.SOIL) { e.setUseInteractedBlock(PlayerInteractEvent.Result.DENY); e.setCancelled(true); block.setType(material); block.setData(block.getData()); } } }
Example 4
Source File: CraftBlockState.java From Thermos with GNU General Public License v3.0 | 6 votes |
public boolean update(boolean force, boolean applyPhysics) { Block block = getBlock(); if (block.getType() != getType()) { if (force) { block.setTypeId(getTypeId(), applyPhysics); } else { return false; } } block.setData(getRawData(), applyPhysics); world.getHandle().markBlockForUpdate(x, y, z); // Cauldron start - restore TE data from snapshot if (nbt != null) { TileEntity te = world.getHandle().getTileEntity(x, y, z); if (te != null) { te.readFromNBT(nbt); } } // Cauldron end return true; }
Example 5
Source File: ControlPointBlockDisplay.java From ProjectAres with GNU Affero General Public License v3.0 | 5 votes |
private void setBlock(BlockVector pos, Competitor team) { final Block block = BlockUtils.blockAt(match.getWorld(), pos); if(this.controlPoint.getDefinition().getVisualMaterials().query(new BlockQuery(block)).isAllowed()) { if(team != null) { block.setData(BukkitUtils.chatColorToDyeColor(team.getColor()).getWoolData()); } else { this.progressDisplayImage.restore(pos); } } }
Example 6
Source File: HillObjective.java From CardinalPGM with MIT License | 5 votes |
private void renderCaptured() { if (captured == null) return; for(Block block : captured.getBlocks()) { if (!visualMaterials.evaluate(block).equals(FilterState.ALLOW)) continue; byte color = team != null ? MiscUtil.convertChatColorToDyeColor(team.getColor()).getWoolData() : -1; if (color == -1) { Pair<Material,Byte> oldBlock = oldCaptured.getBlockAt(new BlockVector(block.getLocation().position())); if (oldBlock.getLeft().equals(block.getType())) color = oldBlock.getRight(); } if (color != -1) block.setData(color); } }
Example 7
Source File: BlockListener.java From Carbon with GNU Lesser General Public License v3.0 | 5 votes |
@SuppressWarnings("deprecation") private void setDoubleSlab(Player player, Block block) { block.setType(Carbon.injector().redSandstoneDoubleSlabMat); block.setData((byte) 0); block.getWorld().playSound(block.getLocation(), Sound.DIG_STONE, 1, 1); if (player.getGameMode() != GameMode.CREATIVE) { if (player.getItemInHand().getAmount() > 1) player.getItemInHand().setAmount(player.getItemInHand().getAmount() - 1); else player.setItemInHand(null); } }
Example 8
Source File: PlayerHeadProvider.java From UHC with MIT License | 5 votes |
public void setBlockAsHead(String name, Block headBlock, BlockFaceXZ direction) { // set the type to skull headBlock.setType(Material.SKULL); headBlock.setData((byte) 1); final Skull state = (Skull) headBlock.getState(); state.setSkullType(SkullType.PLAYER); state.setOwner(name); state.setRotation(direction.getBlockFace()); state.update(); }
Example 9
Source File: NMS_v1_8_R3.java From Crazy-Crates with MIT License | 5 votes |
@Override public void pasteSchematic(File f, Location loc) { loc = loc.subtract(2, 1, 2); try { FileInputStream fis = new FileInputStream(f); NBTTagCompound nbt = NBTCompressedStreamTools.a(fis); short width = nbt.getShort("Width"); short height = nbt.getShort("Height"); short length = nbt.getShort("Length"); byte[] blocks = nbt.getByteArray("Blocks"); byte[] data = nbt.getByteArray("Data"); fis.close(); //paste for (int x = 0; x < width; ++x) { for (int y = 0; y < height; ++y) { for (int z = 0; z < length; ++z) { int index = y * width * length + z * width + x; final Location l = new Location(loc.getWorld(), x + loc.getX(), y + loc.getY(), z + loc.getZ()); int b = blocks[index] & 0xFF;//make the block unsigned, so that blocks with an id over 127, like quartz and emerald, can be pasted final Block block = l.getBlock(); block.setType(Material.getMaterial(b)); block.setData(data[index]); //you can check what type the block is here, like if(m.equals(Material.BEACON)) to check if it's a beacon } } } } catch (Exception e) { e.printStackTrace(); } }
Example 10
Source File: NMS_v1_11_R1.java From Crazy-Crates with MIT License | 5 votes |
@Override public void pasteSchematic(File f, Location loc) { loc = loc.subtract(2, 1, 2); try { FileInputStream fis = new FileInputStream(f); NBTTagCompound nbt = NBTCompressedStreamTools.a(fis); short width = nbt.getShort("Width"); short height = nbt.getShort("Height"); short length = nbt.getShort("Length"); byte[] blocks = nbt.getByteArray("Blocks"); byte[] data = nbt.getByteArray("Data"); fis.close(); //paste for (int x = 0; x < width; ++x) { for (int y = 0; y < height; ++y) { for (int z = 0; z < length; ++z) { int index = y * width * length + z * width + x; final Location l = new Location(loc.getWorld(), x + loc.getX(), y + loc.getY(), z + loc.getZ()); int b = blocks[index] & 0xFF;//make the block unsigned, so that blocks with an id over 127, like quartz and emerald, can be pasted final Block block = l.getBlock(); block.setType(Material.getMaterial(b)); block.setData(data[index]); //you can check what type the block is here, like if(m.equals(Material.BEACON)) to check if it's a beacon } } } } catch (Exception e) { e.printStackTrace(); } }
Example 11
Source File: NMS_v1_12_R1.java From Crazy-Crates with MIT License | 5 votes |
@Override public void pasteSchematic(File f, Location loc) { loc = loc.subtract(2, 1, 2); try { FileInputStream fis = new FileInputStream(f); NBTTagCompound nbt = NBTCompressedStreamTools.a(fis); short width = nbt.getShort("Width"); short height = nbt.getShort("Height"); short length = nbt.getShort("Length"); byte[] blocks = nbt.getByteArray("Blocks"); byte[] data = nbt.getByteArray("Data"); fis.close(); //paste for (int x = 0; x < width; ++x) { for (int y = 0; y < height; ++y) { for (int z = 0; z < length; ++z) { int index = y * width * length + z * width + x; final Location l = new Location(loc.getWorld(), x + loc.getX(), y + loc.getY(), z + loc.getZ()); int b = blocks[index] & 0xFF;//make the block unsigned, so that blocks with an id over 127, like quartz and emerald, can be pasted final Block block = l.getBlock(); block.setType(Material.getMaterial(b)); block.setData(data[index]); //you can check what type the block is here, like if(m.equals(Material.BEACON)) to check if it's a beacon } } } } catch (Exception e) { e.printStackTrace(); } }
Example 12
Source File: NMS_v1_10_R1.java From Crazy-Crates with MIT License | 5 votes |
@Override public void pasteSchematic(File f, Location loc) { loc = loc.subtract(2, 1, 2); try { FileInputStream fis = new FileInputStream(f); NBTTagCompound nbt = NBTCompressedStreamTools.a(fis); short width = nbt.getShort("Width"); short height = nbt.getShort("Height"); short length = nbt.getShort("Length"); byte[] blocks = nbt.getByteArray("Blocks"); byte[] data = nbt.getByteArray("Data"); fis.close(); //paste for (int x = 0; x < width; ++x) { for (int y = 0; y < height; ++y) { for (int z = 0; z < length; ++z) { int index = y * width * length + z * width + x; final Location l = new Location(loc.getWorld(), x + loc.getX(), y + loc.getY(), z + loc.getZ()); int b = blocks[index] & 0xFF;//make the block unsigned, so that blocks with an id over 127, like quartz and emerald, can be pasted final Block block = l.getBlock(); block.setType(Material.getMaterial(b)); block.setData(data[index]); //you can check what type the block is here, like if(m.equals(Material.BEACON)) to check if it's a beacon } } } } catch (Exception e) { e.printStackTrace(); } }
Example 13
Source File: NMS_v1_9_R2.java From Crazy-Crates with MIT License | 5 votes |
@Override public void pasteSchematic(File f, Location loc) { loc = loc.subtract(2, 1, 2); try { FileInputStream fis = new FileInputStream(f); NBTTagCompound nbt = NBTCompressedStreamTools.a(fis); short width = nbt.getShort("Width"); short height = nbt.getShort("Height"); short length = nbt.getShort("Length"); byte[] blocks = nbt.getByteArray("Blocks"); byte[] data = nbt.getByteArray("Data"); fis.close(); //paste for (int x = 0; x < width; ++x) { for (int y = 0; y < height; ++y) { for (int z = 0; z < length; ++z) { int index = y * width * length + z * width + x; final Location l = new Location(loc.getWorld(), x + loc.getX(), y + loc.getY(), z + loc.getZ()); int b = blocks[index] & 0xFF;//make the block unsigned, so that blocks with an id over 127, like quartz and emerald, can be pasted final Block block = l.getBlock(); block.setType(Material.getMaterial(b)); block.setData(data[index]); //you can check what type the block is here, like if(m.equals(Material.BEACON)) to check if it's a beacon } } } } catch (Exception e) { e.printStackTrace(); } }
Example 14
Source File: NMS_v1_9_R1.java From Crazy-Crates with MIT License | 5 votes |
@Override public void pasteSchematic(File f, Location loc) { loc = loc.subtract(2, 1, 2); try { FileInputStream fis = new FileInputStream(f); NBTTagCompound nbt = NBTCompressedStreamTools.a(fis); short width = nbt.getShort("Width"); short height = nbt.getShort("Height"); short length = nbt.getShort("Length"); byte[] blocks = nbt.getByteArray("Blocks"); byte[] data = nbt.getByteArray("Data"); fis.close(); //paste for (int x = 0; x < width; ++x) { for (int y = 0; y < height; ++y) { for (int z = 0; z < length; ++z) { int index = y * width * length + z * width + x; final Location l = new Location(loc.getWorld(), x + loc.getX(), y + loc.getY(), z + loc.getZ()); int b = blocks[index] & 0xFF;//make the block unsigned, so that blocks with an id over 127, like quartz and emerald, can be pasted final Block block = l.getBlock(); block.setType(Material.getMaterial(b)); block.setData(data[index]); //you can check what type the block is here, like if(m.equals(Material.BEACON)) to check if it's a beacon } } } } catch (Exception e) { e.printStackTrace(); } }
Example 15
Source File: ControlPointBlockDisplay.java From PGM with GNU Affero General Public License v3.0 | 5 votes |
@SuppressWarnings("deprecation") private void setBlock(Block block, Competitor team) { if (this.controlPoint .getDefinition() .getVisualMaterials() .query(new BlockQuery(block)) .isAllowed()) { if (team != null) { block.setData(BukkitUtils.chatColorToDyeColor(team.getColor()).getWoolData()); } else { this.progressDisplayImage.restore(block); } } }
Example 16
Source File: RescuePlatform.java From BedwarsRel with GNU General Public License v3.0 | 4 votes |
@SuppressWarnings("deprecation") public void create(Player player, Game game) { this.game = game; this.owner = player; int breakTime = BedwarsRel.getInstance() .getIntConfig("specials.rescue-platform.break-time", 10); int waitTime = BedwarsRel .getInstance().getIntConfig("specials.rescue-platform.using-wait-time", 20); boolean canBreak = BedwarsRel.getInstance().getBooleanConfig("specials.rescue-platform.can-break", false); Material configMaterial = Utils.getMaterialByConfig("specials.rescue-platform.block", Material.STAINED_GLASS); if (waitTime > 0) { ArrayList<RescuePlatform> livingPlatforms = this.getLivingPlatforms(); if (!livingPlatforms.isEmpty()) { for (RescuePlatform livingPlatform : livingPlatforms) { int waitLeft = waitTime - livingPlatform.getLivingTime(); if (waitLeft > 0) { player.sendMessage( ChatWriter.pluginMessage( BedwarsRel._l(player, "ingame.specials.rescue-platform.left", ImmutableMap.of("time", String.valueOf(waitLeft))))); return; } } } } if (player.getLocation().getBlock().getRelative(BlockFace.DOWN).getType() != Material.AIR) { player.sendMessage( ChatWriter.pluginMessage(ChatColor.RED + BedwarsRel._l(player, "errors.notinair"))); return; } Location mid = player.getLocation().clone(); mid.setY(mid.getY() - 1.0D); Team team = game.getPlayerTeam(player); ItemStack usedStack = null; if (BedwarsRel.getInstance().getCurrentVersion().startsWith("v1_8")) { usedStack = player.getInventory().getItemInHand(); usedStack.setAmount(usedStack.getAmount() - 1); player.getInventory().setItem(player.getInventory().getHeldItemSlot(), usedStack); } else { if (player.getInventory().getItemInOffHand().getType() == this.getItemMaterial()) { usedStack = player.getInventory().getItemInOffHand(); usedStack.setAmount(usedStack.getAmount() - 1); player.getInventory().setItemInOffHand(usedStack); } else if (player.getInventory().getItemInMainHand().getType() == this.getItemMaterial()) { usedStack = player.getInventory().getItemInMainHand(); usedStack.setAmount(usedStack.getAmount() - 1); player.getInventory().setItemInMainHand(usedStack); } } player.updateInventory(); for (BlockFace face : BlockFace.values()) { if (face.equals(BlockFace.DOWN) || face.equals(BlockFace.UP)) { continue; } Block placed = mid.getBlock().getRelative(face); if (placed.getType() != Material.AIR) { continue; } placed.setType(configMaterial); if (configMaterial.equals(Material.STAINED_GLASS) || configMaterial.equals(Material.WOOL) || configMaterial.equals(Material.STAINED_CLAY)) { placed.setData(team.getColor().getDyeColor().getWoolData()); } if (!canBreak) { game.getRegion().addPlacedUnbreakableBlock(placed, null); } else { game.getRegion().addPlacedBlock(placed, null); } this.addPlatformBlock(placed); } if (breakTime > 0 || waitTime > 0) { this.runTask(breakTime, waitTime); game.addSpecialItem(this); } }
Example 17
Source File: BlockAdapterMagicValues.java From DungeonsXL with GNU General Public License v3.0 | 4 votes |
@Override public void openDoor(Block block) { block.setData((byte) (block.getData() + 4)); }
Example 18
Source File: BlockAdapterMagicValues.java From DungeonsXL with GNU General Public License v3.0 | 4 votes |
@Override public void closeDoor(Block block) { block.setData((byte) (block.getData() - 4)); }
Example 19
Source File: BlockAdapterMagicValues.java From DungeonsXL with GNU General Public License v3.0 | 4 votes |
@Override public void setAxis(Block block, boolean z) { block.setData(z ? (byte) 2 : 1); }
Example 20
Source File: ItemManager.java From civcraft with GNU General Public License v2.0 | 4 votes |
@SuppressWarnings("deprecation") public static void setData(Block block, int data) { block.setData((byte)data); }