我怎样才能检测到一名球员是否射杀了另一名弓箭手? 我想得到球员的名字。 那我怎么能这样做呢?
答案 0 :(得分:2)
使用bukkit events,特别是EntityDamageByEntityEvent。然后只需检查玩家是谁:
@EventHandler
public void onEntityDamageByEntity(EntityDamageByEntityEvent event) {
Entity damager = event.getDamager();
if(damager instanceof Arrow) { // check if the damager is an arrow
Arrow arrow = (Arrow) damager;
if(arrow.getShooter() instanceof Player) {
// the arrow.getShooter() here is the player who fired the arrow
}
Entity entityHit = event.getEntity();
if(entityHit instanceof Player) {
Player playerHit = (Player) entityHit;
// playerHit here is the player who got hit
}
}
基本上你是如何获得玩家的,现在你只需要使用这些信息在聊天或任何你想做的事情中打印出来。祝你好运!