Java Code Examples for org.bukkit.entity.Entity#remove()

The following examples show how to use org.bukkit.entity.Entity#remove() . 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: MobListener.java    From civcraft with GNU General Public License v2.0 6 votes vote down vote up
@EventHandler(priority = EventPriority.NORMAL)
public void onChunkLoad(ChunkLoadEvent event) {
	
	for (Entity e : event.getChunk().getEntities()) {
		if (e instanceof Monster) {
			e.remove();
			return;
		}
		
		if (e instanceof IronGolem) {
			e.remove();
			return;
		}
	}

}
 
Example 2
Source File: ArmorStandDisplayItem.java    From QuickShop-Reremake with GNU General Public License v3.0 6 votes vote down vote up
@Override
public boolean removeDupe() {
    if (this.armorStand == null) {
        Util.debugLog("Warning: Trying to removeDupe for a null display shop.");
        return false;
    }
    boolean removed = false;
    for (Entity entity : armorStand.getNearbyEntities(1.5, 1.5, 1.5)) {
        if (entity.getType() != EntityType.ARMOR_STAND) {
            continue;
        }
        ArmorStand eArmorStand = (ArmorStand) entity;

        if (!eArmorStand.getUniqueId().equals(this.armorStand.getUniqueId())) {
            if (DisplayItem.checkIsTargetShopDisplay(eArmorStand.getItemInHand(), this.shop)) {
                Util.debugLog("Removing dupes ArmorEntity " + eArmorStand.getUniqueId() + " at " + eArmorStand.getLocation());
                entity.remove();
                removed = true;
            }
        }
    }
    return removed;
}
 
Example 3
Source File: RealDisplayItem.java    From QuickShop-Reremake with GNU General Public License v3.0 6 votes vote down vote up
@Override
public boolean removeDupe() {
    if (this.item == null) {
        Util.debugLog("Warning: Trying to removeDupe for a null display shop.");
        return false;
    }

    boolean removed = false;
    // Chunk chunk = shop.getLocation().getChunk();
    for (Entity entity : item.getNearbyEntities(1.5, 1.5, 1.5)) {
        if (entity.getType() != EntityType.DROPPED_ITEM) {
            continue;
        }
        Item eItem = (Item) entity;
        UUID displayUUID = this.item.getUniqueId();
        if (!eItem.getUniqueId().equals(displayUUID)) {
            if (DisplayItem.checkIsTargetShopDisplay(eItem.getItemStack(), this.shop)) {
                Util.debugLog(
                        "Removing a duped ItemEntity " + eItem.getUniqueId() + " at " + eItem.getLocation());
                entity.remove();
                removed = true;
            }
        }
    }
    return removed;
}
 
Example 4
Source File: EnderDragonEvent.java    From SkyWarsReloaded with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void endEvent(boolean force) {
	if (fired) {
		if (force && length != -1) {
			br.cancel();
		}
		World world = gMap.getCurrentWorld();
		for (Entity ent: world.getEntities()) {
			if (ent instanceof EnderDragon) {
				ent.remove();
				break;
			}
		}
		if (gMap.getMatchState() == MatchState.PLAYING) {
			MatchManager.get().message(gMap, ChatColor.translateAlternateColorCodes('&', endMessage));
		}
		if (repeatable || force) {
			setStartTime();
			this.startTime = this.startTime + gMap.getTimer();
			this.fired = false;
		}
	}
}
 
Example 5
Source File: MobFeature.java    From VoxelGamesLibv2 with MIT License 6 votes vote down vote up
@Override
public void enable() {
    worldName = getPhase().getFeature(MapFeature.class).getWorld().getName();

    if (removeExisting) {
        for (Entity entity : getPhase().getFeature(MapFeature.class).getWorld().getEntities()) {
            if (blacklist.length != 0) {
                if (Arrays.stream(blacklist).anyMatch(m -> m.equals(entity.getType()))) {
                    entity.remove();
                }
            } else if (whitelist.length != 0) {
                if (Arrays.stream(whitelist).noneMatch(m -> m.equals(entity.getType()))) {
                    entity.remove();
                }
            } else {
                entity.remove();
            }
        }
    }
}
 
