Java Code Examples for org.bukkit.block.Block#getLocation()

The following examples show how to use org.bukkit.block.Block#getLocation() . 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: PlantsListener.java    From ExoticGarden with GNU General Public License v3.0 6 votes vote down vote up
private void dropFruitFromTree(Block block) {
    for (int x = -1; x < 2; x++) {
        for (int y = -1; y < 2; y++) {
            for (int z = -1; z < 2; z++) {
                // inspect a cube at the reference
                Block fruit = block.getRelative(x, y, z);
                if (fruit.isEmpty()) continue;

                Location loc = fruit.getLocation();
                SlimefunItem check = BlockStorage.check(loc);
                if (check == null) continue;

                for (Tree tree : ExoticGarden.getTrees()) {
                    if (check.getID().equalsIgnoreCase(tree.getFruitID())) {
                        BlockStorage.clearBlockInfo(loc);
                        ItemStack fruits = check.getItem();
                        fruit.getWorld().playEffect(loc, Effect.STEP_SOUND, Material.OAK_LEAVES);
                        fruit.getWorld().dropItemNaturally(loc, fruits);
                        fruit.setType(Material.AIR);
                        break;
                    }
                }
            }
        }
    }
}
 
Example 2
Source File: Main.java    From ArmorStandTools with MIT License 6 votes vote down vote up
boolean checkBlockPermission(Player p, Block b) {
    if(b == null) return true;
    debug("PlotSquaredHook.api: " + PlotSquaredHook.api);
    if (PlotSquaredHook.api != null) {
        Location l = b.getLocation();
        debug("PlotSquaredHook.isPlotWorld(l): " + PlotSquaredHook.isPlotWorld(l));
        if(PlotSquaredHook.isPlotWorld(l)) {
            return PlotSquaredHook.checkPermission(p, l);
        }
    }
    if(Config.worldGuardPlugin != null) {
        if(!Utils.hasPermissionNode(p, "astools.bypass-wg-flag") && !getWorldGuardAstFlag(b.getLocation())) {
            return false;
        }
        return Config.worldGuardPlugin.createProtectionQuery().testBlockBreak(p, b);
    }
    BlockBreakEvent breakEvent = new BlockBreakEvent(b, p);
    Bukkit.getServer().getPluginManager().callEvent(breakEvent);
    return !breakEvent.isCancelled();
}
 
Example 3
Source File: SpleefTracker.java    From CardinalPGM with MIT License 6 votes vote down vote up
@EventHandler(priority = EventPriority.MONITOR)
public void onEntityExplode(EntityExplodeEvent event) {
    if (event.isCancelled() || GameHandler.getGameHandler().getMatch().getModules().getModule(TitleRespawn.class).isDeadUUID(event.getEntity().getUniqueId())) return;
    for (Block block : event.blockList()) {
        for (Player player : Bukkit.getOnlinePlayers()) {
            Location location = block.getLocation();
            location.setY(location.getY() + 1);
            Location playerLoc = player.getLocation();
            if (playerLoc.getBlockX() == location.getBlockX() && playerLoc.getBlockY() == location.getBlockY() && playerLoc.getBlockZ() == location.getBlockZ()) {
                Description description = null;
                if (player.getLocation().add(new Vector(0, 1, 0)).getBlock().getType().equals(Material.LADDER)) {
                    description = Description.OFF_A_LADDER;
                } else if (player.getLocation().add(new Vector(0, 1, 0)).getBlock().getType().equals(Material.VINE)) {
                    description = Description.OFF_A_VINE;
                } else if (player.getLocation().getBlock().getType().equals(Material.WATER) || player.getLocation().getBlock().getType().equals(Material.STATIONARY_WATER)) {
                    description = Description.OUT_OF_THE_WATER;
                } else if (player.getLocation().getBlock().getType().equals(Material.LAVA) || player.getLocation().getBlock().getType().equals(Material.STATIONARY_LAVA)) {
                    description = Description.OUT_OF_THE_LAVA;
                }
                OfflinePlayer damager = (TntTracker.getWhoPlaced(event.getEntity()) != null ? Bukkit.getOfflinePlayer(TntTracker.getWhoPlaced(event.getEntity())) : null);
                Bukkit.getServer().getPluginManager().callEvent(new TrackerDamageEvent(player, damager, damager != null && damager.getPlayer() != null ? ((Player) damager).getInventory().getItemInMainHand() : new ItemStack(Material.AIR), Cause.TNT, description, Type.SPLEEFED));
            }
        }
    }
}
 
