diff --git a/src/main/java/world/bentobox/bentobox/BentoBox.java b/src/main/java/world/bentobox/bentobox/BentoBox.java index 855c56ec2..f3388e9d7 100644 --- a/src/main/java/world/bentobox/bentobox/BentoBox.java +++ b/src/main/java/world/bentobox/bentobox/BentoBox.java @@ -25,6 +25,7 @@ import world.bentobox.bentobox.listeners.DeathListener; import world.bentobox.bentobox.listeners.JoinLeaveListener; import world.bentobox.bentobox.listeners.NetherPortals; import world.bentobox.bentobox.listeners.PanelListenerManager; +import world.bentobox.bentobox.listeners.flags.NetherTreesListener; import world.bentobox.bentobox.managers.AddonsManager; import world.bentobox.bentobox.managers.CommandsManager; import world.bentobox.bentobox.managers.FlagsManager; @@ -195,7 +196,7 @@ public class BentoBox extends JavaPlugin { } /** - * Register listeners + * Registers listeners. */ private void registerListeners() { PluginManager manager = getServer().getPluginManager(); @@ -205,6 +206,8 @@ public class BentoBox extends JavaPlugin { manager.registerEvents(new PanelListenerManager(), this); // Nether portals manager.registerEvents(new NetherPortals(this), this); + // Nether trees conversion + manager.registerEvents(new NetherTreesListener(this), this); // End dragon blocking manager.registerEvents(new BlockEndDragon(this), this); // Banned visitor commands diff --git a/src/main/java/world/bentobox/bentobox/listeners/NetherPortals.java b/src/main/java/world/bentobox/bentobox/listeners/NetherPortals.java index eeeccf96f..a1da0288a 100644 --- a/src/main/java/world/bentobox/bentobox/listeners/NetherPortals.java +++ b/src/main/java/world/bentobox/bentobox/listeners/NetherPortals.java @@ -257,24 +257,4 @@ public class NetherPortals implements Listener { e.setCancelled(true); } } - - /** - * Converts trees to gravel and glowstone - * - * @param e - event - */ - @EventHandler(priority = EventPriority.LOW, ignoreCancelled = true) - public boolean onTreeGrow(StructureGrowEvent e) { - if (!plugin.getIWM().isNetherTrees(e.getWorld()) || !e.getWorld().getEnvironment().equals(Environment.NETHER)) { - return false; - } - for (BlockState b : e.getBlocks()) { - if (Tag.LOGS.isTagged(b.getType())) { - b.setType(Material.GRAVEL); - } else if (Tag.LEAVES.isTagged(b.getType())) { - b.setType(Material.GLOWSTONE); - } - } - return true; - } } \ No newline at end of file diff --git a/src/main/java/world/bentobox/bentobox/listeners/flags/NetherTreesListener.java b/src/main/java/world/bentobox/bentobox/listeners/flags/NetherTreesListener.java new file mode 100644 index 000000000..aca1de820 --- /dev/null +++ b/src/main/java/world/bentobox/bentobox/listeners/flags/NetherTreesListener.java @@ -0,0 +1,48 @@ +package world.bentobox.bentobox.listeners.flags; + +import org.bukkit.Material; +import org.bukkit.Tag; +import org.bukkit.World; +import org.bukkit.block.BlockState; +import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; +import org.bukkit.event.Listener; +import org.bukkit.event.world.StructureGrowEvent; +import world.bentobox.bentobox.BentoBox; +import world.bentobox.bentobox.api.configuration.WorldSettings; + +/** + * Handles conversion of trees in the Nether if {@link WorldSettings#isNetherTrees()} is {@code true}. + * + * @author tastybento + */ +public class NetherTreesListener implements Listener { + + private BentoBox plugin; + + public NetherTreesListener(BentoBox plugin) { + this.plugin = plugin; + } + + /** + * Converts trees to gravel and glowstone. + * + * @param e event + */ + @EventHandler(priority = EventPriority.LOW, ignoreCancelled = true) + public void onTreeGrow(StructureGrowEvent e) { + // Don't do anything if we're not in the right place. + if (!plugin.getIWM().isNetherTrees(e.getWorld()) || !e.getWorld().getEnvironment().equals(World.Environment.NETHER)) { + return; + } + + // Modify everything! + for (BlockState b : e.getBlocks()) { + if (Tag.LOGS.isTagged(b.getType())) { + b.setType(Material.GRAVEL); + } else if (Tag.LEAVES.isTagged(b.getType())) { + b.setType(Material.GLOWSTONE); + } + } + } +} diff --git a/src/test/java/world/bentobox/bentobox/listeners/NetherPortalsTest.java b/src/test/java/world/bentobox/bentobox/listeners/NetherPortalsTest.java index 924f4b7cc..93824e707 100644 --- a/src/test/java/world/bentobox/bentobox/listeners/NetherPortalsTest.java +++ b/src/test/java/world/bentobox/bentobox/listeners/NetherPortalsTest.java @@ -1,6 +1,3 @@ -/** - * - */ package world.bentobox.bentobox.listeners; import static org.junit.Assert.assertFalse; @@ -70,9 +67,6 @@ public class NetherPortalsTest { private World nether; private World end; - /** - * @throws java.lang.Exception - */ @Before public void setUp() throws Exception { // Set up plugin @@ -159,14 +153,6 @@ public class NetherPortalsTest { when(iwm.inWorld(any(Location.class))).thenReturn(false); } - /** - * Test method for {@link world.bentobox.bentobox.listeners.NetherPortals#NetherPortals(world.bentobox.bentobox.BentoBox)}. - */ - @Test - public void testNetherPortals() { - assertNotNull(new NetherPortals(plugin)); - } - /** * Test method for {@link world.bentobox.bentobox.listeners.NetherPortals#onBlockBreak(org.bukkit.event.block.BlockBreakEvent)}. */ @@ -739,50 +725,4 @@ public class NetherPortalsTest { Mockito.verify(block).getLocation(); assertTrue(e.isCancelled()); } - - /** - * Test method for {@link world.bentobox.bentobox.listeners.NetherPortals#onTreeGrow(org.bukkit.event.world.StructureGrowEvent)}. - */ - @Test - public void testOnTreeGrow() { - NetherPortals np = new NetherPortals(plugin); - Location loc = mock(Location.class); - // Wrong world to start - when(loc.getWorld()).thenReturn(world); - BlockState log = mock(BlockState.class); - when(log.getType()).thenReturn(Material.OAK_LOG); - BlockState log2 = mock(BlockState.class); - when(log2.getType()).thenReturn(Material.ACACIA_LOG); - BlockState leaves = mock(BlockState.class); - when(leaves.getType()).thenReturn(Material.OAK_LEAVES); - BlockState leaves2 = mock(BlockState.class); - when(leaves2.getType()).thenReturn(Material.OAK_LEAVES); - List blocks = new ArrayList<>(); - blocks.add(log); - blocks.add(log2); - blocks.add(leaves); - blocks.add(leaves2); - StructureGrowEvent e = new StructureGrowEvent(loc, TreeType.ACACIA, false, null, blocks); - // No nether trees - when(iwm.isNetherTrees(world)).thenReturn(false); - assertFalse(np.onTreeGrow(e)); - // nether trees, wrong world - e = new StructureGrowEvent(loc, TreeType.ACACIA, false, null, blocks); - when(iwm.isNetherTrees(world)).thenReturn(true); - assertFalse(np.onTreeGrow(e)); - // Make the world nether - when(iwm.isNetherTrees(nether)).thenReturn(true); - when(loc.getWorld()).thenReturn(nether); - e = new StructureGrowEvent(loc, TreeType.ACACIA, false, null, blocks); - /* - * Temporary - * TODO: Fix for 1.13 - assertTrue(np.onTreeGrow(e)); - Mockito.verify(log).setType(Material.GRAVEL); - Mockito.verify(log2).setType(Material.GRAVEL); - Mockito.verify(leaves).setType(Material.GLOWSTONE); - Mockito.verify(leaves2).setType(Material.GLOWSTONE); - */ - } - }