Skip to content

Commit

Permalink
Merge pull request Updated-NoCheatPlus#372 from IAISI/master
Browse files Browse the repository at this point in the history
Minor performance improvements
  • Loading branch information
Lysandr0 authored Sep 15, 2024
2 parents 38d0486 + d4181ce commit 53d14f3
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import org.bukkit.block.Container;

import fr.neatmonster.nocheatplus.utilities.map.BlockCache;
import org.bukkit.block.ShulkerBox;

public class BukkitShulkerBox implements BukkitShapeModel {

Expand All @@ -31,8 +32,8 @@ public double[] getShape(final BlockCache blockCache,
final BlockState state = block.getState();
//final BlockData blockData = state.getBlockData();

if (state instanceof Container) {
if (!((Container) state).getInventory().getViewers().isEmpty()) {
if (state instanceof ShulkerBox) {
if (!((ShulkerBox) state).getInventory().getViewers().isEmpty()) {
return new double[] {0.0, 0.0, 0.0, 1.0, 1.5, 1.0};
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -487,13 +487,18 @@ public static double axisDistance(final double pos, final double minPos, final d
return pos < minPos ? Math.abs(pos - minPos) : (pos > maxPos ? Math.abs(pos - maxPos) : 0.0);
}

public static boolean isCollidingWithEntities(final Player p, final boolean onlylivingenitites) {
if (onlylivingenitites) {
List<Entity> entities = p.getNearbyEntities(0.15, 0.2, 0.15);
entities.removeIf(e -> !(e instanceof LivingEntity));
return !entities.isEmpty();
public static boolean isCollidingWithEntities(final Player p, final boolean onlyLivingEntities) {
double xzRange = 0.15;
double yRange = onlyLivingEntities ? 0.2 : 0.15;

// Directly iterate over entities and check conditions to avoid unnecessary collection creation.
for (Entity entity : p.getWorld().getNearbyEntities(p.getLocation(), xzRange, yRange, xzRange)) {
if (!onlyLivingEntities || entity instanceof LivingEntity) {
return true; // Collision detected, return early
}
}
return !p.getNearbyEntities(0.15, 0.15, 0.15).isEmpty();

return false; // No collision detected
}

/**
Expand Down

0 comments on commit 53d14f3

Please sign in to comment.