Eventhandler wont register

Discussion in 'Plugin Development' started by J_ZAX123, Nov 29, 2019.

  1. Offline

    J_ZAX123

    So I've been working on this plugin for a while now and all the events have been working until I updated it to 1.14.4 then some of the events just stopped working. I have no idea why but it seems as if they just aren't registered anymore. My event handlers in my other classes are working just not in my Main or Projectiles class I'm still new to javascript so I might just be making a really stupid mistake and help is much appreciated. I also removed all the crafting recipes and commands in my main classes to save room on characters and I also had no problems with them.

    Here is my Main class:
    Code:
    @SuppressWarnings("unused")
    public class Main extends JavaPlugin implements Listener
    {
      public final InventoryListener Listener = new InventoryListener();
      private Menu menu;
      private HashMap<Player, Integer> cooldownTime;
      private HashMap<Player, BukkitRunnable> cooldownTask;
    
    @Override
    public void onEnable()
          {
        saveDefaultConfig();
        menu = new Menu();
      
        cooldownTime = new HashMap<Player, Integer>();
        cooldownTask = new HashMap<Player, BukkitRunnable>();
        Bukkit.getServer().getLogger().info("------------------------");
        Bukkit.getServer().getLogger().info("===DnD Time===");
        Bukkit.getServer().getLogger().info("------------------------");
        getServer().getPluginManager().registerEvents(this, this);
        getServer().getPluginManager().registerEvents(new Chat(), this);
        getServer().getPluginManager().registerEvents(new InventoryListener(), this);
        getServer().getPluginManager().registerEvents(new Projectiles(), this);
        getServer().getPluginManager().registerEvents(new Menu(), this);
      
      }
      public void onDisable()
      {
    //inside jokes with my friends
        getLogger().info("=============");
        getLogger().info("China NOT NOW!");
        getLogger().info("=============");
      }
    
      @EventHandler
        public void onPlayerUse(PlayerInteractEvent event)
        {
        Player player = event.getPlayer();  
      
        if (player.getInventory().getItemInMainHand() != null)
            {
              if (((player.getInventory().getItemInMainHand().getType().equals(Material.CLOCK))))
              {
                  menu.show(event.getPlayer());
              }
            }
        }
    }
    
    Projectiles class:
    Code:
    public class Projectiles implements Listener
    {
        public HashMap<String, Long> cooldown;
      
        public Projectiles()
        {
            cooldown = new HashMap<String, Long>();
        }
      
      @EventHandler
      public boolean beam (PlayerAnimationEvent event)
      {
        if (event.getAnimationType().equals(PlayerAnimationType.ARM_SWING))
        {
          double d20 = Math.floor(Math.random() * 20.0D) + 1.0D;
          Player player = event.getPlayer();
          player.sendMessage("test");
        
          if ((player.getInventory().getItemInMainHand() != null) && (player.getInventory().getItemInMainHand().getType() == Material.BOOK) && (player.getInventory().getItemInMainHand().getItemMeta().getDisplayName().equals(ChatColor.RED + "Inflict Wounds")))
          {
           if (player.getGameMode() != GameMode.CREATIVE) {player.getInventory().getItemInMainHand().setAmount(player.getInventory().getItemInMainHand().getAmount() - 1); }
           player.sendMessage("test1");
           int seconds = 5;
           if(cooldown.containsKey(player.getName()))
           {
               long timer = (cooldown.get(player.getName())/1000 + seconds) - System.currentTimeMillis()/1000;
               if(!(timer < 0))
               {
                   player.sendMessage("You have to wait for " + timer + " seconds for your magic to regenerate");
                   return true;
                }else
                {
                    cooldown.remove(player.getName());
                }
            }else
            {
                cooldown.put(player.getName(), System.currentTimeMillis());
            }
            if (d20 > 14.0D)
            {
                player.sendMessage("You rolled a " + d20 + " inflict wounds was successful");
                Location loc = player.getLocation();
                Vector direction = loc.getDirection();
                player.getLocation().getWorld().playSound(loc, Sound.ENTITY_PLAYER_SMALL_FALL, 1.0F, 2.0F);
              for (double t = 0.0D; t < 16.0D; t += 1.0D)
              {
                loc.add(direction);
                loc.add(0.0D, 1.5D, 0.0D);
                if (loc.getBlock().getType().isSolid())
                  break;
                Entity[] arrayOfEntity1;
                double d4 = (arrayOfEntity1 = loc.getChunk().getEntities()).length; for (int d1 = 0; d1 < d4; d1++)
                {
                    Entity e = arrayOfEntity1[d1];
                  if ((e.getLocation().distance(loc) < 1.5D) &&  (e != player) && (e.getType().isAlive()))
                  {
                    Damageable d = (Damageable)e;
                  if(d20>18)
                  {
                      d.damage(20.0D, player);
                      String succiw = ChatColor.translateAlternateColorCodes('&', " &fYour inflict wounds was &aVERY &f successful");
                      player.sendMessage(succiw);
                      break;
                  }else
                  {
                    d.damage(5.0D, player);
                    break;
                    }
                  }
                }
                loc.subtract(0.0D, 1.5D, 0.0D);
              }
            }
            else
            {
              player.sendMessage("You rolled a " + d20 + " inflict wounds was unsuccessful");
              if(d20 < 2)
              {
                  String unsucciw = ChatColor.translateAlternateColorCodes('&', "&fYour inflict wounds was &4VERY &f unsuccessful");
                  player.sendMessage(unsucciw);
                  player.damage(2);
              }
            }
            }
          return true;
        }
      
      
      
        if (event.getAnimationType().equals(PlayerAnimationType.ARM_SWING))
        {
          Player player = event.getPlayer();
        
          if ((player.getInventory().getItemInMainHand() != null) && (player.getInventory().getItemInMainHand().getType() == Material.BOOK) && (player.getInventory().getItemInMainHand().getItemMeta().getDisplayName().equals(ChatColor.AQUA + "Heal Wounds")))
          {
            if (player.getGameMode() != GameMode.CREATIVE) {player.getInventory().getItemInMainHand().setAmount(player.getInventory().getItemInMainHand().getAmount() - 1);}
            int seconds = 5;
          
            if(cooldown.containsKey(player.getName()))
            {
               long timer = (cooldown.get(player.getName())/1000 + seconds) - System.currentTimeMillis()/1000;
               if(!(timer < 0))
               {
                   player.sendMessage("You have to wait for " + timer + " seconds for your magic to regenerate");
                   return true;
                }else
                {
                     cooldown.remove(player.getName());
                }
             }else
             {
                 cooldown.put(player.getName(), System.currentTimeMillis());
             }
            Location loc = player.getLocation();
            Vector direction = loc.getDirection();
            player.getLocation().getWorld().playSound(loc, Sound.BLOCK_NOTE_BLOCK_CHIME, 100.0F, 100.0F);
            for (double t = 0.0D; t < 32.0D; t += 1.0D)
            {
              loc.add(direction);
              loc.add(0.0D, 1.5D, 0.0D);
              if (loc.getBlock().getType().isSolid())
              break;
              Entity[] arrayOfEntity2;
              double d4 = (arrayOfEntity2 = loc.getChunk().getEntities()).length;
              for (int d2 = 0; d2 < d4; d2++)
              {
                Entity e = arrayOfEntity2[d2];
                if (e.getLocation().distance(loc) < 1.5D)
                {
                  if (e.getType().isAlive())
                  {
                    Damageable d = (Damageable)e;
                    if (e != player)
                    {
                      ((LivingEntity)d).addPotionEffect(new PotionEffect(PotionEffectType.REGENERATION, 100, 0));
                    }
                  }
                }
              }loc.subtract(0.0D, 1.5D, 0.0D);
              }
            }
          return true;
          }
      
        if (event.getAnimationType().equals(PlayerAnimationType.ARM_SWING))
        {
            Player player = event.getPlayer();    
            if (player.getInventory().getItemInMainHand() != null)
            {
              if ((player.getInventory().getItemInMainHand().getType() == Material.BOOK) && (player.getInventory().getItemInMainHand().getItemMeta().getDisplayName().equals(ChatColor.RED + "Thunder Clap")))
              {
                  double d20 = Math.floor(Math.random() * 20.0D) + 1.0D;
                
                  if (player.getGameMode() != GameMode.CREATIVE) {player.getInventory().getItemInMainHand().setAmount(player.getInventory().getItemInMainHand().getAmount() - 1);}
                  int seconds = 5;
                  if(cooldown.containsKey(player.getName()))
                  {
                     long timer = (cooldown.get(player.getName())/1000 + seconds) - System.currentTimeMillis()/1000;
                     if(!(timer < 0))
                     {
                         player.sendMessage("You have to wait for " + timer + " seconds for your magic to regenerate");
                         return true;
                      }else
                      {
                           cooldown.remove(player.getName());
                      }
                   }else
                   {
                       cooldown.put(player.getName(), System.currentTimeMillis());
                   }
                  if (d20 > 12.0D)
                  {
                player.sendMessage("You rolled a " + d20 + " thunder clap was successful");
                Location loc = player.getLocation();
                Vector direction = loc.getDirection();
                World world = player.getWorld();
                Block targetblock = player.getTargetBlockExact(64);
                Location location = targetblock.getLocation();
                world.createExplosion(location, 0.0F);
                player.getLocation().getWorld().playSound(loc, Sound.ENTITY_LIGHTNING_BOLT_IMPACT, 10.0F, 10.0F);
                for (double t = 0.0D; t < 32.0D; t += 1.0D)
                {
                  loc.add(direction);
                  loc.add(0.0D, 1.5D, 0.0D);
                  if (loc.getBlock().getType().isSolid())
                    break;
                  Entity[] arrayOfEntity4;
                  double z = (arrayOfEntity4 = loc.getChunk().getEntities()).length; for (int d1 = 0; d1 < z; d1++)
                  {
                      Entity e = arrayOfEntity4[d1];
                    if ((e.getLocation().distance(loc) < 1.5D) && (e != player))
                    {
                      Damageable d11 = (Damageable)e;
                      if (e.getType().isAlive())
                      {
                          if(d20 > 18)
                          {
                              String succtc = ChatColor.translateAlternateColorCodes('&', "&fYour thunder clap was &aVERY &f successful");
                              player.sendMessage(succtc);
                              world.createExplosion(location, 2);
                              d11.damage(10.0D, player);
                              break;
                          }else
                          {
                              d11.damage(4.0D, player);
                              break;
                          }
                      }
                    }
                  }
                }
                }else
                {
                    player.sendMessage("You rolled a " + d20 + " thunder clap was unsuccessful");
                    if(d20 < 2)
                    {
                        String unsucctc = ChatColor.translateAlternateColorCodes('&', "&fYour thunder clap was &4VERY &f unsuccessful");
                      player.sendMessage(unsucctc);
                      player.damage(2);
                    }
                }
              }
          }
            return true;
        }
        
        if (event.getAnimationType().equals(PlayerAnimationType.ARM_SWING))
        {
          Player player = event.getPlayer();
          if (player.getInventory().getItemInMainHand() != null)
          {
            if ((player.getInventory().getItemInMainHand().getType() == Material.BOOK) && (player.getInventory().getItemInMainHand().getItemMeta().getDisplayName().equals(ChatColor.RED + "Lightning Bolt")))
            {
              double d20 = Math.floor(Math.random() * 20.0D) + 1.0D;
            
              if (player.getGameMode() != GameMode.CREATIVE) {player.getInventory().getItemInMainHand().setAmount(player.getInventory().getItemInMainHand().getAmount() - 1); }
              int seconds = 5;
              if(cooldown.containsKey(player.getName()))
              {
                 long timer = (cooldown.get(player.getName())/1000 + seconds) - System.currentTimeMillis()/1000;
                 if(!(timer < 0))
                 {
                     player.sendMessage("You have to wait for " + timer + " seconds for your magic to regenerate");
                     return true;
                  }else
                  {
                       cooldown.remove(player.getName());
                  }
               }else
               {
                   cooldown.put(player.getName(), System.currentTimeMillis());
               }
              if (d20 > 10.0D)
              {
                player.sendMessage("You rolled a " + d20 + " lighning bolt was successful");
                Location loc = player.getLocation();
                loc.getDirection();
                World world = player.getWorld();
                Block targetblock = player.getTargetBlockExact(64);
                Location location = targetblock.getLocation();
                world.strikeLightning(location);
                player.getLocation().getWorld().playSound(loc, Sound.ENTITY_LIGHTNING_BOLT_IMPACT, 1.0F, 2.0F);
                if(d20 > 18)
                {
                    world.createExplosion(location, 1);
                    world.strikeLightning(location);world.strikeLightning(location);world.strikeLightning(location);
                    String succlb = ChatColor.translateAlternateColorCodes('&', "&fYour thunder bolt was &aVERY &f successful");
                    player.sendMessage(succlb);
                }
              }
              else
              {
                player.sendMessage("You rolled a " + d20 + "lightning bolt was unsuccessful");
                if(d20<2)
                {
                  String unsucclb = ChatColor.translateAlternateColorCodes('&', "&fYour thunder bolt was &4VERY &f unsuccessful");
                player.sendMessage(unsucclb);
                World world = player.getWorld();
                Location loc = player.getLocation();
                world.strikeLightning(loc);
                }
              }
            }
          }
          return true;
        }
      
        if (event.getAnimationType().equals(PlayerAnimationType.ARM_SWING))
        {
          Player player = event.getPlayer();
          if ((player.getInventory().getItemInMainHand() != null) && (player.getInventory().getItemInMainHand().getType() == Material.BOOK) && (player.getInventory().getItemInMainHand().getItemMeta().getDisplayName().equals(ChatColor.RED + "Fire Bolt")))
          {
            if (player.getGameMode() != GameMode.CREATIVE) {player.getInventory().getItemInMainHand().setAmount(player.getInventory().getItemInMainHand().getAmount() - 1); }
            double d20 = Math.floor(Math.random() * 20.0D) + 1.0D;
            int seconds = 5;
            if(cooldown.containsKey(player.getName()))
            {
               long timer = (cooldown.get(player.getName())/1000 + seconds) - System.currentTimeMillis()/1000;
               if(!(timer < 0))
               {
                   player.sendMessage("You have to wait for " + timer + " seconds for your magic to regenerate");
                   return true;
                }else
                {
                     cooldown.remove(player.getName());
                }
             }else
             {
                 cooldown.put(player.getName(), System.currentTimeMillis());
             }
            if (d20 > 8.0D)
            {
              player.sendMessage("You rolled a " + d20 + " fire bolt was successful");
              Location loc = player.getLocation();
              loc.getDirection();
              World world = player.getWorld();
              Block targetblock = player.getTargetBlockExact(64);
              Location location = targetblock.getLocation();
              double x = location.getX();
              double y = location.getY() + 1.0D;
              double z = location.getZ();
              new Location(world, x, y, z);
              location.getBlock().getRelative(org.bukkit.block.BlockFace.UP).setType(Material.FIRE);
              player.getLocation().getWorld().playSound(loc, Sound.ENTITY_GHAST_SHOOT, 1.0F, 2.0F);
              if(d20>18)
              {
                  String succfb = ChatColor.translateAlternateColorCodes('&', " &fYour fire bolt was &aVERY &f successful");
                  player.sendMessage(succfb);
                  world.createExplosion(location, 2);
              }
            }else
            {
              player.sendMessage("You rolled a " + d20 + " fire bolt was unsuccessful");
              if(d20<2)
              {
                    String unsuccfb = ChatColor.translateAlternateColorCodes('&', "&fYour fire bolt was &4VERY &f unsuccessful");
                    player.sendMessage(unsuccfb);
                    player.setFireTicks(40);
              }
            }
          }
          return true;
        }
        if (event.getAnimationType().equals(PlayerAnimationType.ARM_SWING))
        {
          Player player = event.getPlayer();
          if ((player.getInventory().getItemInMainHand() != null) && (player.getInventory().getItemInMainHand().getType() == Material.DIAMOND_SWORD) && (player.getInventory().getItemInMainHand().getItemMeta().getDisplayName().equals(ChatColor.RED + "Fire Sword")))
          {
              Location loc = player.getLocation();
              Vector direction = loc.getDirection();
              player.getLocation().getWorld().playSound(loc, Sound.ENTITY_GHAST_SHOOT, 1.0F, 2.0F);
              for (double t = 0.0D; t < 5.0D; t += 1.0D) {
                loc.add(direction);
                loc.add(0.0D, 1.5D, 0.0D);
                if (loc.getBlock().getType().isSolid())
                break;
                Entity[] arrayOfEntity3;
                double d5 = (arrayOfEntity3 = loc.getChunk().getEntities()).length; for (int d3 = 0; d3 < d5; d3++) { Entity e = arrayOfEntity3[d3];
                  if ((e.getLocation().distance(loc) < 1.5D) && (e != player) && (e.getType().isAlive())) {
                   //Damageable d13 = (Damageable)e;
                    Location locatione = e.getLocation();
                    locatione.getDirection();
                    World world = e.getWorld();
                    double x = locatione.getX();
                    double y = locatione.getY() + 1.0D;
                    double z = locatione.getZ();
                    new Location(world, x, y, z);
                    //test later
                    //if(!locatione.getBlock().getType().equals(Material.AIR)) return;
                    locatione.getBlock().setType(Material.FIRE);
                    break;
                  }
                }
                loc.subtract(0.0D, 1.5D, 0.0D);
              }
            }
          return true;
          }
      
        if (event.getAnimationType().equals(PlayerAnimationType.ARM_SWING))
        {
          Player player = event.getPlayer();
          if ((player.getInventory().getItemInMainHand() != null) &&
            (player.getInventory().getItemInMainHand().getType() == Material.STICK) && (player.getInventory().getItemInMainHand().getItemMeta().getDisplayName().equals(ChatColor.RED + "Boom Stick")))
          {
              int seconds = 30;
              if(cooldown.containsKey(player.getName()))
              {
                 long timer = (cooldown.get(player.getName())/1000 + seconds) - System.currentTimeMillis()/1000;
                 if(!(timer < 0))
                 {
                     player.sendMessage("You have to wait for " + timer + " seconds for your boom stick to recharge");
                     return true;
                  }else
                  {
                       cooldown.remove(player.getName());
                  }
               }else
               {
                   cooldown.put(player.getName(), System.currentTimeMillis());
               }
              Location loc = player.getLocation();
              Vector direction = loc.getDirection();
              player.getLocation().getWorld().playSound(loc, Sound.ENTITY_GHAST_SHOOT, 1.0F, 2.0F);
              for (double t = 0.0D; t < 8.0D; t += 1.0D)
              {
                loc.add(direction);
                loc.add(0.0D, 1.5D, 0.0D);
                if (loc.getBlock().getType().isSolid())
                break;
                Entity[] arrayOfEntity3;
                double d5 = (arrayOfEntity3 = loc.getChunk().getEntities()).length; for (int d3 = 0; d3 < d5; d3++)
                {
                    Entity e = arrayOfEntity3[d3];
                  if ((e.getLocation().distance(loc) < 1.5D) && (e != player) && (e.getType().isAlive()))
                  {
                    Damageable d13 = (Damageable)e;
                    World world = d13.getWorld();
                    Location locatione = d13.getLocation();
                    double x = locatione.getX();
                    double y = locatione.getY() + 1.0D;
                    double z = locatione.getZ();
                    new Location(world, x, y, z);
                    world.createExplosion(locatione, 1);
                    world.strikeLightning(locatione);
                    d13.damage(6.0D);
                    break;
                  }
                }
                loc.subtract(0.0D, 1.5D, 0.0D);
              }
            }
          return true;
        }
      
        if (event.getAnimationType().equals(PlayerAnimationType.ARM_SWING))
        {
          Player player = event.getPlayer();
          if ((player.getInventory().getItemInMainHand() != null) && (player.getInventory().getItemInMainHand().getType() == Material.DIAMOND_SWORD) && (player.getInventory().getItemInMainHand().getItemMeta().getDisplayName().equals(ChatColor.RED + "Ghast Sword")))
          {
              int seconds = 10;
              if(cooldown.containsKey(player.getName()))
              {
                 long timer = (cooldown.get(player.getName())/1000 + seconds) - System.currentTimeMillis()/1000;
                 if(!(timer < 0))
                 {
                     player.sendMessage("You have to wait for " + timer + " seconds for your ghast sword to recharge its magic");
                     return true;
                  }else
                  {
                       cooldown.remove(player.getName());
                  }
               }else
               {
                   cooldown.put(player.getName(), System.currentTimeMillis());
               }
              Location loc = player.getLocation();
              Vector direction = loc.getDirection();
              player.getLocation().getWorld().playSound(loc, Sound.ENTITY_GHAST_SHOOT, 1.0F, 2.0F);
              for (double t = 0.0D; t < 8.0D; t += 1.0D)
              {
                loc.add(direction);
                loc.add(0.0D, 1.5D, 0.0D);
                if (loc.getBlock().getType().isSolid())
                  break;
                Entity[] arrayOfEntity3;
                double d5 = (arrayOfEntity3 = loc.getChunk().getEntities()).length; for (int d3 = 0; d3 < d5; d3++) { Entity e = arrayOfEntity3[d3];
                  if ((e.getLocation().distance(loc) < 1.5D) && (e != player) && (e.getType().isAlive()))
                  {
                    Location locatione = e.getLocation();
                    locatione.getDirection();
                    World world = e.getWorld();
                    double x = locatione.getX();
                    double y = locatione.getY() + 1.0D;
                    double z = locatione.getZ();
                    new Location(world, x, y, z);
                    player.launchProjectile(Fireball.class);
                    break;
                  }
                }
                loc.subtract(0.0D, 1.5D, 0.0D);
              }
            }
          return true;
          }
      
        if (event.getAnimationType().equals(PlayerAnimationType.ARM_SWING))
        {
          Player player = event.getPlayer();
        
          if ((player.getInventory().getItemInMainHand() != null) && (player.getInventory().getItemInMainHand().getType() == Material.STICK) && (player.getInventory().getItemInMainHand().getItemMeta().getDisplayName().equals(ChatColor.RED + "Javelin")))
          {
           if (player.getGameMode() != GameMode.CREATIVE)
           {
               player.getInventory().getItemInMainHand().setAmount(player.getInventory().getItemInMainHand().getAmount() - 1);
           }
           double d20j = Math.floor(Math.random() * 20.0D) + 1.0D;
           int seconds = 3;
           if(cooldown.containsKey(player.getName()))
           {
               long timer = (cooldown.get(player.getName())/1000 + seconds) - System.currentTimeMillis()/1000;
               if(!(timer < 0))
               {
                   player.sendMessage("You have to wait for " + timer + " to retrieve another javelin");
                   return true;
                }else
                {
                    cooldown.remove(player.getName());
                }
            }else
            {
                cooldown.put(player.getName(), System.currentTimeMillis());
            }
          
            if (d20j > 12.0D)
            {
              player.sendMessage("You rolled a " + d20j + " your javelin throw was successful");
              Location loc = player.getLocation();
              Vector direction = loc.getDirection();
              player.getLocation().getWorld().playSound(loc, Sound.ENTITY_PLAYER_ATTACK_SWEEP, 1.0F, 2.0F);
              for (double t = 0.0D; t < 16.0D; t += 1.0D)
              {
                loc.add(direction);
                loc.add(0.0D, 1.5D, 0.0D);
                if (loc.getBlock().getType().isSolid())
                  break;
                Entity[] arrayOfEntity3;
                double d5 = (arrayOfEntity3 = loc.getChunk().getEntities()).length; for (int d3 = 0; d3 < d5; d3++)
                {
                    Entity e = arrayOfEntity3[d3];
                  if ((e.getLocation().distance(loc) < 1.5D) && (e != player) && (e.getType().isAlive()))
                  {
                    Damageable d13 = (Damageable)e;
                    d13.damage(4.0D, player);
                    break;
                  }
                }
                loc.subtract(0.0D, 1.5D, 0.0D);
              }
            }
            else {
              player.sendMessage("You rolled a " + d20j + " your javelin throw was unsuccessful");
            }
          }
          return true;
        }
      
        if (event.getAnimationType().equals(PlayerAnimationType.ARM_SWING))
        {
          Player player = event.getPlayer();
        
          if ((player.getInventory().getItemInMainHand() != null) && (player.getInventory().getItemInMainHand().getType() == Material.IRON_NUGGET) && (player.getInventory().getItemInMainHand().getItemMeta().getDisplayName().equals(ChatColor.RED + "Evil Undead Boss Spawn Egg")))
                  {
                      if (player.getGameMode() != GameMode.CREATIVE) {player.getInventory().getItemInMainHand().setAmount(player.getInventory().getItemInMainHand().getAmount() - 1);}
                      Mobs.spawnZombie(player);
                      return true;
                  }
        }
        if (event.getAnimationType().equals(PlayerAnimationType.ARM_SWING))
        {
            Player player = event.getPlayer();
            if ((player.getInventory().getItemInMainHand() != null) && (player.getInventory().getItemInMainHand().getType() == Material.IRON_NUGGET) && (player.getInventory().getItemInMainHand().getItemMeta().getDisplayName().equals(ChatColor.RED + "Bone Boss Spawn Egg")))
                  {
                if (player.getGameMode() != GameMode.CREATIVE) {player.getInventory().getItemInMainHand().setAmount(player.getInventory().getItemInMainHand().getAmount() - 1);}
                Mobs.spawnSkeleton(player);
                  return true;
                  }
        }
        if (event.getAnimationType().equals(PlayerAnimationType.ARM_SWING))
        {
          Player player = event.getPlayer();
          
            if ((player.getInventory().getItemInMainHand() != null) && (player.getInventory().getItemInMainHand().getType() == Material.IRON_NUGGET) && (player.getInventory().getItemInMainHand().getItemMeta().getDisplayName().equals(ChatColor.RED + "Arachnid Boss Spawn Egg")))
                  {
                if (player.getGameMode() != GameMode.CREATIVE) {player.getInventory().getItemInMainHand().setAmount(player.getInventory().getItemInMainHand().getAmount() - 1);}
                  Mobs.spawnSpider(player);
                  return true;
                  }
        }
            if (event.getAnimationType().equals(PlayerAnimationType.ARM_SWING))
            {
              Player player = event.getPlayer();
          
            if ((player.getInventory().getItemInMainHand() != null) && (player.getInventory().getItemInMainHand().getType() == Material.IRON_NUGGET) && (player.getInventory().getItemInMainHand().getItemMeta().getDisplayName().equals(ChatColor.RED + "Fire Boss Spawn Egg")))
                {
                    if (player.getGameMode() != GameMode.CREATIVE) {player.getInventory().getItemInMainHand().setAmount(player.getInventory().getItemInMainHand().getAmount() - 1); }
                    Mobs.spawnBlaze(player);
                    return true;
                }
            }
          
            if (event.getAnimationType().equals(PlayerAnimationType.ARM_SWING))
            {
              Player player = event.getPlayer();
          
            if ((player.getInventory().getItemInMainHand() != null) && (player.getInventory().getItemInMainHand().getType() == Material.IRON_NUGGET) && (player.getInventory().getItemInMainHand().getItemMeta().getDisplayName().equals(ChatColor.RED + "Big Ghost Boss Spawn Egg")))
                    {
                    if (player.getGameMode() != GameMode.CREATIVE) {player.getInventory().getItemInMainHand().setAmount(player.getInventory().getItemInMainHand().getAmount() - 1); }
                    Mobs.spawnGhast(player);
                    return true;
                    }
            }
          
            if (event.getAnimationType().equals(PlayerAnimationType.ARM_SWING))
            {
              Player player = event.getPlayer();
          
              if ((player.getInventory().getItemInMainHand() != null) && (player.getInventory().getItemInMainHand().getType() == Material.IRON_NUGGET) && (player.getInventory().getItemInMainHand().getItemMeta().getDisplayName().equals(ChatColor.RED + "Big Boom Boss Spawn Egg")))
                    {
                    if (player.getGameMode() != GameMode.CREATIVE) {player.getInventory().getItemInMainHand().setAmount(player.getInventory().getItemInMainHand().getAmount() - 1); }
                    Mobs.spawnCreeper(player);
                    return true;
                    }
            }
        return false;
      }
    }
    
    Sorry for the messy code I'm still new to this.
     
    Last edited: Nov 30, 2019
  2. Offline

    yPedx

    Java

    In your events you're checking if the item in the player's main hand is null, but it's never null. If the player is not holding any item, it returns air, not null.
     
  3. Offline

    J_ZAX123

    so would the beginning of my if statement be:

    if (!(player.getInventory().getItemInMainHand().equals(Material.AIR))

    or would I make air an itemstack because it says "Unlikely argument type for equals(): Material seems to be unrelated to ItemStack"
    also it's not sending the player the test message which is what was leading me to believe that the even simply isn't functioning, because even if it was executing the if statement if it was null then it should still send the player the test message.
     
  4. Offline

    yPedx

    @J_ZAX123
    You should compare items like this;
    Code:
    Itemstack is = player.getInventory().getItemInMainHand();
    
    if(is.getType() == Material.AIR){
        // return because they aren't holding anything.
        // You can also use != to check if they have a specific item type.
    }
    Some things to know about the code above:
    is can never be null. It can only be AIR.
    Use == to compare the item type (Material.AIR is an enum, and those are compared with ==).
     
    Last edited: Dec 1, 2019
  5. Offline

    J_ZAX123

    Thank you so much I finally got it to work.
     
    Last edited: Dec 2, 2019

Share This Page