Solved Explosive Arrows aren´t working...

Discussion in 'Plugin Development' started by TheOwner3D, Jun 12, 2013.

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

    TheOwner3D

    Can someone explain me, why this code isn´t working?

    Code:
    package me.okaay.Feeling.Listeners;
     
    import me.okaay.Feeling.Feeling;
     
    import org.bukkit.*;
    import org.bukkit.entity.*;
    import org.bukkit.event.Listener;
    import org.bukkit.event.entity.EntityShootBowEvent;
    import org.bukkit.event.entity.ProjectileHitEvent;
    import org.bukkit.inventory.ItemStack;
    import org.bukkit.inventory.PlayerInventory;
    import org.bukkit.inventory.meta.ItemMeta;
     
    public class ArrowExplodeListener
        implements Listener
    {
     
        public ArrowExplodeListener()
        {
        }
     
        public void onFireBow(EntityShootBowEvent event)
        {
            Player p = (Player)event.getEntity();
            if(event.getEntityType() == EntityType.PLAYER && (new StringBuilder()).append(ChatColor.RED).append(Feeling.craftName).toString().equals(p.getItemInHand().getItemMeta().getDisplayName()) && p.hasPermission("Feeling.use.creeperarrow") && !p.getInventory().contains(Material.SULPHUR))
                event.setCancelled(true);
        }
     
        public void ProjectileHit(ProjectileHitEvent event)
        {
            if(event.getEntity().getShooter() instanceof Player)
            {
                Player p = (Player)event.getEntity().getShooter();
                if((new StringBuilder()).append(ChatColor.RED).append(Feeling.craftName).toString().equals(p.getItemInHand().getItemMeta().getDisplayName()) && p.getInventory().contains(Material.SULPHUR))
                {
                    Projectile projectile = event.getEntity();
                    double X = projectile.getLocation().getX();
                    double Y = projectile.getLocation().getY();
                    double Z = projectile.getLocation().getZ();
                    projectile.getWorld().createExplosion(X, Y, Z, 4F, false, true);
                    if(p.getGameMode() != GameMode.CREATIVE)
                    {
                        ItemStack itemGunpowder = new ItemStack(Material.SULPHUR, 1);
                        p.getInventory().removeItem(new ItemStack[] {
                            itemGunpowder
                        });
                    }
                }
            }
        }
    }
    
    My arrwos aren´t exploding....
     
  2. Offline

    Joeisi

    have you tried having it log things to the console window? seeing what part of the code it may not get to? (This may not be the case, but we need to debug this.)

    I have a feeling it is hanging up here:

    Code:java
    1. if((new StringBuilder()).append(ChatColor.RED).append(Feeling.craftName).toString().equals(p.getItemInHand().getItemMeta().getDisplayName()) && p.getInventory().contains(Material.SULPHUR))


    Try printing out StringBuilder().append(ChatColor.RED).append(Feeling.craftName).toString() and p.getItemInHand().getItemMeta().getDisplayName()

    Another Idea is to have instead of .equal, use .equalsignorecase()
    (Assuming you dont have any Arrow metadatas that have alternate Capitalizations)
     
  3. Offline

    valon750

    Just an idea, but how about assigning the arrow to a hashmap? then checking against it when it hits a block or whatnot.

    At least that's what I did for my ArrowMythology plugin :)

    Let me know how it works out!
     
  4. Offline

    psycowithespn

    You are missing @EventHandler annotations above the event methods.
     
    Xcaviler and Rprrr like this.
  5. Offline

    TheOwner3D

Thread Status:
Not open for further replies.

Share This Page