mirror of
https://github.com/EngineHub/WorldGuard.git
synced 2024-11-28 05:25:20 +01:00
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:
parent
3f77a9b721
commit
0eb68ef864
@ -87,7 +87,9 @@ public void run() {
|
||||
ApplicableRegionSet applicable = regionManager
|
||||
.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 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) {
|
||||
return;
|
||||
}
|
||||
if (minHealth == null) minHealth = 0;
|
||||
if (maxHealth == null) maxHealth = 20;
|
||||
|
||||
if (player.getHealth() >= 20 && healAmount > 0) {
|
||||
if (player.getHealth() >= maxHealth && healAmount > 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (healDelay <= 0 && healAmount > 0) {
|
||||
player.setHealth(20);
|
||||
if (healDelay <= 0) {
|
||||
player.setHealth(healAmount > 0 ? maxHealth : minHealth); // this will insta-kill if the flag is unset
|
||||
state.lastHeal = now;
|
||||
} 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;
|
||||
}
|
||||
}
|
||||
|
@ -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 IntegerFlag HEAL_DELAY = new IntegerFlag("heal-delay");
|
||||
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 RegionGroupFlag TELE_PERM = new RegionGroupFlag("teleport-group", RegionGroupFlag.RegionGroup.MEMBERS);
|
||||
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 Flag<?>[] flagsList = new Flag<?>[] {
|
||||
PASSTHROUGH, BUILD, PVP, MOB_DAMAGE, MOB_SPAWNING, CREEPER_EXPLOSION, SLEEP,
|
||||
TNT, LIGHTER, FIRE_SPREAD, LAVA_FIRE, CHEST_ACCESS, WATER_FLOW, LAVA_FLOW,
|
||||
USE, PLACE_VEHICLE, GREET_MESSAGE, FAREWELL_MESSAGE, NOTIFY_ENTER,
|
||||
NOTIFY_LEAVE, DENY_SPAWN, HEAL_DELAY, HEAL_AMOUNT, TELE_LOC,
|
||||
TELE_PERM, SPAWN_LOC, SPAWN_PERM, BUYABLE, PRICE, SNOW_FALL, LEAF_DECAY,
|
||||
GHAST_FIREBALL, BLOCKED_CMDS, ALLOWED_CMDS, ENTRY, ENTRY_PERM, EXIT, EXIT_PERM,
|
||||
INVINCIBILITY, SNOW_MELT, ICE_MELT, ICE_FORM, MUSHROOMS
|
||||
PASSTHROUGH, BUILD, PVP, CHEST_ACCESS,
|
||||
TNT, LIGHTER, USE, PLACE_VEHICLE, SLEEP,
|
||||
MOB_DAMAGE, MOB_SPAWNING, DENY_SPAWN, CREEPER_EXPLOSION, GHAST_FIREBALL,
|
||||
GREET_MESSAGE, FAREWELL_MESSAGE, NOTIFY_ENTER, NOTIFY_LEAVE,
|
||||
EXIT, EXIT_PERM, ENTRY, ENTRY_PERM,
|
||||
HEAL_AMOUNT, HEAL_DELAY, MIN_HEAL, MAX_HEAL, INVINCIBILITY,
|
||||
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 {
|
||||
|
Loading…
Reference in New Issue
Block a user