Java Code Examples for org.bukkit.Bukkit.getOnlinePlayers()

The following are Jave code examples for showing how to use getOnlinePlayers() of the org.bukkit.Bukkit class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: HCFCore   File: FactionClaimForArgument.java   View Source Code Vote up 6 votes
@Override
public List<String> onTabComplete(CommandSender sender, Command command, String label, String[] args)
{
  if ((args.length != 2) || (!(sender instanceof Player)))
  {
    return Collections.emptyList();
  }
  if (args[1].isEmpty()) {
        return null;
    }
    Player player = (Player)sender;
    List<String> results = new ArrayList(this.plugin.getFactionManager().getFactionNameMap().keySet());
    for (Player target : Bukkit.getOnlinePlayers()) {
        if ((player.canSee(target)) && (!results.contains(target.getName()))) {
            results.add(target.getName());
        }
    }
    return results;
}
 
Example 2
Project: SamaGamesAPI   File: BeginTimer.java   View Source Code Vote up 6 votes
/**
 * Send a piano note to the players if the remaining seconds are
 * belows or equals 5.
 *
 * @param seconds Actual remaining seconds
 */
private void sendSound(int seconds)
{
    boolean ring = false;

    if (seconds <= 5 && seconds != 0)
    {
        ring = true;
    }

    for(Player player : Bukkit.getOnlinePlayers())
    {
        player.setLevel(seconds);

        if (ring)
            player.playSound(player.getLocation(), Sound.BLOCK_NOTE_HARP, 1L, 1L);

        if (seconds == 0)
            player.playSound(player.getLocation(), Sound.BLOCK_NOTE_PLING, 1L, 1L);
    }
}
 
Example 3
Project: Arcadia-Spigot   File: KingOfTheHillGame.java   View Source Code Vote up 6 votes
@Override
public void onPreStart() {
    Location spawnLocation = Utils.parseLocation((String) this.getGameMap().fetchSetting("startPosition"));
    MaterialData materialData = Utils.parseMaterialData((String) this.getGameMap().fetchSetting("item"));
    ItemStack itemStack = new ItemStack(materialData.getItemType(), 1, materialData.getData());
    itemStack.addUnsafeEnchantment(Enchantment.KNOCKBACK,
        Integer.parseInt((String) this.getGameMap().fetchSetting("knockbackAmount")));
    for(Player player : Bukkit.getOnlinePlayers()) {
        if(!this.getAPI().getGameManager().isAlive(player)) continue;
        player.teleport(spawnLocation);
        player.setGameMode(GameMode.ADVENTURE);
        player.getInventory().addItem(itemStack);
    }
    this.hill = new Cuboid(Utils.parseLocation((String) this.getGameMap().fetchSetting("hillBoundsA")),
        Utils.parseLocation((String) this.getGameMap().fetchSetting("hillBoundsB")));
}
 
Example 4
Project: SurvivalPlus   File: BedFatigue.java   View Source Code Vote up 5 votes
private void wakePlayer(Player player)
{
	if (sleeping.containsKey(player))
       {
       	Bukkit.getConsoleSender().sendMessage(player.getName());
           PacketPlayOutAnimation aniPacket = new PacketPlayOutAnimation(((CraftPlayer) player).getHandle(), 2);
           for (Player o : Bukkit.getOnlinePlayers())
           {
               ((CraftPlayer) o).getHandle().playerConnection.sendPacket(aniPacket);
           }
           sleeping.remove(player);
           //player.teleport(player.getBedSpawnLocation());
       }
}
 
