Java Code Examples for org.bukkit.event.entity.EntityChangeBlockEvent#getTo()

The following examples show how to use org.bukkit.event.entity.EntityChangeBlockEvent#getTo() . 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 5 votes vote down vote up
@EventHandler
public void onEntityChangeBlock(EntityChangeBlockEvent event) {
    if (event.isCancelled()) {
        return;
    }

    for (String gameName : Main.getGameNames()) {
        Game game = Main.getGame(gameName);
        if (GameCreator.isInArea(event.getBlock().getLocation(), game.getPos1(), game.getPos2())) {
            if (game.getStatus() == GameStatus.RUNNING || game.getStatus() == GameStatus.GAME_END_CELEBRATING) {
                if (event.getEntityType() == EntityType.FALLING_BLOCK
                        && game.getOriginalOrInheritedAllowBlockFalling()) {
                    if (event.getBlock().getType() != event.getTo()) {
                        if (!game.getRegion().isBlockAddedDuringGame(event.getBlock().getLocation())) {
                            if (event.getBlock().getType() != Material.AIR) {
                                game.getRegion().putOriginalBlock(event.getBlock().getLocation(),
                                        event.getBlock().getState());
                            }
                            game.getRegion().addBuiltDuringGame(event.getBlock().getLocation());
                        }
                    }
                    return; // allow block fall
                }
            }

            if (game.getStatus() != GameStatus.DISABLED) {
                event.setCancelled(true);
            }
        }
    }
}
 
Example 2
Source File: WorldListener.java    From BedWars with GNU Lesser General Public License v3.0 5 votes vote down vote up
@EventHandler
public void onEntityChangeBlock(EntityChangeBlockEvent event) {
    if (event.isCancelled()) {
        return;
    }

    for (String gameName : Main.getGameNames()) {
        Game game = Main.getGame(gameName);
        if (GameCreator.isInArea(event.getBlock().getLocation(), game.getPos1(), game.getPos2())) {
            if (game.getStatus() == GameStatus.RUNNING || game.getStatus() == GameStatus.GAME_END_CELEBRATING) {
                if (event.getEntityType() == EntityType.FALLING_BLOCK
                        && game.getOriginalOrInheritedAllowBlockFalling()) {
                    if (event.getBlock().getType() != event.getTo()) {
                        if (!game.getRegion().isBlockAddedDuringGame(event.getBlock().getLocation())) {
                            if (event.getBlock().getType() != Material.AIR) {
                                game.getRegion().putOriginalBlock(event.getBlock().getLocation(),
                                        event.getBlock().getState());
                            }
                            game.getRegion().addBuiltDuringGame(event.getBlock().getLocation());
                        }
                    }
                    return; // allow block fall
                }
            }

            if (game.getStatus() != GameStatus.DISABLED) {
                event.setCancelled(true);
            }
        }
    }
}
 
Example 3
Source File: BlockTransformListener.java    From ProjectAres with GNU Affero General Public License v3.0 5 votes vote down vote up
@EventWrapper
public void onEntityChangeBlock(final EntityChangeBlockEvent event) {
    // Igniting TNT with an arrow is already handled from the ExplosionPrimeEvent
    if(event.getEntity() instanceof Arrow &&
       event.getBlock().getType() == Material.TNT &&
       event.getTo() == Material.AIR) return;

    callEvent(event, event.getBlock().getState(), BlockStateUtils.cloneWithMaterial(event.getBlock(), event.getToData()), entityResolver.getOwner(event.getEntity()));
}
 
Example 4
Source File: PlayerEvents.java    From uSkyBlock with GNU General Public License v3.0 5 votes vote down vote up
@EventHandler
public void onLavaAbsorption(EntityChangeBlockEvent event) {
    if (!plugin.getWorldManager().isSkyWorld(event.getBlock().getWorld())) {
        return;
    }
    if (isLavaSource(event.getBlock().getBlockData())) {
        if (event.getTo() != Material.LAVA) {
            event.setCancelled(true);
            // TODO: R4zorax - 21-07-2018: missing datavalue (might convert stuff - exploit)
            ItemStack item = new ItemStack(event.getTo(), 1);
            Location above = event.getBlock().getLocation().add(0, 1, 0);
            event.getBlock().getWorld().dropItemNaturally(above, item);
        }
    }
}