Setting player spawn points

Discussion in 'Plugin Development' started by the_merciless, Apr 20, 2012.

  1. Offline

    the_merciless

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    i want to type /sp to save my position in the config, then /sp again to save the next position, and so on
    but my code doesnt quite work. the first time i use the command it saves my posistion in the config but still returns false, and the second time i use it, it saves my position again but overwrites first position and still returns false. any ideas?

    Code:
      public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args ){
        int point = 1;
            if(cmd.getName().equalsIgnoreCase("sp")){
            Player p = (Player)sender;
            double x = p.getLocation().getX();
            double y = p.getLocation().getY();
            double z = p.getLocation().getZ();
            getConfig().set(point + " x", x);
            getConfig().set(point + " y", y);
            getConfig().set(point + " z", z);
            saveConfig();
            p.sendMessage(ChatColor.BLUE + "You have set the spawn point for player " + point);
            point ++;
         
            }
         
            return false;
     
        }

    This post has been edited 1 time. It was last edited by the_merciless Apr 20, 2012.
  2. Offline

    Njol

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Make point static. The value of a local variable is not persistent across invocations of the block they are defined in. You'll likely have to save it in the config as well and load it when your plugin is enabled.
  3. Offline

    the_merciless

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    thx worked well

Share This Page