Игрок-убийца.

Discussion in 'Разработка плагинов' started by Pasha_Robber, 23/3/16.

  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.
Dismiss Notice
We welcome you on our site. This site is devoted to the Nukkit project and all that is connected with him. Here you can communicate, download plugins, also many other things get acquainted! Register the account right now :3
  1. Pasha_Robber

    Pasha_Robber Pioneer

    Messages:
    3
    Likes Received:
    0
    Minecraft:
    Pasha_Robber
    Здравствуйте! Как получить игрока убившего другого игрока?
     
  2. fromgate

    fromgate Administrator

    Messages:
    668
    Likes Received:
    187
    Нужно у Player есть метод позволяющий узнать причину последнего урона.

    Code:
      @EventHandler
    public void onJoin (PlayerJoinEvent event){
    Regions.getSelector().setSelMode(event.getPlayer(),false);
    }
    
    [pre][code]public void onDeath (PlayerDeathEvent event){
        Player damager = getDamager(event.getEntity().getLastDamageCause());
        if (damager==null) return; // Игрок умер не в PVP
    }
    
    private Player getDamager(EntityDamageEvent event){
        Player player = null;
        if (event.getEntity() instanceof Player) player = (Player) event.getEntity();
        else if (event instanceof EntityDamageByEntityEvent) {
            Entity damager = ((EntityDamageByEntityEvent) event).getDamager();
            if (damager instanceof Player) player = (Player) damager;
        } else if (event instanceof EntityDamageByChildEntityEvent) {
            Entity damager = ((EntityDamageByChildEntityEvent) event).getDamager();
            if (damager instanceof Player) player = (Player) damager;
        }
        return player;
    }
    [/code][/pre]
     
    j0sky likes this.
  3. Pasha_Robber

    Pasha_Robber Pioneer

    Messages:
    3
    Likes Received:
    0
    Minecraft:
    Pasha_Robber
    Большое спасибо!
     

Share This Page