Not saved to config file

Discussion in 'Plugin Development' started by Pollio, Jan 24, 2016.

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

    Pollio

    I'm trying to save to locations to a config fille, but for some reason it doesn't work. Can someone take a look at it?

    Thanks in advance

    This is my main class
    Code:
    package me.Apolioo;
    
    import org.bukkit.ChatColor;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;
    import org.bukkit.plugin.java.JavaPlugin;
    
    public class MyFirstPlugin extends JavaPlugin {
       
        @Override
        public void onEnable() {
            getLogger().info("LEAGUE OF LEGENDS 1.0");
            getConfig().options().copyDefaults(true);
            saveConfig();   
        }
       
        @Override
        public void onDisable() {
           
        }
       
        //Command    
        public boolean onCommand1(CommandSender sender, Command cmd, String label, String[] args){
           
            if (cmd.getName().equalsIgnoreCase("spawn1") && sender instanceof Player) {
               
                Player player  = (Player) sender;
                getConfig().set("loc1.world", player.getLocation().getWorld().getName());
                getConfig().set("loc1.x", player.getLocation().getX());
                getConfig().set("loc1.y", player.getLocation().getY());
                getConfig().set("loc1.z", player.getLocation().getZ());
                saveConfig();
                player.sendMessage(ChatColor.GREEN + "Spawn 1 is gezet!");
               
               
               
                return true;
               
            }
           
             return false;
        }
    
    
    public boolean onCommand2(CommandSender sender, Command cmd, String label, String[] args){
        
         if (cmd.getName().equalsIgnoreCase("spawn2") && sender instanceof Player) {
            
             Player player  = (Player) sender;
                getConfig().set("loc2.world", player.getLocation().getWorld().getName());
                getConfig().set("loc2.x", player.getLocation().getX());
                getConfig().set("loc2.y", player.getLocation().getY());
                getConfig().set("loc2.z", player.getLocation().getZ());
                saveConfig();
                player.sendMessage(ChatColor.GREEN + "Spawn 2 is gezet!");
               
               
                return true;
         }
        
         return false;
        
    }
    }
    
    Plugin.yml
    Code:
    name: MyFirstPlugin
    main: me.Apolioo.MyFirstPlugin
    version: 1.0
    commands:
       spawn1:
          description: Zet Spawn1
          usage: /<command>
       spawn2:
          description: Zet Spawn2
          usage: /<command>
    Config.yml
    Code:
    #Spawn1
    loc1:
      world:
      x:
      y:
      z:
    
    #Spawn2
    loc2:
      world:
      x:
      y:
      z:
    And the only thing I get in my Config.yml after doing the command is this.
    Code:
    loc1: {}
    loc2: {}
    
     
  2. Online

    timtower Administrator Administrator Moderator

    @Pollio You can only have 1 onCommand, not onCommand1, onCommand2 etc
     
  3. Offline

    Pollio

    Ok thanks I see now, didn't know that.
    Thanks!
     
  4. Offline

    XavierMechanics

    @Pollio Why not else if the second command?
     
Thread Status:
Not open for further replies.

Share This Page