Example 4
Source File: HuntEffect.java    From Civs with GNU General Public License v3.0 6 votes vote down vote up
public static Location findNearbyLocationForTeleport(Location location, int radius, Player player) {
    int times = 0;
    Block targetBlock;
    do {
        times++;
        int xRadius = (int) (Math.random()*radius);
        if (Math.random() > .5) {
            xRadius = xRadius *-1;
        }
        int x = location.getBlockX() + xRadius;
        int zRadius = (int) ((Math.sqrt(radius*radius - xRadius*xRadius)));
        if (Math.random() > .5) {
            zRadius = zRadius *-1;
        }
        int z = location.getBlockZ() + zRadius;
        targetBlock = location.getWorld().getHighestBlockAt(x, z);
    } while (times < 5 && (targetBlock.getType() == Material.LAVA));

    if (times == 5) {
        return null;
    }


    return targetBlock.getLocation();
}
 
Example 5
Source File: CommonBlockEventHandler.java    From GriefDefender with MIT License 6 votes vote down vote up
public void handleBlockSpread(Event event, Block fromBlock, BlockState newState) {
    if (!GDFlags.BLOCK_SPREAD) {
        return;
    }

    final World world = fromBlock.getWorld();
    if (!GriefDefenderPlugin.getInstance().claimsEnabledForWorld(world.getUID())) {
        return;
    }

    final Location sourceLocation = fromBlock != null ? fromBlock.getLocation() : null;
    final GDPermissionUser user = CauseContextHelper.getEventUser(sourceLocation, PlayerTracker.Type.NOTIFIER);

    Location location = newState.getLocation();
    GDClaim targetClaim = this.storage.getClaimAt(location);

    final Tristate result = GDPermissionManager.getInstance().getFinalPermission(event, location, targetClaim, Flags.BLOCK_SPREAD, fromBlock, newState.getBlock().isEmpty() ? newState.getType() : newState, user, TrustTypes.BUILDER, true);
    if (result == Tristate.FALSE) {
        ((Cancellable) event).setCancelled(true);
    }
}
 
Example 6
Source File: SurgarCanePopulator.java    From UhcCore with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void populate(World world, Random random, Chunk chunk){
    for (int x = 1; x < 15; x++) {
        for (int z = 1; z < 15; z++) {
            Block block = world.getHighestBlockAt(chunk.getBlock(x, 0, z).getLocation());
            Block below = block.getRelative(BlockFace.DOWN);

            if (percentage > random.nextInt(100) && (below.getType() == Material.SAND || below.getType() == Material.GRASS)){

                Material water = UniversalMaterial.STATIONARY_WATER.getType();
                if (
                        below.getRelative(BlockFace.NORTH).getType() == water ||
                        below.getRelative(BlockFace.EAST).getType() == water ||
                        below.getRelative(BlockFace.SOUTH).getType() == water ||
                        below.getRelative(BlockFace.WEST).getType() == water
                ){
                    if (block.getType() == Material.AIR){
                        int height = random.nextInt(3)+1;
                        Location location = block.getLocation();
                        while (height > 0){
                            world.getBlockAt(location).setType(UniversalMaterial.SUGAR_CANE_BLOCK.getType());
                            location = location.add(0, 1, 0);
                            height--;
                        }
                    }
                }
            }
        }
    }
}
 
