下面列出了org.bukkit.event.entity.EntityDamageEvent.DamageCause#CONTACT 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
@EventHandler
public void onEntityDamage(EntityDamageEvent e) {
if (e instanceof EntityDamageByEntityEvent
&& !(e.getCause() == DamageCause.BLOCK_EXPLOSION || e.getCause() == DamageCause.ENTITY_EXPLOSION))
return;
Entity entity = e.getEntity();
if (plugin.getLWC().isProtectable(e.getEntity().getType())) {
int A = 50000 + entity.getUniqueId().hashCode();
LWC lwc = LWC.getInstance();
Protection protection = lwc.getPhysicalDatabase().loadProtection(entity.getWorld().getName(), A, A, A);
if (protection != null) {
if (e.getCause() != DamageCause.CONTACT)
e.setCancelled(true);
}
}
}
private static DamageCause getBlockDamageCause(Block block) {
switch (block.getType()) {
case LAVA:
case STATIONARY_LAVA:
return DamageCause.LAVA;
case FIRE:
return DamageCause.FIRE;
default:
return DamageCause.CONTACT;
}
}
private static DamageCause getBlockDamageCause(Block block) {
switch(block.getType()) {
case LAVA:
case STATIONARY_LAVA:
return DamageCause.LAVA;
case FIRE:
return DamageCause.FIRE;
default:
return DamageCause.CONTACT;
}
}