Locations not loading

Discussion in 'Plugin Development' started by crushh87, Jan 27, 2013.

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

    crushh87

    Okay, so I am sorta having a problem with my locations wanting to be used after a reload.
    Yes, I have saved the X,Y,Z to the config for the locations.

    So:
    Player sets Location.
    (the location's X,Y,Z are saved to the config)
    Player teleports to location
    Server Reloads.
    Player attempts to teleport to the location
    Internal error on the line player.teleport(Loc);

    One Example of setting the location
    [syntax = java]
    Code:
    }else if (args[0].equalsIgnoreCase("setlobby")){
                        if(player.hasPermission("bx.admin")){
                        Location lobbyLoc = player.getLocation();
                        this.lobbyLoc = lobbyLoc;
                        double x = lobbyLoc.getX();
                        double y = lobbyLoc.getY();
                        double z = lobbyLoc.getZ();
                        this.getConfig().set("lobbyLoc.X", x);
                        this.getConfig().set("lobbyLoc.Y", y);
                        this.getConfig().set("lobbyLoc.Z", z);
                        this.getConfig().set("lobbyLoc.world", lobbyLoc.getWorld().getName());
                        player.sendMessage(ChatColor.GREEN + "[Boxing] Lobby Saved!");
                        this.saveConfig();
                   
                        return true;
                        }
    [/syntax]

    On enable and disable
    Code:java
    1.  
    2. @Override
    3. public void onDisable(){
    4. PluginDescriptionFile pdfFile = this.getDescription();
    5. this.logger.info(ChatColor.RED + pdfFile.getName() + "Has Been Enabled");
    6. this.saveConfig();
    7.  
    8. }
    9.  
    10. @Override
    11. public void onEnable(){
    12. PluginDescriptionFile pdfFile = this.getDescription();
    13. this.logger.info(pdfFile.getName() + " Version " + pdfFile.getVersion()
    14. + " Has Been Disabled! ");
    15. PluginManager manager = this.getServer().getPluginManager();
    16. manager.registerEvents(new BoxingListener(this), this);
    17. getServer().getScheduler().scheduleAsyncRepeatingTask(this, new Runnable(){
    18. public void run(){
    19. for(Player online: Bukkit.getOnlinePlayers()){
    20. String pName = online.getName();
    21. if(player1.contains(pName) || player2.contains(pName)){
    22. if(online.getHealth() <= 8){
    23. PotionEffect confuse = new PotionEffect(PotionEffectType.CONFUSION, 401, 0);
    24. PotionEffect blind = new PotionEffect(PotionEffectType.BLINDNESS, 401, 0);
    25. online.addPotionEffect(confuse);
    26. online.addPotionEffect(blind);
    27.  
    28. }
    29. }
    30. }
    31. }
    32. }, 0, 10L);
    33.  
    34.  
    35. }
    36.  
     
  2. Offline

    ZeusAllMighty11

    I'd guess it's because you don't initialize the variable when the plugin needs it to , as it's only initialized when you set the config values. Therefore, NPE
     
  3. Offline

    crushh87

    How would you suggest fixing this?
     
  4. Offline

    ZeusAllMighty11

    Code:
    Location loc;
    double locx;
    double locy;
    doubel locz;
     
    locx = plugin.getConfig().getDouble("Something.Path.x");
    locy = plugin.getConfig().getDouble("Something.Path.y");
    locz = plugin.getConfig().getDouble("Something.Path.z");
     
    //
     
    public boolean onCommand(...){
        ... if(args[1] equals ignore case("setlobby")){
            plugin.getConfig().set("Something.path.x", p.getLocation().getX();
            // same for y
            // same for z
        }
    }
     
    // when it comes to teleporting
     
    loc = new Location(world, locx,locy,lcz);
    
     
  5. Offline

    blablubbabc

    If the world is not loaded, getWorld(worldname) returns null :(
     
Thread Status:
Not open for further replies.

Share This Page