Solved Config.yml not being saved

Discussion in 'Plugin Development' started by DrTURTLE2, Jul 26, 2016.

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

    DrTURTLE2

    Hello all, I have recently picked up some developing again after not doing it for about a year or so. I am just having fun trying to code a minigame type plugin. I am trying to save the coords of my location and putting it in a config.yml, however upon doing this, it does not work. When I type the command nothing happens. In the code you can see I try to send a message to console and I try sending a message to player and neither works. There are no errors in console.

    Here is the code:
    Code:
    public class setspawn implements CommandExecutor{
        public main plugin;
        public setspawn(main instance){
            plugin = instance;
        }
       
        public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
            
            Player p = (Player) sender;
            Logger log = Bukkit.getLogger();
           
            if(p.getName().equalsIgnoreCase("setspawnsumo")){
                log.info("hi");
                if(sender instanceof Player){
                    log.info("hi2");
                plugin.getConfig().set("Sumo" + ".x", p.getLocation().getBlockX());
                plugin.getConfig().set("Sumo" + ".y", p.getLocation().getBlockY());
                plugin.getConfig().set("Sumo" + ".x", p.getLocation().getBlockZ());
                plugin.saveConfig();
                p.sendMessage("Saved Sumo Coords");
                }
               
               
               
               
               
            }
           
            return false;
       
    }
    }
    
     
  2. @DrTURTLE2
    Can we see your main class where you register the command? Also can we see the plugin.yml?
     
  3. Offline

    DrTURTLE2

    Main Class:
    Code:
    public class main extends JavaPlugin {
        private static filemanager FileManager;
        private static main instance;
       
        public ArrayList<String> minigame = new ArrayList<String>();
        public ArrayList<String> sumo = new ArrayList<String>();
       
        public void onEnable(){
            instance = this;
           
            FileManager = new filemanager();
            getConfig().options().copyDefaults(true);
            saveConfig();
            getCommands();
            getEvents();
       
        }
        public void onDisable(){
            saveConfig();
        }
        public void getCommands(){
            getCommand("setspawnsumo").setExecutor(new sumo.setspawn(this));
        }
        public void getEvents(){
           
        }
        public filemanager getFileManager(){
            return FileManager;
        }
        public static main getInstance() {
           
            return instance;
        }
       
    }
    
    plugin.yml:
    Code:
    main: main.main
    name: Minigames
    version: 1.0
    author: DrTURTLE2
    description: Minigame plugin
    commands:
       setspawnsumo:
    @AlvinB
     
  4. @DrTURTLE2
    You need to put a description and usage for the command in the plugin.yml. Something like this:
    Code:
    commands:
        mycommand:
            description: My Command!
            usage: /mycommand
     
  5. Offline

    DrTURTLE2

    That cant possibly be what is causing the problem. I did however try it and is doing the same stuff (nothing). I feel like it has something to do with the command itself.
     
  6. @AlvinB Usage is not required.

    @DrTURTLE2 A few issues with the plugin
    1. Naming conventions
    2. Stop the static abuse
    3. You are doing new sumo.setspawn - sumo is a String List?
    4. Don't blindly cast, check before hand!
    5. No need to make a variable you call once or twice
     
  7. @DrTURTLE2
    Wops, that is not the problem, but I still recommend doing it. Your real problem is that you're checking if the players name is "setspawnsumo". You also need to instanceof check before casting, what if the CommandSender isn't a player? Then you will get a ClassCastException. Another thing to keep in mind is naming conventions. Variable and method names should be camelCase (first word lowercase, the rest with a capital letter) and class names should be UpperCase (all words with capital letter). Another thing is package names, they should be: "com.domainyouown.projectname" or if you don't own a domain, "me.myusername.projectname".
     
  8. Offline

    DrTURTLE2

    Jesus I feel stupid after you pointing out that I am checking if their name is setspawnsumo. Thank you all for the replies. I look forward to working on my conventions and making my work cleaner. Thank you all for the help.
     
Thread Status:
Not open for further replies.

Share This Page