Example 7
Source File: NMSHandler.java    From SkyWarsReloaded with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void playEnderChestAction(Block block, boolean open) {
       Location location = block.getLocation();
       WorldServer world = ((CraftWorld) location.getWorld()).getHandle();
       BlockPosition position = new BlockPosition(location.getX(), location.getY(), location.getZ());
       TileEntityEnderChest ec = (TileEntityEnderChest) world.getTileEntity(position);
       world.playBlockAction(position, ec.w(), 1, open ? 1 : 0);
   }
 
Example 8
Source File: NMSHandler.java    From SkyWarsReloaded with GNU General Public License v3.0 5 votes vote down vote up
public void playEnderChestAction(Block block, boolean open) {
       Location location = block.getLocation();
       WorldServer world = ((CraftWorld) location.getWorld()).getHandle();
       BlockPosition position = new BlockPosition(location.getX(), location.getY(), location.getZ());
       TileEntityEnderChest ec = (TileEntityEnderChest) world.getTileEntity(position);
	if (ec != null) {
		world.playBlockAction(position, ec.getBlock(), 1, open ? 1 : 0);
	}
}
 
Example 9
Source File: GlobalListener.java    From RedProtect with GNU General Public License v3.0 5 votes vote down vote up
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
public void onEntityExplode(EntityExplodeEvent e) {
    List<Block> toRemove = new ArrayList<>();
    for (Block b : e.blockList()) {
        Location l = b.getLocation();
        Region r = RedProtect.get().rm.getTopRegion(l);
        if (r == null && !RedProtect.get().config.globalFlagsRoot().worlds.get(l.getWorld().getName()).entity_block_damage) {
            toRemove.add(b);
        }
    }
    if (!toRemove.isEmpty()) {
        e.blockList().removeAll(toRemove);
    }
}
 
Example 10
Source File: Compat19.java    From RedProtect with GNU General Public License v3.0 5 votes vote down vote up
@EventHandler(priority = EventPriority.LOW)
public void onPlayerInteract(PlayerInteractEvent event) {
    Player p = event.getPlayer();
    Block b = event.getClickedBlock();
    ItemStack itemInHand = event.getItem();

    Location l;

    if (b != null) {
        l = b.getLocation();
        RedProtect.get().logger.debug(LogLevel.DEFAULT, "PlayerListener - Is PlayerInteractEvent event. The block is " + b.getType().name());
    } else {
        l = p.getLocation();
    }

    if (RedProtect.get().tpWait.contains(p.getName())) {
        RedProtect.get().tpWait.remove(p.getName());
        RedProtect.get().lang.sendMessage(p, "cmdmanager.region.tpcancelled");
    }

    if (itemInHand != null && (event.getAction().name().equals("RIGHT_CLICK_BLOCK") || b == null)) {
        Material hand = itemInHand.getType();
        Region r = RedProtect.get().rm.getTopRegion(l);
        // Deny chorus teleport
        if (r != null && hand.equals(Material.CHORUS_FRUIT) && !r.canTeleport(p)) {
            RedProtect.get().lang.sendMessage(p, "playerlistener.region.cantuse");
            event.setCancelled(true);
            event.setUseItemInHand(Event.Result.DENY);
        }
        // Deny glide boost
        if (r == null && p.isGliding() && itemInHand.getType().name().contains("FIREWORK") && !p.hasPermission("redprotect.bypass.glide") &&
                !RedProtect.get().config.globalFlagsRoot().worlds.get(p.getWorld().getName()).player_glide.allow_boost) {
            event.setUseItemInHand(Event.Result.DENY);
            event.setCancelled(true);
            RedProtect.get().lang.sendMessage(p, "globallistener.elytra.cantboost");
        }
    }
}
 
