[Help] Mob Velocity

Discussion in 'Plugin Development' started by super292, Oct 22, 2013.

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

    super292

    Every time I try to hit the mob with a stick, it takes to hits to make the mob shoot in the air. All the other things are functioning correctly but the mob being shot in the air. Here's the code.
    Code:java
    1. public class InspireMobBoom extends JavaPlugin implements Listener {
    2.  
    3. @Override
    4. public void onEnable() {
    5. Bukkit.getPluginManager().registerEvents(this, this);
    6. }
    7.  
    8. @EventHandler
    9. public void onEntityDamage(EntityDamageByEntityEvent event) {
    10. if(event.getDamager() instanceof Player && event.getEntity() instanceof Creature) {
    11. Player player = (Player) event.getDamager();
    12. final Entity e = event.getEntity();
    13. if(player.getItemInHand().getType().equals(Material.STICK)) {
    14. player.sendMessage(ChatColor.DARK_RED + "[" + ChatColor.AQUA + "Mob Blaster" + ChatColor.DARK_RED + "] " + ChatColor.DARK_RED + "Boom!");
    15. event.getEntity().setVelocity(new Vector(0, 1.35, 0));
    16. Firework fw = player.getWorld().spawn(player.getLocation(), Firework.class);
    17. FireworkMeta fwm = fw.getFireworkMeta();
    18. FireworkEffect effect = FireworkEffect.builder().withColor(Color.GREEN).with(Type.BALL).build();
    19. fwm.addEffects(effect);
    20. fwm.setPower(0);
    21. fw.setFireworkMeta(fwm);
    22. Bukkit.getScheduler().scheduleSyncDelayedTask(this, new Runnable() {
    23. public void run() {
    24. Location l = e.getLocation();
    25. l.getWorld().createExplosion(l, 1.0f);
    26. e.remove();;
    27. l.getWorld().playEffect(l,Effect.MOBSPAWNER_FLAMES,31);
    28. }
    29. }, 35);
    30. }
    31. }
    32. }
    33. }

    Can someone tell me why the mob takes two hits to shoot into the air and how to fix it? Thanks!
     
Thread Status:
Not open for further replies.

Share This Page