EntityExplodeEvent Not Catching Custom Explosion From Arrow Help!

Discussion in 'Spigot Plugin Development' started by XZot1K, May 2, 2015.

  1. Hey so the 2 classes below is my ability class and my noexplode class but when the arrow hits the ground and explodes the explode event doesn't catch it fix plz (both classes are registered in the main class)
    Ability Class:
    Code (Text):
    package JKMODz.plugins.orginsclasses.abilitys;
    import java.util.HashMap;
    import org.bukkit.Effect;
    import org.bukkit.Material;
    import org.bukkit.entity.Arrow;
    import org.bukkit.entity.Entity;
    import org.bukkit.entity.EntityType;
    import org.bukkit.entity.Player;
    import org.bukkit.entity.Projectile;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.block.Action;
    import org.bukkit.event.entity.ProjectileHitEvent;
    import org.bukkit.event.player.PlayerInteractEvent;
    import org.bukkit.metadata.FixedMetadataValue;
    import org.bukkit.projectiles.ProjectileSource;
    import org.bukkit.util.Vector;
    import JKMODz.plugins.orgins.base.Main;
    import com.sk89q.worldguard.bukkit.WorldGuardPlugin;
    public class ArcherAbility1 implements Listener {
        Main plugin;
        public ArcherAbility1(Main instance) {
            plugin = instance;
        }
        WorldGuardPlugin worldguard;
        public ArcherAbility1(WorldGuardPlugin instance) {
            worldguard = instance;
        }
        public HashMap<String, Long> esc = new HashMap<String, Long>();
        int esct = 12;
        @EventHandler
        public void onInteract(PlayerInteractEvent e) {
            Player player = e.getPlayer();
            if (e.getAction() == Action.RIGHT_CLICK_AIR
                    || e.getAction() == Action.RIGHT_CLICK_BLOCK) {
                if (player.getItemInHand().hasItemMeta()) {
                    if (player.getItemInHand().getItemMeta().hasDisplayName()) {
                        if (player.getItemInHand().getItemMeta().getDisplayName()
                                .equals("§cExplosive Shot")) {
                            if (plugin.allowsPVP(player.getLocation(),
                                    player.getWorld())) {
                                if (player.getItemInHand().getType() == Material.ARROW) {
                                    if (esc.containsKey(player.getName())) {
                                        long secondsLeft = ((Long) esc.get(player
                                                .getName())).longValue()
                                                / 1000L
                                                + esct
                                                - System.currentTimeMillis()
                                                / 1000L;
                                        if (secondsLeft > 0L) {
                                            e.setCancelled(true);
                                            player.sendMessage(plugin.prefix
                                                    + " §eYou Can't Use That Ability For Another §a"
                                                    + secondsLeft + " §eSeconds!");
                                            return;
                                        }
                                    }
                                    Vector direction = player.getLocation()
                                            .getDirection();
                                    Arrow arrow = player
                                            .launchProjectile(Arrow.class);
                                    arrow.setVelocity(direction.multiply(2));
                                    arrow.setCustomName("§cExplosive Arrow");
                                    arrow.setMetadata("§cExplosive Arrow",
                                            new FixedMetadataValue(plugin, "aa1"));
                                    arrow.setCustomNameVisible(true);
                                    esc.put(((Player) player).getName(), Long
                                            .valueOf(System.currentTimeMillis()));
                                }
                            } else {
                                player.sendMessage(plugin.prefix
                                        + " §eYou Are In A No PvP Zone!");
                            }
                        }
                    }
                }
            }
        }
        @EventHandler
        public void onHit(ProjectileHitEvent e) {
            Projectile arrow = e.getEntity();
            ProjectileSource player = e.getEntity().getShooter();
            if (arrow.getType() == EntityType.ARROW) {
                if (arrow.hasMetadata("§cExplosive Arrow")) {
                    //for (Entity entity : arrow.getNearbyEntities(5, 5, 5)) {
                        //if (entity instanceof Player) {
                            //if (entity != player && entity != null) {
                                arrow.getWorld().playEffect(arrow.getLocation(),
                                        Effect.EXPLOSION_LARGE, 1);
                                arrow.getWorld().createExplosion(
                                        arrow.getLocation(), 5.0f);
                            //}
                        //}
                    //}
                    arrow.remove();
                }
            }
        }
    }
     
    NoExplode Class:
    Code (Text):
    package JKMODz.plugins.orginsclasses.events;
    import java.util.ArrayList;
    import java.util.UUID;
    import org.bukkit.Bukkit;
    import org.bukkit.block.Block;
    import org.bukkit.block.BlockState;
    import org.bukkit.entity.Entity;
    import org.bukkit.entity.EntityType;
    import org.bukkit.entity.FallingBlock;
    import org.bukkit.entity.Item;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.entity.EntityChangeBlockEvent;
    import org.bukkit.event.entity.EntityExplodeEvent;
    import org.bukkit.util.Vector;
    import JKMODz.plugins.orgins.base.Main;
    public class NoBlockExplosion implements Listener {
        Main plugin;
        public NoBlockExplosion(Main instance) {
            plugin = instance;
        }
        ArrayList<UUID> Falling = new ArrayList<UUID>();
        int tickdelay = 0;
     
        @SuppressWarnings("deprecation")
        @EventHandler
        public void onExplode(EntityExplodeEvent e) {
         
            for (final Block b : e.blockList()) {
                final BlockState state = b.getState();
                float x = -1.0F + (float) (Math.random() * 2.0D);
                float y = -1.0F + (float) (Math.random() * 2.0D);
                float z = -1.0F + (float) (Math.random() * 2.0D);
                FallingBlock fallingBlock = b.getWorld().spawnFallingBlock(
                        b.getLocation(), b.getTypeId(), b.getData());
                ((FallingBlock) fallingBlock).setDropItem(false);
                fallingBlock.setVelocity(new Vector(x, y, z));
                Falling.add(fallingBlock.getUniqueId());
             
                Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() {
                    public void run() {
                     
                        state.update(true, false);
                    }
                }, tickdelay);
             
             
            }
        }
     
        @EventHandler
        public void EntityChangeBlockEvent(final EntityChangeBlockEvent e) {
            if (e.getEntityType() == EntityType.FALLING_BLOCK) {
                if (Falling.contains(e.getEntity().getUniqueId())) {
                 
                    e.setCancelled(true);
                 
                    for(Entity item : e.getEntity().getNearbyEntities(5, 5, 5)){
                     
                        if(item instanceof Item){
                         
                            item.remove();
                         
                        }
                     
                    }
                 
                }
             
            }
         
        }  
    }
     
     
  2. Registered Events?
     
  3. they both are registered Ive done tons of testing it works with like tnt but anything using the createExplosion() option doesn't work
     
  4. From getWorld() ? Try using a TNTPrimed
     
  5. the ability class creates a arrow at the players eye site and throws it the onHit it gets the arrows world the create a explosion while the NoBlockExplode class gets the block list and regens it instantly with the delay 0 and throws blocks everywhere then cancels them from forming but for some reason its not counting the createexplosion as a explosion but it works with primed tnt and other explosions such as fireballs
     
  6. minelazz

    Supporter

    You need to call the event in onHit method
     
  7. how can I do that? Its a event
     
  8. minelazz

    Supporter

    Bukkit.getPluginManager().callEvent(new EntityExplodeEvent(...));
     
    • Like Like x 1
  9. gigosaurus

    Supporter

    Try listening to the BlockExplodeEvent instead of the EntityExplodeEvent as your explosion isn't caused by an entity.
     
    • Winner Winner x 1
  10. THANK YOU SO MUCH!
     
  11. Thank you for the help aswel :)