Help please!

Discussion in 'Plugin Development' started by Epixel, Sep 11, 2016.

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

    Epixel

    I've coded a plugin with basic staff commands. Below, you will see the /freeze command. I coded this plugin on my laptop, and everything worked perfectly. However, when I move the code to my main computer, I get errors on the code that had no errors at all on my laptop. The error is: "Can only iterate over an array or an instance of java.lang.Iterable". The error is where it says "for (Player frozen : ERROR ->frozen<-ERROR)"
    Code:
    public class Main extends JavaPlugin implements Listener {
    
        private ArrayList<Player> frozen = new ArrayList<Player>();
    
        public void onEnable() {
            getLogger().info("eCore has been enabled");
            registerCommands();
            registerEvents();
            Bukkit.getServer().getScheduler().scheduleSyncRepeatingTask(this, new Runnable() {
                public void run() {
                    for (Player all : Bukkit.getServer().getOnlinePlayers())
                        if (frozen.contains(all)) {
                            for (Player frozen : frozen) {
                                frozen.sendMessage(ChatColor.GRAY + "                     ");
                                frozen.sendMessage(ChatColor.DARK_RED + "YOU HAVE BEEN FROZEN!");
                                frozen.sendMessage(ChatColor.RED + "YOU HAVE 5 MINUTES TO JOIN TEAMSPEAK!");
                                frozen.sendMessage(ChatColor.RED + "https://www.teamspeak.com/downloads");
                                frozen.sendMessage(ChatColor.RED + "TeamSpeak IP:");
                                frozen.sendMessage(ChatColor.RED + "DO NOT LOG OUT, IT WILL RESULT IN A PERMANENT BAN!");
                                frozen.sendMessage(ChatColor.GRAY + "                     ");
                            }
    
                        }
                }
            }, 0, 100);
    
        }
     
  2. Offline

    Kermit_23

    you are missing a bracket at for (Player all : Bukkit.getServer().getOnlinePlayers())
     
  3. Offline

    Epixel

    So it should say "(Player all : Bukkit.getServer().getOnlinePlayers())" ?
    Because I did that and it didn't work
     
  4. Offline

    timtower Administrator Administrator Moderator

    @Epixel Updated code?
    for (Player frozen : frozen) {
    And that assigns to itself, or tries to loop through itself.
    Please keep an eye on your variables.
     
  5. @Epixel Didn't you already have a thread on this issue?

    No bracket therefor will only run the 1 line under

    Why are you looping through all the frozen players for each player? That means if there are 20 online the frozen players will be messaged 20 times.
     
  6. Offline

    Epixel

    No, I've never had a thread about this.

    What I don't get, is that this worked on my laptop..?

    *deleted message*

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
  7. Offline

    JanTuck

    It shouldnt have worked on your laptop

    Sent from Tapatalk
     
    Zombie_Striker likes this.
Thread Status:
Not open for further replies.

Share This Page