[Solved] MM API usage

Discussion in 'Support' started by Roger M, Apr 30, 2018.

  1. Roger M

    Roger M Member
    Supporter

    Joined:
    May 13, 2016
    Messages:
    71
    Likes Received:
    8
    I need some help from someone with a little more of a java background than myself. On chunk loading I am testing to see if entities are Mythic Mobs or not, and it is not working, but rather getting a NPE. Here is the class in question:
    Code:
    package mobdetection;
    
    import io.lumine.xikage.mythicmobs.MythicMobs;
    import org.bukkit.Bukkit;
    import org.bukkit.entity.Entity;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.world.ChunkLoadEvent;
        
    
    /**
    *
    * @author RogerPlaysMC <github.com/RogerPlaysMC>
    */
    public class ChunkLoading implements Listener{
        MythicMobs pl =(MythicMobs)Bukkit.getPluginManager().getPlugin("MythicMobs");
      
        @EventHandler
        public void onLoad(ChunkLoadEvent c){
            Entity[] en = c.getChunk().getEntities();
            if(en == null){
                return;
            }
            for(Entity ent: en){
                if(ent == null){
                    return;
                }
                if(!pl.getAPIHelper().isMythicMob(ent)){  //This is where the NPE starts
                    Bukkit.broadcastMessage(ent.getType().toString());
                }
                if(pl.getAPIHelper().isMythicMob(ent)){  //This also sends a NPE if the previous if statement is eliminated
                    Bukkit.broadcastMessage("GG" + ent.getType().toString());
                }
            }
        }
    }
    What this should do is detect existing mobs on chunk load. If they are not a MM, say the type. If they are a MM, say the "GG" + the type. MythicMobs.getAPIHelper().isMythicMob(ent) should be returning a boolean for the the if statement according to the javadocs, and I have tried doing it by using the UUID instead with the same result.

    The NPE comes from the commented line above. When I don't use the MM condition and instead just print out the type of every mob instead, everything works out fine.

    Would I be better of looking for a MM specific meta tag on the mob?

    Thanks in advance for the help. I know this is likely due to my limited understanding of java, so apologies in advance. @xikage @jaylawl (sorry for the tags, but I bet you two have the most experience with this sort of issue).

    Using Spigot 1.12.2, updated today, and the latest dev release of MM.
     
    #1
    Last edited: May 1, 2018
  2. xikage

    xikage Administrator
    Administrator Developer Supporter

    Joined:
    Jul 18, 2015
    Messages:
    582
    Likes Received:
    207
    It looks like it should work fine. Can you post the NPE?
     
    #2
  3. Roger M

    Roger M Member
    Supporter

    Joined:
    May 13, 2016
    Messages:
    71
    Likes Received:
    8
    Well, it's odd, it started working properly after my most recent build where I used IntelliJ instead of NetBeans... no idea why, but I'm not fighting it. Line for line copy too.

    It is also setting off a crazy NPE chain on server startup, but that's because MM has not loaded yet and my plugin is trying to call the API every time a spawn chunk loads, so no worries there.

    ^ I just removed "load: startup" from the plugin.yml. Since there is already a depend on MM it enabled after MM, and the NPE on startup is gone.

    In summary, the problem was NetBeans for some unknown reason, and I appreciate you taking the time to look at this @xikage !
     
    #3

Share This Page