Add option to disable flying on pvp

This commit is contained in:
Magnus Ulf 2019-07-15 08:08:35 +02:00
parent 35c38ce4b8
commit 6724c4f065
4 changed files with 45 additions and 11 deletions

View File

@ -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<String> oldWorlds = newFaction.getClaimedWorlds();

View File

@ -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("<i>Flying is disabled in combat.");
}
if (mattacker.isFlying())
{
mattacker.setFlying(false);
deactivateForPlayer(attacker);
mattacker.msg("<i>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("<b>Only players can fly");
throw new MassiveException().addMsg("<b>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("<i>You can ask a faction admin to change the flag");
ex.addMsg("<i>You can ask a faction admin to change the flag.");
}
}
// ... or only server admins can change it ...

View File

@ -324,6 +324,9 @@ public class MConf extends Entity<MConf>
// 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
// -------------------------------------------- //

View File

@ -805,12 +805,7 @@ public class MPlayer extends SenderEntity<MPlayer> implements FactionsParticipat
// We clean the chunks further by removing what does not change.
// This is also very suggested cleaning of EventFactionsChunksChange input.
Iterator<PS> 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<i> already owns this land.", newFaction.describeTo(this, true));