HELP! Im a noob coder :P

Discussion in 'Plugin Development' started by ImRayz66, Nov 13, 2014.

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

    ImRayz66

    Basically... i need help sending a message to everyone inside an array list!

    Btw the arraylist is called 'staff'

    Code:java
    1. if (cmd.getName().equalsIgnoreCase("callstaff")) {
    2. if(!(sender instanceof Player)) {
    3. sender.sendMessage(ChatColor.GREEN + "You need to be a player!");
    4. return true;
    5. }
    6. sender.sendMessage(ChatColor.GREEN + "" + ChatColor.BOLD + "You have called a staff member!");
     
  2. Offline

    JordyPwner

    Learn java before using the Bukkit Api
     
    davidp027 and mine-care like this.
  3. Offline

    ImRayz66

    dude.... thats what forums are for. I am new. I need to know pls
     
  4. Offline

    FerusGrim

    The forums are to assist authors/programmers when they get stuck.

    His suggesting that you learn Java before attempting to utilize the Bukkit API is assisting you.

    To answer your question, look up and learn what is and how to use a for-each loop. No one will spoon feed the answer to you for such a basic concept.
     
  5. Offline

    teej107

    ImRayz66 In case you haven't heard / read, creating Bukkit plugins require you to have a basic knowledge of Java, which you lack of. FerusGrim gave you the answer to further your Java knowledge. Good Luck!
     
    mine-care likes this.
  6. Offline

    VG.Developments

    For loop through all online players, then check if the online players have a certain perm, if they do, send them the msg.
     
  7. Offline

    teej107

    That's not even what the OP is asking. Btw there is a more simple way of doing that anyway.
     
  8. Offline

    VG.Developments

    teej107 How so? By my understanding, what i said would do exactly what he said.
     
  9. Offline

    jensdeboom

    ImRayz66 To get every object out of an ArrayList, you want to use a for loop:
    Code:java
    1. ArrayList<String> callstaff = new ArrayList<String>();
    2.  
    3. for(String s : callstaff){
    4. Player staff = Bukkit.getServer().getPlayer(s);
    5. staff.sendMessage("You have been called!");
    6. }

    ArrayLists and for-loops are basic Java tough, you should know a little more about Java before starting with the Bukkit API (no offence ;) ).
     
  10. Offline

    teej107

    He doesnt need permissions, he doesn't need every online player. His question was how to loop through a list called staff. Bukkit#broadcast(String message, String permission) will achieve the same effect as your answer with only one line of code.
     
  11. Offline

    FerusGrim

    jensdeboom
    Way to ignore everyone who was telling him to look up for-loops, and spoonfeeding him the answer anyways. :)

    Btw, Server#getPlayer probably isn't what you want to use. Just saying. I'm sure you can utilize the Javadocs to find which method you should be using.
     
  12. Offline

    BetaNyan

    Enhanced for loop of the list of players, send message.
     
  13. Offline

    jensdeboom

    FerusGrim I did tell him to learn some more Java, but why not explain to him what a for loop is and how to use it?

    teej107 he asked how to get every object of an ArrayList, nog how to send a message to everyone with a permission.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 29, 2016
  14. jensdeboom Doing so will encourage him to just copy the solution without knowing how it works. It'll give him a false sense of security and he'll continue onwards, only to encounter problems again, and will rely on people to solve it for him again. :)
     
    FerusGrim likes this.
  15. Offline

    teej107

Thread Status:
Not open for further replies.

Share This Page