Implemented contact damage and fixed other damage protection.

This commit is contained in:
sk89q 2011-01-20 00:55:20 -08:00
parent 430f2f57e9
commit 69ccb9f12b
3 changed files with 72 additions and 29 deletions

View File

@ -59,12 +59,13 @@ spawn:
teleport-to-home-on-death: off
player-damage:
disable-fall-damage: on
disable-lava-damage: on
disable-fire-damage: on
disable-drowning-damage: on
disable-suffocation-damage: on
teleport-on-suffocation: on
disable-fall-damage: off
disable-lava-damage: off
disable-fire-damage: off
disable-drowning-damage: off
disable-suffocation-damage: off
disable-contact-damage: off
teleport-on-suffocation: off
regions:
enable: on

View File

@ -56,32 +56,10 @@ public void onEntityDamageByBlock(EntityDamageByBlockEvent event) {
return;
}
if (plugin.disableFallDamage && type == DamageCause.FALL) {
event.setCancelled(true);
return;
}
if (plugin.disableLavaDamage && type == DamageCause.LAVA) {
event.setCancelled(true);
return;
}
if (plugin.disableFireDamage && (type == DamageCause.FIRE
|| type == DamageCause.FIRE_TICK)) {
event.setCancelled(true);
return;
}
if (plugin.disableDrowningDamage && type == DamageCause.DROWNING) {
event.setCancelled(true);
return;
}
if (type == DamageCause.DROWNING
&& plugin.amphibiousPlayers.contains(player.getName())) {
event.setCancelled(true);
return;
}
}
}
@ -112,6 +90,66 @@ public void onEntityDamageByEntity(EntityDamageByEntityEvent event) {
}
}
public void onEntityDamageByProjectile(EntityDamageByProjectileEvent event) {
Entity defender = event.getEntity();
if (defender instanceof Player) {
Player player = (Player)defender;
if (plugin.invinciblePlayers.contains(player.getName())) {
event.setCancelled(true);
return;
}
}
}
public void onEntityDamage(EntityDamageEvent event) {
Entity defender = event.getEntity();
DamageCause type = event.getCause();
if (defender instanceof Player) {
Player player = (Player)defender;
if (plugin.invinciblePlayers.contains(player.getName())) {
event.setCancelled(true);
return;
}
if (plugin.disableFallDamage && type == DamageCause.FALL) {
event.setCancelled(true);
return;
}
if (plugin.disableFireDamage && (type == DamageCause.FIRE
|| type == DamageCause.FIRE_TICK)) {
event.setCancelled(true);
return;
}
if (plugin.disableDrowningDamage && type == DamageCause.DROWNING) {
event.setCancelled(true);
return;
}
if (plugin.disableSuffocationDamage && type == DamageCause.SUFFOCATION) {
event.setCancelled(true);
return;
}
if (plugin.disableContactDamage && type == DamageCause.CONTACT) {
event.setCancelled(true);
return;
}
if (type == DamageCause.DROWNING
&& plugin.amphibiousPlayers.contains(player.getName())) {
event.setCancelled(true);
return;
}
}
}
@Override
public void onEntityExplode(EntityExplodeEvent event) {
if (event.getEntity() instanceof LivingEntity) {

View File

@ -122,6 +122,7 @@ public class WorldGuardPlugin extends JavaPlugin {
boolean exactRespawn;
boolean teleportToHome;
boolean disableContactDamage;
boolean disableFallDamage;
boolean disableLavaDamage;
boolean disableFireDamage;
@ -186,6 +187,8 @@ private void registerEvents() {
registerEvent(Event.Type.BLOCK_PLACED, blockListener, Priority.Normal);
registerEvent(Event.Type.BLOCK_RIGHTCLICKED, blockListener, Priority.Normal);
registerEvent(Event.Type.ENTITY_DAMAGED, entityListener, Priority.Normal);
registerEvent(Event.Type.ENTITY_DAMAGEDBY_PROJECTILE, entityListener, Priority.Normal);
registerEvent(Event.Type.ENTITY_DAMAGEDBY_BLOCK, entityListener, Priority.Normal);
registerEvent(Event.Type.ENTITY_DAMAGEDBY_ENTITY, entityListener, Priority.Normal);
registerEvent(Event.Type.ENTITY_EXPLODE, entityListener, Priority.Normal);
@ -291,6 +294,7 @@ public void loadConfiguration() {
disableFireDamage = config.getBoolean("player-damage.disable-fire-damage", false);
disableDrowningDamage = config.getBoolean("player-damage.disable-water-damage", false);
disableSuffocationDamage = config.getBoolean("player-damage.disable-suffocation-damage", false);
disableContactDamage = config.getBoolean("player-damage.disable-contact-damage", false);
teleportOnSuffocation = config.getBoolean("player-damage.teleport-on-suffocation", false);
useRegions = config.getBoolean("regions.enable", true);