I get an error every time I join with the join connected through the configuration file.
Main class:
public Core plugin;
@Override
public void onEnable() {
Bukkit.getServer().getPluginManager().registerEvents(new Events(), this);
new DiscordCommand(this);
new TeamspeakCommand(this);
new cHubCommand(this);
new PingCommand(this);
new HelpCommand(this);
new WebsiteCommand(this);
new BuyCommand(this);
new MenuCommand(this);
getConfig().options().copyDefaults(true);
saveConfig();
}
Events class:
@EventHandler
public void onPlayerJoin(PlayerJoinEvent event) {
Player player = event.getPlayer();
event.setJoinMessage(null);
event.getPlayer().sendMessage(Core.getPlugin(null).getConfig().getString("joinmessage_1.", "§fWelcome to the official §acHub§f network!"));
event.getPlayer().sendMessage(Core.getPlugin(null).getConfig().getString("joinmessage_1.", "§fWelcome to the official §acHub§f network!"));
event.getPlayer().sendMessage(Core.getPlugin(null).getConfig().getString("joinmessage_2.", "§fIf you need any assistance, type §a/help"));
event.getPlayer().sendMessage(Core.getPlugin(null).getConfig().getString("joinmessage_line_2.", "§7§m--------------------------------------"));
Console error: https://pastebin.com/CDwK3UFj
Problem is with Core.getPlugin(null)
. Method getPlugin()
is from parents class JavaPlugin which your Core.java extends and you can't pass null as a argument.
If you want to refer to your plugin object (Core.java) you can change it to Core.getPlugin(Core.class)
but more professional would be to pass reference to this class in constructor.
So, the beginning of your Events.class will look like:
Core plugin;
public Events(Core plugin){
this.plugin = plugin;
}
and then you can simply do:
event.getPlayer().sendMessage(plugin.getConfig().getString("joinmessage_1.", "§fWelcome to the official §acHub§f network!"));
and in Core class you will change it to:
Bukkit.getServer().getPluginManager().registerEvents(new Events(this), this);