Added min and max health flags to go along with the other healing flags. Also organized the flag list for readability.

This commit is contained in:
Wizjany 2011-08-08 19:56:45 -04:00
parent 3f77a9b721
commit 0eb68ef864
2 changed files with 24 additions and 12 deletions

View File

@ -87,7 +87,9 @@ public void run() {
ApplicableRegionSet applicable = regionManager ApplicableRegionSet applicable = regionManager
.getApplicableRegions(playerLocation); .getApplicableRegions(playerLocation);
processHeal(applicable, player, state); if (!RegionQueryUtil.isInvincible(plugin, player, applicable)) {
processHeal(applicable, player, state);
}
} }
} }
@ -109,20 +111,25 @@ private void processHeal(ApplicableRegionSet applicable, Player player,
Integer healAmount = applicable.getFlag(DefaultFlag.HEAL_AMOUNT); Integer healAmount = applicable.getFlag(DefaultFlag.HEAL_AMOUNT);
Integer healDelay = applicable.getFlag(DefaultFlag.HEAL_DELAY); Integer healDelay = applicable.getFlag(DefaultFlag.HEAL_DELAY);
Integer minHealth = applicable.getFlag(DefaultFlag.MIN_HEAL);
Integer maxHealth = applicable.getFlag(DefaultFlag.MAX_HEAL);
if (healAmount == null || healDelay == null || healAmount == 0 || healDelay < 0) { if (healAmount == null || healDelay == null || healAmount == 0 || healDelay < 0) {
return; return;
} }
if (minHealth == null) minHealth = 0;
if (maxHealth == null) maxHealth = 20;
if (player.getHealth() >= 20 && healAmount > 0) { if (player.getHealth() >= maxHealth && healAmount > 0) {
return; return;
} }
if (healDelay <= 0 && healAmount > 0) { if (healDelay <= 0) {
player.setHealth(20); player.setHealth(healAmount > 0 ? maxHealth : minHealth); // this will insta-kill if the flag is unset
state.lastHeal = now; state.lastHeal = now;
} else if (now - state.lastHeal > healDelay * 1000) { } else if (now - state.lastHeal > healDelay * 1000) {
player.setHealth(Math.min(20, Math.max(0, player.getHealth() + healAmount))); // clamp health between minimum and maximum
player.setHealth(Math.min(maxHealth, Math.max(minHealth, player.getHealth() + healAmount)));
state.lastHeal = now; state.lastHeal = now;
} }
} }

View File

@ -63,6 +63,8 @@ public final class DefaultFlag {
public static final SetFlag<CreatureType> DENY_SPAWN = new SetFlag<CreatureType>("deny-spawn", new CreatureTypeFlag(null)); public static final SetFlag<CreatureType> DENY_SPAWN = new SetFlag<CreatureType>("deny-spawn", new CreatureTypeFlag(null));
public static final IntegerFlag HEAL_DELAY = new IntegerFlag("heal-delay"); public static final IntegerFlag HEAL_DELAY = new IntegerFlag("heal-delay");
public static final IntegerFlag HEAL_AMOUNT = new IntegerFlag("heal-amount"); public static final IntegerFlag HEAL_AMOUNT = new IntegerFlag("heal-amount");
public static final IntegerFlag MIN_HEAL = new IntegerFlag("heal-min-health");
public static final IntegerFlag MAX_HEAL = new IntegerFlag("heal-max-health");
public static final VectorFlag TELE_LOC = new VectorFlag("teleport"); public static final VectorFlag TELE_LOC = new VectorFlag("teleport");
public static final RegionGroupFlag TELE_PERM = new RegionGroupFlag("teleport-group", RegionGroupFlag.RegionGroup.MEMBERS); public static final RegionGroupFlag TELE_PERM = new RegionGroupFlag("teleport-group", RegionGroupFlag.RegionGroup.MEMBERS);
public static final VectorFlag SPAWN_LOC = new VectorFlag("spawn"); public static final VectorFlag SPAWN_LOC = new VectorFlag("spawn");
@ -73,13 +75,16 @@ public final class DefaultFlag {
public static final SetFlag<String> ALLOWED_CMDS = new SetFlag<String>("allowed-cmds", new CommandStringFlag(null)); public static final SetFlag<String> ALLOWED_CMDS = new SetFlag<String>("allowed-cmds", new CommandStringFlag(null));
public static final Flag<?>[] flagsList = new Flag<?>[] { public static final Flag<?>[] flagsList = new Flag<?>[] {
PASSTHROUGH, BUILD, PVP, MOB_DAMAGE, MOB_SPAWNING, CREEPER_EXPLOSION, SLEEP, PASSTHROUGH, BUILD, PVP, CHEST_ACCESS,
TNT, LIGHTER, FIRE_SPREAD, LAVA_FIRE, CHEST_ACCESS, WATER_FLOW, LAVA_FLOW, TNT, LIGHTER, USE, PLACE_VEHICLE, SLEEP,
USE, PLACE_VEHICLE, GREET_MESSAGE, FAREWELL_MESSAGE, NOTIFY_ENTER, MOB_DAMAGE, MOB_SPAWNING, DENY_SPAWN, CREEPER_EXPLOSION, GHAST_FIREBALL,
NOTIFY_LEAVE, DENY_SPAWN, HEAL_DELAY, HEAL_AMOUNT, TELE_LOC, GREET_MESSAGE, FAREWELL_MESSAGE, NOTIFY_ENTER, NOTIFY_LEAVE,
TELE_PERM, SPAWN_LOC, SPAWN_PERM, BUYABLE, PRICE, SNOW_FALL, LEAF_DECAY, EXIT, EXIT_PERM, ENTRY, ENTRY_PERM,
GHAST_FIREBALL, BLOCKED_CMDS, ALLOWED_CMDS, ENTRY, ENTRY_PERM, EXIT, EXIT_PERM, HEAL_AMOUNT, HEAL_DELAY, MIN_HEAL, MAX_HEAL, INVINCIBILITY,
INVINCIBILITY, SNOW_MELT, ICE_MELT, ICE_FORM, MUSHROOMS SNOW_FALL, SNOW_MELT, ICE_FORM, ICE_MELT, MUSHROOMS, LEAF_DECAY,
FIRE_SPREAD, LAVA_FIRE, LAVA_FLOW, WATER_FLOW,
TELE_LOC, TELE_PERM, SPAWN_LOC, SPAWN_PERM,
BLOCKED_CMDS, ALLOWED_CMDS, PRICE, BUYABLE,
}; };
static { static {