Locations not saving?!

Discussion in 'Plugin Development' started by DaanSander, Mar 18, 2015.

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

    DaanSander

    Hello I am creating a plugin with spawns but i want to save te spawn location in my config but it isnt saving

    command to save file:
    Code:
    package me.daansander.amhub.command;
    
    import me.daansander.amhub.AmHub;
    import org.bukkit.Location;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandExecutor;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;
    
    /**
    * Created by Daan on 18-3-2015.
    */
    public class SetSpawn implements CommandExecutor {
    
        @Override
        public boolean onCommand(CommandSender sender, Command cmd, String s, String[] args) {
            if(cmd.getName().equalsIgnoreCase("setspawn") && sender instanceof Player) {
                Player p = (Player) sender;
                Location loc = p.getLocation();
                AmHub.plugin.getConfig().set("Spawn.w", loc.getWorld().getName());
                AmHub.config.set("Spawn.x ", loc.getX());
                AmHub.config.set("Spawn.y ", loc.getY());
                AmHub.plugin.getConfig().set("Spawn.z ", loc.getZ());
                p.sendMessage(loc.getWorld().getName() + loc.getX() + loc.getY() + loc.getZ());
                p.sendMessage("spawn set!");
                return true;
            }
            return true;
        }
    }
    
    main:
    Code:
    package me.daansander.amhub;
    
    import me.daansander.amhub.command.SetSpawn;
    import me.daansander.amhub.listeners.PlayerJoin;
    import org.bukkit.Bukkit;
    import org.bukkit.configuration.file.FileConfiguration;
    import org.bukkit.permissions.Permission;
    import org.bukkit.plugin.java.JavaPlugin;
    
    /**
    * Created by Daan on 18-3-2015.
    */
    public class AmHub extends JavaPlugin {
    
        public static FileConfiguration config;
        public static AmHub plugin = null;
    
        public Permission fly = new Permission("AmHub.fly");
    
        public void onEnable() {
            plugin = this;
            config = getConfig();
            saveDefaultConfig();
            Bukkit.getConsoleSender().sendMessage("Starting AMHUB by DaanSander");
            getServer().getPluginManager().registerEvents(new PlayerJoin(), this);
            getCommand("setspawn").setExecutor(new SetSpawn());
        }
    
    }
    
    sorry for bad enlgish
     
  2. @DaanSander You aren't saving the config in your command.
     
  3. Offline

    Zombie_Striker

    You have to save your config with " saveConfig(); "

    Also, in your onCommand, you have a useless return true; statement. Remove the first statement.
     
  4. Offline

    DaanSander

    thx just 1 question left how can i teleport the player to that location?
     
  5. Offline

    Zombie_Striker

    player#teleport();
     
  6. Offline

    DaanSander

    @Zombie_Striker but how can i teleport the player to the saved location in the config
     
  7. Offline

    nverdier

    @DaanSander Player#teleport(Location location)

    Use the location you get from the config.
     
  8. Offline

    DaanSander

    i know that but howwwwwwwwwww my config looks like:
    Code:
    Spawn:
      x: 1325.221988512501
      y: 4.0
      z: 214.24360841989392
      w: world
     
  9. Offline

    ColonelHedgehog

    Use Location's constructor. ;)
    Code:
    new Location(w, x, y, z);
     
  10. And to get values use for example:
    int x = config.getInt("x");
    World w = Bukkit.getWorld(config.getString("w"));
     
Thread Status:
Not open for further replies.

Share This Page