Handle inventory max stack sizes better. Fixes BUKKIT-5564
Manual merge of 7e37cf9