Example 11
Source File: SpawnerPlaceListener.java    From MineableSpawners with MIT License 5 votes vote down vote up
private void handlePlacement(Player player, Block block, EntityType type, double cost) {
    CreatureSpawner spawner = (CreatureSpawner) block.getState();
    spawner.setSpawnedType(type);
    spawner.update();

    if (plugin.getConfigurationHandler().getBoolean("placing", "log")) {
        Location loc = block.getLocation();
        System.out.println("[MineableSpawners] Player " + player.getName() + " placed a " + type.name().toLowerCase() + " spawner at x:" + loc.getX() + ", y:" + loc.getY() + ", z:" + loc.getZ() + " (" + loc.getWorld().getName() + ")");
    }

    if (cost > 0) {
        player.sendMessage(plugin.getConfigurationHandler().getMessage("placing", "transaction-success").replace("%type%", Chat.uppercaseStartingLetters(type.name())).replace("%cost%", df.format(cost).replace("%balance%", df.format(plugin.getEcon().getBalance(player)))));
    }
}
 
Example 12
Source File: PlayerInteractListener.java    From IridiumSkyblock with GNU General Public License v2.0 4 votes vote down vote up
@EventHandler
public void onPlayerInteract(PlayerInteractEvent event) {
    try {
        final Player player = event.getPlayer();
        final Location playerLocation = player.getLocation();
        final IslandManager islandManager = IridiumSkyblock.getIslandManager();
        if (!islandManager.isIslandWorld(playerLocation)) return;

        final User user = User.getUser(player);
        final Block block = event.getClickedBlock();

        if (event.getAction().toString().startsWith("RIGHT_CLICK")) {
            if (player.getItemInHand() != null) {
                int crystals = Utils.getCrystals(player.getItemInHand()) * player.getItemInHand().getAmount();
                if (crystals != 0) {
                    player.setItemInHand(null);
                    user.getIsland().setCrystals(user.getIsland().getCrystals() + crystals);
                    player.sendMessage(Utils.color(IridiumSkyblock.getMessages().depositedCrystals.replace("%amount%", crystals + "").replace("%prefix%", IridiumSkyblock.getConfiguration().prefix)));
                }
            }
        }

        if (block != null) {
            final Location location = block.getLocation();
            final Island island = islandManager.getIslandViaLocation(location);
            if (island != null) {
                if (!island.getPermissions(user).interact) {
                    event.setCancelled(true);
                    return;
                }
                final ItemStack itemInHand = player.getItemInHand();
                if (itemInHand.getType().equals(Material.BUCKET) && island.failedGenerators.remove(location)) {
                    if (itemInHand.getAmount() == 1)
                        itemInHand.setType(Material.LAVA_BUCKET);
                    else {
                        player.getInventory().addItem(new ItemStack(Material.LAVA_BUCKET));
                        player.getItemInHand().setAmount(itemInHand.getAmount() - 1);
                    }
                    block.setType(Material.AIR);
                }
            } else if (!user.bypassing) {
                event.setCancelled(true);
                return;
            }
        }

        final ItemStack item = event.getItem();
        if (IridiumSkyblock.getConfiguration().allowWaterInNether
                && event.getAction().equals(Action.RIGHT_CLICK_BLOCK)
                && item != null
                && block != null) {
            final World world = block.getWorld();
            if (!world.getEnvironment().equals(World.Environment.NETHER)) return;
            if (!item.getType().equals(Material.WATER_BUCKET)) return;

            event.setCancelled(true);

            final BlockFace face = event.getBlockFace();
            block.getRelative(face).setType(Material.WATER);

            final Block relative = block.getRelative(face);
            final BlockPlaceEvent blockPlaceEvent = new BlockPlaceEvent(relative, relative.getState(), block, item, player, false);
            if (blockPlaceEvent.isCancelled()) {
                block.getRelative(face).setType(Material.AIR);
            } else if (player.getGameMode().equals(GameMode.SURVIVAL)) {
                if (item.getAmount() == 1) {
                    item.setType(Material.BUCKET);
                } else {
                    item.setAmount(item.getAmount() - 1);
                    player.getInventory().addItem(new ItemStack(Material.BUCKET));
                }
            }
        }
    } catch (Exception e) {
        IridiumSkyblock.getInstance().sendErrorMessage(e);
    }
}
 
