本文整理了Java中org.bukkit.Bukkit.getOnlinePlayers()
方法的一些代码示例,展示了Bukkit.getOnlinePlayers()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Bukkit.getOnlinePlayers()
方法的具体详情如下:
包路径:org.bukkit.Bukkit
类名称:Bukkit
方法名:getOnlinePlayers
暂无
代码示例来源:origin: Bukkit/Bukkit
@Override
public boolean execute(CommandSender sender, String currentAlias, String[] args) {
if (!testPermission(sender)) return true;
StringBuilder online = new StringBuilder();
final Collection<? extends Player> 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.toString());
return true;
}
代码示例来源:origin: Bukkit/Bukkit
private void processIPBan(String ip, CommandSender sender, String reason) {
Bukkit.getBanList(BanList.Type.IP).addBan(ip, reason, null, sender.getName());
// Find all matching players and kick
for (Player player : Bukkit.getOnlinePlayers()) {
if (player.getAddress().getAddress().getHostAddress().equals(ip)) {
player.kickPlayer("You have been IP banned.");
}
}
Command.broadcastCommandMessage(sender, "Banned IP Address " + ip);
}
代码示例来源:origin: GlowstoneMC/Glowstone
@Override
public boolean execute(CommandSender sender, String label, String[] args,
CommandMessages commandMessages) {
if (!testPermission(sender, commandMessages.getPermissionMessage())) {
return true;
}
Collection<? extends Player> players = Bukkit.getOnlinePlayers();
Collection<String> messages =
new ArrayList<>(players.size() + 1);
messages.add(new LocalizedStringImpl("list.header", commandMessages.getResourceBundle())
.get(players.size(), Bukkit.getMaxPlayers()));
if (args.length > 0 && (Objects.equals(args[0], "uuids" /* NON-NLS */) || Objects
.equals(args[0], "ids" /* NON-NLS */))) {
LocalizedStringImpl nameAndUuidMessage = new LocalizedStringImpl("list.name-and-uuid",
commandMessages.getResourceBundle());
Bukkit.getOnlinePlayers().forEach(p -> messages.add(
nameAndUuidMessage.get(p.getName(), UuidUtils.toString(p.getUniqueId()))));
} else {
Bukkit.getOnlinePlayers().forEach(p -> messages.add(p.getName()));
}
sender.sendMessage(messages.toArray(EMPTY));
return true;
}
代码示例来源:origin: Bukkit/Bukkit
@Override
public boolean execute(CommandSender sender, String currentAlias, String[] args) {
if (!testPermission(sender)) return true;
Command.broadcastCommandMessage(sender, "Stopping the server..");
Bukkit.shutdown();
String reason = this.createString(args, 0);
if (StringUtils.isNotEmpty(reason)) {
for (Player player : Bukkit.getOnlinePlayers()) {
player.kickPlayer(reason);
}
}
return true;
}
代码示例来源:origin: GlowstoneMC/Glowstone
sendBullet(sender, t, b, "glowstone.about.api-version", Bukkit.getBukkitVersion());
sendBullet(sender, t, b, "glowstone.about.players",
Bukkit.getOnlinePlayers().size());
sendBullet(sender, t, b, "glowstone.about.worlds", Bukkit.getWorlds().size());
sendBullet(sender, t, b, "glowstone.about.plugins",
代码示例来源:origin: MylesIsCool/ViaVersion
@Override
public ViaCommandSender[] getOnlinePlayers() {
ViaCommandSender[] array = new ViaCommandSender[Bukkit.getOnlinePlayers().size()];
int i = 0;
for (Player player : Bukkit.getOnlinePlayers()) {
array[i++] = new BukkitCommandSender(player);
}
return array;
}
代码示例来源:origin: BentoBoxWorld/BentoBox
@Override
public Optional<List<String>> tabComplete(User user, String alias, List<String> args) {
return Optional.of(Bukkit.getOnlinePlayers().stream().map(Player::getName).collect(Collectors.toList()));
}
}
代码示例来源:origin: bitquest/bitquest
public void announce(final String message) {
for (Player player : Bukkit.getOnlinePlayers()) {
player.sendMessage(message);
}
}
代码示例来源:origin: FunnyGuilds/FunnyGuilds
public static void updatePlayers() {
for (Player player : Bukkit.getOnlinePlayers()) {
updatePlayer(player);
}
}
代码示例来源:origin: PyvesB/AdvancedAchievements
@Override
public void run() {
long currentTime = System.currentTimeMillis();
Bukkit.getOnlinePlayers().stream().forEach(p -> updateTime(p, currentTime));
previousRunMillis = currentTime;
}
代码示例来源:origin: ProSavage/SavageFactions
public void playSoundForAll(String sound) {
for (Player pl : Bukkit.getOnlinePlayers()) {
playSound(pl, sound);
}
}
代码示例来源:origin: games647/ScoreboardStats
public void updateGlobals() {
replacers.values()
.stream()
.filter(Replacer::isGlobal)
.filter(replacer -> !replacer.isEventVariable())
.forEach(replacer -> {
int score = replacer.scoreReplace(null);
String variable = replacer.getVariable();
Bukkit.getOnlinePlayers().forEach(player -> boardManager.updateVariable(player, variable, score));
});
}
代码示例来源:origin: MylesIsCool/ViaVersion
@Override
public void run() {
List<UUID> players = new ArrayList<>(handCache.keySet());
for (Player p : Bukkit.getOnlinePlayers()) {
handCache.put(p.getUniqueId(), convert(p.getItemInHand()));
players.remove(p.getUniqueId());
}
// Remove offline players
for (UUID uuid : players) {
handCache.remove(uuid);
}
}
代码示例来源:origin: DevLeoko/AdvancedBan
@Override
public void notify(String perm, List<String> notification) {
for (Player p : Bukkit.getOnlinePlayers()) {
if (hasPerms(p, perm)) {
for (String str : notification) {
sendMessage(p, str);
}
}
}
}
代码示例来源:origin: libraryaddict/LibsDisguises
@Override
public void onDisable() {
DisguiseUtilities.saveDisguises();
for (Player player : Bukkit.getOnlinePlayers()) {
DisguiseUtilities.removeSelfDisguiseScoreboard(player);
}
}
代码示例来源:origin: SpigotMC/Spigot-API
private void processIPBan(String ip, CommandSender sender, String reason) {
Bukkit.getBanList(BanList.Type.IP).addBan(ip, reason, null, sender.getName());
// Find all matching players and kick
for (Player player : Bukkit.getOnlinePlayers()) {
if (player.getAddress().getAddress().getHostAddress().equals(ip)) {
player.kickPlayer("You have been IP banned.");
}
}
Command.broadcastCommandMessage(sender, "Banned IP Address " + ip);
}
代码示例来源:origin: NyaaCat/RPGItems-reloaded
public static void refreshItem() {
for (Player player : Bukkit.getOnlinePlayers()) {
for (ItemStack item : player.getInventory()) {
Optional<RPGItem> rpgItem = ItemManager.toRPGItem(item);
rpgItem.ifPresent(r -> r.updateItem(item));
}
for (ItemStack item : player.getInventory().getArmorContents()) {
Optional<RPGItem> rpgItem = ItemManager.toRPGItem(item);
rpgItem.ifPresent(r -> r.updateItem(item));
}
}
}
代码示例来源:origin: MylesIsCool/ViaVersion
@Override
public void onReload() {
if (Bukkit.getPluginManager().getPlugin("ProtocolLib") != null) {
getLogger().severe("ViaVersion is already loaded, we're going to kick all the players... because otherwise we'll crash because of ProtocolLib.");
for (Player player : Bukkit.getOnlinePlayers()) {
player.kickPlayer(ChatColor.translateAlternateColorCodes('&', getConf().getReloadDisconnectMsg()));
}
} else {
getLogger().severe("ViaVersion is already loaded, this should work fine. If you get any console errors, try rebooting.");
}
}
代码示例来源:origin: TimoCloud/TimoCloud
public int getMaxPlayersAmount() {
try {
ServerListPingEvent event = new ServerListPingEvent(InetAddress.getLocalHost(), Bukkit.getMotd(), Bukkit.getOnlinePlayers().size(), Bukkit.getMaxPlayers());
Bukkit.getPluginManager().callEvent(event);
return event.getMaxPlayers();
} catch (Exception e) {
severe("Error while calling ServerListPingEvent: ");
TimoCloudBukkit.getInstance().severe(e);
return Bukkit.getMaxPlayers();
}
}
代码示例来源:origin: Dytanic/CloudNet
@EventHandler(priority = EventPriority.HIGHEST)
public void handle0(AsyncPlayerPreLoginEvent e)
{
for (Player all : Bukkit.getOnlinePlayers())
if (all.getUniqueId().equals(e.getUniqueId()))
{
e.disallow(AsyncPlayerPreLoginEvent.Result.KICK_BANNED, ChatColor.translateAlternateColorCodes('&', CloudAPI.getInstance().getCloudNetwork().getMessages().getString("server-kick-proxy-disallow")));
return;
}
CloudServer.getInstance().getPlayerAndCache(e.getUniqueId());
}
内容来源于网络,如有侵权,请联系作者删除!