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;
|
2012-02-02 22:13:53 +01:00
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.logging.Level;
|
2011-02-06 13:36:11 +01:00
|
|
|
|
2011-08-02 03:22:16 +02:00
|
|
|
import org.bukkit.Location;
|
2012-02-02 22:13:53 +01:00
|
|
|
import org.bukkit.Material;
|
2011-03-22 17:20:21 +01:00
|
|
|
import org.bukkit.entity.Creeper;
|
2012-02-20 23:59:18 +01:00
|
|
|
import org.bukkit.entity.Enderman;
|
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;
|
2012-02-02 22:13:53 +01:00
|
|
|
import org.bukkit.entity.TNTPrimed;
|
2012-01-28 11:37:55 +01:00
|
|
|
import org.bukkit.event.EventHandler;
|
|
|
|
import org.bukkit.event.EventPriority;
|
|
|
|
import org.bukkit.event.Listener;
|
2011-03-23 17:39:56 +01:00
|
|
|
import org.bukkit.event.entity.CreatureSpawnEvent;
|
2012-02-20 23:59:18 +01:00
|
|
|
import org.bukkit.event.entity.EntityChangeBlockEvent;
|
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-03-23 17:39:56 +01:00
|
|
|
import org.bukkit.event.entity.EntityTargetEvent;
|
2012-02-02 22:13:53 +01:00
|
|
|
import org.bukkit.event.entity.ExplosionPrimeEvent;
|
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
|
|
|
|
|
|
|
|
2012-01-28 11:37:55 +01:00
|
|
|
public class FactionsEntityListener implements Listener
|
2011-10-08 22:03:44 +02:00
|
|
|
{
|
|
|
|
public P p;
|
|
|
|
public FactionsEntityListener(P p)
|
|
|
|
{
|
|
|
|
this.p = p;
|
|
|
|
}
|
2012-01-15 18:41:13 +01:00
|
|
|
|
2012-01-28 11:37:55 +01:00
|
|
|
@EventHandler(priority = EventPriority.NORMAL)
|
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.
|
|
|
|
*/
|
2012-01-28 11:37:55 +01:00
|
|
|
@EventHandler(priority = EventPriority.NORMAL)
|
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
|
|
|
}
|
2012-01-17 08:57:25 +01:00
|
|
|
|
2012-01-28 11:37:55 +01:00
|
|
|
@EventHandler(priority = EventPriority.NORMAL)
|
2011-03-06 21:13:48 +01:00
|
|
|
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
|
|
|
}
|
2012-01-17 08:57:25 +01:00
|
|
|
else if
|
|
|
|
(
|
2011-10-08 22:03:44 +02:00
|
|
|
(
|
2012-01-17 08:57:25 +01:00
|
|
|
faction.isNone()
|
|
|
|
&&
|
|
|
|
Conf.wildernessBlockTNT
|
|
|
|
&&
|
|
|
|
! Conf.worldsNoWildernessProtection.contains(loc.getWorld().getName())
|
|
|
|
)
|
|
|
|
||
|
|
|
|
(
|
|
|
|
faction.isNormal()
|
|
|
|
&&
|
2011-10-08 22:03:44 +02:00
|
|
|
(
|
2012-01-17 08:57:25 +01:00
|
|
|
online ? Conf.territoryBlockTNT : Conf.territoryBlockTNTWhenOffline
|
2011-10-08 22:03:44 +02:00
|
|
|
)
|
|
|
|
)
|
2012-01-17 08:57:25 +01:00
|
|
|
||
|
|
|
|
(
|
|
|
|
faction.isWarZone()
|
|
|
|
&&
|
|
|
|
Conf.warZoneBlockTNT
|
|
|
|
)
|
|
|
|
||
|
|
|
|
(
|
|
|
|
faction.isSafeZone()
|
|
|
|
&&
|
|
|
|
Conf.safeZoneBlockTNT
|
|
|
|
)
|
|
|
|
)
|
|
|
|
{
|
|
|
|
// we'll assume it's TNT, which needs prevention
|
|
|
|
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;
|
2012-01-17 09:56:22 +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-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();
|
2012-01-17 09:56:22 +01:00
|
|
|
|
|
|
|
if (damager == damagee) // ender pearl usage and other self-inflicted damage
|
|
|
|
return true;
|
2011-09-08 10:20:55 +02:00
|
|
|
|
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;
|
|
|
|
}
|
2012-02-07 22:04:20 +01:00
|
|
|
|
|
|
|
if (locFaction.isWarZone() && Conf.warZoneFriendlyFire)
|
2011-06-10 14:38:14 +02:00
|
|
|
return true;
|
2012-02-07 22:04:20 +01:00
|
|
|
|
|
|
|
if (Conf.worldsIgnorePvP.contains(defenderLoc.getWorld().getName()))
|
|
|
|
return true;
|
|
|
|
|
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 19:20:33 +02:00
|
|
|
attacker.msg("<i>You can't hurt %s<i>.", defender.describeTo(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 19:20:33 +02:00
|
|
|
attacker.msg("<i>You can't hurt %s<i> in their own territory unless you declare them as an enemy.", defender.describeTo(attacker));
|
|
|
|
defender.msg("%s<i> tried to hurt you.", attacker.describeTo(defender, true));
|
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-23 02:43:25 +02:00
|
|
|
defender.msg("<i>Enemy damage reduced by <rose>%s<i>.", perc);
|
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
|
|
|
|
2012-01-28 11:37:55 +01:00
|
|
|
@EventHandler(priority = EventPriority.NORMAL)
|
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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-01-28 11:37:55 +01:00
|
|
|
@EventHandler(priority = EventPriority.NORMAL)
|
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
|
|
|
|
2012-01-28 11:37:55 +01:00
|
|
|
@EventHandler(priority = EventPriority.NORMAL)
|
2011-04-28 22:45:43 +02:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-01-28 11:37:55 +01:00
|
|
|
@EventHandler(priority = EventPriority.NORMAL)
|
2011-04-28 22:45:43 +02:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-01-28 11:37:55 +01:00
|
|
|
@EventHandler(priority = EventPriority.NORMAL)
|
2012-02-20 23:59:18 +01:00
|
|
|
public void onEntityChangeBlock(EntityChangeBlockEvent event)
|
2011-10-08 22:03:44 +02:00
|
|
|
{
|
|
|
|
if (event.isCancelled()) return;
|
2011-09-22 13:22:01 +02:00
|
|
|
|
2012-02-20 23:59:18 +01:00
|
|
|
// for now, only interested in Enderman tomfoolery
|
|
|
|
if (!(event.getEntity() instanceof Enderman)) return;
|
2011-09-22 13:22:01 +02:00
|
|
|
|
2012-02-20 23:59:18 +01:00
|
|
|
if (stopEndermanBlockManipulation(event.getBlock().getLocation()))
|
2011-10-08 22:03:44 +02:00
|
|
|
{
|
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;
|
|
|
|
}
|
2012-02-02 22:13:53 +01:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Canceled redstone torch placement next to existing TNT is still triggering an explosion, thus, our workaround here.
|
|
|
|
* related to this:
|
|
|
|
* https://bukkit.atlassian.net/browse/BUKKIT-89
|
|
|
|
* though they do finally appear to have fixed the converse situation (existing redstone torch, TNT placement attempted but canceled)
|
|
|
|
*/
|
|
|
|
private static ArrayList<PotentialExplosionExploit> exploitExplosions = new ArrayList<PotentialExplosionExploit>();
|
|
|
|
|
|
|
|
@EventHandler(priority = EventPriority.NORMAL)
|
|
|
|
public void onExplosionPrime(ExplosionPrimeEvent event)
|
|
|
|
{
|
|
|
|
if (event.isCancelled()) return;
|
|
|
|
if (! (event.getEntity() instanceof TNTPrimed)) return;
|
|
|
|
if (exploitExplosions.isEmpty()) return;
|
|
|
|
|
|
|
|
// make sure this isn't a TNT explosion exploit attempt
|
|
|
|
|
|
|
|
int locX = event.getEntity().getLocation().getBlockX();
|
|
|
|
int locZ = event.getEntity().getLocation().getBlockZ();
|
|
|
|
|
|
|
|
for (int i = exploitExplosions.size() - 1; i >= 0; i--)
|
|
|
|
{
|
|
|
|
PotentialExplosionExploit ex = exploitExplosions.get(i);
|
|
|
|
|
|
|
|
// remove anything from the list older than 8 seconds
|
|
|
|
if (ex.timeMillis + 8000 < System.currentTimeMillis())
|
|
|
|
{
|
|
|
|
exploitExplosions.remove(i);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
int absX = Math.abs(ex.X - locX);
|
|
|
|
int absZ = Math.abs(ex.Z - locZ);
|
|
|
|
if (absX < 5 && absZ < 5)
|
|
|
|
{ // it sure looks like an exploit attempt
|
|
|
|
// let's tattle on him to everyone
|
2012-02-04 23:22:55 +01:00
|
|
|
String msg = "NOTICE: Player \""+ex.playerName+"\" attempted to exploit a TNT bug in the territory of \""+ex.faction.getTag()+"\"";
|
|
|
|
P.p.log(Level.WARNING, msg + " at "+ex.X+","+ex.Z+" (X,Z) using a "+ex.item.name());
|
2012-02-02 22:13:53 +01:00
|
|
|
for (FPlayer fplayer : FPlayers.i.getOnline())
|
|
|
|
{
|
2012-02-04 23:22:55 +01:00
|
|
|
fplayer.sendMessage(msg+". Coordinates logged.");
|
2012-02-02 22:13:53 +01:00
|
|
|
}
|
|
|
|
event.setCancelled(true);
|
|
|
|
exploitExplosions.remove(i);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public static void trackPotentialExplosionExploit(String playerName, Faction faction, Material item, Location location)
|
|
|
|
{
|
|
|
|
exploitExplosions.add(new PotentialExplosionExploit(playerName, faction, item, location));
|
|
|
|
}
|
|
|
|
|
|
|
|
public static class PotentialExplosionExploit
|
|
|
|
{
|
|
|
|
public String playerName;
|
|
|
|
public Faction faction;
|
|
|
|
public Material item;
|
|
|
|
public long timeMillis;
|
|
|
|
public int X;
|
|
|
|
public int Z;
|
|
|
|
|
|
|
|
public PotentialExplosionExploit(String playerName, Faction faction, Material item, Location location)
|
|
|
|
{
|
|
|
|
this.playerName = playerName;
|
|
|
|
this.faction = faction;
|
|
|
|
this.item = item;
|
|
|
|
this.timeMillis = System.currentTimeMillis();
|
|
|
|
this.X = location.getBlockX();
|
|
|
|
this.Z = location.getBlockZ();
|
|
|
|
}
|
|
|
|
}
|
2011-02-06 13:36:11 +01:00
|
|
|
}
|