Example 13
Source File: SignExtension.java    From HeavySpleef with GNU General Public License v3.0 4 votes vote down vote up
@EventHandler
public void onPlayerInteract(PlayerInteractEvent event) {
	Block clickedBlock = event.getClickedBlock();
	if (clickedBlock == null) {
		return;
	}
	
	if (clickedBlock.getType() != Material.SIGN_POST && clickedBlock.getType() != Material.WALL_SIGN) {
		return;
	}
	
	Location loc = clickedBlock.getLocation();
	if (!loc.equals(location)) {
		return;
	}
	
	SpleefPlayer player = getHeavySpleef().getSpleefPlayer(event.getPlayer());
	
	Action action = event.getAction();
	if (action == Action.LEFT_CLICK_BLOCK && player.getBukkitPlayer().getGameMode() == GameMode.CREATIVE) {
		return;
	}
	
	String[] permissions = getPermission();
	boolean hasPermission = false;
	
	for (String perm : permissions) {
		if (!player.hasPermission(perm)) {
			continue;
		}
		
		hasPermission = true;
	}
	
	if (!hasPermission) {
		player.sendMessage(i18n.getString(Messages.Command.NO_PERMISSION));
		return;
	}

	event.setCancelled(true);
	onSignClick(player);
}
 
Example 14
Source File: ChestProtectListener.java    From ShopChest with MIT License 4 votes vote down vote up
@EventHandler(ignoreCancelled = true)
public void onBlockPlace(BlockPlaceEvent e) {
    final Player p = e.getPlayer();
    final Block b = e.getBlockPlaced();

    if (!b.getType().equals(Material.CHEST) && !b.getType().equals(Material.TRAPPED_CHEST)) {
        return;
    }
    
    Chest c = (Chest) b.getState();
    Block b2;

    // Can't use Utils::getChestLocations since inventory holder
    // has not been updated yet in this event (for 1.13+)

    if (Utils.getMajorVersion() < 13) {
        InventoryHolder ih = c.getInventory().getHolder();
        if (!(ih instanceof DoubleChest)) {
            return;
        }

        DoubleChest dc = (DoubleChest) ih;
        Chest l = (Chest) dc.getLeftSide();
        Chest r = (Chest) dc.getRightSide();

        if (b.getLocation().equals(l.getLocation())) {
            b2 = r.getBlock();
        } else {
            b2 = l.getBlock();
        }
    } else {
        org.bukkit.block.data.type.Chest data = (org.bukkit.block.data.type.Chest) c.getBlockData();

        if (data.getType() == Type.SINGLE) {
            return;
        }

        BlockFace neighborFacing;

        switch (data.getFacing()) {
            case NORTH:
                neighborFacing = data.getType() == Type.LEFT ? BlockFace.EAST : BlockFace.WEST;
                break;
            case EAST:
                neighborFacing = data.getType() == Type.LEFT ? BlockFace.SOUTH : BlockFace.NORTH;
                break;
            case SOUTH:
                neighborFacing = data.getType() == Type.LEFT ? BlockFace.WEST : BlockFace.EAST;
                break;
            case WEST:
                neighborFacing = data.getType() == Type.LEFT ? BlockFace.NORTH : BlockFace.SOUTH;
                break;
            default:
                neighborFacing = null;
        }

        b2 = b.getRelative(neighborFacing);
    }

    final Shop shop = shopUtils.getShop(b2.getLocation());
    if (shop == null)
        return;

    plugin.debug(String.format("%s tries to extend %s's shop (#%d)", p.getName(), shop.getVendor().getName(), shop.getID()));

    ShopExtendEvent event = new ShopExtendEvent(p, shop, b.getLocation());
    Bukkit.getPluginManager().callEvent(event);
    if (event.isCancelled() && !p.hasPermission(Permissions.EXTEND_PROTECTED)) {
        e.setCancelled(true);
        p.sendMessage(LanguageUtils.getMessage(Message.NO_PERMISSION_EXTEND_PROTECTED));
        return;
    }

    if (!p.getUniqueId().equals(shop.getVendor().getUniqueId()) && !p.hasPermission(Permissions.EXTEND_OTHER)) {
        e.setCancelled(true);
        p.sendMessage(LanguageUtils.getMessage(Message.NO_PERMISSION_EXTEND_OTHERS));
        return;
    }

    if (!ItemUtils.isAir(b.getRelative(BlockFace.UP).getType())) {
        e.setCancelled(true);
        p.sendMessage(LanguageUtils.getMessage(Message.CHEST_BLOCKED));
        return;
    }

    final Shop newShop = new Shop(shop.getID(), plugin, shop.getVendor(), shop.getProduct(), shop.getLocation(), shop.getBuyPrice(), shop.getSellPrice(), shop.getShopType());

    shopUtils.removeShop(shop, true, new Callback<Void>(plugin) {
        @Override
        public void onResult(Void result) {
            newShop.create(true);
            shopUtils.addShop(newShop, true);
            plugin.debug(String.format("%s extended %s's shop (#%d)", p.getName(), shop.getVendor().getName(), shop.getID()));
        }
    });
}
 
