config.yml

Discussion in 'Plugin Development' started by MrTheNewGuy, Jul 3, 2012.

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

    MrTheNewGuy

    what's te best code to check that Config.yml exists or not?
     
  2. depends on what you call the best, fast or easy to understand or nice to look
     
  3. Offline

    MrTheNewGuy

    just a way
     
  4. Offline

    Jnorr44

    haha alright... heres what I use to create my config.yml (checks if it exists)
    Code:
    public class Flow extends JavaPlugin {
        @Override public void onEnable() {
            final File f = new File(getDataFolder(), "config.yml");
            if (!f.exists()) {
                saveDefaultConfig();
            }
     
  5. Offline

    MrTheNewGuy

    thanks!!
    btw do you know how to change the config file on a command
    like change:
    Code:
    Kick: false
    to
    Code:
    Kick: true
    on a command
     
  6. this.getConfg().set("Kick",true);
     
  7. Offline

    Jnorr44

    ferrybig knows everything.... hes beat me to like 5 answers today haha.
     
  8. Offline

    MrTheNewGuy

    do you know how to get if it is true or false
    i am doing this but it doen't work
    Code:
    if (plugin.getConfig().getBoolean("Kick") == true) {
     
    }
     
  9. why it dont work?
     
  10. Offline

    MrTheNewGuy

    it tells me "could not pass PlayerJoinEvent"

    here is the rest on my code if you need it:
    Code:
    public class LoginMessage extends JavaPlugin {
        public static LoginMessage plugin;
     
        @Override
        public void onEnable() {
            super.onEnable();
     
            final File f = new File(getDataFolder(), "config.yml");
            if (!f.exists()) {
                saveDefaultConfig();
            }
     
            getServer().getPluginManager().registerEvents(new Listener() {
                @SuppressWarnings("unused")
                @EventHandler
                public void playerJoin(PlayerJoinEvent event) {
                    Player player = event.getPlayer();
                    if (plugin.getConfig().getBoolean("Kick") == true) {
                        if (player.isOp()) {
                            return;
                        } else {
     
                            String output = ChatColor.translateAlternateColorCodes(
                                    '&', getConfig().getString("KickMessage"));
     
                            player.kickPlayer(output);
                        }
     
                    } else {
                        return;
                    }
                }
            }, this);
        }
     
        @Override
        public void onDisable() {
            super.onDisable();
        }
     
        @Override
        public boolean onCommand(CommandSender sender, Command command,
                String label, String[] args) {
            Player player = (Player) sender;
     
            if (label.equalsIgnoreCase("k")) {
                if (args.length == 1) {
                    if (args[0].equalsIgnoreCase("on")) {
                       
                        this.getConfig().set("Kick",true);
                        player.sendMessage("The server will now kick the players that whant to join");
                    } else if (args[0].equalsIgnoreCase("off")) {
                       
                        this.getConfig().set("Kick",false);
                        player.sendMessage("The server will now let players enter");
                    }
                }
            }
     
            return super.onCommand(sender, command, label, args);
        }
    }
    
     
  11. what is the stack trace?
    to whits line is the stack trace pointing?
    {edit} cause: plugin = null, you forgot to do plugin = this inside onEnable()
     
  12. Offline

    MrTheNewGuy

    line 31
     
  13. see my edit, if you didn;t see it already
     
  14. Offline

    MrTheNewGuy

    it is
    Code:
    plugin = new LoginMessage();
    isn't it?
     
  15. add the following to the onEnable methode
    Code:java
    1. plugin=this;
     
  16. Offline

    MrTheNewGuy

    k

    i have never done that.

    btw: i think you are a plugin god ;)

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 26, 2016
Thread Status:
Not open for further replies.

Share This Page