private Location getSafeLocation(Location loc) { int blockY = loc.getBlockY(); World world = loc.getWorld(); if (blockY > world.getHighestBlockYAt(loc)) { blockY = world.getHighestBlockYAt(loc) + 1; Block current = world.getBlockAt(loc.getBlockX(), blockY, loc.getBlockZ()); if (current.isEmpty() && current.getRelative(BlockFace.UP).isEmpty()) { hadSpace = true; } else if (hadSpace) { if (current.getType().isSolid()) { found = true; blockY++;
private void placeBoat(GlowPlayer player, ItemStack holding) { Block targetBlock = player.getTargetBlock((Set<Material>) null, 5); if (targetBlock != null && !targetBlock.isEmpty() && targetBlock.getRelative(BlockFace.UP).isEmpty()) { Location location = targetBlock.getRelative(BlockFace.UP).getLocation(); // center boat on cursor location location.add(0.6875f, 0, 0.6875f); location.setYaw(player.getLocation().getYaw()); Boat boat = targetBlock.getWorld().spawn(location, Boat.class); boat.setWoodType(woodType); if (player.getGameMode() != GameMode.CREATIVE) { player.getInventory().removeItem(holding); } } }
@Override public boolean generate(World world, Random random, int blockX, int blockY, int blockZ) { Location l = new Location(world, blockX, blockY, blockZ); while ((l.getBlock().getType() == Material.AIR || l.getBlock().getType() == Material.LEAVES) && blockY > 0) { l.subtract(0, 1, 0); if (!canPlaceOn(l.getBlock().getRelative(BlockFace.DOWN).getState())) { return false; if ((Math.abs(x - l.getBlockX()) != radius || Math.abs(z - l.getBlockZ()) != radius || random.nextBoolean()) && !delegate.getBlockState(world, x, y, z).getType().isSolid()) { delegate .setTypeAndRawData(world, x, y, z, Material.LEAVES, leavesType);
private boolean isNearWater(Block block) { for (BlockFace face : SIDES) { switch (block.getRelative(face).getType()) { case WATER: case STATIONARY_WATER: return true; default: break; } } return false; }
@EventHandler(priority=EventPriority.MONITOR, ignoreCancelled=true) public void onLeavesDecay(LeavesDecayEvent event) { Location loc = event.getBlock().getLocation(); String wn = getWorld(loc.getWorld()).getName(); sscache.invalidateSnapshot(wn, loc.getBlockX(), loc.getBlockY(), loc.getBlockZ()); if(onleaves) { mapManager.touch(wn, loc.getBlockX(), loc.getBlockY(), loc.getBlockZ(), "leavesdecay"); } } };
@EventHandler(priority=EventPriority.MONITOR, ignoreCancelled=true) public void onBlockBreak(BlockBreakEvent evt) { Block b = evt.getBlock(); if(b == null) return; /* Work around for stupid mods.... */ Location l = b.getLocation(); core.listenerManager.processBlockEvent(EventType.BLOCK_BREAK, b.getType().getId(), getWorld(l.getWorld()).getName(), l.getBlockX(), l.getBlockY(), l.getBlockZ()); } }, DynmapPlugin.this);
@EventHandler(ignoreCancelled = true) public void onPlayerBucketEmpty(PlayerBucketEmptyEvent event) { Player player = event.getPlayer(); Block blockAffected = event.getBlockClicked().getRelative(event.getBlockFace()); boolean allowed = false; // Milk buckets can't be emptied as of writing if (event.getBucket() == Material.MILK_BUCKET) { allowed = true; } ItemStack item = new ItemStack(event.getBucket(), 1); Material blockMaterial = Materials.getBucketBlockMaterial(event.getBucket()); Events.fireToCancel(event, new PlaceBlockEvent(event, create(player), blockAffected.getLocation(), blockMaterial).setAllowed(allowed)); Events.fireToCancel(event, new UseItemEvent(event, create(player), player.getWorld(), item).setAllowed(allowed)); if (event.isCancelled()) { playDenyEffect(event.getPlayer(), blockAffected.getLocation().add(0.5, 0.5, 0.5)); } }
/** * Find a a Location obove or below the specified Location, which is on ground. * * <p>The returned Location will be at the center of the block, X and Y wise. * * @param spawn The Location a safe spawn position should be found at. * @return The location to spawn the player at. */ private static Location findSafeSpawnLocation(Location spawn) { World world = spawn.getWorld(); int blockX = spawn.getBlockX(); int blockY = spawn.getBlockY(); int blockZ = spawn.getBlockZ(); int highestY = world.getHighestBlockYAt(blockX, blockZ); int y = blockY; boolean wasPreviousSafe = false; for (; y <= highestY; y++) { Material type = world.getBlockAt(blockX, y, blockZ).getType(); boolean safe = Material.AIR.equals(type); if (wasPreviousSafe && safe) { y--; break; } wasPreviousSafe = safe; } return new Location(world, blockX + 0.5, y, blockZ + 0.5); }
: ((BlockCommandSender) sender).getBlock().getLocation(); final Entity[] entities = new CommandTarget(sender, args[0]).getMatched(location); targets = new ArrayList<>(); } else { currentLocation = sender instanceof Entity ? ((Entity) sender).getLocation() : ((BlockCommandSender) sender).getBlock().getLocation(); currentLocation = new Location(world, 0, 0, 0); if (CommandUtils.isPhysical(sender)) { spawnLocation = sender instanceof Entity ? ((Entity) sender).getLocation() : ((BlockCommandSender) sender).getBlock().getLocation(); } else { sender.sendMessage(ChatColor.RED target.setBedSpawnLocation(spawnLocation, true); sender.sendMessage("Set " + target.getName() + "'s spawn point to " + spawnLocation.getBlockX() + ", " + spawnLocation.getBlockY() + ", " + spawnLocation.getBlockZ() + ".");
@Override public boolean onBlockBreak(BlockBreakEvent e, ItemStack item, int fortune, List<ItemStack> drops) { if (SlimefunManager.isItemSimiliar(e.getPlayer().getInventory().getItemInMainHand(), SlimefunItems.PICKAXE_OF_VEIN_MINING, true)) { if (e.getBlock().getType().toString().endsWith("_ORE")) { List<Location> blocks = new ArrayList<Location>(); Vein.calculate(e.getBlock().getLocation(), e.getBlock().getLocation(), blocks, 16); for (Location block: blocks) { Block b = block.getBlock(); b.getWorld().playEffect(b.getLocation(), Effect.STEP_SOUND, b.getType()); for (ItemStack drop: b.getDrops()) { b.getWorld().dropItemNaturally(b.getLocation(), drop.getType().isBlock() ? drop: new CustomItem(drop, fortune)); } b.setType(Material.AIR); } } return true; } else return false; } });
@Override public boolean onBlockBreak(BlockBreakEvent e, ItemStack item, int fortune, List<ItemStack> drops) { if (SlimefunManager.isItemSimiliar(e.getPlayer().getInventory().getItemInMainHand(), SlimefunItems.PICKAXE_OF_CONTAINMENT, true)) { if (e.getBlock().getType() != Material.SPAWNER) return true; ItemStack spawner = SlimefunItems.BROKEN_SPAWNER.clone(); ItemMeta im = spawner.getItemMeta(); List<String> lore = im.getLore(); for (int i = 0; i < lore.size(); i++) { if (lore.get(i).contains("<Type>")) lore.set(i, lore.get(i).replace("<Type>", StringUtils.format(((CreatureSpawner) e.getBlock().getState()).getSpawnedType().toString()))); } im.setLore(lore); spawner.setItemMeta(im); e.getBlock().getLocation().getWorld().dropItemNaturally(e.getBlock().getLocation(), spawner); e.setExpToDrop(0); return true; } else return false; } });
@EventHandler(ignoreCancelled = true) public void onTelepathicCircuitPlace(BlockPlaceEvent event) { ItemStack is = event.getItemInHand(); if (!is.getType().equals(Material.DAYLIGHT_DETECTOR) || !is.hasItemMeta()) { return; } ItemMeta im = is.getItemMeta(); if (im.hasDisplayName() && im.getDisplayName().equals("TARDIS Telepathic Circuit")) { UUID uuid = event.getPlayer().getUniqueId(); String l = event.getBlock().getLocation().toString(); plugin.getTrackerKeeper().getTelepathicPlacements().put(uuid, l); } } }
@EventHandler(ignoreCancelled = true) public void onBlockPlace(BlockPlaceEvent event) { if (event instanceof BlockMultiPlaceEvent) return; BlockState previousState = event.getBlockReplacedState(); // Some blocks, like tall grass and fire, get replaced if (previousState.getType() != Material.AIR) { Events.fireToCancel(event, new BreakBlockEvent(event, create(event.getPlayer()), previousState.getLocation(), previousState.getType())); } if (!event.isCancelled()) { ItemStack itemStack = new ItemStack(event.getBlockPlaced().getType(), 1); Events.fireToCancel(event, new UseItemEvent(event, create(event.getPlayer()), event.getPlayer().getWorld(), itemStack)); } if (!event.isCancelled()) { Events.fireToCancel(event, new PlaceBlockEvent(event, create(event.getPlayer()), event.getBlock())); } if (event.isCancelled()) { playDenyEffect(event.getPlayer(), event.getBlockPlaced().getLocation().add(0.5, 0.5, 0.5)); } }
public void run() { BlockToCheck btt; while(blocks_to_check.isEmpty() != true) { btt = blocks_to_check.pop(); Location loc = btt.loc; World w = loc.getWorld(); if(!w.isChunkLoaded(loc.getBlockX()>>4, loc.getBlockZ()>>4)) continue; int bt = w.getBlockTypeIdAt(loc); /* Avoid stationary and moving water churn */ if(bt == 9) bt = 8; if(btt.typeid == 9) btt.typeid = 8; if((bt != btt.typeid) || (btt.data != w.getBlockAt(loc).getData())) { String wn = getWorld(w).getName(); sscache.invalidateSnapshot(wn, loc.getBlockX(), loc.getBlockY(), loc.getBlockZ()); mapManager.touch(wn, loc.getBlockX(), loc.getBlockY(), loc.getBlockZ(), btt.trigger); } } blocks_to_check = null; /* Kick next run, if one is needed */ startIfNeeded(); } public void startIfNeeded() {
public static void setBreaking(Block block, int breakAmount, int range) { String worldName = block.getWorld().getName(); Location location = block.getLocation(); int rangeSquared = range * range; for (Player player : Bukkit.getOnlinePlayers()) { if (!player.getWorld().getName().equals(worldName) || player.getLocation().distanceSquared(location) > rangeSquared) { continue; } sendBreaking(player, getBlockEntityId(block), location, breakAmount); } }
@EventHandler public void onPlace(BlockPlaceEvent e) { if (ProtectionSystem.build(e.getPlayer(), e.getBlock().getLocation(), true)) { if (config.buggedBlocks && !config.buggedBlocksExclude.contains(e.getBlock().getType())) { ItemStack returnItem = e.getItemInHand().clone(); returnItem.setAmount(1); Bukkit.getScheduler().runTaskLater(FunnyGuilds.getInstance(), () -> { e.getBlockReplacedState().update(true); if (config.buggedBlockReturn) { e.getPlayer().getInventory().addItem(returnItem); } }, config.buggedBlocksTimer); return; } e.setCancelled(true); } }
@EventHandler void onPlayerBucketFill(PlayerBucketFillEvent event) { Player p = event.getPlayer(); if (!bitQuest.canBuild(event.getBlockClicked().getLocation(), event.getPlayer())) { p.sendMessage(ChatColor.DARK_RED + "You don't have permission to do that!"); event.setCancelled(true); } }
final Set<Material> blockedMaterials) { Map<Vector, Double> neighbors = new HashMap<>(); final Vector start = location.toVector(); final Material materialAt = location.getWorld().getBlockAt( neighbor.toLocation(location.getWorld())).getType(); if (materialAt.equals(Material.AIR) && location.getWorld().getBlockAt( neighbor.add(new Vector(0, -1, 0)).toLocation( location.getWorld())).getType().equals(Material.AIR)) { continue; if (materialAt.isSolid() && location.getWorld().getBlockAt( neighbor.add(new Vector(0, 1, 0)).toLocation( location.getWorld())).getType().isSolid()) { continue;