DaniYoutuber 823
DaniYoutuber 823

Reputation: 3

Error: Could not pass event PlayerJoinEvent to Plugin (BUKKIT)

I'm doing a test plugin, and when I log in, it doesn't tell me the login message, but it gives me an error. Here is the log: https://pastebin.com/SyBN5G2k

I looked up in internet but I can't found nothing that helps me.

Can someone help me i need it to make my server!

This the code of the PlayerJoinEvent event :

package com.Test.events;

import org.bukkit.Location;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerJoinEvent;

import com.Test.main.MClass;

public class Enter implements Listener{
    private MClass plugin;

    public Enter(MClass plugin) {
        this.plugin = plugin;
    }

    @EventHandler
    public void onEnter(PlayerJoinEvent event) {
        Player player = event.getPlayer();
        Location spawn = new Location(player.getWorld(), -8, 64, -467.0, -90, 0);
        player.teleport(spawn);

        FileConfiguration config = plugin.getConfig();
        String path = "config.welcome-message";
        if(config.getString(path).equals("true")) {
            String text = "Config.welcome-message-text";
            player.sendMessage(config.getString(text));
        }
    }
}

And this my main class (called MClass)

package com.Test.main;

import java.io.File;

import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.plugin.PluginDescriptionFile;
import org.bukkit.plugin.PluginManager;
import org.bukkit.plugin.java.JavaPlugin;

import com.Test.commands.CommandPotatoes;
import com.Test.commands.PrincipalCommand;
import com.Test.events.Enter;

public class MClass extends JavaPlugin{
    public String configPath;
    PluginDescriptionFile pdffile = getDescription();
    //Declaration on variables thas include info of the version and the name
    public String name = ChatColor.GOLD+""+ChatColor.BOLD+"["+pdffile.getName()+"] "+ChatColor.RESET;
    public String version = pdffile.getVersion();

    //Instruction on enable plugin
    public void onEnable() {
        //Mensaje de la consola que indica que el plugin ha sido activado
        Bukkit.getConsoleSender().sendMessage(name+ChatColor.BLUE+"Sucesfully loaded (ver "+version+")");
        registerCommands();
        registerEvents();
        registerConfig();
    }

    public void registerCommands() {
        this.getCommand("potatoes").setExecutor(new CommandPotatoes(this));
        this.getCommand("test").setExecutor(new PrincipalCommand(this));
    }
    public void registerEvents() {
        PluginManager pm = getServer().getPluginManager();
        pm.registerEvents(new Enter(this), this);
    }
    public void registerConfig() {
        File config = new File(this.getDataFolder(),"config.yml");
        configPath = config.getPath();
        if(!config.exists()) {
            this.getConfig().options().copyDefaults(true);
            saveConfig();
        }

        }
}

Plz help i need it to make my server :(

Upvotes: 0

Views: 1014

Answers (1)

SkyBoat
SkyBoat

Reputation: 36

This is what you are looking for:

Caused by: java.lang.NullPointerException
    at com.Test.events.Enter.onEnter(Enter.java:27) ~[?:?]

Line #27 would be if(config.getString(path).equals("true")) Check whether there is indeed a string at that path, meaning

config:
  welcome-message: true

as a side note, you should use boolean types for truth values, not strings.

Upvotes: 1

Related Questions