Example 5
Project: NameTagChanger   File: NameTagChanger.java   View Source Code Vote up 5 votes
private void updatePlayer(Player player, String oldName) {
    Validate.isTrue(enabled, "NameTagChanger is disabled");
    GameProfileWrapper newProfile = gameProfiles.get(player.getUniqueId());
    if (newProfile == null) {
        newProfile = packetHandler.getDefaultPlayerProfile(player);
    }
    List<Team> scoreboardTeamsToUpdate = Lists.newArrayList();
    sendingPackets = true;
    for (Player otherPlayer : Bukkit.getOnlinePlayers()) {
        if (otherPlayer.equals(player)) {
            if (otherPlayer.getScoreboard().getEntryTeam(player.getName()) != null) {
                scoreboardTeamsToUpdate.add(otherPlayer.getScoreboard().getEntryTeam(player.getName()));
            }
            continue;
        }
        if (otherPlayer.canSee(player)) {
            packetHandler.sendTabListRemovePacket(player, otherPlayer);
            packetHandler.sendTabListAddPacket(player, newProfile, otherPlayer);
            if (otherPlayer.getWorld().equals(player.getWorld())) {
                packetHandler.sendEntityDestroyPacket(player, otherPlayer);
                packetHandler.sendNamedEntitySpawnPacket(player, otherPlayer);
            }
        }
        // The player we want to rename is in a scoreboard team.
        if (otherPlayer.getScoreboard().getEntryTeam(player.getName()) != null) {
            scoreboardTeamsToUpdate.add(otherPlayer.getScoreboard().getEntryTeam(player.getName()));
        }
    }
    if (oldName != null) {
        String newName = newProfile.getName();
        for (Team team : scoreboardTeamsToUpdate) {
            Bukkit.getOnlinePlayers().stream().filter(p -> p.getScoreboard() == team.getScoreboard()).forEach(p -> {
                packetHandler.sendScoreboardRemovePacket(oldName, p, team.getName());
                packetHandler.sendScoreboardAddPacket(newName, p, team.getName());
            });
        }
    }
    sendingPackets = false;
}
 
Example 6
Project: SurvivalPlus   File: Survival.java   View Source Code Vote up 5 votes
public void onDisable()
{
	PluginDescriptionFile pdfFile = getDescription();
	Logger logger = getLogger();
	getServer().getScheduler().cancelTasks(this);
	getServer().resetRecipes();
	usingPlayers = new ArrayList<Player>();
	//Avoid WorkbenchShare glitch
	for(Player p : Bukkit.getOnlinePlayers())
	{
		if (p.hasMetadata("shared_workbench"))
		{
			Block workbench = (p.getMetadata("shared_workbench").get(0).value() instanceof Block) ? (Block)p.getMetadata("shared_workbench").get(0).value() : null;
			
			if(workbench != null && workbench.getType() == Material.WORKBENCH)
			{
				if (workbench.hasMetadata("shared_players"))
					workbench.removeMetadata("shared_players", Survival.instance);
				else
					p.getOpenInventory().getTopInventory().clear();
				
				p.closeInventory();	
			}
			
			p.removeMetadata("shared_workbench", Survival.instance);
		}
	}
	
	logger.info(pdfFile.getName() + " has been disabled.");
}
 
Example 7
Project: AgarMC   File: InvisibleLoop.java   View Source Code Vote up 5 votes
/**
 * To be used for hiding players but not in tab, and looped to avoid entity
 * respawn on view when coming back from away
 */

@Override
public void run()
{
    for (Player p1 : Bukkit.getOnlinePlayers())
        for (Player p2 : Bukkit.getOnlinePlayers())
            if (!p1.equals(p2))
                ((CraftPlayer)p1).getHandle().playerConnection.sendPacket(new PacketPlayOutEntityDestroy(p2.getEntityId()));
}
 
Example 8
Project: mczone   File: ListCmd.java   View Source Code Vote up 5 votes
@Override
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
    Chat.player(sender, "&6Currently &c" + Bukkit.getOnlinePlayers().length + "/" + Bukkit.getMaxPlayers() + " &6players online:");
    String players = "";
    for (Player p : Bukkit.getOnlinePlayers()) {
    	Gamer g = Gamer.get(p);
    	players += g.getPrefix() + "&7" + p.getDisplayName() + "&f, ";
    }
    if (players.length() > 4)
    	players = players.substring(0, players.length() - 4);
    
    Chat.player(sender, "&6Player List: " + players);
	
    return true;
}
 
