org.bukkit.event.world.StructureGrowEvent Java Examples

The following examples show how to use org.bukkit.event.world.StructureGrowEvent. 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: WorldListener.java    From BedWars with GNU Lesser General Public License v3.0 6 votes vote down vote up
@EventHandler
public void onStructureGrow(StructureGrowEvent event) {
    if (event.isCancelled()) {
        return;
    }

    for (String gameName : Main.getGameNames()) {
        Game game = Main.getGame(gameName);
        if (game.getStatus() == GameStatus.RUNNING || game.getStatus() == GameStatus.GAME_END_CELEBRATING) {
            if (GameCreator.isInArea(event.getLocation(), game.getPos1(), game.getPos2())) {
                event.setCancelled(true);
                return;
            }
        }
    }
}
 
Example #2
Source File: BlockEventHandler.java    From GriefDefender with MIT License 6 votes vote down vote up
@EventHandler(priority = EventPriority.LOWEST)
public void onStructureGrow(StructureGrowEvent event) {
    final World world = event.getLocation().getWorld();
    if (!GriefDefenderPlugin.getInstance().claimsEnabledForWorld(world.getUID())) {
        return;
    }

    for (BlockState blockstate : event.getBlocks()) {
        final Location location = blockstate.getLocation();
        final GDClaim targetClaim = this.storage.getClaimAt(location);

        if (targetClaim.isWilderness()) {
            continue;
        }

        final Tristate result = GDPermissionManager.getInstance().getFinalPermission(event, location, targetClaim, Flags.BLOCK_GROW, null, blockstate, event.getPlayer(), TrustTypes.BUILDER, true);
        if (result == Tristate.FALSE) {
            event.setCancelled(true);
            return;
        }
    }
}
 
Example #3
Source File: ShopProtectionListener.java    From QuickShop-Reremake with GNU General Public License v3.0 6 votes vote down vote up
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void onStructureGrow(StructureGrowEvent event) {
    if (!useEnhanceProtection) {
        return;
    }

    for (BlockState blockstate : event.getBlocks()) {
        final Shop shop = getShopNature(blockstate.getLocation(), true);

        if (shop == null) {
            continue;
        }

        event.setCancelled(true);
        return;
        // plugin.getLogger().warning("[Exploit Alert] a StructureGrowing tried to break the shop of "
        // + shop);
        // Util.sendMessageToOps(ChatColor.RED + "[QuickShop][Exploit alert] A StructureGrowing tried
        // to break the shop of " + shop);
    }
}
 
Example #4
Source File: WorldListener.java    From BedWars with GNU Lesser General Public License v3.0 6 votes vote down vote up
@EventHandler
public void onStructureGrow(StructureGrowEvent event) {
    if (event.isCancelled()) {
        return;
    }

    for (String gameName : Main.getGameNames()) {
        Game game = Main.getGame(gameName);
        if (game.getStatus() == GameStatus.RUNNING || game.getStatus() == GameStatus.GAME_END_CELEBRATING) {
            if (GameCreator.isInArea(event.getLocation(), game.getPos1(), game.getPos2())) {
                event.setCancelled(true);
                return;
            }
        }
    }
}
 
Example #5
Source File: LWCBlockListener.java    From Modern-LWC with MIT License 6 votes vote down vote up
@EventHandler
public void onStructureGrow(StructureGrowEvent event) {
    if (!LWC.ENABLED) {
        return;
    }

    LWC lwc = LWC.getInstance();
    // the blocks that were changed / replaced
    List<BlockState> blocks = event.getBlocks();

    for (BlockState block : blocks) {
        if (!lwc.isProtectable(block.getBlock())) {
            continue;
        }
        // we don't have the block id of the block before it
        // so we have to do some raw lookups (these are usually cache hits
        // however, at least!)
        Protection protection = lwc.getPhysicalDatabase().loadProtection(block.getWorld().getName(), block.getX(),
                block.getY(), block.getZ());
        if (protection != null) {
            event.setCancelled(true);
        }
    }
}
 
