Events messing with other Events

Discussion in 'Plugin Development' started by SilverNinja555, Dec 6, 2017.

  1. Offline

    SilverNinja555

    I really do not understand why :
    Code:
    @EventHandler
    
        public void wolfSpawn(EntitySpawnEvent e){
            Entity original = e.getEntity();
            Biome biome = original.getLocation().getBlock().getBiome();
            Material block = original.getLocation().getBlock().getType();
            int random = (int) (Math.random() * 1000);
            if(!original.equals(EntityType.ENDER_CRYSTAL) && !original.equals(EntityType.ENDER_DRAGON) && !original.equals(EntityType.WITHER)){
                if(biome.equals(Biome.SWAMPLAND)){
                    if(random < 5 && (block.equals(Material.DIRT) || block.equals(Material.GRASS_PATH))){
                        e.setCancelled(true);
                        spawnPoisonWolf(instance, original);
                    }
                }
    }
    }
    Messes with :
    Code:
    @EventHandler
    
        public void spawnWolfCheck(InventoryClickEvent e){
    
            HumanEntity user = e.getWhoClicked();
    
            ItemStack item = e.getCurrentItem();
    
            if(e.getInventory().equals(wolfMenu)){
    
                if(item.getData().getItemType().equals(Material.BONE)){
    
                    user.getLocation().getWorld().spawnEntity(user.getLocation(), EntityType.WOLF);
    
                    e.setCancelled(true);
    
                }
    }
    }
    By the way, the InventoryClickEvent worked before I added the EntitySpawnEvent.
     
  2. So for one don't use the human entity, use player to see the inventory click.

    Can you post your registering of the events inside pastebin and the full clas, please?
     
  3. Offline

    SilverNinja555

  4. Offline

    timtower Ninja on the waves Moderator

    @SilverNinja555 Enums need to be compared with ==
    Strings with equals or equalsIgnoreCase
     
  5. Offline

    SilverNinja555

  6. Offline

    timtower Ninja on the waves Moderator

  7. Offline

    SilverNinja555

  8. Offline

    timtower Ninja on the waves Moderator

    @SilverNinja555 Did you try to debug to see to which check the code runs?
     
  9. Offline

    SilverNinja555

    @timtower I first tested the InventoryClickEvent(btw, change the == wolfMenu to .equals). It for some reason doesn't register the clicking with the EntitySpawnEvent, but works fine without the EntitySpawnEvent.
     
  10. Offline

    timtower Ninja on the waves Moderator

  11. Offline

    SilverNinja555

  12. Offline

    timtower Ninja on the waves Moderator

    Could you post the code that you used to check that?
     
  13. Offline

    SilverNinja555

    @timtower

    I just did:
    Code:
        public void spawnWolfCheck(InventoryClickEvent e){
          
            Player user = (Player) e.getWhoClicked();
    user.sendMessage("event triggered");
            ItemStack item = e.getCurrentItem();
    
            if(e.getInventory().equals(wolfMenu)){
    user.sendMessage("in wolfMenu");
                if(item.getData().getItemType() == Material.BONE){
    
                    user.getLocation().getWorld().spawnEntity(user.getLocation(), EntityType.WOLF);
    
                    e.setCancelled(true);
    
               
    }
    }
    It did not send the "event triggered"
     

Share This Page