Java Code Examples for org.bukkit.block.Block#getState()
The following examples show how to use
org.bukkit.block.Block#getState() .
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: Cannon.java From civcraft with GNU General Public License v2.0 | 6 votes |
private void updateAngleSign(Block block) { Sign sign = (Sign)block.getState(); sign.setLine(0, "YAW"); sign.setLine(1, ""+this.angle); double a = this.angle; if (a > 0) { sign.setLine(2, "-->"); } else if (a < 0){ sign.setLine(2, "<--"); } else { sign.setLine(2, ""); } sign.setLine(3, ""); sign.update(); }
Example 2
Source File: ProgrammableAndroid.java From Slimefun4 with GNU General Public License v3.0 | 6 votes |
protected void depositItems(BlockMenu menu, Block facedBlock) { if (facedBlock.getType() == Material.DISPENSER && BlockStorage.check(facedBlock, "ANDROID_INTERFACE_ITEMS")) { Dispenser d = (Dispenser) facedBlock.getState(); for (int slot : getOutputSlots()) { ItemStack stack = menu.getItemInSlot(slot); if (stack != null) { Optional<ItemStack> optional = d.getInventory().addItem(stack).values().stream().findFirst(); if (optional.isPresent()) { menu.replaceExistingItem(slot, optional.get()); } else { menu.replaceExistingItem(slot, null); } } } } }
Example 3
Source File: XBlock.java From IridiumSkyblock with GNU General Public License v2.0 | 6 votes |
/** * Wool and Dye. But Dye is not a block itself. */ public static DyeColor getColor(Block block) { if (XMaterial.ISFLAT) { if (!(block.getBlockData() instanceof Colorable)) return null; Colorable colorable = (Colorable) block.getBlockData(); return colorable.getColor(); } BlockState state = block.getState(); MaterialData data = state.getData(); if (data instanceof Wool) { Wool wool = (Wool) data; return wool.getColor(); } return null; }
Example 4
Source File: XBlock.java From XSeries with MIT License | 6 votes |
/** * Wool and Dye. But Dye is not a block itself. */ public static DyeColor getColor(Block block) { if (ISFLAT) { if (!(block.getBlockData() instanceof Colorable)) return null; Colorable colorable = (Colorable) block.getBlockData(); return colorable.getColor(); } BlockState state = block.getState(); MaterialData data = state.getData(); if (data instanceof Wool) { Wool wool = (Wool) data; return wool.getColor(); } return null; }
Example 5
Source File: SignUtil.java From GriefDefender with MIT License | 5 votes |
public static boolean isSellSign(Block block) { if (!isSign(block)) { return false; } final Sign sign = (Sign) block.getState(); final String header = ChatColor.stripColor(sign.getLine(0)); if (header.equalsIgnoreCase(SELL_SIGN)) { return true; } return false; }
Example 6
Source File: v1_15_R1.java From IridiumSkyblock with GNU General Public License v2.0 | 5 votes |
@Override public void setBlockFast(Block block, int blockId, byte data) { BlockState state = block.getState(); if (state.getType().name().endsWith("AIR") && blockId == 0) return; if (state instanceof InventoryHolder) { ((InventoryHolder) state).getInventory().clear(); } XMaterial material = XMaterial.requestOldXMaterial(blockId, (byte) 0); if (material != null && material.parseMaterial() != null) { block.setBlockData(IridiumSkyblock.getInstance().fromLegacy(material.parseMaterial(), data), false); } }
Example 7
Source File: Buildable.java From civcraft with GNU General Public License v2.0 | 5 votes |
public synchronized void buildRepairTemplate(Template tpl, Block centerBlock) { HashMap<Chunk, Chunk> chunkUpdates = new HashMap<Chunk, Chunk>(); for (int x = 0; x < tpl.size_x; x++) { for (int y = 0; y < tpl.size_y; y++) { for (int z = 0; z < tpl.size_z; z++) { Block b = centerBlock.getRelative(x, y, z); //b.setTypeIdAndData(tpl.blocks[x][y][z].getType(), (byte)tpl.blocks[x][y][z].getData(), false); if (tpl.blocks[x][y][z].specialType == Type.COMMAND) { ItemManager.setTypeIdAndData(b, CivData.AIR, (byte)0, false); } else { ItemManager.setTypeIdAndData(b, tpl.blocks[x][y][z].getType(), (byte)tpl.blocks[x][y][z].getData(), false); } chunkUpdates.put(b.getChunk(), b.getChunk()); if (ItemManager.getId(b) == CivData.WALL_SIGN || ItemManager.getId(b) == CivData.SIGN) { Sign s2 = (Sign)b.getState(); s2.setLine(0, tpl.blocks[x][y][z].message[0]); s2.setLine(1, tpl.blocks[x][y][z].message[1]); s2.setLine(2, tpl.blocks[x][y][z].message[2]); s2.setLine(3, tpl.blocks[x][y][z].message[3]); s2.update(); } } } } }
Example 8
Source File: CraftEventFactory.java From Thermos with GNU General Public License v3.0 | 5 votes |
/** * BlockFadeEvent */ public static BlockFadeEvent callBlockFadeEvent(Block block, net.minecraft.block.Block type) { BlockState state = block.getState(); state.setTypeId(net.minecraft.block.Block.getIdFromBlock(type)); BlockFadeEvent event = new BlockFadeEvent(block, state); Bukkit.getPluginManager().callEvent(event); return event; }
Example 9
Source File: BlockDataService.java From Slimefun4 with GNU General Public License v3.0 | 5 votes |
/** * This method returns the NBT data previously stored inside this {@link Block}. * * @param b * The {@link Block} to retrieve data from * @return The stored value */ public Optional<String> getBlockData(Block b) { BlockState state = b.getState(); if (state instanceof TileState) { return getString((TileState) state, namespacedKey); } else { return Optional.empty(); } }
Example 10
Source File: OreCrusher.java From Slimefun4 with GNU General Public License v3.0 | 5 votes |
@Override public void onInteract(Player p, Block b) { Block dispBlock = b.getRelative(BlockFace.DOWN); Dispenser disp = (Dispenser) dispBlock.getState(); Inventory inv = disp.getInventory(); for (ItemStack current : inv.getContents()) { for (ItemStack convert : RecipeType.getRecipeInputs(this)) { if (convert != null && SlimefunUtils.isItemSimilar(current, convert, true)) { ItemStack adding = RecipeType.getRecipeOutput(this, convert); Inventory outputInv = findOutputInventory(adding, dispBlock, inv); if (outputInv != null) { ItemStack removing = current.clone(); removing.setAmount(convert.getAmount()); inv.removeItem(removing); outputInv.addItem(adding); p.getWorld().playEffect(b.getLocation(), Effect.STEP_SOUND, 1); } else SlimefunPlugin.getLocalization().sendMessage(p, "machines.full-inventory", true); return; } } } SlimefunPlugin.getLocalization().sendMessage(p, "machines.unknown-material", true); }
Example 11
Source File: ContainerAdapter.java From DungeonsXL with GNU General Public License v3.0 | 5 votes |
public static boolean isValidContainer(Block block) { if (Version.isAtLeast(Version.MC1_12_1)) { return block.getState() instanceof Container; } else { return block.getState() instanceof Chest; } }
Example 12
Source File: XBlock.java From IridiumSkyblock with GNU General Public License v2.0 | 5 votes |
/** * Sets the type of any block that can be colored. * * @param block the block to color. * @param color the color to use. * @return true if the block can be colored, otherwise false. */ public static boolean setColor(Block block, DyeColor color) { if (XMaterial.ISFLAT) { String type = block.getType().name(); if (type.endsWith("WOOL")) block.setType(Material.getMaterial(color.name() + "_WOOL")); else if (type.endsWith("BED")) block.setType(Material.getMaterial(color.name() + "_BED")); else if (type.endsWith("STAINED_GLASS")) block.setType(Material.getMaterial(color.name() + "_STAINED_GLASS")); else if (type.endsWith("STAINED_GLASS_PANE")) block.setType(Material.getMaterial(color.name() + "_STAINED_GLASS_PANE")); else if (type.endsWith("TERRACOTTA")) block.setType(Material.getMaterial(color.name() + "_TERRACOTTA")); else if (type.endsWith("GLAZED_TERRACOTTA")) block.setType(Material.getMaterial(color.name() + "_GLAZED_TERRACOTTA")); else if (type.endsWith("BANNER")) block.setType(Material.getMaterial(color.name() + "_BANNER")); else if (type.endsWith("WALL_BANNER")) block.setType(Material.getMaterial(color.name() + "_WALL_BANNER")); else if (type.endsWith("CARPET")) block.setType(Material.getMaterial(color.name() + "_CARPET")); else if (type.endsWith("SHULKER_BOX")) block.setType(Material.getMaterial(color.name() + "_SHULKERBOX")); else if (type.endsWith("CONCRETE")) block.setType(Material.getMaterial(color.name() + "_CONCRETE")); else if (type.endsWith("CONCRETE_POWDER")) block.setType(Material.getMaterial(color.name() + "_CONCRETE_POWDER")); else return false; return true; } BlockState state = block.getState(); state.setRawData(color.getWoolData()); state.update(true); return false; }
Example 13
Source File: SignUtil.java From GriefDefender with MIT License | 5 votes |
public static boolean isRentSign(Block block) { if (!isSign(block)) { return false; } final Sign sign = (Sign) block.getState(); final String header = ChatColor.stripColor(sign.getLine(0)); if (header.equalsIgnoreCase(RENT_SIGN)) { return true; } return false; }
Example 14
Source File: VersionHelper18.java From RedProtect with GNU General Public License v3.0 | 5 votes |
public void toggleDoor(Block b) { BlockState state = b.getState(); if (state instanceof Door) { Door op = (Door) state.getData(); if (!op.isOpen()) op.setOpen(true); else op.setOpen(false); state.setData(op); state.update(); } }
Example 15
Source File: VersionHelper113.java From RedProtect with GNU General Public License v3.0 | 5 votes |
public Block getBlockRelative(Block block) { if (block.getState() instanceof Sign) { Directional dir = (Directional) block.getBlockData(); return block.getRelative(dir.getFacing().getOppositeFace()); } return null; }
Example 16
Source File: SpawnerExplodeListener.java From MineableSpawners with MIT License | 4 votes |
@EventHandler (ignoreCancelled = true, priority = EventPriority.HIGHEST) public void onSpawnerExplode(EntityExplodeEvent e) { if (!plugin.getConfigurationHandler().getBoolean("explode", "drop")) { return; } for (Block block : e.blockList()) { if (!block.getType().equals(XMaterial.SPAWNER.parseMaterial())) { continue; } double dropChance = plugin.getConfigurationHandler().getDouble("explode", "chance")/100; if (dropChance != 1) { double random = Math.random(); if (random >= dropChance) { return; } } CreatureSpawner spawner = (CreatureSpawner) block.getState(); ItemStack item = new ItemStack(XMaterial.SPAWNER.parseMaterial()); ItemMeta meta = item.getItemMeta(); String mobFormatted = Chat.uppercaseStartingLetters(spawner.getSpawnedType().toString()); meta.setDisplayName(plugin.getConfigurationHandler().getMessage("global", "name").replace("%mob%", mobFormatted)); List<String> newLore = new ArrayList<>(); if (plugin.getConfigurationHandler().getList("global", "lore") != null && plugin.getConfigurationHandler().getBoolean("global", "lore-enabled")) { for (String line : plugin.getConfigurationHandler().getList("global", "lore")) { newLore.add(Chat.format(line).replace("%mob%", mobFormatted)); } meta.setLore(newLore); } item.setItemMeta(meta); item = plugin.getNmsHandler().setType(item, spawner.getSpawnedType()); block.getLocation().getWorld().dropItemNaturally(block.getLocation(), item); } }
Example 17
Source File: BrewingStandContainer.java From Transport-Pipes with MIT License | 4 votes |
public BrewingStandContainer(Block block) { super(block); this.chunk = block.getChunk(); this.cachedBrewingStand = (BrewingStand) block.getState(); this.cachedInv = cachedBrewingStand.getInventory(); }
Example 18
Source File: ContainerManager.java From RedProtect with GNU General Public License v3.0 | 4 votes |
private boolean validateBreakSign(Block b, Player p) { Sign s = (Sign) b.getState(); return validatePrivateSign(b) && (s.getLine(1).isEmpty() || s.getLine(1).equals(p.getName())); }
Example 19
Source File: FutureBlockReplace.java From AnnihilationPro with MIT License | 4 votes |
public FutureBlockReplace(Block b, boolean cobble) { this.state = b.getState(); b.setType(cobble? Material.COBBLESTONE:Material.AIR); }
Example 20
Source File: Flag.java From PGM with GNU Affero General Public License v3.0 | 4 votes |
private static Banner toBanner(Block block) { if (block == null) return null; BlockState state = block.getState(); return state instanceof Banner ? (Banner) state : null; }