Permalink
Browse files

Added depth checks to Pipes.

  • Loading branch information...
me4502 committed May 15, 2017
1 parent e032371 commit 076bb19f998545caa85ccea1da24dadf12bf6314
Showing with 14 additions and 8 deletions.
  1. +14 −8 src/main/java/com/sk89q/craftbook/mechanics/pipe/Pipes.java
@@ -118,7 +118,8 @@ else if (block.getRelative(face).getType() == Material.SIGN_POST && face != Bloc
return null;
}
- private void searchNearbyPipes(Block block, Set<Vector> visitedPipes, List<ItemStack> items, Set<ItemStack> filters, Set<ItemStack> exceptions) {
+ private void searchNearbyPipes(Block block, Set<Vector> visitedPipes, List<ItemStack> items, Set<ItemStack> filters, Set<ItemStack> exceptions,
+ int depth) {
LinkedList<Block> searchQueue = new LinkedList<Block>();
//Enumerate the search queue.
@@ -192,7 +193,12 @@ else if (off.getType() == Material.THIN_GLASS || off.getType() == Material.STAIN
//Use the queue to search blocks.
for(Block bl : searchQueue) {
if (bl.getType() == Material.GLASS || bl.getType() == Material.STAINED_GLASS) {
- searchNearbyPipes(bl, visitedPipes, items, filters, exceptions);
+ try {
+ searchNearbyPipes(bl, visitedPipes, items, filters, exceptions, depth + 1);
+ } catch (StackOverflowError e) {
+ CraftBookPlugin.logger().warning("Pipes encountered a StackOverflowError at position: " + bl.getLocation().toString() + ". "
+ + "This occured at a depth of: " + depth);
+ }
} else if (bl.getType() == Material.PISTON_BASE) {
PistonBaseMaterial p = (PistonBaseMaterial) bl.getState().getData();
@@ -252,7 +258,7 @@ else if (off.getType() == Material.THIN_GLASS || off.getType() == Material.STAIN
items.addAll(newItems);
}
- if (!items.isEmpty()) searchNearbyPipes(block, visitedPipes, items, filters, exceptions);
+ if (!items.isEmpty()) searchNearbyPipes(block, visitedPipes, items, filters, exceptions, depth + 1);
} else if (bl.getType() == Material.DROPPER) {
ChangedSign sign = getSignOnPiston(bl);
@@ -288,7 +294,7 @@ else if (off.getType() == Material.THIN_GLASS || off.getType() == Material.STAIN
items.removeAll(filteredItems);
items.addAll(newItems);
- if (!items.isEmpty()) searchNearbyPipes(block, visitedPipes, items, filters, exceptions);
+ if (!items.isEmpty()) searchNearbyPipes(block, visitedPipes, items, filters, exceptions, depth + 1);
}
}
}
@@ -347,7 +353,7 @@ private void startPipe(Block block, List<ItemStack> items, boolean request) {
items.addAll(event.getItems());
if(!event.isCancelled()) {
visitedPipes.add(fac.getLocation().toVector());
- searchNearbyPipes(block, visitedPipes, items, filters, exceptions);
+ searchNearbyPipes(block, visitedPipes, items, filters, exceptions, 0);
}
if (!items.isEmpty()) {
@@ -370,7 +376,7 @@ private void startPipe(Block block, List<ItemStack> items, boolean request) {
items.addAll(event.getItems());
if(!event.isCancelled()) {
visitedPipes.add(fac.getLocation().toVector());
- searchNearbyPipes(block, visitedPipes, items, filters, exceptions);
+ searchNearbyPipes(block, visitedPipes, items, filters, exceptions, 0);
}
if (!items.isEmpty()) {
@@ -396,7 +402,7 @@ private void startPipe(Block block, List<ItemStack> items, boolean request) {
if (!event.isCancelled()) {
visitedPipes.add(fac.getLocation().toVector());
- searchNearbyPipes(block, visitedPipes, items, filters, exceptions);
+ searchNearbyPipes(block, visitedPipes, items, filters, exceptions, 0);
}
if (!items.isEmpty()) {
@@ -413,7 +419,7 @@ private void startPipe(Block block, List<ItemStack> items, boolean request) {
items.addAll(event.getItems());
if(!event.isCancelled() && !items.isEmpty()) {
visitedPipes.add(fac.getLocation().toVector());
- searchNearbyPipes(block, visitedPipes, items, filters, exceptions);
+ searchNearbyPipes(block, visitedPipes, items, filters, exceptions, 0);
}
leftovers.addAll(items);
}

0 comments on commit 076bb19

Please sign in to comment.