onProjectileHitEvent problem

Discussion in 'Plugin Development' started by AcePilot10, Mar 26, 2015.

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

    AcePilot10

    So, I have been making this plugin that would act like the smoke grenades in the game Cops N' Crims on Hypixel. All it does is when an egg hits a block it will save the blocks into an array of blocks and spawn in a bunch of flowers on top of each other. I'm fairly certain there is no problem with the flower placement, but the issue is when the onProjectileHitEvent is fired it gives me an error. Here's my code for the event
    Code:
        static Block[] block;
       
        @EventHandler
        public void onProjectileHit(ProjectileHitEvent event) {
            if(event.getEntity().getType() == EntityType.EGG) {
                Egg egg = (Egg) event.getEntity();
                ItemStack grenade = (ItemStack) egg;
                ItemMeta grenadeMeta = grenade.getItemMeta();
                if(grenadeMeta.getDisplayName().equals("Smoke Grenade")) {
                        block[0] = (Block) egg.getLocation().getBlock();
                        block[1] = block[0].getLocation().add(0,1,0).getBlock();
                        block[2] = block[0].getLocation().add(0,2,0).getBlock();
                        block[3] = block[0].getLocation().add(0,3,0).getBlock();
                        block[4] = block[0].getLocation().add(1,0,0).getBlock();
                        block[5] = block[0].getLocation().add(2,0,0).getBlock();
                        block[6] = block[0].getLocation().add(3,0,0).getBlock();
                        block[7] = block[0].getLocation().add(0,0,1).getBlock();
                        block[8] = block[0].getLocation().add(0,0,2).getBlock();
                        block[9] = block[0].getLocation().add(0,0,3).getBlock();
                        block[1].setType(Material.YELLOW_FLOWER);
                        block[2].setType(Material.YELLOW_FLOWER);
                        block[3].setType(Material.YELLOW_FLOWER);
                        block[4].setType(Material.YELLOW_FLOWER);
                        block[5].setType(Material.YELLOW_FLOWER);
                        block[6].setType(Material.YELLOW_FLOWER);
                        block[7].setType(Material.YELLOW_FLOWER);
                        block[8].setType(Material.YELLOW_FLOWER);
                        block[9].setType(Material.YELLOW_FLOWER);
                        Main.main.startTimer();
                }
            }
        }
    And here's the error in console:
    Code:
    [18:35:35 ERROR]: Could not pass event ProjectileHitEvent to Grenade v1.0
    org.bukkit.event.EventException
    Any help would be awesome! Thanks so much!!
     
  2. Invisible

    nverdier

  3. Offline

    AcePilot10

  4. Invisible

    nverdier

    @AcePilot10 First of all, read this. Secondly, you're casting to Egg on this line
    You have to check that the Entity is actually an Egg before you cast!
     
  5. Offline

    ColonelHedgehog

    MY EYES!

    Code:
    for(int i = 0; i < 9; i++)
    {
        block[i].setType(Material.YELLOW_FLOWER);
    }
     
    nverdier likes this.
  6. Offline

    AcePilot10

    @ColonelHedgehog I hate you xD but thanks that helps alot.

    @nverdier i will test that you

    Thanks so much for the responses guys! I love youuuu!!!!!!!!!!!!

    I threw in an if statement and that doesn't seem to be the problem :/
     
    Last edited by a moderator: Mar 26, 2015
    ColonelHedgehog likes this.
Thread Status:
Not open for further replies.

Share This Page