2 Things that will make it work using the If statements.
1st, use different items for each handin. Using the SAME item each time for each level seems to confuse the program. If there is a way to clear the items after handing them in and setting the new setglobal, before the next if statememt, then it may work.
To make it properly return the items if they are not correct, add a
return;.
Code:
else
{
plugin::return_items(\%itemcount);
return;
}