diff --git a/src/main/java/world/bentobox/greenhouses/managers/RecipeManager.java b/src/main/java/world/bentobox/greenhouses/managers/RecipeManager.java index c8c2a72..2389b1b 100644 --- a/src/main/java/world/bentobox/greenhouses/managers/RecipeManager.java +++ b/src/main/java/world/bentobox/greenhouses/managers/RecipeManager.java @@ -182,7 +182,10 @@ public class RecipeManager { String[] split = conversions.split(":"); double convChance = Double.parseDouble(split[0]); Material newMaterial = Material.valueOf(split[1]); - Material localMaterial = Material.valueOf(split[2]); + Material localMaterial = null; + if(split.length > 2) { + localMaterial = Material.valueOf(split[2]); + } b.addConvBlocks(oldMaterial, newMaterial, convChance, localMaterial); } } catch (Exception e) { @@ -199,7 +202,10 @@ public class RecipeManager { Material oldMaterial = Material.valueOf(split[0].toUpperCase()); double convChance = Double.parseDouble(split[1]); Material newMaterial = Material.valueOf(split[2]); - Material localMaterial = Material.valueOf(split[3]); + Material localMaterial = null; + if(split.length > 3) { + localMaterial = Material.valueOf(split[3]); + } b.addConvBlocks(oldMaterial, newMaterial, convChance, localMaterial); } catch (Exception e) { addon.logError("Could not parse " + oldMat); diff --git a/src/test/java/world/bentobox/greenhouses/greenhouse/BiomeRecipeTest.java b/src/test/java/world/bentobox/greenhouses/greenhouse/BiomeRecipeTest.java index b58304c..e9b0fbe 100644 --- a/src/test/java/world/bentobox/greenhouses/greenhouse/BiomeRecipeTest.java +++ b/src/test/java/world/bentobox/greenhouses/greenhouse/BiomeRecipeTest.java @@ -156,7 +156,7 @@ public class BiomeRecipeTest { } /** - * Test method for {@link world.bentobox.greenhouses.greenhouse.BiomeRecipe#addMobs(org.bukkit.entity.EntityType, int, org.bukkit.Material)}. + * Test method for {@link world.bentobox.greenhouses.greenhouse.BiomeRecipe#addMobs(org.bukkit.entity.EntityType, double, org.bukkit.Material)}. */ @Test public void testAddMobs() { @@ -168,7 +168,7 @@ public class BiomeRecipeTest { } /** - * Test method for {@link world.bentobox.greenhouses.greenhouse.BiomeRecipe#addMobs(org.bukkit.entity.EntityType, int, org.bukkit.Material)}. + * Test method for {@link world.bentobox.greenhouses.greenhouse.BiomeRecipe#addMobs(org.bukkit.entity.EntityType, double, org.bukkit.Material)}. */ @Test public void testAddMobsOver100Percent() { @@ -182,7 +182,7 @@ public class BiomeRecipeTest { } /** - * Test method for {@link world.bentobox.greenhouses.greenhouse.BiomeRecipe#addMobs(org.bukkit.entity.EntityType, int, org.bukkit.Material)}. + * Test method for {@link world.bentobox.greenhouses.greenhouse.BiomeRecipe#addMobs(org.bukkit.entity.EntityType, double, org.bukkit.Material)}. */ @Test public void testAddMobsOver100PercentDouble() { @@ -195,7 +195,7 @@ public class BiomeRecipeTest { } /** - * Test method for {@link world.bentobox.greenhouses.greenhouse.BiomeRecipe#addPlants(org.bukkit.Material, int, org.bukkit.Material)}. + * Test method for {@link world.bentobox.greenhouses.greenhouse.BiomeRecipe#addPlants(org.bukkit.Material, double, org.bukkit.Material)}. */ @Test public void testAddPlants() { @@ -207,7 +207,7 @@ public class BiomeRecipeTest { } /** - * Test method for {@link world.bentobox.greenhouses.greenhouse.BiomeRecipe#addPlants(org.bukkit.Material, int, org.bukkit.Material)}. + * Test method for {@link world.bentobox.greenhouses.greenhouse.BiomeRecipe#addPlants(org.bukkit.Material, double, org.bukkit.Material)}. */ @Test public void testAddPlantsOver100Percent() { @@ -267,25 +267,6 @@ public class BiomeRecipeTest { verify(b).setType(Material.CLAY); } - /** - * Test method for {@link world.bentobox.greenhouses.greenhouse.BiomeRecipe#convertBlock(org.bukkit.block.Block)}. - */ - @Test - public void testConvertBlockNotInGreenhouse() { - // Setup - this.testAddConvBlocks(); - // Mock - Block b = mock(Block.class); - when(b.getType()).thenReturn(Material.SAND); - Block ab = mock(Block.class); - when(ab.getType()).thenReturn(Material.WATER); - when(b.getRelative(any())).thenReturn(ab); - when(ab.getLocation()).thenReturn(location); - when(gh.contains(any())).thenReturn(false); - br.convertBlock(b); - verify(b, never()).setType(any()); - } - /** * Test method for {@link world.bentobox.greenhouses.greenhouse.BiomeRecipe#convertBlock(org.bukkit.block.Block)}. */ @@ -315,6 +296,26 @@ public class BiomeRecipeTest { verify(b, never()).setType(Material.CLAY); } + /** + * Test method for {@link world.bentobox.greenhouses.greenhouse.BiomeRecipe#convertBlock(org.bukkit.block.Block)}. + */ + @Test + public void testConvertBlockNoLocalBlock() { + // Setup + Material oldMaterial = Material.SAND; + Material newMaterial = Material.CLAY; + double convChance = 100D; + br.addConvBlocks(oldMaterial, newMaterial, convChance, null); + + // Mock + Block b = mock(Block.class); + when(b.getType()).thenReturn(Material.SAND); + br.convertBlock(b); + + verify(b, never()).getRelative(any()); + verify(b).setType(Material.CLAY); + } + /** * Test method for {@link world.bentobox.greenhouses.greenhouse.BiomeRecipe#convertBlock(org.bukkit.block.Block)}. */