Example #6
Source File: BlockListener.java    From RedProtect with GNU General Public License v3.0 6 votes vote down vote up
@EventHandler(ignoreCancelled = true)
public void onStructureGrow(StructureGrowEvent e) {
    RedProtect.get().logger.debug(LogLevel.BLOCKS, "BlockListener - Is StructureGrowEvent event");
    if (!RedProtect.get().config.configRoot().region_settings.deny_structure_bypass_regions) {
        return;
    }
    Region rfrom = RedProtect.get().rm.getTopRegion(e.getLocation());
    for (BlockState bstt : e.getBlocks()) {
        Region rto = RedProtect.get().rm.getTopRegion(bstt.getLocation());
        Block bloc = bstt.getLocation().getBlock();
        //deny blocks spread in/out regions
        if (rfrom != null && rto != null && rfrom != rto && !rfrom.sameLeaders(rto)) {
            bstt.setType(bloc.getType());
        }
        if (rfrom == null && rto != null) {
            bstt.setType(bloc.getType());
        }
        if (rfrom != null && rto == null) {
            bstt.setType(bloc.getType());
        }
        bstt.update();
    }
}
 
Example #7
Source File: NetherPortals.java    From askyblock with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Converts trees to gravel and glowstone
 * 
 * @param e - event
 */
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
public void onTreeGrow(final StructureGrowEvent e) {
    if (DEBUG)
        plugin.getLogger().info("DEBUG: " + e.getEventName());

    if (!Settings.netherTrees) {
        return;
    }
    if (!Settings.createNether || ASkyBlock.getNetherWorld() == null) {
        return;
    }
    // Check world
    if (!e.getLocation().getWorld().equals(ASkyBlock.getNetherWorld())) {
        return;
    }
    for (BlockState b : e.getBlocks()) {
        if (b.getType() == Material.LOG || b.getType() == Material.LOG_2) {
            b.setType(Material.GRAVEL);
        } else if (b.getType() == Material.LEAVES || b.getType() == Material.LEAVES_2) {
            b.setType(Material.GLOWSTONE);
        }
    }
}
 
Example #8
Source File: EntityLimits.java    From askyblock with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Prevents trees from growing outside of the protected area.
 *
 * @param e - event
 */
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
public void onTreeGrow(final StructureGrowEvent e) {
    if (DEBUG) {
        plugin.getLogger().info(e.getEventName());
    }
    // Check world
    if (!IslandGuard.inWorld(e.getLocation())) {
        return;
    }
    // Check if this is on an island
    Island island = plugin.getGrid().getIslandAt(e.getLocation());
    if (island == null || island.isSpawn()) {
        return;
    }
    Iterator<BlockState> it = e.getBlocks().iterator();
    while (it.hasNext()) {
        BlockState b = it.next();
        if (b.getType() == Material.LOG || b.getType() == Material.LOG_2
                || b.getType() == Material.LEAVES || b.getType() == Material.LEAVES_2) {
            if (!island.onIsland(b.getLocation())) {
                it.remove();
            }
        }
    }
}
 
Example #9
Source File: BlockTransformListener.java    From PGM with GNU Affero General Public License v3.0 5 votes vote down vote up
@EventWrapper
public void onStructureGrow(final StructureGrowEvent event) {
  for (BlockState block : event.getBlocks()) {
    this.callEvent(
        new BlockTransformEvent(event, block.getLocation().getBlock().getState(), block));
  }
}
 
Example #10
Source File: PlantsListener.java    From ExoticGarden with GNU General Public License v3.0 5 votes vote down vote up
@EventHandler
public void onGrow(StructureGrowEvent e) {
    if (PaperLib.isPaper()) {
        if (PaperLib.isChunkGenerated(e.getLocation())) {
            growStructure(e);
        } else {
            PaperLib.getChunkAtAsync(e.getLocation()).thenRun(() -> growStructure(e));
        }
    } else {
        if (!e.getLocation().getChunk().isLoaded()) {
            e.getLocation().getChunk().load();
        }
        growStructure(e);
    }
}
 
Example #11
Source File: BlockListener.java    From BedwarsRel with GNU General Public License v3.0 5 votes vote down vote up
@EventHandler(ignoreCancelled = true)
public void onStructureGrow(StructureGrowEvent grow) {

  Game game = BedwarsRel.getInstance().getGameManager().getGameByLocation(grow.getLocation());
  if (game == null) {
    return;
  }

  grow.setCancelled(true);
}
 
