Solved Join Message Boolean Error

Discussion in 'Spigot Plugin Development' started by Richard37, Feb 6, 2020.

  1. Hey,
    I am making a chat format plugin and when I set Join Message Enable to False in my config file it stills give a Join Message.
    Code (Java):
     @EventHandler
        public void onJoin(PlayerJoinEvent e){
            Player p = e.getPlayer();
            if (config.getBoolean("First Join Message Enabled",true)){
                if (!p.hasPlayedBefore()){
                    Bukkit.broadcastMessage(Utils.chat(config.getString("First Join Message").replace("<player>", p.getName())));
                    e.setJoinMessage(null);
                }
            }
            if (config.getBoolean("Join Message Enabled", true)) {
                e.setJoinMessage(Utils.chat(config.getString("Join Message").replace("<player>", p.getName())));
            } else {
                e.setJoinMessage(null);
            }
        }
     
  2. Can we see your config?
    Also I may be mistaken but you can't have spaced in your path, use underscores or dashes instead.

    And:
    if (config.getBoolean("First Join Message Enabled",true)){
    can simply be replaced with if (config.getBoolean("First Join Message Enabled")) {.
     
  3. Sure
    Code (Text):
    First Join Message Enabled: 'true'
    First Join Message: '&d <player> &ehas joined the server for the first time!'

    Join Message Enabled: 'true'
    Join Message: '&d <player> &ehas joined the server.'

    Leave Message Enabled: 'true'
    Leave Message: '&d <player> &ehas left the server.'
     
  4. But I have space in my path when I use Strings and it works fine. Just the boolean is not working.
     
  5. Having quotes around your boolean will return a string, try it without the '.
    So Leave Message Enabled: true
     
    • Like Like x 1
  6. I know I had this before but it was not working so I just used the method I use now.
     
  7. Try remove the quotes around the boolean in the config
     
  8. The plugin can't find the boolean in the config. And since you are using that method, it will always default to "true".
     
  9. I didn't know you can put space in a yaml
    Also with quotes it means it's a string as stated before.
    Make sure the event is registered
    Code (Java):
    if (config.getBoolean("Join Message Enabled")) {
                e.setJoinMessage(Utils.chat(config.getString("Join Message").replace("<player>", p.getName())));
            } else {
                e.setJoinMessage(null);
            }
     
  10. Thank you it works.