Join Message Not Working (org.bukkit.event.EventException: null)

Discussion in 'Plugin Development' started by Skyve_5, Oct 15, 2022.

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


    "Could not pass event PlayerJoinEvent to JoinMessage v1.1
    org.bukkit.event.EventException: null" the first line of the error message I get in the console every time someone logs in to the server.

    Since I've only just started with making plugins (this is my second right after a hello world plugin), I've been following tutorials to get the hang of it.

    To be specific, this is the tutorial I was following for this plugin:

    I followed it letter for letter pretty much. Only changed package and class names, but for some reason I'm getting that error message.

    This is my Main:
    package me.skyve.joinmessage;
    import me.skyve.joinmessage.join.JoinListener;
    public class Main extends JavaPlugin {
        public void onEnable(){
            new JoinListener(this);
    This is my JoinListener code:
    package me.skyve.joinmessage.join;
    import me.skyve.joinmessage.Main;
    import me.skyve.joinmessage.utils.Utils;
    import org.bukkit.Bukkit;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.player.PlayerJoinEvent;
    public class JoinListener implements Listener {
        private static Main plugin;
        public JoinListener(Main plugin){
            this.plugin = plugin;
            Bukkit.getPluginManager().registerEvents(this, plugin);
        public void onJoin(PlayerJoinEvent e){
            Player p = e.getPlayer();
            if (!p.hasPlayedBefore()){
              "firstjoin_message").replace("<player>", p.getName())));
            } else{
              "join_message").replace("<player>", p.getName())));
    This is my Utils code:
    package me.skyve.joinmessage.utils;
    import org.bukkit.ChatColor;
    public class Utils {
        public static String chat(String s){
            return ChatColor.translateAlternateColorCodes('&', s);
    This is my config.yml file's contents:
    firstJoin_message: '&a<player> &7has joined for the first time!'
    join_message '&e<player> &7has joined the game! Welcome back!'
    I of course have a plugin.yml file but I didn't think that was necessary to provide.

    Does anyone know what I'm doing wrong? Thanks so much for helping.
  2. Online

    timtower Administrator Administrator Moderator

    @Skyve_5 Please post the full error, can't do anything without it.
  3. Offline


    Are you sure that the config contains the join message?
    I don't see any code that adds any default values to the config,
  4. Offline


    I'm not exactly sure this was the issue to begin with, but see how in the config file "join_message" has no colon after it, I changed that and now it works somehow. Could this have been the issue? Also sorry I didn't post the full error, I went to do that and then discovered a new error saying that there needed to be the colon and after i fixed that as i said, it worked.
  5. Offline


    ... getString("firstjoin_message") ...
    firstJoin_message: '&a<player> &7has joined for the first time!'
    See a slight problem here? firstjoin_message =/= firstJoin_message. Config pathing is case sensitive.

    Also, never hang methods off of other methods that are nullable. Also also, this could be compressed down with a simple ternary:
    Bukkit.broadcastMessage( ? "" : "first") + "join_message").replace("<player>", p.getName())));
    However, given the fact getString() is nullable when not passed a value, I wouldn't actually do that. I'd do
    String msg = plugin.getConfig().getString((p.hasPlayedBefore() ? "" : "first") + "join_message");
    if (msg == null) return;
    Bukkit.broadcastMessage("<player>", p.getName())));
  6. Offline


    This is really helpful. Thanks so much. I'm really new to all this so I didn't know it was case sensitive. The tutorial I was watching must have fixed this off camera before demonstrating it working. I will keep the suggestions in mind for future projects as well. Again thanks so much.
  7. Offline


    No problem! I recommend sticking to all lowercase when possible, it avoids issues like this. The only time I mix case is in variables and class names, stuff like that. Since end users may edit config files manually, keeping it l/c means less chance they'll bungle it.

    Also it's a good idea to keep casing in mind when writing functions. So like when you want to, say, switch on args in a command:
    onCommand {
      switch (cmd.getName().toLowerCase()) {
      case "arg1":
      .. etc
    Anything that can be touched by the user could be messed up by said user, so I usually force to lowercase all the time except for when I'm actually writing out (like I'd l/c their input if I need to check something, but if their input is going to be the displayname of an item you certainly don't want to l/c it when writing that for example).
Thread Status:
Not open for further replies.

Share This Page