Optimize ArrowStopper #282
@ -61,18 +61,23 @@ public class ArrowStopper {
|
|||||||
|
|
||||||
private boolean checkBlocks(Block start, Block end) {
|
private boolean checkBlocks(Block start, Block end) {
|
||||||
Block cursor = start;
|
Block cursor = start;
|
||||||
|
BlockFace from = BlockFace.SELF;
|
||||||
|
|
||||||
while (!cursor.getLocation().equals(end.getLocation())) {
|
while (!cursor.getLocation().equals(end.getLocation())) {
|
||||||
BlockFace nearest = BlockFace.SELF;
|
BlockFace nearest = BlockFace.SELF;
|
||||||
double nearestDistance = cursor.getLocation().distance(end.getLocation());
|
double nearestDistance = getSquareDistance(cursor.getLocation(), end.getLocation());
|
||||||
for (BlockFace face : BLOCK_FACES) {
|
for (BlockFace face : BLOCK_FACES) {
|
||||||
|
if(face == from) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
Block relative = cursor.getRelative(face);
|
Block relative = cursor.getRelative(face);
|
||||||
double distance = relative.getLocation().distance(end.getLocation());
|
double distance = getSquareDistance(relative.getLocation(), end.getLocation());
|
||||||
if(distance < nearestDistance) {
|
if(distance < nearestDistance) {
|
||||||
nearestDistance = distance;
|
nearestDistance = distance;
|
||||||
nearest = face;
|
nearest = face;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
from = nearest;
|
||||||
cursor = cursor.getRelative(nearest);
|
cursor = cursor.getRelative(nearest);
|
||||||
if(checkBlock(cursor))
|
if(checkBlock(cursor))
|
||||||
return true;
|
return true;
|
||||||
@ -81,6 +86,10 @@ public class ArrowStopper {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private double getSquareDistance(Location loc1, Location loc2) {
|
||||||
Chaoscaot markierte diese Unterhaltung als gelöst
Veraltet
|
|||||||
|
return loc1.getX() * loc2.getX() + loc1.getY() * loc2.getY() + loc1.getZ() * loc2.getZ();
|
||||||
|
}
|
||||||
|
|
||||||
private boolean checkBlock(Block block) {
|
private boolean checkBlock(Block block) {
|
||||||
return Config.HiddenBlocks.contains(block.getType().name().toLowerCase());
|
return Config.HiddenBlocks.contains(block.getType().name().toLowerCase());
|
||||||
}
|
}
|
||||||
|
In neuem Issue referenzieren
Einen Benutzer sperren
Location#distanceSquared(Location)