From 0053d89d2b80eb58d4c9f268a85ed1cb2452c64a Mon Sep 17 00:00:00 2001 From: Mike Primm Date: Sat, 11 Feb 2012 23:28:44 -0600 Subject: [PATCH] Add some extra array bounds protection --- .../org/dynmap/bukkit/NewMapChunkCache.java | 74 +++++++++++-------- 1 file changed, 43 insertions(+), 31 deletions(-) diff --git a/src/main/java/org/dynmap/bukkit/NewMapChunkCache.java b/src/main/java/org/dynmap/bukkit/NewMapChunkCache.java index 32f55493..c15b4bfb 100644 --- a/src/main/java/org/dynmap/bukkit/NewMapChunkCache.java +++ b/src/main/java/org/dynmap/bukkit/NewMapChunkCache.java @@ -160,44 +160,56 @@ public class NewMapChunkCache implements MapChunkCache { } public final BiomeMap getBiome() { - return biomemap[x - x_base][z - z_base]; + try { + return biomemap[x - x_base][z - z_base]; + } catch (Exception ex) { + return BiomeMap.NULL; + } } public final int countSmoothedSwampBiomes() { - return swampcnt[x - x_base][z - z_base]; + try { + return swampcnt[x - x_base][z - z_base]; + } catch (Exception ex) { + return 0; + } } public final int countSmoothedSwampBiomes(int sx, int sz, int scale) { - int xx = x - x_base; - int zz = z - z_base; - sx <<= 1; - sz <<= 1; - int s0 = swampcnt[xx][zz]; - int w; - int tot; - if(sx < scale) { - w = scale - sx; - tot = (w * swampcnt[xx-1][zz]) + ((scale - w) * s0); + try { + int xx = x - x_base; + int zz = z - z_base; + sx <<= 1; + sz <<= 1; + int s0 = swampcnt[xx][zz]; + int w; + int tot; + if(sx < scale) { + w = scale - sx; + tot = (w * swampcnt[xx-1][zz]) + ((scale - w) * s0); + } + else if(sx > scale) { + w = sx - scale; + tot = (w * swampcnt[xx+1][zz]) + ((scale - w) * s0); + } + else { + tot = scale * s0; + } + if(sz < scale) { + w = scale - sz; + tot += (w * swampcnt[xx][zz-1]) + ((scale - w) * s0); + } + else if(sz > scale) { + w = sz - scale; + tot += (w * swampcnt[xx][zz+1]) + ((scale - w) * s0); + } + else { + tot += scale * s0; + } + return tot; + } catch (Exception ex) { + return 0; } - else if(sx > scale) { - w = sx - scale; - tot = (w * swampcnt[xx+1][zz]) + ((scale - w) * s0); - } - else { - tot = scale * s0; - } - if(sz < scale) { - w = scale - sz; - tot += (w * swampcnt[xx][zz-1]) + ((scale - w) * s0); - } - else if(sz > scale) { - w = sz - scale; - tot += (w * swampcnt[xx][zz+1]) + ((scale - w) * s0); - } - else { - tot += scale * s0; - } - return tot; } public final double getRawBiomeTemperature() {