Java.util.ArrayList cannot be cast to org.bukkit.World

Discussion in 'Plugin Development' started by JustFrozen, Jan 29, 2019.

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

    JustFrozen

    Hi, I have a problem.
    Booting or reloading my Minecraft server is no problem but when I type in this special command I get an errorcode in the console:

    upload_2019-1-29_22-33-28.png

    Here are my Classes:
    Main:

    upload_2019-1-29_22-36-4.png


    Plugin.yml:
    upload_2019-1-29_22-37-8.png

    And my class with the command:

    Code:
    package de.justfrozen.advtools.cmds;
    
    
    import org.bukkit.Bukkit;
    import org.bukkit.World;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandExecutor;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;
    
    public class TimeSet implements CommandExecutor {
    
        @Override
        public boolean onCommand(CommandSender s, Command cmd, String label, String[] args) {
            if(s instanceof Player) {
                World w = (World) Bukkit.getServer().getWorlds();
                Player p = (Player) s;
            
                if(p.hasPermission("advtools.timeset")) {
                    if(args.length == 1) {
                    
                        if(args[0].equalsIgnoreCase("morning")) {
                            p.sendMessage("§6Zeit wurde auf §c24000 §6gestellt");
                            w.setTime(24000L);
                            w.getTime();
                        
                        }else if(args[0].equalsIgnoreCase("day")) {
                            p.sendMessage("§6Zeit wurde auf §c6000 §6gestellt");
                            w.setTime(6000L);
                        
                        }else if(args[0].equalsIgnoreCase("evening")) {
                            p.sendMessage("§6Zeit wurde auf §c12000 §6gestellt");
                            w.setTime(12000L);
                        
                        }else if(args[0].equalsIgnoreCase("night")) {
                            p.sendMessage("§6Zeit wurde auf §c18000 §6gestellt");
                            w.setTime(18000L);
                        
                        }else
                            p.sendMessage("§7/w §6<clear:sun:rain:thunder>");
                    
                    }else
                        p.sendMessage("§7/w §6<clear:sun:rain:thunder>");
                    
                    } else
                        p.sendMessage("§cNicht genügend Rechte");
              
          
            } else
                  s.sendMessage("In der Konsole nicht verfuegbar");
            return false;
    }
    }
    There are no Errors in the code
     
    Last edited by a moderator: Jan 30, 2019
  2. Offline

    KarimAKL

    This line is the problem, 'getWorlds()' returns an arraylist of worlds, not a world.
     
  3. Offline

    JustFrozen

    Thank you! Any ideas to fix the error now?
    My goal is to control the time through commands in minecraft
     
  4. Offline

    timtower Administrator Administrator Moderator

  5. Offline

    KarimAKL

    @JustFrozen You could do 'Bukkit.getServer().getWorld("name_of_world");', then you could make the command specify the world with an argument and then get the world with the name of that argument, of course check if a world exists with that name.
     
  6. Offline

    JustFrozen

    Okay thank you, I'll try in a min

    Thanks! it worked

    @timtower
    The world in which the player stands at the moment

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jan 30, 2019
    KarimAKL likes this.
Thread Status:
Not open for further replies.

Share This Page