Home > Mobile >  why isn't my config file modifying my servers motd?
why isn't my config file modifying my servers motd?

Time:10-04

So as the title says I need my config file to modify my servers motd, I feel like I've done everything the right way but obviously something is wrong, so let me show you what I'm working with

me.zavage.motd.Main

package me.zavage.motd;

import org.bukkit.plugin.java.JavaPlugin;

public class Main extends JavaPlugin {
    
    @Override
    public void onEnable() {
        saveDefaultConfig();
    }

}

me.zavage.motd.listeners.PingListener

package me.zavage.motd.listeners;

import java.io.File;
import org.bukkit.Bukkit;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.server.ServerListPingEvent;
import me.zavage.motd.Main;
import me.zavage.motd.utils.Utils;

public class PingListener implements Listener {
    
    private Main plugin;
    
    @EventHandler
    public void onPing(ServerListPingEvent e) {
        
        e.setMaxPlayers(plugin.getConfig().getInt("maxplayers"));
        e.setMotd(Utils.chat(plugin.getConfig().getString("motd"   "\n"   (Utils.chat(plugin.getConfig().getString("motd_line_2"))))));
        try {
            e.setServerIcon(Bukkit.loadServerIcon(new File(plugin.getConfig().getString("server_icon_path"))));
        } catch (Exception e1) {
            e1.printStackTrace();
        }
    }

}

Then we have the config.yml

#can only be a NUMBER with NO DECIMALS!
maxplayers: ''

motd: ''

#next line on motd
motd_line_2:

#create a folder inside the first page of your server files, call it "icon" and drop you server icon in there
#server icon MUST be 64 x 64 pixels
#                                                              #NameOfIcon#
#path example "C:\Users\user\Desktop\minecraft test server\icon\icon.png
server_icon_path: ''

CodePudding user response:

If the code that you show if everything that you are using, there is few issues.

  • You don't register the listener
package me.zavage.motd;

import org.bukkit.plugin.java.JavaPlugin;

public class Main extends JavaPlugin {
    
    @Override
    public void onEnable() {
        saveDefaultConfig();

        getServer().getPluginManager().registerEvents(new PingListener(this), this);
    }
}
  • You don't set the plugin variable in the listener, and you don't have constructor
public class PingListener implements Listener {
    
    private Main plugin;
    
    public PingListener(Main plugin) {
       this.plugin = plugin;
    }
}
  • Finally, you are searching for the motd\n motd_line_2 message. You have to use this in your ServerListPingEvent listener :
e.setMaxPlayers(plugin.getConfig().getInt("maxplayers"));
e.setMotd(Utils.chat(plugin.getConfig().getString("motd")   "\n"   plugin.getConfig().getString("motd_line_2")));
try {
   e.setServerIcon(Bukkit.loadServerIcon(new File(plugin.getConfig().getString("server_icon_path"))));
} catch (Exception exc) {
   exc.printStackTrace();
}
  • Related