All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.bukkit.command.defaults.ListCommand Maven / Gradle / Ivy

There is a newer version: 2.4.0
Show newest version
package org.bukkit.command.defaults;

import com.google.common.collect.ImmutableList;
import org.apache.commons.lang.Validate;
import org.bukkit.Bukkit;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;

import java.util.Collection;
import java.util.List;

@Deprecated
public class ListCommand extends VanillaCommand {
  public ListCommand() {
    super("list");
    this.description = "Lists all online players";
    this.usageMessage = "/list";
    this.setPermission("bukkit.command.list");
  }

  @Override
  public boolean execute(CommandSender sender, String currentAlias, String[] args) {
    if (!testPermission(sender)) return true;

    StringBuilder online = new StringBuilder();

    final Collection players = Bukkit.getOnlinePlayers();

    for (Player player : players) {
      // If a player is hidden from the sender don't show them in the list
      if (sender instanceof Player && !((Player) sender).canSee(player))
        continue;

      if (online.length() > 0) {
        online.append(", ");
      }

      online.append(player.getDisplayName());
    }

    sender.sendMessage("There are " + players.size() + "/" + Bukkit.getMaxPlayers() + " players online:\n" + online);

    return true;
  }

  @Override
  public List tabComplete(CommandSender sender, String alias, String[] args) throws IllegalArgumentException {
    Validate.notNull(sender, "Sender cannot be null");
    Validate.notNull(args, "Arguments cannot be null");
    Validate.notNull(alias, "Alias cannot be null");

    return ImmutableList.of();
  }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy