Help with config.yml setup

Discussion in 'Spigot Plugin Development' started by brandonlea, May 26, 2017.

  1. Hello how can i pull information out from config.yml this is my code
    Code (Text):
    package events;

    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.player.AsyncPlayerChatEvent;

    import Commands.main;
    import net.md_5.bungee.api.ChatColor;

    public class PlayerChat implements Listener {

        main plugin;
        public void ConfigListener(main instance) {
        plugin = instance;
        public void chatFormat(AsyncPlayerChatEvent event){
        Player p = event.getPlayer();
        event.setFormat(ChatColor.GREEN + plugin.getConfig().getString("prefix") + p.getDisplayName() + ChatColor.DARK_GRAY + ": " + ChatColor.BLUE + event.getMessage());

  2. You basically already did it.

    Code (Text):

  3. it's not showing in game tho

    this is the config file

    Code (Text):
    prefix: 'Member'
    message: 'Hello welcome'
  4. Have you registered your listener class?

    Edit: To be more into the topic: Is your chat format beeing printed?
  5. i've done everything

    Code (Text):
    package Commands;

    import org.bukkit.Bukkit;
    import org.bukkit.event.Listener;
    import org.bukkit.plugin.PluginManager;

    public class main extends JavaPlugin implements Listener {
        //When the plugin is Enabled
        public void onEnable() {
            PluginManager pm = Bukkit.getPluginManager();
            getCommand("gm").setExecutor(new gamemode());
            pm.registerEvents(new events.PlayerChat(), this);
        //When the plugin is Disabled
        public void onDisable() {
  6. does the config file exist in your data folder?
  7. look at the picture :(

    Attached Files:

  8. no i meant in your plugins data folder
    like "plugins/YOURPLUGIN/config.yml"
  9. yeah it is i've checked it
  10. is the chat format beeing printed?
  11. not now but when i do
    Code (Text):
    event.setFormat(ChatColor.GREEN + "ranks" + p.getDisplayName() + ChatColor.DARK_GRAY + ": " + ChatColor.BLUE + event.getMessage());
    that works
  12. ive fixed it but when i edit the file it wont put it in game
  13. Use plugin.reloadConfig();
  14. okay thanks shell i put this in ondisable or enable
  15. Add this into a command. Like /plreload or something, then add reloadConfig(). You have to use this command whenever the config is edited.
  16. Okay thanks also whats the best way to generate the folder in plugins
  17. What does that mean?
  18. so when you load the plugin in makes the plugin folder with config inside it i was just wondering the best way to do it
  19. do saveConfig() on enable.