mirror of
https://github.com/EngineHub/WorldGuard.git
synced 2025-02-04 14:31:40 +01:00
Allow invincibility flag to disable god mode (when set to deny) unless the player has the worldguard.god.override-regions permission.
This commit is contained in:
parent
3757056e46
commit
17741822c1
@ -87,7 +87,8 @@ public void run() {
|
|||||||
ApplicableRegionSet applicable = regionManager
|
ApplicableRegionSet applicable = regionManager
|
||||||
.getApplicableRegions(playerLocation);
|
.getApplicableRegions(playerLocation);
|
||||||
|
|
||||||
if (!RegionQueryUtil.isInvincible(plugin, player, applicable)) {
|
if (!RegionQueryUtil.isInvincible(plugin, player, applicable)
|
||||||
|
&& !plugin.getGlobalStateManager().hasGodMode(player)) {
|
||||||
processHeal(applicable, player, state);
|
processHeal(applicable, player, state);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -26,6 +26,7 @@
|
|||||||
import com.sk89q.worldedit.Vector;
|
import com.sk89q.worldedit.Vector;
|
||||||
import com.sk89q.worldguard.protection.ApplicableRegionSet;
|
import com.sk89q.worldguard.protection.ApplicableRegionSet;
|
||||||
import com.sk89q.worldguard.protection.flags.DefaultFlag;
|
import com.sk89q.worldguard.protection.flags.DefaultFlag;
|
||||||
|
import com.sk89q.worldguard.protection.flags.StateFlag;
|
||||||
import com.sk89q.worldguard.protection.managers.RegionManager;
|
import com.sk89q.worldguard.protection.managers.RegionManager;
|
||||||
|
|
||||||
public class RegionQueryUtil {
|
public class RegionQueryUtil {
|
||||||
@ -63,4 +64,21 @@ public static boolean isInvincible(WorldGuardPlugin plugin, Player player,
|
|||||||
|
|
||||||
return state.wasInvincible;
|
return state.wasInvincible;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static Boolean isAllowedInvinciblity(WorldGuardPlugin plugin, Player player) {
|
||||||
|
Location loc = player.getLocation();
|
||||||
|
World world = player.getWorld();
|
||||||
|
FlagStateManager.PlayerFlagState state = plugin.getFlagStateManager().getState(player);
|
||||||
|
Vector vec = new Vector(state.lastInvincibleX, state.lastInvincibleY, state.lastInvincibleZ);
|
||||||
|
|
||||||
|
StateFlag.State regionState = plugin.getGlobalRegionManager().get(world).
|
||||||
|
getApplicableRegions(vec).getFlag(DefaultFlag.INVINCIBILITY);
|
||||||
|
if (regionState == StateFlag.State.ALLOW) {
|
||||||
|
return true;
|
||||||
|
} else if (regionState == StateFlag.State.DENY) {
|
||||||
|
return false;
|
||||||
|
} else {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -67,6 +67,7 @@
|
|||||||
import com.sk89q.worldguard.blacklist.events.ItemUseBlacklistEvent;
|
import com.sk89q.worldguard.blacklist.events.ItemUseBlacklistEvent;
|
||||||
import com.sk89q.worldguard.protection.ApplicableRegionSet;
|
import com.sk89q.worldguard.protection.ApplicableRegionSet;
|
||||||
import com.sk89q.worldguard.protection.flags.DefaultFlag;
|
import com.sk89q.worldguard.protection.flags.DefaultFlag;
|
||||||
|
import com.sk89q.worldguard.protection.flags.StateFlag;
|
||||||
import com.sk89q.worldguard.protection.managers.RegionManager;
|
import com.sk89q.worldguard.protection.managers.RegionManager;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -164,8 +165,7 @@ private void onEntityDamageByBlock(EntityDamageByBlockEvent event) {
|
|||||||
} else if (defender instanceof Player) {
|
} else if (defender instanceof Player) {
|
||||||
Player player = (Player) defender;
|
Player player = (Player) defender;
|
||||||
|
|
||||||
if (cfg.hasGodMode(player)
|
if (isInvincible(player)) {
|
||||||
|| (wcfg.useRegions && RegionQueryUtil.isInvincible(plugin, player))) {
|
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -238,13 +238,8 @@ private void onEntityDamageByEntity(EntityDamageByEntityEvent event) {
|
|||||||
|
|
||||||
ConfigurationManager cfg = plugin.getGlobalStateManager();
|
ConfigurationManager cfg = plugin.getGlobalStateManager();
|
||||||
WorldConfiguration wcfg = cfg.get(player.getWorld());
|
WorldConfiguration wcfg = cfg.get(player.getWorld());
|
||||||
|
|
||||||
if (cfg.hasGodMode(player)) {
|
|
||||||
event.setCancelled(true);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (wcfg.useRegions && RegionQueryUtil.isInvincible(plugin, player)) {
|
if (isInvincible(player)) {
|
||||||
if (wcfg.regionInvinciblityRemovesMobs
|
if (wcfg.regionInvinciblityRemovesMobs
|
||||||
&& attacker instanceof LivingEntity && !(attacker instanceof Player)
|
&& attacker instanceof LivingEntity && !(attacker instanceof Player)
|
||||||
&& !(attacker instanceof Tameable && ((Tameable) attacker).isTamed())) {
|
&& !(attacker instanceof Tameable && ((Tameable) attacker).isTamed())) {
|
||||||
@ -359,7 +354,7 @@ private void onEntityDamageByProjectile(EntityDamageByEntityEvent event) {
|
|||||||
ConfigurationManager cfg = plugin.getGlobalStateManager();
|
ConfigurationManager cfg = plugin.getGlobalStateManager();
|
||||||
WorldConfiguration wcfg = cfg.get(player.getWorld());
|
WorldConfiguration wcfg = cfg.get(player.getWorld());
|
||||||
|
|
||||||
if (cfg.hasGodMode(player) || (wcfg.useRegions && RegionQueryUtil.isInvincible(plugin, player))) {
|
if (isInvincible(player)) {
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -426,8 +421,7 @@ public void onEntityDamage(EntityDamageEvent event) {
|
|||||||
} else if (defender instanceof Player) {
|
} else if (defender instanceof Player) {
|
||||||
Player player = (Player) defender;
|
Player player = (Player) defender;
|
||||||
|
|
||||||
if (cfg.hasGodMode(player)
|
if (isInvincible(player)) {
|
||||||
|| (wcfg.useRegions && RegionQueryUtil.isInvincible(plugin, player))) {
|
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
player.setFireTicks(0);
|
player.setFireTicks(0);
|
||||||
return;
|
return;
|
||||||
@ -772,4 +766,26 @@ public void onEntityRegainHealth(EntityRegainHealthEvent event) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check if a player is invincible, via either god mode or region flag. If
|
||||||
|
* the region denies invincibility, the player must have the another
|
||||||
|
* permission to override it.
|
||||||
|
*
|
||||||
|
* @param player
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
private boolean isInvincible(Player player) {
|
||||||
|
ConfigurationManager cfg = plugin.getGlobalStateManager();
|
||||||
|
WorldConfiguration wcfg = cfg.get(player.getWorld());
|
||||||
|
|
||||||
|
boolean god = cfg.hasGodMode(player);
|
||||||
|
Boolean allowed = wcfg.useRegions && RegionQueryUtil.isAllowedInvinciblity(plugin, player);
|
||||||
|
if (allowed == false && wcfg.useRegions) {
|
||||||
|
return god && plugin.hasPermission(player, "worldguard.god.override-regions");
|
||||||
|
} else if (allowed == true || !wcfg.useRegions) {
|
||||||
|
return god;
|
||||||
|
} else {
|
||||||
|
return RegionQueryUtil.isInvincible(plugin, player);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user