Example 15
Source File: PlayerEventHandler.java    From GriefDefender with MIT License 4 votes vote down vote up
public void onPlayerBucketEvent(PlayerBucketEvent event) {
    final Player player = event.getPlayer();
    final Block clickedBlock = event.getBlockClicked();
    GDCauseStackManager.getInstance().pushCause(player);
    if (!GriefDefenderPlugin.getInstance().claimsEnabledForWorld(player.getWorld().getUID())) {
        return;
    }
    if (GriefDefenderPlugin.isTargetIdBlacklisted(Flags.INTERACT_BLOCK_SECONDARY.getName(), clickedBlock, player.getWorld().getUID())) {
        return;
    }

    GDTimings.PLAYER_INTERACT_BLOCK_SECONDARY_EVENT.startTiming();
    final Object source = player;
    final Location location = clickedBlock.getLocation();
    final GDClaim claim = this.dataStore.getClaimAt(location);
    final TrustType trustType = NMSUtil.getInstance().isTileInventory(location) || clickedBlock != null && clickedBlock.getType() == Material.ENDER_CHEST ? TrustTypes.CONTAINER : TrustTypes.ACCESSOR;

    Tristate result = GDPermissionManager.getInstance().getFinalPermission(event, location, claim, Flags.INTERACT_BLOCK_SECONDARY, source, clickedBlock, player, trustType, true);
    if (result == Tristate.FALSE) {
        event.setCancelled(true);
        GDTimings.PLAYER_INTERACT_BLOCK_SECONDARY_EVENT.stopTiming();
        return;
    }

    GDTimings.PLAYER_INTERACT_BLOCK_SECONDARY_EVENT.stopTiming();

    if (event instanceof PlayerBucketEmptyEvent) {
        // check block place
        result = GDPermissionManager.getInstance().getFinalPermission(event, location, claim, Flags.BLOCK_PLACE, source, event.getBucket().name().toLowerCase().replace("_bucket", ""), player, TrustTypes.BUILDER, true);
        if (result == Tristate.FALSE) {
            event.setCancelled(true);
            return;
        }
    } else if (event instanceof PlayerBucketFillEvent) {
        // check block break
        result = GDPermissionManager.getInstance().getFinalPermission(event, location, claim, Flags.BLOCK_BREAK, source, event.getBlockClicked(), player, TrustTypes.BUILDER, true);
        if (result == Tristate.FALSE) {
            event.setCancelled(true);
            return;
        }
    }
}
 
