Skip to content

Commit

Permalink
Fixes #2
Browse files Browse the repository at this point in the history
Signed-off-by: nsgwick <[email protected]>
  • Loading branch information
nickstuaw committed Jun 12, 2022
1 parent 24b2770 commit 840dd4f
Showing 1 changed file with 23 additions and 11 deletions.
34 changes: 23 additions & 11 deletions src/main/java/com/nsgwick/personalpvp/Listeners.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,7 @@
import org.jetbrains.annotations.NotNull;
import com.nsgwick.personalpvp.config.GeneralConfig;

import java.util.Arrays;
import java.util.List;
import java.util.UUID;
import java.util.*;
import java.util.stream.Collectors;
import java.util.stream.Stream;

Expand Down Expand Up @@ -299,15 +297,12 @@ public void onSplash(final PotionSplashEvent e){
if(e.getPotion().getEffects().stream().map(PotionEffect::getType)
.noneMatch(Arrays.asList(Utils.BAD_EFFECTS)::contains)) return;
/*
Save a filtered stream of uuids of the players affected.
*/
Stream<UUID> stream = e.getAffectedEntities().stream()
.filter(livingEntity -> livingEntity instanceof Player).map(LivingEntity::getUniqueId);
/*
If the shooter has pvp disabled or none of the affected entities have it enabled,
If the shooter has pvp disabled or any of the affected entities have it disabled,
*/
if(PPVPPlugin.inst().pvp().pvpNegative((((Player) shooter).getUniqueId()))
|| stream.noneMatch(PPVPPlugin.inst().pvp()::pvpPositive)) {
|| e.getAffectedEntities().stream()
.filter(livingEntity -> livingEntity instanceof Player).map(LivingEntity::getUniqueId)
.anyMatch(PPVPPlugin.inst().pvp()::pvpNegative)) {
/*
cancel the potion splash event.
*/
Expand All @@ -319,8 +314,25 @@ public void onSplash(final PotionSplashEvent e){
/*
Send a pvp alert if necessary.
*/
TaskManager.blockedAttack(stream.toArray(UUID[]::new));
TaskManager.blockedAttack(e.getAffectedEntities().stream()
.filter(livingEntity -> livingEntity instanceof Player).map(LivingEntity::getUniqueId)
.toArray(UUID[]::new));
}
/*
Create an empty list.
*/
List<UUID> affectedUuids = new ArrayList<>();
/*
List the uuids of players with pvp disabled affected by the potion.
*/
e.getAffectedEntities().stream()
.filter(livingEntity -> livingEntity instanceof Player).map(LivingEntity::getUniqueId)
.filter(PPVPPlugin.inst().pvp()::pvpNegative)
.forEach(affectedUuids::add);
for(UUID uuid : affectedUuids) {
e.getAffectedEntities().remove(Bukkit.getPlayer(uuid));
}

}
/*
Old code which hasn't been tested properly.
Expand Down

0 comments on commit 840dd4f

Please sign in to comment.