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

The following examples show how to use org.bukkit.event.entity.EntityChangeBlockEvent#getEntity() . 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: IslandGuard.java    From askyblock with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Allows or prevents enderman griefing
 */
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
public void onEndermanGrief(final EntityChangeBlockEvent e) {
    if (DEBUG) {
        plugin.getLogger().info(e.getEventName());
    }
    if (!(e.getEntity() instanceof Enderman)) {
        return;
    }
    if (!inWorld(e.getEntity())) {
        return;
    }
    // Prevent Enderman griefing at spawn
    if (plugin.getGrid() != null && plugin.getGrid().isAtSpawn(e.getEntity().getLocation())) {
        e.setCancelled(true);
    }
    if (Settings.allowEndermanGriefing)
        return;
    // Stop the Enderman from griefing
    // plugin.getLogger().info("Enderman stopped from griefing);
    e.setCancelled(true);
}
 
Example 2
Source File: BukkitPlotListener.java    From PlotMe-Core with GNU General Public License v3.0 6 votes vote down vote up
@EventHandler(ignoreCancelled = true)
public void onSandCannon(EntityChangeBlockEvent event) {
    BukkitEntity entity = new BukkitEntity(event.getEntity());
    if (manager.isPlotWorld(entity) && event.getEntityType().equals(EntityType.FALLING_BLOCK)) {
        if (event.getTo().equals(Material.AIR)) {
            entity.setMetadata("plotFallBlock", new FixedMetadataValue(plugin, event.getBlock().getLocation()));
        } else {
            List<MetadataValue> values = entity.getMetadata("plotFallBlock");

            if (!values.isEmpty()) {

                org.bukkit.Location spawn = (org.bukkit.Location) (values.get(0).value());
                org.bukkit.Location createdNew = event.getBlock().getLocation();

                if (spawn.getBlockX() != createdNew.getBlockX() || spawn.getBlockZ() != createdNew.getBlockZ()) {
                    event.setCancelled(true);
                }
            }
        }
    }
}
 
Example 3
Source File: BlockEventTracker.java    From GriefDefender with MIT License 5 votes vote down vote up
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onBlockSpawnFalling(EntityChangeBlockEvent event) {
    final Entity entity = event.getEntity();
    if (entity instanceof FallingBlock) {
        final GDEntity gdEntity = EntityTracker.getCachedEntity(event.getEntity().getEntityId());
        if (gdEntity != null) {
            final GDPermissionUser user = PermissionHolderCache.getInstance().getOrCreateUser(gdEntity.getOwnerUUID());
            final GDClaimManager claimWorldManager = GriefDefenderPlugin.getInstance().dataStore.getClaimWorldManager(event.getBlock().getWorld().getUID());
            final GDChunk gdChunk = claimWorldManager.getChunk(event.getBlock().getChunk());
            gdChunk.addTrackedBlockPosition(event.getBlock(), user.getUniqueId(), PlayerTracker.Type.OWNER);
        }
    }
}
 
Example 4
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 5
Source File: BlockPhysicsListener.java    From Slimefun4 with GNU General Public License v3.0 5 votes vote down vote up
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
public void onBlockFall(EntityChangeBlockEvent e) {
    if (e.getEntity().getType() == EntityType.FALLING_BLOCK && BlockStorage.hasBlockInfo(e.getBlock())) {
        e.setCancelled(true);
        FallingBlock block = (FallingBlock) e.getEntity();

        if (block.getDropItem()) {
            block.getWorld().dropItemNaturally(block.getLocation(), new ItemStack(block.getBlockData().getMaterial(), 1));
        }
    }
}
 
