This commit is contained in:
nossr50
2024-02-22 18:04:57 -08:00
parent 416c5383c9
commit 4d85f24d98
2 changed files with 16 additions and 13 deletions

View File

@ -9,7 +9,6 @@ import com.gmail.nossr50.events.fake.FakeEntityTameEvent;
import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.metadata.MobMetaFlagType;
import com.gmail.nossr50.metadata.MobMetadataService;
import com.gmail.nossr50.party.PartyManager;
import com.gmail.nossr50.runnables.TravelingBlockMetaCleanup;
import com.gmail.nossr50.skills.archery.Archery;
import com.gmail.nossr50.skills.mining.BlastMining;
@ -259,16 +258,16 @@ 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(mcMMO.p.getPartyConfig().isPartyEnabled() && event.getEntity() instanceof Player defender) {
if(event.getEntity() instanceof Player defender) {
if(event.getCombuster() instanceof Projectile projectile) {
if(projectile.getShooter() instanceof Player attacker) {
if(checkParties(event, defender, attacker)) {
if(checkIfInPartyOrSamePlayer(event, defender, attacker)) {
event.setCancelled(true);
}
}
} else if(event.getCombuster() instanceof Player attacker) {
if(checkParties(event, defender, attacker)) {
if(checkIfInPartyOrSamePlayer(event, defender, attacker)) {
event.setCancelled(true);
}
}
@ -364,8 +363,8 @@ public class EntityListener implements Listener {
//If the attacker is a Player or a projectile belonging to a player
if(attacker instanceof Projectile projectile) {
if(projectile.getShooter() instanceof Player attackingPlayer && !attackingPlayer.equals(defendingPlayer)) {
//Check for party friendly fire and cancel the event
if (mcMMO.p.getPartyConfig().isPartyEnabled() && checkParties(event, defendingPlayer, attackingPlayer)) {
//Check for friendly fire and cancel the event
if (checkIfInPartyOrSamePlayer(event, defendingPlayer, attackingPlayer)) {
return;
}
}
@ -383,7 +382,7 @@ public class EntityListener implements Listener {
}
}
} else if (attacker instanceof Player attackingPlayer){
if (mcMMO.p.getPartyConfig().isPartyEnabled() && checkParties(event, defendingPlayer, attackingPlayer))
if (checkIfInPartyOrSamePlayer(event, defendingPlayer, attackingPlayer))
return;
}
}
@ -482,14 +481,17 @@ public class EntityListener implements Listener {
}
}
public boolean checkParties(Cancellable event, Player defendingPlayer, Player attackingPlayer) {
if (!UserManager.hasPlayerDataKey(defendingPlayer) || !UserManager.hasPlayerDataKey(attackingPlayer)) {
public boolean checkIfInPartyOrSamePlayer(Cancellable event, Player defendingPlayer, Player attackingPlayer) {
// This check is probably necessary outside of the party system
if (defendingPlayer.equals(attackingPlayer)) {
return true;
}
// We want to make sure we're not gaining XP or applying abilities
// when we hit ourselves
if (defendingPlayer.equals(attackingPlayer)) {
if(!pluginRef.isPartySystemEnabled()) {
return false;
}
if (!UserManager.hasPlayerDataKey(defendingPlayer) || !UserManager.hasPlayerDataKey(attackingPlayer)) {
return true;
}