Example 16
Source File: EntityEventHandler.java    From GriefDefender with MIT License 4 votes vote down vote up
@EventHandler(priority = EventPriority.LOWEST)
public void onEntityExplodeEvent(EntityExplodeEvent event) {
    final World world = event.getEntity().getLocation().getWorld();
    if (!GDFlags.EXPLOSION_BLOCK || !GriefDefenderPlugin.getInstance().claimsEnabledForWorld(world.getUID())) {
        return;
    }

    GDCauseStackManager.getInstance().pushCause(event.getEntity());
    // check entity tracker
    final GDEntity gdEntity = EntityTracker.getCachedEntity(event.getEntity().getEntityId());
    GDPermissionUser user = null;
    if (gdEntity != null) {
        user = PermissionHolderCache.getInstance().getOrCreateUser(gdEntity.getOwnerUUID());
    }

    Entity source = event.getEntity();
    if (GriefDefenderPlugin.isSourceIdBlacklisted(Flags.EXPLOSION_BLOCK.toString(), source, world.getUID())) {
        return;
    }

    final String sourceId = GDPermissionManager.getInstance().getPermissionIdentifier(source);
    boolean denySurfaceExplosion = GriefDefenderPlugin.getActiveConfig(world.getUID()).getConfig().claim.explosionBlockSurfaceBlacklist.contains(sourceId);
    if (!denySurfaceExplosion) {
        denySurfaceExplosion = GriefDefenderPlugin.getActiveConfig(world.getUID()).getConfig().claim.explosionBlockSurfaceBlacklist.contains("any");
    }
    GDTimings.EXPLOSION_EVENT.startTiming();
    GDClaim targetClaim = null;
    final int cancelBlockLimit = GriefDefenderPlugin.getGlobalConfig().getConfig().claim.explosionCancelBlockLimit;
    final List<Block> filteredLocations = new ArrayList<>();
    for (Block block : event.blockList()) {
        final Location location = block.getLocation();
        targetClaim =  GriefDefenderPlugin.getInstance().dataStore.getClaimAt(location);
        if (denySurfaceExplosion && block.getWorld().getEnvironment() != Environment.NETHER && location.getBlockY() >= location.getWorld().getSeaLevel()) {
            filteredLocations.add(block);
            GDPermissionManager.getInstance().processEventLog(event, location, targetClaim, Flags.EXPLOSION_BLOCK.getPermission(), source, block, user, "explosion-surface", Tristate.FALSE);
            continue;
        }
        final Tristate result = GDPermissionManager.getInstance().getFinalPermission(event, location, targetClaim, Flags.EXPLOSION_BLOCK, source, block, user, true);
        if (result == Tristate.FALSE) {
            // Avoid lagging server from large explosions.
            if (event.blockList().size() > cancelBlockLimit) {
                event.setCancelled(true);
                break;
            }
            filteredLocations.add(block);
        }
    }

    if (event.isCancelled()) {
        event.blockList().clear();
    } else if (!filteredLocations.isEmpty()) {
        event.blockList().removeAll(filteredLocations);
    }
    GDTimings.EXPLOSION_EVENT.stopTiming();
}
 
Example 17
Source File: ExtensionLobbyWall.java    From HeavySpleef with GNU General Public License v3.0 4 votes vote down vote up
public static SignRow generateRow(Sign clicked) {
	Block block = clicked.getBlock();
	Location location = block.getLocation();
	Block attachedOn = getAttached(clicked);
	
	Location mod = attachedOn.getLocation().subtract(location);
	BlockFace2D dir = BlockFace2D.byVector2D(mod.getBlockX(), mod.getBlockZ());
	
	BlockFace2D leftDir = dir.left();
	BlockFace2D rightDir = dir.right();
	
	BlockFace leftFace = leftDir.getBlockFace3D();
	BlockFace rightFace = rightDir.getBlockFace3D();
	
	Location start = location;
	Block lastBlock = block;
	
	while (true) {
		Block leftBlock = lastBlock.getRelative(leftFace);
		if (leftBlock.getType() != Material.WALL_SIGN) {
			break;
		}
		
		lastBlock = leftBlock;
		start = leftBlock.getLocation();
	}
	
	Location end = location;
	lastBlock = block;
	
	while (true) {
		Block rightBlock = lastBlock.getRelative(rightFace);
		if (rightBlock.getType() != Material.WALL_SIGN) {
			break;
		}
		
		lastBlock = rightBlock;
		end = rightBlock.getLocation();
	}
	
	try {
		return new SignRow(clicked.getWorld(), start.toVector(), end.toVector());
	} catch (SignRowValidationException e) {
		throw new RuntimeException(e);
	}
}
 
