Add option to disable flying on pvp
This commit is contained in:
parent
35c38ce4b8
commit
6724c4f065
@ -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();
|
||||
|
@ -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 ...
|
||||
|
@ -323,7 +323,10 @@ 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
|
||||
// -------------------------------------------- //
|
||||
|
@ -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));
|
||||
|
Loading…
Reference in New Issue
Block a user