2011-07-18 22:06:02 +02:00
package com.massivecraft.factions.listeners ;
2011-02-06 13:36:11 +01:00
2011-03-07 04:13:27 +01:00
import java.text.MessageFormat ;
2011-02-06 13:36:11 +01:00
import org.bukkit.ChatColor ;
2011-08-02 03:22:16 +02:00
import org.bukkit.Location ;
2011-03-22 17:20:21 +01:00
import org.bukkit.entity.Creeper ;
2011-02-06 13:36:11 +01:00
import org.bukkit.entity.Entity ;
2011-03-18 00:02:29 +01:00
import org.bukkit.entity.Fireball ;
2011-02-06 13:36:11 +01:00
import org.bukkit.entity.Player ;
2011-09-08 10:20:55 +02:00
import org.bukkit.entity.Projectile ;
2011-03-23 17:39:56 +01:00
import org.bukkit.event.entity.CreatureSpawnEvent ;
2011-09-22 13:22:01 +02:00
import org.bukkit.event.entity.EndermanPickupEvent ;
import org.bukkit.event.entity.EndermanPlaceEvent ;
2011-02-06 13:36:11 +01:00
import org.bukkit.event.entity.EntityDamageByEntityEvent ;
2011-02-13 17:04:06 +01:00
import org.bukkit.event.entity.EntityDamageEvent ;
2011-02-06 13:36:11 +01:00
import org.bukkit.event.entity.EntityDeathEvent ;
2011-03-06 21:13:48 +01:00
import org.bukkit.event.entity.EntityExplodeEvent ;
2011-02-06 13:36:11 +01:00
import org.bukkit.event.entity.EntityListener ;
2011-03-23 17:39:56 +01:00
import org.bukkit.event.entity.EntityTargetEvent ;
2011-04-28 22:45:43 +02:00
import org.bukkit.event.painting.PaintingBreakByEntityEvent ;
import org.bukkit.event.painting.PaintingBreakEvent ;
import org.bukkit.event.painting.PaintingPlaceEvent ;
2011-07-18 22:06:02 +02:00
import com.massivecraft.factions.Board ;
import com.massivecraft.factions.Conf ;
import com.massivecraft.factions.FLocation ;
import com.massivecraft.factions.FPlayer ;
2011-10-08 22:03:44 +02:00
import com.massivecraft.factions.FPlayers ;
2011-07-18 22:06:02 +02:00
import com.massivecraft.factions.Faction ;
2011-10-08 22:03:44 +02:00
import com.massivecraft.factions.P ;
2011-07-18 22:06:02 +02:00
import com.massivecraft.factions.struct.Relation ;
2011-10-08 22:03:44 +02:00
import com.massivecraft.factions.util.MiscUtil ;
2011-02-06 13:36:11 +01:00
2011-10-08 22:03:44 +02:00
public class FactionsEntityListener extends EntityListener
{
public P p ;
public FactionsEntityListener ( P p )
{
this . p = p ;
}
2011-02-06 13:36:11 +01:00
@Override
2011-10-08 22:03:44 +02:00
public void onEntityDeath ( EntityDeathEvent event )
{
2011-02-06 13:36:11 +01:00
Entity entity = event . getEntity ( ) ;
2011-10-08 22:03:44 +02:00
if ( ! ( entity instanceof Player ) )
{
2011-02-06 13:36:11 +01:00
return ;
}
2011-05-29 23:28:29 +02:00
2011-02-06 13:36:11 +01:00
Player player = ( Player ) entity ;
2011-10-08 22:03:44 +02:00
FPlayer fplayer = FPlayers . i . get ( player ) ;
2011-05-29 23:28:29 +02:00
Faction faction = Board . getFactionAt ( new FLocation ( player . getLocation ( ) ) ) ;
2011-10-08 22:03:44 +02:00
if ( faction . isWarZone ( ) )
{
// war zones always override worldsNoPowerLoss either way, thus this layout
if ( ! Conf . warZonePowerLoss )
{
2011-10-21 18:14:04 +02:00
fplayer . msg ( " <i>You didn't lose any power since you were in a war zone. " ) ;
2011-05-29 23:28:29 +02:00
return ;
}
2011-10-08 22:03:44 +02:00
if ( Conf . worldsNoPowerLoss . contains ( player . getWorld ( ) . getName ( ) ) )
{
2011-10-21 18:14:04 +02:00
fplayer . msg ( " <b>The world you are in has power loss normally disabled, but you still lost power since you were in a war zone. " ) ;
2011-05-29 23:28:29 +02:00
}
2011-10-08 22:03:44 +02:00
}
else if ( faction . isNone ( ) & & ! Conf . wildernessPowerLoss & & ! Conf . worldsNoWildernessProtection . contains ( player . getWorld ( ) . getName ( ) ) )
{
2011-10-21 18:14:04 +02:00
fplayer . msg ( " <i>You didn't lose any power since you were in the wilderness. " ) ;
2011-06-02 01:32:09 +02:00
return ;
2011-10-08 22:03:44 +02:00
}
else if ( Conf . worldsNoPowerLoss . contains ( player . getWorld ( ) . getName ( ) ) )
{
2011-10-21 18:14:04 +02:00
fplayer . msg ( " <i>You didn't lose any power due to the world you died in. " ) ;
2011-05-29 23:28:29 +02:00
return ;
2011-10-08 22:03:44 +02:00
}
else if ( Conf . peacefulMembersDisablePowerLoss & & fplayer . hasFaction ( ) & & fplayer . getFaction ( ) . isPeaceful ( ) )
{
2011-10-21 18:14:04 +02:00
fplayer . msg ( " <i>You didn't lose any power since you are in a peaceful faction. " ) ;
2011-08-05 10:50:47 +02:00
return ;
2011-05-29 23:28:29 +02:00
}
2011-03-23 17:39:56 +01:00
fplayer . onDeath ( ) ;
2011-10-21 18:14:04 +02:00
fplayer . msg ( " <i>Your power is now <h> " + fplayer . getPowerRounded ( ) + " / " + fplayer . getPowerMaxRounded ( ) ) ;
2011-02-06 13:36:11 +01:00
}
2011-02-13 17:04:06 +01:00
2011-02-06 13:36:11 +01:00
/ * *
* Who can I hurt ?
* I can never hurt members or allies .
* I can always hurt enemies .
* I can hurt neutrals as long as they are outside their own territory .
* /
@Override
2011-10-21 18:14:04 +02:00
public void onEntityDamage ( EntityDamageEvent event )
{
if ( event . isCancelled ( ) ) return ;
2011-02-06 13:36:11 +01:00
2011-10-21 18:14:04 +02:00
if ( event instanceof EntityDamageByEntityEvent )
{
2011-07-29 13:39:20 +02:00
EntityDamageByEntityEvent sub = ( EntityDamageByEntityEvent ) event ;
2011-10-21 18:14:04 +02:00
if ( ! this . canDamagerHurtDamagee ( sub ) )
{
2011-02-13 17:04:06 +01:00
event . setCancelled ( true ) ;
}
2011-10-21 18:14:04 +02:00
}
else if ( Conf . safeZonePreventAllDamageToPlayers & & isPlayerInSafeZone ( event . getEntity ( ) ) )
{
2011-07-29 13:39:20 +02:00
// Players can not take any damage in a Safe Zone
event . setCancelled ( true ) ;
}
2011-02-13 09:33:42 +01:00
}
2011-03-22 17:20:21 +01:00
2011-03-06 21:13:48 +01:00
@Override
public void onEntityExplode ( EntityExplodeEvent event )
{
2011-10-08 22:03:44 +02:00
if ( event . isCancelled ( ) ) return ;
2011-03-22 17:20:21 +01:00
2011-08-23 07:37:31 +02:00
Location loc = event . getLocation ( ) ;
Faction faction = Board . getFactionAt ( new FLocation ( loc ) ) ;
2011-10-13 05:31:18 +02:00
2011-10-08 22:03:44 +02:00
if ( faction . noExplosionsInTerritory ( ) )
{
2011-08-05 10:50:47 +02:00
// faction is peaceful and has explosions set to disabled
event . setCancelled ( true ) ;
2011-10-13 05:31:18 +02:00
return ;
2011-08-05 10:50:47 +02:00
}
2011-10-13 05:31:18 +02:00
boolean online = faction . hasPlayersOnline ( ) ;
if
2011-10-08 22:03:44 +02:00
(
event . getEntity ( ) instanceof Creeper
& &
(
( faction . isNone ( ) & & Conf . wildernessBlockCreepers & & ! Conf . worldsNoWildernessProtection . contains ( loc . getWorld ( ) . getName ( ) ) )
| |
( faction . isNormal ( ) & & ( online ? Conf . territoryBlockCreepers : Conf . territoryBlockCreepersWhenOffline ) )
| |
( faction . isWarZone ( ) & & Conf . warZoneBlockCreepers )
| |
2011-05-29 23:28:29 +02:00
faction . isSafeZone ( )
2011-10-08 22:03:44 +02:00
)
)
{
2011-05-29 23:28:29 +02:00
// creeper which needs prevention
2011-03-22 17:20:21 +01:00
event . setCancelled ( true ) ;
2011-10-08 22:03:44 +02:00
}
else if
(
event . getEntity ( ) instanceof Fireball
& &
(
( faction . isNone ( ) & & Conf . wildernessBlockFireballs & & ! Conf . worldsNoWildernessProtection . contains ( loc . getWorld ( ) . getName ( ) ) )
| |
( faction . isNormal ( ) & & ( online ? Conf . territoryBlockFireballs : Conf . territoryBlockFireballsWhenOffline ) )
| |
( faction . isWarZone ( ) & & Conf . warZoneBlockFireballs )
| |
2011-05-29 23:28:29 +02:00
faction . isSafeZone ( )
2011-10-08 22:03:44 +02:00
)
)
{
2011-05-29 23:28:29 +02:00
// ghast fireball which needs prevention
2011-03-22 17:20:21 +01:00
event . setCancelled ( true ) ;
2011-10-08 22:03:44 +02:00
}
else if
(
(
faction . isNone ( )
& &
Conf . wildernessBlockTNT
& &
! Conf . worldsNoWildernessProtection . contains ( loc . getWorld ( ) . getName ( ) )
)
| |
(
faction . isNormal ( )
& &
(
online ? Conf . territoryBlockTNT : Conf . territoryBlockTNTWhenOffline
)
)
| |
(
faction . isWarZone ( )
& &
Conf . warZoneBlockTNT
)
| |
(
faction . isSafeZone ( )
& &
Conf . safeZoneBlockTNT
)
)
{
2011-05-29 23:28:29 +02:00
// we'll assume it's TNT, which needs prevention
New boolean config options territoryBlockTNT (default false), safeZoneDenyBuild (default true), safeZoneDenyUseage (default true), safeZoneBlockTNT (default true). territoryBlockTNT prevents TNT explosions inside faction territory, which defaults to false (same as before). It prevents TNT cannons from being a viable tactic, and I think for most people it would be an undesirable option. safeZoneBlockTNT prevents TNT explosions inside safe zone areas, which defaults to true (new behavior). I think most server operators would prefer safe zones to be safe from TNT, from TNT cannons or otherwise. safeZoneDenyBuild prevents players from building inside safe zone areas, which defaults to true (same as before). This option is added for server admins who, for whatever reason, want to let their players build and break inside safe zone areas. safeZoneDenyUseage prevents players from using items in the territoryDenyUseageMaterials list, which defaults to true (new behavior). This will (with the default list) prevent players from dumping/using buckets inside safe zone areas.
2011-04-04 13:31:48 +02:00
event . setCancelled ( true ) ;
2011-03-18 00:02:29 +01:00
}
2011-03-06 21:13:48 +01:00
}
2011-07-29 13:39:20 +02:00
2011-10-08 22:03:44 +02:00
public boolean isPlayerInSafeZone ( Entity damagee )
{
if ( ! ( damagee instanceof Player ) )
{
2011-07-29 13:39:20 +02:00
return false ;
}
2011-10-08 22:03:44 +02:00
if ( Board . getFactionAt ( new FLocation ( damagee . getLocation ( ) ) ) . isSafeZone ( ) )
{
2011-07-29 13:39:20 +02:00
return true ;
}
return false ;
}
2011-10-08 22:03:44 +02:00
public boolean canDamagerHurtDamagee ( EntityDamageByEntityEvent sub )
{
2011-03-07 04:13:27 +01:00
Entity damager = sub . getDamager ( ) ;
Entity damagee = sub . getEntity ( ) ;
int damage = sub . getDamage ( ) ;
2011-02-06 13:36:11 +01:00
2011-10-08 22:03:44 +02:00
if ( ! ( damagee instanceof Player ) )
{
2011-02-13 09:33:42 +01:00
return true ;
}
2011-02-06 13:36:11 +01:00
2011-10-08 22:03:44 +02:00
FPlayer defender = FPlayers . i . get ( ( Player ) damagee ) ;
2011-03-23 17:39:56 +01:00
2011-10-08 22:03:44 +02:00
if ( defender = = null | | defender . getPlayer ( ) = = null )
{
2011-05-12 07:52:17 +02:00
return true ;
}
2011-08-02 03:22:16 +02:00
Location defenderLoc = defender . getPlayer ( ) . getLocation ( ) ;
2011-10-08 22:03:44 +02:00
if ( Conf . worldsIgnorePvP . contains ( defenderLoc . getWorld ( ) . getName ( ) ) )
{
2011-08-02 03:22:16 +02:00
return true ;
}
2011-08-05 10:50:47 +02:00
Faction defLocFaction = Board . getFactionAt ( new FLocation ( defenderLoc ) ) ;
2011-09-08 10:20:55 +02:00
// for damage caused by projectiles, getDamager() returns the projectile... what we need to know is the source
2011-10-08 22:03:44 +02:00
if ( damager instanceof Projectile )
{
2011-09-08 10:20:55 +02:00
damager = ( ( Projectile ) damager ) . getShooter ( ) ;
}
2011-08-05 10:50:47 +02:00
// Players can not take attack damage in a SafeZone, or possibly peaceful territory
if ( defLocFaction . noPvPInTerritory ( ) ) {
2011-10-08 22:03:44 +02:00
if ( damager instanceof Player )
{
FPlayer attacker = FPlayers . i . get ( ( Player ) damager ) ;
2011-10-21 18:14:04 +02:00
attacker . msg ( " <i>You can't hurt other players in " + ( defLocFaction . isSafeZone ( ) ? " a SafeZone. " : " peaceful territory. " ) ) ;
2011-08-05 10:50:47 +02:00
return false ;
2011-03-23 17:39:56 +01:00
}
2011-08-05 10:50:47 +02:00
return ! defLocFaction . noMonstersInTerritory ( ) ;
2011-03-23 17:39:56 +01:00
}
2011-10-08 22:03:44 +02:00
if ( ! ( damager instanceof Player ) )
{
2011-03-23 17:39:56 +01:00
return true ;
}
2011-10-08 22:03:44 +02:00
FPlayer attacker = FPlayers . i . get ( ( Player ) damager ) ;
2011-05-12 07:52:17 +02:00
2011-10-08 22:03:44 +02:00
if ( attacker = = null | | attacker . getPlayer ( ) = = null )
{
2011-05-12 07:52:17 +02:00
return true ;
}
2011-10-08 22:03:44 +02:00
if ( attacker . hasLoginPvpDisabled ( ) )
{
2011-10-21 18:14:04 +02:00
attacker . msg ( " <i>You can't hurt other players for " + Conf . noPVPDamageToOthersForXSecondsAfterLogin + " seconds after logging in. " ) ;
2011-06-23 03:10:42 +02:00
return false ;
}
2011-06-10 14:38:14 +02:00
Faction locFaction = Board . getFactionAt ( new FLocation ( attacker ) ) ;
2011-06-08 23:22:19 +02:00
// so we know from above that the defender isn't in a safezone... what about the attacker, sneaky dog that he might be?
2011-10-08 22:03:44 +02:00
if ( locFaction . noPvPInTerritory ( ) )
{
2011-10-21 18:14:04 +02:00
attacker . msg ( " <i>You can't hurt other players while you are in " + ( locFaction . isSafeZone ( ) ? " a SafeZone. " : " peaceful territory. " ) ) ;
2011-06-08 23:22:19 +02:00
return false ;
}
2011-10-08 22:03:44 +02:00
else if ( locFaction . isWarZone ( ) & & Conf . warZoneFriendlyFire )
{
2011-06-10 14:38:14 +02:00
return true ;
}
2011-06-08 23:22:19 +02:00
2011-09-16 08:45:23 +02:00
Faction defendFaction = defender . getFaction ( ) ;
Faction attackFaction = attacker . getFaction ( ) ;
2011-10-08 22:03:44 +02:00
if ( attackFaction . isNone ( ) & & Conf . disablePVPForFactionlessPlayers )
{
2011-10-21 18:14:04 +02:00
attacker . msg ( " <i>You can't hurt other players until you join a faction. " ) ;
2011-08-02 01:28:34 +02:00
return false ;
}
2011-10-08 22:03:44 +02:00
else if ( defendFaction . isNone ( ) )
{
if ( defLocFaction = = attackFaction & & Conf . enablePVPAgainstFactionlessInAttackersLand )
{
2011-09-16 08:45:23 +02:00
// Allow PVP vs. Factionless in attacker's faction territory
return true ;
}
2011-10-08 22:03:44 +02:00
else if ( Conf . disablePVPForFactionlessPlayers )
{
2011-10-21 18:14:04 +02:00
attacker . msg ( " <i>You can't hurt players who are not currently in a faction. " ) ;
2011-09-16 08:45:23 +02:00
return false ;
}
2011-08-02 01:28:34 +02:00
}
2011-10-08 22:03:44 +02:00
if ( defendFaction . isPeaceful ( ) )
{
2011-10-21 18:14:04 +02:00
attacker . msg ( " <i>You can't hurt players who are in a peaceful faction. " ) ;
2011-08-05 10:50:47 +02:00
return false ;
}
2011-10-08 22:03:44 +02:00
else if ( attackFaction . isPeaceful ( ) )
{
2011-10-21 18:14:04 +02:00
attacker . msg ( " <i>You can't hurt players while you are in a peaceful faction. " ) ;
2011-08-05 10:50:47 +02:00
return false ;
}
2011-10-12 17:25:01 +02:00
Relation relation = defendFaction . getRelationTo ( attackFaction ) ;
2011-02-06 13:36:11 +01:00
2011-07-28 16:04:11 +02:00
// You can not hurt neutral factions
2011-10-08 22:03:44 +02:00
if ( Conf . disablePVPBetweenNeutralFactions & & relation . isNeutral ( ) )
{
2011-10-21 18:14:04 +02:00
attacker . msg ( " <i>You can't hurt neutral factions. Declare them as an enemy. " ) ;
2011-07-29 12:12:14 +02:00
return false ;
2011-07-28 16:04:11 +02:00
}
2011-02-06 13:36:11 +01:00
// Players without faction may be hurt anywhere
2011-10-08 22:03:44 +02:00
if ( ! defender . hasFaction ( ) )
{
2011-02-13 09:33:42 +01:00
return true ;
2011-02-06 13:36:11 +01:00
}
// You can never hurt faction members or allies
2011-10-08 22:03:44 +02:00
if ( relation . isMember ( ) | | relation . isAlly ( ) )
{
2011-10-21 18:14:04 +02:00
attacker . msg ( " <i>You can't hurt " + defender . getNameAndRelevant ( attacker ) ) ;
2011-02-13 09:33:42 +01:00
return false ;
2011-02-06 13:36:11 +01:00
}
2011-08-05 10:50:47 +02:00
boolean ownTerritory = defender . isInOwnTerritory ( ) ;
2011-02-06 13:36:11 +01:00
// You can not hurt neutrals in their own territory.
2011-10-08 22:03:44 +02:00
if ( ownTerritory & & relation . isNeutral ( ) )
{
2011-10-21 18:14:04 +02:00
attacker . msg ( " <i>You can't hurt " + relation . getColor ( ) + defender . getNameAndRelevant ( attacker ) + " <i> in their own territory unless you declare them as an enemy. " ) ;
defender . msg ( attacker . getNameAndRelevant ( defender ) + " <i> tried to hurt you. " ) ;
2011-02-13 09:33:42 +01:00
return false ;
2011-02-06 13:36:11 +01:00
}
// Damage will be dealt. However check if the damage should be reduced.
2011-10-08 22:03:44 +02:00
if ( ownTerritory & & Conf . territoryShieldFactor > 0 )
{
2011-03-23 17:39:56 +01:00
int newDamage = ( int ) Math . ceil ( damage * ( 1D - Conf . territoryShieldFactor ) ) ;
2011-03-07 04:13:27 +01:00
sub . setDamage ( newDamage ) ;
2011-02-06 13:36:11 +01:00
// Send message
2011-03-23 17:39:56 +01:00
String perc = MessageFormat . format ( " {0,number,#%} " , ( Conf . territoryShieldFactor ) ) ; // TODO does this display correctly??
2011-10-21 18:14:04 +02:00
defender . msg ( " <i>Enemy damage reduced by " + ChatColor . RED + perc + " <i>. " ) ;
2011-02-06 13:36:11 +01:00
}
2011-02-13 09:33:42 +01:00
return true ;
2011-02-06 13:36:11 +01:00
}
2011-03-23 17:39:56 +01:00
2011-08-02 03:22:16 +02:00
@Override
2011-10-08 22:03:44 +02:00
public void onCreatureSpawn ( CreatureSpawnEvent event )
{
if ( event . isCancelled ( ) | | event . getLocation ( ) = = null )
{
2011-03-23 17:39:56 +01:00
return ;
}
2011-10-08 22:03:44 +02:00
if ( Conf . safeZoneNerfedCreatureTypes . contains ( event . getCreatureType ( ) ) & & Board . getFactionAt ( new FLocation ( event . getLocation ( ) ) ) . noMonstersInTerritory ( ) )
{
2011-03-23 17:39:56 +01:00
event . setCancelled ( true ) ;
}
}
@Override
2011-10-08 22:03:44 +02:00
public void onEntityTarget ( EntityTargetEvent event )
{
if ( event . isCancelled ( ) ) return ;
2011-03-23 17:39:56 +01:00
// if there is a target
Entity target = event . getTarget ( ) ;
2011-10-08 22:03:44 +02:00
if ( target = = null )
{
2011-03-23 17:39:56 +01:00
return ;
}
// We are interested in blocking targeting for certain mobs:
2011-10-08 22:03:44 +02:00
if ( ! Conf . safeZoneNerfedCreatureTypes . contains ( MiscUtil . creatureTypeFromEntity ( event . getEntity ( ) ) ) )
{
2011-03-23 17:39:56 +01:00
return ;
}
// in case the target is in a safe zone.
2011-10-08 22:03:44 +02:00
if ( Board . getFactionAt ( new FLocation ( target . getLocation ( ) ) ) . noMonstersInTerritory ( ) )
{
2011-03-23 17:39:56 +01:00
event . setCancelled ( true ) ;
}
}
2011-04-28 22:45:43 +02:00
@Override
public void onPaintingBreak ( PaintingBreakEvent event )
{
2011-10-08 22:03:44 +02:00
if ( event . isCancelled ( ) ) return ;
if ( ! ( event instanceof PaintingBreakByEntityEvent ) )
{
2011-04-28 22:45:43 +02:00
return ;
}
Entity breaker = ( ( PaintingBreakByEntityEvent ) event ) . getRemover ( ) ;
2011-10-08 22:03:44 +02:00
if ( ! ( breaker instanceof Player ) )
{
2011-04-28 22:45:43 +02:00
return ;
}
2011-10-13 05:31:18 +02:00
if ( ! FactionsBlockListener . playerCanBuildDestroyBlock ( ( Player ) breaker , event . getPainting ( ) . getLocation ( ) , " remove paintings " , false ) )
2011-10-08 22:03:44 +02:00
{
2011-04-28 22:45:43 +02:00
event . setCancelled ( true ) ;
}
}
@Override
public void onPaintingPlace ( PaintingPlaceEvent event )
{
2011-10-08 22:03:44 +02:00
if ( event . isCancelled ( ) ) return ;
2011-04-28 22:45:43 +02:00
2011-10-13 05:31:18 +02:00
if ( ! FactionsBlockListener . playerCanBuildDestroyBlock ( event . getPlayer ( ) , event . getBlock ( ) . getLocation ( ) , " place paintings " , false ) )
2011-10-08 22:03:44 +02:00
{
2011-04-28 22:45:43 +02:00
event . setCancelled ( true ) ;
}
}
2011-09-22 13:22:01 +02:00
@Override
2011-10-08 22:03:44 +02:00
public void onEndermanPickup ( EndermanPickupEvent event )
{
if ( event . isCancelled ( ) ) return ;
2011-09-22 13:22:01 +02:00
2011-10-08 22:03:44 +02:00
if ( stopEndermanBlockManipulation ( event . getBlock ( ) . getLocation ( ) ) )
{
2011-09-22 13:22:01 +02:00
event . setCancelled ( true ) ;
}
}
@Override
2011-10-08 22:03:44 +02:00
public void onEndermanPlace ( EndermanPlaceEvent event )
{
if ( event . isCancelled ( ) ) return ;
2011-09-22 13:22:01 +02:00
2011-10-08 22:03:44 +02:00
if ( stopEndermanBlockManipulation ( event . getLocation ( ) ) )
{
2011-09-22 13:22:01 +02:00
event . setCancelled ( true ) ;
}
}
2011-10-08 22:03:44 +02:00
private boolean stopEndermanBlockManipulation ( Location loc )
{
if ( loc = = null )
{
2011-09-22 13:22:01 +02:00
return false ;
}
// quick check to see if all Enderman deny options are enabled; if so, no need to check location
2011-10-08 22:03:44 +02:00
if
(
Conf . wildernessDenyEndermanBlocks
& &
Conf . territoryDenyEndermanBlocks
& &
Conf . territoryDenyEndermanBlocksWhenOffline
& &
Conf . safeZoneDenyEndermanBlocks
& &
Conf . warZoneDenyEndermanBlocks
)
{
2011-09-22 13:22:01 +02:00
return true ;
}
FLocation fLoc = new FLocation ( loc ) ;
Faction claimFaction = Board . getFactionAt ( fLoc ) ;
2011-10-08 22:03:44 +02:00
if ( claimFaction . isNone ( ) )
{
2011-09-22 13:22:01 +02:00
return Conf . wildernessDenyEndermanBlocks ;
}
2011-10-08 22:03:44 +02:00
else if ( claimFaction . isNormal ( ) )
{
2011-10-01 13:16:53 +02:00
return claimFaction . hasPlayersOnline ( ) ? Conf . territoryDenyEndermanBlocks : Conf . territoryDenyEndermanBlocksWhenOffline ;
2011-09-22 13:22:01 +02:00
}
2011-10-08 22:03:44 +02:00
else if ( claimFaction . isSafeZone ( ) )
{
2011-09-22 13:22:01 +02:00
return Conf . safeZoneDenyEndermanBlocks ;
}
2011-10-08 22:03:44 +02:00
else if ( claimFaction . isWarZone ( ) )
{
2011-09-22 13:22:01 +02:00
return Conf . warZoneDenyEndermanBlocks ;
}
return false ;
}
2011-02-06 13:36:11 +01:00
}