Example #12
Source File: ShopItemListener.java    From ShopChest with MIT License 5 votes vote down vote up
@EventHandler(priority = EventPriority.HIGH)
public void onStructureGrow(StructureGrowEvent e) {
    for (BlockState state : e.getBlocks()) {
        Block newBlock = state.getBlock();
        if (shopUtils.isShop(newBlock.getLocation()) || shopUtils.isShop(newBlock.getRelative(BlockFace.DOWN).getLocation())) {
            e.setCancelled(true);
        }
    }
}
 
Example #13
Source File: BukkitPlotListener.java    From PlotMe-Core with GNU General Public License v3.0 5 votes vote down vote up
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
public void onStructureGrow(StructureGrowEvent event) {
    BukkitWorld world = new BukkitWorld(event.getWorld());
    if (manager.isPlotWorld(world)) {
        for (int i = 0; i < event.getBlocks().size(); i++) {
            PlotId id = manager.getPlotId(BukkitUtil.adapt(event.getBlocks().get(i).getLocation()));
            if (id == null) {
                event.getBlocks().remove(i);
                i--;
            } else {
                event.setCancelled(api.isPlotLocked(id));
            }
        }
    }
}
 
Example #14
Source File: PlantsListener.java    From ExoticGarden with GNU General Public License v3.0 4 votes vote down vote up
private void growStructure(StructureGrowEvent e) {
    SlimefunItem item = BlockStorage.check(e.getLocation().getBlock());

    if (item != null) {
        e.setCancelled(true);
        for (Tree tree : ExoticGarden.getTrees()) {
            if (item.getID().equalsIgnoreCase(tree.getSapling())) {
                BlockStorage.clearBlockInfo(e.getLocation());
                Schematic.pasteSchematic(e.getLocation(), tree);
                return;
            }
        }

        for (Berry berry : ExoticGarden.getBerries()) {
            if (item.getID().equalsIgnoreCase(berry.toBush())) {
                switch (berry.getType()) {
                    case BUSH:
                        e.getLocation().getBlock().setType(Material.OAK_LEAVES);
                        break;
                    case ORE_PLANT:
                    case DOUBLE_PLANT:
                        Block blockAbove = e.getLocation().getBlock().getRelative(BlockFace.UP);
                        item = BlockStorage.check(blockAbove);
                        if (item != null) return;

                        if (!Tag.SAPLINGS.isTagged(blockAbove.getType()) && !Tag.LEAVES.isTagged(blockAbove.getType())) {
                            switch (blockAbove.getType()) {
                                case AIR:
                                case CAVE_AIR:
                                case SNOW:
                                    break;
                                default:
                                    return;
                            }
                        }

                        BlockStorage.store(blockAbove, berry.getItem());
                        e.getLocation().getBlock().setType(Material.OAK_LEAVES);
                        blockAbove.setType(Material.PLAYER_HEAD);
                        Rotatable rotatable = (Rotatable) blockAbove.getBlockData();
                        rotatable.setRotation(faces[ThreadLocalRandom.current().nextInt(faces.length)]);
                        blockAbove.setBlockData(rotatable);

                        SkullBlock.setFromHash(blockAbove, berry.getTexture());
                        break;
                    default:
                        e.getLocation().getBlock().setType(Material.PLAYER_HEAD);
                        Rotatable s = (Rotatable) e.getLocation().getBlock().getBlockData();
                        s.setRotation(faces[ThreadLocalRandom.current().nextInt(faces.length)]);
                        e.getLocation().getBlock().setBlockData(s);

                        SkullBlock.setFromHash(e.getLocation().getBlock(), berry.getTexture());
                        break;
                }

                BlockStorage._integrated_removeBlockInfo(e.getLocation(), false);
                BlockStorage.store(e.getLocation().getBlock(), berry.getItem());
                e.getWorld().playEffect(e.getLocation(), Effect.STEP_SOUND, Material.OAK_LEAVES);
                break;
            }
        }
    }
}