Added the ability to disable fall, water, lava, and fire damage individually.

This commit is contained in:
sk89q 2010-11-29 12:30:42 -08:00
parent cf31df35ec
commit 19aa20537d
2 changed files with 50 additions and 0 deletions

View File

@ -103,6 +103,9 @@ public void initialize() {
if (!registerHook("HEALTH_CHANGE", PluginListener.Priority.MEDIUM)) {
missingFeatures.add("god mode");
}
if (!registerHook("DAMAGE", PluginListener.Priority.MEDIUM)) {
missingFeatures.add("disabling fall, water, lava, and fire damage");
}
if (missingFeatures.size() > 0) {
logger.log(Level.WARNING, "WorldGuard: Your version of hMod does not support "

View File

@ -85,6 +85,10 @@ public class WorldGuardListener extends PluginListener {
private boolean noPhysicsGravel;
private boolean noPhysicsSand;
private boolean allowPortalAnywhere;
private boolean disableFallDamage;
private boolean disableLavaDamage;
private boolean disableFireDamage;
private boolean disableWaterDamage;
private int loginProtection;
private int spawnProtection;
private boolean kickOnDeath;
@ -160,6 +164,10 @@ public void loadConfiguration() {
noPhysicsGravel = properties.getBoolean("no-physics-gravel", false);
noPhysicsSand = properties.getBoolean("no-physics-sand", false);
allowPortalAnywhere = properties.getBoolean("allow-portal-anywhere", false);
disableFallDamage = properties.getBoolean("disable-fall-damage", false);
disableLavaDamage = properties.getBoolean("disable-lava-damage", false);
disableFireDamage = properties.getBoolean("disable-fire-damage", false);
disableWaterDamage = properties.getBoolean("disable-water-damage", false);
loginProtection = properties.getInt("login-protection", 3);
spawnProtection = properties.getInt("spawn-protection", 0);
kickOnDeath = properties.getBoolean("kick-on-death", false);
@ -922,6 +930,45 @@ public boolean onHealthChange(Player player, int oldValue, int newValue) {
return false;
}
/**
* Called when a living object is attacked.
* tip:
* Use isMob() and isPlayer() and getPlayer().
*
* @param type
* type of damage dealt.
* @param attacker
* object that is attacking.
* @param defender
* object that is defending.
* @param amount
* amount of damage dealt.
*
* @return
*/
public boolean onDamage(PluginLoader.DamageType type, BaseEntity attacker,
BaseEntity defender, int amount) {
if (disableFallDamage && type == PluginLoader.DamageType.FALL) {
return true;
}
if (disableLavaDamage && type == PluginLoader.DamageType.LAVA) {
return true;
}
if (disableFireDamage && (type == PluginLoader.DamageType.FIRE
|| type == PluginLoader.DamageType.FIRE_TICK)) {
return true;
}
if (disableWaterDamage && type == PluginLoader.DamageType.WATER) {
return true;
}
return false;
}
/**
* Called on player disconnect
*