Java Code Examples for org.bukkit.World#getEntities()

The following examples show how to use org.bukkit.World#getEntities() . 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: Statistics.java    From Modern-LWC with MIT License 6 votes vote down vote up
/**
 * Obtain an entity count of a Entity class.
 *
 * @param clazz If null, all entities are counted
 * @return
 */
public static int getEntityCount(Class<? extends Entity> clazz) {
    int count = 0;

    for (World world : Bukkit.getServer().getWorlds()) {
        if (clazz == null) {
            count += world.getEntities().size();
        } else {
            for (Entity entity : world.getEntities()) {
                if (entity != null && clazz.isInstance(entity)) {
                    count++;
                }
            }
        }
    }

    return count;
}
 
Example 2
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 3
Source File: LimitsV2.java    From Modern-LWC with MIT License 5 votes vote down vote up
@Override
public int getProtectionCount(Player player, Material material) {
    int i = 0;
    for (World world : Bukkit.getWorlds()) {
        for (Entity ent : world.getEntities()) {
            int A = 50000 + ent.getUniqueId().hashCode();
            Protection prot = LWC.getInstance().getPhysicalDatabase().loadProtection(ent.getWorld().getName(),
                    A, A, A);
            if (prot.getBukkitOwner() == player) {
                i++;
            }
        }
    }
    return i;
}
 
Example 4
Source File: SentinelUtilities.java    From Sentinel with MIT License 5 votes vote down vote up
/**
 * Gets the entity for a given UUID.
 */
public static Entity getEntityForID(UUID id) {
    if (!SentinelVersionCompat.v1_12) {
        for (World world : Bukkit.getServer().getWorlds()) {
            for (Entity e : world.getEntities()) {
                if (e.getUniqueId().equals(id)) {
                    return e;
                }
            }
        }
        return null;
    }
    return Bukkit.getServer().getEntity(id);
}
 
Example 5
Source File: CombatManager.java    From CombatLogX with GNU General Public License v3.0 5 votes vote down vote up
private Entity getEntityByUUID(World world, UUID uuid) {
    if(world == null || uuid == null) return null;

    List<Entity> entityList = world.getEntities();
    for(Entity entity : entityList) {
        UUID entityId = entity.getUniqueId();
        if(!uuid.equals(entityId)) continue;
        
        return entity;
    }
    
    return null;
}
 
Example 6
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 7
Source File: ZombieEscape.java    From ZombieEscape with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void onEnable() {
    configuration = new Configuration(this);
    configuration.setupHikari(hikari, configuration.getSettingsConfig());

    gameArena = new GameArena(this);
    menuManager = new MenuManager(this);

    serverSpawn = configuration.getSpawn();

    Bukkit.setSpawnRadius(0);

    World world = Bukkit.getWorlds().get(0);
    world.setSpawnFlags(false, false);
    world.setGameRuleValue("doMobSpawning", "false");

    for (Entity entity : world.getEntities()) {
        if (!(entity instanceof Player) && entity instanceof LivingEntity) {
            entity.remove();
        }
    }

    registerListeners();
    getCommand("game").setExecutor(new Game());
    getCommand("setlobbyspawn").setExecutor(new SetLobbySpawn(this));
    getCommand("ztele").setExecutor(new Ztele(this));

    menuManager.addMenu("hkits", new HumanKitMenu("Human Kit Menu", 9, this));
    menuManager.addMenu("zkits", new ZombieKitMenu("Zombie Kit Menu", 9, this));
    menuManager.addMenu("vote", new VoteMenu(Utils.color("&8Vote"), 9, gameArena));
}
 
Example 8
Source File: EntityUtil.java    From civcraft with GNU General Public License v2.0 5 votes vote down vote up
public static Entity getEntity(World world, UUID uuid) {

		for (Entity ent : world.getEntities()) {
			if (ent.getUniqueId().equals(uuid)) {
				return ent;
			}
		}
		
		return null;
	}
 
Example 9
Source File: NPCFactory.java    From NPCFactory with MIT License 5 votes vote down vote up
/**
 * Get all npc's from a specific world
 *
 * @param world World to get npc's from
 * @return A list of all npc's in the world
 */
public List<NPC> getNPCs(World world) {
    List<NPC> npcList = new ArrayList<NPC>();
    for(Entity entity : world.getEntities()) {
        if(isNPC(entity)) {
            npcList.add(getNPC(entity));
        }
    }

    return npcList;
}
 
Example 10
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();
        }
    }
}