Improved attacker and defender's party check

This commit is contained in:
bm01 2012-05-08 19:39:12 +02:00
parent 946ea19371
commit 9b3838b912
2 changed files with 17 additions and 16 deletions

View File

@ -1,11 +1,14 @@
package com.gmail.nossr50.listeners;
import org.bukkit.Material;
import org.bukkit.entity.AnimalTamer;
import org.bukkit.entity.Entity;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
import org.bukkit.entity.Projectile;
import org.bukkit.entity.TNTPrimed;
import org.bukkit.entity.Tameable;
import org.bukkit.entity.Wolf;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
@ -58,14 +61,22 @@ public class EntityListener implements Listener {
return;
}
Entity defender = event.getEntity();
Entity attacker = event.getDamager();
if (attacker instanceof Player && defender instanceof Player) {
if (!defender.getWorld().getPVP()) {
return;
}
if (attacker instanceof Projectile) {
attacker = ((Projectile) attacker).getShooter();
}
else if (attacker instanceof Tameable) {
AnimalTamer animalTamer = ((Tameable) attacker).getOwner();
if (animalTamer instanceof Player) {
attacker = (Player) animalTamer;
}
}
Entity defender = event.getEntity();
if (attacker instanceof Player && defender instanceof Player) {
if (Party.getInstance().inSameParty((Player)defender, (Player)attacker)) {
event.setCancelled(true);
return;

View File

@ -268,9 +268,7 @@ public class Combat {
int damage = event.getDamage();
if (permInstance.archery(attacker) && damage > 0) {
if (permInstance.archeryBonus(attacker)) {
/*Archery needs a damage bonus to be viable in PVP*/
int skillLvl = Users.getProfile(attacker).getSkillLevel(SkillType.ARCHERY);
double dmgBonusPercent = ((skillLvl / 50) * 0.1D);
@ -293,16 +291,8 @@ public class Combat {
startGainXp(attacker, PPa, target, SkillType.ARCHERY, pluginx);
if (target instanceof Player) {
Player defender = (Player) target;
PlayerProfile PPd = Users.getProfile(defender);
if (PPa.inParty() && PPd.inParty() && Party.getInstance().inSameParty(defender, attacker)) {
event.setCancelled(true);
return;
}
if (permInstance.daze(attacker)) {
Archery.dazeCheck(defender, attacker);
Archery.dazeCheck((Player) target, attacker);
}
}
}