Example 6
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 7
Source File: EntityEventHandler.java    From GriefDefender with MIT License 4 votes vote down vote up
@EventHandler(priority = EventPriority.LOWEST)
public void onEntityChangeBlockEvent(EntityChangeBlockEvent event) {
    if (!GDFlags.BLOCK_BREAK) {
        return;
    }

    final Block block = event.getBlock();
    if (block.isEmpty()) {
        return;
    }
    final World world = event.getBlock().getWorld();
    if (!GriefDefenderPlugin.getInstance().claimsEnabledForWorld(world.getUID())) {
        return;
    }

    final Location location = block.getLocation();
    final GDClaim targetClaim = this.baseStorage.getClaimAt(location);

    final Entity source = event.getEntity();
    GDPermissionUser user = null;
    if (source instanceof Tameable) {
        final UUID uuid = NMSUtil.getInstance().getTameableOwnerUUID(source);
        if (uuid != null) {
            user = PermissionHolderCache.getInstance().getOrCreateUser(uuid);
        }
    }
    if (user == null && !NMSUtil.getInstance().isEntityMonster(event.getEntity())) {
        final GDEntity gdEntity = EntityTracker.getCachedEntity(event.getEntity().getEntityId());
        if (gdEntity != null) {
            user = PermissionHolderCache.getInstance().getOrCreateUser(gdEntity.getOwnerUUID());
        }
        if (user == null && source instanceof FallingBlock) {
            // always allow blocks to fall if no user found
            return;
        }
    }
    final Tristate result = GDPermissionManager.getInstance().getFinalPermission(event, location, targetClaim, Flags.BLOCK_BREAK, event.getEntity(), event.getBlock(), user, TrustTypes.BUILDER, true);
    if (result == Tristate.FALSE) {
        event.setCancelled(true);
        return;
    }
}
 
Example 8
Source File: IslandGuard.java    From askyblock with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Trap TNT being primed by flaming arrows
 * @param e - event
 */
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
public void onTNTPrimed(final EntityChangeBlockEvent e) {
    if (DEBUG) {
        plugin.getLogger().info(e.getEventName());
        plugin.getLogger().info("DEBUG: block = " + e.getBlock().getType());
        plugin.getLogger().info("DEBUG: entity = " + e.getEntityType());
        plugin.getLogger().info("DEBUG: material changing to " + e.getTo());
    }
    if (actionAllowed(e.getEntity().getLocation(), SettingsFlag.FIRE)) {
        return;
    }
    if (e.getBlock() == null) {
        return;
    }
    // Check for TNT
    if (!e.getBlock().getType().equals(Material.TNT)) {
        //plugin.getLogger().info("DEBUG: not tnt");
        return;
    }
    // Check world
    if (!inWorld(e.getBlock())) {
        return;
    }
    // Check if this is on an island
    Island island = plugin.getGrid().getIslandAt(e.getBlock().getLocation());
    if (island == null || island.isSpawn()) {
        return;
    }
    // Stop TNT from being damaged if it is being caused by a visitor with a flaming arrow
    if (e.getEntity() instanceof Projectile) {
        //plugin.getLogger().info("DEBUG: projectile");
        Projectile projectile = (Projectile) e.getEntity();
        // Find out who fired it
        if (projectile.getShooter() instanceof Player) {
            //plugin.getLogger().info("DEBUG: player shot arrow. Fire ticks = " + projectile.getFireTicks());
            if (projectile.getFireTicks() > 0) {
                //plugin.getLogger().info("DEBUG: arrow on fire");
                Player shooter = (Player)projectile.getShooter();
                if (!plugin.getGrid().locationIsAtHome(shooter, true, e.getBlock().getLocation())) {
                    //plugin.getLogger().info("DEBUG: shooter is not at home");
                    // Only say it once a second
                    // Debounce event (it can be called twice for the same action)
                    if (!tntBlocks.contains(e.getBlock().getLocation())) {
                        Util.sendMessage(shooter, ChatColor.RED + plugin.myLocale(shooter.getUniqueId()).islandProtected);
                        tntBlocks.add(e.getBlock().getLocation());
                        plugin.getServer().getScheduler().runTaskLater(plugin, new Runnable() {

                            @Override
                            public void run() {
                                tntBlocks.remove(e.getBlock().getLocation());
                            }}, 20L);
                    }
                    // Remove the arrow
                    projectile.remove();
                    e.setCancelled(true);
                }
            }
        }
    }
}