1.8.8 Cancel ender pearl teleport if it hit a block

Discussion in 'Spigot Plugin Development' started by SkrtPvP, Jul 1, 2021.

  1. How can I cancel teleportation via Ender Pearl if it's hit against a certain block?

    For Spigot 1.8
     
    • Agree Agree x 1
  2. I know this method, but it does not exist in version 1.8.8
     
  3. Yo waddup, it really sucks that in 1.8 the #getHitBlock() doesn't exist in the ProjectileHitEvent

    however that should work:

    Code (Java):
    @EventHandler
        public void onProjectileHit(ProjectileHitEvent event) {
         
            Entity entity = event.getEntity();
         
            if (entity instanceof EnderPearl) {

                Location loc = entity.getLocation();
             
                Vector vec = entity.getVelocity();
             
                Location loc2 = new Location(loc.getWorld(), loc.getX() + vec.getX(), loc.getY() + vec.getY(),
                        loc.getZ() + vec.getZ());
             
                if(loc2.getBlock().getType().equals(YOUR_BLOCK)) {
                    doSomething();
                }
             
            }
        }
     
  4. Compare enums (Material) with ==
     
    • Agree Agree x 1