Instructions
Dig a moat around whatever structure you are trying to protect. The moat should be at least two blocks wide, two blocks deep, and go all the way around your structure.
Construct several trap doors at a crafting table by filling the bottom six spaces with wood planks, and then completely cover the top of your moat with trap doors.
Craft a bucket and dig underground. Once you are deep enough to find lava, gather some in your bucket.
Open all the trap doors, and fill your moat with lava.
Close all the trap doors.
Craft pressure plates by placing two wooden planks next to each other at a crafting table.
Place pressure plates in front of each trap door. Monsters coming to attack you will step on the pressure plate, the trap door will open, and their next step will cause them to fall into the lava. This will also work with any animals that happen to walk by.