Example 9
Project: Locked   File: GiveGodItem.java   View Source Code Vote up 5 votes
@Override
public boolean execute(CommandSender sender, String[] args) throws CommandException {
    if (!(sender instanceof Player)) {
        throw new CommandException("Only players can use this command!");
    }
    Player player = (Player) sender;

    ItemStack goditem = new ItemStack(Material.DIAMOND_SWORD);
    ItemMeta goditemMeta = goditem.getItemMeta();
    goditemMeta.setDisplayName(ChatColor.BLUE + "GOD ITEM!");
    goditemMeta.addEnchant(Enchantment.DAMAGE_ALL, 1000, true);
    goditemMeta.addEnchant(Enchantment.DURABILITY, 1000, true);
    goditem.setItemMeta(goditemMeta);
    if (args.length == 0) {
        player.getInventory().addItem(goditem);
        player.sendMessage(ChatColor.AQUA + "Receiving item...");
        return true;
    }
    if (args.length == 1) {
        boolean x = false;
        for (Player p : Bukkit.getOnlinePlayers()) {
            if (p.getName().equals(args[0])) {
                x = true;
                break;
            }
        }
        if (!x) {
            player.sendMessage(ChatColor.RED + "Could not find the specified player.");
            return true;
        }
        Player target = Bukkit.getPlayer(args[0]);
        target.getInventory().addItem(goditem);
        target.sendMessage(ChatColor.AQUA + "Receiving item...");
        return true;
    }
    player.sendMessage(ChatColor.RED + "/givegoditem [player]");
    return true;
}
 
Example 10
Project: mczone   File: Walls.java   View Source Code Vote up 5 votes
public static void updateSpectators() {
	for (String list : getSpectators()) {
		Player t = Bukkit.getPlayerExact(list);
		if (t == null || !t.isOnline())
			continue;
		
		t.setAllowFlight(true);
		
		for (Player p : Bukkit.getOnlinePlayers()) {
			if (getSpectators().contains(p.getName()))
				continue;
			p.hidePlayer(t);
		}
	}
}
 
Example 11
Project: NineSlots   File: Main.java   View Source Code Vote up 5 votes
/**
 * Send the given message to all online players.
 *
 * @param message The message to send.
 */
public void broadcast(String message) {
    for (Player online : Bukkit.getOnlinePlayers()) {
        online.sendMessage(message);
    }

    Bukkit.getLogger().info(message);
}
 
Example 12
Project: Warzone   File: StartCountdown.java   View Source Code Vote up 5 votes
@Override
protected void onTick() {
    if(isCancelled()) return;

    int amountParticipating = teamManagerModule.getAmountParticipating();
    if (amountParticipating < REQUIRED_PLAYERS) {
        int needed = REQUIRED_PLAYERS - amountParticipating;
        getBossBar().setProgress(1);
        getBossBar().setTitle(ChatColor.RED + "Waiting for " + ChatColor.AQUA + needed +
                ChatColor.RED + " more player" + (needed == 1 ? "" : "s") + " to join");
        getBossBar().setColor(BarColor.RED);

        setTimeLeft(getTimeMax());
        return;
    }

    getBossBar().setProgress((getTimeMax() - getTimeLeft()) / getTimeMax());

    if (getTimeLeft() % 20 == 0) {
        getBossBar().setColor(BarColor.GREEN);
        getBossBar().setTitle(ChatColor.GREEN + "Match starting in " + ChatColor.DARK_RED + getTimeLeftSeconds() +
                ChatColor.GREEN + " second" + (getTimeLeftSeconds() > 1 ? "s" : ""));

        if (getTimeLeftSeconds() <= 3) {
            for (Player player : Bukkit.getOnlinePlayers()) {
                player.playSound(player.getLocation(), Sound.BLOCK_NOTE_PLING, 1, 1);
                if (!TGM.get().getModule(TeamManagerModule.class).getSpectators().containsPlayer(player)) {
                    player.sendTitle(ChatColor.YELLOW.toString() + getTimeLeftSeconds(), "", 0, 5, 15);
                }
            }
        }
    }
}
 
