Fixes water placement in nether-related areas
https://github.com/BentoBoxWorld/Greenhouses/issues/70 https://github.com/BentoBoxWorld/Greenhouses/issues/71
This commit is contained in:
parent
a8dec9a89b
commit
b0a0ae6e88
|
@ -7,6 +7,8 @@ import java.util.Set;
|
||||||
|
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
|
import org.bukkit.Particle;
|
||||||
|
import org.bukkit.Sound;
|
||||||
import org.bukkit.Tag;
|
import org.bukkit.Tag;
|
||||||
import org.bukkit.World;
|
import org.bukkit.World;
|
||||||
import org.bukkit.block.Biome;
|
import org.bukkit.block.Biome;
|
||||||
|
@ -51,13 +53,25 @@ public class GreenhouseEvents implements Listener {
|
||||||
* Permits water to be placed in the Nether if in a greenhouse and in an acceptable biome
|
* Permits water to be placed in the Nether if in a greenhouse and in an acceptable biome
|
||||||
* @param e - event
|
* @param e - event
|
||||||
*/
|
*/
|
||||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled=true)
|
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled=true)
|
||||||
public void onPlayerInteractInNether(PlayerBucketEmptyEvent e) {
|
public void onPlayerInteractInNether(PlayerBucketEmptyEvent e) {
|
||||||
|
if (!e.getBucket().equals(Material.WATER_BUCKET)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Block b = e.getBlockClicked().getRelative(e.getBlockFace());
|
||||||
if (e.getPlayer().getWorld().getEnvironment().equals(World.Environment.NETHER)
|
if (e.getPlayer().getWorld().getEnvironment().equals(World.Environment.NETHER)
|
||||||
&& e.getBucket().equals(Material.WATER_BUCKET)
|
&& !addon.getManager().getMap().getGreenhouse(b.getLocation())
|
||||||
&& !addon.getManager().getMap().getGreenhouse(e.getBlockClicked().getLocation())
|
|
||||||
.map(gh -> gh.getBiomeRecipe().getBiome()).map(NETHER_BIOMES::contains).orElse(true)) {
|
.map(gh -> gh.getBiomeRecipe().getBiome()).map(NETHER_BIOMES::contains).orElse(true)) {
|
||||||
e.getBlockClicked().getRelative(e.getBlockFace()).setType(Material.WATER);
|
// In Nether not a nether greenhouse
|
||||||
|
b.setType(Material.WATER);
|
||||||
|
} else if (!e.getPlayer().getWorld().getEnvironment().equals(World.Environment.NETHER)
|
||||||
|
&& addon.getManager().getMap().getGreenhouse(b.getLocation())
|
||||||
|
.map(gh -> gh.getBiomeRecipe().getBiome()).map(NETHER_BIOMES::contains).orElse(true)) {
|
||||||
|
// Not in Nether, in a nether greenhouse
|
||||||
|
e.setCancelled(true);
|
||||||
|
e.getPlayer().getInventory().getItemInMainHand().setType(Material.BUCKET);
|
||||||
|
b.getWorld().spawnParticle(Particle.SMOKE_NORMAL, b.getLocation(), 10);
|
||||||
|
b.getWorld().playSound(b.getLocation(), Sound.ENTITY_GENERIC_EXTINGUISH_FIRE, 1F, 5F);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -65,16 +79,25 @@ public class GreenhouseEvents implements Listener {
|
||||||
* Makes water in the Nether if ice is broken and in a greenhouse
|
* Makes water in the Nether if ice is broken and in a greenhouse
|
||||||
* @param e - event
|
* @param e - event
|
||||||
*/
|
*/
|
||||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled=true)
|
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled=true)
|
||||||
public void onIceBreak(BlockBreakEvent e) {
|
public void onIceBreak(BlockBreakEvent e) {
|
||||||
if (!e.getBlock().getWorld().getEnvironment().equals(World.Environment.NETHER)
|
if (!Tag.ICE.isTagged(e.getBlock().getType())) {
|
||||||
|| !Tag.ICE.isTagged(e.getBlock().getType())) {
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (!addon.getManager().getMap().getGreenhouse(e.getBlock().getLocation())
|
Block b = e.getBlock();
|
||||||
|
if (b.getWorld().getEnvironment().equals(World.Environment.NETHER)
|
||||||
|
&& !addon.getManager().getMap().getGreenhouse(b.getLocation())
|
||||||
.map(gh -> gh.getBiomeRecipe().getBiome()).map(NETHER_BIOMES::contains).orElse(true)) {
|
.map(gh -> gh.getBiomeRecipe().getBiome()).map(NETHER_BIOMES::contains).orElse(true)) {
|
||||||
|
//
|
||||||
e.setCancelled(true);
|
e.setCancelled(true);
|
||||||
e.getBlock().setType(Material.WATER);
|
b.setType(Material.WATER);
|
||||||
|
} else if (!e.getPlayer().getWorld().getEnvironment().equals(World.Environment.NETHER)
|
||||||
|
&& addon.getManager().getMap().getGreenhouse(b.getLocation())
|
||||||
|
.map(gh -> gh.getBiomeRecipe().getBiome()).map(NETHER_BIOMES::contains).orElse(true)) {
|
||||||
|
// Not in Nether, in a nether greenhouse
|
||||||
|
e.setCancelled(true);
|
||||||
|
b.setType(Material.AIR);
|
||||||
|
b.getWorld().playSound(b.getLocation(), Sound.BLOCK_GLASS_BREAK, 1F, 1F);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -15,6 +15,7 @@ import java.util.Optional;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
|
import org.bukkit.Sound;
|
||||||
import org.bukkit.Tag;
|
import org.bukkit.Tag;
|
||||||
import org.bukkit.World;
|
import org.bukkit.World;
|
||||||
import org.bukkit.World.Environment;
|
import org.bukkit.World.Environment;
|
||||||
|
@ -29,6 +30,7 @@ import org.bukkit.event.player.PlayerMoveEvent;
|
||||||
import org.bukkit.event.player.PlayerTeleportEvent;
|
import org.bukkit.event.player.PlayerTeleportEvent;
|
||||||
import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause;
|
import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
import org.bukkit.inventory.PlayerInventory;
|
||||||
import org.bukkit.util.BoundingBox;
|
import org.bukkit.util.BoundingBox;
|
||||||
import org.junit.After;
|
import org.junit.After;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
|
@ -77,6 +79,10 @@ public class GreenhouseEventsTest {
|
||||||
private Greenhouse gh1;
|
private Greenhouse gh1;
|
||||||
@Mock
|
@Mock
|
||||||
private Greenhouse gh2;
|
private Greenhouse gh2;
|
||||||
|
@Mock
|
||||||
|
private PlayerInventory inv;
|
||||||
|
@Mock
|
||||||
|
private ItemStack waterBucket;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @throws java.lang.Exception
|
* @throws java.lang.Exception
|
||||||
|
@ -106,6 +112,9 @@ public class GreenhouseEventsTest {
|
||||||
|
|
||||||
when(player.getWorld()).thenReturn(world);
|
when(player.getWorld()).thenReturn(world);
|
||||||
when(world.getEnvironment()).thenReturn(Environment.NETHER);
|
when(world.getEnvironment()).thenReturn(Environment.NETHER);
|
||||||
|
when(player.getInventory()).thenReturn(inv);
|
||||||
|
when(inv.getItemInMainHand()).thenReturn(waterBucket);
|
||||||
|
|
||||||
// Location
|
// Location
|
||||||
when(location.getBlockX()).thenReturn(5);
|
when(location.getBlockX()).thenReturn(5);
|
||||||
when(location.getBlockY()).thenReturn(15);
|
when(location.getBlockY()).thenReturn(15);
|
||||||
|
@ -134,11 +143,12 @@ public class GreenhouseEventsTest {
|
||||||
* Test method for {@link world.bentobox.greenhouses.listeners.GreenhouseEvents#onPlayerInteractInNether(org.bukkit.event.player.PlayerInteractEvent)}.
|
* Test method for {@link world.bentobox.greenhouses.listeners.GreenhouseEvents#onPlayerInteractInNether(org.bukkit.event.player.PlayerInteractEvent)}.
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void testOnPlayerInteractInNether() {
|
public void testOnPlayerInteractInNetherInGreenhouse() {
|
||||||
Block clickedBlock = mock(Block.class);
|
Block clickedBlock = mock(Block.class);
|
||||||
when(clickedBlock.getLocation()).thenReturn(location);
|
when(clickedBlock.getLocation()).thenReturn(location);
|
||||||
Block nextBlock = mock(Block.class);
|
Block nextBlock = mock(Block.class);
|
||||||
when(clickedBlock.getRelative(any())).thenReturn(nextBlock);
|
when(clickedBlock.getRelative(any())).thenReturn(nextBlock);
|
||||||
|
when(nextBlock.getLocation()).thenReturn(location);
|
||||||
ItemStack item = mock(ItemStack.class);
|
ItemStack item = mock(ItemStack.class);
|
||||||
when(item.getType()).thenReturn(Material.WATER_BUCKET);
|
when(item.getType()).thenReturn(Material.WATER_BUCKET);
|
||||||
PlayerBucketEmptyEvent e = new PlayerBucketEmptyEvent(player, nextBlock, clickedBlock, BlockFace.UP, Material.WATER_BUCKET, item);
|
PlayerBucketEmptyEvent e = new PlayerBucketEmptyEvent(player, nextBlock, clickedBlock, BlockFace.UP, Material.WATER_BUCKET, item);
|
||||||
|
@ -146,6 +156,23 @@ public class GreenhouseEventsTest {
|
||||||
verify(nextBlock).setType(Material.WATER);
|
verify(nextBlock).setType(Material.WATER);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test method for {@link world.bentobox.greenhouses.listeners.GreenhouseEvents#onPlayerInteractInNether(org.bukkit.event.player.PlayerInteractEvent)}.
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
public void testOnPlayerInteractInNetherOutsideOfGreenhouse() {
|
||||||
|
Block clickedBlock = mock(Block.class);
|
||||||
|
when(clickedBlock.getLocation()).thenReturn(location);
|
||||||
|
Block nextBlock = mock(Block.class);
|
||||||
|
when(clickedBlock.getRelative(any())).thenReturn(nextBlock);
|
||||||
|
when(nextBlock.getLocation()).thenReturn(mock(Location.class));
|
||||||
|
ItemStack item = mock(ItemStack.class);
|
||||||
|
when(item.getType()).thenReturn(Material.WATER_BUCKET);
|
||||||
|
PlayerBucketEmptyEvent e = new PlayerBucketEmptyEvent(player, nextBlock, clickedBlock, BlockFace.UP, Material.WATER_BUCKET, item);
|
||||||
|
ghe.onPlayerInteractInNether(e);
|
||||||
|
verify(nextBlock, never()).setType(Material.WATER);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test method for {@link world.bentobox.greenhouses.listeners.GreenhouseEvents#onPlayerInteractInNether(org.bukkit.event.player.PlayerInteractEvent)}.
|
* Test method for {@link world.bentobox.greenhouses.listeners.GreenhouseEvents#onPlayerInteractInNether(org.bukkit.event.player.PlayerInteractEvent)}.
|
||||||
*/
|
*/
|
||||||
|
@ -172,6 +199,8 @@ public class GreenhouseEventsTest {
|
||||||
when(clickedBlock.getLocation()).thenReturn(location);
|
when(clickedBlock.getLocation()).thenReturn(location);
|
||||||
Block nextBlock = mock(Block.class);
|
Block nextBlock = mock(Block.class);
|
||||||
when(clickedBlock.getRelative(any())).thenReturn(nextBlock);
|
when(clickedBlock.getRelative(any())).thenReturn(nextBlock);
|
||||||
|
when(clickedBlock.getWorld()).thenReturn(world);
|
||||||
|
when(nextBlock.getWorld()).thenReturn(world);
|
||||||
ItemStack item = mock(ItemStack.class);
|
ItemStack item = mock(ItemStack.class);
|
||||||
when(item.getType()).thenReturn(Material.WATER_BUCKET);
|
when(item.getType()).thenReturn(Material.WATER_BUCKET);
|
||||||
PlayerBucketEmptyEvent e = new PlayerBucketEmptyEvent(player, nextBlock, clickedBlock, BlockFace.UP, Material.WATER_BUCKET, item);
|
PlayerBucketEmptyEvent e = new PlayerBucketEmptyEvent(player, nextBlock, clickedBlock, BlockFace.UP, Material.WATER_BUCKET, item);
|
||||||
|
@ -266,7 +295,7 @@ public class GreenhouseEventsTest {
|
||||||
* Test method for {@link world.bentobox.greenhouses.listeners.GreenhouseEvents#onIceBreak(org.bukkit.event.block.BlockBreakEvent)}.
|
* Test method for {@link world.bentobox.greenhouses.listeners.GreenhouseEvents#onIceBreak(org.bukkit.event.block.BlockBreakEvent)}.
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void testOnIceBreakNotNether() {
|
public void testOnIceBreakNotNetherNetherGreenhouse() {
|
||||||
when(world.getEnvironment()).thenReturn(Environment.THE_END);
|
when(world.getEnvironment()).thenReturn(Environment.THE_END);
|
||||||
when(Tag.ICE.isTagged(any(Material.class))).thenReturn(true);
|
when(Tag.ICE.isTagged(any(Material.class))).thenReturn(true);
|
||||||
|
|
||||||
|
@ -275,10 +304,31 @@ public class GreenhouseEventsTest {
|
||||||
when(block.getWorld()).thenReturn(world);
|
when(block.getWorld()).thenReturn(world);
|
||||||
BlockBreakEvent e = new BlockBreakEvent(block, player);
|
BlockBreakEvent e = new BlockBreakEvent(block, player);
|
||||||
ghe.onIceBreak(e);
|
ghe.onIceBreak(e);
|
||||||
verify(block, never()).setType(Material.WATER);
|
verify(block).setType(Material.AIR);
|
||||||
assertFalse(e.isCancelled());
|
assertTrue(e.isCancelled());
|
||||||
|
verify(world).playSound(any(), eq(Sound.BLOCK_GLASS_BREAK), eq(1F), eq(1F));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test method for {@link world.bentobox.greenhouses.listeners.GreenhouseEvents#onIceBreak(org.bukkit.event.block.BlockBreakEvent)}.
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
public void testOnIceBreakNotNetherNotNetherGreenhouse() {
|
||||||
|
when(world.getEnvironment()).thenReturn(Environment.THE_END);
|
||||||
|
when(Tag.ICE.isTagged(any(Material.class))).thenReturn(true);
|
||||||
|
|
||||||
|
Block block = mock(Block.class);
|
||||||
|
when(block.getType()).thenReturn(Material.ICE);
|
||||||
|
when(block.getWorld()).thenReturn(world);
|
||||||
|
when(block.getLocation()).thenReturn(location);
|
||||||
|
BlockBreakEvent e = new BlockBreakEvent(block, player);
|
||||||
|
ghe.onIceBreak(e);
|
||||||
|
assertFalse(e.isCancelled());
|
||||||
|
verify(block, never()).setType(any());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test method for {@link world.bentobox.greenhouses.listeners.GreenhouseEvents#onIceBreak(org.bukkit.event.block.BlockBreakEvent)}.
|
* Test method for {@link world.bentobox.greenhouses.listeners.GreenhouseEvents#onIceBreak(org.bukkit.event.block.BlockBreakEvent)}.
|
||||||
*/
|
*/
|
||||||
|
@ -290,6 +340,7 @@ public class GreenhouseEventsTest {
|
||||||
Block block = mock(Block.class);
|
Block block = mock(Block.class);
|
||||||
when(block.getType()).thenReturn(Material.ICE);
|
when(block.getType()).thenReturn(Material.ICE);
|
||||||
when(block.getWorld()).thenReturn(world);
|
when(block.getWorld()).thenReturn(world);
|
||||||
|
|
||||||
BlockBreakEvent e = new BlockBreakEvent(block, player);
|
BlockBreakEvent e = new BlockBreakEvent(block, player);
|
||||||
ghe.onIceBreak(e);
|
ghe.onIceBreak(e);
|
||||||
verify(block, never()).setType(Material.WATER);
|
verify(block, never()).setType(Material.WATER);
|
||||||
|
|
Loading…
Reference in New Issue