Getting INT from config.yml

Discussion in 'Plugin Development' started by da_Do, Nov 3, 2018.

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

    da_Do

    Good evening, i am new at programming, and i need some help.
    I want to get X position from config, and its not working. Can you help me please ?

    Code:
    package me.MobArena.main;
    
    import org.bukkit.Location;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;
    import org.bukkit.event.Listener;
    import org.bukkit.plugin.java.JavaPlugin;
    
    public class Main extends JavaPlugin implements Listener {
       
        public void onEnable() {
            getLogger().info("Plugin Enabled");
            saveConfig();
        }
       
        public void onDisable() {
            getLogger().info("Plugin Disabled");
            saveConfig();
        }
       
        // SETSPAWN
        public boolean onCommand(CommandSender sender, Command cmd, String label, String[] arg) {
            if(sender instanceof Player) {
                if(cmd.getName().equalsIgnoreCase("setspawn1")) {
                    Player p = (Player) sender;
                    Location l1 = p.getLocation();
                    int x1, y1, z1;
                    x1 = l1.getBlockX();
                    y1 = l1.getBlockY();
                    z1 = l1.getBlockZ();
                   
                    getConfig().set(x1 + " " + y1 + " " + z1, "Spawn1 ");
                    saveConfig();
                   
                    p.sendMessage("Suradnice su : " + l1.getBlockX() + " " + l1.getBlockY() + " " + l1.getBlockZ());
                }
               
                if(cmd.getName().equalsIgnoreCase("setspawn2")) {
                    Player p = (Player) sender;
                    Location l2 = p.getLocation();
                   
                    int x2, y2, z2;
                    x2 = l2.getBlockX();
                    y2 = l2.getBlockY();
                    z2 = l2.getBlockZ();
                   
                    getConfig().set(x2 + " " + y2 + " " + z2, "Spawn2 ");
                    saveConfig();
                   
                    p.sendMessage("Suradnice su : " + l2.getBlockX() + " " + l2.getBlockY() + " " + l2.getBlockZ());
                   
                   
                    if(cmd.getName().equalsIgnoreCase("getx2")) {
                        getConfig().getInt("", x2);
                       
                        p.sendMessage("X2 je : " + getConfig().getInt(x2));
                    }
                }
               
            }
           
            return true;   
           
        }
       
       
       
       
       
    }
    
    //NOT COMPLETE
    Thanks
     
  2. Offline

    timtower Administrator Administrator Moderator

    @da_Do getInt returns an int, it doesn't change a value.
     
  3. Offline

    YoloSanta

    getConfig()#getInt("path")
     
Thread Status:
Not open for further replies.

Share This Page