Give all

Discussion in 'Plugin Development' started by WolfMaster, Aug 26, 2012.

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

    WolfMaster

    I am making a plugin for someone and i need to know how to give everyone an item in the server

    i have everything else

    here is the code so far

    Code:
    package me.wolfmaster.Give;
     
    import java.util.logging.Logger;
     
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;
    import org.bukkit.plugin.java.JavaPlugin;
     
    public class Main extends JavaPlugin{
       
    public final Logger logger = Logger.getLogger("Minecraft");
     
    public void onEnable(){
        logger.info("Give All Has Been Enabled!");
    }
     
    public void onDisable(){
        logger.info("Give All Has Been Disabled!");
    }
     
    public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args){
        Player player = (Player) sender;
        if(commandLabel.equalsIgnoreCase("giveall"));
       
        if(sender.hasPermission("giveall.allow"));
       
       
       
       
               
    }
    }
    
    All i need to know is the give all command part and then i can finish the code by myself :)
     
  2. Offline

    adde

    There should be some way to choose to "select" every player on the server, you know like you did there, Player player = (Player) sender;
    There should be something that choose all players on the server, I don't remember.
     
  3. Offline

    WolfMaster

    difficult that one! :(
     
  4. Offline

    keensta

    You can use
    Player[] all = Bukkit.getOnlinePlayers();
    Then use a loop to give them the items.
     
  5. Offline

    WolfMaster

    The loop would be...
     
  6. Offline

    Waterflames

  7. Offline

    keensta

    It's normally best to know java (bassic level) before developing plugins.
     
  8. Offline

    WolfMaster

    would it be possible for me just to use the normal give command and it work?

    i CAN make them, i have a basic level and i learn as i go along

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 28, 2016
  9. Offline

    keensta

    Well then when someone normally says a loop you should of got it but ok.
    Also as far as i know the give command will not work with all the players (Never tried)
    Do this
    Code:Java
    1.  
    2. Player[] all = Bukkit.getOnlinePlayers();
    3. for(Player ply1 : all){
    4. ply1.getInventory().addItem(new ItemStack(Material.APPLE));
    5. }
    6.  
     
  10. Offline

    08jne01

    what about:
    Code:
    for(Player player : Bukkit.getServer().getOnlinePlayers{
    //give items to players in here eg:
    player.getInventory().addItem(new ItemStack(Material.DIAMOND, 64);
    }
    
    That itterates through each player on the server.
     
  11. Offline

    WolfMaster

    can you do it so the amount is chooseable?
     
  12. Offline

    keensta

    Oh course just change the 64 to a int var. Then make the var get the int from a command argument.
     
  13. Offline

    WolfMaster

    ahh right, simple enough

    thats what i was going to do but i didnt know whether it would work or not

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 28, 2016
Thread Status:
Not open for further replies.

Share This Page