From 6f782b8503308e42735bfe49aa28d13a5d6ecaf7 Mon Sep 17 00:00:00 2001 From: ulumulu1510 Date: Sun, 29 Jan 2017 15:31:56 +0100 Subject: [PATCH] Add DisallowCause to EventFactionsPvpDisallowed. --- .../factions/engine/DisallowCause.java | 17 +++++++++++++++++ .../factions/engine/EngineCanCombatHappen.java | 18 +++++++++--------- .../event/EventFactionsPvpDisallowed.java | 7 ++++++- 3 files changed, 32 insertions(+), 10 deletions(-) create mode 100644 src/com/massivecraft/factions/engine/DisallowCause.java diff --git a/src/com/massivecraft/factions/engine/DisallowCause.java b/src/com/massivecraft/factions/engine/DisallowCause.java new file mode 100644 index 00000000..ae0dfbc3 --- /dev/null +++ b/src/com/massivecraft/factions/engine/DisallowCause.java @@ -0,0 +1,17 @@ +package com.massivecraft.factions.engine; + +public enum DisallowCause +{ + // -------------------------------------------- // + // ENUM + // -------------------------------------------- // + + PEACEFUL_LAND, + FACTIONLESS, + FRIENDLYFIRE, + OWN_TERRITORY + + // END OF LIST + ; + +} diff --git a/src/com/massivecraft/factions/engine/EngineCanCombatHappen.java b/src/com/massivecraft/factions/engine/EngineCanCombatHappen.java index 4ea1bd6c..b3db6a91 100644 --- a/src/com/massivecraft/factions/engine/EngineCanCombatHappen.java +++ b/src/com/massivecraft/factions/engine/EngineCanCombatHappen.java @@ -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("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("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("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("You can't hurt %s.", 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("You can't hurt %s in their own territory unless you declare them as an enemy.", mdefender.describeTo(uattacker)); diff --git a/src/com/massivecraft/factions/event/EventFactionsPvpDisallowed.java b/src/com/massivecraft/factions/event/EventFactionsPvpDisallowed.java index dd137b9c..794fc280 100644 --- a/src/com/massivecraft/factions/event/EventFactionsPvpDisallowed.java +++ b/src/com/massivecraft/factions/event/EventFactionsPvpDisallowed.java @@ -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; }