Knockback

Discussion in 'Plugin Development' started by diamondcodes, Oct 23, 2014.

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

    diamondcodes

    Is there a method for Knockback? Like I want to cancel player knockback when something explodes, How would I do this?
     
  2. Offline

    mine-care

    I cannot recall any such way but you can start a delayed task that will teleport player to the location he was on the time of hit after 20 ticks (1sec) so even if teleported, he is ran back on the place of hit
     
  3. Offline

    teej107

    I think setting the velocity would be better.
     
  4. Offline

    diamondcodes

    mine-care Alright so Its for a ExplosivePick plugin, Here is my code. Would I add it to BlockBreak or EntityDamage? (Have not really used Delayed tasks)

    Code:java
    1. package me.nite.main;
    2.  
    3. import java.util.ArrayList;
    4. import org.bukkit.entity.Player;
    5. import org.bukkit.event.EventHandler;
    6. import org.bukkit.event.Listener;
    7. import org.bukkit.event.block.BlockBreakEvent;
    8. import org.bukkit.event.entity.EntityDamageEvent;
    9.  
    10. public class BlockBreak implements Listener {
    11. private Main plugin;
    12.  
    13. public BlockBreak(Main instance) {
    14. this.plugin = instance;
    15. }
    16.  
    17. ArrayList<Player> list = new ArrayList();
    18.  
    19. @EventHandler
    20. public void onBlockBreak(BlockBreakEvent e) {
    21. if (e.getPlayer().getItemInHand().getItemMeta().getLore().equals("ยง7Explosive 1")) ;
    22. {
    23. this.list.add(e.getPlayer());
    24. e.getBlock().getWorld().createExplosion(e.getBlock().getLocation(), (float) plugin.getConfig().getDouble("explosion"));
    25. e.getPlayer().getItemInHand().setDurability((short) 0);
    26. }
    27. }
    28.  
    29. @EventHandler
    30. public void onExplosionDamage(EntityDamageEvent e) {
    31. if ((e.getCause() == EntityDamageEvent.DamageCause.BLOCK_EXPLOSION) &&
    32. ((e.getEntity() instanceof Player))) {
    33. e.setCancelled(true);
    34. }
    35. }
    36. }
     
  5. Offline

    teej107

    diamondcodes EntityDamage. You are checking in the EntityDamageEvent already. Since when would a block break set a player at a certain velocity?
     
  6. Offline

    97WaterPolo

    diamondcodes
    first off your durability method that you are currently using will give the item full durability every time.

    How I would do it if it helps

    EntityDamageEvent
    If entity is a player
    If the cause is an explosion
    Player.setVelocity(new Vector());// might want to run this a tick later, not sure.
     
  7. Offline

    mine-care

    teej107 yeah you are right it would be better to use a vector :)
     
  8. Offline

    Luke_Lax

    You could just fake an explosion by sending the client packets for explosions and deleting the blocks via code but it's up to you :)
     
Thread Status:
Not open for further replies.

Share This Page