Multiple 'messages' in a YAML file

Discussion in 'Plugin Development' started by Piggo564, Jul 11, 2020.

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

    Piggo564

    Hello, I have followed this tutorial by Reflxction https://bukkit.org/threads/creating-and-managing-custom-yaml-files.473063/ to create a YAML File with a message in it that is outputted to the user when they join the server. However, I have made a second message for when the user leaves the server, but this breaks both the join and leave messages. I copy and pasted the code within the listeners class, but replaced every 'join' with the word 'quit' and added my message to the YML file. I am unsure as to why it is breaking both of the messages.
    NOTE: I have not changed anything within my main plugin class in order to add the quit message and I am fairly sure that shouldn't be a problem as my Listeners class is the only one that mentions separate messages.

    My YML File:
    Code:
    Messages:
      OnJoin: "&eWelcome to my Kingdom!"
      OnQuit: "&eWe will miss you!"
    My Listeners Class:
    Code:
    package me.Piggo564.YML;
    
    import org.bukkit.ChatColor;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.player.PlayerJoinEvent;
    import org.bukkit.event.player.PlayerQuitEvent;
    
    public class Listeners implements Listener {
      
        private App app;
      
        public Listeners(App app) {
            this.app = app;
        }
      
        @EventHandler
        public void onPlayerJoin(PlayerJoinEvent event) {
            String unformattedMessage = app.getMessagesConfig().getString("Messages.OnJoin");
          
            String formattedMessage = ChatColor.translateAlternateColorCodes('&', unformattedMessage);
            event.getPlayer().sendMessage(formattedMessage);
        }
      
        @EventHandler
        public void onPlayerQuit(PlayerQuitEvent event) {
            String unformattedMessage = app.getMessagesConfig().getString("Messages.OnQuit");
          
            String formattedMessage = ChatColor.translateAlternateColorCodes('&', unformattedMessage);
            event.getPlayer().sendMessage(formattedMessage);
        }
    
    }
     
  2. Offline

    Strahan

    When you say "it breaks", what do you mean? Does it throw an error? What is the error? Also getString is nullable, so you should be checking for that.
     
Thread Status:
Not open for further replies.

Share This Page