Solved Explosion not working

Discussion in 'Plugin Development' started by vhbob, Apr 30, 2015.

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

    vhbob

    so im trying to create an explosion if an arrow has a certain item meta heres the code ( That doesnt work )
    Code:
        @EventHandler(priority = EventPriority.LOWEST)
        public void entityDamagedByArrow(EntityDamageByEntityEvent e) {
            if (!(e.getDamager() instanceof Arrow))
                return;
            if (!(e.getEntity() instanceof LivingEntity))
                return;
            Arrow a = (Arrow) e.getDamager();
            LivingEntity le = (LivingEntity) e.getEntity();
            if (a.hasMetadata("isExploding"))
                a.getWorld().createExplosion(a.getLocation(), 3F);
            if (a.hasMetadata("poisonous"))
                le.addPotionEffect(new PotionEffect(PotionEffectType.POISON,
                        5 * 20, a.getMetadata("poisonous").get(0).asInt(), false));
        }
     
  2. Offline

    ninjaboy323

    Try creating debug lines in between your code and see how far they get

    Bukkit.getServer().broadcastMessage("debug1");

    and so on in between code and see where the code is stopping, if it doesn't stop it is an issue with the create explosion.
     
  3. Offline

    Garnetty

    I just made this if you wanna give it a shot.
    You can make an enumerator called ArrowModifier like so:
    Code:
    public enum ArrowModifier
    {
        EXPLODING, POISONOUS, WITHERING
    }
    Then on the ProjectileLaunchEvent you can define a HashMap that uses the Arrow's HashCode as the key and an ArrowModifier as a value. I stuck the Arrow's hashcode in and put explosive as the value like so:
    Code:
    private static HashMap<Integer, ArrowModifier> arrows = new HashMap<>();
     
        @EventHandler
        public void onShoot(ProjectileLaunchEvent e)
        {
            if (e.getEntity() instanceof Arrow)
            {
                Arrow a = (Arrow) e.getEntity();
         
                // Right here you can check if they have the "requirements" to have
                // explosions or poison or wither etc, then set it in the map.
    
                arrows.put(a.hashCode(), ArrowModifier.EXPLODING);
            }
        }
    Then on the ProjectileHitEvent check if the damager is an Arrow, and if the entity is a Player. If that passed, Check if the HashMap contains the Arrow's hashcode. If so, check to see if it returned ArrowModifier.EXPLODING, and if that returnes true, BOOM.
    Code:
    @EventHandler
        public void onArrowHit(EntityDamageByEntityEvent e)
        {
            if (e.getEntity() instanceof Player && e.getDamager() instanceof Arrow)
            {
                Player p = (Player) e.getEntity();
         
                Arrow a = (Arrow) e.getDamager();
         
                if (arrows.containsKey(a.hashCode()))
                {
                    if (arrows.get(a.hashCode()) == ArrowModifier.EXPLODING)
                    {
                        p.getWorld().createExplosion(p.getLocation(), 4.00F);
                    }
                }
            }
        }
    I don't really know about meta on entities such as arrows, so I prefer to just make maps with
    HashCodes :p
     
    Last edited: Apr 30, 2015
  4. Offline

    vhbob

    nvm fixed! i forgot to specify the arrow as "isExploding" XD
     
  5. Offline

    Garnetty

    ALL MY WORK FOR NOTHING. I'm glad you got it working :)
     
    vhbob likes this.
Thread Status:
Not open for further replies.

Share This Page