mirror of
https://github.com/EngineHub/WorldGuard.git
synced 2025-01-03 06:57:33 +01:00
Implemented a PvM Flag
This commit is contained in:
parent
d827e01760
commit
82cde6b5ec
@ -20,12 +20,14 @@
|
||||
|
||||
import static com.sk89q.worldguard.bukkit.BukkitUtil.toVector;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.entity.Creature;
|
||||
import org.bukkit.entity.Creeper;
|
||||
import org.bukkit.entity.EnderDragon;
|
||||
import org.bukkit.entity.EnderPearl;
|
||||
@ -37,6 +39,7 @@
|
||||
import org.bukkit.entity.LivingEntity;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.entity.Projectile;
|
||||
import org.bukkit.entity.Slime;
|
||||
import org.bukkit.entity.TNTPrimed;
|
||||
import org.bukkit.entity.Tameable;
|
||||
import org.bukkit.entity.ThrownPotion;
|
||||
@ -223,6 +226,7 @@ private void onEntityDamageByEntity(EntityDamageByEntityEvent event) {
|
||||
|
||||
if (attacker instanceof Player) {
|
||||
Player player = (Player) attacker;
|
||||
LocalPlayer localPlayer = plugin.wrapPlayer(player);
|
||||
|
||||
ConfigurationManager cfg = plugin.getGlobalStateManager();
|
||||
WorldConfiguration wcfg = cfg.get(player.getWorld());
|
||||
@ -239,6 +243,29 @@ private void onEntityDamageByEntity(EntityDamageByEntityEvent event) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Bukkit doesn't consider Slimes to be Creatures for whatever reason
|
||||
if (defender instanceof Creature || defender instanceof Slime) {
|
||||
if (wcfg.useRegions) {
|
||||
Vector pt = toVector(defender.getLocation());
|
||||
Vector pt2 = toVector(attacker.getLocation());
|
||||
RegionManager mgr = plugin.getGlobalRegionManager().get(player.getWorld());
|
||||
|
||||
// Accumulate all entities that aren't allowed to be attacked here
|
||||
Set<EntityType> entityTypes = new HashSet<EntityType>();
|
||||
Set<EntityType> es = mgr.getApplicableRegions(pt).getFlag(DefaultFlag.DENY_PVM, localPlayer);
|
||||
Set<EntityType> es2 = mgr.getApplicableRegions(pt2).getFlag(DefaultFlag.DENY_PVM, localPlayer);
|
||||
|
||||
if (es != null) entityTypes.addAll(es);
|
||||
if (es2 != null) entityTypes.addAll(es2);
|
||||
|
||||
if (entityTypes.contains(defender.getType())) {
|
||||
player.sendMessage(ChatColor.DARK_RED + "You may not attack that mob here.");
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (defender instanceof ItemFrame) {
|
||||
@ -281,17 +308,30 @@ private void onEntityDamageByEntity(EntityDamageByEntityEvent event) {
|
||||
}
|
||||
|
||||
if (attacker != null) {
|
||||
if (attacker instanceof Player) {
|
||||
if (wcfg.useRegions) {
|
||||
Vector pt = toVector(defender.getLocation());
|
||||
Vector pt2 = toVector(attacker.getLocation());
|
||||
RegionManager mgr = plugin.getGlobalRegionManager().get(player.getWorld());
|
||||
|
||||
if (attacker instanceof Player) {
|
||||
if (!mgr.getApplicableRegions(pt2).allows(DefaultFlag.PVP, plugin.wrapPlayer((Player) attacker))) {
|
||||
tryCancelPVPEvent((Player) attacker, player, event, true);
|
||||
} else if (!mgr.getApplicableRegions(pt).allows(DefaultFlag.PVP ,localPlayer)) {
|
||||
tryCancelPVPEvent((Player) attacker, player, event, false);
|
||||
}
|
||||
} else {
|
||||
// Accumulate all entities that aren't allowed to be attacked here
|
||||
Set<EntityType> entityTypes = new HashSet<EntityType>();
|
||||
Set<EntityType> es = mgr.getApplicableRegions(pt).getFlag(DefaultFlag.DENY_PVM, localPlayer);
|
||||
Set<EntityType> es2 = mgr.getApplicableRegions(pt2).getFlag(DefaultFlag.DENY_PVM, localPlayer);
|
||||
|
||||
if (es != null) entityTypes.addAll(es);
|
||||
if (es2 != null) entityTypes.addAll(es2);
|
||||
|
||||
if (entityTypes.contains(attacker.getType())) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -408,6 +448,43 @@ private void onEntityDamageByProjectile(EntityDamageByEntityEvent event) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (attacker instanceof Player) {
|
||||
Player player = (Player) attacker;
|
||||
LocalPlayer localPlayer = plugin.wrapPlayer(player);
|
||||
|
||||
ConfigurationManager cfg = plugin.getGlobalStateManager();
|
||||
WorldConfiguration wcfg = cfg.get(player.getWorld());
|
||||
|
||||
if (event.getDamager() instanceof EnderPearl && attacker.equals(defender)) return;
|
||||
if (wcfg.useRegions) {
|
||||
Vector pt = toVector(defender.getLocation());
|
||||
Vector pt2 = toVector(attacker.getLocation());
|
||||
RegionManager mgr = plugin.getGlobalRegionManager().get(player.getWorld());
|
||||
|
||||
if (defender instanceof Player) {
|
||||
if (!mgr.getApplicableRegions(pt2).allows(DefaultFlag.PVP, plugin.wrapPlayer((Player) attacker))) {
|
||||
tryCancelPVPEvent((Player) attacker, player, event, true);
|
||||
} else if (!mgr.getApplicableRegions(pt).allows(DefaultFlag.PVP, localPlayer)) {
|
||||
tryCancelPVPEvent((Player) attacker, player, event, false);
|
||||
}
|
||||
} else {
|
||||
// Accumulate all entities that aren't allowed to be attacked here
|
||||
Set<EntityType> entityTypes = new HashSet<EntityType>();
|
||||
Set<EntityType> es = mgr.getApplicableRegions(pt).getFlag(DefaultFlag.DENY_PVM, localPlayer);
|
||||
Set<EntityType> es2 = mgr.getApplicableRegions(pt2).getFlag(DefaultFlag.DENY_PVM, localPlayer);
|
||||
|
||||
if (es != null) entityTypes.addAll(es);
|
||||
if (es2 != null) entityTypes.addAll(es2);
|
||||
|
||||
if (entityTypes.contains(defender.getType())) {
|
||||
player.sendMessage(ChatColor.DARK_RED + "You may not attack that mob here.");
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (defender instanceof Player) {
|
||||
Player player = (Player) defender;
|
||||
LocalPlayer localPlayer = plugin.wrapPlayer(player);
|
||||
@ -422,35 +499,33 @@ private void onEntityDamageByProjectile(EntityDamageByEntityEvent event) {
|
||||
}
|
||||
|
||||
// Check Mob
|
||||
if (attacker != null && !(attacker instanceof Player)) {
|
||||
if (!(attacker instanceof Player)) {
|
||||
if (wcfg.disableMobDamage) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
|
||||
if (wcfg.useRegions) {
|
||||
Vector pt = toVector(defender.getLocation());
|
||||
Vector pt2 = toVector(attacker.getLocation());
|
||||
RegionManager mgr = plugin.getGlobalRegionManager().get(player.getWorld());
|
||||
|
||||
if (!mgr.getApplicableRegions(pt).allows(DefaultFlag.MOB_DAMAGE, localPlayer)) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Check Player
|
||||
// if (event.getDamager() instanceof EnderPearl || event.getDamager() instanceof Snowball) return;
|
||||
if (attacker != null && attacker instanceof Player) {
|
||||
if (event.getDamager() instanceof EnderPearl && attacker == player) return;
|
||||
if (wcfg.useRegions) {
|
||||
Vector pt = toVector(defender.getLocation());
|
||||
Vector pt2 = toVector(attacker.getLocation());
|
||||
RegionManager mgr = plugin.getGlobalRegionManager().get(player.getWorld());
|
||||
// Accumulate all entities that aren't allowed to be attacked here
|
||||
Set<EntityType> entityTypes = new HashSet<EntityType>();
|
||||
Set<EntityType> es = mgr.getApplicableRegions(pt).getFlag(DefaultFlag.DENY_PVM, localPlayer);
|
||||
Set<EntityType> es2 = mgr.getApplicableRegions(pt2).getFlag(DefaultFlag.DENY_PVM, localPlayer);
|
||||
|
||||
if (!mgr.getApplicableRegions(pt2).allows(DefaultFlag.PVP, plugin.wrapPlayer((Player) attacker))) {
|
||||
tryCancelPVPEvent((Player) attacker, player, event, true);
|
||||
} else if (!mgr.getApplicableRegions(pt).allows(DefaultFlag.PVP, localPlayer)) {
|
||||
tryCancelPVPEvent((Player) attacker, player, event, false);
|
||||
if (es != null) entityTypes.addAll(es);
|
||||
if (es2 != null) entityTypes.addAll(es2);
|
||||
|
||||
if (entityTypes.contains(attacker.getType())) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -78,6 +78,7 @@ public final class DefaultFlag {
|
||||
public static final BooleanFlag NOTIFY_ENTER = new BooleanFlag("notify-enter", RegionGroup.ALL);
|
||||
public static final BooleanFlag NOTIFY_LEAVE = new BooleanFlag("notify-leave", RegionGroup.ALL);
|
||||
public static final SetFlag<EntityType> DENY_SPAWN = new SetFlag<EntityType>("deny-spawn", RegionGroup.ALL, new EntityTypeFlag(null));
|
||||
public static final SetFlag<EntityType> DENY_PVM = new SetFlag<EntityType>("deny-pvm", new EntityTypeFlag(null));
|
||||
public static final EnumFlag<GameMode> GAME_MODE = new EnumFlag<GameMode>("game-mode", GameMode.class, RegionGroup.ALL);
|
||||
public static final IntegerFlag HEAL_DELAY = new IntegerFlag("heal-delay", RegionGroup.ALL);
|
||||
public static final IntegerFlag HEAL_AMOUNT = new IntegerFlag("heal-amount", RegionGroup.ALL);
|
||||
@ -100,7 +101,7 @@ public final class DefaultFlag {
|
||||
public static final Flag<?>[] flagsList = new Flag<?>[] {
|
||||
PASSTHROUGH, BUILD, CONSTRUCT, PVP, CHEST_ACCESS, PISTONS,
|
||||
TNT, LIGHTER, USE, PLACE_VEHICLE, DESTROY_VEHICLE, SLEEP,
|
||||
MOB_DAMAGE, MOB_SPAWNING, DENY_SPAWN, INVINCIBILITY, EXP_DROPS,
|
||||
MOB_DAMAGE, MOB_SPAWNING, DENY_SPAWN, DENY_PVM, INVINCIBILITY, EXP_DROPS,
|
||||
CREEPER_EXPLOSION, OTHER_EXPLOSION, ENDERDRAGON_BLOCK_DAMAGE, GHAST_FIREBALL, ENDER_BUILD,
|
||||
GREET_MESSAGE, FAREWELL_MESSAGE, NOTIFY_ENTER, NOTIFY_LEAVE,
|
||||
EXIT, ENTRY, LIGHTNING, ENTITY_PAINTING_DESTROY, ENDERPEARL,
|
||||
|
Loading…
Reference in New Issue
Block a user