Solved Easy - how to get the spawnpoint of a world?

Discussion in 'Plugin Development' started by kaskoepoes112, Feb 8, 2013.

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

    kaskoepoes112

    hey,

    So I've a problem,
    I want to get the spawn point of the world (the defaultspawnpoint)
    So I thought lets make this code:

    Code:
    private Location spawnpoint = getServer().getWorld("world").getSpawnLocation();
    doesn't work (null pointer)

    or :

    Code:
    private Location spawnpoint = new Location (getServer().getWorld("world").getSpawnLocation());

    that doesn't work too (it's not even good java :S but I had no idea what else to do)

    I've sesriously no idea how to do this .. (sorry I'm new here)
    Please help :)!

    thanks ! :D
     
  2. Offline

    Yukari

    Should work, can you post the rest of your code, and also exactly what the error says?
     
  3. If you're using other plugins that effect the spawn-points of a world they might be interfering.
    We'll need to see the rest of the code, the stack trace as well as a list of other plugins you have.
     
  4. If the NPE triggers on that first line you posted, then getServer() or getWorld() returns null, not getSpawnLocation().

    And you really shouldn't hardcode world name... I belive .getWorlds().get(0) will give you the main world but you should asign it in onEnable().
     
  5. Offline

    RealDope

    Also I don't think you have to create a new location object, you can just set the location equal to .getSpawnLocation()
     
  6. Offline

    kaskoepoes112

    still not working :(

    my full code for now:

    Code:
    package com.hotmail.kwolsink.CkasSurvival;
     
     
    import org.bukkit.Bukkit;
    import org.bukkit.ChatColor;
    import org.bukkit.Location;
    import org.bukkit.World;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.player.PlayerLoginEvent;
    import org.bukkit.plugin.java.JavaPlugin;
     
     
     
    public class CkasSurvival extends JavaPlugin
    {
     
        // ..
     
     
     
        int TijdvoorStart = 120;
     
        World world = this.getServer().getWorlds().get(0);
     
        // ..
     
     
     
     
        @Override
        public void onEnable()
        {
            getLogger().info("CkasSurvival is ready to go!");
            getCommand("kit").setExecutor(new CkasSurvivalCommands());
         
        }
     
     
         
     
     
        public void matchCountdown()
        {
     
     
        Bukkit.broadcastMessage(ChatColor.RED + "Match starting in 120 secconds!"); 
     
        this.getServer().getScheduler().scheduleSyncDelayedTask(this, new Runnable() {
            @Override
            public void run() {
             
                if (! (TijdvoorStart == - 1))
                {
                TijdvoorStart = TijdvoorStart - 15;
                getServer().broadcastMessage("Match starts in " + TijdvoorStart + " secconds!");
                // ..
                if (TijdvoorStart == 0)
                {
                    TijdvoorStart --;
                    final Player[] PLAYERS_MEEDOEN = Bukkit.getOnlinePlayers();
                    for (int x = 0 ; x < PLAYERS_MEEDOEN.length ; x ++)
                    {
                        PLAYERS_MEEDOEN[x].teleport(world.getSpawnLocation());
                    }
                 
                }
             
                }
            }
        }, 300L); // 20L = 1 seconde , nu om de 15 seconde
     
        }
    }
     
    
    but it is this line :


    Code:
      World world = this.getServer().getWorlds().get(0);
    :/
    I didn't put that line in my onEnable() method because I've no idea how to use it in the scheduler method if it's in the onEnable method :S

    but I got a nullpointer again and it's just that one line of code

    sorry , late reply :p
     
  7. Offline

    Tirelessly

    Code:
    World world; //put that where it is now
     
    onEnable(){
    ...
    world = getServer().getWorlds().get(0);
    ...
    }
    
     
    kaskoepoes112 and AlexLeporiday like this.
  8. If there isnt a world called "world", it will return null.
    Remember: World names are Sometimes case sensetive
     
  9. Offline

    kaskoepoes112

    oh lol thanks a lot!

    I told you I was a noob XD
     
Thread Status:
Not open for further replies.

Share This Page