Example 6
Source File: EntityRemoveListener.java    From StackMob-3 with GNU General Public License v3.0 6 votes vote down vote up
private void cleanupEntity(Entity entity) {
    // Check if entity is a mob, since they despawn on chunk unload.
    if (entity instanceof Monster) {
        sm.getCache().remove(entity.getUniqueId());
        StackTools.removeSize(entity);
        return;
    }

    // Add to storage
    if (StackTools.hasValidData(entity)) {
        int stackSize = StackTools.getSize(entity);
        StackTools.removeSize(entity);
        if (stackSize <= 1 && stackSize != GlobalValues.NO_STACKING) {
            return;
        }
        if (sm.getCustomConfig().getBoolean("remove-chunk-unload")) {
            entity.remove();
            return;
        }
        sm.getCache().put(entity.getUniqueId(), stackSize);
    }
}
 
Example 7
Source File: PGMListener.java    From ProjectAres with GNU Affero General Public License v3.0 5 votes vote down vote up
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void clearActiveEnderPearls(final PlayerDeathEvent event) {
    for(Entity entity : event.getEntity().getWorld().getEntitiesByClass(EnderPearl.class)) {
        if(((EnderPearl) entity).getShooter() == event.getEntity()) {
            entity.remove();
        }
    }
}
 
Example 8
Source File: ChunkListener.java    From FastAsyncWorldedit with GNU General Public License v3.0 5 votes vote down vote up
public void cleanup(Chunk chunk) {
    for (Entity entity : chunk.getEntities()) {
        if (entity.getType() == EntityType.DROPPED_ITEM) {
            entity.remove();
        }
    }

}
 
Example 9
Source File: BatBomb.java    From NBTEditor with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void onExplode(Item item, Location location) {
	List<Entity> passengers = item.getPassengers();
	if (passengers.size() != 0) {
		Entity bat = passengers.get(0);
		if (bat != null && bat instanceof Bat && !bat.isDead()) {
			bat.remove();
			spawnBatsAt(location, 10, 50);
		}
	}
}
 
Example 10
Source File: XPCollector.java    From Slimefun4 with GNU General Public License v3.0 5 votes vote down vote up
protected void tick(Block b) {
    Iterator<Entity> iterator = b.getWorld().getNearbyEntities(b.getLocation(), 4.0, 4.0, 4.0, n -> n instanceof ExperienceOrb && n.isValid()).iterator();
    int experiencePoints = 0;

    while (iterator.hasNext() && experiencePoints == 0) {
        Entity entity = iterator.next();

        if (ChargableBlock.getCharge(b) < ENERGY_CONSUMPTION) {
            return;
        }

        experiencePoints = getStoredExperience(b) + ((ExperienceOrb) entity).getExperience();

        ChargableBlock.addCharge(b, -ENERGY_CONSUMPTION);
        entity.remove();

        int withdrawn = 0;
        BlockMenu menu = BlockStorage.getInventory(b);

        for (int level = 0; level < getStoredExperience(b); level = level + 10) {
            if (menu.fits(SlimefunItems.FILLED_FLASK_OF_KNOWLEDGE, getOutputSlots())) {
                withdrawn = withdrawn + 10;
                menu.pushItem(SlimefunItems.FILLED_FLASK_OF_KNOWLEDGE.clone(), getOutputSlots());
            }
        }

        BlockStorage.addBlockInfo(b, DATA_KEY, String.valueOf(experiencePoints - withdrawn));
    }
}
 
Example 11
Source File: GridManager.java    From askyblock with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Removes monsters around location l
 *
 * @param l location
 */
public void removeMobs(final Location l) {
    if (!inWorld(l)) {
        return;
    }
    //plugin.getLogger().info("DEBUG: removing mobs");
    // Don't remove mobs if at spawn
    if (this.isAtSpawn(l)) {
        //plugin.getLogger().info("DEBUG: at spawn!");
        return;
    }

    final int px = l.getBlockX();
    final int py = l.getBlockY();
    final int pz = l.getBlockZ();
    for (int x = -1; x <= 1; x++) {
        for (int z = -1; z <= 1; z++) {
            final Chunk c = l.getWorld().getChunkAt(new Location(l.getWorld(), px + x * 16, py, pz + z * 16));
            if (c.isLoaded()) {
                for (final Entity e : c.getEntities()) {
                    //plugin.getLogger().info("DEBUG: " + e.getType());
                    // Don't remove if the entity is an NPC or has a name tag
                    if (e.getCustomName() != null || e.hasMetadata("NPC"))
                        continue;
                    if (e instanceof Monster && !Settings.mobWhiteList.contains(e.getType())) {
                        e.remove();
                    }
                }
            }
        }
    }
}
 
Example 12
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 13
Source File: NPCFactory.java    From NPCFactory with MIT License 5 votes vote down vote up
/**
 * Despawn all npc's on a single world.
 *
 * @param world World to despawn npc's on.
 */
