Skip to content

Commit

Permalink
2.1.230
Browse files Browse the repository at this point in the history
  • Loading branch information
nossr50 committed Feb 23, 2024
1 parent 416c538 commit 4d85f24
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 13 deletions.
3 changes: 2 additions & 1 deletion Changelog.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
Version 2.1.230
Fixed an error that could happen when mcMMO was saving when parties were disabled by party.yml
Fixed an error that could happen when mcMMO was saving when parties were disabled by party.yml (thanks IAISI & L4BORG)
Fixed several exceptions when checking PVP damage when parties were disabled by party.yml (thanks IAISI & L4BORG)

Version 2.1.229
Added new party.yml config, which lets admins disable the party system entirely without having to use permissions
Expand Down
26 changes: 14 additions & 12 deletions src/main/java/com/gmail/nossr50/listeners/EntityListener.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
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;
Expand Down Expand Up @@ -259,16 +258,16 @@ else if (isTracked) {
@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);
}
}
Expand Down Expand Up @@ -364,8 +363,8 @@ else if (attacker instanceof TNTPrimed && defender instanceof Player) {
//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;
}
}
Expand All @@ -383,7 +382,7 @@ else if (attacker instanceof TNTPrimed && defender instanceof Player) {
}
}
} else if (attacker instanceof Player attackingPlayer){
if (mcMMO.p.getPartyConfig().isPartyEnabled() && checkParties(event, defendingPlayer, attackingPlayer))
if (checkIfInPartyOrSamePlayer(event, defendingPlayer, attackingPlayer))
return;
}
}
Expand Down Expand Up @@ -482,14 +481,17 @@ public void onEntityDamageMonitor(EntityDamageByEntityEvent entityDamageEvent) {
}
}

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;
}

Expand Down

0 comments on commit 4d85f24

Please sign in to comment.