Could not pass event PlayerInteractEvent

Discussion in 'Plugin Development' started by legostarwarszach, Jun 9, 2013.

Thread Status:
Not open for further replies.
  1. Im getting this error everytime I interact with a Gold Sword. I know where the error is, it's in my line:
    Code:
                if(plugin.inagame.containsValue(player)){
    
    The place where the problem appears is in code:
    Code:
        @EventHandler
        public void onPlayerInteract(PlayerInteractEvent inter){
            Player player = inter.getPlayer();
            int blockID = player.getItemInHand().getType().getId();
            if(player.hasPermission(new Permissions().usegod)){
                if(plugin.inagame.containsValue(player)){
        //        if(inagame.)
            if(blockID==283){
                Block b = player.getTargetBlock(null, 50);
                Location l = b.getLocation();
                World w = player.getWorld();
                w.strikeLightning(l);
                inter.setCancelled(true);
            }if(blockID==276){
                Block b1 = player.getTargetBlock(null, 50);
                Location l1 = b1.getLocation();
                World w1 = player.getWorld();
                w1.createExplosion(l1, 5);
                inter.setCancelled(true);
            }if(blockID==352){
                Block b2 = player.getTargetBlock(null, 50);
                Block la = b2.getLocation().add(0,1,0).getBlock();
                Location l2 = la.getLocation();
                World w2 = player.getWorld();
                w2.spawnEntity(l2, EntityType.WOLF);
                inter.setCancelled(true);
            }if(blockID==267){
                Block b3 = player.getTargetBlock(null, 50);
                Block lb = b3.getLocation().add(0,1,0).getBlock();
                Location l3 = lb.getLocation();
                World w3 = player.getWorld();
                w3.spawnEntity(l3, EntityType.IRON_GOLEM);
                inter.setCancelled(true);
            }if(blockID==369){
            }
            }if(!(plugin.inagame.containsValue(player))){
               
            }
       
        }
        }
        
    Thanks,
    Zach
     
  2. Offline

    caseif

    You haven't provided the stack trace, but I'll assume it's an NPE. In that case, the null variables could be plugin or inagame. Debug to figure out which is null and why.
     
  3. Offline

    caseif

    I would recommend creating an instance of the plugin in the onEnable() and saving it to a global variable in the main class, then just either referencing that, or creating a plugin variable in each class and setting the value to that of the instance in the main class.
     

  4. Ummmmm, can you give me and example?
     
  5. Offline

    caseif

    Define an unassigned static global plugin variable in the main class of type MainClass:
    Code:
    public static MainClass plugin;
    Directly reference it from other classes:
    Code:
    MainClass.plugin.whateverMethodYouWantToCall();
    Create a new instance and reference that:
    Code:
    // this code goes in the class you're calling plugin from
    public static plugin = MainClass.plugin;
    plugin.whateverMethodYouWantToCall();
     
Thread Status:
Not open for further replies.

Share This Page