Me and my friend are trying to make a motd command but it doesnt works, can any 1 help? Code: Code (Text): String update = plugin.getConfig().getString("update"); Error: java.lang.NullPointerException at me.bukkit.<init>(Test.java:19) ~[?:?] Line 19: String update = plugin.getConfig().getString("update"); Config file: update: test thanks in advance!
sure Code (Text): public class Test implements Listener { String update = plugin.getConfig().getString("update"); @EventHandler @setMotd(ServerListPingEvent e) { e.setMotd(update);
public class main extends JavaPlugin { @Override public void onEnable(){ Bukkit.getServer().getPluginManager().registerEvents(Test(this), this); System.out.println("ENABLED");
yes. I forgot to add it Code (Text): Yes, I did define "plugin" I forgot to add it public class Test implements Listener { public main plugin; public Test(main instance){ plugin = instance; } String update = plugin.getConfig().getString("update"); @EventHandler @setMotd(ServerListPingEvent e) { e.setMotd(update); full error: http://pastebin.com/6U6597eh
You have not save the configuration... Add this to your onEnable Code (Text): saveDefaultConfig(); And initialize "update" in the event, when if you change your motd it automatically change the motd on ping.
your "plugin" is intialized when the Constructor of the Class is called, however the update String is intialzied before, so when plugin wasn't intialzied yet Try that: Code (Text): public main plugin; public Test(main instance){ plugin = instance; update = plugin.getConfig().getString("update"); } String update;
he wants to be able to set the server motd to whats in the config, not to be able to tell wheter it says Update in config or not, if he wanted to do so, your code would still be incorrect though, you would need to do Code (Text): if(getConfig.getBoolean("Update") == true) if he wanted to do so
Code (Text): try { e.setMotd(plugin.getConfig().getString("update")); } catch (NullPointerException ex){ System.out.println("Error"); }