[Solved] Once again, I need help. How do you make it so when they login it will do something

Discussion in 'Plugin Development' started by 20liwlill20, Feb 12, 2012.

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

    20liwlill20

    I need help on the script were if someone goes on the server it will do something, I know how to make it do something but I need to know how to make it so if they login it will :D please post.
     
  2. Code:
    @EventHandler
    public void onPlayerLogin(PlayerLoginEvent event)
    {
      //What ever here
    }
     
  3. Offline

    davejavu

    You'd need to register PlayerLoginEvent in onEnable() then do what kumpelblase2 said in the class <plugin name>PlayerListener.
     
  4. What you said is the old event system.

    Code:
    public class YourListener implements Listener
    {
      @EventHandler
      public void playerLogin(PlayerLoginEvent event)
      {
     
      }
    }
    Code:
    getServer().getPluginManager().registerEvents(new YourListener(), this);
    done.
     
  5. Offline

    20liwlill20

    And were shall i put that?.... In my main or make another class?
     
  6. in my second post the first code part is a separate class for you listener where you can add more events if you'd like to. The second part is the registration of the listener which goes into your onEnable().
     
    20liwlill20 likes this.
  7. getServer().getPluginManager().registerEvents(this, this); in your onEnable and
    the other one after your onEnable
     
  8. Offline

    20liwlill20

    Ah ok thx for your help i will try that out :D.
     
  9. Offline

    dillyg10

    I've tried the above steps, and it's not working for me D:.

    Here is the basics of my code, and the rrors:
    Code:
    public class blacklistcheckogin implements Listener {
        blacklist plugin;
     
        @EventHandler
     
        public void onPlayerLogin(PlayerLoginEvent event)
        {
        //stuff in here :)
        }
    }
    //Code in the onEnable() in my main class...
    @Override onEnable() {
        blacklist plugin;
        getServer().getPluginManager().registerEvents(new blacklistcheckogin(), plugin);
     
    }
     
    //And finally all the wonderful erros...
    12:35:16 [SEVERE] Error occurred while enabling Blacklist v1.0 (Is it up to date?): org.bukkit.plugin.PluginManager.registerEvents(Lorg/bukkit/event/Listener;Lorg/bukkit/plugin/Plugin;)V
    java.lang.NoSuchMethodError: org.bukkit.plugin.PluginManager.registerEvents(Lorg/bukkit/event/Listener;Lorg/bukkit/plugin/Plugin;)V
        at com.gmail.dillyg10.blacklist.onEnable(blacklist.java:25)
        at org.bukkit.plugin.java.JavaPlugin.setEnabled(JavaPlugin.java:230)
        at org.bukkit.plugin.java.JavaPluginLoader.enablePlugin(JavaPluginLoader.java:989)
        at org.bukkit.plugin.SimplePluginManager.enablePlugin(SimplePluginManager.java:280)
        at org.bukkit.craftbukkit.CraftServer.loadPlugin(CraftServer.java:190)
        at org.bukkit.craftbukkit.CraftServer.enablePlugins(CraftServer.java:173)
        at org.bukkit.craftbukkit.CraftServer.reload(CraftServer.java:443)
        at org.bukkit.Bukkit.reload(Bukkit.java:188)
        at org.bukkit.command.defaults.ReloadCommand.execute(ReloadCommand.java:22)
        at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:168)
        at org.bukkit.craftbukkit.CraftServer.dispatchCommand(CraftServer.java:385)
        at org.bukkit.craftbukkit.CraftServer.dispatchCommand(CraftServer.java:381)
        at net.minecraft.server.MinecraftServer.b(MinecraftServer.java:573)
        at net.minecraft.server.MinecraftServer.w(MinecraftServer.java:550)
        at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:434)
        at net.minecraft.server.ThreadServerApplication.run(SourceFile:465)
     
     
    // so it's throwing a noMethodFoundExcetipn, but the mehtod is clearly there, so I'm not sure what is going on :d
    
    Hope somone can help!
    (here is a pastie with everything above)

    http://pastie.org/3402778
     
  10. Offline

    Bisa

    Might be a long shot but is your class really named "blacklistcheckogin"?
     
  11. looks like it is.

    'plugin' is empty.
     
  12. Offline

    dillyg10

    I tried using this as a second param, still threw an exception.

    And yes, my class name is blacklistchecklogin, but that in no way would throw any sort of exception. :D.
    By the way, I do want to mention that I have done a lot of debugging (I would say around a good day or 2) and I just can't figure it out, even after looking @ the bukkit javadocs, and a lot of other resources. I'm hoping that once the new event system is a little bit more ironed out, there will be more resources on it.
     
  13. Offline

    Sir Savary

    dillyg10

    Looks like you're having an issue that I'm having, registerEvents() can't be found in PluginManager. Is this a bug in Bukkit 1.1-R4? (@kumpelblase2)
     
  14. Offline

    arnie231

    Its not a bug R4 works for me this is what i use Below

    Code:java
    1.  
    2. @Override
    3. public void onEnable()
    4. {
    5. registerEvents();
    6. }
    7.  


    Code:java
    1.  
    2. public void registerEvents() {
    3. PluginManager pm = getServer().getPluginManager();
    4. pm.registerEvents(new ExampleListener(), this);
    5. log.info("[Example] Events registered");
    6.  
    7. }
    8. }
    9.  
     
  15. Offline

    Sir Savary

    arnie231

    Doesn't work for me, I'm getting an "The method registerEvents(ElderTrollsListener, Main) is undefined for the type PluginManager" from eclipse and a stack trace from CraftBukkit.

    StackTrace
    Code:
    2012-02-17 20:19:28 [SEVERE] Error occurred while enabling ElderTrollsRPG v0.01 (Is it up to date?): Unresolved compilation problem:
        The method registerEvents(ElderTrollsListener, Main) is undefined for the type PluginManager
     
    java.lang.Error: Unresolved compilation problem:
        The method registerEvents(ElderTrollsListener, Main) is undefined for the type PluginManager
     
        at plugin.CobaltTeam.eldertrolls.Main.onEnable(Main.java:49)
        at org.bukkit.plugin.java.JavaPlugin.setEnabled(JavaPlugin.java:231)
        at org.bukkit.plugin.java.JavaPluginLoader.enablePlugin(JavaPluginLoader.java:1057)
        at org.bukkit.plugin.SimplePluginManager.enablePlugin(SimplePluginManager.java:379)
        at org.bukkit.craftbukkit.CraftServer.loadPlugin(CraftServer.java:191)
        at org.bukkit.craftbukkit.CraftServer.enablePlugins(CraftServer.java:174)
        at net.minecraft.server.MinecraftServer.t(MinecraftServer.java:357)
        at net.minecraft.server.MinecraftServer.a(MinecraftServer.java:344)
        at net.minecraft.server.MinecraftServer.init(MinecraftServer.java:175)
        at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:408)
        at net.minecraft.server.ThreadServerApplication.run(SourceFile:465)
     
  16. Offline

    Njol

    Does ElderTrollsListener implement Listener?
     
  17. try doing /version at the server,a nd post the result, so we can see its version
     
  18. It's registerEvent and not registerEvents.
     
  19. Offline

    Sir Savary

    It does, yes.
    Server version? Erm, running CraftBukkit 1.1-R4, not sure how this is relevant to a compilation issue.
     
  20. Offline

    stelar7

    what version are you compiling against?
    if it's an older version then "The method registerEvents(listener, plugin) is undefined for the type PluginManager"
    meaning that the method "registerEvents(Listener, Plugin)" does not exsist in the PluginManager
     
  21. Update your Bukkit.
    The method is registerEvents, not registerEvent Pandemoneus
     
  22. I am still used to the old event system.
    But registerEvent does still exist.
     
  23. Yes, but for the purpose of their discussion that's not applicable :)
     
  24. mayby you compiling whit r4, but your server are running an onlder version, because you forgot to chence r3 to r4 at the start up script, whit /version we can see
     
  25. Offline

    Sir Savary

    Erm, what? I am using Bukkit R4 and CraftBukkit R4.
     
  26. what version of r4?
     
  27. Offline

    Sir Savary

    Recommended on both.
     
  28. what build nummer, because I also use that function at the recommend build whitout problems
     
  29. Offline

    Sir Savary

    nvm, it fixed itself.
     
Thread Status:
Not open for further replies.

Share This Page