Arrow attacks are now included in the friendly fire filter
This commit is contained in:
parent
14ad1299b2
commit
4316469ec1
@ -1,3 +1,3 @@
|
|||||||
name: Factions
|
name: Factions
|
||||||
version: 1.0 beta3
|
version: 1.0 beta4
|
||||||
main: com.bukkit.mcteam.factions.Factions
|
main: com.bukkit.mcteam.factions.Factions
|
@ -1,7 +1,6 @@
|
|||||||
package com.bukkit.mcteam.factions;
|
package com.bukkit.mcteam.factions;
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.logging.Logger;
|
|
||||||
|
|
||||||
import org.bukkit.ChatColor;
|
import org.bukkit.ChatColor;
|
||||||
|
|
||||||
|
@ -52,9 +52,10 @@ public class Factions extends JavaPlugin {
|
|||||||
pm.registerEvent(Event.Type.PLAYER_QUIT, this.playerListener, Event.Priority.Normal, this);
|
pm.registerEvent(Event.Type.PLAYER_QUIT, this.playerListener, Event.Priority.Normal, this);
|
||||||
pm.registerEvent(Event.Type.ENTITY_DEATH, this.entityListener, Event.Priority.Normal, this);
|
pm.registerEvent(Event.Type.ENTITY_DEATH, this.entityListener, Event.Priority.Normal, this);
|
||||||
pm.registerEvent(Event.Type.ENTITY_DAMAGEDBY_ENTITY, this.entityListener, Event.Priority.Normal, this);
|
pm.registerEvent(Event.Type.ENTITY_DAMAGEDBY_ENTITY, this.entityListener, Event.Priority.Normal, this);
|
||||||
|
pm.registerEvent(Event.Type.ENTITY_DAMAGEDBY_PROJECTILE, this.entityListener, Event.Priority.Normal, this);
|
||||||
pm.registerEvent(Event.Type.BLOCK_DAMAGED, this.blockListener, Event.Priority.Normal, this);
|
pm.registerEvent(Event.Type.BLOCK_DAMAGED, this.blockListener, Event.Priority.Normal, this);
|
||||||
pm.registerEvent(Event.Type.BLOCK_PLACED, this.blockListener, Event.Priority.Normal, this);
|
pm.registerEvent(Event.Type.BLOCK_PLACED, this.blockListener, Event.Priority.Normal, this);
|
||||||
pm.registerEvent(Event.Type.BLOCK_INTERACT, this.blockListener, Event.Priority.Normal, this);
|
pm.registerEvent(Event.Type.BLOCK_INTERACT, this.blockListener, Event.Priority.Normal, this);
|
||||||
|
|
||||||
Log.info("=== INIT DONE (Took "+(System.currentTimeMillis()-timeInitStart)+"ms) ===");
|
Log.info("=== INIT DONE (Took "+(System.currentTimeMillis()-timeInitStart)+"ms) ===");
|
||||||
Log.threshold = Conf.logThreshold;
|
Log.threshold = Conf.logThreshold;
|
||||||
|
@ -42,50 +42,66 @@ public class FactionsEntityListener extends EntityListener {
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void onEntityDamageByEntity(EntityDamageByEntityEvent event) {
|
public void onEntityDamageByEntity(EntityDamageByEntityEvent event) {
|
||||||
if (event.isCancelled()) {
|
if ( event.isCancelled()) {
|
||||||
return; // Some other plugin decided. Alright then.
|
return; // Some other plugin decided. Alright then.
|
||||||
}
|
}
|
||||||
|
|
||||||
Entity entity = event.getEntity();
|
if ( ! this.canDamagerHurtDamagee(event.getDamager(), event.getEntity(), event.getDamage())) {
|
||||||
if ( ! (entity instanceof Player)) {
|
event.setCancelled(true);
|
||||||
return;
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onEntityDamageByProjectile(EntityDamageByProjectileEvent event) {
|
||||||
|
//DamageCause dc = event.getCause();
|
||||||
|
//Log.debug("dc.toString(): "+dc.toString());
|
||||||
|
//Log.debug("event.getDamager().getClass(): "+event.getDamager().getClass());
|
||||||
|
//Log.debug("event.getEntity().getClass(): "+event.getEntity().getClass());
|
||||||
|
|
||||||
|
if ( event.isCancelled()) {
|
||||||
|
return; // Some other plugin decided. Alright then.
|
||||||
}
|
}
|
||||||
|
|
||||||
Entity damager = event.getDamager();
|
if ( ! this.canDamagerHurtDamagee(event.getDamager(), event.getEntity(), event.getDamage())) {
|
||||||
|
event.setCancelled(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean canDamagerHurtDamagee(Entity damager, Entity damagee, int damage) {
|
||||||
if ( ! (damager instanceof Player)) {
|
if ( ! (damager instanceof Player)) {
|
||||||
return;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
Log.debug(((Player)entity).getName()+ " is the defender");
|
if ( ! (damagee instanceof Player)) {
|
||||||
Log.debug(((Player)damager).getName()+ " is the damager");
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
Follower defender = Follower.get((Player)entity);
|
Follower defender = Follower.get((Player)damagee);
|
||||||
Follower attacker = Follower.get((Player)damager);
|
Follower attacker = Follower.get((Player)damager);
|
||||||
Relation relation = defender.getRelation(attacker);
|
Relation relation = defender.getRelation(attacker);
|
||||||
|
|
||||||
|
Log.debug(attacker.getName() + " attacked " + defender.getName());
|
||||||
|
|
||||||
// Players without faction may be hurt anywhere
|
// Players without faction may be hurt anywhere
|
||||||
if (defender.factionId == 0) {
|
if (defender.factionId == 0) {
|
||||||
return;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// You can never hurt faction members or allies
|
// You can never hurt faction members or allies
|
||||||
if (relation == Relation.MEMBER || relation == Relation.ALLY) {
|
if (relation == Relation.MEMBER || relation == Relation.ALLY) {
|
||||||
attacker.sendMessage(Conf.colorSystem+"You can't hurt "+defender.getNameAndRelevant(attacker));
|
attacker.sendMessage(Conf.colorSystem+"You can't hurt "+defender.getNameAndRelevant(attacker));
|
||||||
event.setCancelled(true);
|
return false;
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// You can not hurt neutrals in their own territory.
|
// You can not hurt neutrals in their own territory.
|
||||||
if (relation == Relation.NEUTRAL && defender.isInOwnTerritory()) {
|
if (relation == Relation.NEUTRAL && defender.isInOwnTerritory()) {
|
||||||
attacker.sendMessage(Conf.colorSystem+"You can't hurt "+relation.getColor()+defender.getNameAndRelevant(attacker)+" in their own territory.");
|
attacker.sendMessage(Conf.colorSystem+"You can't hurt "+relation.getColor()+defender.getNameAndRelevant(attacker)+" in their own territory.");
|
||||||
defender.sendMessage(attacker.getNameAndRelevant(defender)+Conf.colorSystem+" tried to hurt you.");
|
defender.sendMessage(attacker.getNameAndRelevant(defender)+Conf.colorSystem+" tried to hurt you.");
|
||||||
event.setCancelled(true);
|
return false;
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Damage will be dealt. However check if the damage should be reduced.
|
// Damage will be dealt. However check if the damage should be reduced.
|
||||||
if (defender.isInOwnTerritory()) {
|
if (defender.isInOwnTerritory() && Conf.territoryShieldFactor > 0) {
|
||||||
int damage = event.getDamage();
|
|
||||||
int toHeal = (int)(damage * Conf.territoryShieldFactor);
|
int toHeal = (int)(damage * Conf.territoryShieldFactor);
|
||||||
defender.heal(toHeal);
|
defender.heal(toHeal);
|
||||||
|
|
||||||
@ -95,10 +111,6 @@ public class FactionsEntityListener extends EntityListener {
|
|||||||
defender.sendMessage(Conf.colorSystem+"Enemy damage reduced by "+ChatColor.RED+hearts+Conf.colorSystem+" hearts.");
|
defender.sendMessage(Conf.colorSystem+"Enemy damage reduced by "+ChatColor.RED+hearts+Conf.colorSystem+" hearts.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*@Override
|
|
||||||
public void onEntityDamageByProjectile(EntityDamageByProjectileEvent event) {
|
|
||||||
event.
|
|
||||||
}*/
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user