Listeners Not listening.

Discussion in 'Plugin Development' started by NoMansLand, Feb 25, 2013.

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

    NoMansLand

    Hello Again Bukkit,

    I have been writing this plugin for 2 days now, fixed a prior issue by doing a re-write and now I can't get my event listeners to listen.

    there's 2 java files: Main.java & Listeners.java

    This is Main.java:
    This is Listeners.java:

    Thank you for your help.
     
  2. Offline

    Tirelessly

    Listener class shouldn't extend JavaPlugin.
     
  3. Offline

    NoMansLand

    With out it, log.getLogger() doesnt work.
     
  4. Offline

    Tirelessly

    So use an instance of your main class passed via the constructor to call JavaPlugin methods
     
  5. Offline

    NoMansLand

    1:24:04 PM
    CONSOLE:
    [SEVERE] [GL] GL v0.1 attempted to register an invalid EventHandler method signature "public void net.myfallen.gl.Listeners.onPlayerCommandPreprocess(org.bukkit.entity.Player,org.bukkit.command.Command) throws java.sql.SQLException" in class net.myfallen.gl.Listeners
    any idea why I would get this then onPlayerCommandPreprocess?
     
  6. Offline

    chasechocolate

    Why do you have the @EventHandler annotation on a method that is not an event listener (onPlayerCommandPreprocess)?

    NoMansLand Oh and what Tirelessly is saying:
    Code:java
    1. //In your Listeners class:
    2. private Main plugin;
    3. public Listeners(Main plugin){
    4. this.plugin = plugin;
    5. }

    And then the logger can be accessed with:
    Code:java
    1. plugin.getLogger().info("Hello");


    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 31, 2016
  7. Offline

    NoMansLand

    I figured that out afterwards and then repeatedly banged my head into the desk for being an idiot..

    Didn't help much.. but now i'm getting this:

    2013-02-25 21:32:54 [SEVERE] Could not pass event PlayerJoinEvent to GL v0.1
    org.bukkit.event.EventException
    at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:427)
    at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.java:62)
    at org.bukkit.plugin.SimplePluginManager.fireEvent(SimplePluginManager.java:477)
    at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.java:462)
    at net.minecraft.server.v1_4_R1.PlayerList.c(PlayerList.java:159)
    at net.minecraft.server.v1_4_R1.PlayerList.a(PlayerList.java:98)
    at net.minecraft.server.v1_4_R1.PendingConnection.d(PendingConnection.java:130)
    at net.minecraft.server.v1_4_R1.PendingConnection.c(PendingConnection.java:45)
    at net.minecraft.server.v1_4_R1.DedicatedServerConnectionThread.a(DedicatedServerConnectionThread.java:44)
    at net.minecraft.server.v1_4_R1.DedicatedServerConnection.b(SourceFile:29)
    at net.minecraft.server.v1_4_R1.MinecraftServer.r(MinecraftServer.java:598)
    at net.minecraft.server.v1_4_R1.DedicatedServer.r(DedicatedServer.java:224)
    at net.minecraft.server.v1_4_R1.MinecraftServer.q(MinecraftServer.java:494)
    at net.minecraft.server.v1_4_R1.MinecraftServer.run(MinecraftServer.java:427)
    at net.minecraft.server.v1_4_R1.ThreadServerApplication.run(SourceFile:849)
    Caused by: java.lang.NullPointerException
    at net.myfallen.gl.Listeners.onPlayerJoin(Listeners.java:24)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:425)
    ... 14 more

    The exact same Player joinPlayer = player.getEvent(); works in other plugins that i've developed..
     
  8. Offline

    chasechocolate

    player.getEvent()? *event.getPlayer()
     
  9. Offline

    NoMansLand

    Sorry typo, but that's what I have in the script and it's giving the the null error.

    Line 24: plugin.getLogger().info("[GL] - A player has joined the server. Performing Integrity Tests.");
    (listeners.java)

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 31, 2016
  10. Offline

    AmShaegar

    In onEnable() it should be like this:

    getServer().getPluginManager().registerEvents(new Listeners(this), this);​

    In Listeners it should be like this:

    private Main plugin;
    public Listeners(Main plugin){
    this.plugin = plugin;​
    }

    Oh and:

    public class Main extends JavaPlugin implements Listener {
     
  11. Offline

    NoMansLand

    I replaced all the "log.info" with System.out.Print() and it works now, but do I have to set the commands I want submitted with " public void onPlayerCommandPreprocess(Player player, Command cmd) throws SQLException {" or is there a way to log every command done?
     
  12. Offline

    fireblast709

    It happens because you have a syntax error in your SQL. You might want to get the query where it happens and see where exactly you made that mistake.
     
  13. Offline

    NoMansLand

    If I had a Syntax error or any error in my SQL it would come up with something, would it not? I'd like to think so.. or even print out the line that a command has been sent.

    Here's the java: http://pastebin.com/eBdhjQeM

    The plugin.yml

    The only issue now is that it wont get the commands
     
  14. Offline

    NoMansLand

    Does anyone have any idea how to get all the commands listened to?
     
Thread Status:
Not open for further replies.

Share This Page