Example 18
Source File: CreateTreeCommand.java    From GiantTrees with GNU General Public License v3.0 4 votes vote down vote up
@Override
public boolean onCommand(final CommandSender sender, final Command command,
                         final String label, final String[] arg) {
  if (sender instanceof ConsoleCommandSender) {
    sender.sendMessage("Cannot create giant trees from the console");
    return true;
  }

  if (arg.length != 1) {
    // incorrect number of arguments
    return false;
  }

  final Player player = (Player) sender;
  if (player.hasPermission("gianttrees.create")) {
    final Chunk chunk = player.getLocation().getChunk();
    final World world = chunk.getWorld();
    final Random seed = new Random(world.getSeed());

    final String species = arg[0];
    final File treeFile = new File(this.plugin.getDataFolder(), species
                                                                + ".xml");
    final File rootFile = new File(this.plugin.getDataFolder(), species
                                                                + ".root.xml");

    if (!treeFile.exists()) {
      sender.sendMessage(ChatColor.RED + "Tree " + species
                         + " does not exist.");
      sender.sendMessage("Use \"/tree-edit " + species
                         + "\" from the server console to create it.");
      return true;
    }

    final Block highestSoil = this.getHighestSoil(player.getWorld()
                                                        .getHighestBlockAt(player.getLocation()));

    final Location base = highestSoil.getLocation();
    this.popup.sendPopup(player, "Stand back!");
    this.renderer.renderTreeWithHistory(base, treeFile, rootFile,
                                        seed.nextInt(), player, true);
  }
  return true;
}
 
Example 19
Source File: BlockPlaceListener.java    From IridiumSkyblock with GNU General Public License v2.0 4 votes vote down vote up
@EventHandler
public void onBlockPlace(BlockPlaceEvent 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;

        final Player player = event.getPlayer();
        final User user = User.getUser(player);

        final Material material = block.getType();
        final XMaterial xmaterial = XMaterial.matchXMaterial(material);
        final Config config = IridiumSkyblock.getConfiguration();
        final Integer max = config.limitedBlocks.get(xmaterial);
        if (max != null) {
            if (island.valuableBlocks.getOrDefault(xmaterial.name(), 0) >= max) {
                player.sendMessage(Utils.color(IridiumSkyblock.getMessages().blockLimitReached
                        .replace("%prefix%", config.prefix)));
                event.setCancelled(true);
                return;
            }
        }

        if (user.islandID == island.getId()) {
            for (Mission mission : IridiumSkyblock.getMissions().missions) {
                final Map<String, Integer> levels = island.getMissionLevels();
                levels.putIfAbsent(mission.name, 1);

                final MissionData level = mission.levels.get(levels.get(mission.name));
                if (level == null) continue;
                if (level.type != MissionType.BLOCK_PLACE) continue;

                final List<String> conditions = level.conditions;

                if (
                        conditions.isEmpty()
                                ||
                                conditions.contains(xmaterial.name())
                                ||
                                conditions.contains(((Crops) block.getState().getData()).getState().toString())
                )
                    island.addMission(mission.name, 1);
            }
        }

        if (!island.getPermissions(user).placeBlocks)
            event.setCancelled(true);
    } catch (Exception e) {
        IridiumSkyblock.getInstance().sendErrorMessage(e);
    }
}
 
Example 20
Source File: ChunkWrapper.java    From ObsidianDestroyer with GNU General Public License v3.0 2 votes vote down vote up
/**
 * Adds a block with a timer to the chunk
 *
 * @param durability the damage done to the block
 * @param time       the time value of the block
 * @param block      the block to be added
 */
public void addBlockTimer(int durability, long time, Block block) {
    Key key = new Key(block.getLocation(), durability, time);
    durabilities.put(key.hashCode(), key);
}