Example 13
Project: Monsters_vs_Players   File: Night.java   View Source Code Vote up 5 votes
@Override
public void run() {
    world.setTime(world.getTime() + 140);

    // Time change (24,000 is the same as 0);
    if (world.getTime() >= 24000) {
        world.setTime(world.getTime() - 24000);
    }

    //Night Start
    if (currentTime == 40) {
        getLogger().info("Awooo~");
    }

// TODO:SpecialNightAbilities
// TODO:Night Stop
// TODO:Show events
// TODO:Show counter events

//TODO: pew pew!

    // Day Start
    if (currentTime >= 0) {
        this.cancel();
    new Day().runTaskTimer(Main.cat, 20, 20);
    }


    // Tell the time to everybody (Spectators???)
    for (Player player : Bukkit.getOnlinePlayers()) {
        player.setLevel(currentTime);
    }



    // Countdown
    currentTime--;
}
 
Example 14
Project: UltimateSpawn   File: PlayerVisibility.java   View Source Code Vote up 5 votes
public static void hidePlayer(Player p) {
	for (Player player : Bukkit.getOnlinePlayers()) {
		p.hidePlayer(player);
	}
	
	PVPlayer.remove(p);
}
 
Example 15
Project: SurvivalPlus   File: ParticleEffect.java   View Source Code Vote up 5 votes
/**
 * Sends the packet to all players in a certain range
 * 
 * @param center Center location of the effect
 * @param range Range in which players will receive the packet (Maximum range for particles is usually 16, but it can differ for some types)
 * @throws IllegalArgumentException If the range is lower than 1
 * @see #sendTo(Location center, Player player)
 */
public void sendTo(Location center, double range) throws IllegalArgumentException {
	if (range < 1) {
		throw new IllegalArgumentException("The range is lower than 1");
	}
	String worldName = center.getWorld().getName();
	double squared = range * range;
	for (Player player : Bukkit.getOnlinePlayers()) {
		if (!player.getWorld().getName().equals(worldName) || player.getLocation().distanceSquared(center) > squared) {
			continue;
		}
		sendTo(center, player);
	}
}
 
Example 16
Project: Arcadia-Spigot   File: Arcadia.java   View Source Code Vote up 5 votes
public void onDisable() {
    this.getAPI().getGameManager().setGameState(GameState.FINISHED);
    for(Player player : Bukkit.getOnlinePlayers()) {
        if(player.getVehicle() != null) {
            Entity vehicle = player.getVehicle();
            vehicle.eject();
            vehicle.remove();
        }
        this.getAPI().getGameManager().setAlive(player, false);
    }
    this.getAPI().getTranslationManager().kickPlayers("common.server-restarting");
    removeCustomWorlds();
}
 
Example 17
Project: HCFCore   File: FactionListener.java   View Source Code Vote up 5 votes
@EventHandler(ignoreCancelled = true, priority = EventPriority.MONITOR)
public void onFactionCreate(FactionCreateEvent event) {
    Faction faction = event.getFaction();
    if (faction instanceof PlayerFaction) {
        CommandSender sender = event.getSender();
        for (Player player : Bukkit.getOnlinePlayers()) {
            Relation relation = faction.getRelation(player);
            String msg = ChatColor.YELLOW + "The faction " + relation.toChatColour() + (player == null ? faction.getName() : faction.getName()) + ChatColor.YELLOW + " has been " + ChatColor.GREEN
                    + "created" + ChatColor.YELLOW + " by " + ChatColor.AQUA + (sender instanceof Player ? ((Player) sender).getName() : sender.getName()) + ChatColor.YELLOW + '.';
            player.sendMessage(msg);
        }
    }
}
 
Example 18
Project: SamaGamesAPI   File: GameUtils.java   View Source Code Vote up 4 votes
/**
 * Broadcast a sound to all players
 *
 * @param sound Sound
 */
public static void broadcastSound(Sound sound)
{
    for(Player player : Bukkit.getOnlinePlayers())
        player.playSound(player.getPlayer().getPlayer().getLocation(), sound, 1, 1);
}
 
Example 19
Project: MT_Core   File: CustomScoreboards.java   View Source Code Vote up 4 votes
public void updateScoreboard() {
	for (Player p : Bukkit.getOnlinePlayers()) {
		p.setScoreboard(pkTeamsBoard);
	}
}
 
Example 20
Project: Kineticraft   File: Core.java   View Source Code Vote up 2 votes
/**
 * Get all online players, safe for async operations.
 * @return players
 */
public static Set<Player> getOnlineAsync() {
    return new HashSet<>(Bukkit.getOnlinePlayers());
}