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

The following examples show how to use org.bukkit.event.entity.EntityChangeBlockEvent#getEntityType() . 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: FlyingMobEvents.java    From askyblock with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Withers change blocks to air after they are hit (don't know why)
 * This prevents this when the wither has been spawned by a visitor
 * @param e - event
 */
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
public void WitherChangeBlocks(final EntityChangeBlockEvent e) {
    if (DEBUG) {
        plugin.getLogger().info(e.getEventName());
    }
    // Only cover withers in the island world
    if (e.getEntityType() != EntityType.WITHER || !IslandGuard.inWorld(e.getEntity()) ) {
        return;
    }
    if (mobSpawnInfo.containsKey(e.getEntity())) {
        // We know about this wither
        if (DEBUG) {
            plugin.getLogger().info("DEBUG: We know about this wither");
        }
        if (!mobSpawnInfo.get(e.getEntity()).inIslandSpace(e.getEntity().getLocation())) {
            // Cancel the block changes
            if (DEBUG) {
                plugin.getLogger().info("DEBUG: cancelled wither block change");
            }
            e.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: 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 4
Source File: ChunkListener.java    From FastAsyncWorldedit with GNU General Public License v3.0 5 votes vote down vote up
@EventHandler(priority = EventPriority.LOWEST)
public void onBlockChange(EntityChangeBlockEvent event) {
    if (physicsFreeze) {
        event.setCancelled(true);
        return;
    }
    Block block = event.getBlock();
    int x = block.getX();
    int z = block.getZ();
    int cx = x >> 4;
    int cz = z >> 4;
    int[] count = getCount(cx, cz);
    if (count[1] >= Settings.IMP.TICK_LIMITER.FALLING) {
        event.setCancelled(true);
        return;
    }
    if (event.getEntityType() == EntityType.FALLING_BLOCK) {
        if (++count[1] >= Settings.IMP.TICK_LIMITER.FALLING) {

            // Only cancel falling blocks when it's lagging
            if (Fawe.get().getTimer().getTPS() < 18) {
                cancelNearby(cx, cz);
                if (rateLimit <= 0) {
                    rateLimit = 20;
                    Fawe.debug("[FAWE `tick-limiter`] Detected and cancelled falling block lag source at " + block.getLocation());
                }
                event.setCancelled(true);
                return;
            } else {
                count[1] = 0;
            }
        }
    }
}
 
Example 5
Source File: FlagAnvilSpleef.java    From HeavySpleef with GNU General Public License v3.0 5 votes vote down vote up
@SuppressWarnings("deprecation")
@EventHandler
public void onEntityChangeBlockEvent(EntityChangeBlockEvent e) {
	EntityType type = e.getEntityType();
	if (type != EntityType.FALLING_BLOCK) {
		return;
	}
	
	Entity entity = e.getEntity();
	if (!fallingAnvils.contains(entity)) {
		return;
	}
	
	Block block = e.getBlock();
	Block under = block.getRelative(BlockFace.DOWN);
	
	fallingAnvils.remove(entity);
	e.setCancelled(true);		
	
	if (!game.canSpleef(under)) {
		entity.remove();
		return;
	}
	
	Material material = under.getType();
	under.setType(Material.AIR);
	World world = under.getWorld();

       Sound anvilLandSound = Game.getSoundEnumType("ANVIL_LAND");
       if (anvilLandSound != null) {
           world.playSound(block.getLocation(), anvilLandSound, 1.0f, 1.0f);
       }
	
	if (game.getPropertyValue(GameProperty.PLAY_BLOCK_BREAK)) {
		world.playEffect(under.getLocation(), Effect.STEP_SOUND, material.getId());
	}
}
 
Example 6
Source File: BlockPhysics.java    From FunnyGuilds with Apache License 2.0 4 votes vote down vote up
@EventHandler
public void onFall(EntityChangeBlockEvent event) {
    if (event.getEntityType() == EntityType.FALLING_BLOCK && GuildHeartProtectionHandler.isGuildHeart(event.getBlock())) {
        event.setCancelled(true);
    }
}