public void despawnAll(World world) {
    for(Entity entity : world.getEntities()) {
        if(entity.hasMetadata("NPC")) {
            entity.remove();
        }
    }
}
 
Example 14
Source File: Freeze.java    From ProjectAres with GNU Affero General Public License v3.0 5 votes vote down vote up
private void removeEntities(Location origin, double radius) {
    if(radius <= 0) return;

    double radiusSq = radius * radius;
    for(Entity ent : origin.getWorld().getEntities()) {
        if(origin.distanceSquared(ent.getLocation()) > radiusSq)
            continue;

        if(ent instanceof TNTPrimed) {
            ent.remove();
        }
    }
}
 
Example 15
Source File: GameArena.java    From ZombieEscape with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Initializes the game state, and sets up defaults
 */
public void startGame() {
    Bukkit.getPluginManager().callEvent(new GameStartEvent());

    final String MAPS_PATH = PLUGIN.getConfiguration().getSettingsConfig().getString("MapsPath");
    final String ARENAS_PATH = PLUGIN.getConfiguration().getSettingsConfig().getString("ArenasPath");

    this.mapSelection = VOTE_MANAGER.getWinningMap();
    this.gameFile = new GameFile(ARENAS_PATH, mapSelection + ".yml");
    this.arenaWorld = Bukkit.createWorld(new WorldCreator(MAPS_PATH + gameFile.getConfig().getString("World")));
    this.arenaWorld.setSpawnFlags(false, false);
    this.arenaWorld.setGameRuleValue("doMobSpawning", "false");
    this.spawns = gameFile.getLocations(arenaWorld, "Spawns");
    this.doors = gameFile.getDoors(arenaWorld);
    this.checkpoints = gameFile.getCheckpoints(arenaWorld);
    this.nukeRoom = gameFile.getLocation(arenaWorld, "Nukeroom");
    this.handleStart();

    VOTE_MANAGER.resetVotes();

    Bukkit.getConsoleSender().sendMessage(Utils.color("&6Start game method"));

    // Clear entities
    for (Entity entity : arenaWorld.getEntities()) {
        if (!(entity instanceof Player) && (entity instanceof Animals || entity instanceof Monster)) {
            entity.remove();
        }
    }
}
 
Example 16
Source File: PGMListener.java    From PGM with GNU Affero General Public License v3.0 5 votes vote down vote up
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void clearActiveEnderPearls(final PlayerDeathEvent event) {
  for (Entity entity : event.getEntity().getWorld().getEntitiesByClass(EnderPearl.class)) {
    if (((EnderPearl) entity).getShooter() == event.getEntity()) {
      entity.remove();
    }
  }
}
 
Example 17
Source File: ChunkListener.java    From FastAsyncWorldedit with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Prevent FireWorks from loading chunks
 * @param event
 */
@EventHandler(priority = EventPriority.LOWEST)
public void onChunkLoad(ChunkLoadEvent event) {
    if (!Settings.IMP.TICK_LIMITER.FIREWORKS_LOAD_CHUNKS) {
        Chunk chunk = event.getChunk();
        Entity[] entities = chunk.getEntities();
        World world = chunk.getWorld();

        Exception e = new Exception();
        int start = 14;
        int end = 22;
        int depth = Math.min(end, getDepth(e));

        for (int frame = start; frame < depth; frame++) {
            StackTraceElement elem = getElement(e, frame);
            if (elem == null) return;
            String className = elem.getClassName();
            int len = className.length();
            if (className != null) {
                if (len > 15 && className.charAt(len - 15) == 'E' && className.endsWith("EntityFireworks")) {
                    for (Entity ent : world.getEntities()) {
                        if (ent.getType() == EntityType.FIREWORK) {
                            Vector velocity = ent.getVelocity();
                            double vertical = Math.abs(velocity.getY());
                            if (Math.abs(velocity.getX()) > vertical || Math.abs(velocity.getZ()) > vertical) {
                                Fawe.debug("[FAWE `tick-limiter`] Detected and cancelled rogue FireWork at " + ent.getLocation());
                                ent.remove();
                            }
                        }
                    }
                }
            }
        }
    }
}
 
