Java Code Examples for org.bukkit.block.BlockState#update()
The following examples show how to use
org.bukkit.block.BlockState#update() .
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: QuadCrateSession.java From Crazy-Crates with MIT License | 6 votes |
private void rotateChest(Block chest, Integer direction) { BlockFace blockFace; switch (direction) { case 0://East blockFace = BlockFace.WEST; break; case 1://South blockFace = BlockFace.NORTH; break; case 2://West blockFace = BlockFace.EAST; break; case 3://North blockFace = BlockFace.SOUTH; break; default: blockFace = BlockFace.DOWN; break; } BlockState state = chest.getState(); state.setData(new Chest(blockFace)); state.update(); }
Example 2
Source File: BlockGrowListener.java From IridiumSkyblock with GNU General Public License v2.0 | 6 votes |
@EventHandler public void onBlockGrow(BlockGrowEvent event) { try { final Block block = event.getBlock(); final Location location = block.getLocation(); final IslandManager islandManager = IridiumSkyblock.getIslandManager(); final Island island = islandManager.getIslandViaLocation(location); if (island == null) return; if (island.getFarmingBooster() == 0) return; final Material material = block.getType(); if (!XBlock.isCrops(material)) return; event.setCancelled(true); final Crops crops = new Crops(CropState.RIPE); final BlockState blockState = block.getState(); blockState.setData(crops); blockState.update(); } catch (Exception e) { IridiumSkyblock.getInstance().sendErrorMessage(e); } }
Example 3
Source File: DoorEvent.java From BetonQuest with GNU General Public License v3.0 | 6 votes |
@Override protected Void execute(String playerID) throws QuestRuntimeException { Block block = loc.getLocation(playerID).getBlock(); BlockState state = block.getState(); MaterialData data = state.getData(); if (data instanceof Openable) { Openable openable = (Openable) data; switch (type) { case ON: openable.setOpen(true); break; case OFF: openable.setOpen(false); break; case TOGGLE: openable.setOpen(!openable.isOpen()); break; } state.setData((MaterialData) openable); state.update(); } return null; }
Example 4
Source File: XBlock.java From IridiumSkyblock with GNU General Public License v2.0 | 6 votes |
public static boolean setDirection(Block block, BlockFace facing) { if (XMaterial.ISFLAT) { if (!(block.getBlockData() instanceof Directional)) return false; Directional direction = (Directional) block.getBlockData(); direction.setFacing(facing); return true; } BlockState state = block.getState(); MaterialData data = state.getData(); if (data instanceof org.bukkit.material.Directional) { ((org.bukkit.material.Directional) data).setFacingDirection(facing); state.update(true); return true; } return false; }
Example 5
Source File: XBlock.java From XSeries with MIT License | 5 votes |
public static boolean setWooden(Block block, XMaterial species) { block.setType(species.parseMaterial()); if (ISFLAT) return true; TreeSpecies type = species == XMaterial.SPRUCE_LOG ? TreeSpecies.REDWOOD : TreeSpecies.valueOf(species.name().substring(0, species.name().indexOf('_'))); BlockState state = block.getState(); MaterialData data = state.getData(); ((Wood) data).setSpecies(type); state.update(true); return true; }
Example 6
Source File: BlockDropsMatchModule.java From ProjectAres with GNU Affero General Public License v3.0 | 5 votes |
private void replaceBlock(BlockDrops drops, Block block, MatchPlayer player) { if(drops.replacement != null) { EntityChangeBlockEvent event = new EntityChangeBlockEvent(player.getBukkit(), block, drops.replacement); getMatch().callEvent(event); if(!event.isCancelled()) { BlockState state = block.getState(); state.setType(drops.replacement.getItemType()); state.setData(drops.replacement); state.update(true, true); } } }
Example 7
Source File: CraftEventFactory.java From Thermos with GNU General Public License v3.0 | 5 votes |
public static void handleBlockSpreadEvent(Block block, Block source, net.minecraft.block.Block type, int data) { BlockState state = block.getState(); state.setTypeId(net.minecraft.block.Block.getIdFromBlock(type)); state.setRawData((byte) data); BlockSpreadEvent event = new BlockSpreadEvent(block, source, state); Bukkit.getPluginManager().callEvent(event); if (!event.isCancelled()) { state.update(true); } }
Example 8
Source File: CraftEventFactory.java From Kettle with GNU General Public License v3.0 | 5 votes |
public static boolean handleBlockFormEvent(World world, BlockPos pos, IBlockState block, @Nullable Entity entity) { BlockState blockState = world.getWorld().getBlockAt(pos.getX(), pos.getY(), pos.getZ()).getState(); blockState.setType(CraftMagicNumbers.getMaterial(block.getBlock())); blockState.setRawData((byte) block.getBlock().getMetaFromState(block)); BlockFormEvent event = (entity == null) ? new BlockFormEvent(blockState.getBlock(), blockState) : new EntityBlockFormEvent(entity.getBukkitEntity(), blockState.getBlock(), blockState); world.getServer().getPluginManager().callEvent(event); if (!event.isCancelled()) { blockState.update(true); } return !event.isCancelled(); }
Example 9
Source File: FallingBlocksMatchModule.java From PGM with GNU Affero General Public License v3.0 | 5 votes |
@SuppressWarnings("deprecation") private void fall(long pos, @Nullable ParticipantState breaker) { // Block must be removed BEFORE spawning the FallingBlock, or it will not appear on the client // https://bugs.mojang.com/browse/MC-72248 Block block = blockAt(match.getWorld(), pos); BlockState oldState = block.getState(); block.setType(Material.AIR, false); FallingBlock fallingBlock = block .getWorld() .spawnFallingBlock(block.getLocation(), oldState.getType(), oldState.getRawData()); BlockFallEvent event = new BlockFallEvent(block, fallingBlock); match.callEvent( breaker == null ? new BlockTransformEvent(event, block, Material.AIR) : new ParticipantBlockTransformEvent(event, block, Material.AIR, breaker)); if (event.isCancelled()) { fallingBlock.remove(); oldState.update(true, false); // Restore the old block if the fall is cancelled } else { block.setType( Material.AIR, true); // This is already air, but physics have not been applied yet, so do that now } }
Example 10
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 11
Source File: BlockAdapterMagicValues.java From DungeonsXL with GNU General Public License v3.0 | 5 votes |
@Override public void setFacing(Block block, BlockFace facing) { BlockState state = block.getState(); MaterialData data = state.getData(); if (!(data instanceof Directional)) { throw new IllegalArgumentException("Block is not Directional"); } ((Directional) data).setFacingDirection(facing); state.setData(data); state.update(); }
Example 12
Source File: VersionHelper113.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 13
Source File: BlockDataService.java From Slimefun4 with GNU General Public License v3.0 | 5 votes |
/** * This will store the given {@link String} inside the NBT data of the given {@link Block} * * @param b * The {@link Block} in which to store the given value * @param value * The value to store */ public void setBlockData(Block b, String value) { BlockState state = b.getState(); if (state instanceof TileState) { setString((TileState) state, namespacedKey, value); state.update(); } }
Example 14
Source File: XBlock.java From XSeries with MIT License | 5 votes |
public static void setAge(Block block, int age) { if (ISFLAT) { if (!(block.getBlockData() instanceof Ageable)) return; Ageable ageable = (Ageable) block.getBlockData(); ageable.setAge(age); } BlockState state = block.getState(); MaterialData data = state.getData(); data.setData((byte) age); state.update(true); }
Example 15
Source File: VersionHelper112.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(); op.setOpen(!op.isOpen()); state.setData(op); state.update(); } }
Example 16
Source File: XBlock.java From IridiumSkyblock with GNU General Public License v2.0 | 5 votes |
public static boolean setWooden(Block block, XMaterial species) { block.setType(species.parseMaterial()); if (XMaterial.ISFLAT) return true; TreeSpecies type = species == XMaterial.SPRUCE_LOG ? TreeSpecies.REDWOOD : TreeSpecies.valueOf(species.name().substring(0, species.name().indexOf('_'))); BlockState state = block.getState(); MaterialData data = state.getData(); ((Wood) data).setSpecies(type); state.update(true); return true; }
Example 17
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 18
Source File: XBlock.java From IridiumSkyblock with GNU General Public License v2.0 | 5 votes |
public static void setAge(Block block, int age) { if (XMaterial.ISFLAT) { if (!(block.getBlockData() instanceof Ageable)) return; Ageable ageable = (Ageable) block.getBlockData(); ageable.setAge(age); } BlockState state = block.getState(); MaterialData data = state.getData(); data.setData((byte) age); state.update(true); }
Example 19
Source File: BlockFire.java From Carbon with GNU Lesser General Public License v3.0 | 4 votes |
@SuppressWarnings("deprecation") @Override public void a(World world, int i, int j, int k, Random random) { if(world.getGameRules().getBoolean("doFireTick")) { boolean flag = world.getType(i, j - 1, k) == Blocks.NETHERRACK; if(((world.worldProvider instanceof WorldProviderTheEnd)) && (world.getType(i, j - 1, k) == Blocks.BEDROCK)) { flag = true; } if(!canPlace(world, i, j, k)) { fireExtinguished(world, i, j, k); } if((!flag) && (world.Q()) && ((world.isRainingAt(i, j, k)) || (world.isRainingAt(i - 1, j, k)) || (world.isRainingAt(i + 1, j, k)) || (world.isRainingAt(i, j, k - 1)) || (world.isRainingAt(i, j, k + 1)))) { fireExtinguished(world, i, j, k); } else { int l = world.getData(i, j, k); if(l < 15) { world.setData(i, j, k, l + random.nextInt(3) / 2, 4); } world.a(i, j, k, this, a(world) + random.nextInt(10)); if((!flag) && (!e(world, i, j, k))) { if((!World.a(world, i, j - 1, k)) || (l > 3)) { fireExtinguished(world, i, j, k); } } else if((!flag) && (!e(world, i, j - 1, k)) && (l == 15) && (random.nextInt(4) == 0)) { fireExtinguished(world, i, j, k); } else { boolean flag1 = world.z(i, j, k); byte b0 = 0; if(flag1) { b0 = -50; } a(world, i + 1, j, k, 300 + b0, random, l); a(world, i - 1, j, k, 300 + b0, random, l); a(world, i, j - 1, k, 250 + b0, random, l); a(world, i, j + 1, k, 250 + b0, random, l); a(world, i, j, k - 1, 300 + b0, random, l); a(world, i, j, k + 1, 300 + b0, random, l); for(int i1 = i - 1; i1 <= i + 1; i1++) { for(int j1 = k - 1; j1 <= k + 1; j1++) { for(int k1 = j - 1; k1 <= j + 4; k1++) { if((i1 != i) || (k1 != j) || (j1 != k)) { int l1 = 100; if(k1 > j + 1) { l1 += (k1 - (j + 1)) * 100; } int i2 = m(world, i1, k1, j1); if(i2 > 0) { int j2 = (i2 + 40 + world.difficulty.a() * 7) / (l + 30); if(flag1) { j2 /= 2; } if((j2 > 0) && (random.nextInt(l1) <= j2) && ((!world.Q()) || (!world.isRainingAt(i1, k1, j1))) && (!world.isRainingAt(i1 - 1, k1, k)) && (!world.isRainingAt(i1 + 1, k1, j1)) && (!world.isRainingAt(i1, k1, j1 - 1)) && (!world.isRainingAt(i1, k1, j1 + 1))) { int k2 = l + random.nextInt(5) / 4; if(k2 > 15) { k2 = 15; } if((world.getType(i1, k1, j1) != this) && (!CraftEventFactory.callBlockIgniteEvent(world, i1, k1, j1, i, j, k).isCancelled())) { Server server = world.getServer(); org.bukkit.World bworld = world.getWorld(); BlockState blockState = bworld.getBlockAt(i1, k1, j1).getState(); blockState.setTypeId(Block.getId(this)); blockState.setData(new MaterialData(Block.getId(this), (byte) k2)); BlockSpreadEvent spreadEvent = new BlockSpreadEvent(blockState.getBlock(), bworld.getBlockAt(i, j, k), blockState); server.getPluginManager().callEvent(spreadEvent); if(!spreadEvent.isCancelled()) { blockState.update(true); } } } } } } } } } } } }
Example 20
Source File: ShopManager.java From QuickShop-Reremake with GNU General Public License v3.0 | 4 votes |
/** * Create a shop use Shop and Info object. * * @param shop The shop object * @param info The info object */ public void createShop(@NotNull Shop shop, @NotNull Info info) { Player player = Bukkit.getPlayer(shop.getOwner()); if (player == null) { throw new IllegalStateException("The owner creating the shop is offline or not exist"); } ShopCreateEvent shopCreateEvent = new ShopCreateEvent(shop, player); if (Util.fireCancellableEvent(shopCreateEvent)) { Util.debugLog("Cancelled by plugin"); return; } if (info.getSignBlock() != null && autoSign) { if (Util.isAir(info.getSignBlock().getType()) || info.getSignBlock().getType() == Material.WATER) { info.getSignBlock().setType(Util.getSignMaterial()); BlockState bs = info.getSignBlock().getState(); if (info.getSignBlock().getType() == Material.WATER && (bs.getBlockData() instanceof Waterlogged)) { Waterlogged waterable = (Waterlogged) bs.getBlockData(); waterable.setWaterlogged(true); // Looks like sign directly put in water } if (bs.getBlockData() instanceof WallSign) { WallSign signBlockDataType = (WallSign) bs.getBlockData(); BlockFace bf = info.getLocation().getBlock().getFace(info.getSignBlock()); if (bf != null) { signBlockDataType.setFacing(bf); bs.setBlockData(signBlockDataType); } } else { plugin.getLogger().warning("Sign material " + bs.getType().name() + " not a WallSign, make sure you using correct sign material."); } bs.update(true); } else { if (!plugin.getConfig().getBoolean("shop.allow-shop-without-space-for-sign")) { MsgUtil.sendMessage(player, MsgUtil.getMessage("failed-to-put-sign", player)); Util.debugLog("Sign cannot placed cause no enough space(Not air block)"); return; } } } //load the shop finally shop.onLoad(); //first init shop.setSignText(); //sync add to prevent compete issue addShop(shop.getLocation().getWorld().getName(), shop); //save to database plugin.getDatabaseHelper().createShop( shop, null, e -> Bukkit.getScheduler().runTask(plugin, () -> { //also remove from memory when failed shop.delete(true); plugin.getLogger().warning("Shop create failed, trying to auto fix the database..."); boolean backupSuccess = Util.backupDatabase(); if (backupSuccess) { plugin.getDatabaseHelper().removeShop(shop); } else { plugin.getLogger().warning("Failed to backup the database, all changes will revert after a reboot."); } })); }