mirror of
https://github.com/EngineHub/WorldGuard.git
synced 2024-11-30 06:23:49 +01:00
Clean up Heal and Feed flags.
Allow the flags to increase values for players who are invincible (or in creative mode), but not decrease them. Fixes WORLDGUARD-3492.
This commit is contained in:
parent
fbd8206038
commit
ea75549a29
@ -19,6 +19,7 @@
|
||||
|
||||
package com.sk89q.worldguard.session.handler;
|
||||
|
||||
import com.sk89q.worldguard.LocalPlayer;
|
||||
import com.sk89q.worldguard.protection.ApplicableRegionSet;
|
||||
import com.sk89q.worldguard.protection.flags.DefaultFlag;
|
||||
import com.sk89q.worldguard.session.Session;
|
||||
@ -35,17 +36,23 @@ public FeedFlag(Session session) {
|
||||
|
||||
@Override
|
||||
public void tick(Player player, ApplicableRegionSet set) {
|
||||
if (!getSession().isInvincible(player) && player.getGameMode() != GameMode.CREATIVE) {
|
||||
long now = System.currentTimeMillis();
|
||||
LocalPlayer localPlayer = getSession().getPlugin().wrapPlayer(player);
|
||||
|
||||
Integer feedAmount = set.getFlag(DefaultFlag.FEED_AMOUNT);
|
||||
Integer feedDelay = set.getFlag(DefaultFlag.FEED_DELAY);
|
||||
Integer minHunger = set.getFlag(DefaultFlag.MIN_FOOD);
|
||||
Integer maxHunger = set.getFlag(DefaultFlag.MAX_FOOD);
|
||||
Integer feedAmount = set.queryValue(localPlayer, DefaultFlag.FEED_AMOUNT);
|
||||
Integer feedDelay = set.queryValue(localPlayer, DefaultFlag.FEED_DELAY);
|
||||
Integer minHunger = set.queryValue(localPlayer, DefaultFlag.MIN_FOOD);
|
||||
Integer maxHunger = set.queryValue(localPlayer, DefaultFlag.MAX_FOOD);
|
||||
|
||||
if (feedAmount == null || feedDelay == null || feedAmount == 0 || feedDelay < 0) {
|
||||
return;
|
||||
}
|
||||
if (feedAmount < 0
|
||||
&& (getSession().isInvincible(player)
|
||||
|| (player.getGameMode() != GameMode.SURVIVAL && player.getGameMode() != GameMode.ADVENTURE))) {
|
||||
// don't starve invincible players
|
||||
return;
|
||||
}
|
||||
if (minHunger == null) {
|
||||
minHunger = 0;
|
||||
}
|
||||
@ -72,6 +79,5 @@ public void tick(Player player, ApplicableRegionSet set) {
|
||||
lastFeed = now;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -38,7 +38,6 @@ public HealFlag(Session session) {
|
||||
public void tick(Player player, ApplicableRegionSet set) {
|
||||
LocalPlayer localPlayer = getPlugin().wrapPlayer(player);
|
||||
|
||||
if (!getSession().isInvincible(player) && player.getGameMode() != GameMode.CREATIVE) {
|
||||
if (player.getHealth() <= 0) {
|
||||
return;
|
||||
}
|
||||
@ -53,11 +52,15 @@ public void tick(Player player, ApplicableRegionSet set) {
|
||||
if (healAmount == null || healDelay == null || healAmount == 0 || healDelay < 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (healAmount < 0
|
||||
&& (getSession().isInvincible(player)
|
||||
|| (player.getGameMode() != GameMode.SURVIVAL && player.getGameMode() != GameMode.ADVENTURE))) {
|
||||
// don't damage invincible players
|
||||
return;
|
||||
}
|
||||
if (minHealth == null) {
|
||||
minHealth = 0.0;
|
||||
}
|
||||
|
||||
if (maxHealth == null) {
|
||||
maxHealth = player.getMaxHealth();
|
||||
}
|
||||
@ -79,6 +82,5 @@ public void tick(Player player, ApplicableRegionSet set) {
|
||||
lastHeal = now;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user