[Help] List

Discussion in 'Spigot Plugin Development' started by SwagiWagi, Jun 9, 2016.

  1. Hey guys!

    When the player types /website I want it to send him a message from the list from config.yml.
    This is my code:
    Code (Text):
    package me.rom.com;

    import java.util.List;

    import org.bukkit.command.Command;
    import org.bukkit.command.CommandExecutor;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;

    public class Commands implements CommandExecutor {
       
        private Core plugin;
       
        public Commands(Core pl) {
            plugin = pl;
        }
        public boolean onWebsite(CommandSender sender, Command cmd, String label, String[] arg3) {
            if((label.equalsIgnoreCase("website"))) {
                if (!(sender instanceof Player)){
                    sender.sendMessage("Hey! You must be a player to use this command!");
                    return false;
                }
                Player player = (Player) sender;
            List<String> ws = plugin.getConfig().getStringList("Website");
                for (String wsm : ws);{
                player.sendMessage(wsm);
        }
                return true;
        }
        }
    }
     
    What is wrong?
     
  2. MiniDigger

    Supporter

    remove that ';' there
     
  3. Thank you, why is there an error on here:
    Code (Text):
    public class Commands implements CommandExecutor {
     
    On "Commands"
     
  4. MiniDigger

    Supporter

    > an error
    much infos, very useful, much wow.
     
  5. MiniDigger

    Supporter

    every command executor need to have a onCommand method. why did you name your method onWebsite? it needs to be named onCommand
     
  6. Oops, thanks.
    [​IMG]
     
  7. MiniDigger

    Supporter

    I will not fixing every little beginner mistake you have made. you can't call the getConfig method in a random class, it only works in the main class or using a reference to your main class.
     
  8. Thank you.
     
  9. May anyone else help me on how to fix the error?
     
  10. MiniDigger

    Supporter

    I did tell you how to fix it, if you don't understood what I said -> go learn java
     
    • Agree Agree x 1
  11. Let me tell it like this:
    How do I reference it?
     
  12. MiniDigger

    Supporter

    you already kinda did it. you have a reference to your main class in your command executor, you just need to use it...