How to do this?

Discussion in 'Spigot Plugin Development' started by ServerProxy, Apr 29, 2017.

  1. So I stored my ToDoList in a ArrayList with /add <ARGUMENT>, I want to know how do I show that to a player? I can't do, Sender.sendmessage(todolist);

    Sadly I can not give the code, as this is a private plugin. The Array List's name is todolist.
     
  2. I am not the best of coders. How do I do this?
     
  3. Similar to this..
    Code (Text):

    for(String message : arrayOfMessages){
    //Send message
    }
     
     
  4. I recommend you take some Java tutorials before you dive into development of bukkit plugins. This will allow you to get faster at developing your plugins and prevent you from waiting for a response from us when you need help.

    A quick Google search should yield plenty, I'm happy to help as well. Good luck!
     
    • Agree Agree x 1
  5. This does not work :/ Can you add diyar.sav on skype, so I can show you through join.me?
     
  6. i don't use skype anymore so no, but you can put your code in a code block here or you upload the source to github / pastebin so i can take a look at what you made
    Also what do you mean by "that doesn't work" ? What have you tried to implement?
     
  7. This is exactly how you need to go about it you'll have to replace arrayOfMessages with your list/array



    Sent from my iPhone using Tapatalk
     
  8. Learn the language before you start using Spigot and Bukkit. For me, someone who does, this is quite a simple question and would've been done without question.
    To answer you'res tho, use a for loop, if you don't know what that is, learn it.
     
    • Agree Agree x 1
  9. https://gyazo.com/7a6047eb510b85f084703d73f3f6ebd6

    Code:

    Code (Text):
    package me.diyar.todolist.commands;

    import java.util.ArrayList;

    import org.bukkit.ChatColor;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandExecutor;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;
    import org.bukkit.plugin.java.JavaPlugin;

    public class Commands extends JavaPlugin implements CommandExecutor {

       
       
           
        for(String message : todolist){
           
        }
            //Send message
           
           
       
        ArrayList todolist = new ArrayList();
       
       
        public static String setColours(String s) {
            return ChatColor.translateAlternateColorCodes('&', s);
        }

        @Override
        public boolean onCommand(CommandSender sender, Command cmd, String cmdlabel, String[] args) {
            if (cmd.getName().equalsIgnoreCase("add")) {
                if (!(sender.hasPermission("todolist.add")))
                    sender.sendMessage("&cYou don't have the required permissions.");
                if (args.length == 0) {
                    sender.sendMessage("&cUsage: &7/add &7&l <OBJECTIVE>");
                if (args.length == 1) {
                    todolist.add(args[0]);
                if (args.length == 2) {
                    sender.sendMessage("&cUsage: &7/add &7&l <OBJECTIVE");
               
            if (cmd.getName().equalsIgnoreCase("todo")) {
               
                   
                if (!(sender.hasPermission("todolist.list"))) {
                    sender.sendMessage("&cYou don't have the required permissions.");
                }else if (!(sender instanceof Player)) {
                    sender.sendMessage("&cYou can not look at the list! Try ingame!");
                }else if (args.length == 0) {
                    sender.sendMessage(message);
                }
                   
                }
                   
                }
                }
                   
                }
                   
                }
                     
            }
            return true;
        }

    }
         
     
    No red underlines are there, but when I add the loop there is red underlines. Look at the gyazo for where the red lines are.
     
  10. Are you going to specify you're arraylist? What error is it giving you? Tell us, don't expect us to know.
    Also, you stated you're arraylist after you stated you're for loop. Again, learn java
     
  11. This won't fix you problem, but when sending messages with colours, just use the ChatColor enum, it's easier and works better as well
     
  12. I swear sometimes I need a good pinch in my arm to check if I'm still awake and not having a nightmare.
     
    • Agree Agree x 2
    • Funny Funny x 1
  13. Why do you use my code at the top of your class in no constructor?
     
  14. I don't understand, that's why.
     
  15. You would understand if you learnt Java first.
    Code must be inside some method.
     
  16. s
    Uhm, sorry mate. If your gonna be like
    Don't reply.
     
  17. Be like what? Realistic?
    I'm sorry, but if you don't know Java, plugin development isn't going to be for you.
    If you learn Java first you will understand what you have done wrong.
    As I said before, your code needs to be in some method.
     
  18. Hi :)
    This is a forum for people who need help with Spigot.
    This is not a Java babysitting service.
    Cya :)
     
  19. well it's true. these are things that are very basic fundamentals of the language, and by not knowing them, you cause more problems when given a solution to a first occurring problem. such as how we have here