You can no longer set fire to party members

This commit is contained in:
nossr50 2019-06-18 14:04:42 -07:00
parent c83d38b5c2
commit fa6995b9fd
2 changed files with 107 additions and 76 deletions

View File

@ -1,6 +1,8 @@
Version 2.1.83 Version 2.1.83
Updated hu_HU locale (thanks andris155) Updated hu_HU locale (thanks andris155)
(FIX) Arrow Retrieval will no longer work with piercing enchant on crossbows (FIX) Arrow Retrieval will no longer work with piercing enchant on crossbows
WG Flags should now correctly recognize when a projectile belongs to a player and respect flag settings
You can no longer set party members on fire with your bow
Version 2.1.82 Version 2.1.82
Added new WG flag 'mcmmo-hardcore' if set to negative players will not be penalized by hardcore mode (if hardcore mode is enabled) it defaults to true Added new WG flag 'mcmmo-hardcore' if set to negative players will not be penalized by hardcore mode (if hardcore mode is enabled) it defaults to true

View File

@ -32,9 +32,7 @@ import org.bukkit.OfflinePlayer;
import org.bukkit.block.Block; import org.bukkit.block.Block;
import org.bukkit.enchantments.Enchantment; import org.bukkit.enchantments.Enchantment;
import org.bukkit.entity.*; import org.bukkit.entity.*;
import org.bukkit.event.EventHandler; import org.bukkit.event.*;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.entity.*; import org.bukkit.event.entity.*;
import org.bukkit.event.entity.EntityDamageEvent.DamageCause; import org.bukkit.event.entity.EntityDamageEvent.DamageCause;
import org.bukkit.event.entity.EntityDamageEvent.DamageModifier; import org.bukkit.event.entity.EntityDamageEvent.DamageModifier;
@ -275,6 +273,27 @@ public class EntityListener implements Listener {
} }
} }
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void onEntityCombustByEntityEvent(EntityCombustByEntityEvent event) {
//Prevent players from setting fire to each other if they are in the same party
if(event.getEntity() instanceof Player) {
Player defender = (Player) event.getEntity();
if(event.getCombuster() instanceof Projectile) {
Projectile projectile = (Projectile) event.getCombuster();
if(projectile.getShooter() instanceof Player) {
Player attacker = (Player) projectile.getShooter();
if(checkParties(event, defender, attacker))
return;
}
} else if(event.getCombuster() instanceof Player) {
Player attacker = (Player) event.getCombuster();
if(checkParties(event, defender, attacker))
return;
}
}
}
/** /**
* Handle EntityDamageByEntity events that involve modifying the event. * Handle EntityDamageByEntity events that involve modifying the event.
* *
@ -287,6 +306,26 @@ public class EntityListener implements Listener {
Entity defender = event.getEntity(); Entity defender = event.getEntity();
Entity attacker = event.getDamager(); Entity attacker = event.getDamager();
if(WorldGuardUtils.isWorldGuardLoaded())
{
if(attacker instanceof Player) {
if(!WorldGuardManager.getInstance().hasMainFlag((Player) attacker))
return;
} else if(attacker instanceof Projectile) {
Projectile projectile = (Projectile) attacker;
if(projectile.getShooter() instanceof Player) {
if(!WorldGuardManager.getInstance().hasMainFlag((Player) projectile.getShooter()))
return;
}
}
}
/* WORLD BLACKLIST CHECK */ /* WORLD BLACKLIST CHECK */
if(WorldBlacklist.isWorldBlacklisted(event.getEntity().getWorld())) if(WorldBlacklist.isWorldBlacklisted(event.getEntity().getWorld()))
return; return;
@ -305,44 +344,6 @@ public class EntityListener implements Listener {
return; return;
} }
if(attacker instanceof Player)
{
Player player = (Player) attacker;
/* WORLD GUARD MAIN FLAG CHECK */
if(WorldGuardUtils.isWorldGuardLoaded())
{
if(!WorldGuardManager.getInstance().hasMainFlag(player))
return;
}
}
if (damage <= 0) {
if (defender instanceof Player && attacker instanceof Player) {
Player defendingPlayer = (Player) defender;
Player attackingPlayer = (Player) attacker;
if (event.getDamage(DamageModifier.ABSORPTION) > 0) {
//If friendly fire is off don't allow players to hurt one another
if(!Config.getInstance().getPartyFriendlyFire())
if ((PartyManager.inSameParty(defendingPlayer, attackingPlayer) || PartyManager.areAllies(defendingPlayer, attackingPlayer)) && !(Permissions.friendlyFire(attackingPlayer) && Permissions.friendlyFire(defendingPlayer))) {
event.setCancelled(true);
return;
}
}
}
return;
}
/*
As far as I can tell at one point we registered meta-data about custom damage and we no longer do that.
if (defender.hasMetadata(mcMMO.customDamageKey)) {
defender.removeMetadata(mcMMO.customDamageKey, plugin);
return;
}
*/
if (Misc.isNPCEntityExcludingVillagers(defender) || !defender.isValid() || !(defender instanceof LivingEntity)) { if (Misc.isNPCEntityExcludingVillagers(defender) || !defender.isValid() || !(defender instanceof LivingEntity)) {
return; return;
} }
@ -357,26 +358,7 @@ public class EntityListener implements Listener {
return; return;
} }
if (attacker instanceof Projectile) { if (attacker instanceof Tameable) {
ProjectileSource projectileSource = ((Projectile) attacker).getShooter();
if (projectileSource instanceof LivingEntity) {
attacker = (LivingEntity) projectileSource;
}
if(defender instanceof Player) {
Player playerDefender = (Player) defender;
UnarmedManager unarmedManager = UserManager.getPlayer(playerDefender).getUnarmedManager();
if (unarmedManager.canDeflect()) {
if(unarmedManager.deflectCheck()) {
event.setCancelled(true);
return;
}
}
}
}
else if (attacker instanceof Tameable) {
AnimalTamer animalTamer = ((Tameable) attacker).getOwner(); AnimalTamer animalTamer = ((Tameable) attacker).getOwner();
if (animalTamer != null && ((OfflinePlayer) animalTamer).isOnline()) { if (animalTamer != null && ((OfflinePlayer) animalTamer).isOnline()) {
@ -389,27 +371,51 @@ public class EntityListener implements Listener {
} }
} }
if (defender instanceof Player && attacker instanceof Player) { //Friendly fire checks
if (defender instanceof Player) {
Player defendingPlayer = (Player) defender; Player defendingPlayer = (Player) defender;
Player attackingPlayer = (Player) attacker; Player attackingPlayer;
if (!UserManager.hasPlayerDataKey(defendingPlayer) || !UserManager.hasPlayerDataKey(attackingPlayer)) { //If the attacker is a Player or a projectile beloning to a player
if(attacker instanceof Projectile || attacker instanceof Player) {
if(attacker instanceof Projectile) {
Projectile projectile = (Projectile) attacker;
if(((Projectile) attacker).getShooter() instanceof Player) {
attackingPlayer = (Player) projectile.getShooter();
//Check for party friendly fire and cancel the event
if (checkParties(event, defendingPlayer, attackingPlayer))
{
return; return;
} }
// We want to make sure we're not gaining XP or applying abilities
// when we hit ourselves
if (defendingPlayer.equals(attackingPlayer)) {
return;
} }
//Party Friendly Fire //Deflect checks
if(!Config.getInstance().getPartyFriendlyFire()) UnarmedManager unarmedManager = UserManager.getPlayer(defendingPlayer).getUnarmedManager();
if ((PartyManager.inSameParty(defendingPlayer, attackingPlayer) || PartyManager.areAllies(defendingPlayer, attackingPlayer)) && !(Permissions.friendlyFire(attackingPlayer) && Permissions.friendlyFire(defendingPlayer))) {
if (unarmedManager.canDeflect()) {
if(unarmedManager.deflectCheck()) {
event.setCancelled(true); event.setCancelled(true);
return; return;
} }
} }
} else {
attackingPlayer = (Player) attacker;
//Check for party friendly fire and cancel the event
if (checkParties(event, defendingPlayer, attackingPlayer))
return;
}
}
}
//Required setup for processCombatAttack
if(attacker instanceof Projectile) {
ProjectileSource shooter = ((Projectile) attacker).getShooter();
if(shooter instanceof LivingEntity) {
attacker = (LivingEntity) shooter;
}
}
CombatUtils.processCombatAttack(event, attacker, target); CombatUtils.processCombatAttack(event, attacker, target);
CombatUtils.handleHealthbars(attacker, target, event.getFinalDamage(), plugin); CombatUtils.handleHealthbars(attacker, target, event.getFinalDamage(), plugin);
@ -429,6 +435,29 @@ public class EntityListener implements Listener {
} }
public boolean checkParties(Cancellable event, Player defendingPlayer, Player attackingPlayer) {
if (!UserManager.hasPlayerDataKey(defendingPlayer) || !UserManager.hasPlayerDataKey(attackingPlayer)) {
return true;
}
// We want to make sure we're not gaining XP or applying abilities
// when we hit ourselves
if (defendingPlayer.equals(attackingPlayer)) {
return true;
}
//Party Friendly Fire
if(!Config.getInstance().getPartyFriendlyFire())
if ((PartyManager.inSameParty(defendingPlayer, attackingPlayer)
|| PartyManager.areAllies(defendingPlayer, attackingPlayer))
&& !(Permissions.friendlyFire(attackingPlayer)
&& Permissions.friendlyFire(defendingPlayer))) {
event.setCancelled(true);
return true;
}
return false;
}
/** /**
* Handle EntityDamage events that involve modifying the event. * Handle EntityDamage events that involve modifying the event.
* *