Add DisallowCause to EventFactionsPvpDisallowed.

This commit is contained in:
ulumulu1510 2017-01-29 15:31:56 +01:00
parent 7076ffbc5d
commit 6f782b8503
3 changed files with 32 additions and 10 deletions

View File

@ -0,0 +1,17 @@
package com.massivecraft.factions.engine;
public enum DisallowCause
{
// -------------------------------------------- //
// ENUM
// -------------------------------------------- //
PEACEFUL_LAND,
FACTIONLESS,
FRIENDLYFIRE,
OWN_TERRITORY
// END OF LIST
;
}

View File

@ -82,9 +82,9 @@ public class EngineCanCombatHappen extends Engine
}
// Utility method used in "canCombatDamageHappen" below.
public static boolean falseUnlessDisallowedPvpEventCancelled(Player attacker, Player defender, EntityDamageByEntityEvent event)
public static boolean falseUnlessDisallowedPvpEventCancelled(Player attacker, Player defender, DisallowCause reason, EntityDamageByEntityEvent event)
{
EventFactionsPvpDisallowed dpe = new EventFactionsPvpDisallowed(attacker, defender, event);
EventFactionsPvpDisallowed dpe = new EventFactionsPvpDisallowed(attacker, defender, reason, event);
dpe.run();
return dpe.isCancelled();
}
@ -121,11 +121,11 @@ public class EngineCanCombatHappen extends Engine
{
// No attacker?
// Let's behave as if it were a player
return falseUnlessDisallowedPvpEventCancelled(null, defender, event);
return falseUnlessDisallowedPvpEventCancelled(null, defender, DisallowCause.PEACEFUL_LAND, event);
}
if (MUtil.isPlayer(eattacker))
{
ret = falseUnlessDisallowedPvpEventCancelled((Player)eattacker, defender, event);
ret = falseUnlessDisallowedPvpEventCancelled((Player)eattacker, defender, DisallowCause.PEACEFUL_LAND, event);
if (!ret && notify)
{
MPlayer attacker = MPlayer.get(eattacker);
@ -153,7 +153,7 @@ public class EngineCanCombatHappen extends Engine
// NOTE: This check is probably not that important but we could keep it anyways.
if (attackerPsFaction.getFlag(MFlag.getFlagPvp()) == false)
{
ret = falseUnlessDisallowedPvpEventCancelled(attacker, defender, event);
ret = falseUnlessDisallowedPvpEventCancelled(attacker, defender, DisallowCause.PEACEFUL_LAND, event);
if (!ret && notify) uattacker.msg("<i>PVP is disabled in %s.", attackerPsFaction.describeTo(uattacker));
return ret;
}
@ -166,7 +166,7 @@ public class EngineCanCombatHappen extends Engine
if (attackFaction.isNone() && MConf.get().disablePVPForFactionlessPlayers)
{
ret = falseUnlessDisallowedPvpEventCancelled(attacker, defender, event);
ret = falseUnlessDisallowedPvpEventCancelled(attacker, defender, DisallowCause.FACTIONLESS, event);
if (!ret && notify) uattacker.msg("<i>You can't hurt other players until you join a faction.");
return ret;
}
@ -179,7 +179,7 @@ public class EngineCanCombatHappen extends Engine
}
else if (MConf.get().disablePVPForFactionlessPlayers)
{
ret = falseUnlessDisallowedPvpEventCancelled(attacker, defender, event);
ret = falseUnlessDisallowedPvpEventCancelled(attacker, defender, DisallowCause.FACTIONLESS, event);
if (!ret && notify) uattacker.msg("<i>You can't hurt players who are not currently in a faction.");
return ret;
}
@ -195,7 +195,7 @@ public class EngineCanCombatHappen extends Engine
// Check the relation
if (relation.isFriend() && defenderPsFaction.getFlag(MFlag.getFlagFriendlyire()) == false)
{
ret = falseUnlessDisallowedPvpEventCancelled(attacker, defender, event);
ret = falseUnlessDisallowedPvpEventCancelled(attacker, defender, DisallowCause.FRIENDLYFIRE, event);
if (!ret && notify) uattacker.msg("<i>You can't hurt %s<i>.", relation.getDescPlayerMany());
return ret;
}
@ -205,7 +205,7 @@ public class EngineCanCombatHappen extends Engine
if (mdefender.hasFaction() && ownTerritory && relation == Rel.NEUTRAL)
{
ret = falseUnlessDisallowedPvpEventCancelled(attacker, defender, event);
ret = falseUnlessDisallowedPvpEventCancelled(attacker, defender, DisallowCause.OWN_TERRITORY, event);
if (!ret && notify)
{
uattacker.msg("<i>You can't hurt %s<i> in their own territory unless you declare them as an enemy.", mdefender.describeTo(uattacker));

View File

@ -4,6 +4,7 @@ import org.bukkit.entity.Player;
import org.bukkit.event.HandlerList;
import org.bukkit.event.entity.EntityDamageByEntityEvent;
import com.massivecraft.factions.engine.DisallowCause;
import com.massivecraft.factions.entity.MPlayer;
/**
@ -35,6 +36,9 @@ public class EventFactionsPvpDisallowed extends EventFactionsAbstract
public Player getDefender() { return this.defender; }
public MPlayer getMDefender() { return this.defender == null ? null : MPlayer.get(this.defender); }
private final DisallowCause cause;
public DisallowCause getCause() { return this.cause; }
private final EntityDamageByEntityEvent event;
public EntityDamageByEntityEvent getEvent() { return this.event; }
@ -42,10 +46,11 @@ public class EventFactionsPvpDisallowed extends EventFactionsAbstract
// CONSTRUCT
// -------------------------------------------- //
public EventFactionsPvpDisallowed(Player attacker, Player defender, EntityDamageByEntityEvent event)
public EventFactionsPvpDisallowed(Player attacker, Player defender, DisallowCause cause, EntityDamageByEntityEvent event)
{
this.attacker = attacker;
this.defender = defender;
this.cause = cause;
this.event = event;
}