Player click

Discussion in 'Plugin Development' started by kalicat, Feb 13, 2014.

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

    kalicat

    How would i detect if a player left or right clicks with a bow in there hand and then shoot an arrow. Also if the arrow hit someone it kills them and gets who killed them. It will be great for your help.
     
  2. kalicat
    For left and right clicking, use PlayerInteractEvent. For shooting with a bow, use EntityShootBowEvent. For arrow hitting a block, use ProjectileHitEvent. For arrow damaging an entity, use EntityDamageByEntityEvent. For arrow killing a player, use EntityDeathEvent.

    Did you even try to search?
     
  3. Offline

    jkjames6

    What Assist said like this: (eg) this will make an explosion if you click with a stick.
    publicvoidonPlayerInteract(PlayerInteractEventevent){
    Player player = event.getPlayer();
    @SuppressWarnings("deprecation")
    int blockId = player.getItemInHand().getType().getId();
    if(blockId == 280){
    @SuppressWarnings("deprecation")
    Block block = player.getTargetBlock(null, 50);
    Location location = block.getLocation();
    World world = player.getWorld();
    world.createExplosion(location, 5);
     
  4. jkjames6
    You should put your code inside the code tags
    [ code ]code here[ / code ]
    it looks much better. The text above would look like this without the spaces
    Code:
    code here
     
  5. Offline

    kalicat

    thank you but how do i get who hit the player
     
  6. Offline

    alex123099

    Code:java
    1. onEntityDamage(EntityDamageEvent event){
    2. if(event instanceof EntityDamageByEntityEvent){
    3. if(event.getDamager instanceof Arrow) {
    4. Arrow a = (Arrow) test.getDamager();
    5. if(a.getShooter() instanceof Player) {
    6. Player player = (Player) a.getShooter();
    7. player.sendMessage("You hit something with an arrow!");
    8. }
    9. }
    10. }
    11. }
    https://forums.bukkit.org/threads/getting-the-shooter-of-an-arrow.53450/
     
Thread Status:
Not open for further replies.

Share This Page