|
7 | 7 | import org.bukkit.Location;
|
8 | 8 | import org.bukkit.Material;
|
9 | 9 | import org.bukkit.block.BlockFace;
|
10 |
| -import org.bukkit.entity.Entity; |
11 | 10 | import org.bukkit.entity.LivingEntity;
|
12 | 11 | import org.bukkit.entity.Player;
|
13 | 12 | import org.bukkit.event.EventHandler;
|
|
29 | 28 | import java.util.Optional;
|
30 | 29 | import java.util.UUID;
|
31 | 30 | import java.util.function.Function;
|
| 31 | +import java.util.stream.Collectors; |
32 | 32 |
|
33 | 33 | public class PlayerListener implements Listener {
|
34 | 34 | private final PermissionItems plugin;
|
@@ -199,26 +199,20 @@ public void onArmorEquip(BlockDispenseEvent e) {
|
199 | 199 | BlockFace facing = state.getFacing();
|
200 | 200 | Location location = e.getBlock().getRelative(facing).getLocation();
|
201 | 201 |
|
202 |
| - LivingEntity target = findDispenserTarget(location); |
| 202 | + boolean anyPrevent = findDispenserTargets(location).stream() |
| 203 | + .filter(target -> target instanceof Player) |
| 204 | + .anyMatch(target -> isPreventedFor((Player) target, e.getItem(), PreventOptions::isEquippingPrevented, "equipping")); |
203 | 205 |
|
204 |
| - if (!(target instanceof Player)) { |
205 |
| - return; |
206 |
| - } |
207 |
| - |
208 |
| - if (isPreventedFor((Player) target, e.getItem(), PreventOptions::isEquippingPrevented, "equipping")) { |
| 206 | + if (anyPrevent) { |
209 | 207 | e.setCancelled(true);
|
210 | 208 | }
|
211 | 209 | }
|
212 | 210 |
|
213 |
| - private LivingEntity findDispenserTarget(Location location) { |
214 |
| - for (Entity entity : location.getWorld().getNearbyEntities(location, 1.5, 1.5, 1.5)) { |
215 |
| - if (!(entity instanceof LivingEntity)) { |
216 |
| - continue; |
217 |
| - } |
218 |
| - |
219 |
| - return (LivingEntity) entity; |
220 |
| - } |
221 |
| - return null; |
| 211 | + private List<LivingEntity> findDispenserTargets(Location location) { |
| 212 | + return location.getWorld().getNearbyEntities(location, 1, 1, 1).stream() |
| 213 | + .filter(entity -> entity instanceof LivingEntity) |
| 214 | + .map(entity -> (LivingEntity) entity) |
| 215 | + .collect(Collectors.toList()); |
222 | 216 | }
|
223 | 217 |
|
224 | 218 | private enum ArmorType {
|
|
0 commit comments