本文整理匯總了Java中org.bukkit.Bukkit.getOnlinePlayers方法的典型用法代碼示例。如果您正苦於以下問題:Java Bukkit.getOnlinePlayers方法的具體用法?Java Bukkit.getOnlinePlayers怎麽用?Java Bukkit.getOnlinePlayers使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.bukkit.Bukkit
的用法示例。
在下文中一共展示了Bukkit.getOnlinePlayers方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: onTabComplete
import org.bukkit.Bukkit; //導入方法依賴的package包/類
@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;
}
示例2: sendSound
import org.bukkit.Bukkit; //導入方法依賴的package包/類
/**
* 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);
}
}
示例3: onPreStart
import org.bukkit.Bukkit; //導入方法依賴的package包/類
@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")));
}
示例4: wakePlayer
import org.bukkit.Bukkit; //導入方法依賴的package包/類
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());
}
}
示例5: updatePlayer
import org.bukkit.Bukkit; //導入方法依賴的package包/類
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;
}
示例6: onDisable
import org.bukkit.Bukkit; //導入方法依賴的package包/類
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.");
}
示例7: run
import org.bukkit.Bukkit; //導入方法依賴的package包/類
/**
* 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()));
}
示例8: onCommand
import org.bukkit.Bukkit; //導入方法依賴的package包/類
@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;
}
示例9: execute
import org.bukkit.Bukkit; //導入方法依賴的package包/類
@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;
}
示例10: updateSpectators
import org.bukkit.Bukkit; //導入方法依賴的package包/類
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);
}
}
}
示例11: broadcast
import org.bukkit.Bukkit; //導入方法依賴的package包/類
/**
* 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);
}
示例12: onTick
import org.bukkit.Bukkit; //導入方法依賴的package包/類
@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);
}
}
}
}
}
示例13: run
import org.bukkit.Bukkit; //導入方法依賴的package包/類
@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--;
}
示例14: hidePlayer
import org.bukkit.Bukkit; //導入方法依賴的package包/類
public static void hidePlayer(Player p) {
for (Player player : Bukkit.getOnlinePlayers()) {
p.hidePlayer(player);
}
PVPlayer.remove(p);
}
示例15: sendTo
import org.bukkit.Bukkit; //導入方法依賴的package包/類
/**
* 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);
}
}