Help please

Discussion in 'Plugin Development' started by Ziddia, Mar 16, 2011.

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

    Ziddia

    Ok, I'm trying to make a normal MOTD plugin, and I've done everything just as I was told. However, I am having some problems with it, it shows these errors.

    Here's my main class:
    Code:
    package ca.ziddia.motd;
    
    public class MOTDAdvanced {package ca.ziddia.motd;
    import org.bukkit.event.Event;
    import org.bukkit.event.Event.Priority;
    import org.bukkit.plugin.PluginDescriptionFile;
    import org.bukkit.plugin.PluginManager;
    import org.bukkit.plugin.java.JavaPlugin;
    
    public class MOTDAdvanced extends JavaPlugin{
     public static MOTDAdvanced instance;
     private final MOTDAdvancedPlayerListener playerListener = new motdPlayerListener();
    PluginDescriptionFile pdfFile = this.getDescription();
     @Override
     public void onEnable() {
         PluginManager pm = getServer().getPluginManager();
         pm.registerEvent(Event.Type.PLAYER_LOGIN, playerListener, Priority.Normal, this);
         System.out.println( pdfFile.getName() + " version " + pdfFile.getVersion() + " is enabled!");
     }
     @Override
     public void onDisable() {
         System.out.println( pdfFile.getName() + " version " + pdfFile.getVersion() + " is disabled!");
    
     }}
    
    I get errors here on lines 1 and 10

    And here's my PlayerListener:

    Code:
    package ca.ziddia.motd;
    
    public class MOTDAdvancedPlayerListener {package ca.ziddia.motd;
    import org.bukkit.entity.Player;
    import org.bukkit.event.player.PlayerListener;
    import org.bukkit.event.player.PlayerLoginEvent;
    import org.bukkit.event.player.PlayerLoginEvent.Result;
    
    public class MOTDAdvancedPlayerListener extends PlayerListener{
        @Override
        public void onPlayerLogin(PlayerLoginEvent event) {
            Player player = event.getPlayer();
            player.sendMessage("WELCOME TO AN AWESOME SERVER!!!");
        }
    }
    
    I get error here on lines 1 and 9.

    Help please
     
  2. Offline

    Edward Hand

    What is this line:
    Code:
    public class MOTDAdvancedPlayerListener {package ca.ziddia.motd;
    ???

    It occurs in both files.
     
  3. Offline

    Ziddia

    Is it not needed?

    Or only in one?

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

    Edward Hand

    Not only is it not needed, it doesn't even make sense...
    (delete them both).
     
  5. Offline

    Ziddia

    I have fixed all errors, now I get this error on the server console:
    Code:
    [SEVERE] Could not load plugins\MOTDAdvanced.jar in plugins: null
    org.bukkit.plugin.InvalidPluginException
        at org.bukkit.plugin.java.JavaPluginLoader.loadPlugin(JavaPluginLoader.java:113)
        at org.bukkit.plugin.SimplePluginManager.loadPlugin(SimplePluginManager.java:159)
        at org.bukkit.plugin.SimplePluginManager.loadPlugins(SimplePluginManager.java:107)
        at org.bukkit.craftbukkit.CraftServer.loadPlugins(CraftServer.java:59)
        at net.minecraft.server.MinecraftServer.e(MinecraftServer.java:204)
        at net.minecraft.server.MinecraftServer.a(MinecraftServer.java:191)
        at net.minecraft.server.MinecraftServer.d(MinecraftServer.java:131)
        at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:246)
        at net.minecraft.server.ThreadServerApplication.run(SourceFile:366)
    Caused by: java.lang.ClassNotFoundException: ca.ziddia.motd.MOTDAdvanced.java
        at java.net.URLClassLoader$1.run(Unknown Source)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.net.URLClassLoader.findClass(Unknown Source)
        at org.bukkit.plugin.java.PluginClassLoader.findClass(PluginClassLoader.java:30)
        at java.lang.ClassLoader.loadClass(Unknown Source)
        at java.lang.ClassLoader.loadClass(Unknown Source)
        at java.lang.ClassLoader.loadClassInternal(Unknown Source)
        at java.lang.Class.forName0(Native Method)
        at java.lang.Class.forName(Unknown Source)
        at org.bukkit.plugin.java.JavaPluginLoader.loadPlugin(JavaPluginLoader.java:105)
        ... 8 more
    These are my revised codes- Main Class:

    Code:
    package ca.ziddia.motd;
    
    import org.bukkit.event.Event;
    import org.bukkit.event.Event.Priority;
    import org.bukkit.plugin.PluginDescriptionFile;
    import org.bukkit.plugin.PluginManager;
    import org.bukkit.plugin.java.JavaPlugin;
    
    public class MOTDAdvanced extends JavaPlugin{
     public static MOTDAdvanced instance;
     private final MOTDAdvancedPlayerListener playerListener = new MOTDAdvancedPlayerListener();
    PluginDescriptionFile pdfFile = this.getDescription();
     @Override
     public void onEnable() {
         PluginManager pm = getServer().getPluginManager();
         pm.registerEvent(Event.Type.PLAYER_LOGIN, playerListener, Priority.Normal, this);
         System.out.println( pdfFile.getName() + " version " + pdfFile.getVersion() + " is enabled!");
     }
     @Override
     public void onDisable() {
         System.out.println( pdfFile.getName() + " version " + pdfFile.getVersion() + " is disabled!");
    
     }}
    
    And my PlayerListener:
    Code:
    package ca.ziddia.motd;
    
    import org.bukkit.entity.Player;
    import org.bukkit.event.player.PlayerListener;
    import org.bukkit.event.player.PlayerLoginEvent;
    
    public class MOTDAdvancedPlayerListener extends PlayerListener{
        @Override
        public void onPlayerLogin(PlayerLoginEvent event) {
            Player player = event.getPlayer();
            player.sendMessage("WELCOME TO AN AWESOME SERVER!!!");
        }
    }
    I can't see anything wrong with it, eclipse says there is nothing wrong with it, but something is going wrong. Please help me
     
  6. Offline

    Edward Hand

    Have you created a plugin.yml?
     
  7. Offline

    Ziddia

    Yeah, it reads like this, it's probably not right though

    name: MOTDAdvanced
    main: ca.ziddia.motd.MOTDAdvanced.java
    version: 0.1
     
  8. Offline

    Edward Hand

    get rid of the .java at the end of the 2nd line and it should be fine.
     
  9. Offline

    Ziddia

    It appears something is still wrong

    Ok I get this upon running the server:
    Code:
    SEVERE] null loading MOTDAdvanced v0.1 (Is it up to date?)
    java.lang.NullPointerException
        at ca.ziddia.motd.MOTDAdvanced.onEnable(MOTDAdvanced.java:17)
        at org.bukkit.plugin.java.JavaPlugin.setEnabled(JavaPlugin.java:118)
        at org.bukkit.plugin.java.JavaPluginLoader.enablePlugin(JavaPluginLoader.java:451)
        at org.bukkit.plugin.SimplePluginManager.enablePlugin(SimplePluginManager.java:217)
        at org.bukkit.craftbukkit.CraftServer.loadPlugin(CraftServer.java:83)
        at org.bukkit.craftbukkit.CraftServer.loadPlugins(CraftServer.java:61)
        at net.minecraft.server.MinecraftServer.e(MinecraftServer.java:204)
        at net.minecraft.server.MinecraftServer.a(MinecraftServer.java:191)
        at net.minecraft.server.MinecraftServer.d(MinecraftServer.java:131)
        at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:246)
        at net.minecraft.server.ThreadServerApplication.run(SourceFile:366)
    And this upon stopping it:
    Code:
    [SEVERE] java.lang.NullPointerException
    2011-03-16 07:32:35 [SEVERE]     at ca.ziddia.motd.MOTDAdvanced.onDisable(MOTDAdvanced.java:21)
    2011-03-16 07:32:35 [SEVERE]     at org.bukkit.plugin.java.JavaPlugin.setEnabled(JavaPlugin.java:120)
    2011-03-16 07:32:35 [SEVERE]     at org.bukkit.plugin.java.JavaPluginLoader.disablePlugin(JavaPluginLoader.java:465)
    2011-03-16 07:32:35 [SEVERE]     at org.bukkit.plugin.SimplePluginManager.disablePlugin(SimplePluginManager.java:229)
    2011-03-16 07:32:35 [SEVERE]     at org.bukkit.plugin.SimplePluginManager.disablePlugins(SimplePluginManager.java:223)
    2011-03-16 07:32:35 [SEVERE]     at org.bukkit.craftbukkit.CraftServer.disablePlugins(CraftServer.java:72)
    2011-03-16 07:32:35 [SEVERE]     at net.minecraft.server.MinecraftServer.g(MinecraftServer.java:227)
    2011-03-16 07:32:35 [SEVERE]     at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:302)
    2011-03-16 07:32:35 [SEVERE]     at net.minecraft.server.ThreadServerApplication.run(SourceFile:366)
    
    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 12, 2016
  10. Offline

    Edward Hand

    Do something more like this:

    Code:
    PluginDescriptionFile pdfFile;
    
     public void onEnable() {
       pdfFile = this.getDescription();
    }
     
  11. Offline

    Ziddia

    Wait... where do I put that?

    You lost me XD
     
  12. Offline

    Edward Hand

    Ok. At the moment your MOTDAdvanced class contains this line:
    Code:
    PluginDescriptionFile pdfFile = this.getDescription();
    You need to define the variable exactly where that line is, but initialise it within your onEnable function.
     
  13. Offline

    Ziddia

    I'm sorry, I'm relatively new to this stuff, and I need proper instruction

    Could you maybe take the required part of my code and copy-paste in your bit where it needs to be? then I can look at that and see exactly what I need to do

    Thanks if you can
     
  14. Offline

    Edward Hand

    1. Find the line I mentioned in my last post and remove everything after and including '=' so that it looks like this
      Code:
      PluginDescriptionFile pdfFile;
    2. Change your onEnable function to this:
      Code:
      public void onEnable() {
           pdfFile = this.getDescription();
            PluginManager pm = getServer().getPluginManager();
            pm.registerEvent(Event.Type.PLAYER_LOGIN, playerListener, Priority.Normal, this);
            System.out.println( pdfFile.getName() + " version " + pdfFile.getVersion() + " is enabled!");
        }
     
  15. Offline

    Ziddia

    I tried that, it gave me errors in eclipse, so I thought I was doing something wrong

    I'll try again, maybe I messed up something and this won't give me errors

    tyvm, worked perfectly, if i need any help with any other plugins i make, could you help me?

    Once again, thankyou.

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

    Edward Hand

    Of course. Post in this forum and I'll likely see it. You can start a conversation with me though if you really need to.
     
  17. Offline

    Ziddia

    OK something is still wrong... so much effort to make such a simple plugin...

    Upon my login, I get this message:
    Code:
    [SEVERE] Could not pass event PLAYER_LOGIN to MOTDAdvanced
    java.lang.NullPointerException
        at org.bukkit.craftbukkit.entity.CraftPlayer.sendMessage(CraftPlayer.java:82)
        at ca.ziddia.motd.MOTDAdvancedPlayerListener.onPlayerLogin(MOTDAdvancedPlayerListener.java:11)
        at org.bukkit.plugin.java.JavaPluginLoader$10.execute(JavaPluginLoader.java:207)
        at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.java:59)
        at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.java:255)
        at net.minecraft.server.ServerConfigurationManager.a(ServerConfigurationManager.java:143)
        at net.minecraft.server.NetLoginHandler.b(NetLoginHandler.java:76)
        at net.minecraft.server.NetLoginHandler.a(NetLoginHandler.java:27)
        at net.minecraft.server.NetworkListenThread.a(SourceFile:87)
        at net.minecraft.server.MinecraftServer.h(MinecraftServer.java:357)
        at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:272)
        at net.minecraft.server.ThreadServerApplication.run(SourceFile:366)
    I think we have something conflicting with PLAYER_LOGIN, that or I have a conflicting plugin. Will try with only MOTDA now.

    Ok, yeah, something's wrong, it couldnt pass the message.

    Please help me someone!

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

    Meta1203

    First off, what is on your 11th line? Second off, we need the whole code for us to be of any help. Try pastebin.com. Also, what is your craftbukkit and bukkit builds? Are they the same?
     
  19. Offline

    Ziddia

    Craftbukkit is 516 I think, bukkit is the one on the wiki.

    If someone could test it for me in the most recent craftbukkit it would be appreciated, will pastebin my code later
     
  20. Offline

    MadMonkeyCo

    Sorry my bad, I told you to use PLAYER_LOGIN and onPlayerLogin.
    You need to use PLAYER_JOIN and onPlayerJoin(PlayerEvent event). The blame is all mine and I admit it. [​IMG]
    Still if you're going to copy a code you should try to inspect it and learn from it.
    PHP:
    package ca.ziddia.motd;

    import org.bukkit.entity.Player;
    import org.bukkit.event.player.PlayerListener;
    import org.bukkit.event.player.PlayerEvent;

    public class 
    MOTDAdvancedPlayerListener extends PlayerListener{
        @
    Override
        
    public void onPlayerJoin(PlayerEvent event) {
            
    Player player event.getPlayer();
            
    player.sendMessage("WELCOME TO AN AWESOME SERVER!!!");
        }
    }
     
  21. Offline

    Ziddia

    Yeah, I did, I just thought upon a login made more sense.

    Thanks for that, what would that event do then?
     
  22. Offline

    MadMonkeyCo

    Login is good for ban plugins and stuff like that.
    Join is good for everything when a player joins except kicking and stuff like that.
    Just a friendly reminder: Remember to change PLAYER_LOGIN to PLAYER_JOIN
    If you have, then great, one diamond for you :) [diamond]
     
  23. Offline

    Ziddia

    Lol just read the wiki entry for login event- it's upon attempting to login, not actually joining

    Its as much my fault as yours for not consulting the event list first
     
  24. Offline

    MadMonkeyCo

  25. Offline

    Ziddia

    THANKYOU! Works perfectly now

    I will keep in touch for the hooks and Permissions for this?

    Thanks again :D
     
Thread Status:
Not open for further replies.

Share This Page