Example 18
Source File: FriendlyFireRefundMatchModule.java    From PGM with GNU Affero General Public License v3.0 5 votes vote down vote up
@EventHandler(priority = EventPriority.NORMAL)
public void onHit(EntityDamageByEntityEvent event) {
  final Entity damager = event.getDamager();
  if (!event.isCancelled()
      || event.getCause() != EntityDamageEvent.DamageCause.PROJECTILE
      || !(damager instanceof Projectile)
      || !damager.hasMetadata(METADATA_KEY)) return;

  final Player shooter = (Player) ((Projectile) damager).getShooter();
  if (match.getParticipant(shooter) == null) return;

  damager.remove();
  shooter.getInventory().addItem(new ItemStack(Material.ARROW));
}
 
Example 19
Source File: EntitySpawnListener.java    From IridiumSkyblock with GNU General Public License v2.0 5 votes vote down vote up
public void monitorEntity(Entity entity) {
    if (entity == null) return;
    if (entity.isDead()) return;

    final UUID uuid = entity.getUniqueId();
    final Island startingIsland = IridiumSkyblock.getInstance().entities.get(uuid);
    if (startingIsland.isInIsland(entity.getLocation())) {
        //The entity is still in the island, so make a scheduler to check again
        Bukkit.getScheduler().scheduleSyncDelayedTask(IridiumSkyblock.getInstance(), () -> monitorEntity(entity), 20);
    } else {
        //The entity is not in the island, so remove it
        entity.remove();
        IridiumSkyblock.getInstance().entities.remove(uuid);
    }
}
 
Example 20
Source File: EliteMobScanner.java    From EliteMobs with GNU General Public License v3.0 4 votes vote down vote up
public static void scanValidAggressiveLivingEntity(LivingEntity livingEntity) {

                if (!EntityTracker.isNaturalEntity(livingEntity) &&
                        !ConfigValues.mobCombatSettingsConfig.getBoolean(MobCombatSettingsConfig.STACK_AGGRESSIVE_SPAWNER_MOBS))
                    return;
                if (EntityTracker.isNaturalEntity(livingEntity) &&
                        !ConfigValues.mobCombatSettingsConfig.getBoolean(MobCombatSettingsConfig.STACK_AGGRESSIVE_NATURAL_MOBS))
                    return;

                for (Entity secondEntity : livingEntity.getNearbyEntities(aggressiveRange, aggressiveRange, aggressiveRange)) {

                    if (!secondEntity.getType().equals(livingEntity.getType())) continue;
                    if (!livingEntity.isValid() || !secondEntity.isValid()) continue;

                    if (!EntityTracker.isNaturalEntity(secondEntity) &&
                            !ConfigValues.mobCombatSettingsConfig.getBoolean(MobCombatSettingsConfig.STACK_AGGRESSIVE_SPAWNER_MOBS))
                        return;
                    if (EntityTracker.isNaturalEntity(secondEntity) &&
                            !ConfigValues.mobCombatSettingsConfig.getBoolean(MobCombatSettingsConfig.STACK_AGGRESSIVE_NATURAL_MOBS))
                        return;


                    EliteMobEntity eliteMobEntity1 = null;
                    EliteMobEntity eliteMobEntity2 = null;

                    int level1 = 1;
                    int level2 = 1;

                    if (EntityTracker.isEliteMob(livingEntity)) {
                        eliteMobEntity1 = EntityTracker.getEliteMobEntity(livingEntity);
                        if (!eliteMobEntity1.canStack()) continue;
                        level1 = eliteMobEntity1.getLevel();
                    }

                    if (EntityTracker.isEliteMob(secondEntity)) {
                        eliteMobEntity2 = EntityTracker.getEliteMobEntity(secondEntity);
                        if (!eliteMobEntity2.canStack()) continue;
                        level2 = eliteMobEntity2.getLevel();
                    }

                    int newLevel = level1 + level2;

                    if (newLevel > ConfigValues.mobCombatSettingsConfig.getInt(MobCombatSettingsConfig.ELITEMOB_STACKING_CAP))
                        return;

                    double healthPercentage = (livingEntity.getHealth() / livingEntity.getAttribute(Attribute.GENERIC_MAX_HEALTH).getValue() +
                            ((LivingEntity) secondEntity).getHealth() / ((LivingEntity) secondEntity).getAttribute(Attribute.GENERIC_MAX_HEALTH).getValue()) / 2;

                    /*
                    This is a bit of a dirty hack
                    It won't register the entity twice, but it will overwrite the existing method
                    */
                    eliteMobEntity1 = new EliteMobEntity(livingEntity, newLevel, healthPercentage, CreatureSpawnEvent.SpawnReason.CUSTOM);
                    secondEntity.remove();

                }

    }