diff --git a/src/com/massivecraft/factions/engine/EngineChunkChange.java b/src/com/massivecraft/factions/engine/EngineChunkChange.java index 2cc5bea3..f010d44e 100644 --- a/src/com/massivecraft/factions/engine/EngineChunkChange.java +++ b/src/com/massivecraft/factions/engine/EngineChunkChange.java @@ -118,7 +118,7 @@ public class EngineChunkChange extends Engine return; } - // ... ensure the claim would not bypass the global max limit ... + // ... ensure the claim would not bypass the global world limit ... if (MConf.get().claimedWorldsMax >= 0) { Set oldWorlds = newFaction.getClaimedWorlds(); diff --git a/src/com/massivecraft/factions/engine/EngineFly.java b/src/com/massivecraft/factions/engine/EngineFly.java index 07e89e63..03a86449 100644 --- a/src/com/massivecraft/factions/engine/EngineFly.java +++ b/src/com/massivecraft/factions/engine/EngineFly.java @@ -16,9 +16,11 @@ import com.massivecraft.massivecore.event.EventMassiveCorePlayerUpdate; import com.massivecraft.massivecore.ps.PS; import com.massivecraft.massivecore.store.DriverFlatfile; import com.massivecraft.massivecore.util.MUtil; +import org.bukkit.entity.Entity; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; +import org.bukkit.event.entity.EntityDamageByEntityEvent; import org.bukkit.event.player.PlayerMoveEvent; import java.io.File; @@ -54,7 +56,7 @@ public class EngineFly extends Engine // ... and the player enables flying ... if (!mplayer.isFlying()) return; - // ... and the player enables flying ... + // ... and the player can fly here... if (!canFlyInTerritory(mplayer, PS.valueOf(player))) return; // ... set allowed ... @@ -97,6 +99,40 @@ public class EngineFly extends Engine event.getFaction().getOnlinePlayers().forEach(EngineFly::deactivateForPlayer); } + @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) + public void territoryShield(EntityDamageByEntityEvent event) + { + // If flying is diabled on PVP ... + if (!MConf.get().flyDisableOnPvp) return; + + // ... and the defender is a player ... + Entity entity = event.getEntity(); + if (MUtil.isntPlayer(entity)) return; + Player defender = (Player)entity; + MPlayer mdefender = MPlayer.get(defender); + + // ... and the attacker is a player ... + Entity eattacker = MUtil.getLiableDamager(event); + if (! (eattacker instanceof Player)) return; + Player attacker = (Player) eattacker; + MPlayer mattacker = MPlayer.get(attacker); + + // ... disable flying for both + if (mdefender.isFlying()) + { + mdefender.setFlying(false); + deactivateForPlayer(defender); + mdefender.msg("Flying is disabled in combat."); + } + + if (mattacker.isFlying()) + { + mattacker.setFlying(false); + deactivateForPlayer(attacker); + mattacker.msg("Flying is disabled in combat."); + } + } + public static boolean canFlyInTerritory(MPlayer mplayer, PS ps) { try @@ -114,7 +150,7 @@ public class EngineFly extends Engine { if (!mplayer.isPlayer()) { - throw new MassiveException().addMsg("Only players can fly"); + throw new MassiveException().addMsg("Only players can fly."); } Faction faction = mplayer.getFaction(); @@ -144,7 +180,7 @@ public class EngineFly extends Engine // ... otherwise ... else { // .. tell them to have someone else edit it ... - ex.addMsg("You can ask a faction admin to change the flag"); + ex.addMsg("You can ask a faction admin to change the flag."); } } // ... or only server admins can change it ... diff --git a/src/com/massivecraft/factions/entity/MConf.java b/src/com/massivecraft/factions/entity/MConf.java index b96eea5d..8fae4bbc 100644 --- a/src/com/massivecraft/factions/entity/MConf.java +++ b/src/com/massivecraft/factions/entity/MConf.java @@ -323,7 +323,10 @@ public class MConf extends Entity // At what speed can players fly with /f fly? public float flySpeed = 0.1f; - + + // Will flying be disabled on pvp + public boolean flyDisableOnPvp = false; + // -------------------------------------------- // // DENY COMMANDS // -------------------------------------------- // diff --git a/src/com/massivecraft/factions/entity/MPlayer.java b/src/com/massivecraft/factions/entity/MPlayer.java index 040e1e3a..6d666031 100644 --- a/src/com/massivecraft/factions/entity/MPlayer.java +++ b/src/com/massivecraft/factions/entity/MPlayer.java @@ -805,12 +805,7 @@ public class MPlayer extends SenderEntity implements FactionsParticipat // We clean the chunks further by removing what does not change. // This is also very suggested cleaning of EventFactionsChunksChange input. Iterator iter = chunks.iterator(); - while (iter.hasNext()) - { - PS chunk = iter.next(); - Faction oldFaction = BoardColl.get().getFactionAt(chunk); - if (newFaction == oldFaction) iter.remove(); - } + chunks.removeIf(chunk -> BoardColl.get().getFactionAt(chunk) == newFaction); if (chunks.isEmpty()) { msg("%s already owns this land.", newFaction.describeTo(this, true));