A proper hook for your plugin

Discussion in 'Plugin Development' started by Randy Schouten, Jul 28, 2011.

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

    Randy Schouten

    I have created an API for my plugin EpicQuest, but whenever I use it in another plugin, it just gives me the nullPointerException.
    This also happens if it's just a void method.

    Plugin code:

    Code:
    	public static randy.eq.eqAPI EpicQuest;
    
    public void onPlayerInteractEntity(PlayerInteractEntityEvent event){
            if(NPCManager.isNPC(event.getRightClicked())){
                Player player = event.getPlayer();
                String newplayer = player.toString().replace("CraftPlayer{name=", "").replace("}", "");
                String npcname = event.getRightClicked().toString().replace("CraftPlayer{name=", "").replace("}", "");
                npcname = ChatColor.stripColor(npcname);
                //If NPC has a specific quest
                if(npcq.qspecific.containsKey(npcname)){
                    player.sendMessage(EpicQuest.getCurrentQuestList(newplayer));
                }
          }
    }
    EpicQuest code (this is part of the eqAPI class):
    Code:
    public String getCurrentQuestList(String player){
            String list = eq.questcurrent.get(player+".questlist").toString();
            return list;
        }
    I am sure it's not empty.
    I gave myself a few quests before trying it and checked that with another command I made in EpicQuest to check the quest list.
     
  2. Offline

    Hretsam

    Do you ever load the the object?
    So EpicQuest = something;
    Otherwise the object will just be empty... (null)
     
  3. Offline

    Randy Schouten

    First I import the class, then I typed the other code with EpicQuest...

    As I said, I'm fairly new to making API's and all, so I don't know how else I would do it :p
     
  4. Offline

    bleachisback

    You need to actually instantiate the variable. To do that with a plugin you would do
    Code:
    EpicQuest quest=(EpicQuest) getServer().getPluginManager().getPlugin("EpicQuest");
     
  5. You have to make whatever hooks into EpicQuest 'depend' on it. You do this in the plugin/yml of the plugin to hookinto epic quest.

    PHP:
    depend: [EpicQuest]
     
    Abrupt likes this.
  6. Offline

    Randy Schouten

    Gotcha, thanks!
     
  7. No problem ;)
     
Thread Status:
Not open for further replies.

Share This Page