Hey im truing to make a plugin which gives the player information when the log in ive registered the event Code: PluginManager pm = this.getServer().getPluginManager(); pm.registerEvent(Event.Type.PLAYER_JOIN, new UMPlayerListener(this), Event.Priority.Monitor, this); and ive got this in my listener Code: public class UMPlayerListener extends PlayerListener{ private final UmTowny plugin; public UMPlayerListener(UmTowny thisa){ this.plugin = thisa; } @Override public void onPlayerJoin(PlayerJoinEvent e){ e.getPlayer().sendMessage("Herro"); } } What do i have wrong?
try this: Code: PluginManager pm = getServer().getPluginManager(); pm.registerEvent(Event.Type.PLAYER_JOIN, UMPlayerListener, Event.Priority.Monitor, this); listener Code: public class UMPlayerListener extends PlayerListener{ private final UmTowny plugin; public UMPlayerListener(UmTowny thisa){ this.plugin = thisa; } public void onPlayerJoin(PlayerJoinEvent e){ e.getPlayer().sendMessage("Herro"); } }
Code: PluginManager pm = this.getServer().getPluginManager(); pm.registerEvent(Event.Type.PLAYER_JOIN, new UMPlayerListener(this), Event.Priority.Monitor, this); to Code: PluginManager pm = getServer().getPluginManager(); pm.registerEvent(Event.Type.PLAYER_JOIN, UMPlayerListener, Event.Priority.Monitor, this);
Declare this in your main class: Code:java private final UMPlayerListener playerListener = new UMPlayerListener(this); Then, change your event registering to this: Code:java pm.registerEvent(Event.Type.PLAYER_JOIN, playerListener, Event.Priority.Monitor, this); I believe the issue is that your player listener isn't final, though I may be wrong.
@Shamebot Honestly, I just look at what I have in my source and pass it on. I don't even remember where the final came into play, probably a habit from my very first plugin that I carry around with me today. So really...it probably doesn't need to be final, but I can't find anything else that stands out as "THIS WONT WORK" in his source.
@DrBoweNur The "Event.(blabla other shit)" is outdated. It would be like "Type.PLAYER_JOIN" and "Priority.(priority)". Just to clarify.
@Jaker232 Ummm, no. They both work just fine, neither is outdated. If you're looking to import an extra package just so you can avoid typing "Event.", then that's your choice.
@Jaker232 But Type and Priority are enums within the Event class, why should you not be able to refer to them with Event.Type and Event.Priority? Edit: @Faelsel He doesn't cancel it, so Monitor is okay.
@Shamebot That's actually a easier way than typing "Event.Priority.(priority)" and "Event.Type.(type)".
But it probably isn't the cause of his problem. @ rob4001 Are you sure it doesn't work? Try and put some debug messages in.
It may get rid of 6 characters that you need to type, but is that really worth having to import 'Type' and 'Priority' to you?
There sure is a lot of bad, incorrect advise in this thread. Of course, that's probably because there's nothing obviously wrong with his code, so people are just throwing out random suggestions. But still...
@rob4001 Glad to help (Though I'm not sure if the final had anything to do with it, may have just been a strange issue with declaring the playerListener to begin with)