本文整理汇总了Java中org.bukkit.event.entity.EntityDamageByEntityEvent.getFinalDamage方法的典型用法代码示例。如果您正苦于以下问题:Java EntityDamageByEntityEvent.getFinalDamage方法的具体用法?Java EntityDamageByEntityEvent.getFinalDamage怎么用?Java EntityDamageByEntityEvent.getFinalDamage使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.bukkit.event.entity.EntityDamageByEntityEvent
的用法示例。
在下文中一共展示了EntityDamageByEntityEvent.getFinalDamage方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: customDeath
import org.bukkit.event.entity.EntityDamageByEntityEvent; //导入方法依赖的package包/类
@EventHandler(priority=EventPriority.HIGHEST)
public void customDeath(EntityDamageByEntityEvent e){
if(e.isCancelled())return;
if(e.getEntity() instanceof Player && e.getDamager() instanceof Player){
Player p = (Player) e.getEntity();
if(e.getFinalDamage() >= p.getHealth()){
Player killer = (Player) e.getDamager();
String uuid2 = killer.getUniqueId().toString();
e.setCancelled(true);
if(! p.getName().equals(killer.getName())){ // if they were killed by someone else, not themselves
setTokens(uuid2, getTokens(uuid2)+2);
killer.sendMessage(tag + ChatColor.BLUE + "You have received " + ChatColor.GOLD + "2" +
ChatColor.BLUE + " tokens for killing " + p.getName());
}
Bukkit.getServer().broadcastMessage(ChatColor.GRAY + killer.getName() + " destroyed " + p.getName());
// Set statistics
//killer.setStatistic(Statistic.KILL_ENTITY, killer.getStatistic(Statistic.KILL_ENTITY) + 1);
//p.setStatistic(Statistic.DEATHS, p.getStatistic(Statistic.DEATHS) + 1);
// Reset health, so they dont die
p.setHealth(p.getMaxHealth());
// Inventory clearing
p.getInventory().clear();
ItemStack air = new ItemStack(Material.AIR);
p.getInventory().setHelmet(air);
p.getInventory().setChestplate(air);
p.getInventory().setLeggings(air);
p.getInventory().setBoots(air);
// Drop emerald at death location
ItemStack reward = new ItemStack(Material.EMERALD);
p.getWorld().dropItemNaturally(p.getLocation(), reward);
// Clear potion effects
for(PotionEffect pe : p.getActivePotionEffects()){
p.removePotionEffect(pe.getType());
}
// Stop infinite kill glitch
p.setGameMode(GameMode.SPECTATOR);
p.setGameMode(GameMode.ADVENTURE);
// Send them to the SPAWN of the world
p.teleport(p.getWorld().getSpawnLocation());
p.setFireTicks(0);
}
}
}