ConfigurationSection configGroups = f.getConfigurationSection("quizDiff." + quizWinners.get(pName));
Set<String> s = configGroups.getKeys(false);
// first of all, count all rewards and see if they'd fit into player's inventory
Integer allBlocks = 0;
Inventory pi = p.getInventory();
Integer maxStackSize = pi.getMaxStackSize();
for (String reward : s) {
Integer blockCount = f.getInt("quizDiff." + quizWinners.get(pName) + "." + reward);
if (blockCount > maxStackSize) {
allBlocks = (int) (allBlocks + Math.ceil(blockCount / maxStackSize));
} else {
allBlocks++;
}
}
// calculate available slots
Integer fullSlots = 0;
for (ItemStack istack : p.getInventory().getContents()) {
if ((istack != null) && istack.getAmount() > 0) {
fullSlots++;
}
}
if ((pi.getSize() - fullSlots) >= allBlocks) {
// fill player's inventory with the reward
for (String reward : s) {
try {
if (reward.contains(":")) {
String[] expl = reward.split(":");
pi.addItem(new ItemStack(Integer.parseInt(expl[0]), f.getInt("quizDiff." + quizWinners.get(pName) + "." + reward), (short) 0, Byte.parseByte(expl[1])));
} else {
pi.addItem(new ItemStack(Integer.parseInt(reward), f.getInt("quizDiff." + quizWinners.get(pName) + "." + reward)));
}
} catch (Throwable e) {
// unable to add item into inventory, inform server owner
LogHelper.logSevere("[CommandsEX] " + _("quizUnableToAddItem", "") + reward + ":" + f.getInt("quizDiff." + quizWinners.get(pName) + "." + reward));
LogHelper.logDebug("Message: " + e.getMessage() + ", cause: " + e.getCause());