Hello, Im trying to get my onJoinEvent Listener working however it looks correct yet wont work. Code (Text): package me.chazplays.helloworld import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; import org.bukkit.event.player.PlayerJoinEvent; public class MyPlayerListener implements Listener { public static Hello plugin; @EventHandler public void onPlayerJoin(PlayerJoinEvent event){ Player player = event.getPlayer(); event.setJoinMessage(getConfig().getString("MOTD")); } }
Did you create an instance of this class and register it? Also, what's even the purpose of this? Code (Text): public static Hello plugin;
Idk why i put that there and all i did was make the listener file and add that along with my main file that just gathers MOTD frm the config when typing /motd
do you get any errors? Code (Text): event.setJoinMessage(getConfig().getString("MOTD")); that should produce an error, because there is no plugin that it is referencing.
From the words MOTD, that sounds like you're wanting to send the message to one player, if so you don't want to set the Join message to it.
Yeah i get an error with the getconfig bit, i want it so if the Player has the perm say motd.notify they would get the MOTD set in the Config.
Code (Text): @EventHandler public void onjoin(PlayerJoinEvent e) { Player p = e.getPlayer(); if(p.hasPermission("perm") { p.sendMessage(getConfig().getString("String")); }
I get http://prntscr.com/7afj1o from the getConfig() part. Also how would i link to my onEnable part too.
In onEnable: Code (Text): Bukkit.getPluginManager().registerEvents(new MyPlayerListener(), this); getConfig: Code (Text): Bukkit.getPluginManager().getPlugin("PluginName").getConfig()
Yah, the fact that it took 10 posts to get you to say there was an error is making this pretty difficult. You need to share as much information as possible as to WHY it won't work. I am not a compiler, its tough to just stare at code without errors and figure out the errors in syntax in every line. You need to initilize this listener in your Main class. So in the onEnable() method in your main class you should have Code (Text): getServer().getPluginManager().registerEvents(new MyPlayerListener(), this); You can also save yourself some trouble by adding this method in your Main class Code (Text): //at the top private Hello plugin; //somewhere in your main class public static Hello getPlugin() { return plugin; } then to get what you want in your listener Code (Text): public class MyPlayerListener implements Listener { @EventHandler public void onPlayerJoin(PlayerJoinEvent event){ Player player = event.getPlayer(); String motd = Hello.getPlugin().getConfig().getString("MOTD")); //notice I am sending the message, not setting the join message player.sendMessage(motd); } }
Can you post your main class and your listener class? can you tell me what line 14 is in 'MyPlayerListener'? My guess is it is the Hello.getPlugin() method. EDIT:: This is my fault, in your main class, in the onEnable() method you need to add Code (Text): plugin = this; apologies. That should fix the issue
You should definitely look through the code, and figure out what your version didn't work, and why this one did. To learn, instead of blindly copying. A lot of the stuff here is covered in many beginner tutorials, so you should have consulted other sources and tried to understand. But, I have no problem helping either way.
I did watch BCBroz however ive read his useless and dang right he was. I did go through the bukkit docs but couldnt work out. Im slowly learning.