Give items to all online players?

Discussion in 'Plugin Development' started by itsatacoshop247, Mar 21, 2011.

Thread Status:
Not open for further replies.
  1. Offline

    itsatacoshop247

    I've got it set to give an item to a single player, but I'm not sure how to give items to all players.
    Also if theres anything that needs imported I'd like to know. Heres what I have:

    Code:
    plugin.getServer().broadcastMessage(ChatColor.RED + "Everyone else got some iron irgnots!");
    player.getInventory().addItem(new ItemStack(265, randomnumber)); //needs to be not just 1 player
     
  2. Offline

    Crash

    Code:
    for(Player p :server.getOnlinePlayers()){
    
        p.getInventory().addItem(new ItemStack(265, randomnumber));
        p.updateInventory();
    
    }
     
  3. Offline

    itsatacoshop247

    Thanks for the fast reply. ':server' gives me and error, and updateInventory(); is deprecated (or so it says in eclipse).
     
  4. Offline

    Crash

    You can use plugin.getServer() to get the server.
    There is probably another way to update the inventory but I'll use updateInventory until they remove it.
     
  5. Offline

    itsatacoshop247

    I went and tried getServer() first but I forgot the plugin.
    But for(Player p: plugin.getServer().getOnlinePlayers()){ is working fine, Thank you kindly!
     
  6. Offline

    Drakia

    player.updateInventory() is deprecated but as far as I know is the only method with which you can force a players inventory to show changes right away.
     
Thread Status:
Not open for further replies.

Share This Page