Importing Heroes plugin

Discussion in 'Plugin Development' started by Whatshiywl, Sep 2, 2012.

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

    Whatshiywl

    Hello all! So I have been trying to make a plugin compatible with Heroes to be a kind of addon to it. It is my first time trying to make a plugin that needs another plugin and I seem to be having problems with using stuff on the code... (I don't acctualy have much java experience)

    The error is the following:
    Code:
    2012-09-02 12:47:56 [SEVERE] null
    org.bukkit.command.CommandException: Unhandled exception executing command 'stats' in plugin HeroeStats v0.1
        at org.bukkit.command.PluginCommand.execute(PluginCommand.java:42)
        at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:168)
        at org.bukkit.craftbukkit.CraftServer.dispatchCommand(CraftServer.java:492)
        at net.minecraft.server.NetServerHandler.handleCommand(NetServerHandler.java:878)
        at net.minecraft.server.NetServerHandler.chat(NetServerHandler.java:825)
        at net.minecraft.server.NetServerHandler.a(NetServerHandler.java:807)
        at net.minecraft.server.Packet3Chat.handle(Packet3Chat.java:44)
        at net.minecraft.server.NetworkManager.b(NetworkManager.java:276)
        at net.minecraft.server.NetServerHandler.d(NetServerHandler.java:109)
        at net.minecraft.server.ServerConnection.b(SourceFile:35)
        at net.minecraft.server.DedicatedServerConnection.b(SourceFile:30)
        at net.minecraft.server.MinecraftServer.q(MinecraftServer.java:581)
        at net.minecraft.server.DedicatedServer.q(DedicatedServer.java:212)
        at net.minecraft.server.MinecraftServer.p(MinecraftServer.java:474)
        at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:406)
        at net.minecraft.server.ThreadServerApplication.run(SourceFile:539)
    Caused by: java.lang.NullPointerException
        at me.Whatshiywl.heroestats.HeroeStats.onCommand(HeroeStats.java:43)
        at org.bukkit.command.PluginCommand.execute(PluginCommand.java:40)
        ... 15 more
    It seems to point to this line of the code:

    getServer().

    The full thing is here:

    Code:
    package me.Whatshiywl.heroestats;
     
    import java.util.logging.Logger;
     
    import me.Whatshiywl.heroestats.HeroeStats;
     
    import org.bukkit.ChatColor;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;
    import org.bukkit.plugin.PluginDescriptionFile;
    import org.bukkit.plugin.java.JavaPlugin;
     
    import com.herocraftonline.heroes.Heroes;
    //import com.herocraftonline.heroes.characters.CharacterManager;
    import com.herocraftonline.heroes.characters.Hero;
    //import com.herocraftonline.heroes.characters.classes.HeroClassManager;
     
    public class HeroeStats extends JavaPlugin
    {
        public final Logger logger = Logger.getLogger("Minecraft");
        //public final Hero hero;
        public Heroes heros;
        public static HeroeStats plugin;
       
        @Override
        public void onDisable()
        {
            PluginDescriptionFile pdfFile = this.getDescription();
            this.logger.info(pdfFile.getName() + " Has Been Disabled!");
        }
       
        @Override   
        public void onEnable()
        {
            PluginDescriptionFile pdfFile = this.getDescription();
            this.logger.info(pdfFile.getName() + " Version " + pdfFile.getVersion() + " Has Been Enabled!");
        }
       
        public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args)
        {
            heros = (Heroes)plugin.
                    getServer().
                    getPluginManager().
                    getPlugin("Heroes");
            Player player = (Player) sender;
            Hero hero = heros.
                    getCharacterManager().
                    getHero(player);
            if(commandLabel.equalsIgnoreCase("stats"))
            {
                player.sendMessage("Health is " + hero.getMaxHealth());
                player.sendMessage(ChatColor.BLUE + "Player stats go here!");
            }
        return false;
        }
    }
    
    I'm not sure about it but is this telling me that my server is returning null? :confused: That makes no sense to me at all xD

    Can anyone please help me? Thanks in advance! \o/
     
  2. Offline

    andf54

    I don’t see plugin field initialised anywhere.

    Look in bukkits javadocs and see what method can return nulls. Make appropriate checks and notifications.
     
  3. Offline

    Whatshiywl

    but isn't "public static HeroeStats plugin;" supposed to initialise the plugin thing? tbh, i realy don't understand what is this plugin field u'r talking about D: nor do I know what are appropriate checks and notifications. basicaly i'm a complete noob with java and making plugins :S

    by methods that can return null you mean something like getServer() or whateverSomething() ?

    sorry for all the stupidity D:
     
  4. Offline

    Firefly

    Learn basic Java. Initialize plugin. Profit.
     
  5. Offline

    tommycake50

    yep you only need basic java C:
     
  6. Offline

    Whatshiywl

    ohhh it was "plugin = this;"!? that worked and makes sense :p i just didn't know this meant initialize haha thanks for the help!
     
  7. Offline

    Firefly

    No that would initialize HeroesPlugin as your plugin, not the actual Heroes plugin.
     
  8. Offline

    Whatshiywl

    ahn... but it works D: it's so beautiful and fancy now without errors... is there any need to change it? I mean, is it bad to leave it like that? :S because i'm being able to manage everything i need so far. :p
     
  9. Offline

    Firefly

    You won't be using anything from Heroes if you leave it like that. Do you understand basic Java? This worries me that you hope you don't "need to change it."
     
  10. Offline

    Whatshiywl

    well, no I don't understand basic Java. I understand basic programming (C++) and with Java I'm kind of learning things on the go. As for the plugin thing, I'm being able to use Heroes stuff. My plugin is being able to get and set Health so far and I think i could do the same for Mana and other stuff... But still, idk the difference of HeroesPlugin and Heroes plugin xD(?)
     
Thread Status:
Not open for further replies.

Share This Page